{"size": 3353, "ext": "js", "max_stars_repo_path": "urule-console-js/src/scorecard/AttributeCell.js", "max_stars_repo_name": "Air-TR/urule-springboot", "max_stars_repo_stars_event_min_datetime": "2017-08-25T07:53:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T06:55:55.000Z", "max_issues_repo_path": "urule-console-js/src/scorecard/AttributeCell.js", "max_issues_repo_name": "Air-TR/urule-springboot", "max_issues_repo_issues_event_min_datetime": "2017-10-20T09:29:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-12T08:51:29.000Z", "max_forks_repo_path": "urule-console-js/src/scorecard/AttributeCell.js", "max_forks_repo_name": "Air-TR/urule-springboot", "max_forks_repo_forks_event_min_datetime": "2017-08-25T08:11:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T12:35:49.000Z"}
{"max_stars_count": 1493, "max_issues_count": 166, "max_forks_count": 669, "avg_line_length": 37.2555555556, "max_line_length": 180, "alphanum_fraction": 0.587533552}
/**
 * Created by Jacky.gao on 2016/9/19.
 */
import Cell from './Cell.js';
export default class AttributeCell extends Cell{
    constructor(row,col,cellData){
        super(row,col,cellData);
        this.type="attribute";
    }
    initCell(cellData){
        const container=$(`<div></div>`);
        this.td.append(container);
        this.propContainer=generateContainer();
        if(cellData){
            this.variableLabel=cellData.variableLabel;
            this.variableName=cellData.variableName;
            this.weight=cellData.weight;
            URule.setDomContent(this.propContainer,this.variableLabel || this.variableName);
        }else{
            URule.setDomContent(this.propContainer,"请选择属性");
        }
        container.append(this.propContainer);
        this.propContainer.css({color:'green'});
        const _this=this;
        const del=$(`<span class="attribute-operation" style="color: #ff0600"><i class="glyphicon glyphicon-remove" style="cursor: pointer" title="删除当前属性行"></i></span>`);
        container.append(del);
        del.click(function () {
            bootbox.confirm("真的要删除？",function (result) {
                if(!result)return;
                _this.row.remove();
            });
        });
        const addCondition=$(`<span class="attribute-operation" style="color: #019dff"><i class="glyphicon glyphicon-plus-sign" style="cursor: pointer" title="添加条件行"></i></span>`);
        container.append(addCondition);
        addCondition.click(function () {
            _this.row.addConditionRow();
        });
        if(this.row.scoreCardTable.attributeCol.category){
            this.refreshAttributeCellMenus(this.row.scoreCardTable.attributeCol.category.variables);
        }
        this.weightContainer=$("<div style='margin-top: 5px;color:#999'><label>权重：</label></div>");
        if(!this.row.scoreCardTable.weightSupport){
            this.weightContainer.hide();
        }

        this.weightEditor=$(`<input type="text" class="form-control" style="width:60px;height: 25px;display: inline-block">`);
        this.weightContainer.append(this.weightEditor);
        if(this.weight){
            this.weightEditor.val(this.weight);
        }
        this.weightEditor.change(function () {
            _this.weight=$(this).val();
        });
        container.append(this.weightContainer);
    }

    showWeight(){
        this.weightContainer.show();
        this.weight=null;
        this.weightEditor.val('');
    }
    hideWeight(){
        this.weightContainer.hide();
        this.weight=null;
        this.weightEditor.val('');
    }

    refreshAttributeCellMenus(variables){
        const menuItems=[];
        const _this=this;
        for(let variable of variables){
            menuItems.push({
                label:variable.label || variable.name,
                onClick:function () {
                    _this.variable=variable;
                    URule.setDomContent(_this.propContainer,variable.label || variable.name);
                }
            })
        }
        if(!this.propContainer.menu){
            this.propContainer.menu=new URule.menu.Menu({menuItems});
            this.propContainer.click(function (e) {
                _this.propContainer.menu.show(e);
            });
        }else{
            this.propContainer.menu.setConfig({menuItems});
        }
    }
}
