From cd7c17482ee9c166daedad14e6bac304de61c9b5 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 1 Oct 2018 19:20:32 +0200 Subject: [PATCH] Move systemtags to compiled handlebars Signed-off-by: Roeland Jago Douma --- build/compile-handlebars-templates.sh | 3 + core/js/core.json | 1 + core/js/systemtags/merged.json | 1 + core/js/systemtags/systemtagsinputfield.js | 53 +------------ core/js/systemtags/templates.js | 74 +++++++++++++++++++ .../js/systemtags/templates/result.handlebars | 13 ++++ .../templates/result_form.handlebars | 7 ++ .../systemtags/templates/selection.handlebars | 5 ++ 8 files changed, 108 insertions(+), 49 deletions(-) create mode 100644 core/js/systemtags/templates.js create mode 100644 core/js/systemtags/templates/result.handlebars create mode 100644 core/js/systemtags/templates/result_form.handlebars create mode 100644 core/js/systemtags/templates/selection.handlebars diff --git a/build/compile-handlebars-templates.sh b/build/compile-handlebars-templates.sh index 8dc0e0397a..96080d12ec 100755 --- a/build/compile-handlebars-templates.sh +++ b/build/compile-handlebars-templates.sh @@ -10,6 +10,9 @@ handlebars -n OC.Settings.Templates settings/js/authtoken.handlebars -f setting # Contactsmenu handlebars -n OC.ContactsMenu.Templates core/js/contactsmenu -f core/js/contactsmenu_templates.js +# Systemtags +handlebars -n OC.SystemTags.Templates core/js/systemtags/templates -f core/js/systemtags/templates.js + # Files app handlebars -n OCA.Files.Templates apps/files/js/templates -f apps/files/js/templates.js diff --git a/core/js/core.json b/core/js/core.json index 19f361d2df..161e4766f3 100644 --- a/core/js/core.json +++ b/core/js/core.json @@ -58,6 +58,7 @@ "files/fileinfo.js", "files/client.js", "systemtags/systemtags.js", + "systemtags/templates.js", "systemtags/systemtagmodel.js", "systemtags/systemtagscollection.js", "systemtags/systemtagsmappingcollection.js", diff --git a/core/js/systemtags/merged.json b/core/js/systemtags/merged.json index 846ba967ed..641858ee2e 100644 --- a/core/js/systemtags/merged.json +++ b/core/js/systemtags/merged.json @@ -1,5 +1,6 @@ [ "systemtags.js", + "templates.js", "systemtagmodel.js", "systemtagsmappingcollection.js", "systemtagscollection.js", diff --git a/core/js/systemtags/systemtagsinputfield.js b/core/js/systemtags/systemtagsinputfield.js index ba72d48620..82fd659c72 100644 --- a/core/js/systemtags/systemtagsinputfield.js +++ b/core/js/systemtags/systemtagsinputfield.js @@ -11,39 +11,6 @@ /* global Handlebars */ (function(OC) { - var TEMPLATE = - ''; - - var RESULT_TEMPLATE = - '' + - ' ' + - '{{#if isAdmin}}' + - ' {{{tagMarkup}}}' + - '{{else}}' + - ' {{name}}' + - '{{/if}}' + - '{{#allowActions}}' + - ' ' + - ' ' + - ' ' + - '{{/allowActions}}' + - ''; - - var SELECTION_TEMPLATE = - '{{#if isAdmin}}' + - ' {{{tagMarkup}}}' + - '{{else}}' + - ' {{name}}' + - '{{/if}}'; - - var RENAME_FORM_TEMPLATE = - '
' + - ' ' + - ' ' + - ' {{#if isAdmin}}' + - ' ' + - ' {{/if}}' + - '
'; /** * @class OC.SystemTags.SystemTagsInputField @@ -64,10 +31,7 @@ className: 'systemTagsInputFieldContainer', template: function(data) { - if (!this._template) { - this._template = Handlebars.compile(TEMPLATE); - } - return this._template(data); + return ''; }, /** @@ -141,12 +105,9 @@ var $item = $(ev.target).closest('.systemtags-item'); var tagId = $item.attr('data-id'); var tagModel = this.collection.get(tagId); - if (!this._renameFormTemplate) { - this._renameFormTemplate = Handlebars.compile(RENAME_FORM_TEMPLATE); - } var oldName = tagModel.get('name'); - var $renameForm = $(this._renameFormTemplate({ + var $renameForm = $(OC.SystemTags.Templates['result_form']({ cid: this.cid, name: oldName, deleteTooltip: t('core', 'Delete'), @@ -310,10 +271,7 @@ * @return {string} HTML markup */ _formatDropDownResult: function(data) { - if (!this._resultTemplate) { - this._resultTemplate = Handlebars.compile(RESULT_TEMPLATE); - } - return this._resultTemplate(_.extend({ + return OC.SystemTags.Templates['result'](_.extend({ renameTooltip: t('core', 'Rename'), allowActions: this._allowActions, tagMarkup: this._isAdmin ? OC.SystemTags.getDescriptiveTag(data)[0].innerHTML : null, @@ -328,10 +286,7 @@ * @return {string} HTML markup */ _formatSelection: function(data) { - if (!this._selectionTemplate) { - this._selectionTemplate = Handlebars.compile(SELECTION_TEMPLATE); - } - return this._selectionTemplate(_.extend({ + return OC.SystemTags.Templates['selection'](_.extend({ tagMarkup: this._isAdmin ? OC.SystemTags.getDescriptiveTag(data)[0].innerHTML : null, isAdmin: this._isAdmin }, data)); diff --git a/core/js/systemtags/templates.js b/core/js/systemtags/templates.js new file mode 100644 index 0000000000..0894d64682 --- /dev/null +++ b/core/js/systemtags/templates.js @@ -0,0 +1,74 @@ +(function() { + var template = Handlebars.template, templates = OC.SystemTags.Templates = OC.SystemTags.Templates || {}; +templates['result'] = template({"1":function(container,depth0,helpers,partials,data) { + return " new-item"; +},"3":function(container,depth0,helpers,partials,data) { + var stack1, helper; + + return " " + + ((stack1 = ((helper = (helper = helpers.tagMarkup || (depth0 != null ? depth0.tagMarkup : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"tagMarkup","hash":{},"data":data}) : helper))) != null ? stack1 : "") + + "\n"; +},"5":function(container,depth0,helpers,partials,data) { + var helper; + + return " " + + container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"name","hash":{},"data":data}) : helper))) + + "\n"; +},"7":function(container,depth0,helpers,partials,data) { + var helper; + + return " \n \n \n"; +},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { + var stack1, helper, options, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", buffer = + "\n\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.isAdmin : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.program(5, data, 0),"data":data})) != null ? stack1 : ""); + stack1 = ((helper = (helper = helpers.allowActions || (depth0 != null ? depth0.allowActions : depth0)) != null ? helper : alias2),(options={"name":"allowActions","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data}),(typeof helper === alias3 ? helper.call(alias1,options) : helper)); + if (!helpers.allowActions) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} + if (stack1 != null) { buffer += stack1; } + return buffer + "';\n"; +},"useData":true}); +templates['result_form'] = template({"1":function(container,depth0,helpers,partials,data) { + var helper; + + return " \n"; +},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { + var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return "
\n \n \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.isAdmin : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
\n"; +},"useData":true}); +templates['selection'] = template({"1":function(container,depth0,helpers,partials,data) { + var stack1, helper; + + return " " + + ((stack1 = ((helper = (helper = helpers.tagMarkup || (depth0 != null ? depth0.tagMarkup : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"tagMarkup","hash":{},"data":data}) : helper))) != null ? stack1 : "") + + "\n"; +},"3":function(container,depth0,helpers,partials,data) { + var helper; + + return " " + + container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"name","hash":{},"data":data}) : helper))) + + "\n"; +},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { + var stack1; + + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.isAdmin : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.program(3, data, 0),"data":data})) != null ? stack1 : ""); +},"useData":true}); +})(); \ No newline at end of file diff --git a/core/js/systemtags/templates/result.handlebars b/core/js/systemtags/templates/result.handlebars new file mode 100644 index 0000000000..ce69c8a21f --- /dev/null +++ b/core/js/systemtags/templates/result.handlebars @@ -0,0 +1,13 @@ + + + {{#if isAdmin}} + {{{tagMarkup}}} + {{else}} + {{name}} + {{/if}} + {{#allowActions}} + + + + {{/allowActions}} +'; diff --git a/core/js/systemtags/templates/result_form.handlebars b/core/js/systemtags/templates/result_form.handlebars new file mode 100644 index 0000000000..28fe8c56fe --- /dev/null +++ b/core/js/systemtags/templates/result_form.handlebars @@ -0,0 +1,7 @@ +
+ + + {{#if isAdmin}} + + {{/if}} +
diff --git a/core/js/systemtags/templates/selection.handlebars b/core/js/systemtags/templates/selection.handlebars new file mode 100644 index 0000000000..b006b12974 --- /dev/null +++ b/core/js/systemtags/templates/selection.handlebars @@ -0,0 +1,5 @@ +{{#if isAdmin}} + {{{tagMarkup}}} +{{else}} + {{name}} +{{/if}}