From 10d3076d6b4dc437e9a926d1bd47a657db0c9792 Mon Sep 17 00:00:00 2001
From: manuroe <manu@matrix.org>
Date: Wed, 13 Jan 2016 09:11:56 +0100
Subject: [PATCH] PushRules settings: Display keywords modal dialog

---
 .../views/settings/Notifications.js           | 43 ++++++++++++++++++-
 .../views/settings/Notifications.css          | 16 +++++++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/src/components/views/settings/Notifications.js b/src/components/views/settings/Notifications.js
index c24937bc88..b92a793058 100644
--- a/src/components/views/settings/Notifications.js
+++ b/src/components/views/settings/Notifications.js
@@ -58,6 +58,8 @@ module.exports = React.createClass({
         };
     },
     
+    keywordsDialogDiv: "",
+    
     componentWillMount: function() {
         this._refreshFromServer();
     },
@@ -155,6 +157,19 @@ module.exports = React.createClass({
         }
     },
     
+    onKeywordsClicked: function(event) {
+        var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
+        Modal.createDialog(QuestionDialog, {
+            title: "Keywords",
+            description: this.keywordsDialogDiv,
+            onFinished: function onFinished(should_leave) {
+                if (should_leave) {
+                    // TODO
+                }
+            }
+        });
+    },
+    
     getRule: function(vectorRuleId) {
         for (var i in this.state.vectorPushRules) {
             var rule = this.state.vectorPushRules[i];
@@ -306,7 +321,7 @@ module.exports = React.createClass({
             // it corresponds to all content push rules (stored in self.state.vectorContentRule)
             self.state.vectorPushRules.push({
                 "vectorRuleId": "keywords",
-                "description" : "Messages containing keywords",
+                "description" : (<span>Messages containing <span className="mx_UserNotifSettings_keywords" onClick={ self.onKeywordsClicked }>keywords</span></span>),
                 "state": self.state.vectorContentRules.state,
             });
 
@@ -435,6 +450,32 @@ module.exports = React.createClass({
             );
         }
 
+        // Prepare keywords dialog here, in a render method, else React complains if
+        // it is done later from onKeywordsClicked
+        var keywords = [];
+        for (var i in this.state.vectorContentRules.rules) {
+            var rule = this.state.vectorContentRules.rules[i];
+            keywords.push(rule.pattern);
+        }
+
+        if (keywords.length) {
+            keywords = keywords.join(", ");
+        }
+        else {
+            keywords = "";
+        }
+
+        this.keywordsDialogDiv = (
+            <div>
+                <div className="mx_UserNotifSettings_keywordsLabel">
+                    <label htmlFor="keywords">Enter keywords separated by a comma:</label>
+                </div>
+                <div>
+                    <input id="keywords" ref="keywords" className="mx_UserNotifSettings_keywordsInput" defaultValue={keywords} autoFocus={true} size="64"/>
+                </div>
+            </div>
+        );
+
         // Build the list of keywords rules that have been defined outside Vector UI
         var externalKeyWords = [];
         for (var i in this.state.externalContentRules) {
diff --git a/src/skins/vector/css/vector-web/views/settings/Notifications.css b/src/skins/vector/css/vector-web/views/settings/Notifications.css
index d6d14f8e53..0a50a691ed 100644
--- a/src/skins/vector/css/vector-web/views/settings/Notifications.css
+++ b/src/skins/vector/css/vector-web/views/settings/Notifications.css
@@ -51,3 +51,19 @@ limitations under the License.
 .mx_UserNotifSettings_pushRulesTable tbody th:first-child {
     text-align: left;
 }
+
+.mx_UserNotifSettings_keywords {
+    cursor: pointer;
+    color: #76cfa6;
+}
+
+.mx_UserNotifSettings_keywordsLabel {
+    text-align: left;
+    padding-bottom: 12px;
+}
+
+.mx_UserNotifSettings_keywordsInput {
+    color: #747474;
+    font-weight: 300;
+    font-size: 15px;
+}