Org.js 69 KB

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