Environment.js 162 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.xScript.Environment = function(ev){
  3. var _data = ev.data;
  4. var _form = ev.form;
  5. var _forms = ev.forms;
  6. this.library = COMMON;
  7. //this.library.version = "4.0";
  8. this.power = {
  9. "isManager": MWF.AC.isProcessManager() || _form.businessData.control.allowReroute,
  10. "isReseter": _form.businessData.control.allowReset,
  11. "isDelete": _form.businessData.control.allowDeleteWork,
  12. "isPront": true,
  13. "isPrint": true
  14. };
  15. //data
  16. var getJSONData = function(jData){
  17. return new MWF.xScript.JSONData(jData, function(data, key, _self){
  18. var p = {"getKey": function(){return key;}, "getParent": function(){return _self;}};
  19. while (p && !_forms[p.getKey()]) p = p.getParent();
  20. if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
  21. }, "", null, _form);
  22. };
  23. this.setData = function(data){
  24. /**
  25. * data对象是流程平台中,流程实例的业务数据;以及内容管理平台中,文档实例的业务数据。<br/>
  26. * 这些数据一般情况下是通过您创建的表单收集而来的,也可以通过脚本进行创建和增删改查操作。<br/>
  27. * data对象基本上是一个JSON对象,您可以用访问JSON对象的方法访问data对象的所有数据,但增加和删除数据时略有不同。
  28. * @module data
  29. * @o2ordernumber 10
  30. * @example
  31. * //您可以在表单或流程的各个嵌入脚本中,通过this来获取当前实例的业务数据,如下:
  32. * var data = this.data;
  33. */
  34. this.data = getJSONData(data);
  35. /**
  36. * 访问或修改data对象的数据。<br/><br/>
  37. * data数据用于存储表单获取的数据,所有属性都是动态的,其格式和访问方式都和JSON类似。<br/>
  38. * 在表单脚本中使用data对象,实现了data和表单可编辑元素的双向绑定。<br/>
  39. * 改变data对象,会自动更新表单元素,修改表单可编辑元素,也会自动修改data对象。
  40. * @member {String|Number} [[property]]
  41. * @memberOf module:data
  42. * @instance
  43. * @example
  44. * var value = this.data.subject; //获取名为subject的数据值
  45. *
  46. * //将subject的值修改为'123'。
  47. * //需要注意的是,用这种方式创建新字段,必须要在当前表单上有一个名为‘subject’的字段组件。
  48. * //如果表单上没有该组件,可以使用this.data.add('subject','123',true)。给已有字段赋值则没有这个限制。
  49. * this.data.subject = '123';
  50. *
  51. * @example
  52. * <caption>
  53. * <b>获取流程文档中的数据网格的值</b>:<br/>
  54. * 如有以下数据网格:
  55. * <img src="img/module/data/datagrid.jpg">
  56. * 其数据网格设计如下(数据网格id为:datagrid):
  57. * <img src="img/module/data/datagridDesign.jpg">
  58. * </caption>
  59. * //获取流程文档中的数据网格的值
  60. * var data = this.data.datagrid;
  61. *
  62. * //获取到的data值格式如下:
  63. * {
  64. * "data": [
  65. * {
  66. * "amountCol": { "amount": "12000" },
  67. * "countCol": { "number": "10" },
  68. * "nameCol": { "name": "手机" },
  69. * "priceCol": { "price": "1200" }
  70. * },
  71. * {
  72. * "amountCol": { "amount": "15000" },
  73. * "countCol": { "number": "5" },
  74. * "nameCol": { "name": "电脑" },
  75. * "priceCol": { "price": "3000" }
  76. * }
  77. * ],
  78. * "total": {
  79. * "amountCol": "27000",
  80. * "countCol": "15"
  81. * }
  82. * }
  83. *
  84. *
  85. * //获取到数据网格中的其他数据:
  86. *
  87. * //获取数据网格中的第一条数据
  88. * var data = this.data.datagrid.data[0];
  89. *
  90. * //获取数据网格中的第一条数据的 nameCol 列的值
  91. * var data = this.data.datagrid.data[0].nameCol.name;
  92. *
  93. * //获取数据网格中的 amountCol 列的总计值
  94. * var data = this.data.datagrid.total.amountCol;
  95. *
  96. *@example
  97. * <caption>
  98. * <b>修改数据网格中的数据</b></br>
  99. * 经过本样例修改后,数据网格将变为:</br>
  100. * <img src="img/module/data/datagrid2.jpg">
  101. * </caption>
  102. * //修改数据网格中的第一条数据的 nameCol 列的值
  103. * this.data.datagrid.data[0].nameCol.name='平板电脑';
  104. */
  105. /**
  106. * 为data对象添加一个数据节点。
  107. * @instance
  108. * @method add
  109. * @memberOf module:data
  110. * @param {(String|Number)} key - 要添加的新的数据节点名称或数组索引号。
  111. * @param {(String|Number|Array|JsonObject)} value - 新的数据节点的值。
  112. * @param {Boolean} [overwrite] - 如果要添加的节点已经存在,是否覆盖。默认为 false。
  113. * @return {(String|Number|Array|JsonObject)} 新添加的数据节点或原有的同名节点。
  114. * @o2syntax
  115. * var newData = this.data.add(key, value, overwrite);
  116. * @example
  117. * //为data添加一个名为"remark"值为"I am remark"的数据
  118. * this.data.add("remark", "I am remark");
  119. * @example
  120. * //为data添加一个名为"person"的Object对象数据
  121. * var person = this.data.add("person", {});
  122. * person.add("name", "Tom");
  123. * person.add("age", 23);
  124. *
  125. * //或者可以这样
  126. * var person = this.data.add("person", {name: "Tom", "age": "23"});
  127. * @example
  128. * //为data添加一个名为"orders"的数组对象数据
  129. * var orders = this.data.add("orders", []);
  130. * orders.add({name: "phone", count: 5});
  131. * orders.add({name: "computer", count: 10});
  132. * orders[0].add("count", 10, true); //将第一条数据的count修改为10
  133. *
  134. * //或者可以这样
  135. * var orders = this.data.add("orders", [
  136. * {name: "phone", count: 5},
  137. * {name: "computer", count: 10}
  138. * ]);
  139. * //将第一条数据修改为name为mobile; count为10
  140. * orders.add(0, {name: "mobile", count: 10}, true);
  141. */
  142. /**保存data对象。
  143. * @method save
  144. * @static
  145. * @memberOf module:data
  146. * @param {Function} [callback] - 保存成功后的回调函数。
  147. * @o2syntax
  148. * this.data.save(callback);
  149. * @example
  150. * this.data.save(function(json){
  151. * this.form.notice("save success!", "success")
  152. *});
  153. */
  154. this.data.save = function(callback){
  155. _form.saveFormData(callback)
  156. // var formData = {
  157. // "data": data,
  158. // "sectionList": _form.getSectionList()
  159. // };
  160. // _form.workAction.saveSectionData(function(){if (callback) callback();}.bind(this), null, (ev.work.id || ev.workCompleted.id), formData);
  161. }
  162. };
  163. this.setData(_data);
  164. //task
  165. //this.task = ev.task;
  166. //this.task.process = function(routeName, opinion, callback){
  167. // _form.submitWork(routeName, opinion, callback);
  168. //};
  169. //inquiredRouteList
  170. //this.inquiredRouteList = null;
  171. //workContext
  172. /**
  173. * 您可以通过workContext获取和流程相关的流程实例对象数据。
  174. * @module workContext
  175. * @o2range {Process}
  176. * @o2ordernumber 20
  177. * @o2syntax
  178. * //您可以在表单或流程的各个嵌入脚本中,通过this来获取当前流程实例数据,如下:
  179. * var context = this.workContext;
  180. */
  181. this.workContext = {
  182. /**
  183. * 获取当前流程实例对象:work对象或workCompleted对象。
  184. * @method getWork
  185. * @static
  186. * @return {(Work|WorkCompleted)} 流程实例对象;如果流程已结束,返回已结束的流程实例对象.
  187. * @o2ActionOut x_processplatform_assemble_surface.WoWork|example=Work|ignoreNoDescr=true|Work对象:
  188. * @o2ActionOut x_processplatform_assemble_surface.WorkCompletedAction.get|example=WorkCompleted|ignoreProps=[properties]|WorkCompleted对象:
  189. * @o2syntax
  190. * var work = this.workContext.getWork();
  191. */
  192. "getWork": function(){return ev.work || ev.workCompleted;},
  193. /**
  194. * 获取当前流程实例所在的活动节点对象:activity对象。
  195. * @method getActivity
  196. * @static
  197. * @return {(Activity|Null)} 当前流程实例所在的活动节点对象,如果当前流程实例已流转完成,则返回null.
  198. * <pre><code class='language-js'>{
  199. * "id": "801087c5-a4e6-4b91-bf4d-a81cdaa04471", //节点ID
  200. * "name": "办理", //节点名称
  201. * "description": "", //节点描述
  202. * "alias": "", //节点别名
  203. * "resetRange": "department", //重置处理人范围
  204. * "resetCount": 0, //重置处理人数字
  205. * "allowReset": true, //是否允许重置
  206. * "manualMode": "single" //处理方式 单人single, 并行parallel, 串行queue, grab抢办
  207. * }</code></pre>
  208. * @o2syntax
  209. * var activity = this.workContext.getActivity();
  210. */
  211. "getActivity": function(){return ev.activity || null;},
  212. /**
  213. * 当前流程实例正在流转中,并且当前用户有待办,则返回当前用户的待办对象,否则返回null。
  214. * @summary 获取当前流程与当前用户相关的待办对象:task对象。
  215. * @o2ActionOut x_processplatform_assemble_surface.TaskAction.get|example=Task
  216. * @method getTask
  217. * @static
  218. * @return {(Task|Null)} 当前用户的待办任务对象:task。当前用户没有对此流程实例的待办时,或流程实例已经流转结束,返回null.
  219. * @o2syntax
  220. * var task = this.workContext.getTask();
  221. */
  222. "getTask": function(){return ev.task || null;},
  223. /**
  224. * 获取当前流程实例的所有待办对象。如果流程实例已流转完成,则返回一个空数组。
  225. * @method getTaskList
  226. * @o2ActionOut x_processplatform_assemble_surface.TaskAction.listWithWork|example=Task
  227. * @static
  228. * @param {Function} [callback] 正确获取待办数组的回调,如果有此参数,本方法以异步执行,否则同步执行
  229. * @param {Function} [error] 获取待办数组出错时的回调。
  230. * @return {(Task[])} 待办任务列表.
  231. * @o2syntax
  232. * //本样例以同步执行
  233. * var taskList = this.workContext.getTaskList();
  234. * @o2syntax
  235. * //本样例以异步执行
  236. * this.workContext.getTaskList( function(taskList){
  237. * //taskList 为待办数组
  238. * });
  239. */
  240. "getTaskList": function(callback, error){
  241. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  242. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  243. var list;
  244. o2.Actions.get("x_processplatform_assemble_surface").listTaskByWork(ev.work.id, function(json){
  245. list = json.data;
  246. if (cb) cb(list);
  247. }, ecb, !!cb);
  248. return list;
  249. },
  250. /**
  251. * 根据当前工作的job获取当前流程实例的所有待办对象。如果流程实例已流转完成,则返回一个空数组。
  252. * @method getTaskListByJob
  253. * @o2ActionOut x_processplatform_assemble_surface.TaskAction.listWithJob|example=Task
  254. * @static
  255. * @param {Function} [callback] 正确获取待办数组的回调,如果有此参数,本方法以异步执行,否则同步执行
  256. * @param {Function} [error] 获取待办数组出错时的回调。
  257. * @return {(Task[])} 待办任务列表.
  258. * @o2syntax
  259. * //本样例以同步执行
  260. * var taskList = this.workContext.getTaskListByJob();
  261. * @o2syntax
  262. * //本样例以异步执行
  263. * this.workContext.getTaskListByJob( function(taskList){
  264. * //taskList 为待办数组
  265. * });
  266. */
  267. "getTaskListByJob": function(callback, error){
  268. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  269. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  270. var list;
  271. o2.Actions.get("x_processplatform_assemble_surface").listTaskByJob(ev.work.job, function(json){
  272. list = json.data;
  273. if (cb) cb(list);
  274. }, ecb, !!cb);
  275. return list;
  276. },
  277. /**
  278. * 获取当前流程实例的所有已办对象。如果流程实例没有任何人处理过,则返回一个空数组。
  279. * @method getTaskCompletedList
  280. * @static
  281. * @param {Function} [callback] 正确获取已办数组的回调,如果有此参数,本方法以异步执行,否则同步执行
  282. * @param {Function} [error] 获取已办数组出错时的回调。
  283. * @return {(TaskCompleted[])} 已办任务列表.
  284. * @o2ActionOut x_processplatform_assemble_surface.TaskCompletedAction.listWithWork|example=Task
  285. * @o2syntax
  286. * //本样例以同步执行
  287. * var taskCompletedList = this.workContext.getTaskCompletedList();
  288. * @o2syntax
  289. * //本样例以异步执行
  290. * this.workContext.getTaskCompletedList( function(taskCompletedList){
  291. * //taskCompletedList 为待办数组
  292. * });
  293. */
  294. "getTaskCompletedList": function(callback, error){
  295. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  296. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  297. var list;
  298. o2.Actions.get("x_processplatform_assemble_surface").listTaskCompletedByWork(ev.work.id, function(json){
  299. list = json.data;
  300. if (cb) cb(list);
  301. }, ecb, !!cb);
  302. return list;
  303. },
  304. /**
  305. * 根据当前工作的job获取当前流程实例的所有已办对象。如果流程实例没有任何人处理过,则返回一个空数组。
  306. * @method getTaskCompletedListByJob
  307. * @static
  308. * @param {Function} [callback] 正确获取已办数组的回调,如果有此参数,本方法以异步执行,否则同步执行
  309. * @param {Function} [error] 获取已办数组出错时的回调。
  310. * @return {(TaskCompleted[])} 已办任务列表.
  311. * @o2ActionOut x_processplatform_assemble_surface.TaskCompletedAction.listWithJob|example=Task
  312. * @o2syntax
  313. * //本样例以同步执行
  314. * var taskCompletedList = this.workContext.getTaskCompletedListByJob();
  315. * @o2syntax
  316. * //本样例以异步执行
  317. * this.workContext.getTaskCompletedListByJob( function(taskCompletedList){
  318. * //taskCompletedList 为待办数组
  319. * });
  320. */
  321. "getTaskCompletedListByJob": function(callback, error){
  322. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  323. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  324. var list;
  325. o2.Actions.get("x_processplatform_assemble_surface").listTaskCompletedByJob(ev.work.job, function(json){
  326. list = json.data;
  327. if (cb) cb(list);
  328. }, ecb, !!cb);
  329. return list;
  330. },
  331. /**
  332. * @summary 获取当前流程实例的所有待阅对象数组。如果流程实例无待阅,则返回一个空数组。
  333. * @method getReadList
  334. * @static
  335. * @param {Function} [callback] 正确获取待阅数组的回调,如果有此参数,本方法以异步执行,否则同步执行
  336. * @param {Function} [error] 获取待阅数组出错时的回调。
  337. * @return {(Read[])} 当前流程实例的所有待阅对象数组.
  338. * @o2ActionOut x_processplatform_assemble_surface.ReadAction.get|example=Read
  339. * @o2syntax
  340. * //本样例以同步执行
  341. * var readList = this.workContext.getReadList();
  342. * @o2syntax
  343. * //本样例以异步执行
  344. * this.workContext.getReadList( function(readList){
  345. * //readList 为待阅数组
  346. * });
  347. */
  348. "getReadList": function(callback, error){
  349. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  350. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  351. var list;
  352. o2.Actions.get("x_processplatform_assemble_surface").listReadByWork(ev.work.id, function(json){
  353. list = json.data;
  354. if (cb) cb(list);
  355. }, ecb, !!cb);
  356. return list;
  357. },
  358. /**
  359. * @summary 根据当前工作的job获取当前流程实例的所有待阅对象。如果流程实例无待阅,则返回一个空数组。
  360. * @method getReadListByJob
  361. * @static
  362. * @param {Function} [callback] 正确获取待阅数组的回调,如果有此参数,本方法以异步执行,否则同步执行
  363. * @param {Function} [error] 获取待阅数组出错时的回调。
  364. * @return {(Read[])} 当前流程实例的所有待阅对象数组.
  365. * @o2ActionOut x_processplatform_assemble_surface.ReadAction.listWithJob|example=Read
  366. * @o2syntax
  367. * //本样例以同步执行
  368. * var readList = this.workContext.getReadListByJob();
  369. * @o2syntax
  370. * //本样例以异步执行
  371. * this.workContext.getReadListByJob( function(readList){
  372. * //readList 为待阅数组
  373. * });
  374. */
  375. "getReadListByJob": function(callback, error){
  376. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  377. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  378. var list;
  379. o2.Actions.get("x_processplatform_assemble_surface").listReadByJob(ev.work.job, function(json){
  380. list = json.data;
  381. if (cb) cb(list);
  382. }, ecb, !!cb);
  383. return list;
  384. },
  385. /**
  386. * @summary 获取当前流程实例的所有已阅对象。如果流程实例没有已阅,则返回一个空数组。
  387. * @method getReadCompletedList
  388. * @static
  389. * @param {Function} [callback] 正确获取已阅数组的回调,如果有此参数,本方法以异步执行,否则同步执行
  390. * @param {Function} [error] 获取已阅数组出错时的回调。
  391. * @return {(ReadCompleted[])} 当前流程实例的所有已阅对象数组.
  392. * @o2ActionOut x_processplatform_assemble_surface.ReadCompletedAction.listWithWork|example=Read
  393. * @o2syntax
  394. * //本样例以同步执行
  395. * var readCompletedList = this.workContext.getReadCompletedList();
  396. * @o2syntax
  397. * //本样例以异步执行
  398. * this.workContext.getReadCompletedList( function(readCompletedList){
  399. * //readCompletedList 为已阅数组
  400. * });
  401. */
  402. "getReadCompletedList": function(callback, error){
  403. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  404. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  405. var list;
  406. o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByWork(ev.work.id, function(json){
  407. list = json.data;
  408. if (cb) cb(list);
  409. }, ecb, !!cb);
  410. return list;
  411. },
  412. /**
  413. * @summary 根据当前工作的job获取当前流程实例的所有已阅对象。如果流程实例没有已阅,则返回一个空数组。
  414. * @method getReadCompletedListByJob
  415. * @static
  416. * @param {Function} [callback] 正确获取已阅数组的回调,如果有此参数,本方法以异步执行,否则同步执行
  417. * @param {Function} [error] 获取已阅数组出错时的回调。
  418. * @return {(ReadCompleted[])} 当前流程实例的所有已阅对象数组.
  419. * @o2ActionOut x_processplatform_assemble_surface.ReadCompletedAction.listWithJob|example=Read
  420. * @o2syntax
  421. * //本样例以同步执行
  422. * var readCompletedList = this.workContext.getReadCompletedListByJob();
  423. * @o2syntax
  424. * //本样例以异步执行
  425. * this.workContext.getReadCompletedListByJob( function(readCompletedList){
  426. * //readCompletedList 为已阅数组
  427. * });
  428. */
  429. "getReadCompletedListByJob": function(callback, error){
  430. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  431. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  432. var list;
  433. o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByJob(ev.work.job, function(json){
  434. list = json.data;
  435. if (cb) cb(list);
  436. }, ecb, !!cb);
  437. return list;
  438. },
  439. "getJobTaskList": this.getTaskListByJob,
  440. "getJobReadList": this.getReadListByJob,
  441. "getJobTaskCompletedList": this.getTaskCompletedListByJob,
  442. "getJobReadCompletedList": this.getReadCompletedListByJob,
  443. /**
  444. * @summary 获取当前人对流程实例的权限。
  445. * @method getControl
  446. * @static
  447. * @return {WorkControl} 流程实例权限对象.
  448. * <pre><code class='language-js'>{
  449. * "allowVisit": true, //是否允许访问
  450. * "allowProcessing": true, //是否允许流转
  451. * "allowReadProcessing": false, //是否有待阅
  452. * "allowSave": true, //是否允许保存业务数据
  453. * "allowReset": false, //是否允许重置处理人
  454. * "allowRetract": false, //是否允许撤回
  455. * "allowReroute": false, //是否允许调度
  456. * "allowDelete": true, //是否允许删除流程实例
  457. * "allowRollback": false, //是否允许流程回溯
  458. * "allowAddSplit": false, //是否允许增加分支
  459. * "allowPress": false, //是否允许催办
  460. * }</code></pre>
  461. * @o2syntax
  462. * var control = this.workContext.getControl();
  463. */
  464. "getControl": function(){return ev.control;},
  465. /**
  466. * @summary 获取当前流程实例的所有流程记录(WorkLog)。
  467. * @method getWorkLogList
  468. * @static
  469. * @return {WorkLog[]} 流程记录对象.
  470. * @o2ActionOut x_processplatform_assemble_surface.WorkLogAction.listWithJob
  471. * @o2syntax
  472. * var workLogList = this.workContext.getWorkLogList();
  473. */
  474. "getWorkLogList": function(){return ev.workLogList;},
  475. /**
  476. * @summary 获取当前流程实例的所有流程记录(Record)。
  477. * @method getRecordList
  478. * @o2ActionOut x_processplatform_assemble_surface.RecordAction.listWithJob
  479. * @static
  480. * @return {Record[]} 流程记录(Record)对象.
  481. * @o2syntax
  482. * var workLogList = this.workContext.getRecordList();
  483. */
  484. "getRecordList": function(){return ev.recordList;},
  485. /**
  486. * @summary 获取当前流程实例的附件对象列表。
  487. * @method getAttachmentList
  488. * @static
  489. * @return {WorkAttachmentData[]} 附件数据.
  490. * @o2ActionOut x_processplatform_assemble_surface.AttachmentAction.getWithWorkOrWorkCompleted|example=Attachment
  491. * @o2syntax
  492. * var attachmentList = this.workContext.getAttachmentList();
  493. */
  494. "getAttachmentList": function(){return ev.attachmentList;},
  495. /**
  496. * @summary 获取当前待办的可选路由。与task对象中的routeNameList取值相同。
  497. * @method getRouteList
  498. * @static
  499. * @return {String[]} 路由字符串数组.
  500. * @o2syntax
  501. * var routeList = this.workContext.getRouteList();
  502. */
  503. "getRouteList": function(){return (ev.task) ? ev.task.routeNameList: null;},
  504. "getInquiredRouteList": function(){return null;},
  505. /**
  506. * @summary 重新设置流程实例标题。。
  507. * @method setTitle
  508. * @static
  509. * @param {String} title - 路由字符串数组.
  510. * @o2syntax
  511. * this.workContext.setTitle(title);
  512. * @example
  513. * this.workContext.setTitle("标题");
  514. */
  515. "setTitle": function(title){
  516. if (!this.workAction){
  517. MWF.require("MWF.xScript.Actions.WorkActions", null, false);
  518. this.workAction = new MWF.xScript.Actions.WorkActions();
  519. }
  520. this.workAction.setTitle(ev.work.id, {"title": title});
  521. }
  522. };
  523. this.workContent = this.workContext;
  524. var _redefineWorkProperties = function(work){
  525. if (work){
  526. work.creatorPersonDn = work.creatorPerson ||"";
  527. work.creatorUnitDn = work.creatorUnit ||"";
  528. work.creatorUnitDnList = work.creatorUnitList ||"";
  529. work.creatorIdentityDn = work.creatorIdentity ||"";
  530. var o = {
  531. "creatorPerson": {"get": function(){return this.creatorPersonDn.substring(0, this.creatorPersonDn.indexOf("@"));}},
  532. "creatorUnit": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  533. "creatorDepartment": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  534. "creatorIdentity": {"get": function(){return this.creatorIdentityDn.substring(0, this.creatorIdentityDn.indexOf("@"));}},
  535. // "creatorUnitList": {
  536. // "get": function(){
  537. // var v = [];
  538. // this.creatorUnitDnList.each(function(dn){
  539. // v.push(dn.substring(0, dn.indexOf("@")))
  540. // });
  541. // return v;
  542. // }
  543. // },
  544. "creatorCompany": {"get": function(){
  545. if (this.creatorUnitLevel){
  546. var level = this.creatorUnitLevel.split("/");
  547. return level[0];
  548. }else{
  549. return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));
  550. }
  551. }}
  552. };
  553. MWF.defineProperties(work, o);
  554. }
  555. return work;
  556. };
  557. var _redefineTaskProperties = function(task){
  558. if (task){
  559. task.personDn = task.person || "";
  560. task.unitDn = task.unit || "";
  561. task.unitDnList = task.unitList || "";
  562. task.identityDn = task.identity || "";
  563. var o = {
  564. "person": {"get": function(){return this.personDn.substring(0, this.personDn.indexOf("@"));}},
  565. "unit": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  566. "department": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  567. "identity": {"get": function(){return this.identityDn.substring(0, this.identityDn.indexOf("@"));}},
  568. // "unitList": {
  569. // "get": function(){
  570. // var v = [];
  571. // this.unitDnList.each(function(dn){
  572. // v.push(dn.substring(0, dn.indexOf("@")))
  573. // });
  574. // return v;
  575. // }
  576. // },
  577. "company": {"get": function(){return this.unitList[0];}}
  578. };
  579. MWF.defineProperties(task, o);
  580. }
  581. return task;
  582. };
  583. _redefineWorkProperties(this.workContext.getWork());
  584. _redefineTaskProperties(_redefineWorkProperties(this.workContext.getTask()));
  585. //dict
  586. this.Dict = MWF.xScript.createDict(_form.json.application);
  587. //unit
  588. var orgActions = null;
  589. var getOrgActions = function(){
  590. // if (!orgActions){
  591. // MWF.xDesktop.requireApp("Org", "Actions.RestActions", null, false);
  592. // orgActions = new MWF.xApplication.Org.Actions.RestActions ();
  593. // }
  594. if (!orgActions){
  595. MWF.require("MWF.xScript.Actions.UnitActions", null, false);
  596. orgActions = new MWF.xScript.Actions.UnitActions();
  597. }
  598. };
  599. var getNameFlag = function(name){
  600. var t = typeOf(name);
  601. if (t==="array"){
  602. var v = [];
  603. name.each(function(id){
  604. v.push((typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  605. });
  606. return v;
  607. }else{
  608. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  609. }
  610. };
  611. this.org = {
  612. //群组***************
  613. //获取群组--返回群组的对象数组
  614. /**
  615. 根据群组标识获取对应的群组对象数组:group对象数组
  616. */
  617. getGroup: function(name, async){
  618. getOrgActions();
  619. var data = {"groupList": getNameFlag(name)};
  620. var v = null;
  621. var cb = function(json){
  622. v = json.data;
  623. v = (v && v.length===1) ? v[0] : v
  624. if (async && o2.typeOf(async)=="function") return async(v);
  625. return v;
  626. };
  627. var promise = orgActions.listGroup(data, cb, null, !!async);
  628. return (!!async) ? promise : v;
  629. // var v = null;
  630. // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  631. // return (v && v.length===1) ? v[0] : v;
  632. },
  633. //查询下级群组--返回群组的对象数组
  634. //nested 布尔 true嵌套下级;false直接下级;默认false;
  635. listSubGroup: function(name, nested, async){
  636. getOrgActions();
  637. var data = {"groupList": getNameFlag(name)};
  638. var v = null;
  639. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  640. // v = json.data;
  641. // return v;
  642. // }.ag().catch(function(json){ return json; });
  643. var cb = function(json){
  644. v = json.data;
  645. if (async && o2.typeOf(async)=="function") return async(v);
  646. return v;
  647. };
  648. var promise;
  649. if (nested){
  650. promise = orgActions.listSubGroupNested(data, cb, null, !!async);
  651. }else{
  652. promise = orgActions.listSubGroupDirect(data, cb, null, !!async);
  653. }
  654. return (!!async) ? promise : v;
  655. // var v = null;
  656. // if (nested){
  657. // orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  658. // }else{
  659. // orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  660. // }
  661. // return v;
  662. },
  663. //查询上级群组--返回群组的对象数组
  664. //nested 布尔 true嵌套上级;false直接上级;默认false;
  665. listSupGroup:function(name, nested, async){
  666. getOrgActions();
  667. var data = {"groupList": getNameFlag(name)};
  668. var v = null;
  669. var cb = function(json){
  670. v = json.data;
  671. if (async && o2.typeOf(async)=="function") return async(v);
  672. return v;
  673. };
  674. var promise
  675. if (nested){
  676. var promise = orgActions.listSupGroupNested(data, cb, null, !!async);
  677. }else{
  678. var promise = orgActions.listSupGroupDirect(data, cb, null, !!async);
  679. }
  680. return (!!async) ? promise : v;
  681. // var v = null;
  682. // if (nested){
  683. // orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  684. // }else{
  685. // orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  686. // }
  687. // return v;
  688. },
  689. //人员所在群组(嵌套)--返回群组的对象数组
  690. listGroupWithPerson:function(name, async){
  691. getOrgActions();
  692. var data = {"personList": getNameFlag(name)};
  693. var v = null;
  694. var cb = function(json){
  695. v = json.data;
  696. if (async && o2.typeOf(async)=="function") return async(v);
  697. return v;
  698. };
  699. var promise = orgActions.listGroupWithPerson(data, cb, null, !!async);
  700. return (!!async) ? promise : v;
  701. // var v = null;
  702. // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  703. // return v;
  704. },
  705. //群组是否拥有角色--返回true, false
  706. groupHasRole: function(name, role, async){
  707. getOrgActions();
  708. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  709. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  710. var v = false;
  711. var cb = function(json){
  712. v = json.data.value;
  713. if (async && o2.typeOf(async)=="function") return async(v);
  714. return v;
  715. };
  716. var promise = orgActions.groupHasRole(data, cb, null, !!async);
  717. return (!!async) ? promise : v;
  718. // var v = false;
  719. // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  720. // return v;
  721. },
  722. //角色***************
  723. //获取角色--返回角色的对象数组
  724. getRole: function(name, async){
  725. getOrgActions();
  726. var data = {"roleList": getNameFlag(name)};
  727. var v = null;
  728. var cb = function(json){
  729. v = json.data;
  730. v = (v && v.length===1) ? v[0] : v;
  731. if (async && o2.typeOf(async)=="function") return async(v);
  732. return v;
  733. };
  734. var promise = orgActions.listRole(data, cb, null, !!async);
  735. return (!!async) ? promise : v;
  736. // var v = null;
  737. // orgActions.listRole(data, function(json){v = json.data;}, null, false);
  738. // return (v && v.length===1) ? v[0] : v;
  739. },
  740. //人员所有角色(嵌套)--返回角色的对象数组
  741. listRoleWithPerson:function(name, async){
  742. getOrgActions();
  743. var data = {"personList": getNameFlag(name)};
  744. var v = null;
  745. var cb = function(json){
  746. v = json.data;
  747. if (async && o2.typeOf(async)=="function") return async(v);
  748. return v;
  749. };
  750. var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
  751. return (!!async) ? promise : v;
  752. // var v = null;
  753. // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  754. // return v;
  755. },
  756. //人员***************
  757. //人员是否拥有角色--返回true, false
  758. personHasRole: function(name, role, async){
  759. getOrgActions();
  760. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  761. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  762. var v = false;
  763. var cb = function(json){
  764. v = json.data.value;
  765. if (async && o2.typeOf(async)=="function") return async(v);
  766. return v;
  767. };
  768. var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
  769. return (!!async) ? promise : v;
  770. // var v = false;
  771. // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  772. // return v;
  773. },
  774. //获取人员--返回人员的对象数组
  775. getPerson: function(name, async){
  776. getOrgActions();
  777. var data = {"personList": getNameFlag(name)};
  778. var v = null;
  779. var cb = function(json){
  780. v = json.data;
  781. v = (v && v.length===1) ? v[0] : v;
  782. if (async && o2.typeOf(async)=="function") return async(v);
  783. return v;
  784. };
  785. var promise = orgActions.listPerson(data, cb, null, !!async);
  786. return (!!async) ? promise : v;
  787. // var v = null;
  788. // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  789. // return (v && v.length===1) ? v[0] : v;
  790. },
  791. //查询下级人员--返回人员的对象数组
  792. //nested 布尔 true嵌套下级;false直接下级;默认false;
  793. listSubPerson: function(name, nested, async){
  794. getOrgActions();
  795. var data = {"personList": getNameFlag(name)};
  796. var v = null;
  797. var cb = function(json){
  798. v = json.data;
  799. if (async && o2.typeOf(async)=="function") return async(v);
  800. return v;
  801. };
  802. var promise;
  803. if (nested){
  804. promise = orgActions.listPersonSubNested(data, cb, null, !!async);
  805. }else{
  806. promise = orgActions.listPersonSubDirect(data, cb, null, !!async);
  807. }
  808. return (!!async) ? promise : v;
  809. },
  810. //查询上级人员--返回人员的对象数组
  811. //nested 布尔 true嵌套上级;false直接上级;默认false;
  812. listSupPerson: function(name, nested, async){
  813. getOrgActions();
  814. var data = {"personList": getNameFlag(name)};
  815. var v = null;
  816. var cb = function(json){
  817. v = json.data;
  818. if (async && o2.typeOf(async)=="function") return async(v);
  819. return v;
  820. };
  821. var promise;
  822. if (nested){
  823. promise = orgActions.listPersonSupNested(data, cb, null, !!async);
  824. }else{
  825. promise = orgActions.listPersonSupDirect(data, cb, null, !!async);
  826. }
  827. return (!!async) ? promise : v;
  828. },
  829. //获取群组的所有人员--返回人员的对象数组
  830. listPersonWithGroup: function(name, async){
  831. getOrgActions();
  832. var data = {"groupList": getNameFlag(name)};
  833. var v = null;
  834. var cb = function(json){
  835. v = json.data;
  836. if (async && o2.typeOf(async)=="function") return async(v);
  837. return v;
  838. };
  839. var promise = orgActions.listPersonWithGroup(data, cb, null, !!async);
  840. return (!!async) ? promise : v;
  841. },
  842. //获取角色的所有人员--返回人员的对象数组
  843. listPersonWithRole: function(name, async){
  844. getOrgActions();
  845. var data = {"roleList": getNameFlag(name)};
  846. var v = null;
  847. var cb = function(json){
  848. v = json.data;
  849. if (async && o2.typeOf(async)=="function") return async(v);
  850. return v;
  851. };
  852. var promise
  853. promise = orgActions.listPersonWithRole(data, cb, null, !!async);
  854. return (!!async) ? promise : v;
  855. },
  856. //获取身份的所有人员--返回人员的对象数组
  857. listPersonWithIdentity: function(name, async){
  858. getOrgActions();
  859. var data = {"identityList": getNameFlag(name)};
  860. var v = null;
  861. var cb = function(json){
  862. v = json.data;
  863. if (async && o2.typeOf(async)=="function") return async(v);
  864. return v;
  865. };
  866. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  867. return (!!async) ? promise : v;
  868. },
  869. //获取身份的所有人员--返回人员的对象数组或人员对象
  870. getPersonWithIdentity: function(name, async){
  871. getOrgActions();
  872. var data = {"identityList": getNameFlag(name)};
  873. var v = null;
  874. var cb = function(json){
  875. v = json.data;
  876. v = (v && v.length===1) ? v[0] : v;
  877. if (async && o2.typeOf(async)=="function") return async(v);
  878. return v;
  879. };
  880. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  881. return (!!async) ? promise : v;
  882. },
  883. //查询组织成员的人员--返回人员的对象数组
  884. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  885. listPersonWithUnit: function(name, nested, async){
  886. getOrgActions();
  887. var data = {"unitList": getNameFlag(name)};
  888. var v = null;
  889. var cb = function(json){
  890. v = json.data;
  891. if (async && o2.typeOf(async)=="function") return async(v);
  892. return v;
  893. };
  894. var promise;
  895. if (nested){
  896. promise = orgActions.listPersonWithUnitNested(data, cb, null, !!async);
  897. }else{
  898. promise = orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
  899. }
  900. return (!!async) ? promise : v;
  901. },
  902. //根据属性查询人员--返回人员的对象数组
  903. //name string 属性名
  904. //value string 属性值
  905. listPersonWithAttribute: function(name, value, async){
  906. getOrgActions();
  907. var data = {"name": name, "attribute": value};
  908. var v = null;
  909. var cb = function(json){
  910. v = json.data;
  911. if (async && o2.typeOf(async)=="function") return async(v);
  912. return v;
  913. };
  914. var promise = orgActions.listPersonWithAttribute(data, cb, null, !!async);
  915. return (!!async) ? promise : v;
  916. },
  917. //根据属性查询人员--返回人员的全称数组
  918. //name string 属性名
  919. //value string 属性值
  920. listPersonNameWithAttribute: function(name, value, async){
  921. getOrgActions();
  922. var data = {"name": name, "attribute": value};
  923. var v = null;
  924. var cb = function(json){
  925. v = json.data.personList;
  926. if (async && o2.typeOf(async)=="function") return async(v);
  927. return v;
  928. };
  929. var promise = orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
  930. return (!!async) ? promise : v;
  931. },
  932. //人员属性************
  933. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  934. appendPersonAttribute: function(person, attr, values, success, failure, async){
  935. getOrgActions();
  936. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  937. var data = {"attributeList":values,"name":attr,"person":personFlag};
  938. var cb = function(json){
  939. if (success) return success(json);
  940. }.ag().catch(function(xhr, text, error){
  941. if (failure) return failure(xhr, text, error);
  942. });
  943. orgActions.appendPersonAttribute(data, cb, null, !!async);
  944. },
  945. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  946. setPersonAttribute: function(person, attr, values, success, failure, async){
  947. getOrgActions();
  948. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  949. var data = {"attributeList":values,"name":attr,"person":personFlag};
  950. var cb = function(json){
  951. if (success) return success(json);
  952. }.ag().catch(function(xhr, text, error){
  953. if (failure) return failure(xhr, text, error);
  954. });
  955. orgActions.setPersonAttribute(data, cb, null, !!async);
  956. },
  957. //获取人员属性值
  958. getPersonAttribute: function(person, attr, async){
  959. getOrgActions();
  960. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  961. var data = {"name":attr,"person":personFlag};
  962. var v = null;
  963. var cb = function(json){
  964. v = json.data.attributeList;
  965. if (async && o2.typeOf(async)=="function") return async(v);
  966. return v;
  967. };
  968. var promise = orgActions.getPersonAttribute(data, cb, null, !!async);
  969. return (!!async) ? promise : v;
  970. },
  971. //列出人员所有属性的名称
  972. listPersonAttributeName: function(name, async){
  973. getOrgActions();
  974. var data = {"personList":getNameFlag(name)};
  975. var v = null;
  976. var cb = function(json){
  977. v = json.data.nameList;
  978. if (async && o2.typeOf(async)=="function") return async(v);
  979. return v;
  980. };
  981. var promise = orgActions.listPersonAttributeName(data, cb, null, !!async);
  982. return (!!async) ? promise : v;
  983. },
  984. //列出人员的所有属性
  985. listPersonAllAttribute: function(name, async){
  986. getOrgActions();
  987. var data = {"personList":getNameFlag(name)};
  988. var v = null;
  989. var cb = function(json){
  990. v = json.data;
  991. if (async && o2.typeOf(async)=="function") return async(v);
  992. return v;
  993. };
  994. var promise = orgActions.listPersonAllAttribute(data, cb, null, !!async);
  995. return (!!async) ? promise : v;
  996. },
  997. //身份**********
  998. //获取身份
  999. getIdentity: function(name, async){
  1000. getOrgActions();
  1001. var data = {"identityList":getNameFlag(name)};
  1002. var v = null;
  1003. var cb = function(json){
  1004. v = json.data;
  1005. v = (v && v.length===1) ? v[0] : v;
  1006. if (async && o2.typeOf(async)=="function") return async(v);
  1007. return v;
  1008. };
  1009. var promise = orgActions.listIdentity(data, cb, null, !!async);
  1010. return (!!async) ? promise : v;
  1011. },
  1012. //列出人员的身份
  1013. listIdentityWithPerson: function(name, async){
  1014. getOrgActions();
  1015. var data = {"personList":getNameFlag(name)};
  1016. var v = null;
  1017. var cb = function(json){
  1018. v = json.data;
  1019. if (async && o2.typeOf(async)=="function") return async(v);
  1020. return v;
  1021. };
  1022. var promise = orgActions.listIdentityWithPerson(data, cb, null, !!async);
  1023. return (!!async) ? promise : v;
  1024. },
  1025. //查询组织成员身份--返回身份的对象数组
  1026. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  1027. listIdentityWithUnit: function(name, nested, async){
  1028. getOrgActions();
  1029. var data = {"unitList": getNameFlag(name)};
  1030. var v = null;
  1031. // var cb = function(json){
  1032. // v = json.data;
  1033. // if (async && o2.typeOf(async)=="function") return async(v);
  1034. // return v;
  1035. // }.ag().catch(function(json){ return json; });
  1036. var cb = function(json){
  1037. v = json.data;
  1038. if (async && o2.typeOf(async)=="function") return async(v);
  1039. return v;
  1040. };
  1041. var method = (nested) ? "listIdentityWithUnitNested" : "listIdentityWithUnitDirect";
  1042. var promise = orgActions[method](data, cb, null, !!async);
  1043. promise.name = "org";
  1044. //
  1045. // if (nested){
  1046. // orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
  1047. // }else{
  1048. // orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
  1049. // }
  1050. return (!!async) ? promise : v;
  1051. },
  1052. //组织**********
  1053. //获取组织
  1054. getUnit: function(name, async){
  1055. getOrgActions();
  1056. var data = {"unitList":getNameFlag(name)};
  1057. var v = null;
  1058. var cb = function(json){
  1059. v = json.data;
  1060. v = (v && v.length===1) ? v[0] : v;
  1061. if (async && o2.typeOf(async)=="function") return async(v);
  1062. return v;
  1063. };
  1064. var promise = orgActions.listUnit(data, cb, null, !!async);
  1065. return (!!async) ? promise : v;
  1066. },
  1067. //查询组织的下级--返回组织的对象数组
  1068. //nested 布尔 true嵌套下级;false直接下级;默认false;
  1069. listSubUnit: function(name, nested, async){
  1070. getOrgActions();
  1071. var data = {"unitList": getNameFlag(name)};
  1072. var v = null;
  1073. var cb = function(json){
  1074. v = json.data;
  1075. if (async && o2.typeOf(async)=="function") return async(v);
  1076. return v;
  1077. };
  1078. var promise;
  1079. if (nested){
  1080. promise = orgActions.listUnitSubNested(data, cb, null, !!async);
  1081. }else{
  1082. promise = orgActions.listUnitSubDirect(data, cb, null, !!async);
  1083. }
  1084. return (!!async) ? promise : v;
  1085. },
  1086. //查询组织的上级--返回组织的对象数组
  1087. //nested 布尔 true嵌套上级;false直接上级;默认false;
  1088. //async 布尔 true异步请求
  1089. listSupUnit: function(name, nested, async){
  1090. getOrgActions();
  1091. var data = {"unitList": getNameFlag(name)};
  1092. var v = null;
  1093. var cb = function(json){
  1094. v = json.data;
  1095. if (async && o2.typeOf(async)=="function") return async(v);
  1096. return v;
  1097. };
  1098. var promise;
  1099. if (nested){
  1100. promise = orgActions.listUnitSupNested(data, cb, null, !!async);
  1101. }else{
  1102. promise = orgActions.listUnitSupDirect(data, cb, null, !!async);
  1103. }
  1104. return (!!async) ? promise : v;
  1105. // if (callback){
  1106. // if (nested){
  1107. // orgActions.listUnitSupNested(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  1108. // }else{
  1109. // orgActions.listUnitSupDirect(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  1110. // }
  1111. // }else{
  1112. // var v = null;
  1113. // if (nested){
  1114. // orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  1115. // }else{
  1116. // orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  1117. // }
  1118. // return v;
  1119. // }
  1120. },
  1121. //根据个人身份获取组织
  1122. //flag 数字 表示获取第几层的组织
  1123. // 字符串 表示获取指定类型的组织
  1124. // 空 表示获取直接所在的组织
  1125. getUnitByIdentity: function(name, flag, async){
  1126. getOrgActions();
  1127. var getUnitMethod = "current";
  1128. var v;
  1129. if (flag){
  1130. if (typeOf(flag)==="string") getUnitMethod = "type";
  1131. if (typeOf(flag)==="number") getUnitMethod = "level";
  1132. }
  1133. var cb;
  1134. var promise;
  1135. switch (getUnitMethod){
  1136. case "current":
  1137. var data = {"identityList":getNameFlag(name)};
  1138. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  1139. // v = json.data; v=(v&&v.length===1) ? v[0] : v; return v;
  1140. // }.ag().catch(function(json){ return json; });
  1141. cb = function(json){
  1142. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  1143. if (async && o2.typeOf(async)=="function") return async(v);
  1144. return v;
  1145. };
  1146. promise = orgActions.listUnitWithIdentity(data, cb, null, !!async);
  1147. break;
  1148. case "type":
  1149. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  1150. cb = function(json){
  1151. v = json.data;
  1152. if (async && o2.typeOf(async)=="function") return async(v);
  1153. return v;
  1154. };
  1155. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  1156. // v = json.data; return v;
  1157. // }.ag().catch(function(json){ return json; });
  1158. promise = orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
  1159. break;
  1160. case "level":
  1161. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  1162. cb = function(json){
  1163. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  1164. if (async && o2.typeOf(async)=="function") return async(v);
  1165. return v;
  1166. };
  1167. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  1168. // v = json.data; return v;
  1169. // }.ag().catch(function(json){ return json; });
  1170. promise = orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
  1171. break;
  1172. }
  1173. return (!!async) ? promise : v;
  1174. },
  1175. //列出身份所在组织的所有上级组织
  1176. listAllSupUnitWithIdentity: function(name, async){
  1177. getOrgActions();
  1178. var data = {"identityList":getNameFlag(name)};
  1179. var v = null;
  1180. var cb = function(json){
  1181. v = json.data;
  1182. if (async && o2.typeOf(async)=="function") return async(v);
  1183. return v;
  1184. };
  1185. var promise = orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
  1186. return (!!async) ? promise : v;
  1187. },
  1188. //获取人员所在的所有组织
  1189. listUnitWithPerson: function(name, async){
  1190. getOrgActions();
  1191. var data = {"personList":getNameFlag(name)};
  1192. var v = null;
  1193. var cb = function(json){
  1194. v = json.data;
  1195. if (async && o2.typeOf(async)=="function") return async(v);
  1196. return v;
  1197. };
  1198. var promise = orgActions.listUnitWithPerson(data, cb, null, !!async);
  1199. return (!!async) ? promise : v;
  1200. },
  1201. //列出人员所在组织的所有上级组织
  1202. listAllSupUnitWithPerson: function(name, async){
  1203. getOrgActions();
  1204. var data = {"personList":getNameFlag(name)};
  1205. var v = null;
  1206. var cb = function(json){
  1207. v = json.data;
  1208. if (async && o2.typeOf(async)=="function") return async(v);
  1209. return v;
  1210. };
  1211. var promise = orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
  1212. return (!!async) ? promise : v;
  1213. },
  1214. //根据组织属性,获取所有符合的组织
  1215. listUnitWithAttribute: function(name, attribute, async){
  1216. getOrgActions();
  1217. var data = {"name":name,"attribute":attribute};
  1218. var v = null;
  1219. var cb = function(json){
  1220. v = json.data;
  1221. if (async && o2.typeOf(async)=="function") return async(v);
  1222. return v;
  1223. };
  1224. promise = orgActions.listUnitWithAttribute(data, cb, null, !!async);
  1225. return (!!async) ? promise : v;
  1226. },
  1227. //根据组织职务,获取所有符合的组织
  1228. listUnitWithDuty: function(name, id, async){
  1229. getOrgActions();
  1230. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  1231. var v = null;
  1232. var cb = function(json){
  1233. v = json.data;
  1234. if (async && o2.typeOf(async)=="function") return async(v);
  1235. return v;
  1236. };
  1237. var promise = orgActions.listUnitWithDuty(data, cb, null, !!async);
  1238. return (!!async) ? promise : v;
  1239. },
  1240. //组织职务***********
  1241. //获取指定的组织职务的身份
  1242. getDuty: function(duty, id, async){
  1243. getOrgActions();
  1244. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  1245. var v = null;
  1246. var cb = function(json){
  1247. v = json.data;
  1248. if (async && o2.typeOf(async)=="function") return async(v);
  1249. return v;
  1250. };
  1251. var promise = orgActions.getDuty(data, cb, null, !!async);
  1252. return (!!async) ? promise : v;
  1253. },
  1254. //获取身份的所有职务名称
  1255. listDutyNameWithIdentity: function(name, async){
  1256. getOrgActions();
  1257. var data = {"identityList":getNameFlag(name)};
  1258. var v = null;
  1259. var cb = function(json){
  1260. v = json.data.nameList;
  1261. if (async && o2.typeOf(async)=="function") return async(v);
  1262. return v;
  1263. };
  1264. var promise = orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
  1265. return (!!async) ? promise : v;
  1266. },
  1267. //获取组织的所有职务名称
  1268. listDutyNameWithUnit: function(name, async){
  1269. getOrgActions();
  1270. var data = {"unitList":getNameFlag(name)};
  1271. var v = null;
  1272. var cb = function(json){
  1273. v = json.data.nameList;
  1274. if (async && o2.typeOf(async)=="function") return async(v);
  1275. return v;
  1276. };
  1277. var promise = orgActions.listDutyNameWithUnit(data, cb, null, !!async);
  1278. return (!!async) ? promise : v;
  1279. },
  1280. //获取组织的所有职务
  1281. listUnitAllDuty: function(name, async){
  1282. getOrgActions();
  1283. var data = {"unitList":getNameFlag(name)};
  1284. var v = null;
  1285. var cb = function(json){
  1286. v = json.data;
  1287. if (async && o2.typeOf(async)=="function") return async(v);
  1288. return v;
  1289. };
  1290. var promise = orgActions.listUnitAllDuty(data, cb, null, !!async);
  1291. return (!!async) ? promise : v;
  1292. },
  1293. //列出顶层组织
  1294. listTopUnit: function(async){
  1295. var action = MWF.Actions.get("x_organization_assemble_control");
  1296. var v = null;
  1297. var cb = function(json){
  1298. v = json.data;
  1299. if (async && o2.typeOf(async)=="function") return async(v);
  1300. return v;
  1301. };
  1302. var promise = action.listTopUnit(cb, null, !!async);
  1303. return (!!async) ? promise : v;
  1304. },
  1305. //组织属性**************
  1306. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  1307. appendUnitAttribute: function(unit, attr, values, success, failure, async){
  1308. getOrgActions();
  1309. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1310. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  1311. var cb = function(json){
  1312. if (success) return success(json);
  1313. }.ag().catch(function(xhr, text, error){
  1314. if (failure) return failure(xhr, text, error);
  1315. });
  1316. orgActions.appendPersonAttribute(data, cb, null, !!async);
  1317. // orgActions.appendUnitAttribute(data, function(json){
  1318. // if (json.data.value){
  1319. // if (success) success();
  1320. // }else{
  1321. // if (failure) failure(null, "", "append values failed");
  1322. // }
  1323. // }, function(xhr, text, error){
  1324. // if (failure) failure(xhr, text, error);
  1325. // }, false);
  1326. },
  1327. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  1328. setUnitAttribute: function(unit, attr, values, success, failure, async){
  1329. getOrgActions();
  1330. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1331. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  1332. var cb = function(json){
  1333. if (success) return success(json);
  1334. }.ag().catch(function(xhr, text, error){
  1335. if (failure) return failure(xhr, text, error);
  1336. });
  1337. orgActions.setUnitAttribute(data, cb, null, !!async);
  1338. // orgActions.setUnitAttribute(data, function(json){
  1339. // if (json.data.value){
  1340. // if (success) success();
  1341. // }else{
  1342. // if (failure) failure(null, "", "append values failed");
  1343. // }
  1344. // }, function(xhr, text, error){
  1345. // if (failure) failure(xhr, text, error);
  1346. // }, false);
  1347. },
  1348. //获取组织属性值
  1349. getUnitAttribute: function(unit, attr, async){
  1350. getOrgActions();
  1351. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1352. var data = {"name":attr,"unit":unitFlag};
  1353. var v = null;
  1354. var cb = function(json){
  1355. v = json.data.attributeList;
  1356. if (async && o2.typeOf(async)=="function") return async(v);
  1357. return v;
  1358. };
  1359. var promise = orgActions.getUnitAttribute(data, cb, null, !!async);
  1360. return (!!async) ? promise : v;
  1361. },
  1362. //列出组织所有属性的名称
  1363. listUnitAttributeName: function(name, async){
  1364. getOrgActions();
  1365. var data = {"unitList":getNameFlag(name)};
  1366. var v = null;
  1367. var cb = function(json){
  1368. v = json.data.nameList;
  1369. if (async && o2.typeOf(async)=="function") return async(v);
  1370. return v;
  1371. };
  1372. var promise = orgActions.listUnitAttributeName(data, cb, null, !!async);
  1373. return (!!async) ? promise : v;
  1374. },
  1375. //列出组织的所有属性
  1376. listUnitAllAttribute: function(name, async){
  1377. getOrgActions();
  1378. var data = {"unitList":getNameFlag(name)};
  1379. var v = null;
  1380. var cb = function(json){
  1381. v = json.data;
  1382. if (async && o2.typeOf(async)=="function") return async(v);
  1383. return v;
  1384. };
  1385. var promise = orgActions.listUnitAllAttribute(data, cb, null, !!async);
  1386. return (!!async) ? promise : v;
  1387. }
  1388. };
  1389. this.Action = (function(){
  1390. var actions = [];
  1391. return function(root, json){
  1392. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  1393. action.getActions = function(callback){
  1394. if (!this.actions) this.actions = {};
  1395. Object.merge(this.actions, json);
  1396. if (callback) callback();
  1397. };
  1398. this.invoke = function(option){
  1399. action.invoke(option)
  1400. }
  1401. }
  1402. })();
  1403. this.service = {
  1404. "jaxwsClient":{},
  1405. "jaxrsClient":{}
  1406. };
  1407. var lookupAction = null;
  1408. var getLookupAction = function(callback){
  1409. if (!lookupAction){
  1410. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  1411. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  1412. lookupAction.getActions = function(actionCallback){
  1413. this.actions = {
  1414. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  1415. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  1416. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  1417. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  1418. };
  1419. if (actionCallback) actionCallback();
  1420. };
  1421. if (callback) callback();
  1422. });
  1423. }else{
  1424. if (callback) callback();
  1425. }
  1426. };
  1427. this.view = {
  1428. "lookup": function(view, callback, async){
  1429. var filterList = {"filterList": (view.filter || null)};
  1430. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function(json){
  1431. var data = {
  1432. "grid": json.data.grid || json.data.groupGrid,
  1433. "groupGrid": json.data.groupGrid
  1434. };
  1435. if (callback) callback(data);
  1436. }, null, async);
  1437. },
  1438. "lookupV1": function(view, callback){
  1439. getLookupAction(function(){
  1440. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  1441. var data = {
  1442. "grid": json.data.grid,
  1443. "groupGrid": json.data.groupGrid
  1444. };
  1445. if (callback) callback(data);
  1446. }.bind(this)});
  1447. }.bind(this));
  1448. },
  1449. "select": function(view, callback, options){
  1450. if (view.view){
  1451. var viewJson = {
  1452. "application": view.application || _form.json.application,
  1453. "viewName": view.view || "",
  1454. "isTitle": (view.isTitle===false) ? "no" : "yes",
  1455. "select": (view.isMulti===false) ? "single" : "multi",
  1456. "filter": view.filter
  1457. };
  1458. if (!options) options = {};
  1459. options.width = view.width;
  1460. options.height = view.height;
  1461. options.title = view.caption;
  1462. var width = options.width || "700";
  1463. var height = options.height || "400";
  1464. if (layout.mobile){
  1465. var size = document.body.getSize();
  1466. width = size.x;
  1467. height = size.y;
  1468. options.style = "viewmobile";
  1469. }
  1470. width = width.toInt();
  1471. height = height.toInt();
  1472. var size = _form.app.content.getSize();
  1473. var x = (size.x-width)/2;
  1474. var y = (size.y-height)/2;
  1475. if (x<0) x = 0;
  1476. if (y<0) y = 0;
  1477. if (layout.mobile){
  1478. x = 20;
  1479. y = 0;
  1480. }
  1481. var _self = this;
  1482. MWF.require("MWF.xDesktop.Dialog", function(){
  1483. var dlg = new MWF.xDesktop.Dialog({
  1484. "title": options.title || "select view",
  1485. "style": options.style || "view",
  1486. "top": y,
  1487. "left": x-20,
  1488. "fromTop":y,
  1489. "fromLeft": x-20,
  1490. "width": width,
  1491. "height": height,
  1492. "html": "<div style='height: 100%;'></div>",
  1493. "maskNode": _form.app.content,
  1494. "container": _form.app.content,
  1495. "buttonList": [
  1496. {
  1497. "text": MWF.LP.process.button.ok,
  1498. "action": function(){
  1499. //if (callback) callback(_self.view.selectedItems);
  1500. if (callback) callback(_self.view.getData());
  1501. this.close();
  1502. }
  1503. },
  1504. {
  1505. "text": MWF.LP.process.button.cancel,
  1506. "action": function(){this.close();}
  1507. }
  1508. ]
  1509. });
  1510. dlg.show();
  1511. if (layout.mobile){
  1512. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1513. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1514. if (backAction) backAction.addEvent("click", function(e){
  1515. dlg.close();
  1516. }.bind(this));
  1517. if (okAction) okAction.addEvent("click", function(e){
  1518. //if (callback) callback(this.view.selectedItems);
  1519. if (callback) callback(this.view.getData());
  1520. dlg.close();
  1521. }.bind(this));
  1522. }
  1523. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  1524. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"}, _form.app, _form.Macro);
  1525. }.bind(this));
  1526. }.bind(this));
  1527. }
  1528. }
  1529. };
  1530. this.statement = {
  1531. "execute": function (statement, callback, async) {
  1532. var parameter = this.parseParameter(statement.parameter);
  1533. var filterList = this.parseFilter(statement.filter, parameter);
  1534. var obj = {
  1535. "filterList": filterList,
  1536. "parameter" : parameter
  1537. };
  1538. MWF.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  1539. statement.name, statement.mode || "data", statement.page || 1, statement.pageSize || 20, obj,
  1540. function (json) {
  1541. if (callback) callback(json);
  1542. }, null, async);
  1543. },
  1544. parseFilter : function( filter, parameter ){
  1545. if( typeOf(filter) !== "array" )return [];
  1546. var filterList = [];
  1547. ( filter || [] ).each( function (d) {
  1548. var parameterName = d.path.replace(/\./g, "_");
  1549. var value = d.value;
  1550. if( d.comparison === "like" || d.comparison === "notLike" ){
  1551. if( value.substr(0, 1) !== "%" )value = "%"+value;
  1552. if( value.substr(value.length-1,1) !== "%" )value = value+"%";
  1553. parameter[ parameterName ] = value; //"%"+value+"%";
  1554. }else{
  1555. if( d.formatType === "dateTimeValue" || d.formatType === "datetimeValue"){
  1556. value = "{ts '"+value+"'}"
  1557. }else if( d.formatType === "dateValue" ){
  1558. value = "{d '"+value+"'}"
  1559. }else if( d.formatType === "timeValue" ){
  1560. value = "{t '"+value+"'}"
  1561. }
  1562. parameter[ parameterName ] = value;
  1563. }
  1564. d.value = parameterName;
  1565. filterList.push( d );
  1566. }.bind(this));
  1567. return filterList;
  1568. },
  1569. parseParameter : function( obj ){
  1570. if( typeOf(obj) !== "object" )return {};
  1571. var parameter = {};
  1572. //传入的参数
  1573. for( var p in obj ){
  1574. var value = obj[p];
  1575. if( typeOf( value ) === "date" ){
  1576. value = "{ts '"+value.format("db")+"'}"
  1577. }
  1578. parameter[ p ] = value;
  1579. }
  1580. return parameter;
  1581. },
  1582. "select": function (statement, callback, options) {
  1583. if (statement.name) {
  1584. // var parameter = this.parseParameter(statement.parameter);
  1585. // var filterList = this.parseFilter(statement.filter, parameter);
  1586. var statementJson = {
  1587. "statementId": statement.name || "",
  1588. "isTitle": (statement.isTitle === false) ? "no" : "yes",
  1589. "select": (statement.isMulti === false) ? "single" : "multi",
  1590. "filter": statement.filter,
  1591. "parameter": statement.parameter
  1592. };
  1593. if (!options) options = {};
  1594. options.width = statement.width;
  1595. options.height = statement.height;
  1596. options.title = statement.caption;
  1597. var width = options.width || "700";
  1598. var height = options.height || "400";
  1599. if (layout.mobile) {
  1600. var size = document.body.getSize();
  1601. width = size.x;
  1602. height = size.y;
  1603. options.style = "viewmobile";
  1604. }
  1605. width = width.toInt();
  1606. height = height.toInt();
  1607. var size = _form.app.content.getSize();
  1608. var x = (size.x - width) / 2;
  1609. var y = (size.y - height) / 2;
  1610. if (x < 0) x = 0;
  1611. if (y < 0) y = 0;
  1612. if (layout.mobile) {
  1613. x = 20;
  1614. y = 0;
  1615. }
  1616. var _self = this;
  1617. MWF.require("MWF.xDesktop.Dialog", function () {
  1618. var dlg = new MWF.xDesktop.Dialog({
  1619. "title": options.title || "select statement view",
  1620. "style": options.style || "view",
  1621. "top": y,
  1622. "left": x - 20,
  1623. "fromTop": y,
  1624. "fromLeft": x - 20,
  1625. "width": width,
  1626. "height": height,
  1627. "html": "<div style='height: 100%;'></div>",
  1628. "maskNode": _form.app.content,
  1629. "container": _form.app.content,
  1630. "buttonList": [
  1631. {
  1632. "text": MWF.LP.process.button.ok,
  1633. "action": function () {
  1634. //if (callback) callback(_self.view.selectedItems);
  1635. if (callback) callback(_self.statement.getData());
  1636. this.close();
  1637. }
  1638. },
  1639. {
  1640. "text": MWF.LP.process.button.cancel,
  1641. "action": function () { this.close(); }
  1642. }
  1643. ]
  1644. });
  1645. dlg.show();
  1646. if (layout.mobile) {
  1647. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1648. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1649. if (backAction) backAction.addEvent("click", function (e) {
  1650. dlg.close();
  1651. }.bind(this));
  1652. if (okAction) okAction.addEvent("click", function (e) {
  1653. //if (callback) callback(this.view.selectedItems);
  1654. if (callback) callback(this.statement.getData());
  1655. dlg.close();
  1656. }.bind(this));
  1657. }
  1658. MWF.xDesktop.requireApp("query.Query", "Statement", function () {
  1659. this.statement = new MWF.xApplication.query.Query.Statement(dlg.content.getFirst(), statementJson, { "style": "select" }, _form.app, _form.Macro);
  1660. }.bind(this));
  1661. }.bind(this));
  1662. }
  1663. }
  1664. };
  1665. //include 引用脚本
  1666. //optionsOrName : {
  1667. // type : "", 默认为process, 可以为 portal process cms
  1668. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  1669. // name : "" // 脚本名称/别名/id
  1670. //}
  1671. //或者name: "" // 脚本名称/别名/id
  1672. // if( !window.includedScripts ){
  1673. // var includedScripts = window.includedScripts = [];
  1674. // }else{
  1675. // var includedScripts = window.includedScripts;
  1676. // }
  1677. /**
  1678. * this.include是一个方法,当您在流程、门户或者内容管理中创建了脚本配置,可以使用this.include()用来引用脚本配置。<br/>
  1679. * <b>(建议使用表单中的预加载脚本,需要判断加载的时候才使用本方法加载脚本,此时建议异步加载有助于表单加载速度。)</b><br/>
  1680. * @module include
  1681. * @o2ordernumber 140
  1682. * @param {(String|Object|String[]|Object[])} optionsOrName 可以是脚本标识字符串(数组)或者是对象(数组)。
  1683. * <pre><code class='language-js'>
  1684. * //如果需要引用本应用的脚本配置,将options设置为String或者String Array。
  1685. * this.include("initScript") //脚本配置的名称、别名或id
  1686. * this.include(["initScript","initScript2"]) //可以是字符串数组
  1687. *
  1688. * //如果需要引用其他应用的脚本配置,将options设置为Object或者Object Array;
  1689. * this.include({
  1690. * //type: 应用类型。可以为 portal process cms。
  1691. * //如果没有该选项或者值为空字符串,则表示应用脚本和被应用的脚本配置类型相同。
  1692. * //比如在门户的A应用脚本中引用门户B应用的脚本配置,则type可以省略。
  1693. * type : "portal",
  1694. * application : "首页", // 门户、流程、CMS的名称、别名、id。 默认为当前应用
  1695. * name : "initScript" // 脚本配置的名称、别名或id
  1696. * })
  1697. * this.include([ //也可以对象和字符串混合数组
  1698. * {
  1699. * type : "portal",
  1700. * application : "首页",
  1701. * name : "initScript"
  1702. * },
  1703. * "initScript2"
  1704. * ])
  1705. * </code></pre>
  1706. * @param {Function} [callback] 加载后执行的回调方法
  1707. * @param {Boolean} [async] 是否异步加载
  1708. * @o2syntax
  1709. * //您可以在表单、流程、视图和查询视图的各个嵌入脚本中,通过this.include()来引用本应用或其他应用的脚本配置,如下:
  1710. * this.include( optionsOrName, callback, async )
  1711. * @example
  1712. * <caption>
  1713. * <b>样例一:</b>在通用脚本中定义返回当前人员名称的方法,在各个门户应用都使用这个方法显示人员名称。<br/>
  1714. * 1、在门户应用中有一个commonApp的应用,在该应用中创建一个脚本,命名为initScript,并定义方法。
  1715. * <img src='img/module/include/define1.png' />
  1716. * </caption>
  1717. * //定义一个方法
  1718. * this.define("getUserName", function(){
  1719. * return ( layout.desktop.session.user || layout.user ).name
  1720. * }.bind(this))
  1721. * @example
  1722. * <caption>
  1723. * 2、在门户页面中添加事件'queryLoad',在事件中引入 initScript 脚本配置。
  1724. * <img src='img/module/include/define2.png' style='max-width:700px;'/>
  1725. * </caption>
  1726. * this.include({
  1727. * type : "portal",
  1728. * application : "commonApp",
  1729. * name : "initScript"
  1730. * })
  1731. *
  1732. * @example
  1733. * <caption>
  1734. * 3、在门户页面的'load'事件中使用方法。<br/>
  1735. * <img src='img/module/include/define3.png' style='max-width:700px;'/>
  1736. * </caption>
  1737. * var userNameNode = this.page.get("userName").node; //获取Dom对象
  1738. * var urerName = this.getUserName(); //使用initScript脚本中的方法
  1739. * userNameNode.set("text", urerName ); //为DOM对象设置值
  1740. */
  1741. var includedScripts = [];
  1742. var _includeSingle = function( optionsOrName , callback, async){
  1743. var options = optionsOrName;
  1744. if( typeOf( options ) == "string" ){
  1745. options = { name : options };
  1746. }
  1747. var name = options.name;
  1748. var type = ( options.type && options.application ) ? options.type : "process";
  1749. var application = options.application || _form.json.application;
  1750. var key = type +"-" + application + "-" + name;
  1751. if (includedScripts.indexOf( key )> -1){
  1752. if (callback) callback.apply(this);
  1753. return;
  1754. }
  1755. //if (includedScripts.indexOf( name )> -1){
  1756. // if (callback) callback.apply(this);
  1757. // return;
  1758. //}
  1759. var scriptAction;
  1760. switch ( type ){
  1761. case "portal" :
  1762. if( this.scriptActionPortal ){
  1763. scriptAction = this.scriptActionPortal;
  1764. }else{
  1765. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  1766. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  1767. }
  1768. break;
  1769. case "process" :
  1770. if( this.scriptActionProcess ){
  1771. scriptAction = this.scriptActionProcess;
  1772. }else{
  1773. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  1774. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  1775. }
  1776. break;
  1777. case "cms" :
  1778. if( this.scriptActionCMS ){
  1779. scriptAction = this.scriptActionCMS;
  1780. }else{
  1781. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1782. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  1783. }
  1784. break;
  1785. }
  1786. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  1787. if (json.data){
  1788. includedScripts.push( key );
  1789. //名称、别名、id
  1790. json.data.importedList.each( function ( flag ) {
  1791. if( type === "portal" ){
  1792. includedScripts.push( type + "-" + json.data.portal + "-" + flag );
  1793. if( json.data.portalName )includedScripts.push( type + "-" + json.data.portalName + "-" + flag );
  1794. if( json.data.portalAlias )includedScripts.push( type + "-" + json.data.portalAlias + "-" + flag );
  1795. }else if( type === "cms" ){
  1796. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  1797. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1798. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1799. }else if( type === "process" ){
  1800. includedScripts.push( type + "-" + json.data.application + "-" + flag );
  1801. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1802. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1803. }
  1804. });
  1805. includedScripts = includedScripts.concat(json.data.importedList);
  1806. MWF.Macro.exec(json.data.text, this);
  1807. if (callback) callback.apply(this);
  1808. }else{
  1809. if (callback) callback.apply(this);
  1810. }
  1811. }.bind(this), null, !!async);
  1812. }
  1813. this.include = function( optionsOrName , callback, async){
  1814. if (o2.typeOf(optionsOrName)=="array"){
  1815. if (!!async){
  1816. var count = optionsOrName.length;
  1817. var loaded = 0;
  1818. optionsOrName.each(function(option){
  1819. _includeSingle.apply(this, [option, function(){
  1820. loaded++;
  1821. if (loaded>=count) if (callback) callback.apply(this);;
  1822. }.bind(this), true]);
  1823. }.bind(this));
  1824. }else{
  1825. optionsOrName.each(function(option){
  1826. _includeSingle.apply(this, [option]);
  1827. }.bind(this));
  1828. if (callback) callback.apply(this);
  1829. }
  1830. }else{
  1831. _includeSingle.apply(this, [optionsOrName , callback, async])
  1832. }
  1833. };
  1834. /**
  1835. * this.define是一个方法,您可以在流程、门户或者内容管理中创建脚本配置,在脚本配置中您可以通过this.define()来定义自己的方法。<br/>
  1836. * 通过这种方式定义方法,在不同的应用使用相同的方法名称也不会造成冲突。
  1837. * @module define
  1838. * @o2ordernumber 150
  1839. * @param {(String)} name 定义的方法名称。
  1840. * @param {Function} fun 定义的方法
  1841. * @param {Boolean} [overwrite] 定义的方法是否能被覆盖重写。默认值为true。
  1842. * @o2syntax
  1843. * this.define(name, fun, overwrite)
  1844. * @example
  1845. * <caption>
  1846. * <b>样例:</b>在通用脚本中定义返回当前人员名称的方法,在各个门户应用都使用这个方法显示人员名称。<br/>
  1847. * 1、在门户应用中有一个commonApp的应用,在该应用中创建一个脚本,命名为initScript,并定义方法。
  1848. * <img src='img/module/include/define1.png' />
  1849. * </caption>
  1850. * //定义一个方法
  1851. * this.define("getUserName", function(){
  1852. * return ( layout.desktop.session.user || layout.user ).name
  1853. * }.bind(this))
  1854. * @example
  1855. * <caption>
  1856. * 2、在门户页面中添加事件'queryLoad',在事件中引入 initScript 脚本配置。
  1857. * <img src='img/module/include/define2.png' style='max-width:700px;'/>
  1858. * </caption>
  1859. * this.include({
  1860. * type : "portal",
  1861. * application : "commonApp",
  1862. * name : "initScript"
  1863. * })
  1864. *
  1865. * @example
  1866. * <caption>
  1867. * 3、在门户页面的'load'事件中使用方法。<br/>
  1868. * <img src='img/module/include/define3.png' style='max-width:700px;'/>
  1869. * </caption>
  1870. * var userNameNode = this.page.get("userName").node; //获取Dom对象
  1871. * var urerName = this.getUserName(); //使用initScript脚本中的方法
  1872. * userNameNode.set("text", urerName ); //为DOM对象设置值
  1873. */
  1874. this.define = function(name, fun, overwrite){
  1875. var over = true;
  1876. if (overwrite===false) over = false;
  1877. var o = {};
  1878. o[name] = {"value": fun, "configurable": over};
  1879. MWF.defineProperties(this, o);
  1880. }.bind(this);
  1881. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  1882. //可在调用前执行 var resolve = this.wait();
  1883. //在异步调用结束后 执行 resolve.cb();
  1884. //目前只有表单的queryload事件支持此方法。
  1885. /**
  1886. * this.wait是一个方法,可以用来处理异步调用时的页面加载。<br/>
  1887. * 该方法使用的具体场景:为了加快速度,需要一次性加载全部外部资源(如:数据字典、外部JS、内容管理文档等)后,再进行表单的加载。<br/>
  1888. * this.wait需和this.goon配合使用。<br/>
  1889. * <b>目前只有流程表单的queryload事件支持此方法。</b>
  1890. * @module wait
  1891. * @o2range {Process}
  1892. * @o2syntax
  1893. * var resolve = this.wait(); //让表单停止加载页面
  1894. *
  1895. * if (resolve && resolve.cb){
  1896. * resolve.cb(); //通过 resolve.cb() 方法继续执行表单加载
  1897. * }else{
  1898. * //如果没有发生异步,则resolve.cb方法不存在,
  1899. * //所以在回调中中使用this.goon();使表单继续加载
  1900. * this.goon();
  1901. * }
  1902. * @example
  1903. * <caption>需要在加载数据字典,内容管理文档数据,按照条件获取的脚本后,再进行加载表单。</caption>
  1904. *
  1905. * var resolve = this.wait(); //this.wait()让表单加载等待回调
  1906. * var scriptLoaded = false; //脚本是否加载完成标识,按条件判断的脚本才建议用this.include(),否则使用预加载脚本更快。
  1907. * var documentLoaded = false; //内容管理文档是否加载完成标识
  1908. * var dictLoaded = true; //数据字典是否加载完成标识
  1909. *
  1910. * //检查是否全部资源已加载,如果是继续加载表单
  1911. * var checkLoad = function(){
  1912. * if (scriptLoaded && documentLoaded && dictLoaded){ //各种资源以及加载完成
  1913. * if (resolve && resolve.cb){
  1914. * resolve.cb(); //通过 resolve.cb() 方法继续执行表单加载
  1915. * }else{
  1916. * //如果没有发生异步,则resolve.cb方法不存在,
  1917. * //所以在回调中中使用this.goon();使表单继续加载
  1918. * this.goon();
  1919. * }
  1920. * }
  1921. * }.bind(this);
  1922. *
  1923. * //判断内容管理文档加载
  1924. * if( this.data.documentId ){
  1925. * //异步载入内容管理文档
  1926. * o2.Actions.get("x_cms_assemble_control").getDocument(this.data.documentId, function (json) {
  1927. * this.form.documentJson = json; //将数据存在this.form上,以便其他地方使用
  1928. * documentLoaded = true; //标记内容管理加载完成
  1929. * checkLoad(); //检查全部资源是否完成加载
  1930. * }.bind(this), null, true); //true 为异步加载标志
  1931. * }else{
  1932. * documentLoaded = true; ////标记内容管理加载完成
  1933. * checkLoad(); //检查全部资源是否完成加载
  1934. * }
  1935. *
  1936. * //判断脚本加载
  1937. * if( this.data.scriptName ){ //假设scriptName为判断条件
  1938. * //加载脚本
  1939. * this.include( this.data.scriptName, function(){ //第二个参数为异步加载后的回调
  1940. * scriptLoaded = true; //标记脚本加载完成
  1941. * checkLoad(); //检查全部资源是否完成加载
  1942. * }, true ); //第三个参数表示异步
  1943. * }else{
  1944. * scriptLoaded = true; ////标记脚本加载完成
  1945. * checkLoad(); //检查全部资源是否完成加载
  1946. * }
  1947. *
  1948. * //加载数据字典bulletinDictionary的category数据
  1949. * var dict = new Dict("bulletinDictionary");
  1950. * dict.get("category", function(data){ //成功的回调
  1951. * this.form.bulletinCategory = data; //将数据存在this.form上,以便其他地方使用
  1952. * dictLoaded = true; //标记数据字典加载完成
  1953. * checkLoad(); //检查全部资源是否完成加载
  1954. * }.bind(this), function(xhr){ //错误的回调
  1955. * dictLoaded = true; ////标记数据字典加载完成
  1956. * checkLoad(); //检查全部资源是否完成加载
  1957. * }, true //异步执行
  1958. * )
  1959. */
  1960. this.wait = function(){
  1961. var _self = this;
  1962. resolve = {"cb": _self.goon.bind(_self)};
  1963. var setResolve = function(callback){
  1964. resolve.cb = callback;
  1965. }.bind(this);
  1966. this.target.event_resolve = setResolve;
  1967. return resolve;
  1968. }
  1969. //和this.wait配合使用,
  1970. //如果没有异步,则resolve.cb方法不存在,
  1971. //所以在回调中中使用this.goon();使表单继续加载
  1972. this.goon = function(){
  1973. this.target.event_resolve = null;
  1974. }
  1975. //仅前台对象-----------------------------------------
  1976. //form
  1977. /**
  1978. * form对象可在流程表单或内容管理表单中可用。(仅前端脚本可用)。
  1979. * @module form
  1980. * @o2range {Process|CMS}
  1981. * @o2ordernumber 40
  1982. * @o2syntax
  1983. * //您可以在流程表单和内容管理的前端脚本中,通过this来获取form对象,如下:
  1984. * var form = this.form;
  1985. */
  1986. this.page = this.form = {
  1987. /**
  1988. * 获取当前表单的基本信息。
  1989. * @method getInfor
  1990. * @static
  1991. * @return {Object} 表单的基本信息.
  1992. * <pre><code class='language-js'>{
  1993. * "id": "db3b2766-93a1-4058-b522-0edb922bd84f", //表单ID
  1994. * "name": "报销申请表单", //表单名称
  1995. * "alias": "报销申请表单", //表单别名
  1996. * "description": "", //表单描述
  1997. * "application": "1dc23336-6be6-402b-bed6-36e707a1dd17", //应用ID
  1998. * "lastUpdatePerson": "XX@huqi@P", //最后修改人
  1999. * "lastUpdateTime": "2018-09-30 22:46:30", //最后修改时间
  2000. * "icon": "...", //表单图标
  2001. * }</code></pre>
  2002. * @o2syntax
  2003. * var form = this.form.getInfor();
  2004. */
  2005. "getInfor": function(){return ev.formInfor;},
  2006. "infor": ev.formInfor,
  2007. /**
  2008. * 获取打开当前文档的component对象。平台中每一个窗口应用,就是一个component对象。此处获取到的对象为x_component_process_Work。
  2009. * @method getApp
  2010. * @static
  2011. * @return {x_component_process_Work}打开当前文档的component对象.
  2012. * @o2syntax
  2013. * var app = this.form.getApp();
  2014. * @example
  2015. * var app = this.form.getApp();
  2016. //所有component对象都有以下方法。
  2017. app.openInNewWindow(); //在新窗口中打开当前应用
  2018. app.setCurrent(); //将当前应用设置为激活状态
  2019. app.minSize(); //应用窗口最小化
  2020. app.maxSize(); //应用窗口最大化
  2021. app.restoreSize(); //应用窗口还原
  2022. app.refresh(); //刷新应用
  2023. app.close(); //关闭应用
  2024. app.setTitle(str); //设置应用标题
  2025. app.dialog(option); //弹出一个对话框(详见MWF.widget.Dialog)
  2026. //显示一个通知消息
  2027. app.notice(content, type, target, where, offset);
  2028. //显示一个确认框
  2029. app.confirm(type, e, title, text, width, height, ok, cancel);
  2030. //弹出一个信息框
  2031. app.alert(type, e, title, text, width, height);
  2032. //为应用绑定一个事件
  2033. app.addEvent(type, fun);
  2034. */
  2035. "getApp": function(){return _form.app;},
  2036. "app": _form.app,
  2037. /**
  2038. * 获取Form对应的DOM对象。
  2039. * @method node
  2040. * @static
  2041. * @return {HTMLDivElement} 当前form对应的div对象.
  2042. * @o2syntax
  2043. * var node = this.form.node();
  2044. */
  2045. "node": function(){return _form.node;},
  2046. /**
  2047. * 获取表单是否可编辑。只读。
  2048. * @member readonly
  2049. * @static
  2050. * @return {Boolean} 是否只读.
  2051. * @o2syntax
  2052. * var readonly = this.form.readonly;
  2053. */
  2054. "readonly": _form.options.readonly,
  2055. /**
  2056. * 获取表单元素对象。<br/>
  2057. * <table>
  2058. * <tr><td>Actionbar(操作条)</td><td>Address(地址输入框)</td><td>Attachment(附件框)</td><td>Button(按钮)</td></tr>
  2059. * <tr><td>Calendar(日期输入框)</td><td>Checkbox(多选按钮)</td><td>Combox(组合框)</td><td>Datagrid(数据网格)</td></tr>
  2060. * <tr><td>Div(容器)</td><td>Htmleditor(富文本编辑框)</td><td>Html(内置html)</td><td>Iframe(嵌入Iframe)</td></tr>
  2061. * <tr><td>Image(图片)</td><td>Label(文本)</td><td>Log(流程意见)</td><td>Monitor(流程监控)</td></tr>
  2062. * <tr><td>Number(数字输入框)</td><td>Office(office控件)</td><td>Opinion(意见框)</td><td>Org(人员组织选择)</td></tr>
  2063. * <tr><td>Radio(单选按钮)</td><td>Select(选择框)</td><td>Sidebar(侧边操作条)</td><td>Stat(统计组件)</td></tr>
  2064. * <tr><td>Subform(子表单)</td><td>Tab(分页)</td><td>Table(表格)</td><td>Textarea(多行输入)</td></tr>
  2065. * <tr><td>Textfield(文本输入框)</td><td>Tree(树状控件)</td><td>View(视图组件)</td><td>ViewSelector(视图选择组件)</td></tr>
  2066. * <tr><td>Documenteditor(公文编辑器)</td><td>ImageClipper(图片编辑器)</td><td></td><td></td></tr>
  2067. * </table>
  2068. * @method get
  2069. * @static
  2070. * @return {FormComponent} 请查看本文档的Classes导航下的FormComponents。
  2071. * @param {String} name 字段标识
  2072. * @o2syntax
  2073. * var field = this.form.get(name);
  2074. * @example
  2075. * var field = this.form.get("subject");
  2076. */
  2077. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  2078. /**
  2079. * 获取表单中可输入的字段元素对象。<br/>
  2080. * <table>
  2081. * <tr><td>Address(地址输入框)</td><td>Attachment(附件框)</td><td>Calendar(日期输入框)</td><td>Checkbox(多选按钮)</td></tr>
  2082. * <tr><td>Combox(组合框)</td><td>Datagrid(数据网格)</td><td>Htmleditor(富文本编辑框)</td><td>Number(数字输入框)</td></tr>
  2083. * <tr><td>Org(人员组织选择)</td><td>Radio(单选按钮)</td><td>Select(选择框)</td><td>Textarea(多行输入)</td></tr>
  2084. * <tr><td>Textfield(文本输入框)</td><td></td><td></td><td></td></tr>
  2085. * </table>
  2086. * @method getField
  2087. * @static
  2088. * @return {FormComponent} 请查看本文档的Classes导航下的FormComponents。
  2089. * @param {String} name 字段标识
  2090. * @o2syntax
  2091. * var field = this.form.getField(name);
  2092. * @example
  2093. * var field = this.form.getField("subject");
  2094. */
  2095. "getField": function(name){return _forms[name];},
  2096. "getAction": function(){return _form.workAction},
  2097. "getDesktop": function(){return _form.app.desktop},
  2098. /**获取业务数据
  2099. * @method getData
  2100. * @static
  2101. * @see module:data
  2102. * @o2syntax
  2103. * var data = this.form.getData();
  2104. * @return {Object} 返回表单绑定的业务数据。
  2105. */
  2106. "getData": function(){return new MWF.xScript.JSONData(_form.getData());},
  2107. /**保存当前表单所绑定的业务数据。<br/>
  2108. * this.form.save()会触发 beforeSave和afterSave事件,因此在beforeSave和afterSave中不允许使用本方法。
  2109. * @method save
  2110. * @static
  2111. * @param {Function} [callback] - 保存后的回调
  2112. * @param {Boolean} [silent] - 是否静默,否提示保存成功,默认为false
  2113. * @o2syntax
  2114. * this.form.save(callback, silent);
  2115. * @example
  2116. * this.form.save(function(){
  2117. * //do someting
  2118. * }, true);
  2119. */
  2120. "save": function(callback, silent){_form.saveWork(callback, silent); },
  2121. /**
  2122. *关闭当前表单
  2123. * @method close
  2124. * @static
  2125. * @example
  2126. * this.form.close();
  2127. */
  2128. "close": function(){_form.closeWork();},
  2129. /**本校验不包括校验意见,校验路由;通常用在弹出提交界面时候的校验
  2130. * @summary 根据表单中所有组件的校验设置和“流转校验”脚本进行校验。
  2131. * @method verify
  2132. * @static
  2133. * @o2syntax
  2134. * this.form.verify()
  2135. * @example
  2136. * if( !this.form.verify() ){
  2137. * return false;
  2138. * }
  2139. * @return {Boolean} 是否通过校验
  2140. */
  2141. "verify": function(){
  2142. return !(!_form.formCustomValidation("", "") || !_form.formValidation("", ""));
  2143. },
  2144. /**对当前表单打开的流程实例进行流转。<b>(仅流程表单中可用)</b><br/>
  2145. * 可以通过this.workContext.getControl().allowProcessing来判断当前用户是否有权限进行流转。<br/>
  2146. * this.form.process()会触发 beforeSave、afterSave、beforeProcess、afterProcess事件,因此在上述事件中不允许使用本方法。
  2147. * @method process
  2148. * @static
  2149. * @param {Object} [option] - 流程的相关数据,如果不带此参数,则弹出路由选择和意见填写框<br/>
  2150. * 格式如下:
  2151. <pre><code class="language-js">
  2152. {
  2153. "routeName": "", //流转到下一步要选择的路由名称
  2154. "opinion": "", //流转意见
  2155. "callback": function(){} //流转完成后的回调方法
  2156. }
  2157. </code></pre>
  2158. * @example
  2159. //不带参数,弹出路由选择和意见填写框
  2160. this.form.process();
  2161. * @example
  2162. //带参数,流转
  2163. this.form.process({
  2164. "routeName": "送审批",
  2165. "opinion": "同意",
  2166. "callback": function(json){
  2167. this.form.notice("process success", "success");
  2168. }.bind(this)
  2169. });
  2170. */
  2171. "process": function(option){
  2172. var op = _form.getOpinion();
  2173. var mds = op.medias;
  2174. if (option){
  2175. _form.submitWork(option.routeName, option.opinion, mds, option.callback,
  2176. option.processor, null, option.appendTaskIdentityList, option.processorOrgList, option.callbackBeforeSave );
  2177. }else{
  2178. _form.processWork();
  2179. }
  2180. },
  2181. /**对当前文档的待办重新设定处理人。<b>(仅流程表单中可用)</b><br/>
  2182. * 可以通过this.workContext.getControl().allowReset来判断当前用户是否有权限重置处理人。<br/>
  2183. * this.form.reset()会触发 beforeReset、afterReset事件,因此在上述事件中不允许使用本方法。
  2184. * @method reset
  2185. * @static
  2186. * @param {Object} [option] - 进行重置处理人的相关参数,如果不带此参数,弹出重置处理人对话框<br/>
  2187. * 格式如下:
  2188. <pre><code class="language-js">
  2189. {
  2190. "names": "", //{Array|String} 要重置给哪些身份
  2191. "opinion": "", //流转意见
  2192. "success ": function(){}, //重置成功后的回调方法
  2193. "failure ": function(){} //重置失败后的回调方法
  2194. }
  2195. </code></pre>
  2196. * @example
  2197. //不带参数,弹出重置处理人对话框
  2198. this.form.reset();
  2199. * @example
  2200. //带参数,直接调用后台服务重置
  2201. this.form.reset({
  2202. "names": ["张三(综合部)"],
  2203. "opinion": "授权处理",
  2204. "success": function(json){
  2205. this.form.notice("reset success", "success");
  2206. }.bind(this),
  2207. "failure": function(xhr, text, error){
  2208. //xhr--HttpRequest请求对象
  2209. //text--HttpResponse内容文本
  2210. //error--错误信息
  2211. this.form.notice("reset failure:"+error, "error");
  2212. }.bind(this)
  2213. });
  2214. */
  2215. "reset": function(option){
  2216. if (!option){
  2217. if (_form.businessData.control["allowReset"]) _form.resetWork();
  2218. }else{
  2219. _form.resetWorkToPeson(option.names, option.opinion, option.keep, option.success, option.failure);
  2220. }
  2221. },
  2222. /**撤回文档操作,上一个处理人收回已经流转下去的文件。<b>(仅流程表单中可用)</b><br/>
  2223. * 这个操作只允许上一个处理人在流转文件之后,下一个处理人未处理的时候执行。<br/>
  2224. * 可以通过this.workContext.getControl().allowRetract来判断当前用户是否有权限撤回。<br/>
  2225. * this.form.retract()会触发 beforeRetract、afterRetract事件,因此在上述事件中不允许使用本方法。
  2226. * @method retract
  2227. * @static
  2228. * @param {Object} [option] - 进行撤回的相关参数,如果不提供option参数,则弹出撤回对话框。<br/>
  2229. * 格式如下:
  2230. <pre><code class="language-js">
  2231. {
  2232. "success ": function(){}, //撤回成功后的回调方法
  2233. "failure ": function(){} //撤回失败后的回调方法
  2234. }
  2235. </code></pre>
  2236. * @example
  2237. //不带参数,则弹出撤回对话框
  2238. this.form.retract();
  2239. * @example
  2240. //带参数,直接调用后台服务撤回
  2241. this.form.retract({
  2242. "success": function(json){
  2243. this.form.notice("retract success", "success");
  2244. }.bind(this),
  2245. "failure": function(xhr, text, error){
  2246. //xhr--HttpRequest请求对象
  2247. //text--HttpResponse内容文本
  2248. //error--错误信息
  2249. this.form.notice("retract failure: "+error, "error");
  2250. }.bind(this)
  2251. });
  2252. */
  2253. "retract": function(option){
  2254. if (!option){
  2255. if (_form.businessData.control["allowRetract"]) _form.retractWork();
  2256. }else{
  2257. _form.doRetractWork(option.success, option.failure);
  2258. }
  2259. },
  2260. /**在已拆分的工作上添加分支。<b>(仅流程表单中可用)</b><br/>
  2261. * 可以通过this.workContext.getControl().allowAddSplit来判断当前用户是否有权限。<br/>
  2262. * @method addSplit
  2263. * @static
  2264. * @param {Object} [option] - 添加分支的相关参数,如果不提供option参数,则弹出添加分支对话框。<br/>
  2265. * 格式如下:
  2266. <pre><code class="language-js">
  2267. {
  2268. "value" : [], //splitValueList 添加的拆分值,拆分值取决于流程拆分节点的设置
  2269. "trimExist" : true, //排除已经存在的拆分值.
  2270. "success ": function(){}, //执行成功后的回调方法
  2271. "failure ": function(){} //执行失败后的回调方法
  2272. }
  2273. </code></pre>
  2274. * @example
  2275. //不带参数,则弹出添加分支对话框
  2276. this.form.addSplit();
  2277. * @example
  2278. //带参数,直接添加分支
  2279. this.form.addSplit({
  2280. "value" : ["开发部@kfb@U"],
  2281. "trimExist" : true,
  2282. "success": function(json){
  2283. this.form.notice("addSplit success", "success");
  2284. }.bind(this),
  2285. "failure": function(xhr, text, error){
  2286. //xhr--HttpRequest请求对象
  2287. //text--HttpResponse内容文本
  2288. //error--错误信息
  2289. this.form.notice("addSplit failure: "+error, "error");
  2290. }.bind(this)
  2291. });
  2292. */
  2293. "addSplit": function(option){
  2294. if (!option){
  2295. if (_form.businessData.control["allowAddSplit"]) _form.addSplit();
  2296. }else{
  2297. _form.addSplitWork(option.value, option.trimExist, option.success, option.failure);
  2298. }
  2299. },
  2300. "rollback": function(option){
  2301. if (!option){
  2302. if (_form.businessData.control["allowRollback"]) _form.rollback();
  2303. }else{
  2304. _form.doRollbackActionInvoke(option.log, option.flow, option.success, option.failure);
  2305. }
  2306. },
  2307. /**删除当前工作文档。<b>(仅流程表单中可用)</b><br/>
  2308. * 可以通过this.workContext.getControl().allowDeleteWork来判断当前用户是否有权限删除文档。<br/>
  2309. * @method deleteWork
  2310. * @static
  2311. * @param {Object} [option] - 删除相关参数,如果不提供option参数,则弹出删除对话框。<br/>
  2312. * 格式如下:
  2313. <pre><code class="language-js">
  2314. {
  2315. "success ": function(){}, //执行成功后的回调方法
  2316. "failure ": function(){} //执行失败后的回调方法
  2317. }
  2318. </code></pre>
  2319. * @example
  2320. //不带参数,则弹出删除提示对话框
  2321. this.form.deleteWork();
  2322. * @example
  2323. //带参数,直接调用服务删除
  2324. this.form.deleteWork({
  2325. "success": function(json){
  2326. this.form.notice("deleteWork success", "success");
  2327. }.bind(this),
  2328. "failure": function(xhr, text, error){
  2329. //xhr--HttpRequest请求对象
  2330. //text--HttpResponse内容文本
  2331. //error--错误信息
  2332. this.form.notice("deleteWork failure: "+error, "error");
  2333. }.bind(this)
  2334. });
  2335. */
  2336. "deleteWork": function(option){
  2337. if (!option){
  2338. if (_form.businessData.control["allowDelete"]) _form.deleteWork();
  2339. }else{
  2340. _form.doDeleteWork(option.success, option.failure);
  2341. }
  2342. },
  2343. /**弹出一个确认框,带确认和关闭按钮
  2344. * @method confirm
  2345. * @static
  2346. * @param {String} type - 要显示的信息类型。可选值:success 成功,info :信息,error :错误, wran : 警告
  2347. * @param {String} title - 确认框标题栏显示文本。
  2348. * @param {String} text - 确认框的内容显示文本。
  2349. * @param {Number} width - 确认框的宽度。
  2350. * @param {String} height - 确认框的高度。
  2351. * @param {Function} ok - 点击“确定”按钮后的回调函数。
  2352. * @param {Function} cancel - 点击“取消”按钮后的回调函数。
  2353. * @example
  2354. this.form.confirm("wran", "删除确认", "您确定要删除吗?", 300, 100,function(){
  2355. //执行删除代码
  2356. this.close();
  2357. }, function(){
  2358. this.close();
  2359. });
  2360. */
  2361. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  2362. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  2363. var p = MWF.getCenter({"x": width, "y": height});
  2364. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  2365. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  2366. }else{
  2367. e = (arguments.length>1) ? arguments[1] : null;
  2368. title = (arguments.length>2) ? arguments[2] : null;
  2369. text = (arguments.length>3) ? arguments[3] : null;
  2370. width = (arguments.length>4) ? arguments[4] : null;
  2371. height = (arguments.length>5) ? arguments[5] : null;
  2372. ok = (arguments.length>6) ? arguments[6] : null;
  2373. cancel = (arguments.length>7) ? arguments[7] : null;
  2374. callback = (arguments.length>8) ? arguments[8] : null;
  2375. mask = (arguments.length>9) ? arguments[9] : null;
  2376. style = (arguments.length>10) ? arguments[10] : null;
  2377. // var p = MWF.getCenter({"x": width, "y": height});
  2378. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  2379. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  2380. }
  2381. },
  2382. /**弹出一个带关闭按钮的信息框
  2383. * @method alert
  2384. * @static
  2385. * @param {String} type - 要显示的信息类型。可选值:success 成功,info :信息,error :错误, wran : 警告
  2386. * @param {String} title - 信息框标题栏显示文本。
  2387. * @param {String} text - 信息框的内容显示文本。
  2388. * @param {Number} width - 信息框宽度。
  2389. * @param {String} height - 信息框的高度。
  2390. * @example
  2391. this.form.alert("wran", "必填提醒", "请填写标题!", 300, 100);
  2392. */
  2393. "alert": function(type, title, text, width, height){
  2394. _form.alert(type, title, text, width, height);
  2395. },
  2396. /**弹出一个提示框
  2397. * @method notice
  2398. * @static
  2399. * @param {String} content - 要显示的信息文本
  2400. * @param {String} [type] - 要显示的信息类型。可选值:success 成功,info :信息,error :错误, wran : 警告
  2401. * @param {Element} [target] - 信息框显示位置的参考DOM对象。
  2402. * @param {Object} [where] - 信息框显示相对于target的x轴和y轴位置。<br/>
  2403. * 如: {"x": "center", "y": "center"}<br/>
  2404. x : <br/>
  2405.  水平位置,可用“left”、“right”和“center”;可以用数组定义外部(outside)位置和内部(inside)位置,如:['right', 'inside']<br/>
  2406. y :<br/>
  2407.  垂直位置,可用“top”、“bottom”和“center”;可以用数组定义外部(outside)位置和内部(inside)位置,如:['top', 'outside']。
  2408. * @param {Object} [offset] - 相对位置的偏移量,允许负值。如:{"x": 10, "y": -10}
  2409. * @param {Object} [option] - 其他选项。如: { delayClose: 5000 } 在5秒后关闭
  2410. * @example
  2411. this.form.notice("this is my information", "info");
  2412. */
  2413. "notice": function(content, type, target, where, offset, option){
  2414. _form.notice(content, type, target, where, offset, option);
  2415. },
  2416. /**给表单添加事件。
  2417. * @method addEvent
  2418. * @static
  2419. * @param {String} type - 事件名称,参考本API Classer->FormComponents->Form的事件
  2420. * @param {Function} event - 事件方法。
  2421. * @example
  2422. this.form.addEvent("load", function(){
  2423. this.form.notice("表单载入完成", "success");
  2424. }.bind(this));
  2425. */
  2426. "addEvent": function(type, event ){_form.addEvent(type, event );},
  2427. /**用一个新的浏览器窗口来打开当前文档,用于打印。<b>(仅流程表单中可用)</b><br/>
  2428. * 如不指定表单,则使用表单设计中指定的打印表单。<br/>
  2429. * @method print
  2430. * @static
  2431. * @param {String} [application] - 指定表单所在的流程应用ID或名称。省略此参数表示当前应用。
  2432. * @param {String} [form] - 指定表单ID或名称。
  2433. * @example
  2434. //在新窗口中使用当前表单中配置的打印表单打开当前文档
  2435. this.form.print();
  2436. * @example
  2437. //在新窗口中使用“订单打印表单”表单打开当前文档
  2438. this.form.print("订单打印表单");
  2439. * @example
  2440. //在新窗口中使用“订单管理”应用中的“订单打印表单”表单打开当前文档
  2441. this.form.print("订单管理", "订单打印表单");
  2442. */
  2443. "print": function(application, form){
  2444. if (arguments.length){
  2445. var app = (arguments.length>1) ? arguments[0] : null;
  2446. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  2447. _form.printWork(app, formName);
  2448. }else{
  2449. _form.printWork();
  2450. }
  2451. },
  2452. /**同print方法。<b>(仅流程表单中可用)</b><br/>
  2453. * @method openWindow
  2454. * @static
  2455. * @see this.form.print()
  2456. * @param {String} [application] - 指定表单所在的流程应用ID或名称。省略此参数表示当前应用。
  2457. * @param {String} [form] - 指定表单ID或名称。
  2458. * @example
  2459. this.form.openWindow();
  2460. */
  2461. "openWindow": function(application, form){
  2462. if (arguments.length){
  2463. var app = (arguments.length>1) ? arguments[0] : null;
  2464. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  2465. _form.openWindow(formName, app);
  2466. }else{
  2467. _form.openWindow();
  2468. }
  2469. },
  2470. /** 打开一个在流转或已完成的流程实例。<br/>
  2471. * @method openWork
  2472. * @static
  2473. * @param {String} [workId] - 在流转的流程实例ID。workId和workCompletedId两个参数必须提供其中一个
  2474. * @param {String} [workCompletedId] - 已完成的流程实例ID。
  2475. * @param {String} [title] - 手机端打开时的窗口标题。
  2476. * @example
  2477. this.form.openWork(id, "", "work title");
  2478. */
  2479. "openWork": function(workId, workCompletedId, title, options){
  2480. var op = options || {};
  2481. op.workId = workId;
  2482. op.workCompletedId = workCompletedId;
  2483. op.docTitle = title;
  2484. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  2485. return layout.desktop.openApplication(this.event, "process.Work", op);
  2486. },
  2487. /** 使用流程的jobId打开工作。<br/>
  2488. * @method openJob
  2489. * @static
  2490. * @param {String} id - 流程的jobId,如果流程拆分后,有多个流程实例(workId会有多个),但jobId是唯一的。
  2491. * @param {Boolean} [choice] - 如果有多个流程实例,是否弹出界面选择。如果传入false,则直接打开第一个工作。
  2492. * @example
  2493. this.form.openJob(jobId, true);
  2494. */
  2495. "openJob": function(id, choice, options){
  2496. var workData = null;
  2497. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  2498. if (json.data) workData = json.data;
  2499. }.bind(this), null, false);
  2500. if (workData){
  2501. var len = workData.workList.length + workData.workCompletedList.length;
  2502. if (len){
  2503. if (len>1 && choice){
  2504. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  2505. workData.workList.each(function(work){
  2506. var workNode = new Element("div", {
  2507. "styles": {
  2508. "background": "#ffffff",
  2509. "border-radius": "10px",
  2510. "clear": "both",
  2511. "margin-bottom": "10px",
  2512. "height": "40px",
  2513. "padding": "10px 10px"
  2514. }
  2515. }).inject(node);
  2516. var html = "<div style='height: 40px; width: 40px; float: left; background: url(../x_component_process_Xform/$Form/default/icon/work.png) no-repeat center center'></div>" +
  2517. "<div style='height: 40px; width: 40px; float: right'><div class='MWFAction' style='height: 20px; width: 40px; margin-top: 10px; border: 1px solid #999999; border-radius: 5px;text-align: center; cursor: pointer'>"+o2.LP.widget.open+"</div></div>"+
  2518. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  2519. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  2520. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  2521. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  2522. workNode.set("html", html);
  2523. var action = workNode.getElement(".MWFAction");
  2524. action.store("work", work);
  2525. action.addEvent("click", function(e){
  2526. var work = e.target.retrieve("work");
  2527. if (work) this.openWork(work.id, null, work.title, options);
  2528. dlg.close();
  2529. }.bind(this));
  2530. }.bind(this));
  2531. workData.workCompletedList.each(function(work){
  2532. var workNode = new Element("div", {
  2533. "styles": {
  2534. "background": "#ffffff",
  2535. "border-radius": "10px",
  2536. "clear": "both",
  2537. "margin-bottom": "10px",
  2538. "height": "40px",
  2539. "padding": "10px 10px"
  2540. }
  2541. }).inject(node);
  2542. var html = "<div style='height: 40px; width: 40px; float: left; background: url(../x_component_process_Xform/$Form/default/icon/work.png) no-repeat center center'></div>" +
  2543. "<div style='height: 40px; width: 40px; float: right'><div class='MWFAction' style='height: 20px; width: 40px; margin-top: 10px; border: 1px solid #999999; border-radius: 5px;text-align: center; cursor: pointer'>"+o2.LP.widget.open+"</div></div>"+
  2544. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  2545. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  2546. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  2547. workNode.set("html", html);
  2548. var action = workNode.getElement(".MWFAction");
  2549. action.store("work", work);
  2550. action.addEvent("click", function(e){
  2551. var work = e.target.retrieve("work");
  2552. if (work) this.openWork(null, work.id, work.title, options);
  2553. dlg.close();
  2554. }.bind(this));
  2555. }.bind(this));
  2556. var height = node.getSize().y+20;
  2557. if (height>600) height = 600;
  2558. var dlg = o2.DL.open({
  2559. "title": o2.LP.widget.choiceWork,
  2560. "style" : "user",
  2561. "isResize": false,
  2562. "content": node,
  2563. "buttonList": [
  2564. {
  2565. "type" : "cancel",
  2566. "text": o2.LP.widget.close,
  2567. "action": function(){dlg.close();}
  2568. }
  2569. ]
  2570. });
  2571. }else{
  2572. if (workData.workList.length){
  2573. var work = workData.workList[0];
  2574. return this.openWork(work.id, null, work.title, options);
  2575. }else{
  2576. var work = workData.workCompletedList[0];
  2577. return this.openWork(null, work.id, work.title, options);
  2578. }
  2579. }
  2580. }
  2581. }
  2582. // var op = options || {};
  2583. // op.workId = id;
  2584. // op.workCompletedId = completedId;
  2585. // op.docTitle = title;
  2586. // op.appId = "process.Work"+(op.workId || op.workCompletedId);
  2587. // layout.desktop.openApplication(this.event, "process.Work", op);
  2588. },
  2589. /** 打开一个内容管理文档。<br/>
  2590. * @method openDocument
  2591. * @static
  2592. * @param {String} id - 内容管理文档实例的ID。
  2593. * @param {Boolean} [title] - 手机APP端打开时的窗口标题。
  2594. * @param {Object} [options] - 其他参数,内容如下<br>
  2595. * <pre><code class="language-js">{
  2596. * "readonly": true, //是否以只读方式打开,默认为true
  2597. * "saveOnClose" : true, //关闭的时候是否自动保存
  2598. * "onPostPublish" : function( documentData ){ //发布前执行方法,但数据已经准备好
  2599. * //documentData 为文档数据
  2600. * },
  2601. * "onAfterPublish" : function( form, documentData ){ //发布后执行的方法
  2602. * //form为内容管理Form对象,documentData 为文档数据
  2603. * },
  2604. * "onPostDelete" : function(){ //删除文档后执行的方法
  2605. * }
  2606. * }</code></pre>
  2607. * @example
  2608. this.form.openDocument(id, "document title");
  2609. */
  2610. "openDocument": function(id, title, options){
  2611. var op = options || {};
  2612. op.documentId = id;
  2613. op.docTitle = title;
  2614. layout.desktop.openApplication(this.event, "cms.Document", op);
  2615. },
  2616. /**打开一个门户页面。<br/>
  2617. * @method openPortal
  2618. * @static
  2619. * @param {String} portal - 要打开的门户应用名称、别名或ID。
  2620. * @param {String} [page] - 要打开的页面名称、别名或ID。如果忽略,则打开门户的默认首页
  2621. * @param {Object} [par] - 打开页面可以传入参数。<br>在被打开的页面中,可以通过脚本this.page.parameters访问到此参数。
  2622. * @example
  2623. this.form.openPortal(id, "", {"type": "my type"});
  2624. */
  2625. "openPortal": function (portal, page, par) {
  2626. var action = MWF.Actions.get("x_portal_assemble_surface");
  2627. action.getApplication(portal, function (json) {
  2628. if (json.data) {
  2629. if (page) {
  2630. action.getPageByName(page, json.data.id, function (pageJson) {
  2631. var pageId = (pageJson.data) ? pageJson.data.id : "";
  2632. layout.desktop.openApplication(null, "portal.Portal", {
  2633. "portalId": json.data.id,
  2634. "pageId": pageId,
  2635. "parameters": par,
  2636. "appId": (par && par.appId) || ("portal.Portal" + json.data.id + pageId)
  2637. })
  2638. });
  2639. } else {
  2640. layout.desktop.openApplication(null, "portal.Portal", {
  2641. "portalId": json.data.id,
  2642. "parameters": par,
  2643. "appId": (par && par.appId) || ("portal.Portal" + json.data.id)
  2644. })
  2645. }
  2646. }
  2647. });
  2648. },
  2649. /**打开一个内容管理栏目(应用)。<br/>
  2650. * @method openCMS
  2651. * @static
  2652. * @param {String} name - 内容管理栏目的名称、别名或ID。
  2653. * @example
  2654. this.form.openCMS("通知公告");
  2655. */
  2656. "openCMS": function(name){
  2657. var action = MWF.Actions.get("x_cms_assemble_control");
  2658. action.getColumn(name, function(json){
  2659. if (json.data){
  2660. layout.desktop.openApplication(null, "cms.Module", {
  2661. "columnId": json.data.id,
  2662. "appId": "cms.Module"+json.data.id
  2663. });
  2664. }
  2665. });
  2666. },
  2667. /**打开一个流程应用。<br/>
  2668. * @method openProcess
  2669. * @static
  2670. * @param {String} name - 流程应用的名称、别名或ID。
  2671. * @example
  2672. this.form.openProcess("财务审批");
  2673. */
  2674. "openProcess": function(name){
  2675. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  2676. action.getApplication(name, function(json){
  2677. if (json.data){
  2678. layout.desktop.openApplication(null, "process.Application", {
  2679. "id": json.data.id,
  2680. "appId": "process.Application"+json.data.id
  2681. });
  2682. }
  2683. });
  2684. },
  2685. /**打开任意一个component应用。<br/>
  2686. * @method openApplication
  2687. * @static
  2688. * @param {String} name - 要打开的component的名称。component对应的名称可以在“控制面板-系统设置-界面设置-模块部署”中找到(即“组件路径”)。
  2689. * @param {Object} [options] - 打开的component的相关参数
  2690. * @example
  2691. //打开会议管理
  2692. this.form.openApplication("Meeting");
  2693. * @example
  2694. //打开一个流转中的流程实例。与 this.form.openWork(id, "", "work title");效果相同
  2695. this.form.openApplication("process.Work", {
  2696. "workId": id, //流程实例ID
  2697. "width": "1200", //宽度
  2698. "height": "800", //高度
  2699. "docTitle": "work title", //APP端窗口标题
  2700. "appId": "process.Work"+id //给新打开的component实例一个唯一名称
  2701. });
  2702. */
  2703. "openApplication":function(name, options){
  2704. layout.desktop.openApplication(null, name, options);
  2705. },
  2706. /**创建一条内容管理文档。
  2707. * @method createDocument
  2708. * @static
  2709. * @param {(String|Object)} [columnOrOptions]
  2710. * 如果不传参数,则弹出范围为平台所有栏目的选择界面。<br/>
  2711. * 当使用String时为内容管理应用(栏目)的名称、别名或ID。<br/>
  2712. * 当使用Object时,本参数后面的参数省略,传入如下格式的内容:
  2713. * <pre><code class="language-js">{
  2714. * "column" : column, //(string)可选,内容管理应用(栏目)的名称、别名或ID
  2715. * "category" : category, //(string)可选,要创建的文档所属的分类的名称、别名或ID
  2716. * "data" : data, //(json object)可选,创建文档时默认的业务数据
  2717. * "identity" : identity, //(string)可选,创建文档所使用的身份。如果此参数为空,且当前人有多个身份的情况下,会弹出身份选择对话框;否则使用默认身份。
  2718. * "callback" : callback, //(funcation)可选,文档创建后的回调函数。
  2719. * "target" : target, //(boolean)可选,为true时,在当前页面打开创建的文档;否则打开新窗口。默认false。
  2720. * "latest" : latest, //(boolean)可选,为true时,如果当前用户已经创建了此分类的文档,并且没有发布过,直接调用此文档为新文档;否则创建一个新文档。默认true。
  2721. * "selectColumnEnable" : selectColumnEnable, //(boolean)可选,是否可以选择应用和分类进行创建文档。有category参数时为默认false,否则默认为true。
  2722. * "ignoreTitle" : ignoreTitle //(boolean)可选,值为false时,创建的时候需要强制填写标题,默认为false。
  2723. * }</code></pre>
  2724. * @param {String} [category] - 要创建的文档所属的分类的名称、别名或ID
  2725. * @param {Object} [data] - 创建文档时默认的业务数据
  2726. * @param {String} [identity] - 可选,创建文档所使用的身份。如果此参数为空,且当前人有多个身份的情况下,会弹出身份选择对话框;否则使用默认身份。
  2727. * @param {Function} [callback] - 文档创建后的回调函数
  2728. * @param {Boolean} [target] - 为true时,在当前页面打开创建的文档;否则打开新窗口。默认false
  2729. * @param {Boolean} [latest] - 为true时,如果当前用户已经创建了此分类的文档,并且没有发布过,直接调用此文档为新文档;否则创建一个新文档。默认true。
  2730. * @param {Boolean} [selectColumnEnable] - 为true时,如果当前用户已经创建了此分类的文档,并且没有发布过,直接调用此文档为新文档;否则创建一个新文档。默认true。
  2731. * @param {Boolean} [ignoreTitle] - 值为false时,创建的时候需要强制填写标题,默认为false。
  2732. * @example
  2733. //启动一个通知公告
  2734. this.form.createDocument("", "通知公告");
  2735. * @example
  2736. //启动一个通知公告,标题为:关于XX的通知,启动后提示
  2737. this.form.createDocument("", "通知公告", {"subject": "关于XX的通知"}, function(json){
  2738. this.form.notice("创建成功!", "success");
  2739. }.bind(this));
  2740. * @example
  2741. //启动一个通知公告,标题为:关于XX的通知,启动后提示
  2742. this.form.createDocument({
  2743. category : "通知公告",
  2744. data : {"subject": "关于XX的通知"},
  2745. callback : function(json){
  2746. this.form.notice("创建成功!", "success");
  2747. }.bind(this)
  2748. });
  2749. */
  2750. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  2751. var column = columnOrOptions;
  2752. var onAfterPublish, onPostPublish;
  2753. if (typeOf(columnOrOptions) == "object") {
  2754. column = columnOrOptions.column;
  2755. category = columnOrOptions.category;
  2756. data = columnOrOptions.data;
  2757. identity = columnOrOptions.identity;
  2758. callback = columnOrOptions.callback;
  2759. target = columnOrOptions.target;
  2760. latest = columnOrOptions.latest;
  2761. selectColumnEnable = columnOrOptions.selectColumnEnable;
  2762. ignoreTitle = columnOrOptions.ignoreTitle;
  2763. onAfterPublish = columnOrOptions.onAfterPublish;
  2764. onPostPublish = columnOrOptions.onPostPublish;
  2765. }
  2766. if (target) {
  2767. if (layout.app && layout.app.inBrowser) {
  2768. layout.app.content.empty();
  2769. layout.app = null;
  2770. }
  2771. }
  2772. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  2773. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  2774. "documentData": data,
  2775. "identity": identity,
  2776. "ignoreTitle": ignoreTitle === true,
  2777. "ignoreDrafted": latest === false,
  2778. "selectColumnEnable": !category || selectColumnEnable === true,
  2779. "restrictToColumn": !!category && selectColumnEnable !== true,
  2780. "categoryFlag": category, //category id or name
  2781. "columnFlag": column, //column id or name,
  2782. "onStarted": function (documentId, data) {
  2783. if (callback) callback();
  2784. },
  2785. "onPostPublish": function () {
  2786. if(onPostPublish)onPostPublish();
  2787. },
  2788. "onAfterPublish": function () {
  2789. if(onAfterPublish)onAfterPublish();
  2790. }
  2791. });
  2792. starter.load();
  2793. })
  2794. },
  2795. /**启动一个流程实例。<br/>
  2796. * @method startProcess
  2797. * @static
  2798. * @param {String} app - 流程应用的名称、别名或ID。
  2799. * @param {String} process - 要启动的流程的名称、别名或ID。
  2800. * @param {Object} [data] - 流程启动时默认的业务数据。
  2801. * @param {String} [identity] - 流程启动所使用的身份。如果此参数为空,且当前人有多个身份的情况下,会弹出身份选择对话框;否则使用默认身份。。
  2802. * @param {Function} [callback] - 流程启动后的回调函数。
  2803. * @param {Boolean} [target] - 为true时,在当前页面打开启动的流程实例;否则打开新窗口。默认false。
  2804. * @param {Boolean} [latest] - 为true时,如果当前用户已经创建了此流程的实例,并且没有流转过,直接调用此实例为新流程实例;否则创建一个新实例。默认false。
  2805. * @example
  2806. //启动一个发文管理实例
  2807. this.form.startProcess("公文管理", "发文管理");
  2808. * @example
  2809. //启动一个发文管理实例,标题为:my file title,启动后提示
  2810. this.form.startProcess("公文管理", "发文管理", {"title": "my file title"}, function(json){
  2811. this.form.notice("create file success!", "success");
  2812. });
  2813. */
  2814. "startProcess": function(app, process, data, identity, callback, target, latest){
  2815. if (arguments.length>2){
  2816. for (var i=2; i<arguments.length; i++){
  2817. if (typeOf(arguments[i])=="boolean"){
  2818. target = arguments[i];
  2819. break;
  2820. }
  2821. }
  2822. }
  2823. if (target){
  2824. if (layout.app && layout.app.inBrowser){
  2825. //layout.app.content.empty();
  2826. layout.app.$openWithSelf = true;
  2827. }
  2828. }
  2829. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  2830. if (json.data){
  2831. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  2832. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  2833. "workData": data,
  2834. "identity": identity,
  2835. "latest": latest,
  2836. "onStarted": function(data, title, processName){
  2837. if (data.work){
  2838. var work = data.work;
  2839. var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
  2840. layout.desktop.openApplication(null, "process.Work", options);
  2841. }else{
  2842. var currentTask = [];
  2843. data.each(function(work){
  2844. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  2845. }.bind(this));
  2846. if (currentTask.length==1){
  2847. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  2848. layout.desktop.openApplication(null, "process.Work", options);
  2849. }else{}
  2850. }
  2851. if (callback) callback(data);
  2852. }.bind(this)
  2853. });
  2854. starter.load();
  2855. }.bind(this));
  2856. }
  2857. });
  2858. }
  2859. };
  2860. /**
  2861. * 在用户提交的时候,选择的路由。仅在表单的“校验意见”和“校验路由”脚本中可用。只读。<b>(仅流程表单中可用)</b>。
  2862. * @member currentRouteName
  2863. * @memberOf module:form
  2864. * @static
  2865. * @return {String} 用户选择的路由。
  2866. * @o2syntax
  2867. * var currentRouteName = this.form.currentRouteName;
  2868. */
  2869. this.form.currentRouteName = _form.json.currentRouteName;
  2870. /**
  2871. * 在用户提交的时候,输入的意见。仅在表单的“校验意见”和“校验路由”脚本中可用。只读。<b>(仅流程表单中可用)</b>。
  2872. * @member opinion
  2873. * @memberOf module:form
  2874. * @static
  2875. * @return {String} 用户填写的意见.
  2876. * @o2syntax
  2877. * var opinion = this.form.opinion;
  2878. */
  2879. this.form.opinion = _form.json.opinion;
  2880. /**
  2881. * 在提交的时候,用户的手写意见以及录音意见,仅在表单的“校验意见”和“校验路由”脚本中可用。只读。<b>(仅流程表单中可用)</b>。
  2882. * @member medias
  2883. * @memberOf module:form
  2884. * @static
  2885. * @return {Blob[]} 手写意见以及录音意见数组。手写意见和录音意见都是 HTML5的blob类型文件。
  2886. * @o2syntax
  2887. * var medias = this.form.medias;
  2888. */
  2889. this.form.medias = [];
  2890. this.target = ev.target;
  2891. this.event = ev.event;
  2892. this.status = ev.status;
  2893. this.session = layout.desktop.session;
  2894. this.Actions = o2.Actions;
  2895. this.query = function(option){
  2896. // options = {
  2897. // "name": "statementName",
  2898. // "data": "json data",
  2899. // "firstResult": 1,
  2900. // "maxResults": 100,
  2901. // "success": function(){},
  2902. // "error": function(){},
  2903. // "async": true or false, default is true
  2904. // }
  2905. if (option){
  2906. var json = (option.data) || {};
  2907. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  2908. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  2909. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  2910. }
  2911. }
  2912. this.Table = MWF.xScript.createTable();
  2913. };
  2914. MWF.xScript.createTable = function(){
  2915. return function(name){
  2916. this.name = name;
  2917. this.action = o2.Actions.get("x_query_assemble_surface");
  2918. this.listRowNext = function(id, count, success, error, async){
  2919. this.action.listRowNext(this.name, id, count, success, error, async);
  2920. };
  2921. this.listRowPrev = function(id, count, success, error, async){
  2922. this.action.listRowPrev(this.name, id, count, success, error, async);
  2923. };
  2924. this.listRowPrev = function(id, count, success, error, async){
  2925. this.action.listRowPrev(this.name, id, count, success, error, async);
  2926. };
  2927. this.listRowSelectWhere = function(where, success, error, async){
  2928. this.action.listRowSelectWhere(this.name, where, success, error, async);
  2929. };
  2930. this.listRowCountWhere = function(where, success, error, async){
  2931. this.action.listRowCountWhere(this.name, where, success, error, async);
  2932. };
  2933. this.deleteRow = function(id, success, error, async){
  2934. this.action.deleteRow(this.name, id, success, error, async);
  2935. };
  2936. this.deleteAllRow = function(success, error, async){
  2937. this.action.deleteAllRow(this.name, success, error, async);
  2938. };
  2939. this.getRow = function(id, success, error, async){
  2940. this.action.getRow(this.name, id, success, error, async);
  2941. };
  2942. this.insertRow = function(data, success, error, async){
  2943. this.action.insertRow(this.name, data, success, error, async);
  2944. };
  2945. this.updateRow = function(id, data, success, error, async){
  2946. this.action.updateRow(this.name, id, data, success, error, async);
  2947. };
  2948. }
  2949. };
  2950. MWF.xScript.JSONData = function(data, callback, key, parent, _form){
  2951. var getter = function(data, callback, k, _self){
  2952. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self, _form);};
  2953. };
  2954. var setter = function(data, callback, k, _self){
  2955. return function(v){
  2956. data[k] = v;
  2957. //debugger;
  2958. //this.add(k, v, true);
  2959. if (callback) callback(data, k, _self);
  2960. }
  2961. };
  2962. var define = function(){
  2963. var o = {};
  2964. for (var k in data) o[k] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, k, this]),"set": setter.apply(this, [data, callback, k, this])};
  2965. o["length"] = {"get": function(){return Object.keys(data).length;}};
  2966. o["some"] = {"get": function(){return data.some;}};
  2967. MWF.defineProperties(this, o);
  2968. var methods = {
  2969. "getKey": {"value": function(){ return key; }},
  2970. "getParent": {"value": function(){ return parent; }},
  2971. "toString": {"value": function() { return data.toString();}},
  2972. "setSection": {"value": function(newKey, newValue){
  2973. this.add(newKey, newValue, true);
  2974. try {
  2975. var path = [this.getKey()];
  2976. p = this.getParent();
  2977. while (p && p.getKey()){
  2978. path.unshift(p.getKey());
  2979. p = p.getParent();
  2980. }
  2981. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  2982. }catch(e){
  2983. }
  2984. }},
  2985. "add": {"value": function(newKey, newValue, overwrite){
  2986. var flag = true;
  2987. var type = typeOf(data);
  2988. if (type==="array"){
  2989. if (arguments.length<2){
  2990. data.push(newKey);
  2991. newValue = newKey;
  2992. newKey = data.length-1;
  2993. }else{
  2994. if (!newKey && newKey!==0){
  2995. data.push(newValue);
  2996. newKey = data.length-1;
  2997. }else{
  2998. flag = false;
  2999. }
  3000. }
  3001. if (flag){
  3002. var o = {};
  3003. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  3004. MWF.defineProperties(this, o);
  3005. }
  3006. this[newKey] = newValue;
  3007. }else if (type==="object"){
  3008. if (!this.hasOwnProperty(newKey)){
  3009. data[newKey] = newValue;
  3010. if (flag){
  3011. var o = {};
  3012. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  3013. MWF.defineProperties(this, o);
  3014. }
  3015. this[newKey] = newValue;
  3016. }else{
  3017. if (overwrite) this[newKey] = newValue;
  3018. }
  3019. }
  3020. return this[newKey];
  3021. }},
  3022. "del": {"value": function(delKey){
  3023. if (!this.hasOwnProperty(delKey)) return null;
  3024. // delete data[delKey];
  3025. // delete this[delKey];
  3026. data[delKey] = "";
  3027. this[delKey] = "";
  3028. return this;
  3029. }}
  3030. };
  3031. MWF.defineProperties(this, methods);
  3032. //this.getKey = function(){ return key; };
  3033. //this.getParent = function(){ return parent; };
  3034. //this.toString = function() { return data.toString();};
  3035. //this.add = function(newKey, newValue, overwrite){
  3036. // var flag = true;
  3037. // var type = typeOf(data);
  3038. // if (!this.hasOwnProperty(newKey)){
  3039. // if (type=="array"){
  3040. // if (arguments.length<2){
  3041. // data.push(newKey);
  3042. // newValue = newKey;
  3043. // newKey = data.length-1;
  3044. // }else{
  3045. // debugger;
  3046. // if (!newKey && newKey!=0){
  3047. // data.push(newValue);
  3048. // newKey = data.length-1;
  3049. // }else{
  3050. // flag == false;
  3051. // }
  3052. // }
  3053. // }else{
  3054. // data[newKey] = newValue;
  3055. // }
  3056. // //var valueType = typeOf(newValue);
  3057. // //var newValueData = newValue;
  3058. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  3059. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  3060. // if (flag){
  3061. // var o = {};
  3062. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  3063. // MWF.defineProperties(this, o);
  3064. // }
  3065. // this[newKey] = newValue;
  3066. // }else{
  3067. // if (overwrite) this[newKey] = newValue;
  3068. // }
  3069. //
  3070. // //var valueType = typeOf(newValue);
  3071. // //var newValueData = newValue;
  3072. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  3073. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  3074. // //
  3075. // //this[newKey] = newValueData;
  3076. //
  3077. // return this[newKey];
  3078. //};
  3079. //this.del = function(delKey){
  3080. // if (!this.hasOwnProperty(delKey)) return null;
  3081. // delete data[newKey];
  3082. // delete this[newKey];
  3083. // return this;
  3084. //};
  3085. };
  3086. var type = typeOf(data);
  3087. if (type==="object" || type==="array") define.apply(this);
  3088. };
  3089. //MWF.xScript.createDict = function(application){
  3090. // return function(name){
  3091. // var applicationId = application;
  3092. // this.name = name;
  3093. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  3094. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  3095. //
  3096. // this.get = function(path, success, failure){
  3097. // debugger;
  3098. // var value = null;
  3099. // if (path){
  3100. // var arr = path.split(/\./g);
  3101. // var ar = arr.map(function(v){
  3102. // return encodeURIComponent(v);
  3103. // });
  3104. // //var p = path.replace(/\./g, "/");
  3105. // var p = ar.join("/");
  3106. // action.getDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  3107. // value = json.data;
  3108. // if (success) success(json.data);
  3109. // }, function(xhr, text, error){
  3110. // if (failure) failure(xhr, text, error);
  3111. // }, false);
  3112. // }else{
  3113. // action.getDictRoot(encodeURIComponent(this.name), applicationId, function(json){
  3114. // value = json.data;
  3115. // if (success) success(json.data);
  3116. // }, function(xhr, text, error){
  3117. // if (failure) failure(xhr, text, error);
  3118. // }, false);
  3119. // }
  3120. //
  3121. // return value;
  3122. // };
  3123. //
  3124. // this.set = function(path, value, success, failure){
  3125. // var p = path.replace(/\./g, "/");
  3126. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  3127. // if (success) success(json.data);
  3128. // }, function(xhr, text, error){
  3129. // if (failure) failure(xhr, text, error);
  3130. // });
  3131. // };
  3132. // this.add = function(path, value, success, failure){
  3133. // var p = path.replace(/\./g, "/");
  3134. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  3135. // if (success) success(json.data);
  3136. // }, function(xhr, text, error){
  3137. // if (failure) failure(xhr, text, error);
  3138. // });
  3139. // };
  3140. // this["delete"] = function(path, success, failure){
  3141. // var p = path.replace(/\./g, "/");
  3142. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  3143. // if (success) success(json.data);
  3144. // }, function(xhr, text, error){
  3145. // if (failure) failure(xhr, text, error);
  3146. // });
  3147. // };
  3148. // this.destory = this["delete"];
  3149. // }
  3150. //};
  3151. // var dictLoaded = {};
  3152. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  3153. MWF.xScript.addDictToCache = function ( options, path, json ) {
  3154. if( !path )path = "root";
  3155. if( path.indexOf("root") !== 0 )path = "root." + path ;
  3156. var type = options.appType || "process";
  3157. var enableAnonymous = options.enableAnonymous || false;
  3158. var appFlagList = [];
  3159. if( options.application )appFlagList.push( options.application );
  3160. if( options.appId )appFlagList.push( options.appId );
  3161. if( options.appName )appFlagList.push( options.appName );
  3162. if( options.appAlias )appFlagList.push( options.appAlias );
  3163. var dictFlagList = [];
  3164. if( options.id )dictFlagList.push( options.id );
  3165. if( options.name )dictFlagList.push( options.name );
  3166. if( options.alias )dictFlagList.push( options.alias );
  3167. var cache = {};
  3168. cache[path] = json;
  3169. for( var i=0; i<appFlagList.length; i++ ){
  3170. for( var j=0; j<dictFlagList.length; j++ ){
  3171. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  3172. if( !MWF.xScript.dictLoaded[k] ){
  3173. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  3174. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  3175. }else if( i===0 && j===0 ){
  3176. MWF.xScript.setDictToCache( k, path ,json );
  3177. var arr = path.split(/\./g);
  3178. var p;
  3179. var cache = MWF.xScript.dictLoaded[k];
  3180. for( var l=0 ; l<arr.length; l++ ){
  3181. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  3182. if( cache[ p ] )break;
  3183. }
  3184. if( p ){
  3185. var mathP = p+".";
  3186. Object.keys( cache ).each( function( path, idx){
  3187. if( path.indexOf( mathP ) === 0 )delete cache[path];
  3188. })
  3189. }
  3190. }
  3191. }
  3192. }
  3193. };
  3194. MWF.xScript.getMatchedDict = function(key, path){
  3195. if( !path )path = "root";
  3196. if( path.indexOf("root") !== 0 )path = "root." + path ;
  3197. var arr = path.split(/\./g);
  3198. if( MWF.xScript.dictLoaded[key] ){
  3199. var dicts = MWF.xScript.dictLoaded[key];
  3200. var list = Array.clone(arr);
  3201. var p;
  3202. var dict;
  3203. for( var i=0 ; i<arr.length; i++ ){
  3204. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  3205. list.shift();
  3206. if( dicts[ p ] ){
  3207. dict = dicts[ p ];
  3208. break;
  3209. }
  3210. }
  3211. return {
  3212. dict : dict,
  3213. unmatchedPathList : list
  3214. }
  3215. }
  3216. return {
  3217. dict : null,
  3218. unmatchedPathList : list
  3219. }
  3220. };
  3221. MWF.xScript.insertDictToCache = function(key, path, json){
  3222. if( MWF.xScript.dictLoaded[key] ){
  3223. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  3224. var dict = matchedDict.dict;
  3225. var list = matchedDict.unmatchedPathList;
  3226. if( !dict ){
  3227. MWF.xScript.dictLoaded[key][path] = json;
  3228. }else{
  3229. for( var j=0; j<list.length-1; j++ ){
  3230. if( !dict[ list[j] ] ){
  3231. dict[ list[j] ] = {};
  3232. }
  3233. dict = dict[ list[j] ];
  3234. }
  3235. var lastPath = list[list.length-1];
  3236. if( !dict[lastPath] ){
  3237. dict[lastPath] = json;
  3238. }else if( typeOf( dict[lastPath] ) === "array" ){
  3239. dict[lastPath].push( json );
  3240. }
  3241. }
  3242. }else{
  3243. MWF.xScript.dictLoaded[key] = {};
  3244. MWF.xScript.dictLoaded[key][path] = json;
  3245. }
  3246. };
  3247. MWF.xScript.setDictToCache = function(key, path, json){
  3248. if( MWF.xScript.dictLoaded[key] ){
  3249. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  3250. var dict = matchedDict.dict;
  3251. var list = matchedDict.unmatchedPathList;
  3252. if( !dict ){
  3253. MWF.xScript.dictLoaded[key][path] = json;
  3254. }else{
  3255. for( var j=0; j<list.length-1; j++ ){
  3256. if( !dict[ list[j] ] ){
  3257. dict[ list[j] ] = {};
  3258. }
  3259. dict = dict[ list[j] ];
  3260. }
  3261. dict[list[list.length-1]] = json;
  3262. }
  3263. }else{
  3264. MWF.xScript.dictLoaded[key] = {};
  3265. MWF.xScript.dictLoaded[key][path] = json;
  3266. }
  3267. };
  3268. MWF.xScript.getDictFromCache = function( key, path ){
  3269. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  3270. var dict = matchedDict.dict;
  3271. var list = matchedDict.unmatchedPathList;
  3272. if( dict ){
  3273. for( var j=0; j<list.length; j++ ){
  3274. dict = dict[ list[j] ];
  3275. if( !dict )return null;
  3276. }
  3277. return dict;
  3278. }
  3279. return null;
  3280. };
  3281. MWF.xScript.deleteDictToCache = function(key, path){
  3282. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  3283. var dict = matchedDict.dict;
  3284. var list = matchedDict.unmatchedPathList;
  3285. if( dict){
  3286. for( var j=0; j<list.length-1; j++ ){
  3287. dict = dict[ list[j] ];
  3288. if( !dict )return;
  3289. }
  3290. delete dict[list[list.length-1]];
  3291. }
  3292. };
  3293. MWF.xScript.createDict = function(application){
  3294. //optionsOrName : {
  3295. // type : "", //默认为process, 可以为 process cms
  3296. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  3297. // name : "", // 数据字典名称/别名/id
  3298. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  3299. //}
  3300. //或者name: "" // 数据字典名称/别名/id
  3301. return function(optionsOrName){
  3302. var options = optionsOrName;
  3303. if( typeOf( options ) == "string" ){
  3304. options = { name : options };
  3305. }
  3306. var name = this.name = options.name;
  3307. var type = ( options.type && options.application ) ? options.type : "process";
  3308. var applicationId = options.application || application;
  3309. var enableAnonymous = options.enableAnonymous || false;
  3310. var opt = {
  3311. "appType" : type,
  3312. "name" : name,
  3313. "appId" : applicationId,
  3314. "enableAnonymous" : enableAnonymous
  3315. };
  3316. var key = name+type+applicationId+enableAnonymous;
  3317. // if (!dictLoaded[key]) dictLoaded[key] = {};
  3318. // this.dictData = dictLoaded[key];
  3319. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  3320. if( type == "cms" ){
  3321. var action = MWF.Actions.get("x_cms_assemble_control");
  3322. }else{
  3323. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  3324. }
  3325. var encodePath = function( path ){
  3326. var arr = path.split(/\./g);
  3327. var ar = arr.map(function(v){
  3328. return encodeURIComponent(v);
  3329. });
  3330. return ar.join("/");
  3331. };
  3332. this.get = function(path, success, failure, async, refresh){
  3333. var value = null;
  3334. if (success===true) async=true;
  3335. if (failure===true) async=true;
  3336. if (!refresh ){
  3337. var data = MWF.xScript.getDictFromCache( key, path );
  3338. if( data ){
  3339. if (success && o2.typeOf(success)=="function") success( data );
  3340. if( !!async ){
  3341. return Promise.resolve( data );
  3342. }else{
  3343. return data;
  3344. }
  3345. }
  3346. }
  3347. // var cb = function(json){
  3348. // value = json.data;
  3349. // MWF.xScript.addDictToCache(opt, path, value);
  3350. // if (success && o2.typeOf(success)=="function") value = success(json.data);
  3351. // return value;
  3352. // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
  3353. var cb = function(json){
  3354. value = json.data;
  3355. MWF.xScript.addDictToCache(opt, path, value);
  3356. if (success && o2.typeOf(success)=="function") value = success(json.data);
  3357. return value;
  3358. };
  3359. var promise;
  3360. if (path){
  3361. var p = encodePath( path );
  3362. //var p = path.replace(/\./g, "/");
  3363. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async, false);
  3364. }else{
  3365. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async, false);
  3366. }
  3367. return (!!async) ? promise : value;
  3368. // if (path){
  3369. // var p = encodePath( path );
  3370. // //var p = path.replace(/\./g, "/");
  3371. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  3372. // value = json.data;
  3373. // // this.dictData[path] = value;
  3374. // MWF.xScript.addDictToCache(opt, path, value);
  3375. // if (success) success(json.data);
  3376. // }.bind(this), function(xhr, text, error){
  3377. // if (failure) failure(xhr, text, error);
  3378. // }, !!async);
  3379. // }else{
  3380. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  3381. // value = json.data;
  3382. // // this.dictData["root"] = value;
  3383. // MWF.xScript.addDictToCache(opt, path, value);
  3384. // if (success) success(json.data);
  3385. // }.bind(this), function(xhr, text, error){
  3386. // if (failure) failure(xhr, text, error);
  3387. // }, !!async);
  3388. // }
  3389. //return value;
  3390. };
  3391. this.set = function(path, value, success, failure){
  3392. var p = encodePath( path );
  3393. //var p = path.replace(/\./g, "/");
  3394. return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  3395. MWF.xScript.setDictToCache(key, path, value);
  3396. if (success) return success(json.data);
  3397. }, function(xhr, text, error){
  3398. if (failure) return failure(xhr, text, error);
  3399. }, false, false);
  3400. };
  3401. this.add = function(path, value, success, failure){
  3402. var p = encodePath( path );
  3403. //var p = path.replace(/\./g, "/");
  3404. return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  3405. MWF.xScript.insertDictToCache(key, path, value);
  3406. if (success) return success(json.data);
  3407. }, function(xhr, text, error){
  3408. if (failure) return failure(xhr, text, error);
  3409. }, false, false);
  3410. };
  3411. this["delete"] = function(path, success, failure){
  3412. var p = encodePath( path );
  3413. //var p = path.replace(/\./g, "/");
  3414. return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  3415. MWF.xScript.deleteDictToCache(key, path);
  3416. if (success) return success(json.data);
  3417. }, function(xhr, text, error){
  3418. if (failure) return failure(xhr, text, error);
  3419. }, false, false);
  3420. };
  3421. this.destory = this["delete"];
  3422. }
  3423. };