Kji has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/204307

Change subject: Implemented three-state checkbox mode for selectFromHierarchy.
......................................................................

Implemented three-state checkbox mode for selectFromHierarchy.

Updated css for selectFromHierarchy to more robustly handle selection of 
elements.

Change-Id: I26b6f694e6ce681bdd6f965e576a65374f8e7829

Implemented switch for using three-state checkbox UI display in 
selectFromHierarchy.

Change-Id: I75bfd3e8d4f4ea5bff24498de363a8acd5892cda

Removed stupid logging statement.

Change-Id: Iea8a8298278a5d7e8c20191ac06241fd335e0d45

Implemented the save semantics of three-state mode for selectFromHierarchy.

Change-Id: I2a273d24ff5506e06f05ee17fc8036641ab06cec

Changed the threestate argument to accept just threestate as well as 
threestate=true

Change-Id: I1d7400a4f794cd5b111d3c70c8f28d92384cab17
---
M HierarchySelectFormInput.php
M selectFromHierarchy.css
M selectFromHierarchy.js
3 files changed, 120 insertions(+), 32 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/HierarchyBuilder 
refs/changes/07/204307/1

diff --git a/HierarchySelectFormInput.php b/HierarchySelectFormInput.php
index 73e8707..745727f 100644
--- a/HierarchySelectFormInput.php
+++ b/HierarchySelectFormInput.php
@@ -69,6 +69,20 @@
                        $this->mCollapsed = 'false';
                }
 
+               if ( array_key_exists( 'threestate', $this->mOtherArgs ) ) {
+                       $this->mThreestate = $this->mOtherArgs['threestate'];
+                       if ( $this->mThreestate ) {
+                               $this->mThreestate = 'true';
+                       }
+                       if ( $this->mThreestate !== 'true' && 
$this->mThreestate !== 'false' ) {
+                               $this->mThreestate = null;
+                               return;
+                       }
+               } else {
+                       $this->mThreestate = 'false';
+               }
+
+
                if ( array_key_exists( 'displaynameproperty', $this->mOtherArgs 
) ) {
                        $displaynameproperty = 
$this->mOtherArgs['displaynameproperty'];
                } else {
@@ -104,6 +118,7 @@
                        'isDisabled' => $this->mIsDisabled,
                        'isMandatory' => array_key_exists( 'mandatory', 
$this->mOtherArgs ),
                        'collapsed' => $this->mCollapsed == 'true' ? true : 
false,
+                       'threestate' => $this->mThreestate == 'true' ? true : 
false,
                        'width' => $this->mWidth,
                        'height' => $this->mHeight,
                        'legacyMode' => $HierarchyBuilder_LegacyMode
diff --git a/selectFromHierarchy.css b/selectFromHierarchy.css
index 8080a05..5b6c8d4 100644
--- a/selectFromHierarchy.css
+++ b/selectFromHierarchy.css
@@ -20,7 +20,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-li > a.selectedHierarchyRow {
+/*li > a.selectedHierarchyRow {
     font-style: italic;
     color: green;
 }
@@ -28,6 +28,16 @@
 li > a.unselectedHierarchyRow {
        font-style: normal;
     color: black;
+}*/
+
+li.jstree-checked > a {
+    font-style: italic;
+    color: green;
+}
+                
+li.jstree-undetermined li.jstree-unchecked > a {
+       font-style: normal;
+    color: black;
 }
 
 .scrollableHierarchy {
diff --git a/selectFromHierarchy.js b/selectFromHierarchy.js
index 87ac2b9..8e6a9dc 100644
--- a/selectFromHierarchy.js
+++ b/selectFromHierarchy.js
@@ -78,6 +78,8 @@
                                        return;
                                }
 
+                               var twostate = params.threestate ? false : true;
+
                                var legacyMode = params.legacyMode;
 
                                var selectedComponents = params.selectedItems;
@@ -156,7 +158,7 @@
                                $( jqDivId )
                                        .bind( "loaded.jstree", function( 
event, data ) {
                                                obj.initializeTree( jqDivId, 
params.isDisabled,
-                                                       selectedComponents, 
true, inputId, params.collapsed, legacyMode );
+                                                       selectedComponents, 
true, inputId, params.collapsed, legacyMode, params.threestate );
                                                $( jqDivId )
                                                        .jstree( "open_all" );
                                        } );
@@ -164,7 +166,7 @@
                                $( jqDivId )
                                        .bind( "refresh.jstree", function( 
event, data ) {
                                                obj.initializeTree( jqDivId, 
params.isDisabled,
-                                                       selectedComponents, 
false, inputId, params.collapsed, legacyMode );
+                                                       selectedComponents, 
false, inputId, params.collapsed, legacyMode, params.threestate );
                                        } );
                                
                                $( jqDivId )
@@ -175,7 +177,8 @@
                                                        "icons": false
                                                },
                                                "checkbox": {
-                                                       "two_state": true
+                                                       "two_state": twostate,
+                                                       "three_state": 
params.threestate
                                                },
                                                "types": {
                                                        "types": {
@@ -230,7 +233,7 @@
                         *  hierarchy should start out in collapsed or expanded 
form.
                         */
                        initializeTree: function( jqDivId, isDisabled, 
selectedComponents,
-                               init, inputId, collapsed, legacyMode ) {
+                               init, inputId, collapsed, legacyMode, 
threestate ) {
                                var obj = this;
                                if ( collapsed ) {
                                        $( jqDivId )
@@ -275,7 +278,7 @@
                                                                                
$( this )
                                                                                
.children( "span:first" )
                                                                                
.text();
-                                                                       
obj.checkNode( elementName, inputId, legacyMode );
+                                                                       
obj.checkNode( jqDivId, elementName, inputId, legacyMode, threestate );
                                                                        
obj.processDups( jqDivId, elementName, "check" );
 
                                                                        $( this 
).attr("class", "selectedHierarchyRow");
@@ -289,7 +292,7 @@
                                                                                
$( this )
                                                                                
.children( "span:first" )
                                                                                
.text();
-                                                                       
obj.uncheckNode( elementName, inputId, legacyMode );
+                                                                       
obj.uncheckNode( jqDivId, elementName, inputId, legacyMode, threestate );
                                                                        
obj.processDups( jqDivId, elementName, "uncheck" );
 
                                                                        $( this 
).attr("class", "unselectedHierarchyRow");
@@ -329,21 +332,33 @@
                         * @param {string} inputId The id of the hidden form 
field used to
                         *  store the possibly updated list of selected 
hierarchy rows.
                         */
-                       checkNode: function( elementName, inputId, legacyMode ) 
{
-                               var selectedComponents =
-                                       this.getSelectedHierarchyComponents( 
inputId );
-                               var pageName = legacyMode ? "[[" + elementName 
+ "]]" : elementName;
-                               var curValue = pageName;
-                               if ( selectedComponents.length > 0 ) {
-                                       var index = $.inArray( pageName, 
selectedComponents );
-                                       if ( index === -1 ) {
-                                               selectedComponents.push( 
pageName );
-                                               selectedComponents.sort();
+                       checkNode: function( jqDivId, elementName, inputId, 
legacyMode, threestate ) {
+                               if (threestate) {
+                                       var selectedComponents = [];
+                                       this.computeConciseSelectedComponents( 
$( jqDivId ), selectedComponents, legacyMode );
+                                       selectedComponents = 
$.unique(selectedComponents);
+                                       selectedComponents.sort();
+                                       
+                                       var curValue = selectedComponents.join( 
"," );
+                                       $( "#" + inputId )
+                                               .val( curValue );
+                               } else {
+                                       var selectedComponents =
+                                               
this.getSelectedHierarchyComponents( inputId );
+                                       var pageName = legacyMode ? "[[" + 
elementName + "]]" : elementName;
+                                       var curValue = pageName;
+                                       if ( selectedComponents.length > 0 ) {
+                                               var index = $.inArray( 
pageName, selectedComponents );
+                                               if ( index === -1 ) {
+                                                       
selectedComponents.push( pageName );
+                                                       
selectedComponents.sort();
+                                               }
+                                               curValue = 
selectedComponents.join( "," );
                                        }
-                                       curValue = selectedComponents.join( "," 
);
+                                       $( "#" + inputId )
+                                               .val( curValue );
                                }
-                               $( "#" + inputId )
-                                       .val( curValue );
+
                        },
 
                        /**
@@ -354,20 +369,68 @@
                         * @param {string} inputId The id of the hidden form 
field used to
                         *  store the possibly updated list of selected 
hierarchy rows.
                         */
-                       uncheckNode: function( elementName, inputId, legacyMode 
) {
-                               var selectedComponents =
-                                       this.getSelectedHierarchyComponents( 
inputId );
-                               var pageName = legacyMode ? "[[" + elementName 
+ "]]" : elementName;
-                               var curValue = "";
-                               if ( selectedComponents.length > 0 ) {
-                                       var index = $.inArray( pageName, 
selectedComponents );
-                                       if ( index !== -1 ) {
-                                               selectedComponents.splice( 
index, 1 );
+                       uncheckNode: function( jqDivId, elementName, inputId, 
legacyMode, threestate ) {
+                               if ( threestate ) {
+                                       var selectedComponents = [];
+                                       this.computeConciseSelectedComponents( 
$( jqDivId ), selectedComponents, legacyMode );
+                                       selectedComponents = 
$.unique(selectedComponents);
+                                       selectedComponents.sort();
+                                       
+                                       var curValue = selectedComponents.join( 
"," );
+                                       $( "#" + inputId )
+                                               .val( curValue );
+                               } else {
+                                       var selectedComponents =
+                                               
this.getSelectedHierarchyComponents( inputId );
+                                       var pageName = legacyMode ? "[[" + 
elementName + "]]" : elementName;
+                                       var curValue = "";
+                                       if ( selectedComponents.length > 0 ) {
+                                               var index = $.inArray( 
pageName, selectedComponents );
+                                               if ( index !== -1 ) {
+                                                       
selectedComponents.splice( index, 1 );
+                                               }
+                                               curValue = 
selectedComponents.join( "," );
                                        }
-                                       curValue = selectedComponents.join( "," 
);
+                                       $( "#" + inputId )
+                                               .val( curValue );
                                }
-                               $( "#" + inputId )
-                                       .val( curValue );
+                       },
+
+                       /**
+                        * Recursively processes a jstree hierarchy to find the 
most concise
+                        * description of the selected pages when in 
three-state mode.
+                        *
+                        * This function recursively traverses the tree from 
top to bottom.
+                        * If a node is selected, then all the children MUST be 
selected so
+                        * this node is added to the list of selected items and 
we return.
+                        * Otherwise, this node is not selected and we recurse 
on each child.
+                        * The result is a list of only the most "senior" nodes 
in the
+                        * hierarchy that have been selected.
+                        *
+                        * @param {jquery} $root The jquery object representing 
the root of
+                        *  the current level within the jstree hierarchy.
+                        * @param {array} selected The list that will contain 
the concise
+                        *  set of selected nodes.
+                        * @param {boolean} legacyMode A boolean indicating 
whether the list
+                        *  of selected pages should be stored using legacy 
formatting with
+                        *  [[]] notion or not.
+                        */
+                       computeConciseSelectedComponents: function( $root, 
selected, legacyMode ) {
+                               var that = this;
+
+                               var $cur = $root;
+                               var $children = 
$root.children('ul').children('li');
+
+                               if ( $cur.hasClass('jstree-checked') ) {
+                                       // TODO: handle legacy mode
+                                       var elementName = 
$cur.children('a').children('span:first').text();
+                                       var pageName = legacyMode ? "[[" + 
elementName + "]]" : elementName;
+                                       selected.push( elementName );
+                               } else {
+                                       $children.each( function () {
+                                               
that.computeConciseSelectedComponents( $( this ), selected );
+                                       });
+                               }
                        },
 
                        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/204307
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1d7400a4f794cd5b111d3c70c8f28d92384cab17
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/HierarchyBuilder
Gerrit-Branch: master
Gerrit-Owner: Kji <k...@mitre.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to