Org.js 69 KB

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