diff --git a/Makefile b/Makefile index 84e11bb0..acdd9dba 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,9 @@ clean: rm -rf $(build_dir) rm -rf node_modules +js-templates: + handlebars -n OCA.AnnouncementCenter.Templates js/templates -f js/templates.js + appstore: clean mkdir -p $(sign_dir) rsync -a \ diff --git a/js/commentstabview.js b/js/commentstabview.js index de412515..3980b125 100644 --- a/js/commentstabview.js +++ b/js/commentstabview.js @@ -11,53 +11,6 @@ /* global Handlebars, escapeHTML */ (function(OC, OCA) { - var TEMPLATE = - '' + - '' + - '' + - ''; - - var EDIT_COMMENT_TEMPLATE = - '
' + - '
' + - ' {{#if avatarEnabled}}' + - '
' + - ' {{/if}}' + - '
{{actorDisplayName}}
' + - '{{#if isEditMode}}' + - ' ' + - '{{/if}}' + - '
' + - '
' + - ' ' + - ' ' + - '{{#if isEditMode}}' + - ' ' + - '{{/if}}' + - ' '+ - '
' + - '
'; - - var COMMENT_TEMPLATE = - '
  • ' + - '
    ' + - ' {{#if avatarEnabled}}' + - '
    ' + - ' {{/if}}' + - '
    {{actorDisplayName}}
    ' + - '{{#if isUserAuthor}}' + - ' ' + - '{{/if}}' + - '
    {{date}}
    ' + - '
    ' + - '
    {{{formattedMessage}}}
    ' + - '{{#if isLong}}' + - '
    ' + - '{{/if}}' + - '
  • '; /** * @memberof OCA.AnnouncementCenter.Comments @@ -86,11 +39,8 @@ }, template: function(params) { - if (!this._template) { - this._template = Handlebars.compile(TEMPLATE); - } var currentUser = OC.getCurrentUser(); - return this._template(_.extend({ + return OCA.AnnouncementCenter.Templates.commentsview(_.extend({ avatarEnabled: this._avatarsEnabled, actorId: currentUser.uid, actorDisplayName: currentUser.displayName @@ -98,11 +48,8 @@ }, editCommentTemplate: function(params) { - if (!this._editCommentTemplate) { - this._editCommentTemplate = Handlebars.compile(EDIT_COMMENT_TEMPLATE); - } var currentUser = OC.getCurrentUser(); - var el = this._editCommentTemplate(_.extend({ + var el = OCA.AnnouncementCenter.Templates.edit_comment(_.extend({ avatarEnabled: this._avatarsEnabled, actorId: currentUser.uid, actorDisplayName: currentUser.displayName, @@ -121,10 +68,6 @@ }, commentTemplate: function(params) { - if (!this._commentTemplate) { - this._commentTemplate = Handlebars.compile(COMMENT_TEMPLATE); - } - params = _.extend({ avatarEnabled: this._avatarsEnabled, editTooltip: t('comments', 'Edit comment'), @@ -138,7 +81,7 @@ params.actorDisplayName = t('comments', '[Deleted user]'); } - return this._commentTemplate(params); + return OCA.AnnouncementCenter.Templates.comment(params); }, getLabel: function() { diff --git a/js/script.js b/js/script.js index ef60ebfc..b32483a4 100644 --- a/js/script.js +++ b/js/script.js @@ -26,47 +26,9 @@ sevenDaysMilliseconds: 7 * 24 * 3600 * 1000, commentsTabView: null, - compiledTemplate: null, - handlebarTemplate: '
    ' + - '

    {{{subject}}}

    ' + - '{{dateRelative}}' + - '
    {{author}}
    ' + - '{{#if isAdmin}}' + - '' + - '{{#if visibilityEveryone}}' + - '' + - '{{else}}' + - '' + - '{{/if}}' + - '' + - '{{/if}}' + - '{{#if comments}}' + - '{{comments}}' + - '{{/if}}' + - '{{#if isAdmin}}' + - '' + - '' + - '' + - '' + - '' + - '{{#if hasNotifications}}' + - '' + - '' + - '' + - '' + - '' + - '{{/if}}' + - '{{/if}}' + - '{{#if message}}' + - '

    {{{message}}}

    ' + - '{{/if}}' + - '
    ' + - '
    ', - init: function() { this.$container = $('#app-content'); this.$content = $('#app-content'); - this.compiledTemplate = Handlebars.compile(this.handlebarTemplate); this.commentsTabView = OCA.AnnouncementCenter.Comments.CommentsTabView; this.commentsTabView.initialize(); @@ -253,7 +215,13 @@ visibilityEveryone: null, visibilityString: null, announcementId: announcement.id, - isAdmin: this.isAdmin + isAdmin: this.isAdmin, + deleteTXT: t('announcementcenter', 'Delete'), + removeNotificationTXT: t('announcementcenter', 'Remove notifications'), + notificationsOffIMG: OC.imagePath('announcementcenter', 'notifications-off.svg'), + deleteIMG: OC.imagePath('core', 'actions/delete.svg'), + placesLinkIMG: OC.imagePath('core', 'places/link.svg'), + placesContactsIMG: OC.imagePath('core', 'places/link.svg') }; if (this.isAdmin) { @@ -268,7 +236,7 @@ } } - var $html = $(this.compiledTemplate(object)); + var $html = $(OCA.AnnouncementCenter.Templates.announcement(object)); $html.find('span.delete-link a').on('click', _.bind(this.deleteAnnouncement, this)); $html.find('span.mute-link a').on('click', _.bind(this.removeNotifications, this)); $html.on('click', _.bind(this._onHighlightAnnouncement, this)); diff --git a/js/templates.js b/js/templates.js new file mode 100644 index 00000000..b08da050 --- /dev/null +++ b/js/templates.js @@ -0,0 +1,182 @@ +(function() { + var template = Handlebars.template, templates = OCA.AnnouncementCenter.Templates = OCA.AnnouncementCenter.Templates || {}; +templates['announcement'] = template({"1":function(container,depth0,helpers,partials,data) { + var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}); + + return " \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.visibilityEveryone : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.program(4, data, 0),"data":data})) != null ? stack1 : "") + + " \n"; +},"2":function(container,depth0,helpers,partials,data) { + var helper; + + return " \n"; +},"4":function(container,depth0,helpers,partials,data) { + var helper; + + return " \n"; +},"6":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return " " + + alias4(((helper = (helper = helpers.comments || (depth0 != null ? depth0.comments : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"comments","hash":{},"data":data}) : helper))) + + "\n"; +},"8":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 \n \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.hasNotifications : depth0),{"name":"if","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"9":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 \n \n"; +},"11":function(container,depth0,helpers,partials,data) { + var stack1, helper; + + return "

    " + + ((stack1 = ((helper = (helper = helpers.message || (depth0 != null ? depth0.message : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"message","hash":{},"data":data}) : helper))) != null ? stack1 : "") + + "

    \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

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

    \n " + + alias4(((helper = (helper = helpers.dateRelative || (depth0 != null ? depth0.dateRelative : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"dateRelative","hash":{},"data":data}) : helper))) + + "\n
    " + + alias4(((helper = (helper = helpers.author || (depth0 != null ? depth0.author : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"author","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 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.comments : depth0),{"name":"if","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.isAdmin : depth0),{"name":"if","hash":{},"fn":container.program(8, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.message : depth0),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n
    \n"; +},"useData":true}); +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) { + var stack1; + + return "
    \n"; +},"6":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))) + + "\""; +},"8":function(container,depth0,helpers,partials,data) { + var helper; + + return " \n"; +},"10":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" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.avatarEnabled : depth0),{"name":"if","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    " + + 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(8, 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(10, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
  • \n"; +},"useData":true}); +templates['commentsview'] = 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}); +templates['edit_comment'] = template({"1":function(container,depth0,helpers,partials,data) { + var helper; + + return "
    \n"; +},"3":function(container,depth0,helpers,partials,data) { + var helper; + + return " \n"; +},"5":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" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.avatarEnabled : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    " + + 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(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n
    \n \n \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.isEditMode : depth0),{"name":"if","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n
    \n
    \n"; +},"useData":true}); +})(); \ No newline at end of file diff --git a/js/templates/announcement.handlebars b/js/templates/announcement.handlebars new file mode 100644 index 00000000..0a2e5294 --- /dev/null +++ b/js/templates/announcement.handlebars @@ -0,0 +1,35 @@ +
    +

    {{{subject}}}

    + {{dateRelative}} +
    {{author}}
    + {{#if isAdmin}} + + {{#if visibilityEveryone}} + + {{else}} + + {{/if}} + + {{/if}} + {{#if comments}} + {{comments}} + {{/if}} + {{#if isAdmin}} + + + + + + {{#if hasNotifications}} + + + + + + {{/if}} + {{/if}} + {{#if message}} +

    {{{message}}}

    + {{/if}} +
    +
    diff --git a/js/templates/comment.handlebars b/js/templates/comment.handlebars new file mode 100644 index 00000000..7188ae0b --- /dev/null +++ b/js/templates/comment.handlebars @@ -0,0 +1,16 @@ +
  • +
    + {{#if avatarEnabled}} +
    + {{/if}} +
    {{actorDisplayName}}
    + {{#if isUserAuthor}} + + {{/if}} +
    {{date}}
    +
    +
    {{{formattedMessage}}}
    + {{#if isLong}} +
    + {{/if}} +
  • diff --git a/js/templates/commentsview.handlebars b/js/templates/commentsview.handlebars new file mode 100644 index 00000000..64a074e5 --- /dev/null +++ b/js/templates/commentsview.handlebars @@ -0,0 +1,6 @@ + + + + diff --git a/js/templates/edit_comment.handlebars b/js/templates/edit_comment.handlebars new file mode 100644 index 00000000..0438ae01 --- /dev/null +++ b/js/templates/edit_comment.handlebars @@ -0,0 +1,19 @@ +
    +
    + {{#if avatarEnabled}} +
    + {{/if}} +
    {{actorDisplayName}}
    + {{#if isEditMode}} + + {{/if}} +
    +
    + + + {{#if isEditMode}} + + {{/if}} + +
    +
    diff --git a/templates/main.php b/templates/main.php index 4213abd2..6031dea5 100644 --- a/templates/main.php +++ b/templates/main.php @@ -6,6 +6,7 @@ \OCP\Util::addScript('oc-backbone-webdav'); script('announcementcenter', [ 'script', + 'templates', 'commentmodel', 'commentcollection', 'commentsummarymodel',