Org.js 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898
  1. MWF.xDesktop.requireApp("process.Xform", "$Input", null, false);
  2. MWF.xDesktop.requireApp("Selector", "package", null, false);
  3. MWF.require("MWF.widget.O2Identity", null, false);
  4. MWF.xApplication.process.Xform.Org = MWF.APPOrg = new Class({
  5. Implements: [Events],
  6. Extends: MWF.APP$Input,
  7. options: {
  8. "moduleEvents": ["load", "queryLoad", "postLoad", "change", "select"],
  9. "selectorEvents" : ["queryLoadSelector","postLoadSelector","postLoadContent","queryLoadCategory","postLoadCategory",
  10. "selectCategory", "unselectCategory","queryLoadItem","postLoadItem","selectItem", "unselectItem","change"],
  11. "readonly": true
  12. },
  13. iconStyle: "orgIcon",
  14. getTextData: function(){
  15. //var value = this.node.get("value");
  16. //var text = this.node.get("text");
  17. var value = this.getValue();
  18. //var text = (this.node.getFirst()) ? this.node.getFirst().get("text") : this.node.get("text");
  19. var text = [];
  20. value.each(function(v){
  21. if( typeOf(v) === "string" ){
  22. text.push(v);
  23. }else{
  24. text.push(v.name+((v.unitName) ? "("+v.unitName+")" : ""));
  25. }
  26. }.bind(this));
  27. return {"value": value || "", "text": [text.join(",")]};
  28. },
  29. loadDescription: function(){
  30. if (this.readonly || this.json.isReadonly)return;
  31. var v = this._getBusinessData();
  32. if (!v || !v.length){
  33. if (this.json.description){
  34. var size = this.node.getFirst().getSize();
  35. var w = size.x-3;
  36. if( this.json.showIcon!='no' && !this.form.json.hideModuleIcon ) {
  37. if (COMMON.Browser.safari) w = w - 20;
  38. }
  39. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  40. this.descriptionNode.setStyles({
  41. "width": ""+w+"px",
  42. "height": ""+size.y+"px",
  43. "line-height": ""+size.y+"px"
  44. });
  45. this.setDescriptionEvent();
  46. }
  47. }
  48. },
  49. setDescriptionEvent: function(){
  50. if (this.descriptionNode){
  51. this.descriptionNode.addEvents({
  52. "mousedown": function( ev ){
  53. this.descriptionNode.setStyle("display", "none");
  54. this.clickSelect( ev );
  55. }.bind(this)
  56. });
  57. }
  58. },
  59. _loadNode: function(){
  60. this.field = true;
  61. if (this.readonly || this.json.isReadonly){
  62. this._loadNodeRead();
  63. }else{
  64. this._getOrgOptions();
  65. if (this.json.isInput){
  66. this._loadNodeInputEdit();
  67. }else{
  68. this._loadNodeEdit();
  69. }
  70. }
  71. },
  72. _getOrgOptions: function(){
  73. this.selectTypeList = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
  74. if( this.selectTypeList.contains( "identity" ) ) {
  75. this.identityOptions = new MWF.APPOrg.IdentityOptions(this.form, this.json);
  76. }
  77. if( this.selectTypeList.contains( "unit" ) ) {
  78. this.unitOptions = new MWF.APPOrg.UnitOptions(this.form, this.json);
  79. }
  80. if( this.selectTypeList.contains( "group" ) ){
  81. this.groupOptions = new MWF.APPOrg.GroupOptions( this.form, this.json );
  82. }
  83. //this.selectUnits = this.getSelectRange();
  84. //if (this.json.selectType=="identity"){
  85. // this.selectDutys = this.getSelectRangeDuty();
  86. //}
  87. },
  88. _computeValue: function(){
  89. var simple = this.json.storeRange === "simple";
  90. var values = [];
  91. if (this.json.identityValue) {
  92. this.json.identityValue.each(function(v){
  93. if (v) values.push(MWF.org.parseOrgData(v, true, simple))
  94. });
  95. }
  96. if (this.json.unitValue) {
  97. this.json.unitValue.each(function(v){ if (v) values.push(MWF.org.parseOrgData(v, true, simple))});
  98. }
  99. if (this.json.dutyValue) {
  100. var dutys = JSON.decode(this.json.dutyValue);
  101. var par;
  102. if (dutys.length){
  103. dutys.each(function(duty){
  104. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  105. var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\")";
  106. var d = this.form.Macro.exec(code, this);
  107. if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  108. d.each(function(dd){if (dd) values.push(MWF.org.parseOrgData(dd, true, simple));});
  109. }.bind(this));
  110. }
  111. }
  112. if (this.json.defaultValue && this.json.defaultValue.code){
  113. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  114. if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
  115. fd.each(function(fdd){
  116. if (fdd){
  117. if (typeOf(fdd)==="string"){
  118. var data;
  119. this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, fdd, false);
  120. values.push(data);
  121. }else{
  122. values.push(fdd);
  123. }
  124. }
  125. }.bind(this));
  126. }
  127. if (this.json.count>0){
  128. return values.slice(0, this.json.count);
  129. }
  130. return values;
  131. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  132. },
  133. getOrgAction: function(){
  134. if (!this.orgAction) this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  135. //if (!this.orgAction) this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
  136. return this.orgAction;
  137. },
  138. getOptions: function(){
  139. var _self = this;
  140. if( this.selectTypeList.length === 0 )return false;
  141. var values = this.getInputData();
  142. var exclude = [];
  143. if( this.json.exclude ){
  144. var v = this.form.Macro.exec(this.json.exclude.code, this);
  145. exclude = typeOf(v)==="array" ? v : [v];
  146. }
  147. //var count = (this.json.count) ? this.json.count : 0;
  148. var identityOpt;
  149. if( this.identityOptions ){
  150. identityOpt = this.identityOptions.getOptions();
  151. if (this.json.identityRange!=="all"){
  152. if ( !identityOpt.noUnit && (!identityOpt.units || !identityOpt.units.length) ){
  153. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  154. identityOpt.disabled = true;
  155. // return false;
  156. }
  157. }
  158. if ( !identityOpt.noUnit && this.json.dutyRange && this.json.dutyRange!=="all"){
  159. if (!identityOpt.dutys || !identityOpt.dutys.length){
  160. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  161. identityOpt.disabled = true;
  162. // return false;
  163. }
  164. }
  165. identityOpt.values = (this.json.isInput) ? [] : values;
  166. identityOpt.exclude = exclude;
  167. if( this.form.json.selectorStyle )identityOpt = Object.merge( identityOpt, this.form.json.selectorStyle );
  168. }
  169. var unitOpt;
  170. if( this.unitOptions ){
  171. unitOpt = this.unitOptions.getOptions();
  172. if (this.json.unitRange!=="all"){
  173. if ( !unitOpt.units || !unitOpt.units.length){
  174. this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  175. unitOpt.disabled = true;
  176. // return false;
  177. }
  178. }
  179. unitOpt.values = (this.json.isInput) ? [] : values;
  180. unitOpt.exclude = exclude;
  181. if( this.form.json.selectorStyle )unitOpt = Object.merge( unitOpt, this.form.json.selectorStyle );
  182. }
  183. var groupOpt;
  184. if( this.groupOptions ){
  185. groupOpt = this.groupOptions.getOptions();
  186. groupOpt.values = (this.json.isInput) ? [] : values;
  187. groupOpt.exclude = exclude;
  188. if( this.form.json.selectorStyle )groupOpt = Object.merge( groupOpt, this.form.json.selectorStyle );
  189. }
  190. //var selectUnits = this.getSelectRange();
  191. //if (this.json.selectType=="identity"){
  192. // var selectDutys = this.getSelectRangeDuty();
  193. //}
  194. //if (this.json.range!=="all"){
  195. // if (!selectUnits.length){
  196. // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  197. // return false;
  198. // }
  199. //}
  200. //if (this.json.selectType=="identity"){
  201. // if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
  202. // if (!selectDutys || !selectDutys.length){
  203. // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  204. // return false;
  205. // }
  206. // }
  207. //}
  208. var defaultOpt = {};
  209. if( this.json.events && typeOf(this.json.events) === "object" ){
  210. Object.each(this.json.events, function(e, key){
  211. if (e.code){
  212. if (this.options.selectorEvents.indexOf(key)!==-1){
  213. if( key === "postLoadSelector" ) {
  214. this.addEvent("loadSelector", function (selector) {
  215. return this.form.Macro.fire(e.code, selector);
  216. }.bind(this))
  217. }else if( key === "queryLoadSelector"){
  218. defaultOpt["onQueryLoad"] = function(target){
  219. return this.form.Macro.fire(e.code, target);
  220. }.bind(this)
  221. }else{
  222. defaultOpt["on"+key.capitalize()] = function(target){
  223. return this.form.Macro.fire(e.code, target);
  224. }.bind(this)
  225. }
  226. }
  227. }
  228. }.bind(this));
  229. }
  230. if( this.selectTypeList.length === 1 ){
  231. return Object.merge( {
  232. "type": this.selectTypeList[0],
  233. "onComplete": function(items){
  234. this.selectOnComplete(items);
  235. }.bind(this),
  236. "onCancel": this.selectOnCancel.bind(this),
  237. // "onLoad": this.selectOnLoad.bind(this),
  238. "onLoad": function(){
  239. //this 为 selector
  240. _self.selectOnLoad(this, this.selector );
  241. },
  242. "onClose": this.selectOnClose.bind(this)
  243. }, defaultOpt, identityOpt || unitOpt || groupOpt )
  244. }else if( this.selectTypeList.length > 1 ){
  245. var options = {
  246. "type" : "",
  247. "types" : this.selectTypeList,
  248. "onComplete": function(items){
  249. this.selectOnComplete(items);
  250. }.bind(this),
  251. "onCancel": this.selectOnCancel.bind(this),
  252. // "onLoad": this.selectOnLoad.bind(this),
  253. "onLoad": function(){
  254. //this 为 selector
  255. _self.selectOnLoad(this)
  256. },
  257. "onClose": this.selectOnClose.bind(this)
  258. };
  259. if( this.form.json.selectorStyle ){
  260. options = Object.merge( options, this.form.json.selectorStyle );
  261. }
  262. if( identityOpt )options.identityOptions = Object.merge( {}, defaultOpt, identityOpt );
  263. if( unitOpt )options.unitOptions = Object.merge( {}, defaultOpt, unitOpt );
  264. if( groupOpt )options.groupOptions = Object.merge( {}, defaultOpt, groupOpt );
  265. return options;
  266. }
  267. //return {
  268. // "type": this.json.selectType,
  269. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  270. // "values": (this.json.isInput) ? [] : values,
  271. // "count": count,
  272. // "units": selectUnits,
  273. // "dutys": (this.json.selectType=="identity") ? selectDutys : [],
  274. // "exclude" : exclude,
  275. // "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
  276. // "categoryType": this.json.categoryType || "unit",
  277. // "onComplete": function(items){
  278. // this.selectOnComplete(items);
  279. // }.bind(this),
  280. // "onCancel": this.selectOnCancel.bind(this),
  281. // "onLoad": this.selectOnLoad.bind(this),
  282. // "onClose": this.selectOnClose.bind(this)
  283. //};
  284. },
  285. selectOnComplete: function(items){
  286. var array = [];
  287. items.each(function(item){
  288. array.push(item.data);
  289. }.bind(this));
  290. var simple = this.json.storeRange === "simple";
  291. this.checkEmpower( array, function( data ){
  292. var values = [];
  293. data.each(function(d){
  294. values.push(MWF.org.parseOrgData(d, true, simple));
  295. }.bind(this));
  296. if (this.json.isInput){
  297. this.addData(values);
  298. }else{
  299. this.setData(values);
  300. }
  301. //this._setBusinessData(values);
  302. this.validationMode();
  303. this.validation();
  304. this.fireEvent("select");
  305. }.bind(this))
  306. },
  307. selectOnCancel: function(){
  308. this.validation();
  309. },
  310. selectOnLoad: function( selector ){
  311. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  312. this.fireEvent("loadSelector", [selector])
  313. },
  314. selectOnClose: function(){
  315. v = this._getBusinessData();
  316. if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  317. },
  318. clickSelect: function( ev ){
  319. if (this.readonly)return;
  320. if( layout.mobile ){
  321. setTimeout( function(){ //如果有输入法界面,这个时候页面的计算不对,所以等100毫秒
  322. var options = this.getOptions();
  323. if(options){
  324. if( this.selector && this.selector.loading ) {
  325. }else if( this.selector && this.selector.selector && this.selector.selector.active ){
  326. }else{
  327. this.selector = new MWF.O2Selector(this.form.app.content, options);
  328. }
  329. }
  330. }.bind(this), 100 )
  331. }else{
  332. var options = this.getOptions();
  333. if(options){
  334. if( this.selector && this.selector.loading ) {
  335. }else if( this.selector && this.selector.selector && this.selector.selector.active ){
  336. }else {
  337. this.selector = new MWF.O2Selector(this.form.app.content, options);
  338. }
  339. }
  340. }
  341. },
  342. resetData: function(){
  343. var v = this.getValue();
  344. //this.setData((v) ? v.join(", ") : "");
  345. this.setData(v);
  346. },
  347. isEmpty: function(){
  348. var data = this.getData();
  349. if( typeOf(data) !== "array" )return true;
  350. if( data.length === 0 )return true;
  351. return false;
  352. },
  353. getInputData: function(){
  354. if (this.json.isInput){
  355. if (this.combox)return this.combox.getData();
  356. return this._getBusinessData();
  357. }else{
  358. return this._getBusinessData();
  359. }
  360. },
  361. _loadNodeRead: function(){
  362. this.node.empty();
  363. var node = new Element("div").inject(this.node);
  364. },
  365. _searchConfirmPerson: function(item){
  366. var inforNode = item.inforNode || new Element("div");
  367. var simple = this.json.storeRange === "simple";
  368. if (item.data){
  369. var data = item.data;
  370. if( this.selectTypeList.contains("identity") && this.json.identityResultType === "person"){
  371. var dn = data.distinguishedName || data;
  372. if( dn.substr( dn.length-1, 1).toLowerCase() === "i" ){
  373. MWF.Actions.get("x_organization_assemble_express").listPersonWithIdentity({
  374. identityList : [dn]
  375. }, function(json){
  376. if( json.data.length > 0 ){
  377. if( data["person"] )json.data[0].id = data["person"];
  378. item.data = MWF.org.parseOrgData( json.data[0], true, simple );
  379. item.value = this.getDataText( item.data );
  380. if(item.node)item.node.set("text", item.value);
  381. }
  382. }.bind(this), null, false)
  383. }
  384. }
  385. if( item.data && ( item.data.createTime || item.data.updateTime ) ){
  386. item.data = MWF.org.parseOrgData( item.data, true, simple );
  387. }
  388. var text = "";
  389. var flag = item.data.distinguishedName.substr(item.data.distinguishedName.length-2, 2);
  390. switch (flag.toLowerCase()){
  391. case "@i":
  392. text = item.data.name+"("+item.data.unitName+")";
  393. break;
  394. case "@p":
  395. text = item.data.name+(item.data.employee ? "("+item.data.employee+")" : "");
  396. break;
  397. case "@u":
  398. text = item.data.levelName;
  399. break;
  400. case "@g":
  401. text = item.data.name;
  402. break;
  403. default:
  404. text = item.data.name;
  405. }
  406. inforNode.set({
  407. "styles": {"font-size": "14px", "color": ""},
  408. "text": text
  409. });
  410. }else{
  411. inforNode.set({
  412. "styles": {"font-size": "14px", "color": "#bd0000"},
  413. "text": MWF.xApplication.process.Xform.LP.noOrgObject
  414. });
  415. }
  416. if (!item.inforNode){
  417. new mBox.Tooltip({
  418. content: inforNode,
  419. setStyles: {content: {padding: 15, lineHeight: 20}},
  420. attach: item.node,
  421. transition: 'flyin'
  422. });
  423. item.inforNode = inforNode;
  424. }
  425. },
  426. getSearchOptions: function(){
  427. if( this.selectTypeList.length === 0 )return false;
  428. var identityOpt;
  429. if( this.identityOptions ){
  430. identityOpt = this.identityOptions.getSearchOptions();
  431. //if (this.json.identityRange!=="all"){
  432. // if ( !identityOpt.units || !identityOpt.units.length){
  433. // this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  434. // return false;
  435. // }
  436. //}
  437. //if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
  438. // if (!identityOpt.dutys || !identityOpt.dutys.length){
  439. // this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  440. // return false;
  441. // }
  442. //}
  443. }
  444. var unitOpt;
  445. if( this.unitOptions ){
  446. unitOpt = this.unitOptions.getSearchOptions();
  447. //if (this.json.unitRange!=="all"){
  448. // if ( !unitOpt.units || !unitOpt.units.length){
  449. // this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  450. // return false;
  451. // }
  452. //}
  453. }
  454. var groupOpt;
  455. if( this.groupOptions ){
  456. groupOpt = this.groupOptions.getOptions();
  457. }
  458. if( this.selectTypeList.length === 1 ){
  459. return Object.merge( {
  460. "type": this.selectTypeList[0]
  461. }, identityOpt || unitOpt || groupOpt )
  462. }else if( this.selectTypeList.length > 1 ){
  463. var options = {
  464. "type" : "",
  465. "types" : this.selectTypeList
  466. };
  467. if( identityOpt )options.identityOptions = identityOpt;
  468. if( unitOpt )options.unitOptions = unitOpt;
  469. if( groupOpt )options.groupOptions = groupOpt;
  470. return options;
  471. }
  472. //return {
  473. // "type": this.json.selectType,
  474. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  475. // "values": (this.json.isInput) ? [] : values,
  476. // "count": count,
  477. // "units": selectUnits,
  478. // "dutys": (this.json.selectType=="identity") ? selectDutys : [],
  479. // "exclude" : exclude,
  480. // "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
  481. // "categoryType": this.json.categoryType || "unit",
  482. // "onComplete": function(items){
  483. // this.selectOnComplete(items);
  484. // }.bind(this),
  485. // "onCancel": this.selectOnCancel.bind(this),
  486. // "onLoad": this.selectOnLoad.bind(this),
  487. // "onClose": this.selectOnClose.bind(this)
  488. //};
  489. },
  490. _searchOptions: function(value, callback){
  491. //var options = {
  492. // "type": this.json.selectType,
  493. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  494. // "units": this.selectUnits,
  495. // "dutys": (this.json.selectType=="identity") ? this.selectDutys : []
  496. //};
  497. var options = this.getSearchOptions();
  498. if (!this.comboxFilter) this.comboxFilter = new MWF.O2SelectorFilter(value, options);
  499. this.comboxFilter.filter(value, function(data){
  500. data.map(function(d){
  501. var value = Object.clone(d);
  502. d.value = value;
  503. var flag = d.distinguishedName.substr(d.distinguishedName.length-2, 2);
  504. switch (flag.toLowerCase()){
  505. case "@i":
  506. d.text = d.name+"("+d.unitName+")";
  507. break;
  508. case "@p":
  509. d.text = d.name+(d.employee ? "("+d.employee+")" : "");
  510. break;
  511. case "@u":
  512. d.text = d.name;
  513. break;
  514. case "@g":
  515. d.text = d.name;
  516. break;
  517. default:
  518. d.text = d.name;
  519. }
  520. });
  521. if (callback) callback(data);
  522. });
  523. },
  524. _resetNodeInputEdit: function(){
  525. var node = new Element("div", {
  526. "styles": {
  527. "overflow": "hidden",
  528. //"position": "relative",
  529. "margin-right": "20px"
  530. }
  531. }).inject(this.node, "after");
  532. this.node.destroy();
  533. this.node = node;
  534. },
  535. _loadNodeInputEdit: function(){
  536. debugger;
  537. this.node.setStyle("overflow","visible");
  538. var input=null;
  539. MWF.require("MWF.widget.Combox", function(){
  540. this.combox = input = new MWF.widget.Combox({
  541. "count": this.json.count || 0,
  542. "splitShow": this.json.splitShow || ", ",
  543. "onCommitInput": function(item){
  544. this._searchConfirmPerson(item);
  545. //this.fireEvent("change");
  546. }.bind(this),
  547. "onChange": function(){
  548. this._setBusinessData(this.getInputData());
  549. this.fireEvent("change");
  550. }.bind(this),
  551. "optionsMethod": this._searchOptions.bind(this)
  552. });
  553. }.bind(this), false);
  554. input.setStyles({
  555. "background": "transparent",
  556. "border": "0px"
  557. });
  558. input.set(this.json.properties);
  559. if (!this.json.preprocessing) this._resetNodeInputEdit();
  560. this.node.empty();
  561. input.inject(this.node);
  562. this.node.set({
  563. "id": this.json.id,
  564. "MWFType": this.json.type
  565. });
  566. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
  567. this.iconNode = new Element("div", {
  568. "styles": this.form.css[this.iconStyle],
  569. "events": {
  570. "click": function (ev) {
  571. this.clickSelect(ev);
  572. }.bind(this)
  573. //this.clickSelect.bind(this)
  574. }
  575. }).inject(this.node, "before");
  576. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  577. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  578. }
  579. this.combox.addEvent("change", function(){
  580. this.validationMode();
  581. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  582. }.bind(this));
  583. },
  584. _resetNodeEdit: function(){
  585. var input = new Element("div", {
  586. "styles": {
  587. "background": "transparent",
  588. "border": "0px",
  589. "min-height": "24px"
  590. }
  591. });
  592. var node = new Element("div", {"styles": {
  593. "overflow": "hidden",
  594. "position": "relative",
  595. "margin-right": "20px",
  596. "min-height": "24px"
  597. }}).inject(this.node, "after");
  598. input.inject(node);
  599. this.node.destroy();
  600. this.node = node;
  601. },
  602. _loadNodeEdit: function(){
  603. if (!this.json.preprocessing) this._resetNodeEdit();
  604. var input = this.node.getFirst();
  605. input.set(this.json.properties);
  606. this.node.set({
  607. "id": this.json.id,
  608. "MWFType": this.json.type,
  609. "events": {
  610. "click": function (ev) {
  611. this.clickSelect(ev);
  612. }.bind(this)
  613. //this.clickSelect.bind(this)
  614. }
  615. });
  616. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
  617. this.iconNode = new Element("div", {
  618. "styles": this.form.css[this.iconStyle],
  619. "events": {
  620. "click": function (ev) {
  621. this.clickSelect(ev);
  622. }.bind(this)
  623. //this.clickSelect.bind(this)
  624. }
  625. }).inject(this.node, "before");
  626. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  627. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  628. }
  629. this.node.getFirst().setStyle("height", "auto");
  630. this.node.getFirst().addEvent("change", function(){
  631. this.validationMode();
  632. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  633. }.bind(this));
  634. },
  635. getDataText: function(data){
  636. if (typeOf(data)=="string") return data;
  637. var text = "";
  638. var flag = data.distinguishedName.substr(data.distinguishedName.length-2, 2);
  639. switch (flag.toLowerCase()){
  640. case "@i":
  641. text = data.name+"("+data.unitName+")";
  642. break;
  643. case "@p":
  644. text = data.name+ (data.employee ? ("("+data.employee+")") : "");
  645. break;
  646. case "@u":
  647. text = data.name;
  648. break;
  649. case "@g":
  650. text = data.name;
  651. break;
  652. default:
  653. text = data.name;
  654. }
  655. return text;
  656. },
  657. addData: function(value){
  658. if (!value) return false;
  659. var simple = this.json.storeRange === "simple";
  660. value.each(function(v){
  661. var vtype = typeOf(v);
  662. if (vtype==="string"){
  663. var data;
  664. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, v, false);
  665. if (data) this.combox.addNewValue(this.getDataText(data), data);
  666. }
  667. if (vtype==="object"){
  668. var d = MWF.org.parseOrgData(v, true, simple);
  669. this.combox.addNewValue(this.getDataText(d), d);
  670. }
  671. }.bind(this));
  672. },
  673. setData: function(value){
  674. if (!value) return false;
  675. var oldValues = this.getData();
  676. var values = [];
  677. var comboxValues = [];
  678. var simple = this.json.storeRange === "simple";
  679. var type = typeOf(value);
  680. if (type==="array"){
  681. value.each(function(v){
  682. var vtype = typeOf(v);
  683. var data = null;
  684. if (vtype==="string"){
  685. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  686. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, v, false);
  687. }
  688. if (vtype==="object") {
  689. data = MWF.org.parseOrgData(v, true, simple);
  690. if(data.woPerson)delete data.woPerson;
  691. }
  692. if (data){
  693. values.push(data);
  694. comboxValues.push({"text": this.getDataText(data),"value": data});
  695. }
  696. }.bind(this));
  697. }
  698. if (type==="string"){
  699. var vData;
  700. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  701. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, value, false);
  702. if (vData){
  703. values.push(vData);
  704. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  705. }
  706. }
  707. if (type==="object"){
  708. var vData = MWF.org.parseOrgData(value, true, simple);
  709. if(vData.woPerson)delete vData.woPerson;
  710. values.push( vData );
  711. comboxValues.push({"text": this.getDataText(value),"value": vData});
  712. }
  713. var change = false;
  714. if (oldValues.length && values.length){
  715. if (oldValues.length === values.length){
  716. for (var i=0; i<oldValues.length; i++){
  717. if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
  718. change = true;
  719. break;
  720. }
  721. }
  722. }else{
  723. change = true;
  724. }
  725. }else if (values.length || oldValues.length) {
  726. change = true;
  727. }
  728. this._setBusinessData(values);
  729. if (change) this.fireEvent("change");
  730. if (this.json.isInput){
  731. if (this.combox){
  732. this.combox.clear();
  733. this.combox.addNewValues(comboxValues);
  734. }else{
  735. var node = this.node.getFirst();
  736. if (node){
  737. node.empty();
  738. comboxValues.each(function(v, i){
  739. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  740. }.bind(this));
  741. }
  742. }
  743. //
  744. // this.combox.clear();
  745. // values.each(function(v){
  746. // var vtype = typeOf(v);
  747. // if (vtype==="string"){
  748. // var data;
  749. // this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), null, v, false);
  750. // if (data) this.combox.addNewValue(this.getDataText(data), data);
  751. // }
  752. // if (vtype==="object"){
  753. // this.combox.addNewValue(this.getDataText(v), v);
  754. // }
  755. // }.bind(this));
  756. }else{
  757. if (this.node.getFirst()){
  758. var node = this.node.getFirst();
  759. node.empty();
  760. this.loadOrgWidget(values, node)
  761. }else{
  762. this.node.empty();
  763. this.loadOrgWidget(values, this.node);
  764. }
  765. }
  766. },
  767. creteShowNode: function(data, islast){
  768. var nodeText = (data.text) ? data.text : data;
  769. if (!islast) nodeText = nodeText + (this.json.splitShow || ", ");
  770. var node = new Element("div", {
  771. "styles": {
  772. "float": "left",
  773. "margin-right": "5px"
  774. },
  775. "text": nodeText
  776. });
  777. var text = "";
  778. if (data.value){
  779. var flag = data.value.distinguishedName.substr(data.value.distinguishedName.length-2, 2);
  780. switch (flag.toLowerCase()){
  781. case "@i":
  782. text = data.value.name+"("+data.value.unitName+")";
  783. break;
  784. case "@p":
  785. text = data.value.name+ (data.value.employee ? "("+data.value.employee+")" : "");
  786. break;
  787. case "@u":
  788. text = data.value.levelName;
  789. break;
  790. case "@g":
  791. text = data.value.name;
  792. break;
  793. default:
  794. text = data.value.name;
  795. }
  796. var inforNode = new Element("div").set({
  797. "styles": {"font-size": "14px", "color": ""},
  798. "text": text
  799. });
  800. new mBox.Tooltip({
  801. content: inforNode,
  802. setStyles: {content: {padding: 15, lineHeight: 20}},
  803. attach: node,
  804. transition: 'flyin'
  805. });
  806. }
  807. return node;
  808. },
  809. _setValue: function(value){
  810. if (value.length==1 && !(value[0])) value=[];
  811. var values = [];
  812. var comboxValues = [];
  813. var type = typeOf(value);
  814. var simple = this.json.storeRange === "simple";
  815. if (type==="array"){
  816. value.each(function(v){
  817. var data=null;
  818. var vtype = typeOf(v);
  819. if (vtype==="string"){
  820. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  821. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, v, false);
  822. }
  823. if (vtype==="object") data = v;
  824. if (data){
  825. var d = MWF.org.parseOrgData(data, true, simple)
  826. values.push(d);
  827. comboxValues.push({"text": this.getDataText(d),"value": d});
  828. }
  829. }.bind(this));
  830. }
  831. if (type==="string"){
  832. var vData;
  833. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  834. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true,simple); }.bind(this), error, value, false);
  835. if (vData){
  836. values.push(vData);
  837. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  838. }
  839. }
  840. if (type==="object"){
  841. var v = MWF.org.parseOrgData(value, true, simple)
  842. values.push(v);
  843. comboxValues.push({"text": this.getDataText(v),"value": v});
  844. }
  845. this._setBusinessData(values);
  846. if (this.json.isInput){
  847. if (this.combox){
  848. this.combox.clear();
  849. this.combox.addNewValues(comboxValues);
  850. // values.each(function(v){
  851. // if (typeOf(v)=="string"){
  852. // this.combox.addNewValue(v);
  853. // }else{
  854. // this.combox.addNewValue(this.getDataText(v), v);
  855. // }
  856. // }.bind(this));
  857. }else{
  858. var node = this.node.getFirst();
  859. if (node){
  860. node.empty();
  861. comboxValues.each(function(v, i){
  862. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  863. }.bind(this));
  864. }
  865. }
  866. }else{
  867. if (this.node.getFirst()){
  868. var node = this.node.getFirst();
  869. this.loadOrgWidget(values, node)
  870. }else{
  871. this.loadOrgWidget(values, this.node);
  872. }
  873. }
  874. //if (this.readonly) this.loadOrgWidget(values, this.node)
  875. //this.node.set("text", value);
  876. },
  877. getValueMethod: function(value){
  878. if (value){
  879. var flag = value.substr(value.length-2, 2);
  880. switch (flag.toLowerCase()){
  881. case "@i":
  882. return "getIdentity";
  883. case "@p":
  884. return "getPerson";
  885. case "@u":
  886. return "getUnit";
  887. case "@g":
  888. return "getGroup";
  889. default:
  890. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  891. }
  892. }
  893. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  894. },
  895. loadOrgWidget: function(value, node){
  896. var disableInfor = layout.mobile ? true : false;
  897. var height = node.getStyle("height").toInt();
  898. if (node.getStyle("overflow")==="visible" && !height) node.setStyle("overflow", "hidden");
  899. if (value && value.length){
  900. value.each(function(data){
  901. var flag = data.distinguishedName.substr(data.distinguishedName.length-2, 2);
  902. var copyData = Object.clone(data);
  903. if( this.json.displayTextScript && this.json.displayTextScript.code ){
  904. this.currentData = copyData;
  905. var displayName = this.form.Macro.exec(this.json.displayTextScript.code, this);
  906. if( displayName ){
  907. copyData.displayName = displayName;
  908. }
  909. this.currentData = null;
  910. }
  911. var widget;
  912. switch (flag.toLowerCase()){
  913. case "@i":
  914. widget = new MWF.widget.O2Identity(copyData, node, {"style": "xform","lazy":true,"disableInfor" : disableInfor});
  915. break;
  916. case "@p":
  917. widget = new MWF.widget.O2Person(copyData, node, {"style": "xform","lazy":true,"disableInfor" : disableInfor});
  918. break;
  919. case "@u":
  920. widget = new MWF.widget.O2Unit(copyData, node, {"style": "xform","lazy":true,"disableInfor" : disableInfor});
  921. break;
  922. case "@g":
  923. widget = new MWF.widget.O2Group(copyData, node, {"style": "xform","lazy":true,"disableInfor" : disableInfor});
  924. break;
  925. default:
  926. widget = new MWF.widget.O2Other(copyData, node, {"style": "xform","lazy":true,"disableInfor" : disableInfor});
  927. }
  928. widget.field = this;
  929. if( layout.mobile ){
  930. widget.node.setStyles({
  931. "float" : "none"
  932. })
  933. }
  934. }.bind(this));
  935. }
  936. },
  937. _loadStyles: function(){
  938. if (this.readonly || this.json.isReadonly){
  939. if (this.json.styles) this.node.setStyles(this.json.styles);
  940. }else{
  941. if (this.json.styles) this.node.setStyles(this.json.styles);
  942. if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
  943. if (this.iconNode && this.iconNode.offsetParent !== null ){
  944. var size = this.node.getSize();
  945. this.iconNode.setStyle("height", ""+size.y+"px");
  946. }
  947. }
  948. },
  949. checkEmpower : function( data, callback ){
  950. if( typeOf(data)==="array" && this.identityOptions && this.json.isCheckEmpower && this.json.identityResultType === "identity" ) {
  951. var empowerChecker = new MWF.APPOrg.EmpowerChecker(this.form, this.json);
  952. empowerChecker.load(data, callback);
  953. }else{
  954. if( callback )callback( data );
  955. }
  956. }
  957. });
  958. MWF.APPOrg.EmpowerChecker = new Class({
  959. Implements: [Events],
  960. initialize: function (form, json) {
  961. this.form = form;
  962. this.json = json;
  963. this.css = this.form.css;
  964. this.checkedAllItems = true;
  965. },
  966. load : function( data, callback, container ){
  967. if( typeOf(data)==="array" && this.json.isCheckEmpower && this.json.identityResultType === "identity" ){
  968. var array = [];
  969. data.each( function( d ){
  970. if( d.distinguishedName ){
  971. var flag = d.distinguishedName.substr(d.distinguishedName.length-1, 1).toLowerCase();
  972. if( flag === "i" ){
  973. array.push( d.distinguishedName )
  974. }
  975. }
  976. }.bind(this));
  977. if( array.length > 0 ){
  978. o2.Actions.get("x_organization_assemble_express").listEmpowerWithIdentity({
  979. "application" : (this.form.businessData.work || this.form.businessData.workCompleted).application,
  980. "process" : (this.form.businessData.work || this.form.businessData.workCompleted).process,
  981. "work" : (this.form.businessData.work || this.form.businessData.workCompleted).id,
  982. "identityList" : array
  983. }, function( json ){
  984. var arr = [];
  985. json.data.each( function(d){
  986. if(d.fromIdentity !== d.toIdentity )arr.push(d);
  987. });
  988. if( arr.length > 0 ){
  989. this.openSelectEmpowerDlg( arr, data, callback, container );
  990. }else{
  991. if( callback )callback( data );
  992. }
  993. }.bind(this), function(){
  994. if( callback )callback( data );
  995. }.bind(this))
  996. }else{
  997. if( callback )callback( data );
  998. }
  999. }else{
  1000. if( callback )callback( data );
  1001. }
  1002. },
  1003. getIgnoreEmpowerArray : function( callback ){
  1004. var array = [];
  1005. if( this.empowerSelectNodes && this.empowerSelectNodes.length ){
  1006. this.empowerSelectNodes.each(function(node){
  1007. if( !node.retrieve("isSelected") ){
  1008. var d = node.retrieve("data");
  1009. array.push( d.fromIdentity );
  1010. }
  1011. }.bind(this));
  1012. }
  1013. if( callback )callback( array );
  1014. return array;
  1015. },
  1016. setIgnoreEmpowerFlag : function(data, callback){
  1017. debugger;
  1018. var ignoreList = this.getIgnoreEmpowerArray();
  1019. for( var i=0; i<data.length; i++ ){
  1020. var d = data[i];
  1021. if( ignoreList.indexOf( d.distinguishedName ) > -1 ){
  1022. d.ignoreEmpower = true;
  1023. }else if( d.ignoreEmpower ){
  1024. delete d.ignoreEmpower;
  1025. }
  1026. }
  1027. if( callback )callback( data );
  1028. },
  1029. replaceEmpowerIdentity : function(data, callback){
  1030. debugger;
  1031. var empowerData = {};
  1032. this.empowerSelectNodes.each(function(node){
  1033. if( node.retrieve("isSelected") ){
  1034. var d = node.retrieve("data");
  1035. empowerData[ d.fromIdentity ] = d;
  1036. }
  1037. }.bind(this));
  1038. if( Object.keys(empowerData).length === 0 ){
  1039. callback( data );
  1040. }else{
  1041. var identityList = [];
  1042. for( var key in empowerData ){
  1043. identityList.push( empowerData[key].toIdentity );
  1044. }
  1045. o2.Actions.get("x_organization_assemble_express").listIdentity({ "identityList" : identityList }, function(json){
  1046. var newData = data.clone();
  1047. var d = {};
  1048. json.data.each( function(j){
  1049. d[j.distinguishedName] = j;
  1050. });
  1051. for( var i=0; i<newData.length; i++ ){
  1052. var nd = newData[i];
  1053. if( nd.distinguishedName && empowerData[nd.distinguishedName]){
  1054. if( d[empowerData[nd.distinguishedName].toIdentity] ){
  1055. newData[i] = d[empowerData[nd.distinguishedName].toIdentity]
  1056. }
  1057. }
  1058. }
  1059. callback( newData );
  1060. },function(){
  1061. callback( data );
  1062. });
  1063. }
  1064. },
  1065. openSelectEmpowerDlg : function( data, orginData, callback, container ){
  1066. if( layout.mobile ){
  1067. this.openSelectEmpowerDlg_mobile(data, orginData, callback, container);
  1068. }else{
  1069. this.openSelectEmpowerDlg_pc(data, orginData, callback, container);
  1070. }
  1071. },
  1072. openSelectEmpowerDlg_mobile : function( data, orginData, callback, container ){
  1073. debugger;
  1074. var that = this;
  1075. //处理json
  1076. var subItemList = [];
  1077. // var empowerMap = {};
  1078. // var selectableItems = [];
  1079. var valueList = [];
  1080. data.each( function( d ){
  1081. subItemList.push({
  1082. "name" : d.fromIdentity.split("@")[0] + " 授权给 " + d.toIdentity.split("@")[0],
  1083. "id" : d.fromIdentity + "#" + d.toIdentity
  1084. })
  1085. valueList.push({
  1086. "name" : d.fromIdentity.split("@")[0] + " 授权给 " + d.toIdentity.split("@")[0],
  1087. "id" : d.fromIdentity + "#" + d.toIdentity
  1088. })
  1089. // empowerMap[ d.fromIdentity ] = d.toIdentity;
  1090. }.bind(this));
  1091. if( subItemList.length === 0 ){
  1092. callback();
  1093. return;
  1094. }
  1095. var empowerList = Array.clone(subItemList);
  1096. // selectableItems.push({
  1097. // "empowerMap" : empowerMap,
  1098. // "subItemList" : subItemList
  1099. // });
  1100. // if( selectableItems.length === 0 ){
  1101. // callback();
  1102. // return;
  1103. // }
  1104. // var empowerList = Array.clone(selectableItems);
  1105. o2.xDesktop.requireApp("Template", "Selector.Custom", function () {
  1106. var options = {
  1107. "count": 0,
  1108. "title": MWF.xApplication.process.Xform.LP.selectEmpower,
  1109. "selectAllEnable" : true,
  1110. "selectableItems": subItemList,
  1111. "expand": false,
  1112. "category": false,
  1113. "values": valueList,
  1114. "zIndex" : 3001,
  1115. "closeOnclickOk" : true,
  1116. "onComplete": function (items) {
  1117. debugger;
  1118. var arr = [];
  1119. items.each(function (item) {
  1120. arr.push( item.data.id )
  1121. }.bind(this));
  1122. var ignoreList = [];
  1123. empowerList.each( function (obj) {
  1124. if( arr.indexOf( obj.id ) === -1 )ignoreList.push( obj.id.split("#")[0] )
  1125. });
  1126. for( var i=0; i<orginData.length; i++ ){
  1127. var d = orginData[i];
  1128. if( ignoreList.indexOf( d.distinguishedName ) > -1 ){
  1129. d.ignoreEmpower = true;
  1130. }else if( d.ignoreEmpower ){
  1131. delete d.ignoreEmpower;
  1132. }
  1133. }
  1134. if( callback )callback( orginData );
  1135. // empowerList.each( function(obj){
  1136. // var list = obj.subItemList.filter(function(item, index){
  1137. // return !arr.contains( item.id );
  1138. // }.bind(this));
  1139. // ignoreList = ignoreList.map(function(item,index){
  1140. // return item.id.split("#")[1];
  1141. // })
  1142. // });
  1143. // empowerList.each( function(obj){
  1144. // var org = that.orgItemsObject[obj.orgId];
  1145. // // if( obj.ignoreList.length > 0 ){
  1146. // var data = org.getData();
  1147. // for( var i=0; i<data.length; i++ ){
  1148. // var d = data[i];
  1149. // if( obj.ignoreList.indexOf( d.distinguishedName ) > -1 ){
  1150. // d.ignoreEmpower = true;
  1151. // }else if( d.ignoreEmpower ){
  1152. // delete d.ignoreEmpower;
  1153. // }
  1154. // }
  1155. // org.setData( data );
  1156. // }
  1157. // if( obj.empowerMap ){
  1158. // var data = org.getValue();
  1159. // for( var i=0; i<data.length; i++ ){
  1160. // var d = data[i];
  1161. // if( obj.empowerMap[ d.distinguishedName ] ){
  1162. // d.empowerToIdentity = obj.empowerMap[ d.distinguishedName ];
  1163. // }
  1164. // }
  1165. // org.empowerData = Array.clone(data);
  1166. // }
  1167. // if(callback)callback();
  1168. // })
  1169. }.bind(this)
  1170. };
  1171. if( this.form.json.selectorStyle ){
  1172. Object.merge(options, this.form.json.selectorStyle );
  1173. }
  1174. options.flatCategory = false;
  1175. var selector = new o2.xApplication.Template.Selector.Custom($(document.body), options);
  1176. selector.load();
  1177. }.bind(this))
  1178. },
  1179. openSelectEmpowerDlg_pc : function( data, orginData, callback, container ){
  1180. var node = new Element("div", {"styles": this.css.empowerAreaNode});
  1181. var html = "<div style=\"line-height: 20px; color: #333333; overflow: hidden\">"+MWF.xApplication.process.Xform.LP.empowerDlgText+"</div>";
  1182. html += "<div style=\"margin-bottom:10px; margin-top:10px; overflow-y:auto;\"></div>";
  1183. node.set("html", html);
  1184. var itemNode = node.getLast();
  1185. this.getEmpowerItems(itemNode, data);
  1186. node.inject( container || this.form.app.content);
  1187. var dlg = o2.DL.open({
  1188. "title": MWF.xApplication.process.Xform.LP.selectEmpower,
  1189. "style": this.form.json.dialogStyle || "user",
  1190. "isResize": true,
  1191. "content": node,
  1192. "width": 630,
  1193. //"height" : 500,
  1194. "buttonList": [
  1195. {
  1196. "type" : "ok",
  1197. "text": MWF.LP.process.button.ok,
  1198. "action": function(d, e){
  1199. //this.replaceEmpowerIdentity( orginData, callback ); //直接替换已授权的人,已废弃
  1200. this.setIgnoreEmpowerFlag( orginData, callback ); //然后设置忽略的人的标志
  1201. dlg.close();
  1202. }.bind(this)
  1203. },
  1204. {
  1205. "type" : "cancel",
  1206. "text": MWF.LP.process.button.cancel,
  1207. "action": function(){dlg.close();}
  1208. }
  1209. ],
  1210. "onPostShow": function(){
  1211. var selectNode = this.createSelectAllEmpowerNode();
  1212. selectNode.inject( dlg.button );
  1213. if( layout.mobile ){
  1214. dlg.node.inject( $(document.body) );
  1215. dlg.node.setStyles({
  1216. "width":"100%",
  1217. "height": "100%",
  1218. "top" : "0px",
  1219. "left" : "0px"
  1220. });
  1221. var y = dlg.node.getSize().y - 190;
  1222. itemNode.setStyle("height",y+"px");
  1223. dlg.options.contentHeight = dlg.node.getSize().y - 100 ; //+100;
  1224. dlg.setContentSize();
  1225. }else{
  1226. dlg.content.setStyle("overflow","hidden");
  1227. var y = Math.min(300, itemNode.getSize().y);
  1228. var marginTop = itemNode.getStyle("margin-top");
  1229. var marginBottom = itemNode.getStyle("margin-bottom");
  1230. itemNode.setStyle("height",y+"px");
  1231. dlg.options.contentHeight = y + 30 + 20 ; //+100;
  1232. dlg.setContentSize();
  1233. dlg.node.setStyles({
  1234. "height": ""+(dlg.options.height) +"px"
  1235. });
  1236. dlg.reCenter();
  1237. }
  1238. }.bind(this)
  1239. });
  1240. },
  1241. getEmpowerItems: function(itemNode, data){
  1242. var _self = this;
  1243. this.empowerSelectNodes = [];
  1244. var count = 1;
  1245. var node;
  1246. data.each(function( d ){
  1247. if(d.fromIdentity == d.toIdentity )return;
  1248. if( count % 2 === 1 ){
  1249. node = new Element("div", {"styles": this.css.empowerItemOddNode}).inject(itemNode);
  1250. node.store("nodeType","Odd");
  1251. //node.setStyle("margin-right","10px");
  1252. }else{
  1253. node = new Element("div", {"styles": this.css.empowerItemEvenNode}).inject(itemNode);
  1254. node.store("nodeType","Even");
  1255. }
  1256. count++;
  1257. this.empowerSelectNodes.push( node );
  1258. node.store("data", d);
  1259. var iconNode = new Element("div.empowerItemIconNode", {"styles": this.css.empowerItemIconNode}).inject(node);
  1260. node.store("iconNode",iconNode);
  1261. var contentNode = new Element("div.empowerItemContentNode", {"styles": this.css.empowerItemContentNode}).inject(node);
  1262. var formIdentityNode = new Element("div.empowerItemPersonNode", {"styles": this.css.empowerItemPersonNode, text : d.fromIdentity.split("@")[0] }).inject(contentNode);
  1263. var titleNode = new Element("div.empowerItemTitleNode", {"styles": this.css.empowerItemTitleNode, text : MWF.xApplication.process.Xform.LP.empowerTo }).inject(contentNode);
  1264. var toIdentityNode = new Element("div.empowerItemPersonNode", {"styles": this.css.empowerItemPersonNode, text : d.toIdentity.split("@")[0] }).inject(contentNode);
  1265. node.addEvents({
  1266. "mouseover": function(){
  1267. var isSelected = this.retrieve("isSelected");
  1268. if (!isSelected){
  1269. this.setStyles(_self.css[ "empowerItem"+this.retrieve("nodeType")+"Node_over" ]);
  1270. if( _self.css.empowerItemIconNode_over ){
  1271. var iconNode = this.retrieve("iconNode");
  1272. if(iconNode)iconNode.setStyles(_self.css.empowerItemIconNode_over);
  1273. }
  1274. }
  1275. },
  1276. "mouseout": function(){
  1277. var isSelected = this.retrieve("isSelected");
  1278. if (!isSelected){
  1279. this.setStyles(_self.css[ "empowerItem"+this.retrieve("nodeType")+"Node" ])
  1280. if( _self.css.empowerItemIconNode_over ){
  1281. var iconNode = this.retrieve("iconNode");
  1282. if(iconNode)iconNode.setStyles(_self.css.empowerItemIconNode);
  1283. }
  1284. }
  1285. },
  1286. "click": function(){
  1287. var isSelected = this.retrieve("isSelected");
  1288. if (isSelected){
  1289. _self.unselectEmpowerItem( this)
  1290. }else{
  1291. _self.selectEmpowerItem(this)
  1292. }
  1293. }
  1294. });
  1295. if( this.checkedAllItems )node.click();
  1296. }.bind(this));
  1297. },
  1298. unselectEmpowerItem : function( itemNode ){
  1299. itemNode.store("isSelected", false);
  1300. itemNode.setStyles( this.css[ "empowerItem"+itemNode.retrieve("nodeType")+"Node" ] );
  1301. itemNode.getElements("div").each( function( div ){
  1302. var className = div.get("class");
  1303. if( className && this.css[className] )div.setStyles( this.css[className] )
  1304. }.bind(this))
  1305. },
  1306. selectEmpowerItem : function( itemNode ){
  1307. itemNode.store("isSelected", true);
  1308. itemNode.setStyles( this.css[ "empowerItem"+itemNode.retrieve("nodeType")+"Node_selected" ] );
  1309. itemNode.getElements("div").each( function( div ){
  1310. var className = div.get("class");
  1311. if( className && this.css[className+"_selected"] )div.setStyles( this.css[className+"_selected"] )
  1312. }.bind(this))
  1313. },
  1314. createSelectAllEmpowerNode : function(){
  1315. var _self = this;
  1316. var node = new Element("div", {
  1317. styles : this.css.empowerSelectAllItemNode,
  1318. text : MWF.xApplication.process.Xform.LP.selectAll
  1319. });
  1320. node.addEvents({
  1321. "mouseover": function(){
  1322. var isSelected = this.retrieve("isSelected");
  1323. if (!isSelected) this.setStyles(_self.css.empowerSelectAllItemNode_over);
  1324. },
  1325. "mouseout": function(){
  1326. var isSelected = this.retrieve("isSelected");
  1327. if (!isSelected) this.setStyles(_self.css.empowerSelectAllItemNode)
  1328. },
  1329. "click": function(){
  1330. var isSelected = this.retrieve("isSelected");
  1331. if (isSelected){
  1332. this.store("isSelected", false);
  1333. this.setStyles( _self.css.empowerSelectAllItemNode );
  1334. _self.empowerSelectNodes.each( function(itemNode){
  1335. _self.unselectEmpowerItem(itemNode)
  1336. }.bind(this))
  1337. }else{
  1338. this.store("isSelected", true);
  1339. this.setStyles( _self.css.empowerSelectAllItemNode_selected );
  1340. _self.empowerSelectNodes.each( function(itemNode){
  1341. _self.selectEmpowerItem(itemNode)
  1342. }.bind(this))
  1343. }
  1344. }
  1345. });
  1346. if( this.checkedAllItems ){
  1347. node.store("isSelected", true);
  1348. node.setStyles( _self.css.empowerSelectAllItemNode_selected );
  1349. }
  1350. return node;
  1351. }
  1352. });
  1353. MWF.APPOrg.GroupOptions = new Class({
  1354. Implements: [Events],
  1355. initialize: function (form, json) {
  1356. this.form = form;
  1357. this.json = json;
  1358. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1359. },
  1360. getOptions: function(){
  1361. var count = (this.json.groupCount) ? this.json.groupCount : 0;
  1362. if( this.json.groupRange==="group" ){
  1363. return {
  1364. "count": count,
  1365. "include": this.getSelectRange( true )
  1366. }
  1367. }else{
  1368. return {
  1369. "count": count
  1370. }
  1371. }
  1372. },
  1373. getSearchOptions : function(){
  1374. return {};
  1375. },
  1376. getSelectRange : function( refresh ){
  1377. if( !this.selectRange || refresh){
  1378. this.selectRange = this._getSelectRange();
  1379. }
  1380. return this.selectRange;
  1381. },
  1382. _getSelectRange : function(){
  1383. var rangeValues = [];
  1384. if (this.json.groupRangeKey && this.json.groupRangeKey.code){
  1385. var v = this.form.Macro.exec(this.json.groupRangeKey.code, this);
  1386. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1387. rangeValues = v;
  1388. //v.each(function(d){
  1389. // if (d){
  1390. // if (typeOf(d)==="string"){
  1391. // var data;
  1392. // this.orgAction.getGroup(function(json){ data = json.data }.bind(this), null, d, false);
  1393. // rangeValues.push(data);
  1394. // }else{
  1395. // rangeValues.push(d);
  1396. // }
  1397. // }
  1398. //}.bind(this));
  1399. }
  1400. return rangeValues;
  1401. }
  1402. });
  1403. MWF.APPOrg.UnitOptions = new Class({
  1404. Implements: [Events],
  1405. initialize : function( form, json ){
  1406. this.form = form;
  1407. this.json = json;
  1408. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1409. },
  1410. getOptions: function(){
  1411. var count = (this.json.unitCount) ? this.json.unitCount : 0;
  1412. var selectUnits = this.getSelectRange( true );
  1413. return {
  1414. "count": count,
  1415. "units": selectUnits,
  1416. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  1417. "expandSubEnable" : (this.json.unitExpandSubEnable=="no") ? false : true
  1418. };
  1419. },
  1420. getSearchOptions : function(){
  1421. var selectUnits = this.getSelectRange( true );
  1422. return {
  1423. "units": selectUnits,
  1424. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType
  1425. };
  1426. },
  1427. getSelectRange : function( refresh ){
  1428. if( !this.selectRange || refresh){
  1429. this.selectRange = this._getSelectRange();
  1430. }
  1431. return this.selectRange;
  1432. },
  1433. _getSelectRange : function(){
  1434. if (this.json.unitRange==="unit"){
  1435. return this.getScriptSelectUnit();
  1436. }
  1437. if (this.json.unitRange==="draftUnit"){
  1438. var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
  1439. if (!dn){
  1440. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1441. var ids = [];
  1442. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1443. return this.getNextSelectUnit(ids);
  1444. }else{
  1445. return [];
  1446. }
  1447. }else{
  1448. return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
  1449. }
  1450. }
  1451. if (this.json.unitRange==="currentUnit"){
  1452. if (this.form.app.currentTask){
  1453. return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
  1454. }else{
  1455. if (this.form.app.taskList && this.form.app.taskList.length){
  1456. var ids = [];
  1457. this.form.app.taskList.each(function(task){ ids.push(task.identity); });
  1458. return this.getNextSelectUnit(ids);
  1459. }else{
  1460. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1461. var ids = [];
  1462. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1463. return this.getNextSelectUnit(ids);
  1464. }else{
  1465. return [];
  1466. }
  1467. }
  1468. }
  1469. }
  1470. return [];
  1471. },
  1472. getScriptSelectUnit: function(){
  1473. var rangeValues = [];
  1474. if (this.json.unitRangeUnit && this.json.unitRangeUnit.length){
  1475. this.json.unitRangeUnit.each(function(unit){
  1476. //var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName;
  1477. //if (unitFlag) rangeValues.push(unitFlag);
  1478. rangeValues.push(unit);
  1479. }.bind(this));
  1480. }
  1481. if (this.json.unitRangeField && this.json.unitRangeField.length){
  1482. this.json.unitRangeField.each(function(field){
  1483. var n = (typeOf(field)=="object") ? field.name : field;
  1484. var v = this.form.businessData.data[n];
  1485. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1486. v.each(function(d){
  1487. if (d){
  1488. // if (typeOf(d)==="string"){
  1489. // var data;
  1490. // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  1491. // rangeValues.push(data);
  1492. // }else{
  1493. rangeValues.push(d);
  1494. // }
  1495. }
  1496. }.bind(this));
  1497. }.bind(this));
  1498. }
  1499. if (this.json.unitRangeKey && this.json.unitRangeKey.code){
  1500. var v = this.form.Macro.exec(this.json.unitRangeKey.code, this);
  1501. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1502. v.each(function(d){
  1503. if (d){
  1504. // if (typeOf(d)==="string"){
  1505. // var data;
  1506. // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  1507. // rangeValues.push(data);
  1508. // }else{
  1509. rangeValues.push(d);
  1510. // }
  1511. }
  1512. }.bind(this));
  1513. }
  1514. return rangeValues;
  1515. },
  1516. getNextSelectUnit: function(id){
  1517. var ids = typeOf(id)==="array" ? id : [id];
  1518. var data;
  1519. var units = [];
  1520. ids.each( function(i){
  1521. if (this.json.unitRangeNext === "direct"){
  1522. this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  1523. if (data && data.woUnit) units.push(data.woUnit);
  1524. }else if(this.json.unitRangeNext==="level"){
  1525. this.orgAction.getUnitWithIdentityWithLevel(i, this.json.unitRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1526. if (data) units.push(data);
  1527. }else if (this.json.unitRangeNext==="type"){
  1528. if (this.json.unitRangeNextUnitType==="all"){
  1529. this.orgAction.getUnitWithIdentityWithLevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1530. }else{
  1531. this.orgAction.getUnitWithIdentityWithType(i, this.json.unitRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1532. }
  1533. if (data) units.push(data);
  1534. }
  1535. data = null;
  1536. }.bind(this));
  1537. return units;
  1538. //if (this.json.unitRangeNext === "direct"){
  1539. // if (typeOf(id)==="array"){
  1540. // var units = [];
  1541. // id.each(function(i){
  1542. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  1543. // if (data && data.woUnit) units.push(data.woUnit);
  1544. // data = null;
  1545. // }.bind(this));
  1546. // return units;
  1547. // }else{
  1548. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
  1549. // return (data.woUnit) ? [data.woUnit] : [];
  1550. // }
  1551. //}
  1552. //if (this.json.unitRangeNext==="level"){
  1553. // this.orgAction.getUnitWithIdentityWithLevel(id, this.json.unitRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1554. // //this.json.rangeNextLevel
  1555. // return (data) ? [data] : [];
  1556. //}
  1557. //if (this.json.unitRangeNext==="type"){
  1558. // if (this.json.unitRangeNextUnitType==="all"){
  1559. // this.orgAction.getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1560. // }else{
  1561. // this.orgAction.getUnitWithIdentityWithType(id, this.json.unitRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1562. // }
  1563. //
  1564. // return (data) ? [data] : [];
  1565. //}
  1566. }
  1567. });
  1568. MWF.APPOrg.IdentityOptions = new Class({
  1569. Implements: [Events],
  1570. initialize : function( form, json ){
  1571. this.form = form;
  1572. this.json = json;
  1573. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1574. },
  1575. getOptions: function(){
  1576. var count = (this.json.identityCount) ? this.json.identityCount : 0;
  1577. if( this.json.identityOnlyUseInclude ){
  1578. return {
  1579. "noUnit" : true,
  1580. "count": count,
  1581. "resultType" : this.json.identityResultType,
  1582. "include" : this._getInclude()
  1583. };
  1584. }else{
  1585. var selectUnits = this.getSelectRange( true );
  1586. var selectDutys = this.getSelectRangeDuty( true );
  1587. return {
  1588. "count": count,
  1589. "units": selectUnits,
  1590. "dutys": selectDutys,
  1591. "expandSubEnable" : (this.json.identityExpandSubEnable=="no") ? false : true,
  1592. "resultType" : this.json.identityResultType,
  1593. "categoryType": this.json.categoryType || "unit",
  1594. "dutyUnitLevelBy" : this.json.dutyUnitLevelBy || "duty",
  1595. "include" : this._getInclude()
  1596. };
  1597. }
  1598. },
  1599. getSearchOptions : function(){
  1600. var selectUnits = this.getSelectRange( true );
  1601. var selectDutys = this.getSelectRangeDuty( true );
  1602. return {
  1603. "units": selectUnits,
  1604. "dutys": selectDutys,
  1605. "resultType" : this.json.identityResultType
  1606. };
  1607. },
  1608. getSelectRange : function( refresh ){
  1609. if( !this.selectRange || refresh ){
  1610. this.selectRange = this._getSelectRange();
  1611. }
  1612. return this.selectRange;
  1613. },
  1614. _getInclude : function(){
  1615. var include = [];
  1616. if( this.json.identityIncludeKey ){
  1617. var v = this.form.Macro.exec(this.json.identityIncludeKey.code, this);
  1618. if( v )include = typeOf(v)==="array" ? v : [v];
  1619. }
  1620. return include;
  1621. },
  1622. _getSelectRange : function(){
  1623. if (this.json.identityRange==="unit"){
  1624. return this.getScriptSelectUnit();
  1625. }
  1626. if (this.json.identityRange==="draftUnit"){
  1627. var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
  1628. if (!dn){
  1629. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1630. var ids = [];
  1631. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1632. return this.getNextSelectUnit(ids);
  1633. }else{
  1634. return [];
  1635. }
  1636. }else{
  1637. return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
  1638. }
  1639. }
  1640. if (this.json.identityRange==="currentUnit"){
  1641. if (this.form.app.currentTask){
  1642. return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
  1643. }else{
  1644. if (this.form.app.taskList && this.form.app.taskList.length){
  1645. var ids = [];
  1646. this.form.app.taskList.each(function(task){ ids.push(task.identity); });
  1647. return this.getNextSelectUnit(ids);
  1648. }else{
  1649. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1650. var ids = [];
  1651. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1652. return this.getNextSelectUnit(ids);
  1653. }else{
  1654. return [];
  1655. }
  1656. }
  1657. }
  1658. }
  1659. return [];
  1660. },
  1661. getScriptSelectUnit: function(){
  1662. var rangeValues = [];
  1663. if (this.json.identityRangeUnit && this.json.identityRangeUnit.length){
  1664. this.json.identityRangeUnit.each(function(unit){
  1665. //var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName ;
  1666. //if (unitFlag) rangeValues.push(unitFlag);
  1667. rangeValues.push(unit);
  1668. }.bind(this));
  1669. }
  1670. if (this.json.identityRangeField && this.json.identityRangeField.length){
  1671. this.json.identityRangeField.each(function(field){
  1672. var n = (typeOf(field)=="object") ? field.name : field;
  1673. var v = this.form.businessData.data[n];
  1674. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1675. v.each(function(d){
  1676. if (d){
  1677. // if (typeOf(d)==="string"){
  1678. // var data;
  1679. // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  1680. // rangeValues.push(data);
  1681. // }else{
  1682. rangeValues.push(d);
  1683. // }
  1684. }
  1685. }.bind(this));
  1686. }.bind(this));
  1687. }
  1688. if (this.json.identityRangeKey && this.json.identityRangeKey.code){
  1689. var v = this.form.Macro.exec(this.json.identityRangeKey.code, this);
  1690. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1691. v.each(function(d){
  1692. if (d){
  1693. // if (typeOf(d)==="string"){
  1694. // var data;
  1695. // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  1696. // rangeValues.push(data);
  1697. // }else{
  1698. rangeValues.push(d);
  1699. // }
  1700. }
  1701. }.bind(this));
  1702. }
  1703. return rangeValues;
  1704. },
  1705. getNextSelectUnit: function(id){
  1706. var ids = typeOf(id)==="array" ? id : [id];
  1707. var data;
  1708. var units = [];
  1709. ids.each(function(i){
  1710. if (this.json.identityRangeNext === "direct"){
  1711. this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  1712. if (data && data.woUnit) units.push(data.woUnit);
  1713. }else if (this.json.identityRangeNext==="level"){
  1714. this.orgAction.getUnitWithIdentityWithLevel(i, this.json.identityRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1715. if (data) units.push(data);
  1716. }else if (this.json.identityRangeNext==="type"){
  1717. if (this.json.identityRangeNextUnitType==="all"){
  1718. this.orgAction.getUnitWithIdentityWithLevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1719. }else{
  1720. this.orgAction.getUnitWithIdentityWithType(i, this.json.identityRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1721. }
  1722. if (data) units.push(data);
  1723. }
  1724. data = null;
  1725. }.bind(this));
  1726. return units;
  1727. //if (this.json.identityRangeNext === "direct"){
  1728. //if (typeOf(id)==="array"){
  1729. // var units = [];
  1730. // id.each(function(i){
  1731. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  1732. // if (data && data.woUnit) units.push(data.woUnit);
  1733. // data = null;
  1734. // }.bind(this));
  1735. // return units;
  1736. //}else{
  1737. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
  1738. // return (data.woUnit) ? [data.woUnit] : [];
  1739. //}
  1740. //}
  1741. //if (this.json.identityRangeNext==="level"){
  1742. // this.orgAction.getUnitWithIdentityWithLevel(id, this.json.identityRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1743. // return (data) ? [data] : [];
  1744. // //this.json.rangeNextLevel
  1745. //}
  1746. //if (this.json.identityRangeNext==="type"){
  1747. // if (this.json.identityRangeNextUnitType==="all"){
  1748. // this.orgAction.getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1749. // }else{
  1750. // this.orgAction.getUnitWithIdentityWithType(id, this.json.identityRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1751. // }
  1752. // return (data) ? [data] : [];
  1753. //}
  1754. },
  1755. getSelectRangeDuty: function( refresh ){
  1756. if( !this.selectRangeDuty || refresh ){
  1757. this.selectRangeDuty = this._getSelectRangeDuty();
  1758. }
  1759. return this.selectRangeDuty;
  1760. },
  1761. _getSelectRangeDuty: function(){
  1762. if (this.json.dutyRange==="duty"){
  1763. return this.getScriptSelectDuty();
  1764. }
  1765. return [];
  1766. },
  1767. getScriptSelectDuty: function(){
  1768. var rangeValues = [];
  1769. if( this.json.rangeDuty && this.json.rangeDuty.length ){
  1770. var rangeDuty = this.json.rangeDuty;
  1771. if( typeOf(rangeDuty) === "string" ){
  1772. rangeDuty = JSON.parse( rangeDuty );
  1773. }
  1774. if( typeOf(rangeDuty) === "array" ){
  1775. rangeDuty.each(function(unit){
  1776. var unitFlag = typeOf(unit) === "string" ? unit : (unit.id || unit.name);
  1777. if (unitFlag) rangeValues.push(unitFlag);
  1778. }.bind(this));
  1779. }
  1780. }
  1781. //if (this.json.rangeDuty && this.json.rangeDuty.length){
  1782. // this.json.rangeDuty.each(function(unit){
  1783. // var unitFlag = unit.id || unit.name;
  1784. // if (unitFlag) rangeValues.push(unitFlag);
  1785. // }.bind(this));
  1786. //}
  1787. if (this.json.rangeDutyField && this.json.rangeDutyField.length){
  1788. this.json.rangeDutyField.each(function(field){
  1789. var n = (typeOf(field)=="object") ? field.name : field;
  1790. var v = this.form.businessData.data[n];
  1791. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1792. v.each(function(d){
  1793. if (d) rangeValues.push(d);
  1794. }.bind(this));
  1795. }.bind(this));
  1796. }
  1797. if (this.json.rangeDutyKey && this.json.rangeDutyKey.code){
  1798. var v = this.form.Macro.exec(this.json.rangeDutyKey.code, this);
  1799. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1800. v.each(function(d){
  1801. if (d) rangeValues.push(d);
  1802. }.bind(this));
  1803. }
  1804. return rangeValues;
  1805. }
  1806. });