Org.js 74 KB

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