提交 a6af7d6b 编写于 作者: U unknown

增加人员组织选择的时候,触发校验的功能

上级 39a06ea9
......@@ -1766,14 +1766,14 @@ MWF.xApplication.Selector.Person.Item = new Class({
}.bind(this)
});
},
clickItem: function( manual ){
clickItem: function( checkValid ){
if ( layout.mobile && this.selector.options.count.toInt()===1){
this.selectedSingle( manual );
this.selectedSingle( checkValid );
}else{
if (this.isSelected){
this.unSelected( manual );
this.unSelected( checkValid );
}else{
this.selected( manual );
this.selected( checkValid );
}
}
},
......@@ -1810,7 +1810,7 @@ MWF.xApplication.Selector.Person.Item = new Class({
}
}
},
selectedSingle: function( manual ){
selectedSingle: function( checkValid ){
if (!this.isSelected){
if (this.selector.currentItem) this.selector.currentItem.unSelectedSingle();
this.getData(function(){
......@@ -1828,17 +1828,17 @@ MWF.xApplication.Selector.Person.Item = new Class({
}
this.selector.fireEvent("selectItem",[this]);
if( manual )this.selector.fireEvent("valid", [this.selector, this]);
if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
}.bind(this));
}else {
this.unSelectedSingle( manual );
this.unSelectedSingle( checkValid );
}
},
getData: function(callback){
if (callback) callback();
},
unSelectedSingle: function(){
unSelectedSingle: function(checkValid){
this.selector.currentItem = null;
this.isSelected = false;
this.selector.selectedItems.erase(this);
......@@ -1852,9 +1852,9 @@ MWF.xApplication.Selector.Person.Item = new Class({
this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
}
this.selector.fireEvent("unselectItem",[this]);
if( manual )this.selector.fireEvent("valid", [this.selector, this]);
if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
},
selected: function( manual ){
selected: function( checkValid, callback ){
var count = this.selector.options.maxCount || this.selector.options.count;
count = count.toInt();
if (!count) count = 0;
......@@ -1883,12 +1883,13 @@ MWF.xApplication.Selector.Person.Item = new Class({
// }
this.selector.fireEvent("selectItem",[this]);
if( manual )this.selector.fireEvent("valid", [this.selector, this]);
if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
if(callback)callback();
}else{
MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
}
},
unSelected: function( manual ){
unSelected: function( checkValid, callback ){
this.isSelected = false;
if( this.node ){
this.node.setStyles(this.selector.css.selectorItem);
......@@ -1953,7 +1954,8 @@ MWF.xApplication.Selector.Person.Item = new Class({
this.selectedItem = null;
}
this.selector.fireEvent("unselectItem",[this]);
if( manual )this.selector.fireEvent("valid", [this.selector, this]);
if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
if(callback)callback();
},
postLoad : function(){},
getParentCategoryByLevel : function( level ){
......@@ -2004,18 +2006,18 @@ MWF.xApplication.Selector.Person.ItemSelected = new Class({
getData: function(callback){
if (callback) callback();
},
clickItem: function( manual ){
clickItem: function( checkValid ){
if (this.items.length){
this.items.each(function(item){
item.unSelected( manual );
item.unSelected( checkValid );
});
if( manual )this.selector.fireEvent("valid", [this.selector, this])
if( checkValid )this.selector.fireEvent("valid", [this.selector, this])
}else{
//this.item.selectedItem = null;
//this.item.isSelected = false;
this.destroy();
this.selector.selectedItems.erase(this);
if( manual )this.selector.fireEvent("valid", [this.selector, this])
if( checkValid )this.selector.fireEvent("valid", [this.selector, this])
}
},
//overItem: function(){
......@@ -2142,10 +2144,10 @@ MWF.xApplication.Selector.Person.ItemCategory = new Class({
}).inject(selectAllWrap);
this.selectAllNode.addEvent( "click", function(ev){
if( this.isSelectedAll ){
this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev) : this.unselectAll(ev);
this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true ) : this.unselectAll(ev, null, true);
this.selector.fireEvent("unselectCatgory",[this])
}else{
this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev) : this.selectAll(ev);
this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev, true) : this.selectAll(ev, true);
this.selector.fireEvent("selectCatgory",[this])
}
ev.stopPropagation();
......@@ -2228,12 +2230,12 @@ MWF.xApplication.Selector.Person.ItemCategory = new Class({
this.selectAllNode.addEvent( "click", function(ev){
if( this.isSelectedAll ){
// this.unselectAll(ev);
this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev) : this.unselectAll(ev);
this.selector.fireEvent("unselectCatgory",[this])
this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true ) : this.unselectAll(ev, null, true);
this.selector.fireEvent("unselectCatgory",[this]);
}else{
// this.selectAll(ev);
this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev) : this.selectAll(ev);
this.selector.fireEvent("selectCatgory",[this])
this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev, true) : this.selectAll(ev, true);
this.selector.fireEvent("selectCatgory",[this]);
}
ev.stopPropagation();
}.bind(this));
......@@ -2303,12 +2305,12 @@ MWF.xApplication.Selector.Person.ItemCategory = new Class({
isSelectAllEnable : function(){
},
unselectAll : function(ev, exclude){
unselectAll : function(ev, exclude, checkValid ){
var excludeList = exclude || [];
if( exclude && typeOf(exclude) !== "array" )excludeList = [exclude];
( this.subItems || [] ).each( function(item){
if(item.isSelected && !excludeList.contains(item) ){
item.unSelected();
item.unSelected( checkValid );
}
}.bind(this));
......@@ -2321,29 +2323,29 @@ MWF.xApplication.Selector.Person.ItemCategory = new Class({
}
this.isSelectedAll = false;
},
unselectAllNested : function( ev, exclude ){
this.unselectAll(ev, exclude );
unselectAllNested : function( ev, exclude, checkValid ){
this.unselectAll(ev, exclude, checkValid);
if( this.subCategorys && this.subCategorys.length ){
this.subCategorys.each( function( category ){
category.unselectAllNested( ev, exclude )
category.unselectAllNested( ev, exclude, checkValid )
})
}
},
selectAllNested : function(){
selectAllNested : function( ev, checkValid ){
debugger;
this.selectAll();
this.selectAll(ev, checkValid);
if( this.subCategorys && this.subCategorys.length ){
this.subCategorys.each( function( category ){
category.selectAllNested()
category.selectAllNested(ev, checkValid)
})
}
},
selectAll: function(ev){
selectAll: function(ev, checkValid){
if( this.loaded || this.selector.isFlatCategory ){
this._selectAll( ev );
this._selectAll( ev, checkValid );
}else{
this.clickItem( function(){
this._selectAll( ev );
this._selectAll( ev, checkValid );
//this.children.setStyles({
// "display": "none",
// "height": "0px"
......@@ -2352,7 +2354,7 @@ MWF.xApplication.Selector.Person.ItemCategory = new Class({
}.bind(this));
}
},
_selectAll : function( ev ){
_selectAll : function( ev, checkValid ){
if( this.selector.options.selectAllRange === "direct" && ( !this.subItems || !this.subItems.length ) )return;
var count = this.selector.options.maxCount || this.selector.options.count;
if (!count) count = 0;
......@@ -2361,8 +2363,14 @@ MWF.xApplication.Selector.Person.ItemCategory = new Class({
if(item.isSelected)selectedSubItemCount++
}.bind(this));
if ((count.toInt()===0) || (this.selector.selectedItems.length+(this.subItems.length-selectedSubItemCount))<=count){
var checkedCount = 0;
this.subItems.each( function(item){
if(!item.isSelected)item.selected();
if(!item.isSelected)item.selected( false, function () {
checkedCount++;
if( this.subItems.length === checkedCount ){
if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
}
}.bind(this));
}.bind(this));
if( this.selectAllNode ){
......
......@@ -311,11 +311,11 @@ MWF.xApplication.Selector.Unit.Item = new Class({
this.selectAllNode.addEvent( "click", function(ev){
if( this.isSelectedAll ){
// this.unselectAll(ev);
this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev) : this.unselectAll(ev);
this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true) : this.unselectAll(ev, null, true);
this.selector.fireEvent("unselectCatgory",[this])
}else{
// this.selectAll(ev);
this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev) : this.selectAll(ev);
this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev, true) : this.selectAll(ev ,true);
this.selector.fireEvent("selectCatgory",[this])
}
ev.stopPropagation();
......@@ -337,7 +337,7 @@ MWF.xApplication.Selector.Unit.Item = new Class({
//this.actionNode.setStyles((this.selector.options.expand) ? this.selector.css.selectorItemCategoryActionNode_expand : this.selector.css.selectorItemCategoryActionNode_collapse);
},
unselectAll : function(ev, exclude){
unselectAll : function(ev, exclude, checkValid){
//( this.subItems || [] ).each( function(item){
// if(item.isSelected)item.unSelected();
//}.bind(this));
......@@ -345,7 +345,7 @@ MWF.xApplication.Selector.Unit.Item = new Class({
if( exclude && typeOf(exclude) !== "array" )excludeList = [exclude];
( this.subItems || [] ).each( function(item){
if(item.isSelected && !excludeList.contains(item) ){
item.unSelected();
item.unSelected( checkValid );
}
}.bind(this));
......@@ -358,44 +358,44 @@ MWF.xApplication.Selector.Unit.Item = new Class({
}
this.isSelectedAll = false;
},
unselectAllNested : function( ev, exclude ){
this.unselectAll(ev, exclude );
unselectAllNested : function( ev, exclude, checkValid ){
this.unselectAll(ev, exclude, checkValid );
if( this.subCategorys && this.subCategorys.length ){
this.subCategorys.each( function( category ){
if(category.unselectAllNested)category.unselectAllNested( ev, exclude )
if(category.unselectAllNested)category.unselectAllNested( ev, exclude, checkValid )
})
}
if( this.subItems && this.subItems.length ){
this.subItems.each( function( item ){
if(item.unselectAllNested)item.unselectAllNested( ev, exclude )
if(item.unselectAllNested)item.unselectAllNested( ev, exclude, checkValid )
})
}
},
selectAllNested : function(){
this.selectAll();
selectAllNested : function(ev, checkValid){
this.selectAll(ev, checkValid);
if( this.subCategorys && this.subCategorys.length ){
this.subCategorys.each( function( category ){
if(category.selectAllNested)category.selectAllNested()
if(category.selectAllNested)category.selectAllNestedev, checkValid()
})
}
if( this.subItems && this.subItems.length ){
this.subItems.each( function( item ){
if(item.selectAllNested)item.selectAllNested()
if(item.selectAllNested)item.selectAllNested(ev, checkValid)
})
}
},
selectAll: function(ev){
selectAll: function(ev, checkValid){
if( this.loaded || this.selector.isFlatCategory ){
this._selectAll( ev )
this._selectAll( ev, checkValid )
}else{
this.loadSubItems(function(){
this._selectAll( ev )
this._selectAll( ev, checkValid )
}.bind(this));
this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_expand);
this.isExpand = true;
}
},
_selectAll : function( ev ){
_selectAll : function( ev, checkValid ){
if( !this.subItems || !this.subItems.length )return;
var count = this.selector.options.maxCount || this.selector.options.count;
if (!count) count = 0;
......@@ -404,8 +404,14 @@ MWF.xApplication.Selector.Unit.Item = new Class({
if(item.isSelected)selectedSubItemCount++
}.bind(this));
if ((count.toInt()===0) || (this.selector.selectedItems.length+(this.subItems.length-selectedSubItemCount))<=count){
var checkedCount = 0;
this.subItems.each( function(item){
if(!item.isSelected)item.selected();
if(!item.isSelected)item.selected(false, function () {
checkedCount++;
if( this.subItems.length === checkedCount ){
if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
}
}.bind(this));
}.bind(this));
if( this.selectAllNode ){
......
......@@ -170,11 +170,11 @@ MWF.xApplication.Selector.UnitWithType.Item = new Class({
this.selectAllNode.addEvent( "click", function(ev) {
if (this.isSelectedAll) {
// this.unselectAll(ev);
this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev) : this.unselectAll(ev);
this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true) : this.unselectAll(ev, null, true);
this.selector.fireEvent("unselectCatgory", [this])
} else {
// this.selectAll(ev);
this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev) : this.selectAll(ev);
this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev, true) : this.selectAll(ev, true);
this.selector.fireEvent("selectCatgory", [this])
}
ev.stopPropagation();
......
......@@ -1775,9 +1775,11 @@ if( MWF.xApplication.process.Xform && MWF.xApplication.process.Xform.Form ){
}.bind(this));
}
defaultOpt["onValid"] = function ( selector ) {
this.validation();
}.bind(this);
if( this.needValid() ){
defaultOpt["onValid"] = function ( selector ) {
this.validOnSelect();
}.bind(this);
}
if( this.form.json.selectorStyle ){
defaultOpt = Object.merge( Object.clone(this.form.json.selectorStyle), defaultOpt );
......@@ -2416,17 +2418,41 @@ if( MWF.xApplication.process.Xform && MWF.xApplication.process.Xform.Form ){
//if (!this.node.isIntoView()) this.node.scrollIntoView();
}
},
needValid: function(){
return (( this.json.validationCount && typeOf( this.json.validationCount.toInt() ) === "number" ) ||
(this.json.validation && this.json.validation.code));
},
validOnSelect : function(){
if( !this.errNode )return true;
var flag=true;
if( this.json.validationCount && typeOf( this.json.validationCount.toInt() ) === "number" ){
if( this.selector.selector.selectedItems.length < this.json.validationCount.toInt() ){
flag = "请至少选择"+this.json.validationCount+""
}
}
if( flag === true ){
if ( this.json.validation && this.json.validation.code){
var data = this.getData();
this.setData( data );
flag = this.form.Macro.exec(this.json.validation.code, this);
if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
}
}
if (flag.toString()!="true"){
this.notValidationMode(flag);
return false;
}else if(this.errNode){
this.errNode.destroy();
this.errNode = null;
}
return true;
},
validation: function(){
var data = this.getData();
this.setData( data );
var flag=true;
if( this.json.validationCount && typeOf( this.json.validationCount.toInt() ) === "number" ){
if( data.length < this.json.validationCount.toInt() ){
//if( this.json.validationCount.toInt() === 1 ){
// flag = "请选择"
//}else{
// flag = "请至少选择"+this.json.validationCount+"项"
//}
flag = "请至少选择"+this.json.validationCount+""
}
}
......@@ -2442,7 +2468,8 @@ if( MWF.xApplication.process.Xform && MWF.xApplication.process.Xform.Form ){
this.notValidationMode(flag);
return false;
}else if(this.errNode){
this.errNode.destroy()
this.errNode.destroy();
this.errNode = null;
}
return true;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册