Org.js 77 KB

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