[Groonga-commit] groonga/gcs-console [master] Avoid invalid index options are chosen

Back to archive index

Yoji SHIDARA null+****@clear*****
Tue Dec 11 13:22:19 JST 2012


Yoji SHIDARA	2012-12-11 13:22:19 +0900 (Tue, 11 Dec 2012)

  New Revision: 67d452c6bb0a3bbc868c40fd43dd500bb3008991
  https://github.com/groonga/gcs-console/commit/67d452c6bb0a3bbc868c40fd43dd500bb3008991

  Log:
    Avoid invalid index options are chosen

  Added files:
    public/js/domain-index-fields.js
  Modified files:
    views/domain-index-fields.jade
    views/layout.jade

  Added: public/js/domain-index-fields.js (+63 -0) 100644
===================================================================
--- /dev/null
+++ public/js/domain-index-fields.js    2012-12-11 13:22:19 +0900 (ee4810a)
@@ -0,0 +1,63 @@
+jQuery(document).ready(function($) {
+  function IndexFieldsOptionsViewModel() {
+    var self = this;
+
+    /* observers */
+    this.chosenType = ko.observable();
+    this.searchChecked = ko.observable();
+    this.facetChecked = ko.observable();
+    this.resultChecked = ko.observable();
+
+    /* treat choosable options for each type */
+    this.searchChoosable = ko.computed(function() {
+      return this.chosenType() === 'literal';
+    }, this);
+    this.facetChoosable = ko.computed(function() {
+      return this.chosenType() !== 'uint';
+    }, this);
+    this.resultChoosable = ko.computed(function() {
+      return this.chosenType() !== 'uint';
+    }, this);
+
+    /* set initial options for each type */
+    this.chosenType.subscribe(function(newType) {
+      switch (newType) {
+        case 'text':
+          self.searchChecked(true);
+          self.facetChecked(false);
+          self.resultChecked(false);
+          break;
+        case 'literal':
+          self.searchChecked(false);
+          self.facetChecked(false);
+          self.resultChecked(false);
+          break;
+        case 'uint':
+          self.searchChecked(true);
+          self.facetChecked(true);
+          self.resultChecked(true);
+          break;
+      }
+    });
+
+    /* 'facet' and 'result' are exclusive except for uint */
+    this.facetChecked.subscribe(function(facetChecked) {
+      if (self.chosenType() === 'uint') {
+        return;
+      }
+      if (facetChecked) {
+        self.resultChecked(false);
+      }
+    });
+    this.resultChecked.subscribe(function(resultChecked) {
+      if (self.chosenType() === 'uint') {
+        return;
+      }
+      if (resultChecked) {
+        self.facetChecked(false);
+      }
+    });
+  }
+
+  ko.applyBindings(new IndexFieldsOptionsViewModel());
+});

  Modified: views/domain-index-fields.jade (+7 -4)
===================================================================
--- views/domain-index-fields.jade    2012-12-11 13:21:24 +0900 (414003a)
+++ views/domain-index-fields.jade    2012-12-11 13:22:19 +0900 (39ac681)
@@ -1,5 +1,8 @@
 extends domain
 
+block head
+  script(src='/js/domain-index-fields.js')
+
 block domain-content
   h2 Index Fields
   if indexFields.length > 0
@@ -56,22 +59,22 @@ block domain-content
       .control-group
         label.control-label Type
         .controls
-          select(type="text", name="type")
+          select(type="text", name="type", data-bind='value: chosenType')
             option(value="text") text
             option(value="literal") literal
             option(value="uint") uint
       .control-group
         label.control-label Search
         .controls
-          input(type="checkbox", name="search")
+          input(type="checkbox", name="search", data-bind='enable: searchChoosable, checked: searchChecked')
       .control-group
         label.control-label Facet
         .controls
-          input(type="checkbox", name="facet")
+          input(type="checkbox", name="facet", data-bind='enable: facetChoosable, checked: facetChecked')
       .control-group
         label.control-label Result
         .controls
-          input(type="checkbox", name="result")
+          input(type="checkbox", name="result", data-bind='enable: resultChoosable, checked: resultChecked')
       .control-group
         .controls
           button.btn(type="submit").btn-primary Create

  Modified: views/layout.jade (+1 -0)
===================================================================
--- views/layout.jade    2012-12-11 13:21:24 +0900 (0a5e5e0)
+++ views/layout.jade    2012-12-11 13:22:19 +0900 (eb426a3)
@@ -7,6 +7,7 @@ html
     script(src='/js/jquery-1.8.3.min.js')
     script(src='/js/knockout-2.2.0.js')
     script(src='/js/bootstrap.min.js')
+    block head
   body
     .navbar.navbar-fixed-top
       .navbar-inner
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index