From e266d20c2cca235250690025b7ca7ce1e8a0b735 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 30 Oct 2018 11:58:35 +0100 Subject: [PATCH 1/2] Move to compiled handlebars Signed-off-by: Roeland Jago Douma --- Makefile | 3 + js/admin.js | 28 +++++-- js/templates.js | 151 +++++++++++++++++++++++++++++++++++ js/templates/icon.handlebars | 7 ++ js/templates/site.handlebars | 85 ++++++++++++++++++++ templates/settings.php | 97 +--------------------- 6 files changed, 268 insertions(+), 103 deletions(-) create mode 100644 js/templates.js create mode 100644 js/templates/icon.handlebars create mode 100644 js/templates/site.handlebars diff --git a/Makefile b/Makefile index 4f89463c..a4ac0de7 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,9 @@ create-tag: git tag -s -a v$(version) -m "Tagging the $(version) release." git push origin v$(version) +js-templates: + handlebars -n OCA.External.Templates js/templates -f js/templates.js + clean: rm -rf $(build_dir) rm -rf node_modules diff --git a/js/admin.js b/js/admin.js index 83efce4f..7c755c33 100644 --- a/js/admin.js +++ b/js/admin.js @@ -93,8 +93,21 @@ $list: null, - _compiledSiteTemplate: null, - _compiledIconTemplate: null, + _renderSite: function(data) { + data.nameTXT = t('external', 'Name'); + data.urlTXT = t('external', 'URL'); + data.languageTXT = t('external', 'Language'); + data.groupsTXT = t('external', 'Groups'); + data.devicesTXT = t('external', 'Devices'); + data.iconTXT = t('external', 'Icon'); + data.positionTXT = t('external', 'Position'); + data.redirectTXT = t('external', 'Redirect'); + data.removeSiteTXT = t('external', 'Remove site') + data.noEmbedTXT = t('external', 'This site does not allow embedding'); + data.deleteIMG = OC.imagePath('core', 'actions/delete.svg'); + + return OCA.External.Templates.site(data); + }, init: function() { var self = this; @@ -103,7 +116,7 @@ $('#add_external_site').click(function(e) { e.preventDefault(); - var $el = $(self._compiledSiteTemplate({ + var $el = $(this._renderSite({ id: 'new-' + Date.now(), name: t('external', 'New site'), icon: 'external.svg', @@ -115,8 +128,6 @@ $el.find('.options').removeClass('hidden'); self.$list.append($el); }); - this._compiledSiteTemplate = Handlebars.compile($('#site-template').html()); - this._compiledIconTemplate = Handlebars.compile($('#icon-template').html()); this.load(); }, @@ -138,7 +149,7 @@ self.availableDevices = response.ocs.data.devices; if (response.ocs.data.sites.length === 0) { - var $el = $(self._compiledSiteTemplate({ + var $el = $(self._renderSite({ id: 'undefined' })); self._attachEvents($el); @@ -154,7 +165,7 @@ var self = this; _.each(this._sites.models, function(site) { - var $el = $(self._compiledSiteTemplate(site.attributes)); + var $el = $(this._renderSite(site.attributes)); self._attachEvents($el); self.$list.append($el); }); @@ -287,8 +298,9 @@ return; } + data.deleteTXT = t('external', 'Delete icon'); - var $row = $(self._compiledIconTemplate(data)); + var $row = $(OCA.External.Templates.icon(data)); self._attachEventsIcon($row); $table.append($row); icons.push(data); diff --git a/js/templates.js b/js/templates.js new file mode 100644 index 00000000..72b8b263 --- /dev/null +++ b/js/templates.js @@ -0,0 +1,151 @@ +(function() { + var template = Handlebars.template, templates = OCA.External.Templates = OCA.External.Templates || {}; +templates['icon'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return "
  • \n
    \n \n
    \n " + + 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 \n
  • \n"; +},"useData":true}); +templates['site'] = template({"1":function(container,depth0,helpers,partials,data,blockParams,depths) { + var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {}); + + return ((stack1 = helpers["if"].call(alias1,(helpers.isSelected || (depth0 && depth0.isSelected) || helpers.helperMissing).call(alias1,(depth0 != null ? depth0.code : depth0),(depths[1] != null ? depths[1].lang : depths[1]),{"name":"isSelected","hash":{},"data":data}),{"name":"if","hash":{},"fn":container.program(2, data, 0, blockParams, depths),"inverse":container.program(4, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); +},"2":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return " \n"; +},"4":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return " \n"; +},"6":function(container,depth0,helpers,partials,data,blockParams,depths) { + var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {}); + + return ((stack1 = helpers["if"].call(alias1,(helpers.isSelected || (depth0 && depth0.isSelected) || helpers.helperMissing).call(alias1,(depth0 != null ? depth0.device : depth0),(depths[1] != null ? depths[1].device : depths[1]),{"name":"isSelected","hash":{},"data":data}),{"name":"if","hash":{},"fn":container.program(7, data, 0, blockParams, depths),"inverse":container.program(9, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); +},"7":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return " \n"; +},"9":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return " \n"; +},"11":function(container,depth0,helpers,partials,data,blockParams,depths) { + var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {}); + + return ((stack1 = helpers["if"].call(alias1,(helpers.isSelected || (depth0 && depth0.isSelected) || helpers.helperMissing).call(alias1,(depth0 != null ? depth0.icon : depth0),(depths[1] != null ? depths[1].icon : depths[1]),{"name":"isSelected","hash":{},"data":data}),{"name":"if","hash":{},"fn":container.program(12, data, 0, blockParams, depths),"inverse":container.program(14, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); +},"12":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return " \n"; +},"14":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return " \n"; +},"16":function(container,depth0,helpers,partials,data,blockParams,depths) { + var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {}); + + return ((stack1 = helpers["if"].call(alias1,(helpers.isSelected || (depth0 && depth0.isSelected) || helpers.helperMissing).call(alias1,(depth0 != null ? depth0.type : depth0),(depths[1] != null ? depths[1].type : depths[1]),{"name":"isSelected","hash":{},"data":data}),{"name":"if","hash":{},"fn":container.program(17, data, 0, blockParams, depths),"inverse":container.program(19, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); +},"17":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return " \n"; +},"19":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return " \n"; +},"21":function(container,depth0,helpers,partials,data) { + return " checked=\"checked\""; +},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { + var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return "
  • \n \n \n \n\n
    \n
    \n \n
    \n\n
    \n \n
    \n\n
    \n \n
    \n\n
    \n \n
    \n\n
    \n \n
    \n\n
    \n \n
    \n\n
    " + + alias4(((helper = (helper = helpers.removeSiteTXT || (depth0 != null ? depth0.removeSiteTXT : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"removeSiteTXT","hash":{},"data":data}) : helper))) + + "
    \n
    \n
  • \n"; +},"useData":true,"useDepths":true}); +})(); \ No newline at end of file diff --git a/js/templates/icon.handlebars b/js/templates/icon.handlebars new file mode 100644 index 00000000..7c826fd3 --- /dev/null +++ b/js/templates/icon.handlebars @@ -0,0 +1,7 @@ +
  • +
    + +
    + {{name}} + +
  • diff --git a/js/templates/site.handlebars b/js/templates/site.handlebars new file mode 100644 index 00000000..332b3ee4 --- /dev/null +++ b/js/templates/site.handlebars @@ -0,0 +1,85 @@ +
  • + + + + + +
  • diff --git a/templates/settings.php b/templates/settings.php index eec8b1fd..d20096af 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -26,6 +26,7 @@ style('external', 'style'); script('external', 'admin'); script('settings', 'apps'); +script('external', 'templates'); /** @var array $_ */ /** @var \OCP\IL10N $l */ @@ -42,102 +43,8 @@ - -

    From 663edbd78b0d0c06c26b7cf45593d0b9b93e42d9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Nov 2018 11:03:52 +0100 Subject: [PATCH 2/2] Fix rendering of sites Signed-off-by: Joas Schilling --- js/admin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/admin.js b/js/admin.js index 7c755c33..19da3e19 100644 --- a/js/admin.js +++ b/js/admin.js @@ -116,7 +116,7 @@ $('#add_external_site').click(function(e) { e.preventDefault(); - var $el = $(this._renderSite({ + var $el = $(self._renderSite({ id: 'new-' + Date.now(), name: t('external', 'New site'), icon: 'external.svg', @@ -165,7 +165,7 @@ var self = this; _.each(this._sites.models, function(site) { - var $el = $(this._renderSite(site.attributes)); + var $el = $(self._renderSite(site.attributes)); self._attachEvents($el); self.$list.append($el); });