diff --git a/app/components/base-modal.js b/app/components/base-modal.js new file mode 100644 index 0000000..dbb2046 --- /dev/null +++ b/app/components/base-modal.js @@ -0,0 +1,9 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + actions: { + close: function() { + return this.sendAction(); + } + } +}); diff --git a/app/components/page-node.js b/app/components/page-node.js index 282d115..21434de 100644 --- a/app/components/page-node.js +++ b/app/components/page-node.js @@ -3,5 +3,18 @@ import Ember from 'ember'; export default Ember.Component.extend({ classNames: ['page-node'], model: null, - hasChildren: Ember.computed.notEmpty('model.children') + hasChildren: Ember.computed.notEmpty('model.children'), + actions: { + addChild: function(){ + this.sendAction('createChild', this.get('model')); + }, + remove: function(){ + var component = this; + var page = this.get('model'); + page.deleteRecord(); + page.save().then(function(){ + component.destroy(); + }); + } + } }); diff --git a/app/controllers/new-page-modal.js b/app/controllers/new-page-modal.js new file mode 100644 index 0000000..a3685c0 --- /dev/null +++ b/app/controllers/new-page-modal.js @@ -0,0 +1,32 @@ +import Ember from 'ember'; +import extractError from 'teamplaybook-ember/lib/extract-error'; + +export default Ember.Controller.extend({ + showError: false, + errorMessage: null, + + actions: { + close: function() { + console.log('on close'); + this.send('closeModal'); + }, + save: function(){ + var controller = this; + var page = this.get('model'); + + var onSaveSucess = function(){ + controller.send('closeModal'); + }; + + var onSaveFailure = function(response){ + controller.setProperties({ + showMessage: false, + showError: true, + errorMessage: extractError(response) + }); + }; + + page.save().then(onSaveSucess, onSaveFailure); + } + } +}); \ No newline at end of file diff --git a/app/controllers/team/pages.js b/app/controllers/team/pages.js index 6c13b11..5cd331c 100644 --- a/app/controllers/team/pages.js +++ b/app/controllers/team/pages.js @@ -1,5 +1,40 @@ import Ember from 'ember'; export default Ember.Controller.extend({ - rootPageNodes: Ember.computed.filterBy('model', 'rootNode', true) -}); + rootPageNodes: Ember.computed.filterBy('model', 'rootNode', true), + actions: { + createRootPage: function(){ + this.createPage(); + }, + + createChildPage: function(parent){ + console.log('here'); + this.createPage(parent); + }, + + onPageCreated: function(page){ + this.get('model').pushObject(page); + } + }, + + createPage: function(parent){ + var controller = this; + var params = this.paramsForPage(parent); + + var page = this.store.createRecord('page', params); + + page.on('didCommit', function(page){ + controller.send('onPageCreated', page); + }); + + this.send('openModal', 'new-page-modal', page); + }, + + paramsForPage: function(parent){ + if(parent){ + return {parentId: parent.get('id')}; + }else{ + return {}; + } + } +}); \ No newline at end of file diff --git a/app/initializers/inject-store-into-component.js b/app/initializers/inject-store-into-component.js new file mode 100644 index 0000000..f07f2af --- /dev/null +++ b/app/initializers/inject-store-into-component.js @@ -0,0 +1,6 @@ +export default { + name: 'inject-store-into-component', + initialize: function(container, application) { + application.inject('component', 'store', 'store:main'); + }, +}; \ No newline at end of file diff --git a/app/models/page.js b/app/models/page.js index c37885f..864713f 100644 --- a/app/models/page.js +++ b/app/models/page.js @@ -5,7 +5,8 @@ var Page = DS.Model.extend({ body: DS.attr('string'), children: DS.hasMany('pages', {inverse: 'parent'}), parent: DS.belongsTo('page'), - rootNode: DS.attr('boolean') + rootNode: DS.attr('boolean'), + parentId: DS.attr('number') }); // Page.reopenClass({ diff --git a/app/routes/application.js b/app/routes/application.js index 29470f1..029ac90 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -6,6 +6,21 @@ export default Ember.Route.extend(ApplicationRouteMixin, { actions: { logout: function() { this.get('session').invalidate(); + }, + + openModal: function(modalName, model) { + this.controllerFor(modalName).set('model', model); + return this.render(modalName, { + into: 'application', + outlet: 'modal' + }); + }, + + closeModal: function() { + return this.disconnectOutlet({ + outlet: 'modal', + parentView: 'application' + }); } } }); \ No newline at end of file diff --git a/app/serializers/application.js b/app/serializers/application.js index b08dc8b..096add1 100644 --- a/app/serializers/application.js +++ b/app/serializers/application.js @@ -1,3 +1,8 @@ +import Ember from 'ember'; import JsonApiSerializer from 'ember-json-api/json-api-serializer'; -export default JsonApiSerializer.extend({}); \ No newline at end of file +export default JsonApiSerializer.extend({ + keyForAttribute: function(key) { + return Ember.String.decamelize(key); + } +}); diff --git a/app/styles/app.scss b/app/styles/app.scss index 3fd71bd..28ad538 100644 --- a/app/styles/app.scss +++ b/app/styles/app.scss @@ -5,5 +5,6 @@ @import "colors"; @import "team-layout"; +@import "modals"; -@import "components/team-options-menu.scss"; \ No newline at end of file +@import "components/team-options-menu.scss"; diff --git a/app/styles/modals.scss b/app/styles/modals.scss new file mode 100644 index 0000000..72ff28d --- /dev/null +++ b/app/styles/modals.scss @@ -0,0 +1,24 @@ +* { + box-sizing: border-box; +} + +.modal { + position: relative; + margin: 10px auto; + width: 300px; + background-color: #fff; + padding: 1em; +} + +input { + width: 100%; +} + +.overlay { + height: 100%; + width: 100%; + position: fixed; + top: 0; + left: 0; + background-color: rgba(0, 0, 0, 0.2); +} \ No newline at end of file diff --git a/app/templates/application.hbs b/app/templates/application.hbs index c24cd68..1e9c8e4 100644 --- a/app/templates/application.hbs +++ b/app/templates/application.hbs @@ -1 +1,2 @@ {{outlet}} +{{outlet 'modal'}} \ No newline at end of file diff --git a/app/templates/components/base-modal.hbs b/app/templates/components/base-modal.hbs new file mode 100644 index 0000000..84b8791 --- /dev/null +++ b/app/templates/components/base-modal.hbs @@ -0,0 +1,6 @@ +
+