From cd7c17482ee9c166daedad14e6bac304de61c9b5 Mon Sep 17 00:00:00 2001
From: Roeland Jago Douma <roeland@famdouma.nl>
Date: Mon, 1 Oct 2018 19:20:32 +0200
Subject: [PATCH] Move systemtags to compiled handlebars

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
---
 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 8dc0e0397aa..96080d12ec1 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 19f361d2dfe..161e4766f3f 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 846ba967ed5..641858ee2ed 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 ba72d486204..82fd659c72e 100644
--- a/core/js/systemtags/systemtagsinputfield.js
+++ b/core/js/systemtags/systemtagsinputfield.js
@@ -11,39 +11,6 @@
 /* global Handlebars */
 
 (function(OC) {
-	var TEMPLATE =
-		'<input class="systemTagsInputField" type="hidden" name="tags" value=""/>';
-
-	var RESULT_TEMPLATE =
-		'<span class="systemtags-item{{#if isNew}} new-item{{/if}}" data-id="{{id}}">' +
-		'    <span class="checkmark icon icon-checkmark"></span>' +
-		'{{#if isAdmin}}' +
-		'    <span class="label">{{{tagMarkup}}}</span>' +
-		'{{else}}' +
-		'    <span class="label">{{name}}</span>' +
-		'{{/if}}' +
-		'{{#allowActions}}' +
-		'    <span class="systemtags-actions">' +
-		'        <a href="#" class="rename icon icon-rename" title="{{renameTooltip}}"></a>' +
-		'    </span>' +
-		'{{/allowActions}}' +
-		'</span>';
-
-	var SELECTION_TEMPLATE =
-		'{{#if isAdmin}}' +
-		'    <span class="label">{{{tagMarkup}}}</span>' +
-		'{{else}}' +
-		'    <span class="label">{{name}}</span>' +
-		'{{/if}}';
-
-	var RENAME_FORM_TEMPLATE =
-		'<form class="systemtags-rename-form">' +
-		'    <label class="hidden-visually" for="{{cid}}-rename-input">{{renameLabel}}</label>' +
-		'    <input id="{{cid}}-rename-input" type="text" value="{{name}}">' +
-		'    {{#if isAdmin}}' +
-		'      <a href="#" class="delete icon icon-delete" title="{{deleteTooltip}}"></a>' +
-		'    {{/if}}' +
-		'</form>';
 
 	/**
 	 * @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 '<input class="systemTagsInputField" type="hidden" name="tags" value=""/>';
 		},
 
 		/**
@@ -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 00000000000..0894d646829
--- /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 "		<span class=\"label\">"
+    + ((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 : "")
+    + "</span>\n";
+},"5":function(container,depth0,helpers,partials,data) {
+    var helper;
+
+  return "		<span class=\"label\">"
+    + 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)))
+    + "</span>\n";
+},"7":function(container,depth0,helpers,partials,data) {
+    var helper;
+
+  return "		<span class=\"systemtags-actions\">\n			<a href=\"#\" class=\"rename icon icon-rename\" title=\""
+    + container.escapeExpression(((helper = (helper = helpers.renameTooltip || (depth0 != null ? depth0.renameTooltip : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"renameTooltip","hash":{},"data":data}) : helper)))
+    + "\"></a>\n		</span>\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 = 
+  "<span class=\"systemtags-item"
+    + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.isNew : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+    + "\" data-id=\""
+    + container.escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"id","hash":{},"data":data}) : helper)))
+    + "\">\n<span class=\"checkmark icon icon-checkmark\"></span>\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 + "</span>';\n";
+},"useData":true});
+templates['result_form'] = template({"1":function(container,depth0,helpers,partials,data) {
+    var helper;
+
+  return "		<a href=\"#\" class=\"delete icon icon-delete\" title=\""
+    + container.escapeExpression(((helper = (helper = helpers.deleteTooltip || (depth0 != null ? depth0.deleteTooltip : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"deleteTooltip","hash":{},"data":data}) : helper)))
+    + "\"></a>\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 "<form class=\"systemtags-rename-form\">\n	 <label class=\"hidden-visually\" for=\""
+    + alias4(((helper = (helper = helpers.cid || (depth0 != null ? depth0.cid : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"cid","hash":{},"data":data}) : helper)))
+    + "-rename-input\">"
+    + alias4(((helper = (helper = helpers.renameLabel || (depth0 != null ? depth0.renameLabel : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"renameLabel","hash":{},"data":data}) : helper)))
+    + "</label>\n	<input id=\""
+    + alias4(((helper = (helper = helpers.cid || (depth0 != null ? depth0.cid : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"cid","hash":{},"data":data}) : helper)))
+    + "-rename-input\" type=\"text\" value=\""
+    + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper)))
+    + "\">\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 : "")
+    + "</form>\n";
+},"useData":true});
+templates['selection'] = template({"1":function(container,depth0,helpers,partials,data) {
+    var stack1, helper;
+
+  return "	<span class=\"label\">"
+    + ((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 : "")
+    + "</span>\n";
+},"3":function(container,depth0,helpers,partials,data) {
+    var helper;
+
+  return "	<span class=\"label\">"
+    + 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)))
+    + "</span>\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 00000000000..ce69c8a21ff
--- /dev/null
+++ b/core/js/systemtags/templates/result.handlebars
@@ -0,0 +1,13 @@
+<span class="systemtags-item{{#if isNew}} new-item{{/if}}" data-id="{{id}}">
+<span class="checkmark icon icon-checkmark"></span>
+	{{#if isAdmin}}
+		<span class="label">{{{tagMarkup}}}</span>
+	{{else}}
+		<span class="label">{{name}}</span>
+	{{/if}}
+	{{#allowActions}}
+		<span class="systemtags-actions">
+			<a href="#" class="rename icon icon-rename" title="{{renameTooltip}}"></a>
+		</span>
+	{{/allowActions}}
+</span>';
diff --git a/core/js/systemtags/templates/result_form.handlebars b/core/js/systemtags/templates/result_form.handlebars
new file mode 100644
index 00000000000..28fe8c56fe2
--- /dev/null
+++ b/core/js/systemtags/templates/result_form.handlebars
@@ -0,0 +1,7 @@
+<form class="systemtags-rename-form">
+	 <label class="hidden-visually" for="{{cid}}-rename-input">{{renameLabel}}</label>
+	<input id="{{cid}}-rename-input" type="text" value="{{name}}">
+	{{#if isAdmin}}
+		<a href="#" class="delete icon icon-delete" title="{{deleteTooltip}}"></a>
+	{{/if}}
+</form>
diff --git a/core/js/systemtags/templates/selection.handlebars b/core/js/systemtags/templates/selection.handlebars
new file mode 100644
index 00000000000..b006b129748
--- /dev/null
+++ b/core/js/systemtags/templates/selection.handlebars
@@ -0,0 +1,5 @@
+{{#if isAdmin}}
+	<span class="label">{{{tagMarkup}}}</span>
+{{else}}
+	<span class="label">{{name}}</span>
+{{/if}}
-- 
GitLab