From bc630e1e51be3800d340821ee228e1f3cb42859f Mon Sep 17 00:00:00 2001 From: Harvey Kandola Date: Tue, 4 Apr 2017 19:11:59 +0100 Subject: [PATCH] use specified doc name when creating from template --- .../components/document/document-heading.js | 4 ++++ app/app/components/folder/start-document.js | 2 +- app/app/services/template.js | 9 ++++++--- app/app/styles/print.scss | 2 +- core/api/endpoint/templates_endpoint.go | 18 ++++++++++++------ 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/app/components/document/document-heading.js b/app/app/components/document/document-heading.js index 2f4998f2..75898007 100644 --- a/app/app/components/document/document-heading.js +++ b/app/app/components/document/document-heading.js @@ -49,7 +49,11 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { this.set('document.name', this.get('docName')); this.set('document.excerpt', this.get('docExcerpt')); + this.showNotification('Saved'); + this.get('browser').setTitle(this.get('document.name')); + this.get('browser').setMetaDescription(this.get('document.excerpt')); + this.get('documentService').save(this.get('document')); this.set('editMode', false); diff --git a/app/app/components/folder/start-document.js b/app/app/components/folder/start-document.js index d4097f89..6e825710 100644 --- a/app/app/components/folder/start-document.js +++ b/app/app/components/folder/start-document.js @@ -123,7 +123,7 @@ export default Ember.Component.extend(NotifierMixin, { this.audit.record('used-saved-template'); this.send("showNotification", "Creating"); - this.get('templateService').importSavedTemplate(this.folder.get('id'), template.id).then((document) => { + this.get('templateService').importSavedTemplate(this.folder.get('id'), template.id, this.get('newDocumentName')).then((document) => { this.get('router').transitionTo('document', this.get('folder.id'), this.get('folder.slug'), document.get('id'), document.get('slug')); }); diff --git a/app/app/services/template.js b/app/app/services/template.js index e3d2eb57..5829eac1 100644 --- a/app/app/services/template.js +++ b/app/app/services/template.js @@ -28,12 +28,15 @@ export default Ember.Service.extend({ }); }, - importSavedTemplate: function (folderId, templateId) { + importSavedTemplate: function (folderId, templateId, docName) { let url = `templates/${templateId}/folder/${folderId}?type=saved`; - return this.get('ajax').post(url).then((doc) => { + return this.get('ajax').request(url, { + method: 'POST', + data: docName + }).then((doc) => { let data = this.get('store').normalize('document', doc); - return this.get('store').push(data); + return this.get('store').push(data); }); }, diff --git a/app/app/styles/print.scss b/app/app/styles/print.scss index 44a605fd..279487f1 100644 --- a/app/app/styles/print.scss +++ b/app/app/styles/print.scss @@ -148,5 +148,5 @@ font-size: 15px; line-height: 25px; color: $color-black; - } + } } diff --git a/core/api/endpoint/templates_endpoint.go b/core/api/endpoint/templates_endpoint.go index 49f617a5..f5e69f5f 100644 --- a/core/api/endpoint/templates_endpoint.go +++ b/core/api/endpoint/templates_endpoint.go @@ -315,27 +315,32 @@ func StartDocumentFromStockTemplate(w http.ResponseWriter, r *http.Request) { func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) { method := "StartDocumentFromSavedTemplate" p := request.GetPersister(r) - params := mux.Vars(r) - folderID := params["folderID"] + folderID := params["folderID"] if len(folderID) == 0 { writeMissingDataError(w, method, "folderID") return } templateID := params["templateID"] - - // We are OK with zero valued template ID because it signals 'give me empty document' if len(templateID) == 0 { writeMissingDataError(w, method, "templateID") return } + defer utility.Close(r.Body) + body, err := ioutil.ReadAll(r.Body) + if err != nil { + writeBadRequestError(w, method, "Bad payload") + return + } + + docTitle := string(body) + // Define an empty document just in case user wanted one. - var err error var d = entity.Document{} - d.Title = "New Document" + d.Title = docTitle d.Location = fmt.Sprintf("template-%s", templateID) d.Excerpt = "A new document" d.Slug = utility.MakeSlug(d.Title) @@ -381,6 +386,7 @@ func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) { d.Template = false d.LabelID = folderID d.UserID = p.Context.UserID + d.Title = docTitle err = p.AddDocument(d)