Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to compiled handlebars #120

Merged
merged 2 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
63 changes: 3 additions & 60 deletions js/commentstabview.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,6 @@
/* global Handlebars, escapeHTML */

(function(OC, OCA) {
var TEMPLATE =
'<ul class="comments">' +
'</ul>' +
'<div class="emptycontent hidden"><div class="icon-comment"></div>' +
'<p>{{emptyResultLabel}}</p></div>' +
'<input type="button" class="showMore hidden" value="{{moreLabel}}"' +
' name="show-more" id="show-more" />' +
'<div class="loading hidden" style="height: 50px"></div>';

var EDIT_COMMENT_TEMPLATE =
'<div class="newCommentRow comment" data-id="{{id}}">' +
' <div class="authorRow">' +
' {{#if avatarEnabled}}' +
' <div class="avatar" data-username="{{actorId}}"></div>' +
' {{/if}}' +
' <div class="author">{{actorDisplayName}}</div>' +
'{{#if isEditMode}}' +
' <a href="#" class="action delete icon icon-delete has-tooltip" title="{{deleteTooltip}}"></a>' +
'{{/if}}' +
' </div>' +
' <form class="newCommentForm">' +
' <textarea rows="1" class="message" placeholder="{{newMessagePlaceholder}}">{{message}}</textarea>' +
' <input class="submit icon-confirm" type="submit" value="" />' +
'{{#if isEditMode}}' +
' <input class="cancel pull-right" type="button" value="{{cancelText}}" />' +
'{{/if}}' +
' <div class="submitLoading icon-loading-small hidden"></div>'+
' </form>' +
'</div>';

var COMMENT_TEMPLATE =
'<li class="comment{{#if isUnread}} unread{{/if}}{{#if isLong}} collapsed{{/if}}" data-id="{{id}}">' +
' <div class="authorRow">' +
' {{#if avatarEnabled}}' +
' <div class="avatar" {{#if actorId}}data-username="{{actorId}}"{{/if}}> </div>' +
' {{/if}}' +
' <div class="author">{{actorDisplayName}}</div>' +
'{{#if isUserAuthor}}' +
' <a href="#" class="action edit icon icon-rename has-tooltip" title="{{editTooltip}}"></a>' +
'{{/if}}' +
' <div class="date has-tooltip live-relative-timestamp" data-timestamp="{{timestamp}}" title="{{altDate}}">{{date}}</div>' +
' </div>' +
' <div class="message">{{{formattedMessage}}}</div>' +
'{{#if isLong}}' +
' <div class="message-overlay"></div>' +
'{{/if}}' +
'</li>';

/**
* @memberof OCA.AnnouncementCenter.Comments
Expand Down Expand Up @@ -86,23 +39,17 @@
},

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
}, params));
},

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,
Expand All @@ -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'),
Expand All @@ -138,7 +81,7 @@
params.actorDisplayName = t('comments', '[Deleted user]');
}

return this._commentTemplate(params);
return OCA.AnnouncementCenter.Templates.comment(params);
},

getLabel: function() {
Expand Down
44 changes: 4 additions & 40 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,9 @@
sevenDaysMilliseconds: 7 * 24 * 3600 * 1000,
commentsTabView: null,

compiledTemplate: null,
handlebarTemplate: '<div class="section" data-announcement-id="{{{announcementId}}}">' +
'<h2>{{{subject}}}</h2>' +
'<span class="has-tooltip live-relative-timestamp" data-timestamp="{{timestamp}}" title="{{dateFormat}}">{{dateRelative}}</span>' +
'<span class="avatar-name-wrapper" data-user="{{authorId}}"><div class="avatar" data-user="{{authorId}}" data-user-display-name="{{author}}"></div><strong>{{author}}</strong></span>' +
'{{#if isAdmin}}' +
'<span class="visibility has-tooltip" title="{{{visibilityString}}}">' +
'{{#if visibilityEveryone}}' +
'<img src="' + OC.imagePath('core', 'places/link') + '">' +
'{{else}}' +
'<img src="' + OC.imagePath('core', 'places/contacts') + '">' +
'{{/if}}' +
'</span>' +
'{{/if}}' +
'{{#if comments}}' +
'<span class="comment-details" data-count="{{num_comments}}">{{comments}}</span>' +
'{{/if}}' +
'{{#if isAdmin}}' +
'<span class="delete-link has-tooltip" title="' + t('announcementcenter', 'Delete') + '">' +
'<a href="#" data-announcement-id="{{{announcementId}}}">' +
'<img class="svg" src="' + OC.imagePath('core', 'actions/delete') + '" alt=""/>' +
'</a>' +
'</span>' +
'{{#if hasNotifications}}' +
'<span class="mute-link has-tooltip" title="' + t('announcementcenter', 'Remove notifications') + '">' +
'<a href="#" data-announcement-id="{{{announcementId}}}">' +
'<img class="svg" src="' + OC.imagePath('announcementcenter', 'notifications-off.svg') + '" alt=""/>' +
'</a>' +
'</span>' +
'{{/if}}' +
'{{/if}}' +
'{{#if message}}' +
'<br /><br /><p>{{{message}}}</p>' +
'{{/if}}' +
'</div>' +
'<hr />',

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();
Expand Down Expand Up @@ -253,7 +215,9 @@
visibilityEveryone: null,
visibilityString: null,
announcementId: announcement.id,
isAdmin: this.isAdmin
isAdmin: this.isAdmin,
deleteTXT: t('announcementcenter', 'Delete'),
removeNotificationTXT: t('announcementcenter', 'Remove notifications')
};

if (this.isAdmin) {
Expand All @@ -268,7 +232,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));
Expand Down
Loading