Move systemtags to compiled handlebars

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-10-01 19:20:32 +02:00
parent d281f2625d
commit cd7c17482e
No known key found for this signature in database
GPG Key ID: F941078878347C0C
8 changed files with 108 additions and 49 deletions

View File

@ -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

View File

@ -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",

View File

@ -1,5 +1,6 @@
[
"systemtags.js",
"templates.js",
"systemtagmodel.js",
"systemtagsmappingcollection.js",
"systemtagscollection.js",

View File

@ -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));

View File

@ -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});
})();

View File

@ -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>';

View File

@ -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>

View File

@ -0,0 +1,5 @@
{{#if isAdmin}}
<span class="label">{{{tagMarkup}}}</span>
{{else}}
<span class="label">{{name}}</span>
{{/if}}