diff --git a/app/controllers/pages.js b/app/controllers/pages.js index c1b2184..514fe01 100644 --- a/app/controllers/pages.js +++ b/app/controllers/pages.js @@ -1,41 +1,78 @@ import Ember from 'ember'; -const { service , store } = Ember.inject; +const {service, store} = Ember.inject; export default Ember.Controller.extend({ - session: service('session'), - sessionAccount: service('session-account'), + session: service('session'), sessionAccount: service('session-account'), actions: { - savePage: function() { + savePage: function() { - var model = this.get('model'); + var model = this.get('model'); + var self = this; - model.save() - .catch(function(err) { - console.error(err); - }); + model.save() + .then(function(d) { + 'use strict'; + console.log(d); + self.send('resetView'); + }) + .catch(function(err) { + console.error(err); + }); - }, + }, - createNew: function() { + createNew: function() { 'use strict'; const cid = this.get('sessionAccount.account.memberof'); var store = this.get('store'); - var newPage = store.createRecord('page',{cid: cid, - vid: 'JPnbDnRzwDSNLTCcS4miFq', content: 0, imageUrl: 'http://lorempixel.com/300/300'}); + var newPage = store.createRecord('page', { + cid: cid, + vid: 'JPnbDnRzwDSNLTCcS4miFq', + content: 0, + imageUrl: 'http://lorempixel.com/300/300' + }); - this.set('content',newPage); + this.set('content', newPage); this.set('isEditing', true); }, cancelEdit: function() { - var model = this.get('model'); - model.rollbackAttributes(); + var model = this.get('model'); + model.rollbackAttributes(); - model = this.store.findAll('page'); - this.set('isEditing', false); - this.set('model', model); + this.send('resetView'); - } + }, performEdit: function(id) { + 'use strict'; + var self = this; + var store = this.get('store'); + console.log(id); + var editPage = this.store.peekRecord('page', id); + + this.set('content', editPage); + this.set('isEditing', true); + }, resetView() { + 'use strict'; + var model = this.get('model'); + + model = this.store.findAll('page'); + this.set('isEditing', false); + this.set('model', model); + }, performDelete: function(id) { + 'use strict'; + console.log('Delete: ', id); + var store = this.get('store'); + console.log(id); + var deletePage = this.store.peekRecord('page', id); + deletePage.destroyRecord() + .then(function(d) { + console.log(d); + }) + .catch(function(e) { + console.error(e); + }); } + + } }); diff --git a/app/models/page.js b/app/models/page.js index 300ea36..b93a371 100644 --- a/app/models/page.js +++ b/app/models/page.js @@ -17,6 +17,11 @@ export default DS.Model.extend({ link3Url: DS.attr('string'), link4Text: DS.attr('string'), link4Url: DS.attr('string'), + usefulPid: function() { + 'use strict'; + + return !Ember.isBlank(this.get('pid')) ? ('/export/' + this.get('pid') + '.html').toString() : false; + }.property('pid'), visibleLink1: function() { return !((Ember.isBlank(this.get('link1Text'))) || (Ember.isBlank(this.get('link1Url')))); }.property('link1Url','link1Text'), diff --git a/app/styles/app.scss b/app/styles/app.scss index 5971f80..ac4ae14 100644 --- a/app/styles/app.scss +++ b/app/styles/app.scss @@ -57,3 +57,9 @@ body { max-width: 300px; max-height: 300px; } + +.linkpid { + border: 1px solid #868686; + padding: 6px; + background-color: lightyellow; +} diff --git a/app/templates/pages.hbs b/app/templates/pages.hbs index 0d6b108..61839c5 100644 --- a/app/templates/pages.hbs +++ b/app/templates/pages.hbs @@ -25,8 +25,8 @@ {{item.pageMode}}