- } else {
- currState = this.root.checkbox;
- }
- } else { // a valid dojo.store.item
- currState = this.store.getValue(storeItem, this.checkboxIdent);
- if( currState == undefined && this.checkboxAll) {
- this._setCheckboxState( storeItem, this.checkboxState );
- currState = this.checkboxState;
- }
- } */
-
- currState = this.store.getValue(storeItem, this.checkboxIdent);
- if( currState == undefined && this.checkboxAll) {
- this._setCheckboxState( storeItem, this.checkboxState );
- currState = this.checkboxState;
- }
-
- return currState; // the current state of the checkbox (true/false or undefined)
- },
-
- _setCheckboxState: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) {
- // summary:
- // Set/update the checkbox state on the dojo.data store.
- // description:
- // Set/update the checkbox state on the dojo.data.store. Retreive the current
- // state of the checkbox and validate if an update is required, this will keep
- // update events to a minimum. On completion a 'onCheckboxChange' event is
- // triggered.
- // If the current state is undefined (ie: no checkbox attribute specified for
- // this dojo.data.item) the 'checkboxAll' attribute is checked to see if one
- // needs to be created. In case of the root the 'checkboxRoot' attribute is checked.
- // NOTE: the store.setValue function will create the 'checkbox' attribute for the
- // item if none exists.
- // storeItem:
- // The item in the dojo.data.store whos checkbox state is updated.
- // newState:
- // The new state of the checkbox: true or false
- // example:
- // | model.setCheckboxState(item, true);
- //
- var stateChanged = true;
-
- if( storeItem != this.root ) {
- var currState = this.store.getValue(storeItem, this.checkboxIdent);
- if( currState != newState && ( currState !== undefined || this.checkboxAll ) ) {
- this.store.setValue(storeItem, this.checkboxIdent, newState);
- } else {
- stateChanged = false; // No changes to the checkbox
- }
- } else { // Tree root instance
- if( this.root.checkbox != newState && ( this.root.checkbox !== undefined || this.checkboxRoot ) ) {
- this.root.checkbox = newState;
- } else {
- stateChanged = false;
- }
- }
- if( stateChanged ) { // In case of any changes trigger the update event.
- this.onCheckboxChange(storeItem);
- }
- return stateChanged;
- },
-
- _updateChildCheckbox: function(/*dojo.data.Item*/ parentItem, /*Boolean*/ newState ) {
- // summary:
- // Set all child checkboxes to true/false depending on the parent checkbox state.
- // description:
- // If a parent checkbox changes state, all child and grandchild checkboxes will be
- // updated to reflect the change. For example, if the parent state is set to true,
- // all child and grandchild checkboxes will receive that same 'true' state.
- // If a child checkbox changes state and has multiple parent, all of its parents
- // need to be re-evaluated.
- // parentItem:
- // The parent dojo.data.item whos child/grandchild checkboxes require updating.
- // newState:
- // The new state of the checkbox: true or false
- //
-
- if( this.mayHaveChildren( parentItem )) {
- this.getChildren( parentItem, dojo.hitch( this,
- function( children ) {
- dojo.forEach( children, function(child) {
- if( this._setCheckboxState(child, newState) ) {
- var parents = this._getParentsItem(child);
- if( parents.length > 1 ) {
- this._updateParentCheckbox( child, newState );
- }
+ },
+ getCheckedItems: function() {
+ var items = this.store._arrayOfAllItems;
+ var result = [];
+
+ for (var i = 0; i < items.length; i++) {
+ if (this.store.getValue(items[i], 'checkbox'))
+ result.push(items[i]);
+ }
+
+ return result;
+ },
+
+ getCheckboxState: function(/*dojo.data.Item*/ storeItem) {
+ // summary:
+ // Get the current checkbox state from the dojo.data.store.
+ // description:
+ // Get the current checkbox state from the dojo.data store. A checkbox can have three
+ // different states: true, false or undefined. Undefined in this context means no
+ // checkbox identifier (checkboxIdent) was found in the dojo.data store. Depending on
+ // the checkbox attributes as specified above the following will take place:
+ // a) If the current checkbox state is undefined and the checkbox attribute 'checkboxAll' or
+ // 'checkboxRoot' is true one will be created and the default state 'checkboxState' will
+ // be applied.
+ // b) If the current state is undefined and 'checkboxAll' is false the state undefined remains
+ // unchanged and is returned. This will prevent any tree node from creating a checkbox.
+ //
+ // storeItem:
+ // The item in the dojo.data.store whos checkbox state is returned.
+ // example:
+ // | var currState = model.getCheckboxState(item);
+ //
+ var currState = undefined;
+
+ // Special handling required for the 'fake' root entry (the root is NOT a dojo.data.item).
+ // this stuff is only relevant for Forest store -fox
+ /* if ( storeItem == this.root ) {
+ if( typeof(storeItem.checkbox) == "undefined" ) {
+ this.root.checkbox = undefined; // create a new checbox reference as undefined.
+ if( this.checkboxRoot ) {
+ currState = this.root.checkbox = this.checkboxState;
+ }
+ } else {
+ currState = this.root.checkbox;
+ }
+ } else { // a valid dojo.store.item
+ currState = this.store.getValue(storeItem, this.checkboxIdent);
+ if( currState == undefined && this.checkboxAll) {
+ this._setCheckboxState( storeItem, this.checkboxState );
+ currState = this.checkboxState;
+ }
+ } */
+
+ currState = this.store.getValue(storeItem, this.checkboxIdent);
+ if( currState == undefined && this.checkboxAll) {
+ this._setCheckboxState( storeItem, this.checkboxState );
+ currState = this.checkboxState;
+ }
+
+ return currState; // the current state of the checkbox (true/false or undefined)
+ },
+
+ _setCheckboxState: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) {
+ // summary:
+ // Set/update the checkbox state on the dojo.data store.
+ // description:
+ // Set/update the checkbox state on the dojo.data.store. Retreive the current
+ // state of the checkbox and validate if an update is required, this will keep
+ // update events to a minimum. On completion a 'onCheckboxChange' event is
+ // triggered.
+ // If the current state is undefined (ie: no checkbox attribute specified for
+ // this dojo.data.item) the 'checkboxAll' attribute is checked to see if one
+ // needs to be created. In case of the root the 'checkboxRoot' attribute is checked.
+ // NOTE: the store.setValue function will create the 'checkbox' attribute for the
+ // item if none exists.
+ // storeItem:
+ // The item in the dojo.data.store whos checkbox state is updated.
+ // newState:
+ // The new state of the checkbox: true or false
+ // example:
+ // | model.setCheckboxState(item, true);
+ //
+ var stateChanged = true;
+
+ if( storeItem != this.root ) {
+ var currState = this.store.getValue(storeItem, this.checkboxIdent);
+ if( currState != newState && ( currState !== undefined || this.checkboxAll ) ) {
+ this.store.setValue(storeItem, this.checkboxIdent, newState);
+ } else {
+ stateChanged = false; // No changes to the checkbox
+ }
+ } else { // Tree root instance
+ if( this.root.checkbox != newState && ( this.root.checkbox !== undefined || this.checkboxRoot ) ) {
+ this.root.checkbox = newState;
+ } else {
+ stateChanged = false;
+ }
+ }
+ if( stateChanged ) { // In case of any changes trigger the update event.
+ this.onCheckboxChange(storeItem);
+ }
+ return stateChanged;
+ },
+
+ _updateChildCheckbox: function(/*dojo.data.Item*/ parentItem, /*Boolean*/ newState ) {
+ // summary:
+ // Set all child checkboxes to true/false depending on the parent checkbox state.
+ // description:
+ // If a parent checkbox changes state, all child and grandchild checkboxes will be
+ // updated to reflect the change. For example, if the parent state is set to true,
+ // all child and grandchild checkboxes will receive that same 'true' state.
+ // If a child checkbox changes state and has multiple parent, all of its parents
+ // need to be re-evaluated.
+ // parentItem:
+ // The parent dojo.data.item whos child/grandchild checkboxes require updating.
+ // newState:
+ // The new state of the checkbox: true or false
+ //
+
+ if( this.mayHaveChildren( parentItem )) {
+ this.getChildren( parentItem, dojo.hitch( this,
+ function( children ) {
+ dojo.forEach( children, function(child) {
+ if( this._setCheckboxState(child, newState) ) {
+ var parents = this._getParentsItem(child);
+ if( parents.length > 1 ) {
+ this._updateParentCheckbox( child, newState );
+ }
+ }
+ if( this.mayHaveChildren( child )) {
+ this._updateChildCheckbox( child, newState );
+ }
+ }, this );
+ }),
+ function(err) {
+ console.error(this, ": updating child checkboxes: ", err);