Commits

nakamura committed f5f69eb

chat.js: display link to archive page

Comments (0)

Files changed (4)

tai/service/static/js/chat.js

     },
 
     templateChannelUserName: Mustache.compile($('#template-channel-user-name').html()),
+    templateArchiveLink: Mustache.compile($('#template-archive-link').html()),
 
     initialize: function() {
         if (!this.model) {
         this.model.on('change:currentChannel', this.openChannel, this);
         this.bookmarks = this.attributes.bookmarks;
         this.bookmarkedId = -1;
+        this.$messagesAndArchiveLinkEl = this.$('#messages-and-archive-link');
+        this.$archiveLinkEl = this.$('#archive-link');
         this.$containerEl = this.$('#message-container');
         this.$namesEl = $('#channel-names-list');
         this.$channelTitle = this.$('#channel-title');
         if (!channel) {
             this.$channelTitle.empty();
             this.$channelTopic.empty();
+            this.$archiveLinkEl.empty();
+            this.$archiveLinkEl.hide();
             this.$containerEl.empty();
             this.$namesEl.empty();
             this.$messageForm.children().attr('disabled', true);
 
         this.$containerEl.empty();
 
+        this.$archiveLinkEl.html(this.templateArchiveLink({name: encodeURIComponent(channel.get('name'))}));
+        this.$archiveLinkEl.hide();
+
         var messages = channel.get('messages');
 
         if (messages.length) {
             view.setUnread();
         }
 
+        if (view.model.get('id') == 0) {
+            // this is first message of this channel.
+            // no need to display link to archive page.
+            this.$archiveLinkEl.hide();
+        } else if (this.$containerEl.children().first().attr('message-id') != 0) {
+            this.$archiveLinkEl.show();
+        }
+
         if (!this.$containerEl.children().length) {
             this.$containerEl.append(view.el);
             return;
     },
 
     isBottom: function() {
-        var el = this.$containerEl[0];
+        var el = this.$messagesAndArchiveLinkEl[0];
         return (el.scrollTop == el.scrollHeight - el.offsetHeight);
     },
 
     scrollToBottom: function(animate) {
-        var el = this.$containerEl[0];
+        var el = this.$messagesAndArchiveLinkEl[0];
         var scrollTopMax = el.scrollHeight - el.offsetHeight;
         if (animate) {
-            this.$containerEl.animate({
+            this.$messagesAndArchiveLinkEl.animate({
                 scrollTop: scrollTopMax
             });
         } else {
-            this.$containerEl.scrollTop(scrollTopMax);
+            this.$messagesAndArchiveLinkEl.scrollTop(scrollTopMax);
         }
     },
 

tai/service/templates/chat.html

                         <a href="#cancel-edit-topic" class="btn btn-small" id="cancel-edit-topic-btn">{{ _('cancel') }}</a>
                     </span>
                 </div>
+                <script type="text/template" id="template-archive-link">
+                    {% raw templateArchiveLink %}
+                </script>
                 <script type="text/template" id="template-priv-message">
                     {% raw templatePrivMessage %}
                 </script>
                 <script type="text/template" id="template-topic-message">
                     {% raw templateTopicMessage %}
                 </script>
-                <div class="app-column" id="message-container">
+                <div class="app-column" id="messages-and-archive-link">
+                    <div id="archive-link" class="message" style="display: none;">
+                    </div>
+                    <div id="message-container">
+                    </div>
                 </div>
                 <div class="input-append" style="display: block;">
                     <form id="message-form">

tai/service/templates/mustach-templates.html

 <a class="channel-name" name="{{ name }}" href="#channel/{{ name }}">{{ name }}</a>
 {{ #unread }}<span class="badge pull-right">{{ unread }}</span>{{ /unread }}
 ''' %}
+{% set templateArchiveLink = '''
+    <div class="message-main">
+        <p class="message-text muted text-center"><a href="''' + reverse_url('ChatArchiveHandler', 'PLACEHOLDER').replace('PLACEHOLDER', '{{ name }}') + '">' + _('Go to Archive page') + '''</a></p>
+    </div>
+''' %}
 {% set templatePrivMessage = '''
     <div class="message-unread-bar" style="display: none;">
     </div>

tai/service/translations/ja.csv

 "click to part from this channel","クリックするとこのチャンネルから離れます"
 "edit topic of this channel","このチャンネルのトピックを編集する"
 
+"Go to archive page","アーカイブページへ"
 "has changed topic to","がトピックを変更しました:"
 
 "Change User Settings","ユーザー設定変更"