{"size": 1816, "ext": "js", "max_stars_repo_path": "src/js/module/multiTreeViewList.js", "max_stars_repo_name": "regular-ui/regular-ui", "max_stars_repo_stars_event_min_datetime": "2015-09-18T09:54:31.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-17T06:57:04.000Z", "max_issues_repo_path": "src/js/module/multiTreeViewList.js", "max_issues_repo_name": "JUNUL/regular-ui", "max_issues_repo_issues_event_min_datetime": "2015-11-11T07:00:48.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-19T08:17:57.000Z", "max_forks_repo_path": "src/js/module/multiTreeViewList.js", "max_forks_repo_name": "JUNUL/regular-ui", "max_forks_repo_forks_event_min_datetime": "2015-09-18T09:54:32.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-12T08:11:26.000Z"}
{"max_stars_count": 98, "max_issues_count": 50, "max_forks_count": 45, "avg_line_length": 27.5151515152, "max_line_length": 64, "alphanum_fraction": 0.4906387665}
/**
 * ------------------------------------------------------------
 * MultiTreeViewList  树型视图列表
 * @author   sensen(rainforest92@126.com)
 * ------------------------------------------------------------
 */

'use strict';

var TreeViewList = require('./treeViewList.js');
var template = require('./multiTreeViewList.html');
var _ = require('regular-ui-base/src/_');

/**
 * @class MultiTreeView
 * @extend SourceComponent
 * @private
 */
var MultiTreeViewList = TreeViewList.extend({
    name: 'multiTreeViewList',
    template: template,
    /**
     * @private
     */
    _onItemCheckedChange: function($event, item) {
        item.checked = $event.checked;

        if($event.checked !== null && item.children) {
            item.children.forEach(function(child) {
                child.checked = $event.checked;
            });
        }

        var parent = this.data.parent;
        if(parent && parent.checked !== item.checked) {    // 剪枝
            var checkedCount = 0;
            parent.children.forEach(function(child) {
                if(child.checked)
                    checkedCount++;
                else if(child.checked === null)
                    checkedCount += 0.5;
            });

            if(checkedCount === 0)
                parent.checked = false;
            else if(checkedCount === parent.children.length)
                parent.checked = true;
            else
                parent.checked = null;
        }

        /**
         * @event check 改变选中状态时触发
         * @property {object} sender 事件发送对象
         * @property {object} item 处理项
         * @property {boolean} checked 选中状态
         */
        this.$ancestor.$emit('check', {
            sender: this,
            item: item,
            checked: item.checked
        });
    }
});

module.exports = TreeViewList;