Org.js 69 KB

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