Org.js 77 KB

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