Org.js 69 KB

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