From 36e5ca431f4d45ceb296a927440941d0af7f0108 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Sun, 5 Feb 2012 13:40:34 -0800 Subject: [PATCH] replace two more underscore templates with handlebar counterparts [ci skip] --- app/views/templates/status_message.jst | 18 ----- app/views/templates/stream_element.jst | 62 ----------------- .../app/templates/status-message.handlebars | 20 ++++++ .../app/templates/stream-element.handlebars | 66 +++++++++++++++++++ public/javascripts/app/views/content_view.js | 19 +++++- public/javascripts/app/views/post_view.js | 19 +++++- 6 files changed, 118 insertions(+), 86 deletions(-) delete mode 100644 app/views/templates/status_message.jst delete mode 100644 app/views/templates/stream_element.jst create mode 100644 public/javascripts/app/templates/status-message.handlebars create mode 100644 public/javascripts/app/templates/stream-element.handlebars diff --git a/app/views/templates/status_message.jst b/app/views/templates/status_message.jst deleted file mode 100644 index 6e3368359..000000000 --- a/app/views/templates/status_message.jst +++ /dev/null @@ -1,18 +0,0 @@ -<% if(photos.length > 0) { %> -
- - - - <% for(photo in photos) { - if(photo == 0){ continue; } - if(photo == 8){ break; } %> - - - - <% } %> -<% } %> - -
- <%= text %> - <%= o_embed_html %> -
diff --git a/app/views/templates/stream_element.jst b/app/views/templates/stream_element.jst deleted file mode 100644 index bbea574ef..000000000 --- a/app/views/templates/stream_element.jst +++ /dev/null @@ -1,62 +0,0 @@ -
- <% if(author.id != (!!current_user && current_user.id)) { %> - - Ignoreuser - - - <% } else { %> - - - - <% } %> - -
- -
- - - - -
- -
- - - <%= author.name %> - - - - - - - - - - <% if(reshares_count) { %> - - - <%= Diaspora.I18n.t("stream.reshares", {count : reshares_count}) %> - <% } %> - -
- - <% if(text !== null && text.match(/#nsfw/i)) { %> -
-
- <%= Diaspora.I18n.t('stream.nsfw') %> - - <%= Diaspora.I18n.t('stream.show') %> - -
- <% } %> - -
- - <% if(text !== null && text.match(/#nsfw/)) { %> -
- <% } %> - - - -
- -
diff --git a/public/javascripts/app/templates/status-message.handlebars b/public/javascripts/app/templates/status-message.handlebars new file mode 100644 index 000000000..5b846eb1a --- /dev/null +++ b/public/javascripts/app/templates/status-message.handlebars @@ -0,0 +1,20 @@ +{{#if photos.length}} +
+ + + {{#with largePhoto}} + + {{/with}} + + + {{#each smallPhotos}} + + + + {{/each}} +{{/if}} + +
+ {{{text}}} + {{{o_embed_html}}} +
diff --git a/public/javascripts/app/templates/stream-element.handlebars b/public/javascripts/app/templates/stream-element.handlebars new file mode 100644 index 000000000..2169338b7 --- /dev/null +++ b/public/javascripts/app/templates/stream-element.handlebars @@ -0,0 +1,66 @@ +
+ {{#if authorIsCurrentUser}} + + Ignoreuser + + + {{else}} + + + + {{/if}} + +
+ +
+ {{#with author}} + + + + {{/with}} + +
+ +
+ + {{#with author}} + + {{name}} + + {{/with}} + + + + - + + + + {{#if reshares_count}} + - + {{t "stream.reshares" count=reshares_count}} + {{/if}} + +
+ + {{#if nsfw}} +
+
+ {{t "stream.nsfw"}} + + {{t "stream.show"}} + +
+ {{/if}} + +
+ + {{#if nsfw}} +
+ {{/if}} + + + +
+ +
diff --git a/public/javascripts/app/views/content_view.js b/public/javascripts/app/views/content_view.js index 5f593bf3f..220f68ccf 100644 --- a/public/javascripts/app/views/content_view.js +++ b/public/javascripts/app/views/content_view.js @@ -3,7 +3,9 @@ app.views.Content = app.views.StreamObject.extend({ var model = this.model return _.extend(this.defaultPresenter(), { text : app.helpers.textFormatter(model), - o_embed_html : embedHTML(model) + o_embed_html : embedHTML(model), + largePhoto : this.largePhoto(), + smallPhotos : this.smallPhotos() }) function embedHTML(model){ @@ -15,12 +17,23 @@ app.views.Content = app.views.StreamObject.extend({ return data.html || "" } } + }, + + largePhoto : function() { + var photos = this.model.get("photos") + if(!photos || photos.length == 0) { return } + return photos[0] + }, + + smallPhotos : function() { + var photos = this.model.get("photos") + if(!photos || photos.length < 2) { return } + return photos.slice(1,8) } }) app.views.StatusMessage = app.views.Content.extend({ - legacyTemplate : true, - template_name : "#status-message-template" + templateName : "status-message" }); app.views.Reshare = app.views.Content.extend({ diff --git a/public/javascripts/app/views/post_view.js b/public/javascripts/app/views/post_view.js index 1047382bc..6689e48ab 100644 --- a/public/javascripts/app/views/post_view.js +++ b/public/javascripts/app/views/post_view.js @@ -1,7 +1,5 @@ app.views.Post = app.views.StreamObject.extend({ - legacyTemplate : true, - - template_name: "#stream-element-template", + templateName: "stream-element", className : "stream_element loaded", @@ -48,6 +46,13 @@ app.views.Post = app.views.StreamObject.extend({ return new postClass({ model : this.model }); }, + presenter : function() { + return _.extend(this.defaultPresenter(), { + authorIsCurrentUser : this.authorIsCurrentUser(), + nsfw : this.nsfw() + }) + }, + removeNsfwShield: function(evt){ if(evt){ evt.preventDefault(); } @@ -97,5 +102,13 @@ app.views.Post = app.views.StreamObject.extend({ this.$(".comment_box").focus(); return this; + }, + + authorIsCurrentUser : function() { + return this.model.get("author").id != (!!app.user() && app.user().id) + }, + + nsfw : function() { + return this.model.get("text") !== null && this.model.get("text").match(/#nsfw/i) } });