Org.js 78 KB

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