mirror of
https://gitlab.silvrtree.co.uk/martind2000/project.git
synced 2025-01-10 23:45:07 +00:00
79 lines
1.9 KiB
JavaScript
79 lines
1.9 KiB
JavaScript
import Ember from 'ember';
|
|
const {service, store} = Ember.inject;
|
|
export default Ember.Controller.extend({
|
|
session: service('session'), sessionAccount: service('session-account'),
|
|
|
|
actions: {
|
|
savePage: function() {
|
|
|
|
var model = this.get('model');
|
|
var self = this;
|
|
|
|
model.save()
|
|
.then(function(d) {
|
|
'use strict';
|
|
console.log(d);
|
|
self.send('resetView');
|
|
})
|
|
.catch(function(err) {
|
|
console.error(err);
|
|
});
|
|
|
|
},
|
|
|
|
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'
|
|
});
|
|
|
|
this.set('content', newPage);
|
|
|
|
this.set('isEditing', true);
|
|
}, cancelEdit: function() {
|
|
var model = this.get('model');
|
|
model.rollbackAttributes();
|
|
|
|
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);
|
|
});
|
|
}
|
|
|
|
}
|
|
});
|