Org.js 79 KB

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