Org.js 77 KB

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