src/aria/widgets/form/list/ListController.js
function (itemIndex) {

            this._stopUpdates();
            var json = this.json;
            var data = this._data;
            var itemsList = data.items;
            var item = itemsList[itemIndex];
            var isSelected = item.selected;

            // Needed to optimize the template
            var newlySelectedIndexes = [];
            var newlyUnselectedIndexes = [];

            // items for which _updateCurrentlyDisabled will be called:
            var changedItems = [item];

            var maxSelectedCount = this._getTrueMaxSelectedCount();
            var previousSelectedCount = data.selectedCount;
            var newSelectedIndex = data.selectedIndex;
            var newSelectedCount = previousSelectedCount;
            this.$assert(149, maxSelectedCount >= previousSelectedCount);

            // now we need to update the selectedIndex and selectedCount properties
            // and also the selection of other items (if max selected count has been reached)
            if (isSelected) {
                newlySelectedIndexes[0] = itemIndex;
                newSelectedCount++;
                if (newSelectedCount > maxSelectedCount) {
                    // selecting a new item would be a problem, we need to unselect another item for this to work
                    var selectedIndexes = this.getSelectedIndexes(); // this may or may not contain itemIndex
                    // (depending on selectedIndex)
                    for (var i = 0, len = selectedIndexes.length; i < len; i++) {
                        var indexSelected = selectedIndexes[i];
                        if (indexSelected != itemIndex) { // do not unselect the item that has just been selected
                            var itemToUnselect = itemsList[indexSelected];
                            // check initiallyDisabled so that programmatically disabled items cannot be unselected
                            // here
                            if (!itemToUnselect.initiallyDisabled) {
                                // we found an item to unselect
                                newSelectedCount--;
                                newlyUnselectedIndexes[0] = indexSelected;
                                json.setValue(itemToUnselect, "selected", false);
                                changedItems.push(itemToUnselect);
                                break;
                            }
                        }
                    }
                    this.$assert(182, newSelectedCount == maxSelectedCount); // we must have found an item to
                    // unselect
                }
                if (newSelectedCount === 1) {
                    newSelectedIndex = itemIndex;
                } else {
                    // more than 1 selected item
                    newSelectedIndex = null;
                }
            } else {
                newlyUnselectedIndexes[0] = itemIndex;
                newSelectedCount--;
                if (newSelectedCount === 0) {
                    this.$assert(194, newSelectedIndex == itemIndex); // it was the only selected item
                    newSelectedIndex = -1;
                } else if (newSelectedCount === 1) {
                    // one remaining selected item, need to find which one
                    var selectedIndexes = this.getSelectedIndexes();
                    this.$assert(202, selectedIndexes.length == 1);
                    newSelectedIndex = selectedIndexes[0];
                } else {
                    // more than one remaining selected item, nothing to do with newSelectedIndex
                    this.$assert(203, newSelectedCount > 1);
                    this.$assert(204, newSelectedIndex == null);
                }
            }
            json.setValue(data, "selectedIndex", newSelectedIndex);
            json.setValue(data, "selectedCount", newSelectedCount);
            if ((newSelectedCount != previousSelectedCount)
                    && (previousSelectedCount == maxSelectedCount || newSelectedCount == maxSelectedCount)) {
                // the number of selected items has changed, and it either the old or the new number is the maximum
                // number
                // update all disabled information
                this._updateCurrentlyDisabled(itemsList);
            } else {
                this._updateCurrentlyDisabled(changedItems);
            }
            this._resumeUpdates();
            // after everything is updated, send the event:
            this._raiseOnChangeEvent(newlySelectedIndexes, newlyUnselectedIndexes);
        }
function (itemIndex) {

            this._stopUpdates();
            var json = this.json;
            var data = this._data;
            var itemsList = data.items;
            var item = itemsList[itemIndex];
            var isSelected = item.selected;

            // Needed to optimize the template
            var newlySelectedIndexes = [];
            var newlyUnselectedIndexes = [];

            // items for which _updateCurrentlyDisabled will be called:
            var changedItems = [item];

            var maxSelectedCount = this._getTrueMaxSelectedCount();
            var previousSelectedCount = data.selectedCount;
            var newSelectedIndex = data.selectedIndex;
            var newSelectedCount = previousSelectedCount;
            this.$assert(149, maxSelectedCount >= previousSelectedCount);

            // now we need to update the selectedIndex and selectedCount properties
            // and also the selection of other items (if max selected count has been reached)
            if (isSelected) {
                newlySelectedIndexes[0] = itemIndex;
                newSelectedCount++;
                if (newSelectedCount > maxSelectedCount) {
                    // selecting a new item would be a problem, we need to unselect another item for this to work
                    var selectedIndexes = this.getSelectedIndexes(); // this may or may not contain itemIndex
                    // (depending on selectedIndex)
                    for (var i = 0, len = selectedIndexes.length; i < len; i++) {
                        var indexSelected = selectedIndexes[i];
                        if (indexSelected != itemIndex) { // do not unselect the item that has just been selected
                            var itemToUnselect = itemsList[indexSelected];
                            // check initiallyDisabled so that programmatically disabled items cannot be unselected
                            // here
                            if (!itemToUnselect.initiallyDisabled) {
                                // we found an item to unselect
                                newSelectedCount--;
                                newlyUnselectedIndexes[0] = indexSelected;
                                json.setValue(itemToUnselect, "selected", false);
                                changedItems.push(itemToUnselect);
                                break;
                            }
                        }
                    }
                    this.$assert(182, newSelectedCount == maxSelectedCount); // we must have found an item to
                    // unselect
                }
                if (newSelectedCount === 1) {
                    newSelectedIndex = itemIndex;
                } else {
                    // more than 1 selected item
                    newSelectedIndex = null;
                }
            } else {
                newlyUnselectedIndexes[0] = itemIndex;
                newSelectedCount--;
                if (newSelectedCount === 0) {
                    this.$assert(194, newSelectedIndex == itemIndex); // it was the only selected item
                    newSelectedIndex = -1;
                } else if (newSelectedCount === 1) {
                    // one remaining selected item, need to find which one
                    var selectedIndexes = this.getSelectedIndexes();
                    this.$assert(202, selectedIndexes.length == 1);
                    newSelectedIndex = selectedIndexes[0];
                } else {
                    // more than one remaining selected item, nothing to do with newSelectedIndex
                    this.$assert(203, newSelectedCount > 1);
                    this.$assert(204, newSelectedIndex == null);
                }
            }
            json.setValue(data, "selectedIndex", newSelectedIndex);
            json.setValue(data, "selectedCount", newSelectedCount);
            if ((newSelectedCount != previousSelectedCount)
                    && (previousSelectedCount == maxSelectedCount || newSelectedCount == maxSelectedCount)) {
                // the number of selected items has changed, and it either the old or the new number is the maximum
                // number
                // update all disabled information
                this._updateCurrentlyDisabled(itemsList);
            } else {
                this._updateCurrentlyDisabled(changedItems);
            }
            this._resumeUpdates();
            // after everything is updated, send the event:
            this._raiseOnChangeEvent(newlySelectedIndexes, newlyUnselectedIndexes);
        }
function ( itemIndex ) { this . _stopUpdates ( ) ; var json = this . json ; var data = this . _data ; var itemsList = data . items ; var item = itemsList [ itemIndex ] ; var isSelected = item . selected ; // Needed to optimize the template var newlySelectedIndexes = [ ] ; var newlyUnselectedIndexes = [ ] ; // items for which _updateCurrentlyDisabled will be called: var changedItems = [ item ] ; var maxSelectedCount = this . _getTrueMaxSelectedCount ( ) ; var previousSelectedCount = data . selectedCount ; var newSelectedIndex = data . selectedIndex ; var newSelectedCount = previousSelectedCount ; this . $assert ( 149 , maxSelectedCount >= previousSelectedCount ) ; // now we need to update the selectedIndex and selectedCount properties // and also the selection of other items (if max selected count has been reached) if ( isSelected ) { newlySelectedIndexes [ 0 ] = itemIndex ; newSelectedCount ++ ; if ( newSelectedCount > maxSelectedCount ) { // selecting a new item would be a problem, we need to unselect another item for this to work var selectedIndexes = this . getSelectedIndexes ( ) ; // this may or may not contain itemIndex // (depending on selectedIndex) for ( var i = 0 , len = selectedIndexes . length ; i < len ; i ++ ) { var indexSelected = selectedIndexes [ i ] ; if ( indexSelected != itemIndex ) { // do not unselect the item that has just been selected var itemToUnselect = itemsList [ indexSelected ] ; // check initiallyDisabled so that programmatically disabled items cannot be unselected // here if ( ! itemToUnselect . initiallyDisabled ) { // we found an item to unselect newSelectedCount -- ; newlyUnselectedIndexes [ 0 ] = indexSelected ; json . setValue ( itemToUnselect , "selected" , false ) ; changedItems . push ( itemToUnselect ) ; break ; } } } this . $assert ( 182 , newSelectedCount == maxSelectedCount ) ; // we must have found an item to // unselect } if ( newSelectedCount === 1 ) { newSelectedIndex = itemIndex ; } else { // more than 1 selected item newSelectedIndex = null ; } } else { newlyUnselectedIndexes [ 0 ] = itemIndex ; newSelectedCount -- ; if ( newSelectedCount === 0 ) { this . $assert ( 194 , newSelectedIndex == itemIndex ) ; // it was the only selected item newSelectedIndex = - 1 ; } else if ( newSelectedCount === 1 ) { // one remaining selected item, need to find which one var selectedIndexes = this . getSelectedIndexes ( ) ; this . $assert ( 202 , selectedIndexes . length == 1 ) ; newSelectedIndex = selectedIndexes [ 0 ] ; } else { // more than one remaining selected item, nothing to do with newSelectedIndex this . $assert ( 203 , newSelectedCount > 1 ) ; this . $assert ( 204 , newSelectedIndex == null ) ; } } json . setValue ( data , "selectedIndex" , newSelectedIndex ) ; json . setValue ( data , "selectedCount" , newSelectedCount ) ; if ( ( newSelectedCount != previousSelectedCount ) && ( previousSelectedCount == maxSelectedCount || newSelectedCount == maxSelectedCount ) ) { // the number of selected items has changed, and it either the old or the new number is the maximum // number // update all disabled information this . _updateCurrentlyDisabled ( itemsList ) ; } else { this . _updateCurrentlyDisabled ( changedItems ) ; } this . _resumeUpdates ( ) ; // after everything is updated, send the event: this . _raiseOnChangeEvent ( newlySelectedIndexes , newlyUnselectedIndexes ) ; }
Called when the selected property of an item changed. This method updates the selectedCount and selectedIndex
properties in the data model and unselect other items if the maximum number of selected items has been
reached.
@param {Number} itemIndex item whose selected property has just changed.
@protected
Called when the selected property of an item changed . This method updates the selectedCount and selectedIndex properties in the data model and unselect other items if the maximum number of selected items has been reached .