$Input.js 23.6 KB
Newer Older
R
roo00 已提交
1
MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
U
jsdoc  
unknown 已提交
2
/** @class $Input 组件类,此类为所有输入组件的父类
U
jsdoc  
unknown 已提交
3
 * @hideconstructor
U
jsodc  
unknown 已提交
4
 * @o2category FormComponents
U
jsdoc  
unknown 已提交
5
* @extends MWF.xApplication.process.Xform.$Module
U
jsdoc  
unknown 已提交
6 7
 * @abstract
 */
U
jsodc  
unknown 已提交
8
MWF.xApplication.process.Xform.$Input = MWF.APP$Input =  new Class(
U
jsdoc  
unknown 已提交
9
    /** @lends MWF.xApplication.process.Xform.$Input# */
U
jsodc  
unknown 已提交
10
    {
R
roo00 已提交
11 12 13
	Implements: [Events],
	Extends: MWF.APP$Module,
	iconStyle: "personfieldIcon",
14
    options: {
NoSubject's avatar
NoSubject 已提交
15
        "moduleEvents": ["change", "load", "queryLoad", "postLoad"]
16
    },
R
roo00 已提交
17 18 19 20 21 22
    initialize: function(node, json, form, options){
        this.node = $(node);
        this.node.store("module", this);
        this.json = json;
        this.form = form;
        this.field = true;
23
        this.fieldModuleLoaded = false;
R
roo00 已提交
24 25 26 27 28 29 30 31 32
    },
	_loadUserInterface: function(){
		this._loadNode();
        if (this.json.compute === "show"){
            this._setValue(this._computeValue());
        }else{
            this._loadValue();
        }
	},
NoSubject's avatar
NoSubject 已提交
33 34 35 36 37 38 39 40 41 42 43
    _loadDomEvents: function(){
        Object.each(this.json.events, function(e, key){
            if (e.code){
                if (this.options.moduleEvents.indexOf(key)===-1){
                    (this.node.getFirst() || this.node).addEvent(key, function(event){
                        return this.form.Macro.fire(e.code, this, event);
                    }.bind(this));
                }
            }
        }.bind(this));
    },
R
roo00 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    _loadEvents: function(){
        Object.each(this.json.events, function(e, key){
            if (e.code){
                if (this.options.moduleEvents.indexOf(key)!==-1){
                    this.addEvent(key, function(event){
                        return this.form.Macro.fire(e.code, this, event);
                    }.bind(this));
                }else{
                    (this.node.getFirst() || this.node).addEvent(key, function(event){
                        return this.form.Macro.fire(e.code, this, event);
                    }.bind(this));
                }
            }
        }.bind(this));
    },
NoSubject's avatar
NoSubject 已提交
59 60 61 62 63 64 65 66 67 68 69
    addModuleEvent: function(key, fun){
        if (this.options.moduleEvents.indexOf(key)!==-1){
            this.addEvent(key, function(event){
                return (fun) ? fun(this, event) : null;
            }.bind(this));
        }else{
            (this.node.getFirst() || this.node).addEvent(key, function(event){
                return (fun) ? fun(this, event) : null;
            }.bind(this));
        }
    },
R
roo00 已提交
70 71

    _loadNode: function(){
72
        if (this.isReadonly()){
R
roo00 已提交
73 74 75 76 77 78 79
            this._loadNodeRead();
        }else{
            this._loadNodeEdit();
        }
    },
    _loadNodeRead: function(){
        this.node.empty();
80 81 82 83
        this.node.set({
            "nodeId": this.json.id,
            "MWFType": this.json.type
        });
R
roo00 已提交
84 85
    },
    loadDescription: function(){
86
        if (this.readonly || this.json.isReadonly)return;
R
roo00 已提交
87 88 89 90 91
        var v = this._getBusinessData();
        if (!v){
            if (this.json.description){
                var size = this.node.getFirst().getSize();
                var w = size.x-3;
92
                if( this.hasIcon() ){
U
unknown 已提交
93 94
                    if (COMMON.Browser.safari) w = w-20;
                }
U
jsdoc  
unknown 已提交
95 96

                /**
U
jsdoc  
unknown 已提交
97
                 * @summary 描述信息节点,允许用户手工输入的组件才有此节点,只读情况下无此节点.
U
jsdoc  
unknown 已提交
98 99
                 * @member {Element}
                 */
R
roo00 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
                this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
                this.descriptionNode.setStyles({
                    "width": ""+w+"px",
                    "height": ""+size.y+"px",
                    "line-height": ""+size.y+"px"
                });
                this.setDescriptionEvent();
            }
        }
    },
    setDescriptionEvent: function(){
        if (this.descriptionNode){
            this.descriptionNode.addEvents({
                "mousedown": function(){
                    this.descriptionNode.setStyle("display", "none");
                    this.clickSelect();
                }.bind(this)
            });
            this.node.getFirst().addEvents({
                "focus": function(){
                    if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
                }.bind(this),
                "blur": function(){
                    if (!this.node.getFirst().get("value")) if (this.descriptionNode)  this.descriptionNode.setStyle("display", "block");
                }.bind(this)
            });
        }
    },
    checkDescription: function(){
        if (!this.node.getFirst().get("value")){
            if (this.descriptionNode)  this.descriptionNode.setStyle("display", "block");
        }else{
            if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
        }
    },
135 136
    _resetNodeEdit: function(){
        var input = new Element("input", {
R
roo00 已提交
137 138 139 140 141 142 143 144
            "styles": {
                "background": "transparent",
                "width": "100%",
                "border": "0px"
            },
            "readonly": true
        });

145 146 147 148 149 150
        var overflow;
        if(this.json.styles && this.json.styles.overflow){
            overflow = this.json.styles.overflow;
        }else{
            overflow = this.hasIcon() ? "hidden" : "visible";
        }
R
roo00 已提交
151
        var node = new Element("div", {"styles": {
152
                "overflow": overflow,
153
                "position": "relative",
154
                "margin-right": this.hasIcon() ? "20px" : "0px",
155 156
                "padding-right": "4px"
            }}).inject(this.node, "after");
R
roo00 已提交
157 158 159
        input.inject(node);

        this.node.destroy();
160 161
        this.node = node;
    },
162 163 164
    hasIcon: function(){
	    return this.json.showIcon!='no' && ( !this.form.json || !this.form.json.hideModuleIcon );
    },
165 166 167 168
    _loadNodeEdit: function(){
	    if (!this.json.preprocessing) this._resetNodeEdit();
	    var input = this.node.getFirst();
        input.set(this.json.properties);
R
roo00 已提交
169 170 171 172 173 174 175 176
		this.node.set({
			"id": this.json.id,
			"MWFType": this.json.type,
			"readonly": true,
			"events": {
				"click": this.clickSelect.bind(this)
			}
		});
177
        if ( this.hasIcon() ){
R
roo00 已提交
178 179 180 181 182 183 184 185 186
            this.iconNode = new Element("div", {
                "styles": this.form.css[this.iconStyle],
                "events": {
                    "click": this.clickSelect.bind(this)
                }
            }).inject(this.node, "before");
        }else if( this.form.json.nodeStyleWithhideModuleIcon ){
            this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
        }
R
roo00 已提交
187 188 189

        this.node.getFirst().addEvent("change", function(){
            this.validationMode();
U
unknown 已提交
190 191 192 193
            if (this.validation()) {
                this._setBusinessData(this.getInputData("change"));
                this.fireEvent("change");
            }
R
roo00 已提交
194
        }.bind(this));
195 196 197 198 199 200
        //
        // var inputNode = this.node.getFirst();
        // if (inputNode) inputNode.addEvent("input", function(e){
        //     var v=e.target.get("value");
        //     this._setEnvironmentData(v);
        // }.bind(this));
R
roo00 已提交
201 202 203 204
	},
    _loadStyles: function(){
        if (this.json.styles) this.node.setStyles(this.json.styles);
        if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
205
        if (this.iconNode && this.iconNode.offsetParent !== null){
R
roo00 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218 219
            var size = this.node.getSize();
            //if (!size.y){
            //    var y1 = this.node.getStyle("height");
            //    var y2 = this.node.getFirst().getStyle("height");
            //    alert(y1+"," +y2);
            //    var y = ((y1!="auto" && y1>y2) || y2=="auto") ? y1 : y2;
            //    size.y = (y=="auto") ? "auto" : y.toInt();
            //    //alert(size.y)
            //}
            this.iconNode.setStyle("height", ""+size.y+"px");
            //alert(this.iconNode.getStyle("height"))
        }
    },
    _computeValue: function(value){
220
        return (this.json.defaultValue && this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
R
roo00 已提交
221 222
    },
	getValue: function(){
223
        if (this.moduleValueAG) return this.moduleValueAG;
R
roo00 已提交
224 225 226 227 228
        var value = this._getBusinessData();
        if (!value) value = this._computeValue();
		return value || "";
	},
    _setValue: function(value){
229 230 231 232 233 234 235 236 237 238
	    // if (value && value.isAG){
	    //     var ag = o2.AG.all(value).then(function(v){
	    //         if (o2.typeOf(v)=="array") v = v[0];
        //         this.__setValue(v);
        //     }.bind(this));
        //     this.moduleValueAG = ag;
	    //     ag.then(function(){
        //         this.moduleValueAG = null;
        //     }.bind(this));
        // }else {
239
        if (!!value && o2.typeOf(value.then)=="function"){
240
            var p = Promise.resolve(value).then(function(v){
241
                this.__setValue(v);
NoSubject's avatar
NoSubject 已提交
242
            }.bind(this), function(){});
243 244
            this.moduleValueAG = p;
        }else{
245
            this.moduleValueAG = null;
NoSubject's avatar
NoSubject 已提交
246
            this.__setValue(value);
247 248
        }

NoSubject's avatar
NoSubject 已提交
249
            //this.__setValue(value);
250
        // }
251 252 253

    },
    __setValue: function(value){
NoSubject's avatar
NoSubject 已提交
254
        this.moduleValueAG = null;
255 256 257 258
        this._setBusinessData(value);
        if (this.node.getFirst()) this.node.getFirst().set("value", value || "");
        if (this.readonly || this.json.isReadonly) this.node.set("text", value);
        this.moduleValueAG = null;
259
        this.fieldModuleLoaded = true;
260
        return value;
R
roo00 已提交
261
    },
262

R
roo00 已提交
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
	_loadValue: function(){
        this._setValue(this.getValue());
	},
	clickSelect: function(){
	},
	_afterLoaded: function(){
//		if (this.iconNode){
////			var p = this.node.getPosition();
////			var s = this.node.getSize();
////			var is = this.iconNode.getSize();
////
////			var y = p.y;
////			var x = p.x+s.x-is.x;
//			this.iconNode.setStyles({
//				"top": "5px",
//				"left": "-18px"
//			});
//		}
281
        if (!this.readonly && !this.json.isReadonly ){
R
roo00 已提交
282 283 284
            this.loadDescription();
        }
	},
285 286 287 288 289 290 291 292 293
    /**
     * @summary 判断组件是否只读.
     * @example
     * var readonly = this.form.get('subject').isReadonly();
     * @return {Boolean} 是否只读.
     */
	isReadonly : function(){
        return !!(this.readonly || this.json.isReadonly);
    },
R
roo00 已提交
294 295 296 297 298
	getTextData: function(){
		//var value = this.node.get("value");
		//var text = this.node.get("text");
        var value = (this.node.getFirst()) ? this.node.getFirst().get("value") : this.node.get("text");
        var text = (this.node.getFirst()) ? this.node.getFirst().get("text") : this.node.get("text");
R
roo00 已提交
299
		return {"value": [value || ""] , "text": [text || value || ""]};
R
roo00 已提交
300
	},
U
unknown 已提交
301
    /**
302
     * @summary 判断组件值是否为空.
U
jsdoc  
unknown 已提交
303 304 305 306 307
     * @example
     * if( this.form.get('subject').isEmpty() ){
     *     this.form.notice('标题不能为空', 'warn');
     * }
     * @return {Boolean} 值是否为空.
U
unknown 已提交
308
     */
U
unknown 已提交
309
    isEmpty : function(){
U
unknown 已提交
310 311
	    var data = this.getData();
	    return !data || !data.trim();
U
unknown 已提交
312
    },
U
unknown 已提交
313
    /**
U
jsdoc  
unknown 已提交
314
     * 在脚本中使用 this.data[fieldId] 也可以获取组件值。
315 316 317
     * 区别如下:<br/>
     * 1、当使用Promise的时候<br/>
     * 使用异步函数生成器(Promise)为组件赋值的时候,用getData方法立即获取数据,可能返回修改前的值,当Promise执行完成以后,会返回修改后的值。<br/>
U
jsdoc  
unknown 已提交
318
     * this.data[fieldId] 立即获取数据,可能获取到异步函数生成器,当Promise执行完成以后,会返回修改后的值。<br/>
319
     * {@link https://www.yuque.com/o2oa/ixsnyt/ws07m0#EggIl|具体差异请查看链接}<br/>
U
jsdoc  
unknown 已提交
320
     * 2、当表单上没有对应组件的时候,可以使用this.data[fieldId]获取值,但是this.form.get('fieldId')无法获取到组件。
321
     * @summary 获取组件值。
322
     * @example
U
jsdoc  
unknown 已提交
323
     * var data = this.form.get('fieldId').getData(); //没有使用promise的情况、
324 325 326
     * @example
     *  //如果无法确定表单上是否有组件,需要判断
     *  var data;
U
jsdoc  
unknown 已提交
327 328
     *  if( this.form.get('fieldId') ){ //判断表单是否有无对应组件
     *      data = this.form.get('fieldId').getData();
329
     *  }else{
U
jsdoc  
unknown 已提交
330
     *      data = this.data['fieldId']; //直接从数据中获取字段值
331
     *  }
U
jsdoc  
unknown 已提交
332 333
     * @example
     *  //使用Promise的情况
U
jsdoc  
unknown 已提交
334
     *  var field = this.form.get("fieldId");
U
jsdoc  
unknown 已提交
335 336 337 338 339 340
     *  var dict = new this.Dict("test"); //test为数据字典名称
     *  var promise = dict.get("tools", true); //异步使用数据字典的get方法时返回Promise,参数true表示异步
     *  promise.then( function(){
     *      var data = field.getData(); //此时由于异步请求已经执行完毕,getData方法获取到了数据字典的值
     *  })
     *  field.setData( promise );
U
jsdoc  
unknown 已提交
341
     * @return 组件的数据.
U
unknown 已提交
342
     */
R
roo00 已提交
343 344
	getData: function(when){
        if (this.json.compute == "save") this._setValue(this._computeValue());
NoSubject's avatar
NoSubject 已提交
345
        return this.getInputData();
R
roo00 已提交
346 347
	},
    getInputData: function(){
NoSubject's avatar
NoSubject 已提交
348 349 350 351 352
        if (this.node.getFirst()){
            return this.node.getFirst().get("value");
        }else{
            return this._getBusinessData();
        }
R
roo00 已提交
353
    },
U
unknown 已提交
354
    /**
355
     * @summary 重置组件的值为默认值或置空。
U
jsdoc  
unknown 已提交
356 357
     *  @example
     * this.form.get('subject').resetData();
U
unknown 已提交
358
     */
R
roo00 已提交
359 360 361
    resetData: function(){
        this.setData(this.getValue());
    },
362
    /**当参数为Promise的时候,请参考文档: {@link  https://www.yuque.com/o2oa/ixsnyt/ws07m0|使用Promise处理表单异步}<br/>
U
jsdoc  
unknown 已提交
363
     * 当表单上没有对应组件的时候,可以使用this.data[fieldId] = data赋值。
U
jsdoc  
unknown 已提交
364
     * @summary 为组件赋值。
365
     * @param data{String|Promise} .
366
     * @param fireChange{boolean} 可选,是否触发change事件,默认false.
367
     * @example
U
jsdoc  
unknown 已提交
368
     *  this.form.get("fieldId").setData("test"); //赋文本值
369 370
     * @example
     *  //如果无法确定表单上是否有组件,需要判断
U
jsdoc  
unknown 已提交
371 372
     *  if( this.form.get('fieldId') ){ //判断表单是否有无对应组件
     *      this.form.get('fieldId').setData( data );
373
     *  }else{
U
jsdoc  
unknown 已提交
374
     *      this.data['fieldId'] = data;
375 376
     *  }
     * @example
U
jsdoc  
unknown 已提交
377
     *  //使用Promise
U
jsdoc  
unknown 已提交
378
     *  var field = this.form.get("fieldId");
U
jsdoc  
unknown 已提交
379 380 381
     *  var dict = new this.Dict("test"); //test为数据字典名称
     *  var promise = dict.get("tools", true); //异步使用数据字典的get方法时返回Promise,参数true表示异步
     *  field.setData( promise );
U
unknown 已提交
382
     */
383
	setData: function(data, fireChange){
384 385 386 387 388 389 390 391 392 393
        // if (data && data.isAG){
        //     var ag = o2.AG.all(data).then(function(v){
        //         if (o2.typeOf(v)=="array") v = v[0];
        //         this.__setData(v);
        //     }.bind(this));
        //     this.moduleValueAG = ag;
        //     ag.then(function(){
        //         this.moduleValueAG = null;
        //     }.bind(this));
        // }else{
394
        if (!!data && o2.typeOf(data.then)=="function"){
395
            var p = o2.promiseAll(data).then(function(v){
396
                this.__setData(v, fireChange);
NoSubject's avatar
NoSubject 已提交
397 398 399 400
                // if (this.node.getFirst() && !this.readonly && !this.json.isReadonly) {
                //     this.checkDescription();
                //     this.validationMode();
                // }
NoSubject's avatar
NoSubject 已提交
401
            }.bind(this), function(){});
402 403 404
            this.moduleValueAG = p;
            p.then(function(){
                this.moduleValueAG = null;
NoSubject's avatar
NoSubject 已提交
405 406
            }.bind(this), function(){
                this.moduleValueAG = null;
407 408
            }.bind(this));
        }else{
409
            this.moduleValueAG = null;
410
            this.__setData(data, fireChange);
NoSubject's avatar
NoSubject 已提交
411 412 413 414
            // if (this.node.getFirst() && !this.readonly && !this.json.isReadonly) {
            //     this.checkDescription();
            //     this.validationMode();
            // }
415
        }
NoSubject's avatar
NoSubject 已提交
416
            //this.__setData(data);
417
        //}
R
roo00 已提交
418
	},
419
    __setData: function(data, fireChange){
420
	    var old = this.getInputData();
421 422 423 424 425 426 427 428
        this._setBusinessData(data);
        if (this.node.getFirst()){
            this.node.getFirst().set("value", data);
            this.checkDescription();
            this.validationMode();
        }else{
            this.node.set("text", data);
        }
429
        if (fireChange && old!==data) this.fireEvent("change");
430 431 432
        this.moduleValueAG = null;
    },

R
roo00 已提交
433 434

    createErrorNode: function(text){
R
roo00 已提交
435

R
roo00 已提交
436 437 438 439 440 441 442 443 444 445
        //var size = this.node.getFirst().getSize();
        //var w = size.x-3;
        //if (COMMON.Browser.safari) w = w-20;
        //node.setStyles({
        //    "width": ""+w+"px",
        //    "height": ""+size.y+"px",
        //    "line-height": ""+size.y+"px",
        //    "position": "absolute",
        //    "top": "0px"
        //});
R
roo00 已提交
446 447
        var node;
        if( this.form.json.errorStyle ){
U
unknown 已提交
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
            if( this.form.json.errorStyle.type === "notice" ){
                if( !this.form.errorNoticing ){ //如果是弹出
                    this.form.errorNoticing = true;
                    this.form.notice(text, "error", this.node, null, null, {
                        onClose : function () {
                            this.form.errorNoticing = false;
                        }.bind(this)
                    });
                }
            }else{
                node = new Element("div",{
                    "styles" : this.form.json.errorStyle.node,
                    "text": text
                });
                if( this.form.json.errorStyle.close ){
                    var closeNode = new Element("div",{
                        "styles" : this.form.json.errorStyle.close ,
                        "events": {
                            "click" : function(){
                                this.destroy();
                            }.bind(node)
                        }
                    }).inject(node);
                }
R
roo00 已提交
472
            }
R
roo00 已提交
473 474 475 476 477 478 479
        }else{
            node = new Element("div");
            var iconNode = new Element("div", {
                "styles": {
                    "width": "20px",
                    "height": "20px",
                    "float": "left",
480
                    "background": "url("+"../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
R
roo00 已提交
481 482 483 484 485 486 487 488 489 490 491 492 493
                }
            }).inject(node);
            var textNode = new Element("div", {
                "styles": {
                    "height": "20px",
                    "line-height": "20px",
                    "margin-left": "20px",
                    "color": "red",
                    "word-break": "keep-all"
                },
                "text": text
            }).inject(node);
        }
R
roo00 已提交
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
        return node;
    },
    notValidationMode: function(text){
        if (!this.isNotValidationMode){
            this.isNotValidationMode = true;
            this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
            this.node.setStyle("border-color", "red");

            this.errNode = this.createErrorNode(text);
            //if (this.iconNode){
            //    this.errNode.inject(this.iconNode, "after");
            //}else{
                this.errNode.inject(this.node, "after");
            //}
            this.showNotValidationMode(this.node);
R
roo00 已提交
509 510 511 512 513 514 515

            var parentNode = this.node;
            while( parentNode.offsetParent === null ){
                parentNode = parentNode.getParent();
            }

            if (!parentNode.isIntoView()) parentNode.scrollIntoView();
R
roo00 已提交
516 517 518 519 520 521 522 523 524 525 526
        }
    },
    showNotValidationMode: function(node){
        var p = node.getParent("div");
        if (p){
            var mwftype = p.get("MWFtype") || p.get("mwftype");
            if (mwftype == "tab$Content"){
                if (p.getParent("div").getStyle("display")=="none"){
                    var contentAreaNode = p.getParent("div").getParent("div");
                    var tabAreaNode = contentAreaNode.getPrevious("div");
                    var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
NoSubject's avatar
NoSubject 已提交
527
                    var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
R
roo00 已提交
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
                    tabNode.click();
                    p = tabAreaNode.getParent("div");
                }
            }
            this.showNotValidationMode(p);
        }
    },
    validationMode: function(){
        if (this.isNotValidationMode){
            this.isNotValidationMode = false;
            this.node.setStyles(this.node.retrieve("borderStyle"));
            if (this.errNode){
                this.errNode.destroy();
                this.errNode = null;
            }
        }
    },
    validationConfigItem: function(routeName, data){
        var flag = (data.status==="all") ? true: (routeName === data.decision);
        if (flag){
            var n = this.getInputData();
            var v = (data.valueType==="value") ? n : n.length;
            switch (data.operateor){
                case "isnull":
                    if (!v){
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "notnull":
                    if (v){
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "gt":
                    if (v>data.value){
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "lt":
                    if (v<data.value){
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "equal":
                    if (v==data.value){
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "neq":
                    if (v!=data.value){
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "contain":
                    if (v.indexOf(data.value)!=-1){
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "notcontain":
                    if (v.indexOf(data.value)==-1){
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
            }
        }
        return true;
    },
    validationConfig: function(routeName, opinion){
        if (this.json.validationConfig){
            if (this.json.validationConfig.length){
                for (var i=0; i<this.json.validationConfig.length; i++) {
                    var data = this.json.validationConfig[i];
                    if (!this.validationConfigItem(routeName, data)) return false;
                }
            }
            return true;
        }
        return true;
    },
U
unknown 已提交
615
    /**
616
     * @summary 根据组件的校验设置进行校验。
U
jsdoc  
unknown 已提交
617
     *  @param {String} [routeName] - 可选,路由名称.
U
jsdoc  
unknown 已提交
618
     *  @example
U
jsdoc  
unknown 已提交
619
     *  if( !this.form.get('fieldId').validation() ){
U
jsdoc  
unknown 已提交
620 621
     *      return false;
     *  }
U
jsdoc  
unknown 已提交
622
     *  @return {Boolean} 是否通过校验
U
unknown 已提交
623
     */
R
roo00 已提交
624
    validation: function(routeName, opinion){
R
roo00 已提交
625 626
        if (!this.readonly && !this.json.isReadonly){
            if (!this.validationConfig(routeName, opinion))  return false;
R
roo00 已提交
627

R
roo00 已提交
628 629
            if (!this.json.validation) return true;
            if (!this.json.validation.code) return true;
630 631

            this.currentRouteName = routeName;
R
roo00 已提交
632
            var flag = this.form.Macro.exec(this.json.validation.code, this);
633 634
            this.currentRouteName = "";

R
roo00 已提交
635 636 637 638 639
            if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
            if (flag.toString()!="true"){
                this.notValidationMode(flag);
                return false;
            }
R
roo00 已提交
640 641 642 643
        }
        return true;
    }
	
644
});