Org.js 82 KB

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