Org.js 74 KB

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