mirror of
https://github.com/documize/community.git
synced 2025-07-20 13:49:42 +02:00
use specified doc name when creating from template
This commit is contained in:
parent
96e4b2058c
commit
bc630e1e51
5 changed files with 24 additions and 11 deletions
|
@ -49,7 +49,11 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
||||||
|
|
||||||
this.set('document.name', this.get('docName'));
|
this.set('document.name', this.get('docName'));
|
||||||
this.set('document.excerpt', this.get('docExcerpt'));
|
this.set('document.excerpt', this.get('docExcerpt'));
|
||||||
|
|
||||||
this.showNotification('Saved');
|
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.get('documentService').save(this.get('document'));
|
||||||
|
|
||||||
this.set('editMode', false);
|
this.set('editMode', false);
|
||||||
|
|
|
@ -123,7 +123,7 @@ export default Ember.Component.extend(NotifierMixin, {
|
||||||
this.audit.record('used-saved-template');
|
this.audit.record('used-saved-template');
|
||||||
this.send("showNotification", "Creating");
|
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'));
|
this.get('router').transitionTo('document', this.get('folder.id'), this.get('folder.slug'), document.get('id'), document.get('slug'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,13 @@ export default Ember.Service.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
importSavedTemplate: function (folderId, templateId) {
|
importSavedTemplate: function (folderId, templateId, docName) {
|
||||||
let url = `templates/${templateId}/folder/${folderId}?type=saved`;
|
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);
|
let data = this.get('store').normalize('document', doc);
|
||||||
return this.get('store').push(data);
|
return this.get('store').push(data);
|
||||||
});
|
});
|
||||||
|
|
|
@ -315,27 +315,32 @@ func StartDocumentFromStockTemplate(w http.ResponseWriter, r *http.Request) {
|
||||||
func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) {
|
func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) {
|
||||||
method := "StartDocumentFromSavedTemplate"
|
method := "StartDocumentFromSavedTemplate"
|
||||||
p := request.GetPersister(r)
|
p := request.GetPersister(r)
|
||||||
|
|
||||||
params := mux.Vars(r)
|
params := mux.Vars(r)
|
||||||
folderID := params["folderID"]
|
|
||||||
|
|
||||||
|
folderID := params["folderID"]
|
||||||
if len(folderID) == 0 {
|
if len(folderID) == 0 {
|
||||||
writeMissingDataError(w, method, "folderID")
|
writeMissingDataError(w, method, "folderID")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
templateID := params["templateID"]
|
templateID := params["templateID"]
|
||||||
|
|
||||||
// We are OK with zero valued template ID because it signals 'give me empty document'
|
|
||||||
if len(templateID) == 0 {
|
if len(templateID) == 0 {
|
||||||
writeMissingDataError(w, method, "templateID")
|
writeMissingDataError(w, method, "templateID")
|
||||||
return
|
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.
|
// Define an empty document just in case user wanted one.
|
||||||
var err error
|
|
||||||
var d = entity.Document{}
|
var d = entity.Document{}
|
||||||
d.Title = "New Document"
|
d.Title = docTitle
|
||||||
d.Location = fmt.Sprintf("template-%s", templateID)
|
d.Location = fmt.Sprintf("template-%s", templateID)
|
||||||
d.Excerpt = "A new document"
|
d.Excerpt = "A new document"
|
||||||
d.Slug = utility.MakeSlug(d.Title)
|
d.Slug = utility.MakeSlug(d.Title)
|
||||||
|
@ -381,6 +386,7 @@ func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) {
|
||||||
d.Template = false
|
d.Template = false
|
||||||
d.LabelID = folderID
|
d.LabelID = folderID
|
||||||
d.UserID = p.Context.UserID
|
d.UserID = p.Context.UserID
|
||||||
|
d.Title = docTitle
|
||||||
|
|
||||||
err = p.AddDocument(d)
|
err = p.AddDocument(d)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue