From a6af7d6bc96fa8c1b81a44c613c189baed1508ef Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 18 Jul 2020 01:27:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=BA=E5=91=98=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E9=80=89=E6=8B=A9=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E6=A0=A1=E9=AA=8C=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- o2web/source/x_component_Selector/Person.js | 80 ++++++++++--------- o2web/source/x_component_Selector/Unit.js | 40 ++++++---- .../x_component_Selector/UnitWithType.js | 4 +- .../x_component_process_Work/Processor.js | 45 ++++++++--- 4 files changed, 105 insertions(+), 64 deletions(-) diff --git a/o2web/source/x_component_Selector/Person.js b/o2web/source/x_component_Selector/Person.js index ffb93f95c0..98b4e35e80 100644 --- a/o2web/source/x_component_Selector/Person.js +++ b/o2web/source/x_component_Selector/Person.js @@ -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 ){ diff --git a/o2web/source/x_component_Selector/Unit.js b/o2web/source/x_component_Selector/Unit.js index 2335369c18..2c19ff656f 100644 --- a/o2web/source/x_component_Selector/Unit.js +++ b/o2web/source/x_component_Selector/Unit.js @@ -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 ){ diff --git a/o2web/source/x_component_Selector/UnitWithType.js b/o2web/source/x_component_Selector/UnitWithType.js index c5a122475e..42cd194097 100644 --- a/o2web/source/x_component_Selector/UnitWithType.js +++ b/o2web/source/x_component_Selector/UnitWithType.js @@ -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(); diff --git a/o2web/source/x_component_process_Work/Processor.js b/o2web/source/x_component_process_Work/Processor.js index 356dc83d98..df95a6dbc6 100644 --- a/o2web/source/x_component_process_Work/Processor.js +++ b/o2web/source/x_component_process_Work/Processor.js @@ -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; } -- GitLab