From d281f2625d0896f9231d0987f7a752c01e73e6b6 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 1 Oct 2018 19:11:22 +0200 Subject: Move Comments to compiled handlebars Signed-off-by: Roeland Jago Douma --- apps/comments/js/commentstabview.js | 59 +-------------- apps/comments/js/merged.json | 1 + apps/comments/js/templates.js | 87 ++++++++++++++++++++++ apps/comments/js/templates/comment.handlebars | 15 ++++ apps/comments/js/templates/edit_comment.handlebars | 16 ++++ apps/comments/js/templates/view.handlebars | 6 ++ 6 files changed, 128 insertions(+), 56 deletions(-) create mode 100644 apps/comments/js/templates.js create mode 100644 apps/comments/js/templates/comment.handlebars create mode 100644 apps/comments/js/templates/edit_comment.handlebars create mode 100644 apps/comments/js/templates/view.handlebars (limited to 'apps') diff --git a/apps/comments/js/commentstabview.js b/apps/comments/js/commentstabview.js index 28382c8b67e..35e73d3f4a6 100644 --- a/apps/comments/js/commentstabview.js +++ b/apps/comments/js/commentstabview.js @@ -11,49 +11,6 @@ /* global Handlebars, escapeHTML */ (function(OC, OCA) { - var TEMPLATE = - '' + - '' + - '' + - ''; - - var EDIT_COMMENT_TEMPLATE = - '<{{tag}} class="newCommentRow comment" data-id="{{id}}">' + - '
' + - '
' + - '
{{actorDisplayName}}
' + - '{{#if isEditMode}}' + - '
' + - ' ' + - '
' + - '{{/if}}' + - '
' + - '
' + - '
{{message}}
' + - ' ' + - ' '+ - '
' + - ''; - - var COMMENT_TEMPLATE = - '
  • ' + - '
    ' + - '
    ' + - '
    {{actorDisplayName}}
    ' + - '{{#if isUserAuthor}}' + - ' ' + - ' ' + - '{{/if}}' + - '
    {{date}}
    ' + - '
    ' + - '
    {{{formattedMessage}}}
    ' + - '{{#if isLong}}' + - '
    ' + - '{{/if}}' + - '
  • '; /** * @memberof OCA.Comments @@ -93,22 +50,16 @@ }, template: function(params) { - if (!this._template) { - this._template = Handlebars.compile(TEMPLATE); - } var currentUser = OC.getCurrentUser(); - return this._template(_.extend({ + return OCA.Comments.Templates['view'](_.extend({ actorId: currentUser.uid, actorDisplayName: currentUser.displayName }, params)); }, editCommentTemplate: function(params) { - if (!this._editCommentTemplate) { - this._editCommentTemplate = Handlebars.compile(EDIT_COMMENT_TEMPLATE); - } var currentUser = OC.getCurrentUser(); - return this._editCommentTemplate(_.extend({ + return OCA.Comments.Templates['edit_comment'](_.extend({ actorId: currentUser.uid, actorDisplayName: currentUser.displayName, newMessagePlaceholder: t('comments', 'New comment …'), @@ -119,10 +70,6 @@ }, commentTemplate: function(params) { - if (!this._commentTemplate) { - this._commentTemplate = Handlebars.compile(COMMENT_TEMPLATE); - } - params = _.extend({ editTooltip: t('comments', 'Edit comment'), isUserAuthor: OC.getCurrentUser().uid === params.actorId, @@ -135,7 +82,7 @@ params.actorDisplayName = t('comments', '[Deleted user]'); } - return this._commentTemplate(params); + return OCA.Comments.Templates['comment'](params); }, getLabel: function() { diff --git a/apps/comments/js/merged.json b/apps/comments/js/merged.json index d5b2b882334..8f40b5621a6 100644 --- a/apps/comments/js/merged.json +++ b/apps/comments/js/merged.json @@ -1,5 +1,6 @@ [ "app.js", + "templates.js", "commentmodel.js", "commentcollection.js", "commentsummarymodel.js", diff --git a/apps/comments/js/templates.js b/apps/comments/js/templates.js new file mode 100644 index 00000000000..90ded7fe4e5 --- /dev/null +++ b/apps/comments/js/templates.js @@ -0,0 +1,87 @@ +(function() { + var template = Handlebars.template, templates = OCA.Comments.Templates = OCA.Comments.Templates || {}; +templates['comment'] = template({"1":function(container,depth0,helpers,partials,data) { + return " unread"; +},"3":function(container,depth0,helpers,partials,data) { + return " collapsed"; +},"5":function(container,depth0,helpers,partials,data) { + return " currentUser"; +},"7":function(container,depth0,helpers,partials,data) { + var helper; + + return "data-username=\"" + + container.escapeExpression(((helper = (helper = helpers.actorId || (depth0 != null ? depth0.actorId : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"actorId","hash":{},"data":data}) : helper))) + + "\""; +},"9":function(container,depth0,helpers,partials,data) { + return " \n
    \n"; +},"11":function(container,depth0,helpers,partials,data) { + 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
    " + + alias4(((helper = (helper = helpers.actorDisplayName || (depth0 != null ? depth0.actorDisplayName : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"actorDisplayName","hash":{},"data":data}) : helper))) + + "
    \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.isUserAuthor : depth0),{"name":"if","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    " + + alias4(((helper = (helper = helpers.date || (depth0 != null ? depth0.date : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"date","hash":{},"data":data}) : helper))) + + "
    \n
    \n
    " + + ((stack1 = ((helper = (helper = helpers.formattedMessage || (depth0 != null ? depth0.formattedMessage : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"formattedMessage","hash":{},"data":data}) : helper))) != null ? stack1 : "") + + "
    \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.isLong : depth0),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
  • \n"; +},"useData":true}); +templates['edit_comment'] = template({"1":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, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return "<" + + alias4(((helper = (helper = helpers.tag || (depth0 != null ? depth0.tag : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"tag","hash":{},"data":data}) : helper))) + + " class=\"newCommentRow comment\" data-id=\"" + + alias4(((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
    \n
    \n
    " + + alias4(((helper = (helper = helpers.actorDisplayName || (depth0 != null ? depth0.actorDisplayName : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"actorDisplayName","hash":{},"data":data}) : helper))) + + "
    \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.isEditMode : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n
    \n
    " + + alias4(((helper = (helper = helpers.message || (depth0 != null ? depth0.message : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"message","hash":{},"data":data}) : helper))) + + "
    \n \n
    '+\n
    \n'\n"; +},"useData":true}); +templates['view'] = 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

    " + + alias4(((helper = (helper = helpers.emptyResultLabel || (depth0 != null ? depth0.emptyResultLabel : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"emptyResultLabel","hash":{},"data":data}) : helper))) + + "

    \n\n
    '\n"; +},"useData":true}); +})(); \ No newline at end of file diff --git a/apps/comments/js/templates/comment.handlebars b/apps/comments/js/templates/comment.handlebars new file mode 100644 index 00000000000..c1a1091a4e0 --- /dev/null +++ b/apps/comments/js/templates/comment.handlebars @@ -0,0 +1,15 @@ +
  • +
    +
    +
    {{actorDisplayName}}
    + {{#if isUserAuthor}} + + + {{/if}} +
    {{date}}
    +
    +
    {{{formattedMessage}}}
    + {{#if isLong}} +
    + {{/if}} +
  • diff --git a/apps/comments/js/templates/edit_comment.handlebars b/apps/comments/js/templates/edit_comment.handlebars new file mode 100644 index 00000000000..05f89ec598a --- /dev/null +++ b/apps/comments/js/templates/edit_comment.handlebars @@ -0,0 +1,16 @@ +<{{tag}} class="newCommentRow comment" data-id="{{id}}"> +
    +
    +
    {{actorDisplayName}}
    + {{#if isEditMode}} +
    + +
    + {{/if}} +
    +
    +
    {{message}}
    + + '+ +
    +' diff --git a/apps/comments/js/templates/view.handlebars b/apps/comments/js/templates/view.handlebars new file mode 100644 index 00000000000..5f52a42861d --- /dev/null +++ b/apps/comments/js/templates/view.handlebars @@ -0,0 +1,6 @@ + + + +' -- cgit v1.2.3