project/app/controllers/pages.js

79 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2016-04-06 15:53:06 +00:00
import Ember from 'ember';
2016-04-12 15:45:01 +00:00
const {service, store} = Ember.inject;
2016-04-06 15:53:06 +00:00
export default Ember.Controller.extend({
2016-04-12 15:45:01 +00:00
session: service('session'), sessionAccount: service('session-account'),
2016-04-06 15:53:06 +00:00
actions: {
2016-04-12 15:45:01 +00:00
savePage: function() {
2016-04-06 15:53:06 +00:00
2016-04-12 15:45:01 +00:00
var model = this.get('model');
var self = this;
2016-04-06 15:53:06 +00:00
2016-04-12 15:45:01 +00:00
model.save()
.then(function(d) {
'use strict';
console.log(d);
self.send('resetView');
})
.catch(function(err) {
console.error(err);
});
2016-04-06 15:53:06 +00:00
2016-04-12 15:45:01 +00:00
},
2016-04-06 15:53:06 +00:00
2016-04-12 15:45:01 +00:00
createNew: function() {
2016-04-06 15:53:06 +00:00
'use strict';
const cid = this.get('sessionAccount.account.memberof');
var store = this.get('store');
2016-04-12 15:45:01 +00:00
var newPage = store.createRecord('page', {
cid: cid,
vid: 'JPnbDnRzwDSNLTCcS4miFq',
content: 0,
imageUrl: 'http://lorempixel.com/300/300'
});
2016-04-06 15:53:06 +00:00
2016-04-12 15:45:01 +00:00
this.set('content', newPage);
2016-04-06 15:53:06 +00:00
this.set('isEditing', true);
}, cancelEdit: function() {
2016-04-12 15:45:01 +00:00
var model = this.get('model');
model.rollbackAttributes();
2016-04-06 15:53:06 +00:00
2016-04-12 15:45:01 +00:00
this.send('resetView');
2016-04-06 15:53:06 +00:00
2016-04-12 15:45:01 +00:00
}, 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');
2016-04-21 15:45:00 +00:00
console.log(id);
var deletePage = this.store.peekRecord('page', id);
deletePage.destroyRecord()
.then(function(d) {
console.log(d);
})
.catch(function(e) {
console.error(e);
});
2016-04-06 15:53:06 +00:00
}
2016-04-12 15:45:01 +00:00
}
2016-04-06 15:53:06 +00:00
});