update: function()

in js/projection/row-tri-state-checkbox.js [93:152]


    update: function (options) {
      if (!Model.__super__.update.call(this, options)) {
        return;
      }

      var checkId = this.get('row.check.id');
      var ids = _.pluck(this.src.data.get('value'), checkId);
      var checkMap = this.get('row.check.map');
      var col = this.get('column.checked');
      var columns = _.clone(this.src.data.get('columns'));
      var checkStateCounters = _.object(
          ['unchecked', 'checked', 'indeterminate'],
          [0, 0, 0]
        );
      var hasCheckboxable = false;
      var checkboxAllow = this.get('row.check.allow');
      var checkboxColumn = _.find(columns, function (item) {
        return item.property === col;
      });
      var rowCheckTemp = this.get('row.check.template');

      var value = _.map(this.src.data.get('value'), function (item) {
        var ret = _.clone(item);
        var check = checkMap[ret[checkId]] || { state: 'unchecked' };
        var disabled = true;
        var isAllowed = _.isFunction(checkboxAllow) ? checkboxAllow(ret) : checkboxAllow;

        checkStateCounters[check.state]++;

        if (isAllowed) {
          disabled = false;
          hasCheckboxable = true;
        }

        ret[col] = _.extend({}, ret[col], {
          $html: rowCheckTemp({ checkState: check.state, disabled: disabled }),
        });

        return ret;
      });

      // set the checkbox in th
      if (!_.isUndefined(checkboxColumn)) {
        var disabledAllCheck = _.size(ids) === 0;

        if (hasCheckboxable) {
          var checkState = getAllCheckState(checkStateCounters, ids.length);

          checkboxColumn.$html = rowCheckTemp({ checkState: checkState, disabled: disabledAllCheck });
          this.attributes['row.check.all'] = _.extend(this.attributes['row.check.all'], { state: checkState });
        } else {
          checkboxColumn.$html = rowCheckTemp({ checkState: this.get('row.check.all').state, disabled: disabledAllCheck });
        }
      }

      this.patch({
        value: value,
        columns: columns,
      });
    },