diff --git a/app/app/components/document/document-sidebar.js b/app/app/components/document/document-sidebar.js index c2ce79ee..52f5dd32 100644 --- a/app/app/components/document/document-sidebar.js +++ b/app/app/components/document/document-sidebar.js @@ -106,6 +106,11 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, { this.attrs.onInsertBlock(block); }, + onDeleteBlock(id) { + this.set('blocks', this.get('blocks').filter((item) => item.get('id') !== id)); + this.attrs.onDeleteBlock(id); + }, + scrollTop() { this.set('showScrollTool', false); diff --git a/app/app/components/document/page-wizard.js b/app/app/components/document/page-wizard.js index 619a9e67..87536103 100644 --- a/app/app/components/document/page-wizard.js +++ b/app/app/components/document/page-wizard.js @@ -12,12 +12,22 @@ import Ember from 'ember'; import NotifierMixin from '../../mixins/notifier'; +const { + computed, +} = Ember; + export default Ember.Component.extend(NotifierMixin, { display: 'section', // which CSS to use hasTemplates: false, didReceiveAttrs() { - this.set('hasBlocks', this.get('blocks.length') > 0); + let blocks = this.get('blocks'); + + this.set('hasBlocks', blocks.get('length') > 0); + + blocks.forEach((b) => { + b.set('deleteId', `delete-block-button-${b.id}`); + }); }, didRender() { @@ -42,6 +52,10 @@ export default Ember.Component.extend(NotifierMixin, { this.attrs.onAddSection(section); }, + onDeleteBlock(id) { + this.attrs.onDeleteBlock(id); + }, + onInsertBlock(block) { this.attrs.onInsertBlock(block); } diff --git a/app/app/components/section/base-editor.js b/app/app/components/section/base-editor.js index b9d0c0bb..b30be215 100644 --- a/app/app/components/section/base-editor.js +++ b/app/app/components/section/base-editor.js @@ -21,10 +21,6 @@ export default Ember.Component.extend({ return is.not.undefined(this.get('page.excerpt')); }), - didReceiveAttrs() { - this._super(...arguments); - }, - didRender() { let self = this; Mousetrap.bind('esc', function () { diff --git a/app/app/pods/document/controller.js b/app/app/pods/document/controller.js index 0e7a6283..7e08039d 100644 --- a/app/app/pods/document/controller.js +++ b/app/app/pods/document/controller.js @@ -15,6 +15,7 @@ import NotifierMixin from '../../mixins/notifier'; export default Ember.Controller.extend(NotifierMixin, { documentService: Ember.inject.service('document'), templateService: Ember.inject.service('template'), + sectionService: Ember.inject.service('section'), page: null, folder: {}, pages: [], @@ -188,6 +189,14 @@ export default Ember.Controller.extend(NotifierMixin, { }); }, + onDeleteBlock(blockId) { + this.get('sectionService').deleteBlock(blockId).then(() => { + this.audit.record("deleted-block"); + this.send("showNotification", "Deleted"); + this.transitionToRoute('document.index'); + }); + }, + onDocumentDelete() { this.get('documentService').deleteDocument(this.get('model.document.id')).then(() => { this.audit.record("deleted-page"); diff --git a/app/app/pods/document/template.hbs b/app/app/pods/document/template.hbs index 3db1ca10..cff52928 100644 --- a/app/app/pods/document/template.hbs +++ b/app/app/pods/document/template.hbs @@ -2,7 +2,7 @@ {{#layout/zone-sidebar}} {{document/document-sidebar document=model.document folder=model.folder pages=model.pages page=model.page isEditor=model.isEditor sections=model.sections - onAddSection=(action 'onAddSection') onInsertBlock=(action 'onInsertBlock') changePageSequence=(action 'onPageSequenceChange') changePageLevel=(action 'onPageLevelChange') gotoPage=(action 'gotoPage')}} + onAddSection=(action 'onAddSection') onInsertBlock=(action 'onInsertBlock') onDeleteBlock=(action 'onDeleteBlock') changePageSequence=(action 'onPageSequenceChange') changePageLevel=(action 'onPageLevelChange') gotoPage=(action 'gotoPage')}} {{/layout/zone-sidebar}} {{#layout/zone-content}} diff --git a/app/app/services/section.js b/app/app/services/section.js index e0018a30..3f7d36d0 100644 --- a/app/app/services/section.js +++ b/app/app/services/section.js @@ -81,6 +81,9 @@ export default BaseService.extend({ return this.get('ajax').post(url, { data: JSON.stringify(payload), contentType: 'json' + }).then((response) => { + let data = this.get('store').normalize('block', response); + return this.get('store').push(data); }); }, @@ -116,5 +119,14 @@ export default BaseService.extend({ method: 'PUT', data: JSON.stringify(block) }); + }, + + // Removes specified reusable content block. + deleteBlock: function (blockId) { + let url = `sections/blocks/${blockId}`; + + return this.get('ajax').request(url, { + method: 'DELETE' + }); } }); diff --git a/app/app/styles/view/document/wizard.scss b/app/app/styles/view/document/wizard.scss index 8eaa0860..e9996962 100644 --- a/app/app/styles/view/document/wizard.scss +++ b/app/app/styles/view/document/wizard.scss @@ -83,17 +83,11 @@ text-align: center; width: 20px; margin-top: 5px; - opacity: 0.3; + opacity: 0.4; > .material-icons, a { color: $color-gray; - - &:hover { - opacity: 1; - color: $color-primary; - } } - } } } diff --git a/app/app/templates/components/document/document-sidebar.hbs b/app/app/templates/components/document/document-sidebar.hbs index 19728baf..9f5529a6 100644 --- a/app/app/templates/components/document/document-sidebar.hbs +++ b/app/app/templates/components/document/document-sidebar.hbs @@ -26,6 +26,6 @@ {{/if}} {{#if showSections}} {{document/page-wizard display='section' document=document folder=folder sections=sections blocks=blocks - onCancel=(action 'onCancel') onAddSection=(action 'onAddSection') onInsertBlock=(action 'onInsertBlock')}} + onCancel=(action 'onCancel') onAddSection=(action 'onAddSection') onInsertBlock=(action 'onInsertBlock') onDeleteBlock=(action 'onDeleteBlock')}} {{/if}} diff --git a/app/app/templates/components/document/page-wizard.hbs b/app/app/templates/components/document/page-wizard.hbs index 4dcb5970..e59d6fa8 100644 --- a/app/app/templates/components/document/page-wizard.hbs +++ b/app/app/templates/components/document/page-wizard.hbs @@ -40,9 +40,15 @@ mode_edit {{/link-to}}
- delete + delete + {{#dropdown-dialog target=block.deleteId position="top right" button="Delete" color="flat-red" onAction=(action 'onDeleteBlock' block.id)}} +
+ Are you sure you want to delete block
+ {{block.title}}?
+