”2016-04-12”

This commit is contained in:
Martin Donnelly 2016-04-12 16:45:01 +01:00
parent 30bbee852a
commit a164666468
4 changed files with 77 additions and 22 deletions

View File

@ -1,41 +1,78 @@
import Ember from 'ember'; import Ember from 'ember';
const { service , store } = Ember.inject; const {service, store} = Ember.inject;
export default Ember.Controller.extend({ export default Ember.Controller.extend({
session: service('session'), session: service('session'), sessionAccount: service('session-account'),
sessionAccount: service('session-account'),
actions: { actions: {
savePage: function() { savePage: function() {
var model = this.get('model'); var model = this.get('model');
var self = this;
model.save() model.save()
.catch(function(err) { .then(function(d) {
console.error(err); 'use strict';
}); console.log(d);
self.send('resetView');
})
.catch(function(err) {
console.error(err);
});
}, },
createNew: function() { createNew: function() {
'use strict'; 'use strict';
const cid = this.get('sessionAccount.account.memberof'); const cid = this.get('sessionAccount.account.memberof');
var store = this.get('store'); var store = this.get('store');
var newPage = store.createRecord('page',{cid: cid, var newPage = store.createRecord('page', {
vid: 'JPnbDnRzwDSNLTCcS4miFq', content: 0, imageUrl: 'http://lorempixel.com/300/300'}); cid: cid,
vid: 'JPnbDnRzwDSNLTCcS4miFq',
content: 0,
imageUrl: 'http://lorempixel.com/300/300'
});
this.set('content',newPage); this.set('content', newPage);
this.set('isEditing', true); this.set('isEditing', true);
}, cancelEdit: function() { }, cancelEdit: function() {
var model = this.get('model'); var model = this.get('model');
model.rollbackAttributes(); model.rollbackAttributes();
model = this.store.findAll('page'); this.send('resetView');
this.set('isEditing', false);
this.set('model', model);
} }, 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);
});
} }
}
}); });

View File

@ -17,6 +17,11 @@ export default DS.Model.extend({
link3Url: DS.attr('string'), link3Url: DS.attr('string'),
link4Text: DS.attr('string'), link4Text: DS.attr('string'),
link4Url: 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() { visibleLink1: function() {
return !((Ember.isBlank(this.get('link1Text'))) || (Ember.isBlank(this.get('link1Url')))); return !((Ember.isBlank(this.get('link1Text'))) || (Ember.isBlank(this.get('link1Url'))));
}.property('link1Url','link1Text'), }.property('link1Url','link1Text'),

View File

@ -57,3 +57,9 @@ body {
max-width: 300px; max-width: 300px;
max-height: 300px; max-height: 300px;
} }
.linkpid {
border: 1px solid #868686;
padding: 6px;
background-color: lightyellow;
}

View File

@ -25,8 +25,8 @@
{{item.pageMode}} {{item.pageMode}}
</div> </div>
<div class="col-md-4 content"> <div class="col-md-4 content">
<button class="btn btn-primary btn-sm">Edit</button> <button class="btn btn-primary btn-sm" {{action "performEdit" item.id}}>Edit</button>
<button class="btn btn-danger btn-sm">Delete</button> <!-- <button class="btn btn-danger btn-sm" {{action "performDelete" item.id}}>Delete</button>-->
</div> </div>
</div> </div>
{{/each}} {{/each}}
@ -44,6 +44,13 @@
<div class="row"> <div class="row">
<div class="col-md-4 content"> <div class="col-md-4 content">
<form {{action "savePage" on='submit'}}> <form {{action "savePage" on='submit'}}>
{{#if model.usefulPid}}
<div class="col-md-12 form-inline">
<p>Link to this page: <span class="linkpid">{{model.usefulPid}}</span></p>
</div>
{{/if}}
<div class="col-md-12 form-inline"> <div class="col-md-12 form-inline">
<label for="title">Title:</label> <label for="title">Title:</label>
{{input id='title' placeholder='title' value=model.title class="form-control" required="required"}} {{input id='title' placeholder='title' value=model.title class="form-control" required="required"}}