diff --git a/app/app/components/document/document-sidebar.js b/app/app/components/document/document-sidebar.js index 3da1ee56..c91de379 100644 --- a/app/app/components/document/document-sidebar.js +++ b/app/app/components/document/document-sidebar.js @@ -10,10 +10,28 @@ // https://documize.com import Ember from 'ember'; +import models from '../../utils/model'; +import TooltipMixin from '../../mixins/tooltip'; + +export default Ember.Component.extend(TooltipMixin, { + sectionService: Ember.inject.service('section'), + documentService: Ember.inject.service('document'), -export default Ember.Component.extend({ document: {}, folder: {}, + sections: [], + showToc: true, + showSectionList: false, + + // didRender() { + // if (this.get('isEditor')) { + // this.addTooltip(document.getElementById("add-section-button")); + // } + // }, + + // willDestroyElement() { + // this.destroyTooltips(); + // }, actions: { // Page up - above pages shunt down. @@ -21,7 +39,7 @@ export default Ember.Component.extend({ this.attrs.changePageSequence(pendingChanges); }, - // Move down -- pages below shift up. + // Move down - pages below shift up. onPageLevelChange(pendingChanges) { this.attrs.changePageLevel(pendingChanges); }, @@ -29,5 +47,47 @@ export default Ember.Component.extend({ gotoPage(id) { return this.attrs.gotoPage(id); }, + + addSection() { + let self = this; + + this.get('sectionService').getAll().then(function(sections) { + self.set('sections', sections); + self.set('showToc', false); + self.set('showSectionList', true); + }); + }, + + showToc() { + this.set('showSectionList', false); + this.set('showToc', true); + }, + + onAddSection(section) { + this.audit.record("added-section"); + this.audit.record("added-section-" + section.contentType); + + let page = models.PageModel.create({ + documentId: this.get('document.id'), + title: `${section.title} Section`, + level: 2, + sequence: 2048, + body: "", + contentType: section.contentType + }); + + let meta = models.PageMetaModel.create({ + documentId: this.get('document.id'), + rawBody: "", + config: "" + }); + + let model = { + page: page, + meta: meta + }; + + this.attrs.onAddPage(model); + } } }); \ No newline at end of file diff --git a/app/app/components/document/document-toolbar.js b/app/app/components/document/document-toolbar.js index 077bde0f..5caf1462 100644 --- a/app/app/components/document/document-toolbar.js +++ b/app/app/components/document/document-toolbar.js @@ -24,7 +24,6 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { didRender() { if (this.get('isEditor')) { - this.addTooltip(document.getElementById("add-section-button")); this.addTooltip(document.getElementById("attachment-button")); this.addTooltip(document.getElementById("save-template-button")); this.addTooltip(document.getElementById("set-meta-button")); diff --git a/app/app/components/document/page-wizard.js b/app/app/components/document/page-wizard.js index 6faca932..15467b08 100644 --- a/app/app/components/document/page-wizard.js +++ b/app/app/components/document/page-wizard.js @@ -13,55 +13,15 @@ import Ember from 'ember'; import NotifierMixin from '../../mixins/notifier'; export default Ember.Component.extend(NotifierMixin, { - title: "New Section", - contentType: "", - - didReceiveAttrs() { - let section = this.get("sections").get('firstObject'); - section.set("selected", true); - }, - - didInsertElement() { - $("#page-title").removeClass("error").focus(); - }, - actions: { - setOption(id) { - let sections = this.get("sections"); - - sections.forEach(function(option) { - Ember.set(option, 'selected', option.id === id); - }); - - this.set("sections", sections); - - // if (this.session.get('popupBlocked')) { - // this.showNotification("Hmm, looks like your browser is blocking popups..."); - // } - }, - - onCancel() { - this.attrs.onCancel(); - }, - - onAction() { - let title = this.get("title"); - let section = this.get("sections").findBy("selected", true); - let contentType = section.contentType; + addSection(section) { if (section.preview) { this.showNotification("Coming soon!"); return; } - if (is.empty(title)) { - $("#page-title").addClass("error").focus(); - return; - } - - this.audit.record('added section ' + section.contentType); - - this.attrs.onAction(title, contentType); + this.attrs.onAction(section); } } }); \ No newline at end of file diff --git a/app/app/pods/document/index/controller.js b/app/app/pods/document/index/controller.js index f6d0c84f..04b86079 100644 --- a/app/app/pods/document/index/controller.js +++ b/app/app/pods/document/index/controller.js @@ -175,6 +175,19 @@ export default Ember.Controller.extend(NotifierMixin, { this.get('documentService').save(doc).then(function() { self.set('model', doc); }); + }, + + onAddPage(page) { + let self = this; + + this.get('documentService').addPage(this.get('model.id'), page).then(function(newPage) { + self.transitionToRoute('document.edit', + self.get('folder.id'), + self.get('folder.slug'), + self.get('model.id'), + self.get('model.slug'), + newPage.id); + }); } } }); \ No newline at end of file diff --git a/app/app/pods/document/index/template.hbs b/app/app/pods/document/index/template.hbs index 23c3ee58..00596de4 100644 --- a/app/app/pods/document/index/template.hbs +++ b/app/app/pods/document/index/template.hbs @@ -8,7 +8,7 @@