Org.js 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448
  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. /** @class Org 人员组织组件。
  5. * @o2cn 人员组织组件
  6. * @example
  7. * //可以在脚本中获取该组件
  8. * //方法1:
  9. * var field = this.form.get("fieldId"); //获取组件对象
  10. * //方法2
  11. * var field = this.target; //在组件本身的脚本中获取,比如事件脚本、默认值脚本、校验脚本等等
  12. *
  13. * var data = field.getData(); //获取值
  14. * field.setData(value); //设置值
  15. * field.hide(); //隐藏字段
  16. * var id = field.json.id; //获取字段标识
  17. * var flag = field.isEmpty(); //字段是否为空
  18. * @extends MWF.xApplication.process.Xform.$Input
  19. * @o2category FormComponents
  20. * @o2range {Process|CMS|Portal}
  21. * @hideconstructor
  22. */
  23. MWF.xApplication.process.Xform.Org = MWF.APPOrg = new Class(
  24. /** @lends MWF.xApplication.process.Xform.Org# */
  25. {
  26. Implements: [Events],
  27. Extends: MWF.APP$Input,
  28. options: {
  29. /**
  30. * 组件加载前触发。当前组件的queryLoad事件还没有在form里注册,通过this.form.get("fieldId")不能获取到当前组件,需要用this.target获取当前组件。
  31. * @event MWF.xApplication.process.Xform.Org#queryLoad
  32. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  33. */
  34. /**
  35. * 组件加载时触发.
  36. * @event MWF.xApplication.process.Xform.Org#load
  37. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  38. */
  39. /**
  40. * 组件加载后触发.
  41. * @event MWF.xApplication.process.Xform.Org#postLoad
  42. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  43. */
  44. /**
  45. * 当组件值改变时触发。
  46. * @event MWF.xApplication.process.Xform.Org#change
  47. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  48. */
  49. /**
  50. * 当组件不允许输入(使用人员选择框)时,完成选择人员,并且给组件赋值后执行。
  51. * @event MWF.xApplication.process.Xform.Org#select
  52. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  53. */
  54. "moduleEvents": ["load", "queryLoad", "postLoad", "change", "select", "removeItem"],
  55. /**
  56. * 人员选择框事件:加载前执行。this.target指向人员选择框。
  57. * @event MWF.xApplication.process.Xform.Org#queryLoadSelector
  58. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  59. */
  60. /**
  61. * 人员选择框事件:加载后执行,由于选择项为异步加载,此时选择项并未加载完成。this.target指向人员选择框。
  62. * @event MWF.xApplication.process.Xform.Org#postLoadSelector
  63. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  64. */
  65. /**
  66. * 人员选择框事件:加载选择框容器节点前执行。this.target指向人员选择框。
  67. * @event MWF.xApplication.process.Xform.Org#queryLoadCategory
  68. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  69. */
  70. /**
  71. * 人员选择框事件:加载选择框容器节点后执行。this.target指向人员选择框。
  72. * @event MWF.xApplication.process.Xform.Org#postLoadContent
  73. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  74. */
  75. /**
  76. * 人员选择框事件:加载分类前执行。this.target指向分类,this.target.selector指向人员选择框。
  77. * @event MWF.xApplication.process.Xform.Org#queryLoadCategory
  78. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  79. */
  80. /**
  81. * 人员选择框事件:加载分类后执行。this.target指向分类,this.target.selector指向人员选择框。
  82. * @event MWF.xApplication.process.Xform.Org#postLoadCategory
  83. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  84. */
  85. /**
  86. * 人员选择框事件:选择分类后执行。this.target指向分类,this.target.selector指向人员选择框。
  87. * @event MWF.xApplication.process.Xform.Org#selectCategory
  88. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  89. */
  90. /**
  91. * 人员选择框事件:取消选择分类后执行。this.target指向分类,this.target.selector指向人员选择框。
  92. * @event MWF.xApplication.process.Xform.Org#unselectCategory
  93. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  94. */
  95. /**
  96. * 人员选择框事件:展开分类后执行。this.target指向分类,this.target.selector指向人员选择框。
  97. * @event MWF.xApplication.process.Xform.Org#expand
  98. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  99. */
  100. /**
  101. * 人员选择框事件:折叠分类后执行。this.target指向分类,this.target.selector指向人员选择框。
  102. * @event MWF.xApplication.process.Xform.Org#collapse
  103. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  104. */
  105. /**
  106. * 人员选择框事件:加载选择项前执行。this.target指向选择项,this.target.selector指向人员选择框。
  107. * @event MWF.xApplication.process.Xform.Org#queryLoadItem
  108. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  109. */
  110. /**
  111. * 人员选择框事件:加载选择项后执行。this.target指向选择项,this.target.selector指向人员选择框。
  112. * @event MWF.xApplication.process.Xform.Org#postLoadItem
  113. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  114. */
  115. /**
  116. * 人员选择框事件:选择选择项后执行。this.target指向选择项,this.target.selector指向人员选择框。
  117. * @event MWF.xApplication.process.Xform.Org#selectItem
  118. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  119. */
  120. /**
  121. * 人员选择框事件:取消选择选择项后执行。this.target指向选择项,this.target.selector指向人员选择框。
  122. * @event MWF.xApplication.process.Xform.Org#unselectItem
  123. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  124. */
  125. /**
  126. * 人员选择框事件:在人员选择框点取消时执行。this.target指向人员选择框。
  127. * @event MWF.xApplication.process.Xform.Org#close
  128. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  129. */
  130. "selectorEvents" : ["queryLoadSelector","postLoadSelector","queryLoadContent","postLoadContent","queryLoadCategory","postLoadCategory",
  131. "selectCategory", "unselectCategory","queryLoadItem","postLoadItem","selectItem", "unselectItem","change","expand","collapse","cancel"],
  132. "readonly": true
  133. },
  134. iconStyle: "orgIcon",
  135. isReadonly : function(){
  136. var readonly = !!(this.readonly || this.form.json.isReadonly);
  137. if( readonly )return readonly;
  138. if( this.json.isReadonly === "script" ){
  139. if( this.json.readonlyScript && this.json.readonlyScript.code ){
  140. readonly = this.form.Macro.exec(this.json.readonlyScript.code, this);
  141. }
  142. }else{
  143. readonly = !!this.json.isReadonly
  144. }
  145. return readonly || !!this.isSectionMergeRead();
  146. },
  147. getTextData: function(){
  148. //var value = this.node.get("value");
  149. //var text = this.node.get("text");
  150. var value = this.getValue();
  151. //var text = (this.node.getFirst()) ? this.node.getFirst().get("text") : this.node.get("text");
  152. var text = [];
  153. if( typeOf( value ) === "object" )value = [value];
  154. if( typeOf( value ) === "array" ){
  155. value.each(function(v){
  156. if( typeOf(v) === "string" ){
  157. text.push(v);
  158. }else{
  159. text.push(v.name+((v.unitName) ? "("+v.unitName+")" : ""));
  160. }
  161. }.bind(this));
  162. return {"value": value || "", "text": [text.join(",")]};
  163. }else{
  164. return {"value": [""], "text": [""]};
  165. }
  166. },
  167. loadDescription: function(){
  168. if (this.isReadonly())return;
  169. if(this.descriptionNode)return;
  170. var v = this._getBusinessData();
  171. if (!v || !v.length){
  172. if (this.json.description){
  173. var size, w;
  174. if( this.node.offsetParent === null ){ //隐藏
  175. size = { y: 26 }
  176. }else{
  177. size = this.node.getFirst().getSize();
  178. w = size.x-3;
  179. if( this.json.showIcon!='no' && !this.form.json.hideModuleIcon ) {
  180. if (COMMON.Browser.safari) w = w - 20;
  181. }
  182. }
  183. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  184. this.descriptionNode.setStyles({
  185. "height": ""+size.y+"px",
  186. "line-height": ""+size.y+"px"
  187. });
  188. if( w )this.descriptionNode.setStyles({
  189. "width": ""+w+"px"
  190. });
  191. this.setDescriptionEvent();
  192. }
  193. }
  194. },
  195. setDescriptionEvent: function(){
  196. if (this.descriptionNode){
  197. this.descriptionNode.addEvents({
  198. "mousedown": function( ev ){
  199. this.descriptionNode.setStyle("display", "none");
  200. if( this.json.isInput ){
  201. if( this.combox ){
  202. if (!this.combox.editItem) this.combox.intoEdit(ev);
  203. window.setTimeout( function () {
  204. this.combox.input.node.focus();
  205. }.bind(this), 300)
  206. }
  207. }else{
  208. this.clickSelect( ev );
  209. }
  210. }.bind(this)
  211. });
  212. }
  213. },
  214. _loadNode: function(){
  215. this.field = true;
  216. if (this.isReadonly()){
  217. this._loadNodeRead();
  218. }else{
  219. this._getOrgOptions();
  220. if (this.json.isInput){
  221. this._loadNodeInputEdit();
  222. }else{
  223. this._loadNodeEdit();
  224. }
  225. }
  226. },
  227. _loadMergeReadContentNode: function(contentNode, data){
  228. this.loadOrgWidget(data.data, contentNode);
  229. },
  230. _loadMergeEditNodeByDefault: function(){
  231. var data = this.getSortedSectionData();
  232. var businessData = [];
  233. data.each(function(d){
  234. businessData = businessData.concat( d.data || [] );
  235. });
  236. this._setBusinessData( businessData );
  237. this._loadNode();
  238. },
  239. _getOrgOptions: function(){
  240. this.selectTypeList = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
  241. if( this.selectTypeList.contains( "identity" ) ) {
  242. this.identityOptions = new MWF.APPOrg.IdentityOptions(this.form, this.json);
  243. }
  244. if( this.selectTypeList.contains( "unit" ) ) {
  245. this.unitOptions = new MWF.APPOrg.UnitOptions(this.form, this.json);
  246. }
  247. if( this.selectTypeList.contains( "group" ) ){
  248. this.groupOptions = new MWF.APPOrg.GroupOptions( this.form, this.json );
  249. }
  250. //this.selectUnits = this.getSelectRange();
  251. //if (this.json.selectType=="identity"){
  252. // this.selectDutys = this.getSelectRangeDuty();
  253. //}
  254. },
  255. _valueMerge: function(values, v){
  256. if (o2.typeOf(v)=="function"){
  257. return v.then(function(re){
  258. this._valueMerge(values, re)
  259. }.bind(this), function(){});
  260. }else{
  261. return values.concat(v);
  262. }
  263. },
  264. _computeValue: function(){
  265. var simple = this.json.storeRange === "simple";
  266. var values = [];
  267. if (this.json.identityValue) {
  268. this.json.identityValue.each(function(v){
  269. if (v) values.push(MWF.org.parseOrgData(v, true, simple))
  270. });
  271. }
  272. if (this.json.unitValue) {
  273. this.json.unitValue.each(function(v){ if (v) values.push(MWF.org.parseOrgData(v, true, simple))});
  274. }
  275. if (this.json.dutyValue) {
  276. var dutys = JSON.decode(this.json.dutyValue);
  277. var par;
  278. if (dutys.length){
  279. dutys.each(function(duty){
  280. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  281. if (par){
  282. var pars = (o2.typeOf(par)=="array") ? par : [par];
  283. var promise = Promise.all(pars).then(function(p){
  284. var uName = p.distinguishedName || p;
  285. if (o2.typeOf(p)=="array") uName = p[0].distinguishedName || p[0];
  286. var code = "return this.org.getDuty(\""+duty.name+"\", \""+uName+"\", true)";
  287. var r = (!!uName) ? this.form.Macro.exec(code, this) : "";
  288. var m = (o2.typeOf(r)=="array") ? "all" : "resolve";
  289. return Promise[m](r).then(function(d){
  290. if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  291. var arr = [];
  292. d.each(function(dd){
  293. if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
  294. });
  295. return arr;
  296. }.bind(this)).catch(function(){
  297. console.log("catch error : can not get duty : " + duty.name, + "-" + uName);
  298. });
  299. }.bind(this), function(){});
  300. values.push(promise);
  301. }
  302. }.bind(this));
  303. }
  304. }
  305. if (this.json.defaultValue && this.json.defaultValue.code){
  306. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  307. if (o2.typeOf(fd)=="array"){
  308. fd.each(function(v){values.push(v);});
  309. }else{
  310. values.push(fd);
  311. }
  312. // if (fd && fd.isAG){
  313. // values.push(fd);
  314. // }else{
  315. // if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
  316. // fd.each(function(fdd){
  317. // if (fdd){
  318. // if (typeOf(fdd)==="string"){
  319. // var data;
  320. // this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, fdd, false);
  321. // values.push(data);
  322. // }else{
  323. // values.push(fdd);
  324. // }
  325. // }
  326. // }.bind(this));
  327. // }
  328. }
  329. // if (this.json.count>0){
  330. // return values.slice(0, this.json.count);
  331. // }
  332. return values;
  333. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  334. },
  335. __computeValue: function(){
  336. var simple = this.json.storeRange === "simple";
  337. var values = [];
  338. if (this.json.identityValue) {
  339. this.json.identityValue.each(function(v){
  340. if (v) values.push(MWF.org.parseOrgData(v, true, simple))
  341. });
  342. }
  343. if (this.json.unitValue) {
  344. this.json.unitValue.each(function(v){ if (v) values.push(MWF.org.parseOrgData(v, true, simple))});
  345. }
  346. if (this.json.dutyValue) {
  347. var dutys = JSON.decode(this.json.dutyValue);
  348. var par;
  349. if (dutys.length){
  350. dutys.each(function(duty){
  351. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  352. if (par && par.isAG){
  353. var ag = o2.AG.all(par).then(function(p){
  354. var uName = "";
  355. if (p && p.length) uName = p[0].distinguishedName || p[0];
  356. var code = "return this.org.getDuty(\""+duty.name+"\", \""+uName+"\", true)";
  357. var r = this.form.Macro.exec(code, this);
  358. o2.AG.all(r).then(function(d) {
  359. //var d = rd[0];
  360. if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  361. var arr = [];
  362. d.each(function(dd){
  363. if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
  364. });
  365. return arr;
  366. }.bind(this));
  367. }.bind(this));
  368. values.push(ag);
  369. }else{
  370. var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\", true)";
  371. var r = this.form.Macro.exec(code, this);
  372. var ag = o2.AG.all(r).then(function(d) {
  373. //var d = rd[0];
  374. if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  375. var arr = [];
  376. d.each(function(dd){
  377. if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
  378. });
  379. return arr;
  380. }.bind(this));
  381. values.push(ag);
  382. // if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  383. // d.each(function(dd){if (dd) values.push(MWF.org.parseOrgData(dd, true, simple));});
  384. }
  385. }.bind(this));
  386. }
  387. }
  388. if (this.json.defaultValue && this.json.defaultValue.code){
  389. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  390. if (fd && fd.isAG){
  391. // value.addResolve(function(v){
  392. // this._setBusinessData(v);
  393. // if (this.node.getFirst()) this.node.getFirst().set("value", v || "");
  394. // if (this.readonly || this.json.isReadonly) this.node.set("text", v);
  395. // }.bind(this));
  396. values.push(fd);
  397. // fd.then(function(v){
  398. // return this._valueMerge(values, v);
  399. // }.bind(this));
  400. // return fd;
  401. }else{
  402. if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
  403. fd.each(function(fdd){
  404. if (fdd){
  405. if (typeOf(fdd)==="string"){
  406. var data;
  407. this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, fdd, false);
  408. values.push(data);
  409. }else{
  410. values.push(fdd);
  411. }
  412. }
  413. }.bind(this));
  414. }
  415. }
  416. if (this.json.count>0){
  417. return values.slice(0, this.json.count);
  418. }
  419. return values;
  420. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  421. },
  422. getOrgAction: function(){
  423. if (!this.orgAction) this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  424. //if (!this.orgAction) this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
  425. return this.orgAction;
  426. },
  427. getOptions: function(){
  428. var _self = this;
  429. if( this.selectTypeList.length === 0 )return false;
  430. var values = this.getInputData() || [];
  431. var exclude = [];
  432. if( this.json.exclude ){
  433. var v = this.form.Macro.exec(this.json.exclude.code, this);
  434. exclude = typeOf(v)==="array" ? v : [v];
  435. }
  436. //var count = (this.json.count) ? this.json.count : 0;
  437. var identityOpt;
  438. if( this.identityOptions ){
  439. identityOpt = this.identityOptions.getOptions();
  440. if (this.json.identityRange!=="all"){
  441. if ( !identityOpt.noUnit && (!identityOpt.units || !identityOpt.units.length) ){
  442. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  443. identityOpt.disabled = true;
  444. // return false;
  445. }
  446. }
  447. if ( !identityOpt.noUnit && this.json.dutyRange && this.json.dutyRange!=="all"){
  448. if (!identityOpt.dutys || !identityOpt.dutys.length){
  449. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  450. identityOpt.disabled = true;
  451. // return false;
  452. }
  453. }
  454. identityOpt.values = (this.json.isInput) ? [] : values;
  455. identityOpt.exclude = exclude;
  456. if( this.form.json.selectorStyle )identityOpt = Object.merge( identityOpt, this.form.json.selectorStyle );
  457. }
  458. var unitOpt;
  459. if( this.unitOptions ){
  460. unitOpt = this.unitOptions.getOptions();
  461. if (this.json.unitRange!=="all"){
  462. if ( !unitOpt.units || !unitOpt.units.length){
  463. this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  464. unitOpt.disabled = true;
  465. // return false;
  466. }
  467. }
  468. unitOpt.values = (this.json.isInput) ? [] : values;
  469. unitOpt.exclude = exclude;
  470. if( this.form.json.selectorStyle )unitOpt = Object.merge( unitOpt, this.form.json.selectorStyle );
  471. }
  472. var groupOpt;
  473. if( this.groupOptions ){
  474. groupOpt = this.groupOptions.getOptions();
  475. groupOpt.values = (this.json.isInput) ? [] : values;
  476. groupOpt.exclude = exclude;
  477. if( this.form.json.selectorStyle )groupOpt = Object.merge( groupOpt, this.form.json.selectorStyle );
  478. }
  479. //var selectUnits = this.getSelectRange();
  480. //if (this.json.selectType=="identity"){
  481. // var selectDutys = this.getSelectRangeDuty();
  482. //}
  483. //if (this.json.range!=="all"){
  484. // if (!selectUnits.length){
  485. // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  486. // return false;
  487. // }
  488. //}
  489. //if (this.json.selectType=="identity"){
  490. // if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
  491. // if (!selectDutys || !selectDutys.length){
  492. // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  493. // return false;
  494. // }
  495. // }
  496. //}
  497. var defaultOpt = {};
  498. if( this.json.events && typeOf(this.json.events) === "object" ){
  499. Object.each(this.json.events, function(e, key){
  500. if (e.code){
  501. if (this.options.selectorEvents.indexOf(key)!==-1){
  502. if( key === "postLoadSelector" ) {
  503. this.addEvent("loadSelector", function (selector) {
  504. return this.form.Macro.fire(e.code, selector);
  505. }.bind(this))
  506. }else if( key === "queryLoadSelector"){
  507. defaultOpt["onQueryLoad"] = function(target){
  508. return this.form.Macro.fire(e.code, target);
  509. }.bind(this)
  510. }else{
  511. defaultOpt["on"+key.capitalize()] = function(target){
  512. return this.form.Macro.fire(e.code, target);
  513. }.bind(this)
  514. }
  515. }
  516. }
  517. }.bind(this));
  518. }
  519. if( this.selectTypeList.length === 1 ){
  520. return Object.merge( {
  521. "type": this.selectTypeList[0],
  522. "onComplete": function(items){
  523. this.selectOnComplete(items);
  524. }.bind(this),
  525. "onCancel": this.selectOnCancel.bind(this),
  526. // "onLoad": this.selectOnLoad.bind(this),
  527. "onLoad": function(){
  528. //this 为 selector
  529. _self.selectOnLoad(this, this.selector );
  530. },
  531. "onClose": this.selectOnClose.bind(this)
  532. }, defaultOpt, identityOpt || unitOpt || groupOpt )
  533. }else if( this.selectTypeList.length > 1 ){
  534. var options = {
  535. "type" : "",
  536. "types" : this.selectTypeList,
  537. "onComplete": function(items){
  538. this.selectOnComplete(items);
  539. }.bind(this),
  540. "onCancel": this.selectOnCancel.bind(this),
  541. // "onLoad": this.selectOnLoad.bind(this),
  542. "onLoad": function(){
  543. //this 为 selector
  544. _self.selectOnLoad(this)
  545. },
  546. "onClose": this.selectOnClose.bind(this)
  547. };
  548. if( this.form.json.selectorStyle ){
  549. options = Object.merge( options, this.form.json.selectorStyle );
  550. }
  551. if( identityOpt )options.identityOptions = Object.merge( {}, defaultOpt, identityOpt );
  552. if( unitOpt )options.unitOptions = Object.merge( {}, defaultOpt, unitOpt );
  553. if( groupOpt )options.groupOptions = Object.merge( {}, defaultOpt, groupOpt );
  554. return options;
  555. }
  556. //return {
  557. // "type": this.json.selectType,
  558. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  559. // "values": (this.json.isInput) ? [] : values,
  560. // "count": count,
  561. // "units": selectUnits,
  562. // "dutys": (this.json.selectType=="identity") ? selectDutys : [],
  563. // "exclude" : exclude,
  564. // "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
  565. // "categoryType": this.json.categoryType || "unit",
  566. // "onComplete": function(items){
  567. // this.selectOnComplete(items);
  568. // }.bind(this),
  569. // "onCancel": this.selectOnCancel.bind(this),
  570. // "onLoad": this.selectOnLoad.bind(this),
  571. // "onClose": this.selectOnClose.bind(this)
  572. //};
  573. },
  574. selectOnComplete: function(items){
  575. var array = [];
  576. items.each(function(item){
  577. array.push(item.data);
  578. }.bind(this));
  579. var simple = this.json.storeRange === "simple";
  580. this.checkEmpower( array, function( data ){
  581. var values = [];
  582. data.each(function(d){
  583. values.push(MWF.org.parseOrgData(d, true, simple));
  584. }.bind(this));
  585. if (this.json.isInput){
  586. this.addData(values);
  587. }else{
  588. this.setData(values, true);
  589. }
  590. //this._setBusinessData(values);
  591. this.validationMode();
  592. this.validation();
  593. var p = this.getValue();
  594. if (p.then){
  595. p.then(function(){
  596. this.fireEvent("select");
  597. }.bind(this), function(){});
  598. }else{
  599. this.fireEvent("select");
  600. }
  601. }.bind(this))
  602. },
  603. selectOnCancel: function(){
  604. this.validation();
  605. },
  606. selectOnLoad: function( selector ){
  607. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  608. this.fireEvent("loadSelector", [selector])
  609. },
  610. selectOnClose: function(){
  611. var v = this._getBusinessData();
  612. if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  613. },
  614. checkDescription: function(){
  615. if (!this.json.description)return;
  616. var v = this._getBusinessData();
  617. if (!v || !v.length){
  618. if( this.descriptionNode ){
  619. if( this.node.getFirst() ){
  620. var size = this.node.getFirst().getSize();
  621. var w = size.x-3;
  622. if( this.json.showIcon!='no' && !this.form.json.hideModuleIcon ) {
  623. if (COMMON.Browser.safari) w = w - 20;
  624. }
  625. this.descriptionNode.setStyles({
  626. "display": "block",
  627. "width": ""+w+"px",
  628. "height": ""+( size.y || 26)+"px",
  629. "line-height": ""+( size.y || 26)+"px"
  630. });
  631. }else{
  632. this.descriptionNode.setStyle("display", "block");
  633. }
  634. }else{
  635. this.loadDescription();
  636. }
  637. }else{
  638. if(this.descriptionNode)this.descriptionNode.setStyle("display", "none");
  639. }
  640. },
  641. /**
  642. * @summary 弹出选择界面.
  643. * @example
  644. * this.form.get('org').clickSelect();
  645. */
  646. clickSelect: function( ev ){
  647. if (this.isReadonly())return;
  648. if( layout.mobile ){
  649. setTimeout( function(){ //如果有输入法界面,这个时候页面的计算不对,所以等100毫秒
  650. var options = this.getOptions();
  651. if(options){
  652. if( this.selector && this.selector.loading ) {
  653. }else if( this.selector && this.selector.selector && this.selector.selector.active ){
  654. }else{
  655. /**
  656. * @summary 人员选择框package的对象
  657. * @member {o2.O2Selector}
  658. * @example
  659. * //可以在脚本中获取该组件
  660. * var selector = this.form.get("fieldId").selector.selector; //获取人员选择框对象
  661. * var options = selector.options; //获取人员选择框的选项
  662. */
  663. this.selector = new MWF.O2Selector(this.form.app.content, options);
  664. }
  665. }
  666. }.bind(this), 100 )
  667. }else{
  668. var options = this.getOptions();
  669. if(options){
  670. if( this.selector && this.selector.loading ) {
  671. }else if( this.selector && this.selector.selector && this.selector.selector.active ){
  672. }else {
  673. this.selector = new MWF.O2Selector(this.form.app.content, options);
  674. }
  675. }
  676. }
  677. },
  678. resetData: function(){
  679. var v = this.getValue();
  680. //this.setData((v) ? v.join(", ") : "");
  681. this.setData(v);
  682. },
  683. isEmpty: function(){
  684. var data = this.getData();
  685. if( typeOf(data) !== "array" )return true;
  686. if( data.length === 0 )return true;
  687. return false;
  688. },
  689. getInputData: function(){
  690. if (this.json.isInput){
  691. if (this.combox)return this.combox.getData();
  692. //return this._getBusinessData();
  693. return this.node.retrieve("data");
  694. }else{
  695. //return this._getBusinessData();
  696. return this.node.retrieve("data");
  697. }
  698. },
  699. _loadNodeRead: function(){
  700. this.node.empty();
  701. var node = new Element("div").inject(this.node);
  702. this.node.set({
  703. "nodeId": this.json.id,
  704. "MWFType": this.json.type
  705. });
  706. },
  707. _searchConfirmPerson: function(item){
  708. var inforNode = item.inforNode || new Element("div");
  709. var simple = this.json.storeRange === "simple";
  710. if (item.data){
  711. var data = item.data;
  712. if( this.selectTypeList.contains("identity") && this.json.identityResultType === "person"){
  713. var dn = data.distinguishedName || data;
  714. if( dn.substr( dn.length-1, 1).toLowerCase() === "i" ){
  715. MWF.Actions.get("x_organization_assemble_express").listPersonWithIdentity({
  716. identityList : [dn]
  717. }, function(json){
  718. if( json.data.length > 0 ){
  719. if( data["person"] )json.data[0].id = data["person"];
  720. item.data = MWF.org.parseOrgData( json.data[0], true, simple );
  721. item.value = this.getDataText( item.data );
  722. if(item.node)item.node.set("text", item.value);
  723. }
  724. }.bind(this), null, false)
  725. }
  726. }
  727. if( item.data && ( item.data.createTime || item.data.updateTime ) ){
  728. item.data = MWF.org.parseOrgData( item.data, true, simple );
  729. }
  730. var text = "";
  731. var flag = item.data.distinguishedName.substr(item.data.distinguishedName.length-2, 2);
  732. switch (flag.toLowerCase()){
  733. case "@i":
  734. text = item.data.name+"("+item.data.unitName+")";
  735. break;
  736. case "@p":
  737. text = item.data.name+(item.data.employee ? "("+item.data.employee+")" : "");
  738. break;
  739. case "@u":
  740. text = item.data.levelName;
  741. break;
  742. case "@g":
  743. text = item.data.name;
  744. break;
  745. default:
  746. text = item.data.name;
  747. }
  748. inforNode.set({
  749. "styles": {"font-size": "14px", "color": ""},
  750. "text": text
  751. });
  752. }else{
  753. inforNode.set({
  754. "styles": {"font-size": "14px", "color": "#bd0000"},
  755. "text": MWF.xApplication.process.Xform.LP.noOrgObject
  756. });
  757. }
  758. if (!item.inforNode){
  759. new mBox.Tooltip({
  760. content: inforNode,
  761. setStyles: {content: {padding: 15, lineHeight: 20}},
  762. attach: item.node,
  763. transition: 'flyin'
  764. });
  765. item.inforNode = inforNode;
  766. }
  767. },
  768. getSearchOptions: function(){
  769. if( this.selectTypeList.length === 0 )return false;
  770. var identityOpt;
  771. if( this.identityOptions ){
  772. identityOpt = this.identityOptions.getSearchOptions();
  773. //if (this.json.identityRange!=="all"){
  774. // if ( !identityOpt.units || !identityOpt.units.length){
  775. // this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  776. // return false;
  777. // }
  778. //}
  779. //if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
  780. // if (!identityOpt.dutys || !identityOpt.dutys.length){
  781. // this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  782. // return false;
  783. // }
  784. //}
  785. }
  786. var unitOpt;
  787. if( this.unitOptions ){
  788. unitOpt = this.unitOptions.getSearchOptions();
  789. //if (this.json.unitRange!=="all"){
  790. // if ( !unitOpt.units || !unitOpt.units.length){
  791. // this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  792. // return false;
  793. // }
  794. //}
  795. }
  796. var groupOpt;
  797. if( this.groupOptions ){
  798. groupOpt = this.groupOptions.getOptions();
  799. }
  800. if( this.selectTypeList.length === 1 ){
  801. return Object.merge( {
  802. "type": this.selectTypeList[0]
  803. }, identityOpt || unitOpt || groupOpt )
  804. }else if( this.selectTypeList.length > 1 ){
  805. var options = {
  806. "type" : "",
  807. "types" : this.selectTypeList
  808. };
  809. if( identityOpt )options.identityOptions = identityOpt;
  810. if( unitOpt )options.unitOptions = unitOpt;
  811. if( groupOpt )options.groupOptions = groupOpt;
  812. return options;
  813. }
  814. //return {
  815. // "type": this.json.selectType,
  816. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  817. // "values": (this.json.isInput) ? [] : values,
  818. // "count": count,
  819. // "units": selectUnits,
  820. // "dutys": (this.json.selectType=="identity") ? selectDutys : [],
  821. // "exclude" : exclude,
  822. // "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
  823. // "categoryType": this.json.categoryType || "unit",
  824. // "onComplete": function(items){
  825. // this.selectOnComplete(items);
  826. // }.bind(this),
  827. // "onCancel": this.selectOnCancel.bind(this),
  828. // "onLoad": this.selectOnLoad.bind(this),
  829. // "onClose": this.selectOnClose.bind(this)
  830. //};
  831. },
  832. _searchOptions: function(value, callback){
  833. //var options = {
  834. // "type": this.json.selectType,
  835. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  836. // "units": this.selectUnits,
  837. // "dutys": (this.json.selectType=="identity") ? this.selectDutys : []
  838. //};
  839. var options = this.getSearchOptions();
  840. if (!this.comboxFilter) this.comboxFilter = new MWF.O2SelectorFilter(value, options);
  841. this.comboxFilter.filter(value, function(data){
  842. data.map(function(d){
  843. var value = Object.clone(d);
  844. d.value = value;
  845. var flag = d.distinguishedName.substr(d.distinguishedName.length-2, 2);
  846. switch (flag.toLowerCase()){
  847. case "@i":
  848. d.text = d.name+"("+d.unitName+")";
  849. break;
  850. case "@p":
  851. d.text = d.name+(d.employee ? "("+d.employee+")" : "");
  852. break;
  853. case "@u":
  854. d.text = d.name;
  855. break;
  856. case "@g":
  857. d.text = d.name;
  858. break;
  859. default:
  860. d.text = d.name;
  861. }
  862. });
  863. if (callback) callback(data);
  864. });
  865. },
  866. _resetNodeInputEdit: function(){
  867. var node = new Element("div", {
  868. "styles": {
  869. "overflow": (this.json.styles && this.json.styles.overflow) ? this.json.styles.overflow : "hidden",
  870. //"position": "relative",
  871. "margin-right": this.hasIcon() ? "20px" : "0px"
  872. }
  873. }).inject(this.node, "after");
  874. this.node.destroy();
  875. this.node = node;
  876. },
  877. _loadNodeInputEdit: function(){
  878. this.node.setStyle("overflow","visible");
  879. var input=null;
  880. MWF.require("MWF.widget.Combox", function(){
  881. this.combox = input = new MWF.widget.Combox({
  882. "count": this.json.count || 0,
  883. "splitShow": this.json.splitShow || ", ",
  884. "onCommitInput": function(item){
  885. this._searchConfirmPerson(item);
  886. //this.fireEvent("change");
  887. }.bind(this),
  888. "onChange": function(){
  889. this.node.store("data", this.getInputData());
  890. this._setBusinessData(this.getInputData());
  891. this.fireEvent("change");
  892. }.bind(this),
  893. "optionsMethod": this._searchOptions.bind(this)
  894. });
  895. }.bind(this), false);
  896. input.setStyles({
  897. "background": "transparent",
  898. "border": "0px"
  899. });
  900. input.set(this.json.properties);
  901. if (!this.json.preprocessing) this._resetNodeInputEdit();
  902. this.node.empty();
  903. input.inject(this.node);
  904. this.node.set({
  905. "id": this.json.id,
  906. "MWFType": this.json.type
  907. });
  908. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
  909. this.iconNode = new Element("div", {
  910. "styles": this.form.css[this.iconStyle],
  911. "events": {
  912. "click": function (ev) {
  913. this.clickSelect(ev);
  914. }.bind(this)
  915. //this.clickSelect.bind(this)
  916. }
  917. }).inject(this.node, "before");
  918. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  919. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  920. }
  921. this.combox.addEvent("change", function(){
  922. this.validationMode();
  923. if (this.validation()){
  924. this.node.store("data", this.getInputData());
  925. this._setBusinessData(this.getInputData("change"));
  926. }
  927. }.bind(this));
  928. },
  929. _resetNodeEdit: function(){
  930. var input = new Element("div", {
  931. "styles": {
  932. "background": "transparent",
  933. "border": "0px",
  934. "min-height": "24px"
  935. }
  936. });
  937. var node = new Element("div", {"styles": {
  938. "overflow": (this.json.styles && this.json.styles.overflow) ? this.json.styles.overflow : "hidden",
  939. "position": "relative",
  940. "margin-right": this.hasIcon() ? "20px" : "0px",
  941. "min-height": "24px"
  942. }}).inject(this.node, "after");
  943. input.inject(node);
  944. this.node.destroy();
  945. this.node = node;
  946. },
  947. _loadNodeEdit: function(){
  948. if (!this.json.preprocessing) this._resetNodeEdit();
  949. var input = this.node.getFirst();
  950. if( !input && this.nodeHtml ){
  951. this.node.set("html", this.nodeHtml);
  952. input = this.node.getFirst();
  953. }
  954. input.set(this.json.properties);
  955. this.node.set({
  956. "id": this.json.id,
  957. "MWFType": this.json.type,
  958. "events": {
  959. "click": function (ev) {
  960. this.clickSelect(ev);
  961. }.bind(this)
  962. //this.clickSelect.bind(this)
  963. }
  964. });
  965. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
  966. this.iconNode = new Element("div", {
  967. "styles": this.form.css[this.iconStyle],
  968. "events": {
  969. "click": function (ev) {
  970. this.clickSelect(ev);
  971. }.bind(this)
  972. //this.clickSelect.bind(this)
  973. }
  974. }).inject(this.node, "before");
  975. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  976. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  977. }
  978. this.node.getFirst().setStyle("height", "auto");
  979. this.node.getFirst().addEvent("change", function(){
  980. this.validationMode();
  981. if (this.validation()){
  982. this.node.store("data", this.getInputData());
  983. this._setBusinessData(this.getInputData("change"));
  984. }
  985. }.bind(this));
  986. },
  987. getDataText: function(data){
  988. if (typeOf(data)=="string") return data;
  989. if( !data || !data.distinguishedName )return "";
  990. var text = "";
  991. var flag = data.distinguishedName.substr(data.distinguishedName.length-2, 2);
  992. switch (flag.toLowerCase()){
  993. case "@i":
  994. text = data.name+"("+data.unitName+")";
  995. break;
  996. case "@p":
  997. text = data.name+ (data.employee ? ("("+data.employee+")") : "");
  998. break;
  999. case "@u":
  1000. text = data.name;
  1001. break;
  1002. case "@g":
  1003. text = data.name;
  1004. break;
  1005. default:
  1006. text = data.name;
  1007. }
  1008. return text;
  1009. },
  1010. addData: function(value){
  1011. if (!value) return false;
  1012. var simple = this.json.storeRange === "simple";
  1013. value.each(function(v){
  1014. var vtype = typeOf(v);
  1015. if (vtype==="string"){
  1016. var data;
  1017. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, v, false);
  1018. if (data) this.combox.addNewValue(this.getDataText(data), data);
  1019. }
  1020. if (vtype==="object"){
  1021. var d = MWF.org.parseOrgData(v, true, simple);
  1022. this.combox.addNewValue(this.getDataText(d), d);
  1023. }
  1024. }.bind(this));
  1025. },
  1026. checkChange: function(oldValues, values){
  1027. var change = false;
  1028. if (!values) values = [];
  1029. if (oldValues.length && (values && values.length)){
  1030. if (oldValues.length === values.length){
  1031. for (var i=0; i<oldValues.length; i++){
  1032. if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
  1033. change = true;
  1034. break;
  1035. }
  1036. }
  1037. }else{
  1038. change = true;
  1039. }
  1040. }else if (values.length || oldValues.length) {
  1041. change = true;
  1042. }
  1043. if (change) this.fireEvent("change");
  1044. },
  1045. setData: function(value, fireChange){
  1046. if (!value) return false;
  1047. var oldValues = this.getData();
  1048. if (value.length==1 && !(value[0])) value=[];
  1049. var promise = this._setValue(value);
  1050. if (fireChange) Promise.resolve(promise).then(function(values){
  1051. o2.promiseAll(values).then(function(v){
  1052. this.checkChange(oldValues, v)
  1053. }.bind(this), function(){});
  1054. }.bind(this), function(){});
  1055. },
  1056. // __setData: function(value){
  1057. // if (!value) return false;
  1058. // var oldValues = this.getData();
  1059. // var values = [];
  1060. // var comboxValues = [];
  1061. //
  1062. // var simple = this.json.storeRange === "simple";
  1063. //
  1064. // var type = typeOf(value);
  1065. // if (type==="array"){
  1066. // value.each(function(v){
  1067. // var vtype = typeOf(v);
  1068. // var data = null;
  1069. // if (vtype==="string"){
  1070. // var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  1071. // this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, v, false);
  1072. // }
  1073. // if (vtype==="object") {
  1074. // data = MWF.org.parseOrgData(v, true, simple);
  1075. // if(data.woPerson)delete data.woPerson;
  1076. // }
  1077. // if (data){
  1078. // values.push(data);
  1079. // comboxValues.push({"text": this.getDataText(data),"value": data});
  1080. // }
  1081. // }.bind(this));
  1082. // }
  1083. // if (type==="string"){
  1084. // var vData;
  1085. // var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  1086. // this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, value, false);
  1087. // if (vData){
  1088. // values.push(vData);
  1089. // comboxValues.push({"text": this.getDataText(vData),"value": vData});
  1090. // }
  1091. // }
  1092. // if (type==="object"){
  1093. // var vData = MWF.org.parseOrgData(value, true, simple);
  1094. // if(vData.woPerson)delete vData.woPerson;
  1095. // values.push( vData );
  1096. // comboxValues.push({"text": this.getDataText(value),"value": vData});
  1097. // }
  1098. //
  1099. // var change = false;
  1100. // if (oldValues.length && values.length){
  1101. // if (oldValues.length === values.length){
  1102. // for (var i=0; i<oldValues.length; i++){
  1103. // if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
  1104. // change = true;
  1105. // break;
  1106. // }
  1107. // }
  1108. // }else{
  1109. // change = true;
  1110. // }
  1111. // }else if (values.length || oldValues.length) {
  1112. // change = true;
  1113. // }
  1114. // this._setBusinessData(values);
  1115. // if (change) this.fireEvent("change");
  1116. //
  1117. // if (this.json.isInput){
  1118. // if (this.combox){
  1119. // this.combox.clear();
  1120. // this.combox.addNewValues(comboxValues);
  1121. // }else{
  1122. // var node = this.node.getFirst();
  1123. // if (node){
  1124. // node.empty();
  1125. // comboxValues.each(function(v, i){
  1126. // this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  1127. // }.bind(this));
  1128. // }
  1129. // }
  1130. // }else{
  1131. // if (this.node.getFirst()){
  1132. // var node = this.node.getFirst();
  1133. // node.empty();
  1134. // this.loadOrgWidget(values, node)
  1135. // }else{
  1136. // this.node.empty();
  1137. // this.loadOrgWidget(values, this.node);
  1138. // }
  1139. // }
  1140. // },
  1141. creteShowNode: function(data, islast){
  1142. var nodeText = (data.text) ? data.text : data;
  1143. if (!islast) nodeText = nodeText + (this.json.splitShow || ", ");
  1144. var node = new Element("div", {
  1145. "styles": {
  1146. "float": "left",
  1147. "margin-right": "5px"
  1148. },
  1149. "text": nodeText
  1150. });
  1151. var text = "";
  1152. if (data.value && data.value.distinguishedName){
  1153. var flag = data.value.distinguishedName.substr(data.value.distinguishedName.length-2, 2);
  1154. switch (flag.toLowerCase()){
  1155. case "@i":
  1156. text = data.value.name+"("+data.value.unitName+")";
  1157. break;
  1158. case "@p":
  1159. text = data.value.name+ (data.value.employee ? "("+data.value.employee+")" : "");
  1160. break;
  1161. case "@u":
  1162. text = data.value.levelName;
  1163. break;
  1164. case "@g":
  1165. text = data.value.name;
  1166. break;
  1167. default:
  1168. text = data.value.name;
  1169. }
  1170. var inforNode = new Element("div").set({
  1171. "styles": {"font-size": "14px", "color": ""},
  1172. "text": text
  1173. });
  1174. new mBox.Tooltip({
  1175. content: inforNode,
  1176. setStyles: {content: {padding: 15, lineHeight: 20}},
  1177. attach: node,
  1178. transition: 'flyin'
  1179. });
  1180. }
  1181. return node;
  1182. },
  1183. _setValue: function(value){
  1184. var values = [];
  1185. var ags = [];
  1186. var simple = this.json.storeRange === "simple";
  1187. var flag = false;
  1188. if (typeOf(value)!=="array") value = (!!value) ? [value] : [];
  1189. //value = (value.flat) ? value.flat() : value.flatten();
  1190. if (value.some(function(e){ return (e && o2.typeOf(e.then)=="function") }) || this.json.asyncMode==="yes"){
  1191. var p = Promise.all(value).then(function(d){
  1192. if (typeOf(d)!=="array") d = (!!d) ? [d] : [];
  1193. d.each(function(da){
  1194. if (typeOf(da)!=="array") da = (!!da) ? [da] : [];
  1195. da.each(function(dd){
  1196. if (dd){
  1197. if (typeOf(dd)==="string"){
  1198. var pp = this.getOrgAction()[this.getValueMethod(dd)](function(json){
  1199. return MWF.org.parseOrgData(json.data, true, simple);
  1200. }.bind(this), null, dd, true).catch(function(e){
  1201. console.log("error:" + e);
  1202. console.log(e);
  1203. });
  1204. ags.push(pp);
  1205. }else{
  1206. values.push(dd);
  1207. }
  1208. }
  1209. }.bind(this));
  1210. }.bind(this));
  1211. if (ags.length){
  1212. return Promise.all(ags).then(function(data){
  1213. values = values.concat(data);
  1214. flag = true;
  1215. this.__setValue(values);
  1216. return values;
  1217. }.bind(this), function(){});
  1218. }else{
  1219. flag = true;
  1220. this.__setValue(values);
  1221. return values
  1222. }
  1223. }.bind(this), function(){});
  1224. this.moduleValueAG = p;
  1225. if (p && p.then) p.then(function(){
  1226. this.moduleValueAG = null;
  1227. }.bind(this), function(){
  1228. this.moduleValueAG = null;
  1229. }.bind(this));
  1230. return p;
  1231. }else{
  1232. value.each(function(dd){
  1233. if (dd){
  1234. if (typeOf(dd)==="string"){
  1235. this.getOrgAction()[this.getValueMethod(dd)](function(json){
  1236. values.push(MWF.org.parseOrgData(json.data, true, simple));
  1237. }.bind(this), null, dd, false);
  1238. }else{
  1239. values.push(dd);
  1240. }
  1241. }
  1242. }.bind(this));
  1243. this.__setValue(values);
  1244. return values
  1245. }
  1246. // var ag = o2.AG.all(value).then(function(d) {
  1247. // if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  1248. //
  1249. // d.each(function(dd){
  1250. // //if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
  1251. // if (dd){
  1252. // if (typeOf(dd)==="string"){
  1253. // ags.push(this.getOrgAction()[this.getValueMethod(dd)](function(json){
  1254. // return MWF.org.parseOrgData(json.data, true, simple);
  1255. // }.bind(this).ag(), null, dd, true));
  1256. // }else{
  1257. // values.push(dd);
  1258. // }
  1259. // }
  1260. // }.bind(this));
  1261. // if (ags.length){
  1262. // return o2.AG.all(ags).then(function(data){
  1263. // values = values.concat(data);
  1264. // flag = true;
  1265. // this.__setValue(values);
  1266. // return values;
  1267. // }.bind(this));
  1268. // }else{
  1269. // flag = true;
  1270. // this.__setValue(values);
  1271. // return values
  1272. // }
  1273. // }.bind(this));
  1274. //
  1275. // this.moduleValueAG = ag;
  1276. // if (ag) ag.then(function(){
  1277. // this.moduleValueAG = null;
  1278. // }.bind(this));
  1279. // return ag;
  1280. },
  1281. __setValue: function(value){
  1282. this.moduleValueAG = null;
  1283. if (value.length==1 && !(value[0])) value=[];
  1284. if (this.json.count>0){
  1285. value = value.slice(0, this.json.count);
  1286. }
  1287. var values = [];
  1288. var comboxValues = [];
  1289. var type = typeOf(value);
  1290. var simple = this.json.storeRange === "simple";
  1291. if (type==="array"){
  1292. value.each(function(v){
  1293. var data=null;
  1294. var vtype = typeOf(v);
  1295. if (vtype==="string"){
  1296. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  1297. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, v, false);
  1298. }
  1299. if (vtype==="object") data = v;
  1300. if (data){
  1301. var d = MWF.org.parseOrgData(data, true, simple)
  1302. values.push(d);
  1303. comboxValues.push({"text": this.getDataText(d),"value": d});
  1304. }
  1305. }.bind(this));
  1306. }
  1307. if (type==="string"){
  1308. var vData;
  1309. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  1310. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true,simple); }.bind(this), error, value, false);
  1311. if (vData){
  1312. values.push(vData);
  1313. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  1314. }
  1315. }
  1316. if (type==="object"){
  1317. var v = MWF.org.parseOrgData(value, true, simple)
  1318. values.push(v);
  1319. comboxValues.push({"text": this.getDataText(v),"value": v});
  1320. }
  1321. this.node.store("data", values);
  1322. this._setBusinessData(values);
  1323. if (this.json.isInput){
  1324. if (this.combox){
  1325. this.combox.clear();
  1326. this.combox.addNewValues(comboxValues);
  1327. // values.each(function(v){
  1328. // if (typeOf(v)=="string"){
  1329. // this.combox.addNewValue(v);
  1330. // }else{
  1331. // this.combox.addNewValue(this.getDataText(v), v);
  1332. // }
  1333. // }.bind(this));
  1334. }else{
  1335. var node = this.node.getFirst();
  1336. if (node){
  1337. node.empty();
  1338. comboxValues.each(function(v, i){
  1339. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  1340. }.bind(this));
  1341. }
  1342. }
  1343. }else{
  1344. if (this.node.getFirst()){
  1345. var node = this.node.getFirst();
  1346. node.empty();
  1347. this.loadOrgWidget(values, node)
  1348. }else{
  1349. this.node.empty();
  1350. this.loadOrgWidget(values, this.node);
  1351. }
  1352. }
  1353. this.checkDescription();
  1354. this.fieldModuleLoaded = true;
  1355. //if (this.readonly) this.loadOrgWidget(values, this.node)
  1356. //this.node.set("text", value);
  1357. },
  1358. getValueMethod: function(value){
  1359. if (value){
  1360. var flag = value.substr(value.length-2, 2);
  1361. switch (flag.toLowerCase()){
  1362. case "@i":
  1363. return "getIdentity";
  1364. case "@p":
  1365. return "getPerson";
  1366. case "@u":
  1367. return "getUnit";
  1368. case "@g":
  1369. return "getGroup";
  1370. default:
  1371. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  1372. }
  1373. }
  1374. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  1375. },
  1376. loadOrgWidget: function(value, node){
  1377. var _self = this;
  1378. var disableInfor = layout.mobile ? true : false;
  1379. if( this.json.showCard === "no" )disableInfor = true;
  1380. var canRemove = this.json.canRemove ? true : false;
  1381. var height = node.getStyle("height").toInt();
  1382. if (node.getStyle("overflow")==="visible" && !height) node.setStyle("overflow", "hidden");
  1383. if (value && value.length){
  1384. value.each(function(data){
  1385. if( !data || !data.distinguishedName )return;
  1386. var flag = data.distinguishedName.substr(data.distinguishedName.length-2, 2);
  1387. var copyData = Object.clone(data);
  1388. if( this.json.displayTextScript && this.json.displayTextScript.code ){
  1389. this.currentData = copyData;
  1390. var displayName = this.form.Macro.exec(this.json.displayTextScript.code, this);
  1391. if( displayName ){
  1392. copyData.displayName = displayName;
  1393. }
  1394. this.currentData = null;
  1395. }
  1396. var opt = {"style": "xform","lazy":true,"disableInfor" : disableInfor, "canRemove":canRemove, "onRemove": function () {
  1397. _self.fireEvent("removeItem", [{
  1398. data: data,
  1399. item: this
  1400. }])
  1401. }, "styles": this.json.itemStyles || "" };
  1402. var widget;
  1403. switch (flag.toLowerCase()){
  1404. case "@i":
  1405. widget = new MWF.widget.O2Identity(copyData, node, opt);
  1406. break;
  1407. case "@p":
  1408. widget = new MWF.widget.O2Person(copyData, node, opt);
  1409. break;
  1410. case "@u":
  1411. widget = new MWF.widget.O2Unit(copyData, node, opt);
  1412. break;
  1413. case "@g":
  1414. widget = new MWF.widget.O2Group(copyData, node, opt);
  1415. break;
  1416. default:
  1417. widget = new MWF.widget.O2Other(copyData, node, opt);
  1418. }
  1419. widget.field = this;
  1420. if( layout.mobile ){
  1421. widget.node.setStyles({
  1422. "float" : "none"
  1423. })
  1424. }
  1425. }.bind(this));
  1426. }
  1427. },
  1428. _loadStyles: function(){
  1429. if (this.isReadonly()){
  1430. if (this.json.styles) this.node.setStyles(this.json.styles);
  1431. }else{
  1432. if (this.json.styles) this.node.setStyles(this.json.styles);
  1433. if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
  1434. if (this.iconNode && this.iconNode.offsetParent !== null ){
  1435. var size = this.node.getSize();
  1436. this.iconNode.setStyle("height", ""+size.y+"px");
  1437. }
  1438. }
  1439. },
  1440. checkEmpower : function( data, callback ){
  1441. if( typeOf(data)==="array" && this.identityOptions && this.json.isCheckEmpower && this.json.identityResultType === "identity" ) {
  1442. var empowerChecker = new MWF.APPOrg.EmpowerChecker(this.form, this.json);
  1443. empowerChecker.load(data, callback);
  1444. }else{
  1445. if( callback )callback( data );
  1446. }
  1447. },
  1448. _beforeReloaded: function(){
  1449. this.selector = null;
  1450. if (this.combox) {
  1451. this.combox.clear();
  1452. this.combox = null;
  1453. }
  1454. },
  1455. getExcelData: function(){
  1456. var text, value = this.getData();
  1457. if (o2.typeOf(value) === "array") {
  1458. var textArray = [];
  1459. value.each(function (item) {
  1460. if (o2.typeOf(item) === "object") {
  1461. textArray.push(item.distinguishedName);
  1462. } else {
  1463. textArray.push(item);
  1464. }
  1465. }.bind(this));
  1466. text = textArray.join(", \n");
  1467. } else if (o2.typeOf(value) === "object") {
  1468. text = value.distinguishedName;
  1469. } else {
  1470. text = value;
  1471. }
  1472. return text;
  1473. },
  1474. setExcelData: function(data){
  1475. this.excelData = data;
  1476. this.setData(data, true);
  1477. }
  1478. });
  1479. MWF.APPOrg.EmpowerChecker = new Class({
  1480. Implements: [Events],
  1481. initialize: function (form, json) {
  1482. this.form = form;
  1483. this.json = json;
  1484. this.css = this.form.css;
  1485. this.checkedAllItems = true;
  1486. },
  1487. load : function( data, callback, container ){
  1488. if( typeOf(data)==="array" && this.json.isCheckEmpower && this.json.identityResultType === "identity" ){
  1489. var array = [];
  1490. data.each( function( d ){
  1491. if( d.distinguishedName ){
  1492. var flag = d.distinguishedName.substr(d.distinguishedName.length-1, 1).toLowerCase();
  1493. if( flag === "i" ){
  1494. array.push( d.distinguishedName )
  1495. }
  1496. }
  1497. }.bind(this));
  1498. if( array.length > 0 ){
  1499. o2.Actions.get("x_organization_assemble_express").listEmpowerWithIdentity({
  1500. "application" : (this.form.businessData.work || this.form.businessData.workCompleted).application,
  1501. "process" : (this.form.businessData.work || this.form.businessData.workCompleted).process,
  1502. "work" : (this.form.businessData.work || this.form.businessData.workCompleted).id,
  1503. "identityList" : array
  1504. }, function( json ){
  1505. var arr = [];
  1506. json.data.each( function(d){
  1507. if(d.fromIdentity !== d.toIdentity )arr.push(d);
  1508. });
  1509. if( arr.length > 0 ){
  1510. this.openSelectEmpowerDlg( arr, data, callback, container );
  1511. }else{
  1512. if( callback )callback( data );
  1513. }
  1514. }.bind(this), function(){
  1515. if( callback )callback( data );
  1516. }.bind(this))
  1517. }else{
  1518. if( callback )callback( data );
  1519. }
  1520. }else{
  1521. if( callback )callback( data );
  1522. }
  1523. },
  1524. getIgnoreEmpowerArray : function( callback ){
  1525. var array = [];
  1526. if( this.empowerSelectNodes && this.empowerSelectNodes.length ){
  1527. this.empowerSelectNodes.each(function(node){
  1528. if( !node.retrieve("isSelected") ){
  1529. var d = node.retrieve("data");
  1530. array.push( d.fromIdentity );
  1531. }
  1532. }.bind(this));
  1533. }
  1534. if( callback )callback( array );
  1535. return array;
  1536. },
  1537. setIgnoreEmpowerFlag : function(data, callback){
  1538. var ignoreList = this.getIgnoreEmpowerArray();
  1539. for( var i=0; i<data.length; i++ ){
  1540. var d = data[i];
  1541. if( ignoreList.indexOf( d.distinguishedName ) > -1 ){
  1542. d.ignoreEmpower = true;
  1543. }else if( d.ignoreEmpower ){
  1544. delete d.ignoreEmpower;
  1545. }
  1546. }
  1547. if( callback )callback( data );
  1548. },
  1549. replaceEmpowerIdentity : function(data, callback){
  1550. var empowerData = {};
  1551. this.empowerSelectNodes.each(function(node){
  1552. if( node.retrieve("isSelected") ){
  1553. var d = node.retrieve("data");
  1554. empowerData[ d.fromIdentity ] = d;
  1555. }
  1556. }.bind(this));
  1557. if( Object.keys(empowerData).length === 0 ){
  1558. callback( data );
  1559. }else{
  1560. var identityList = [];
  1561. for( var key in empowerData ){
  1562. identityList.push( empowerData[key].toIdentity );
  1563. }
  1564. o2.Actions.get("x_organization_assemble_express").listIdentity({ "identityList" : identityList }, function(json){
  1565. var newData = data.clone();
  1566. var d = {};
  1567. json.data.each( function(j){
  1568. d[j.distinguishedName] = j;
  1569. });
  1570. for( var i=0; i<newData.length; i++ ){
  1571. var nd = newData[i];
  1572. if( nd.distinguishedName && empowerData[nd.distinguishedName]){
  1573. if( d[empowerData[nd.distinguishedName].toIdentity] ){
  1574. newData[i] = d[empowerData[nd.distinguishedName].toIdentity]
  1575. }
  1576. }
  1577. }
  1578. callback( newData );
  1579. },function(){
  1580. callback( data );
  1581. });
  1582. }
  1583. },
  1584. openSelectEmpowerDlg : function( data, orginData, callback, container ){
  1585. if( layout.mobile ){
  1586. this.openSelectEmpowerDlg_mobile(data, orginData, callback, container);
  1587. }else{
  1588. this.openSelectEmpowerDlg_pc(data, orginData, callback, container);
  1589. }
  1590. },
  1591. openSelectEmpowerDlg_mobile : function( data, orginData, callback, container ){
  1592. var that = this;
  1593. //处理json
  1594. var subItemList = [];
  1595. // var empowerMap = {};
  1596. // var selectableItems = [];
  1597. var valueList = [];
  1598. data.each( function( d ){
  1599. subItemList.push({
  1600. "name" : d.fromIdentity.split("@")[0] + " "+MWF.xApplication.process.Xform.LP.empowerTo+" " + d.toIdentity.split("@")[0],
  1601. "id" : d.fromIdentity + "#" + d.toIdentity
  1602. })
  1603. valueList.push({
  1604. "name" : d.fromIdentity.split("@")[0] + " "+MWF.xApplication.process.Xform.LP.empowerTo+" " + d.toIdentity.split("@")[0],
  1605. "id" : d.fromIdentity + "#" + d.toIdentity
  1606. })
  1607. // empowerMap[ d.fromIdentity ] = d.toIdentity;
  1608. }.bind(this));
  1609. if( subItemList.length === 0 ){
  1610. callback();
  1611. return;
  1612. }
  1613. var empowerList = Array.clone(subItemList);
  1614. // selectableItems.push({
  1615. // "empowerMap" : empowerMap,
  1616. // "subItemList" : subItemList
  1617. // });
  1618. // if( selectableItems.length === 0 ){
  1619. // callback();
  1620. // return;
  1621. // }
  1622. // var empowerList = Array.clone(selectableItems);
  1623. o2.xDesktop.requireApp("Template", "Selector.Custom", function () {
  1624. var options = {
  1625. "count": 0,
  1626. "title": MWF.xApplication.process.Xform.LP.selectEmpower,
  1627. "selectAllEnable" : true,
  1628. "selectableItems": subItemList,
  1629. "expand": false,
  1630. "category": false,
  1631. "values": valueList,
  1632. "zIndex" : 3001,
  1633. "closeOnclickOk" : true,
  1634. "onComplete": function (items) {
  1635. var arr = [];
  1636. items.each(function (item) {
  1637. arr.push( item.data.id )
  1638. }.bind(this));
  1639. var ignoreList = [];
  1640. empowerList.each( function (obj) {
  1641. if( arr.indexOf( obj.id ) === -1 )ignoreList.push( obj.id.split("#")[0] )
  1642. });
  1643. for( var i=0; i<orginData.length; i++ ){
  1644. var d = orginData[i];
  1645. if( ignoreList.indexOf( d.distinguishedName ) > -1 ){
  1646. d.ignoreEmpower = true;
  1647. }else if( d.ignoreEmpower ){
  1648. delete d.ignoreEmpower;
  1649. }
  1650. }
  1651. if( callback )callback( orginData );
  1652. // empowerList.each( function(obj){
  1653. // var list = obj.subItemList.filter(function(item, index){
  1654. // return !arr.contains( item.id );
  1655. // }.bind(this));
  1656. // ignoreList = ignoreList.map(function(item,index){
  1657. // return item.id.split("#")[1];
  1658. // })
  1659. // });
  1660. // empowerList.each( function(obj){
  1661. // var org = that.orgItemsObject[obj.orgId];
  1662. // // if( obj.ignoreList.length > 0 ){
  1663. // var data = org.getData();
  1664. // for( var i=0; i<data.length; i++ ){
  1665. // var d = data[i];
  1666. // if( obj.ignoreList.indexOf( d.distinguishedName ) > -1 ){
  1667. // d.ignoreEmpower = true;
  1668. // }else if( d.ignoreEmpower ){
  1669. // delete d.ignoreEmpower;
  1670. // }
  1671. // }
  1672. // org.setData( data );
  1673. // }
  1674. // if( obj.empowerMap ){
  1675. // var data = org.getValue();
  1676. // for( var i=0; i<data.length; i++ ){
  1677. // var d = data[i];
  1678. // if( obj.empowerMap[ d.distinguishedName ] ){
  1679. // d.empowerToIdentity = obj.empowerMap[ d.distinguishedName ];
  1680. // }
  1681. // }
  1682. // org.empowerData = Array.clone(data);
  1683. // }
  1684. // if(callback)callback();
  1685. // })
  1686. }.bind(this)
  1687. };
  1688. if( this.form.json.selectorStyle ){
  1689. Object.merge(options, this.form.json.selectorStyle );
  1690. }
  1691. options.flatCategory = false;
  1692. var selector = new o2.xApplication.Template.Selector.Custom($(document.body), options);
  1693. selector.load();
  1694. }.bind(this))
  1695. },
  1696. openSelectEmpowerDlg_pc : function( data, orginData, callback, container ){
  1697. var node = new Element("div", {"styles": this.css.empowerAreaNode});
  1698. var html = "<div style=\"line-height: 20px; color: #333333; overflow: hidden\">"+MWF.xApplication.process.Xform.LP.empowerDlgText+"</div>";
  1699. html += "<div style=\"margin-bottom:10px; margin-top:10px; overflow-y:auto;\"></div>";
  1700. node.set("html", html);
  1701. var itemNode = node.getLast();
  1702. this.getEmpowerItems(itemNode, data);
  1703. node.inject( container || this.form.app.content);
  1704. var dlg = o2.DL.open({
  1705. "title": MWF.xApplication.process.Xform.LP.selectEmpower,
  1706. "style": this.form.json.dialogStyle || "user",
  1707. "isResize": true,
  1708. "content": node,
  1709. "width": 630,
  1710. //"height" : 500,
  1711. "buttonList": [
  1712. {
  1713. "type" : "ok",
  1714. "text": MWF.LP.process.button.ok,
  1715. "action": function(d, e){
  1716. //this.replaceEmpowerIdentity( orginData, callback ); //直接替换已授权的人,已废弃
  1717. this.setIgnoreEmpowerFlag( orginData, callback ); //然后设置忽略的人的标志
  1718. dlg.close();
  1719. }.bind(this)
  1720. },
  1721. {
  1722. "type" : "cancel",
  1723. "text": MWF.LP.process.button.cancel,
  1724. "action": function(){dlg.close();}
  1725. }
  1726. ],
  1727. "onPostShow": function(){
  1728. var selectNode = this.createSelectAllEmpowerNode();
  1729. selectNode.inject( dlg.button );
  1730. if( layout.mobile ){
  1731. dlg.node.inject( $(document.body) );
  1732. dlg.node.setStyles({
  1733. "width":"100%",
  1734. "height": "100%",
  1735. "top" : "0px",
  1736. "left" : "0px"
  1737. });
  1738. var y = dlg.node.getSize().y - 190;
  1739. itemNode.setStyle("height",y+"px");
  1740. dlg.options.contentHeight = dlg.node.getSize().y - 100 ; //+100;
  1741. dlg.setContentSize();
  1742. }else{
  1743. dlg.content.setStyle("overflow","hidden");
  1744. var y = Math.min(300, itemNode.getSize().y);
  1745. var marginTop = itemNode.getStyle("margin-top");
  1746. var marginBottom = itemNode.getStyle("margin-bottom");
  1747. itemNode.setStyle("height",y+"px");
  1748. dlg.options.contentHeight = y + 30 + 20 ; //+100;
  1749. dlg.setContentSize();
  1750. dlg.node.setStyles({
  1751. "height": ""+(dlg.options.height) +"px"
  1752. });
  1753. dlg.reCenter();
  1754. }
  1755. }.bind(this)
  1756. });
  1757. },
  1758. getEmpowerItems: function(itemNode, data){
  1759. var _self = this;
  1760. this.empowerSelectNodes = [];
  1761. var count = 1;
  1762. var node;
  1763. data.each(function( d ){
  1764. if(d.fromIdentity == d.toIdentity )return;
  1765. if( count % 2 === 1 ){
  1766. node = new Element("div", {"styles": this.css.empowerItemOddNode}).inject(itemNode);
  1767. node.store("nodeType","Odd");
  1768. //node.setStyle("margin-right","10px");
  1769. }else{
  1770. node = new Element("div", {"styles": this.css.empowerItemEvenNode}).inject(itemNode);
  1771. node.store("nodeType","Even");
  1772. }
  1773. count++;
  1774. this.empowerSelectNodes.push( node );
  1775. node.store("data", d);
  1776. var iconNode = new Element("div.empowerItemIconNode", {"styles": this.css.empowerItemIconNode}).inject(node);
  1777. node.store("iconNode",iconNode);
  1778. var contentNode = new Element("div.empowerItemContentNode", {"styles": this.css.empowerItemContentNode}).inject(node);
  1779. var formIdentityNode = new Element("div.empowerItemPersonNode", {"styles": this.css.empowerItemPersonNode, text : d.fromIdentity.split("@")[0] }).inject(contentNode);
  1780. var titleNode = new Element("div.empowerItemTitleNode", {"styles": this.css.empowerItemTitleNode, text : MWF.xApplication.process.Xform.LP.empowerTo }).inject(contentNode);
  1781. var toIdentityNode = new Element("div.empowerItemPersonNode", {"styles": this.css.empowerItemPersonNode, text : d.toIdentity.split("@")[0] }).inject(contentNode);
  1782. node.addEvents({
  1783. "mouseover": function(){
  1784. var isSelected = this.retrieve("isSelected");
  1785. if (!isSelected){
  1786. this.setStyles(_self.css[ "empowerItem"+this.retrieve("nodeType")+"Node_over" ]);
  1787. if( _self.css.empowerItemIconNode_over ){
  1788. var iconNode = this.retrieve("iconNode");
  1789. if(iconNode)iconNode.setStyles(_self.css.empowerItemIconNode_over);
  1790. }
  1791. }
  1792. },
  1793. "mouseout": function(){
  1794. var isSelected = this.retrieve("isSelected");
  1795. if (!isSelected){
  1796. this.setStyles(_self.css[ "empowerItem"+this.retrieve("nodeType")+"Node" ])
  1797. if( _self.css.empowerItemIconNode_over ){
  1798. var iconNode = this.retrieve("iconNode");
  1799. if(iconNode)iconNode.setStyles(_self.css.empowerItemIconNode);
  1800. }
  1801. }
  1802. },
  1803. "click": function(){
  1804. var isSelected = this.retrieve("isSelected");
  1805. if (isSelected){
  1806. _self.unselectEmpowerItem( this)
  1807. }else{
  1808. _self.selectEmpowerItem(this)
  1809. }
  1810. }
  1811. });
  1812. if( this.checkedAllItems )node.click();
  1813. }.bind(this));
  1814. },
  1815. unselectEmpowerItem : function( itemNode ){
  1816. itemNode.store("isSelected", false);
  1817. itemNode.setStyles( this.css[ "empowerItem"+itemNode.retrieve("nodeType")+"Node" ] );
  1818. itemNode.getElements("div").each( function( div ){
  1819. var className = div.get("class");
  1820. if( className && this.css[className] )div.setStyles( this.css[className] )
  1821. }.bind(this))
  1822. },
  1823. selectEmpowerItem : function( itemNode ){
  1824. itemNode.store("isSelected", true);
  1825. itemNode.setStyles( this.css[ "empowerItem"+itemNode.retrieve("nodeType")+"Node_selected" ] );
  1826. itemNode.getElements("div").each( function( div ){
  1827. var className = div.get("class");
  1828. if( className && this.css[className+"_selected"] )div.setStyles( this.css[className+"_selected"] )
  1829. }.bind(this))
  1830. },
  1831. createSelectAllEmpowerNode : function(){
  1832. var _self = this;
  1833. var node = new Element("div", {
  1834. styles : this.css.empowerSelectAllItemNode,
  1835. text : MWF.xApplication.process.Xform.LP.selectAll
  1836. });
  1837. node.addEvents({
  1838. "mouseover": function(){
  1839. var isSelected = this.retrieve("isSelected");
  1840. if (!isSelected) this.setStyles(_self.css.empowerSelectAllItemNode_over);
  1841. },
  1842. "mouseout": function(){
  1843. var isSelected = this.retrieve("isSelected");
  1844. if (!isSelected) this.setStyles(_self.css.empowerSelectAllItemNode)
  1845. },
  1846. "click": function(){
  1847. var isSelected = this.retrieve("isSelected");
  1848. if (isSelected){
  1849. this.store("isSelected", false);
  1850. this.setStyles( _self.css.empowerSelectAllItemNode );
  1851. _self.empowerSelectNodes.each( function(itemNode){
  1852. _self.unselectEmpowerItem(itemNode)
  1853. }.bind(this))
  1854. }else{
  1855. this.store("isSelected", true);
  1856. this.setStyles( _self.css.empowerSelectAllItemNode_selected );
  1857. _self.empowerSelectNodes.each( function(itemNode){
  1858. _self.selectEmpowerItem(itemNode)
  1859. }.bind(this))
  1860. }
  1861. }
  1862. });
  1863. if( this.checkedAllItems ){
  1864. node.store("isSelected", true);
  1865. node.setStyles( _self.css.empowerSelectAllItemNode_selected );
  1866. }
  1867. return node;
  1868. }
  1869. });
  1870. MWF.APPOrg.GroupOptions = new Class({
  1871. Implements: [Events],
  1872. initialize: function (form, json) {
  1873. this.form = form;
  1874. this.json = json;
  1875. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1876. },
  1877. getOptions: function(){
  1878. var count = (this.json.groupCount) ? this.json.groupCount : 0;
  1879. if( this.json.groupRange==="group" ){
  1880. return {
  1881. "count": count,
  1882. "storeRange" : this.json.storeRange,
  1883. "include": this.getSelectRange( true )
  1884. }
  1885. }else{
  1886. return {
  1887. "count": count,
  1888. "storeRange" : this.json.storeRange
  1889. }
  1890. }
  1891. },
  1892. getSearchOptions : function(){
  1893. return {};
  1894. },
  1895. getSelectRange : function( refresh ){
  1896. if( !this.selectRange || refresh){
  1897. this.selectRange = this._getSelectRange();
  1898. }
  1899. return this.selectRange;
  1900. },
  1901. _getSelectRange : function(){
  1902. var rangeValues = [];
  1903. if (this.json.groupRangeKey && this.json.groupRangeKey.code){
  1904. var v = this.form.Macro.exec(this.json.groupRangeKey.code, this);
  1905. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1906. rangeValues = v;
  1907. //v.each(function(d){
  1908. // if (d){
  1909. // if (typeOf(d)==="string"){
  1910. // var data;
  1911. // this.orgAction.getGroup(function(json){ data = json.data }.bind(this), null, d, false);
  1912. // rangeValues.push(data);
  1913. // }else{
  1914. // rangeValues.push(d);
  1915. // }
  1916. // }
  1917. //}.bind(this));
  1918. }
  1919. return rangeValues;
  1920. }
  1921. });
  1922. MWF.APPOrg.UnitOptions = new Class({
  1923. Implements: [Events],
  1924. initialize : function( form, json ){
  1925. this.form = form;
  1926. this.json = json;
  1927. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1928. },
  1929. getOptions: function(){
  1930. var count = (this.json.unitCount) ? this.json.unitCount : 0;
  1931. var selectUnits = this.getSelectRange( true );
  1932. return {
  1933. "count": count,
  1934. "units": selectUnits,
  1935. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  1936. "storeRange" : this.json.storeRange,
  1937. "expandSubEnable" : (this.json.unitExpandSubEnable==="no") ? false : true,
  1938. "firstLevelSelectable":this.json.firstLevelSelectable==="yes"
  1939. };
  1940. },
  1941. getSearchOptions : function(){
  1942. var selectUnits = this.getSelectRange( true );
  1943. return {
  1944. "units": selectUnits,
  1945. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType
  1946. };
  1947. },
  1948. getSelectRange : function( refresh ){
  1949. if( !this.selectRange || refresh){
  1950. this.selectRange = this._getSelectRange();
  1951. }
  1952. return this.selectRange;
  1953. },
  1954. _getSelectRange : function(){
  1955. if (this.json.unitRange==="unit"){
  1956. return this.getScriptSelectUnit();
  1957. }
  1958. if (this.json.unitRange==="draftUnit"){
  1959. var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
  1960. if (!dn){
  1961. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1962. var ids = [];
  1963. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1964. return this.getNextSelectUnit(ids);
  1965. }else{
  1966. return [];
  1967. }
  1968. }else{
  1969. return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
  1970. }
  1971. }
  1972. if (this.json.unitRange==="currentUnit"){
  1973. if (this.form.app.currentTask){
  1974. return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
  1975. }else{
  1976. if (this.form.app.taskList && this.form.app.taskList.length){
  1977. var ids = [];
  1978. this.form.app.taskList.each(function(task){ ids.push(task.identity); });
  1979. return this.getNextSelectUnit(ids);
  1980. }else{
  1981. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1982. var ids = [];
  1983. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1984. return this.getNextSelectUnit(ids);
  1985. }else{
  1986. return [];
  1987. }
  1988. }
  1989. }
  1990. }
  1991. return [];
  1992. },
  1993. getScriptSelectUnit: function(){
  1994. var rangeValues = [];
  1995. if (this.json.unitRangeUnit && this.json.unitRangeUnit.length){
  1996. this.json.unitRangeUnit.each(function(unit){
  1997. //var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName;
  1998. //if (unitFlag) rangeValues.push(unitFlag);
  1999. rangeValues.push(unit);
  2000. }.bind(this));
  2001. }
  2002. if (this.json.unitRangeField && this.json.unitRangeField.length){
  2003. this.json.unitRangeField.each(function(field){
  2004. var n = (typeOf(field)=="object") ? field.name : field;
  2005. var v = this.form.businessData.data[n];
  2006. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  2007. v.each(function(d){
  2008. if (d){
  2009. // if (typeOf(d)==="string"){
  2010. // var data;
  2011. // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  2012. // rangeValues.push(data);
  2013. // }else{
  2014. rangeValues.push(d);
  2015. // }
  2016. }
  2017. }.bind(this));
  2018. }.bind(this));
  2019. }
  2020. if (this.json.unitRangeKey && this.json.unitRangeKey.code){
  2021. var v = this.form.Macro.exec(this.json.unitRangeKey.code, this);
  2022. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  2023. v.each(function(d){
  2024. if (d){
  2025. // if (typeOf(d)==="string"){
  2026. // var data;
  2027. // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  2028. // rangeValues.push(data);
  2029. // }else{
  2030. rangeValues.push(d);
  2031. // }
  2032. }
  2033. }.bind(this));
  2034. }
  2035. return rangeValues;
  2036. },
  2037. getNextSelectUnit: function(id){
  2038. var ids = typeOf(id)==="array" ? id : [id];
  2039. var data;
  2040. var units = [];
  2041. ids.each( function(i){
  2042. if (this.json.unitRangeNext === "direct"){
  2043. this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  2044. if (data && data.woUnit) units.push(data.woUnit);
  2045. }else if(this.json.unitRangeNext==="level"){
  2046. this.orgAction.getUnitWithIdentityWithLevel(i, this.json.unitRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2047. if (data) units.push(data);
  2048. }else if (this.json.unitRangeNext==="type"){
  2049. if (this.json.unitRangeNextUnitType==="all"){
  2050. this.orgAction.getUnitWithIdentityWithLevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2051. }else{
  2052. this.orgAction.getUnitWithIdentityWithType(i, this.json.unitRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2053. }
  2054. if (data) units.push(data);
  2055. }
  2056. data = null;
  2057. }.bind(this));
  2058. return units;
  2059. //if (this.json.unitRangeNext === "direct"){
  2060. // if (typeOf(id)==="array"){
  2061. // var units = [];
  2062. // id.each(function(i){
  2063. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  2064. // if (data && data.woUnit) units.push(data.woUnit);
  2065. // data = null;
  2066. // }.bind(this));
  2067. // return units;
  2068. // }else{
  2069. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
  2070. // return (data.woUnit) ? [data.woUnit] : [];
  2071. // }
  2072. //}
  2073. //if (this.json.unitRangeNext==="level"){
  2074. // this.orgAction.getUnitWithIdentityWithLevel(id, this.json.unitRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2075. // //this.json.rangeNextLevel
  2076. // return (data) ? [data] : [];
  2077. //}
  2078. //if (this.json.unitRangeNext==="type"){
  2079. // if (this.json.unitRangeNextUnitType==="all"){
  2080. // this.orgAction.getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2081. // }else{
  2082. // this.orgAction.getUnitWithIdentityWithType(id, this.json.unitRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2083. // }
  2084. //
  2085. // return (data) ? [data] : [];
  2086. //}
  2087. }
  2088. });
  2089. MWF.APPOrg.IdentityOptions = new Class({
  2090. Implements: [Events],
  2091. initialize : function( form, json ){
  2092. this.form = form;
  2093. this.json = json;
  2094. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  2095. },
  2096. getOptions: function(){
  2097. var count = (this.json.identityCount) ? this.json.identityCount : 0;
  2098. if( this.json.identityOnlyUseInclude ){
  2099. return {
  2100. "noUnit" : true,
  2101. "count": count,
  2102. "resultType" : this.json.identityResultType,
  2103. "storeRange" : this.json.storeRange,
  2104. "include" : this._getInclude()
  2105. };
  2106. }else{
  2107. var selectUnits = this.getSelectRange( true );
  2108. var selectDutys = this.getSelectRangeDuty( true );
  2109. return {
  2110. "count": count,
  2111. "units": selectUnits,
  2112. "unitType": this.json.unitType || "",
  2113. "dutys": selectDutys,
  2114. "expandSubEnable" : (this.json.identityExpandSubEnable=="no") ? false : true,
  2115. "resultType" : this.json.identityResultType,
  2116. "categoryType": this.json.categoryType || "unit",
  2117. "dutyUnitLevelBy" : this.json.dutyUnitLevelBy || "duty",
  2118. "storeRange" : this.json.storeRange,
  2119. "include" : this._getInclude()
  2120. };
  2121. }
  2122. },
  2123. getSearchOptions : function(){
  2124. var selectUnits = this.getSelectRange( true );
  2125. var selectDutys = this.getSelectRangeDuty( true );
  2126. return {
  2127. "units": selectUnits,
  2128. "dutys": selectDutys,
  2129. "resultType" : this.json.identityResultType
  2130. };
  2131. },
  2132. getSelectRange : function( refresh ){
  2133. if( !this.selectRange || refresh ){
  2134. this.selectRange = this._getSelectRange();
  2135. }
  2136. return this.selectRange;
  2137. },
  2138. _getInclude : function(){
  2139. var include = [];
  2140. if( this.json.identityIncludeKey ){
  2141. var v = this.form.Macro.exec(this.json.identityIncludeKey.code, this);
  2142. if( v )include = typeOf(v)==="array" ? v : [v];
  2143. }
  2144. return include;
  2145. },
  2146. _getSelectRange : function(){
  2147. if (this.json.identityRange==="unit"){
  2148. return this.getScriptSelectUnit();
  2149. }
  2150. if (this.json.identityRange==="draftUnit"){
  2151. var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
  2152. if (!dn){
  2153. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  2154. var ids = [];
  2155. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  2156. return this.getNextSelectUnit(ids);
  2157. }else{
  2158. return [];
  2159. }
  2160. }else{
  2161. return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
  2162. }
  2163. }
  2164. if (this.json.identityRange==="currentUnit"){
  2165. if (this.form.app.currentTask){
  2166. return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
  2167. }else{
  2168. if (this.form.app.taskList && this.form.app.taskList.length){
  2169. var ids = [];
  2170. this.form.app.taskList.each(function(task){ ids.push(task.identity); });
  2171. return this.getNextSelectUnit(ids);
  2172. }else{
  2173. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  2174. var ids = [];
  2175. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  2176. return this.getNextSelectUnit(ids);
  2177. }else{
  2178. return [];
  2179. }
  2180. }
  2181. }
  2182. }
  2183. return [];
  2184. },
  2185. getScriptSelectUnit: function(){
  2186. var rangeValues = [];
  2187. if (this.json.identityRangeUnit && this.json.identityRangeUnit.length){
  2188. this.json.identityRangeUnit.each(function(unit){
  2189. //var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName ;
  2190. //if (unitFlag) rangeValues.push(unitFlag);
  2191. rangeValues.push(unit);
  2192. }.bind(this));
  2193. }
  2194. if (this.json.identityRangeField && this.json.identityRangeField.length){
  2195. this.json.identityRangeField.each(function(field){
  2196. var n = (typeOf(field)=="object") ? field.name : field;
  2197. var v = this.form.businessData.data[n];
  2198. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  2199. v.each(function(d){
  2200. if (d){
  2201. // if (typeOf(d)==="string"){
  2202. // var data;
  2203. // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  2204. // rangeValues.push(data);
  2205. // }else{
  2206. rangeValues.push(d);
  2207. // }
  2208. }
  2209. }.bind(this));
  2210. }.bind(this));
  2211. }
  2212. if (this.json.identityRangeKey && this.json.identityRangeKey.code){
  2213. var v = this.form.Macro.exec(this.json.identityRangeKey.code, this);
  2214. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  2215. v.each(function(d){
  2216. if (d){
  2217. // if (typeOf(d)==="string"){
  2218. // var data;
  2219. // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  2220. // rangeValues.push(data);
  2221. // }else{
  2222. rangeValues.push(d);
  2223. // }
  2224. }
  2225. }.bind(this));
  2226. }
  2227. return rangeValues;
  2228. },
  2229. getNextSelectUnit: function(id){
  2230. var ids = typeOf(id)==="array" ? id : [id];
  2231. var data;
  2232. var units = [];
  2233. ids.each(function(i){
  2234. if (this.json.identityRangeNext === "direct"){
  2235. this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  2236. if (data && data.woUnit) units.push(data.woUnit);
  2237. }else if (this.json.identityRangeNext==="level"){
  2238. this.orgAction.getUnitWithIdentityWithLevel(i, this.json.identityRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2239. if (data) units.push(data);
  2240. }else if (this.json.identityRangeNext==="type"){
  2241. if (this.json.identityRangeNextUnitType==="all"){
  2242. this.orgAction.getUnitWithIdentityWithLevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2243. }else{
  2244. this.orgAction.getUnitWithIdentityWithType(i, this.json.identityRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2245. }
  2246. if (data) units.push(data);
  2247. }
  2248. data = null;
  2249. }.bind(this));
  2250. return units;
  2251. //if (this.json.identityRangeNext === "direct"){
  2252. //if (typeOf(id)==="array"){
  2253. // var units = [];
  2254. // id.each(function(i){
  2255. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  2256. // if (data && data.woUnit) units.push(data.woUnit);
  2257. // data = null;
  2258. // }.bind(this));
  2259. // return units;
  2260. //}else{
  2261. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
  2262. // return (data.woUnit) ? [data.woUnit] : [];
  2263. //}
  2264. //}
  2265. //if (this.json.identityRangeNext==="level"){
  2266. // this.orgAction.getUnitWithIdentityWithLevel(id, this.json.identityRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2267. // return (data) ? [data] : [];
  2268. // //this.json.rangeNextLevel
  2269. //}
  2270. //if (this.json.identityRangeNext==="type"){
  2271. // if (this.json.identityRangeNextUnitType==="all"){
  2272. // this.orgAction.getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2273. // }else{
  2274. // this.orgAction.getUnitWithIdentityWithType(id, this.json.identityRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2275. // }
  2276. // return (data) ? [data] : [];
  2277. //}
  2278. },
  2279. getSelectRangeDuty: function( refresh ){
  2280. if( !this.selectRangeDuty || refresh ){
  2281. this.selectRangeDuty = this._getSelectRangeDuty();
  2282. }
  2283. return this.selectRangeDuty;
  2284. },
  2285. _getSelectRangeDuty: function(){
  2286. if (this.json.dutyRange==="duty"){
  2287. return this.getScriptSelectDuty();
  2288. }
  2289. return [];
  2290. },
  2291. getScriptSelectDuty: function(){
  2292. var rangeValues = [];
  2293. if( this.json.rangeDuty && this.json.rangeDuty.length ){
  2294. var rangeDuty = this.json.rangeDuty;
  2295. if( typeOf(rangeDuty) === "string" ){
  2296. rangeDuty = JSON.parse( rangeDuty );
  2297. }
  2298. if( typeOf(rangeDuty) === "array" ){
  2299. rangeDuty.each(function(unit){
  2300. var unitFlag = typeOf(unit) === "string" ? unit : (unit.id || unit.name);
  2301. if (unitFlag) rangeValues.push(unitFlag);
  2302. }.bind(this));
  2303. }
  2304. }
  2305. //if (this.json.rangeDuty && this.json.rangeDuty.length){
  2306. // this.json.rangeDuty.each(function(unit){
  2307. // var unitFlag = unit.id || unit.name;
  2308. // if (unitFlag) rangeValues.push(unitFlag);
  2309. // }.bind(this));
  2310. //}
  2311. if (this.json.rangeDutyField && this.json.rangeDutyField.length){
  2312. this.json.rangeDutyField.each(function(field){
  2313. var n = (typeOf(field)=="object") ? field.name : field;
  2314. var v = this.form.businessData.data[n];
  2315. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  2316. v.each(function(d){
  2317. if (d) rangeValues.push(d);
  2318. }.bind(this));
  2319. }.bind(this));
  2320. }
  2321. if (this.json.rangeDutyKey && this.json.rangeDutyKey.code){
  2322. var v = this.form.Macro.exec(this.json.rangeDutyKey.code, this);
  2323. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  2324. v.each(function(d){
  2325. if (d) rangeValues.push(d);
  2326. }.bind(this));
  2327. }
  2328. return rangeValues;
  2329. }
  2330. });