From 168adae009dac6ebed9a2fa14ecc83dbce6b9da9 Mon Sep 17 00:00:00 2001
From: Augier <contact@c-henry.fr>
Date: Sat, 14 Feb 2015 00:17:32 +0100
Subject: [PATCH] Adding help section for chat

---
 app/assets/javascripts/app/views/help_view.js | 35 +++++++++++++++++--
 app/assets/stylesheets/help.css.scss          | 12 +++++++
 app/assets/templates/faq_chat_tpl.jst.hbs     |  6 ++++
 app/assets/templates/help_tpl.jst.hbs         |  6 ++++
 app/controllers/help_controller.rb            | 10 ++++--
 config/locales/diaspora/en.yml                |  5 +++
 spec/javascripts/app/views/help_view_spec.js  | 26 ++++++++++++++
 7 files changed, 94 insertions(+), 6 deletions(-)
 create mode 100644 app/assets/templates/faq_chat_tpl.jst.hbs

diff --git a/app/assets/javascripts/app/views/help_view.js b/app/assets/javascripts/app/views/help_view.js
index ffd773b20d..168715e556 100644
--- a/app/assets/javascripts/app/views/help_view.js
+++ b/app/assets/javascripts/app/views/help_view.js
@@ -9,7 +9,8 @@ app.views.Help = app.views.StaticContentView.extend({
     "click .faq-link-sharing" : "sharing",
     "click .faq-link-posts-and-posting" : "postsAndPosting",
     "click .faq-link-tags": "tags",
-    "click .faq-link-keyboard-shortcuts" : "keyboardShortcuts"
+    "click .faq-link-keyboard-shortcuts" : "keyboardShortcuts",
+    "click .faq-link-chat" :  "chat"
   },
 
   initialize : function() {
@@ -35,6 +36,13 @@ app.views.Help = app.views.StaticContentView.extend({
       }
     };
 
+    this.CHAT_SUBS = {
+      add_contact_roster_a: {
+        toggle_privilege: this.getChatIcons(),
+        contacts_page: this.linkHtml(Routes.contacts_path(), Diaspora.I18n.t('chat.contacts_page'))
+      }
+    };
+
     this.data = {
       title_header: Diaspora.I18n.t( 'title_header' ),
       title_getting_help: Diaspora.I18n.t( 'getting_help.title' ),
@@ -51,7 +59,9 @@ app.views.Help = app.views.StaticContentView.extend({
       title_sharing: Diaspora.I18n.t( 'sharing.title' ),
       title_tags: Diaspora.I18n.t( 'tags.title' ),
       title_keyboard_shortcuts: Diaspora.I18n.t( 'keyboard_shortcuts.title' ),
-      title_miscellaneous: Diaspora.I18n.t( 'miscellaneous.title' )
+      title_miscellaneous: Diaspora.I18n.t( 'miscellaneous.title' ),
+      title_chat: Diaspora.I18n.t( 'chat.title' ),
+      chat_enabled: this.chatEnabled()
     };
 
     return this;
@@ -143,7 +153,7 @@ app.views.Help = app.views.StaticContentView.extend({
   /**
    * Returns The section title whose data-section property equals the given query
    * Returns null if nothing found
-   * @param dataValue Value for the data-section to find
+   * @param data Value for the data-section to find
    * @returns {jQuery}
    */
   findSection: function(data){
@@ -187,8 +197,27 @@ app.views.Help = app.views.StaticContentView.extend({
     e.preventDefault();
   },
 
+  chat: function(e){
+    this.renderStaticSection("chat", "faq_chat", this.CHAT_SUBS);
+    this.menuClicked(e);
+
+    e.preventDefault();
+  },
+
   linkHtml: function(url, text) {
     return "<a href=\"" + url + "\" target=\"_blank\">" + text + "</a>";
+  },
+
+  chatEnabled: function(){
+    return gon.chatEnabled;
+  },
+
+  getChatIcons: function(){
+    return '<div class="help-chat-icons">' +
+           '  <i class="entypo lock-open"></i>' +
+           '  <i class="entypo chat"></i>' +
+           '  <i class="entypo trash"></i>' +
+           '</div>';
   }
 });
 // @license-end
diff --git a/app/assets/stylesheets/help.css.scss b/app/assets/stylesheets/help.css.scss
index f6075d6791..56fde842eb 100644
--- a/app/assets/stylesheets/help.css.scss
+++ b/app/assets/stylesheets/help.css.scss
@@ -91,6 +91,18 @@ ul#help_nav {
       border-radius: 0px 0px 4px 4px;
       background-color: white;
       padding: 10px 20px;
+
+      div.help-chat-icons{
+        text-align: center;
+        font-size: 50px;
+        line-height: 70px;
+
+        i.entypo{
+          color: #bfbfbf;
+
+          &.chat{ color: #000000; }
+        }
+      }
     }
   }
 }
diff --git a/app/assets/templates/faq_chat_tpl.jst.hbs b/app/assets/templates/faq_chat_tpl.jst.hbs
new file mode 100644
index 0000000000..fb3633345c
--- /dev/null
+++ b/app/assets/templates/faq_chat_tpl.jst.hbs
@@ -0,0 +1,6 @@
+<div class='question opened collapsible'>
+    <a class='toggle' href='#'>
+        <h4>{{ add_contact_roster_q }}</h4>
+    </a>
+    <div class='answer hideable'>{{{ add_contact_roster_a }}}</div>
+</div>
\ No newline at end of file
diff --git a/app/assets/templates/help_tpl.jst.hbs b/app/assets/templates/help_tpl.jst.hbs
index 22c198186f..f8f01e7ac7 100644
--- a/app/assets/templates/help_tpl.jst.hbs
+++ b/app/assets/templates/help_tpl.jst.hbs
@@ -68,6 +68,12 @@
             <a href="#" class="section-unselected faq-link" data-section="miscellaneous" data-items="back_to_top photo_albums subscribe_feed diaspora_app">{{ title_miscellaneous }}</a>
             <span class="section-selected">{{ title_miscellaneous }}</span>
           </li>
+          {{#if chat_enabled }}
+          <li>
+            <a href="#" class="section-unselected faq-link-chat" data-section="chat" data-items="add_contact_roster i_m_a_podmin">{{ title_chat }}</a>
+            <span class="section-selected">{{ title_chat }}</span>
+          </li>
+          {{/if}}
         </ul>
       </div>
     </div>
diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb
index 0e3e05f6e6..8d39d3b4a2 100644
--- a/app/controllers/help_controller.rb
+++ b/app/controllers/help_controller.rb
@@ -1,4 +1,8 @@
 class HelpController < ApplicationController
-	before_filter -> { @css_framework = :bootstrap }
-	layout ->(c) { request.format == :mobile ? "application" : "with_header_with_footer" }
-end
+  before_filter -> { @css_framework = :bootstrap }
+  layout -> (c) { request.format == :mobile ? "application" : "with_header_with_footer" }
+
+  def faq
+    gon.chatEnabled = AppConfig.chat.enabled?
+  end
+end
\ No newline at end of file
diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml
index 04d3c29651..b137d13a3e 100644
--- a/config/locales/diaspora/en.yml
+++ b/config/locales/diaspora/en.yml
@@ -449,6 +449,11 @@ en:
       person_multiple_aspects_a: "Yes. Go to your contacts page and click on “My contacts”. For each contact you can use the menu on the right to add them to (or remove them from) as many aspects as you want. Or you can add them to a new aspect (or remove them from an aspect) by clicking the aspect selector button on their profile page. Or you can even just move the pointer over their name where you see it in the stream, and a “hover-card” will appear. You can change the aspects they are in right there."
       delete_aspect_q: "How do I delete an aspect?"
       delete_aspect_a: "In your list of aspects on the left side of the main page, point your mouse at the aspect you want to delete. Click the little “Edit” pencil that appears on the right. Click the “Delete this aspect” button in the box that appears."
+    chat:
+      title: "Chat"
+      contacts_page: "contacts page"
+      add_contact_roster_q: "How do I chat with someone in diaspora*?"
+      add_contact_roster_a: "First, you need to enable chat for one of the aspects that person is in. To do so, go to the %{contacts_page}, select the aspect you want and click on the chat icon to enable chat for the aspect. %{toggle_privilege} You could, if you prefer, create a special aspect called 'Chat' and add the people you want to chat with to that aspect. Once you've done this, open the chat interface and select the person you want to chat with."
     mentions:
       title: "Mentions"
       what_is_a_mention_q: "What is a \"mention\"?"
diff --git a/spec/javascripts/app/views/help_view_spec.js b/spec/javascripts/app/views/help_view_spec.js
index c19567d25d..7a2555a3f2 100644
--- a/spec/javascripts/app/views/help_view_spec.js
+++ b/spec/javascripts/app/views/help_view_spec.js
@@ -134,4 +134,30 @@ describe("app.views.Help", function(){
       });
     });
   });
+
+  describe("chat section", function(){
+    describe("chat enabled", function(){
+      beforeEach(function(){
+        gon.chatEnabled = true;
+        this.view = new app.views.Help();
+        this.view.render();
+      });
+
+      it('should display the chat', function(){
+        expect(this.view.$el.find('a[data-section=chat]').length).toBe(1);
+      });
+    });
+
+    describe("chat disabled", function(){
+      beforeEach(function(){
+        gon.chatEnabled = false;
+        this.view = new app.views.Help();
+        this.view.render();
+      });
+
+      it('should not display the chat', function () {
+        expect(this.view.$el.find('a[data-section=chat]').length).toBe(0);
+      });
+    });
+  });
 });
-- 
GitLab