Environment.js 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730
  1. /**
  2. * Work 数据结构,流程实例对象
  3. * @typedef {Object} Work
  4. * @example
  5. * {
  6. "id": "854e2c22-718e-48bb-98db-96f4b43e7ee8", //流程实例ID
  7. "splitValue": "xxxxxxxxxxxxxx", //流程拆分后的拆分依据
  8. "title": "xx7月北京出差报销审批", //流程实例名称
  9. "startTime": "2018-09-07 14:03:22", //流程启动时间
  10. "startTimeMonth": "2018-09", //流程启动的月份
  11. "creatorPerson": "xx@huqi@P", //流程实例创建人
  12. "creatorIdentity": "xx@481c9edc-5fb5-41f1-b5c2-6ea609082cdb@I", //流程实例创建人身份
  13. "creatorUnit": "xx@c448d8bb-98b8-4305-9d3f-12537723cfcc@U", //流程实例创建人所在组织
  14. "creatorUnitLevelName": "浙江兰德纵横/开发部", //流程实例创建人所在组织层次
  15. "application": "1dc23336-6be6-402b-bed6-36e707a1dd17", //流程应用ID
  16. "applicationName": "财务管理", //流程应用名称
  17. "applicationAlias": "finance", //流程应用别名
  18. "process": "2207db11-dddf-4ebd-864d-3819f3e173c6", //流程ID
  19. "processName": "报销审批流程", //流程名称
  20. "processAlias": "", //流程别名
  21. "activity": "13d15daf-2ac5-4c1b-a669-1607a0e5ed15", //当前活动ID
  22. "activityType": "manual", //当前活动类型
  23. "activityName": "部门领导审核", //当前活动名称
  24. "activityAlias": "", //当前活动别名
  25. "activityDescription": "", //当前活动描述
  26. "activityArrivedTime": "2018-09-27 22:49:21", //当前活动到达时间
  27. "serial": "", //编号
  28. "workStatus": "processing", //流程实例状态
  29. "errorRetry": 0, //流转失败重试次数
  30. "splitting": false, //流程是否拆分
  31. "form": "db3b2766-93a1-4058-b522-0edb922bd84f", //流程展现所使用的表单
  32. "manualTaskIdentityList" : "张三@db3b2766-93a1-4058-b522-0edb922bd84f@I", //预期的处理人
  33. "manualTaskIdentityText" : "张三" //当前处理人身份合并文本,用','分割,超长截断,此字段仅用于显示当前工作的处理人,不索引.
  34. }
  35. */
  36. /**
  37. * WorkCompleted 数据结构,已结束流程实例对象
  38. * @typedef {Object} WorkCompleted
  39. * @example
  40. * {
  41. "id": "be0195f1-f2e2-4eac-911c-99897a43ff8f", //流程实例ID
  42. "title": "xx7月北京出差报销审批", //流程实例名称
  43. "startTime": "2018-09-19 16:14:16", //流程启动时间
  44. "startTimeMonth": "2018-09", //流程启动的月份
  45. "completedTime": "2018-09-19 16:15:28", //流程完成时间
  46. "completedTimeMonth": "2018-09", //流程完成的月份
  47. "creatorPerson": "xx@huqi@P", //流程实例创建人
  48. "creatorIdentity": "xx@481c9edc-5fb5-41f1-b5c2-6ea609082cdb@I", //流程实例创建人身份
  49. "creatorUnit": "xx@c448d8bb-98b8-4305-9d3f-12537723cfcc@U", //流程实例创建人所在组织
  50. "creatorUnitLevelName": "浙江兰德纵横/开发部", //流程实例创建人所在组织层次
  51. "application": "1dc23336-6be6-402b-bed6-36e707a1dd17", //流程应用ID
  52. "applicationName": "财务管理", //流程应用名称
  53. "applicationAlias": "finance", //流程应用别名
  54. "process": "2207db11-dddf-4ebd-864d-3819f3e173c6", //流程ID
  55. "processName": "报销审批流程", //流程名称
  56. "processAlias": "", //流程别名
  57. "serial": "", //编号
  58. "form": "320be1ca-ee49-478f-a751-f65ab67cf818", //流程展现所使用的表单
  59. }
  60. */
  61. /**
  62. * Task数据结构,待办任务对象
  63. * @typedef {Object} Task
  64. * @example
  65. * {
  66. "id": "dd476045-7c79-44f7-9dba-f51d322de40f", //待办ID
  67. "title": "XX7月北京出差报销审批", //流程实例标题
  68. "startTime": "2018-09-27 22:49:22", //待办到达时间
  69. "startTimeMonth": "2018-09", //待办到达的月份
  70. "work": "854e2c22-718e-48bb-98db-96f4b43e7ee8", //流程实例ID
  71. "application": "1dc23336-6be6-402b-bed6-36e707a1dd17", //流程应用ID
  72. "applicationName": "财务管理", //流程应用名称
  73. "applicationAlias": "finance", //流程应用别名
  74. "process": "2207db11-dddf-4ebd-864d-3819f3e173c6", //流程ID
  75. "processName": "报销审批流程", //流程名称
  76. "processAlias": "", //流程别名
  77. "serial": "", //流程编号
  78. "person": "XXX@huqi@P", //待办人名称
  79. "identity": "XX@481c9edc-5fb5-41f1-b5c2-6ea609082cdb@I", //待办人身份
  80. "unit": "XX@c448d8bb-98b8-4305-9d3f-12537723cfcc@U", //待办人所在组织
  81. "activity": "13d15daf-2ac5-4c1b-a669-1607a0e5ed15", //当前活动的ID
  82. "activityName": "部门领导审核", //当前活动的名称
  83. "activityAlias": "", //当前活动的别名
  84. "activityDescription": "", //当前活动描述
  85. "activityType": "manual", //当前活动类型
  86. "creatorPerson": "XX@huqi@P", //流程实例创建人
  87. "creatorIdentity": "XX@481c9edc-5fb5-41f1-b5c2-6ea609082cdb@I", //流程实例创建人的身份
  88. "creatorUnit": "XX@c448d8bb-98b8-4305-9d3f-12537723cfcc@U", //流程实例创建人所在组织
  89. "expired": false, //是否已超时
  90. "urged": false, //是否进行催办
  91. "routeList": [ //可选的路由ID
  92. "89b58fe0-6dcb-4fe7-8c2e-3f77204df6d4",
  93. "f3105b7a-2929-4682-aab8-15fef5ea0f23"
  94. ],
  95. "routeNameList": [ //可选的路由名称
  96. "退回申请人",
  97. "送财务部门复审"
  98. ],
  99. "routeOpinionList": [ //可选路由的默认意见
  100. "",
  101. ""
  102. ],
  103. "first" : true, //是否是第一条待办.
  104. "properties": { //属性对象存储字段
  105. "prevTaskIdentity": "张三@903dbb04-085c-4bb1-9c24-3009bd5f7372@I", //提交的处理人
  106. "prevTaskIdentityList": [ //上一步处理人
  107. "张三@903dbb04-085c-4bb1-9c24-3009bd5f7372@I"
  108. ],
  109. "prevTaskList": [ //上一步任务信息
  110. {
  111. "routeName": "送办理",
  112. "unit": "产品研发组@320189216@U",
  113. "identity": "张三@903dbb04-085c-4bb1-9c24-3009bd5f7372@I",
  114. "person": "张三@zhangsan@P",
  115. "opinion": "",
  116. "startTime": "2020-09-29 17:03:14",
  117. "completedTime": "2020-09-29 17:04:38"
  118. }
  119. ],
  120. "prevTask": { //提交的任务信息
  121. "routeName": "送办理",
  122. "unit": "产品研发组@320189216@U",
  123. "identity": "张三@903dbb04-085c-4bb1-9c24-3009bd5f7372@I",
  124. "person": "张三@zhangsan@P",
  125. "opinion": "",
  126. "startTime": "2020-09-29 17:03:14",
  127. "completedTime": "2020-09-29 17:04:38"
  128. }
  129. }
  130. * }
  131. */
  132. /**
  133. * Read 数据结构,待阅任务对象
  134. * @typedef {Object} Read
  135. * @example
  136. * {
  137. "id": "dd476045-7c79-44f7-9dba-f51d322de40f", //待阅ID
  138. "title": "XX7月北京出差报销审批", //流程实例标题
  139. "startTime": "2018-09-27 22:49:22", //待阅产生时间
  140. "startTimeMonth": "2018-09", //待阅产生的月份
  141. "work": "854e2c22-718e-48bb-98db-96f4b43e7ee8", //流程实例ID
  142. "application": "1dc23336-6be6-402b-bed6-36e707a1dd17", //流程应用ID
  143. "applicationName": "财务管理", //流程应用名称
  144. "applicationAlias": "finance", //流程应用别名
  145. "process": "2207db11-dddf-4ebd-864d-3819f3e173c6", //流程ID
  146. "processName": "报销审批流程", //流程名称
  147. "processAlias": "", //流程别名
  148. "completed": false, //流程是否已完成
  149. "serial": "", //流程编号
  150. "person": "XXX@huqi@P", //待阅人名称
  151. "identity": "XX@481c9edc-5fb5-41f1-b5c2-6ea609082cdb@I", //待阅人身份
  152. "unit": "XX@c448d8bb-98b8-4305-9d3f-12537723cfcc@U", //待阅人所在组织
  153. "activity": "13d15daf-2ac5-4c1b-a669-1607a0e5ed15", //当前活动的ID
  154. "activityName": "部门领导审核", //当前活动的名称
  155. "activityAlias": "", //当前活动的别名
  156. "activityDescription": "", //当前活动描述
  157. "activityType": "manual", //当前活动类型
  158. "creatorPerson": "XX@huqi@P", //流程实例创建人
  159. "creatorIdentity": "XX@481c9edc-5fb5-41f1-b5c2-6ea609082cdb@I", //流程实例创建人的身份
  160. "creatorUnit": "XX@c448d8bb-98b8-4305-9d3f-12537723cfcc@U" //流程实例创建人所在组织
  161. }
  162. */
  163. /**
  164. * Activity 数据结构,流程实例所在的活动节点对象
  165. * @typedef {Object} Activity
  166. * @example
  167. *
  168. {
  169. "id": "801087c5-a4e6-4b91-bf4d-a81cdaa04471", //节点ID
  170. "name": "办理", //节点名称
  171. "description": "", //节点描述
  172. "alias": "", //节点别名
  173. "resetRange": "department", //重置处理人范围
  174. "resetCount": 0, //重置处理人数字
  175. "allowReset": true, //是否允许重置
  176. "manualMode": "single" //处理方式 单人single, 并行parallel, 串行queue, grab抢办
  177. }
  178. */
  179. MWF.xScript = MWF.xScript || {};
  180. MWF.xScript.Environment = function(ev){
  181. var _data = ev.data;
  182. var _form = ev.form;
  183. var _forms = ev.forms;
  184. this.library = COMMON;
  185. //this.library.version = "4.0";
  186. this.power = {
  187. "isManager": MWF.AC.isProcessManager() || _form.businessData.control.allowReroute,
  188. "isReseter": _form.businessData.control.allowReset,
  189. "isDelete": _form.businessData.control.allowDeleteWork,
  190. "isPront": true,
  191. "isPrint": true
  192. };
  193. //data
  194. var getJSONData = function(jData){
  195. return new MWF.xScript.JSONData(jData, function(data, key, _self){
  196. var p = {"getKey": function(){return key;}, "getParent": function(){return _self;}};
  197. while (p && !_forms[p.getKey()]) p = p.getParent();
  198. if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
  199. }, "", null, _form);
  200. };
  201. this.setData = function(data){
  202. this.data = getJSONData(data);
  203. this.data.save = function(callback){
  204. _form.saveFormData(callback)
  205. // var formData = {
  206. // "data": data,
  207. // "sectionList": _form.getSectionList()
  208. // };
  209. // _form.workAction.saveSectionData(function(){if (callback) callback();}.bind(this), null, (ev.work.id || ev.workCompleted.id), formData);
  210. }
  211. };
  212. this.setData(_data);
  213. //task
  214. //this.task = ev.task;
  215. //this.task.process = function(routeName, opinion, callback){
  216. // _form.submitWork(routeName, opinion, callback);
  217. //};
  218. //inquiredRouteList
  219. //this.inquiredRouteList = null;
  220. //workContext
  221. /**
  222. * 你可以通过workContext获取和流程相关的流程实例对象数据。
  223. * @module workContext
  224. * @example
  225. * //您可以在表单或流程的各个嵌入脚本中,通过this来获取当前流程实例数据,如下:
  226. * var context = this.workContext;
  227. */
  228. this.workContext = {
  229. /**
  230. * 当前流程实例正在流转中,并且当前用户有待办,则返回当前用户的待办对象,否则返回null。
  231. * @summary 获取当前流程与当前用户相关的待办对象:task对象。
  232. * @method getTask
  233. * @static
  234. * @return {(Task|Null)} 当前用户的待办任务对象:task。当前用户没有对此流程实例的待办时,或流程实例已经流转结束,返回null.
  235. * @example
  236. * var task = this.workContext.getTask();
  237. */
  238. "getTask": function(){return ev.task || null;},
  239. /**
  240. * 获取当前流程实例对象:work对象或workCompleted对象。
  241. * @method getWork
  242. * @static
  243. * @return {(Work|WorkCompleted)} 流程实例对象;如果流程已结束,返回已结束的流程实例对象.
  244. * @example
  245. * var work = this.workContext.getWork();
  246. */
  247. "getWork": function(){return ev.work || ev.workCompleted;},
  248. /**
  249. * 获取当前流程实例所在的活动节点对象:activity对象。
  250. * @method getActivity
  251. * @static
  252. * @return {(Activity|Null)} 当前流程实例所在的活动节点对象,如果当前流程实例已流转完成,则返回null.
  253. * @example
  254. * var activity = this.workContext.getActivity();
  255. */
  256. "getActivity": function(){return ev.activity || null;},
  257. /**
  258. * 获取当前流程实例的所有待办对象。如果流程实例已流转完成,则返回一个空数组。
  259. * @method getTaskList
  260. * @static
  261. * @return {(Task[])} 待办任务列表.
  262. * @example
  263. * var taskList = this.workContext.getTaskList();
  264. */
  265. "getTaskList": function(callback, error){
  266. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  267. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  268. var list;
  269. o2.Actions.get("x_processplatform_assemble_surface").listTaskByWork(ev.work.id, function(json){
  270. list = json.data;
  271. if (cb) cb(list);
  272. }, ecb, !!cb);
  273. return list;
  274. },
  275. /**
  276. * 根据当前工作的job获取当前流程实例的所有待办对象。如果流程实例已流转完成,则返回一个空数组。
  277. * @method getTaskListByJob
  278. * @static
  279. * @return {(Task[])} 待办任务列表.
  280. * @example
  281. * var taskList = this.workContext.getTaskListByJob();
  282. */
  283. "getTaskListByJob": function(callback, error){
  284. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  285. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  286. var list;
  287. o2.Actions.get("x_processplatform_assemble_surface").listTaskByJob(ev.work.job, function(json){
  288. list = json.data;
  289. if (cb) cb(list);
  290. }, ecb, !!cb);
  291. return list;
  292. },
  293. "getReadList": function(callback, error){
  294. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  295. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  296. var list;
  297. o2.Actions.get("x_processplatform_assemble_surface").listReadByWork(ev.work.id, function(json){
  298. list = json.data;
  299. if (cb) cb(list);
  300. }, ecb, !!cb);
  301. return list;
  302. },
  303. "getReadListByJob": function(callback, error){
  304. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  305. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  306. var list;
  307. o2.Actions.get("x_processplatform_assemble_surface").listReadByJob(ev.work.job, function(json){
  308. list = json.data;
  309. if (cb) cb(list);
  310. }, ecb, !!cb);
  311. return list;
  312. },
  313. "getTaskCompletedList": function(callback, error){
  314. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  315. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  316. var list;
  317. o2.Actions.get("x_processplatform_assemble_surface").listTaskCompletedByWork(ev.work.id, function(json){
  318. list = json.data;
  319. if (cb) cb(list);
  320. }, ecb, !!cb);
  321. return list;
  322. },
  323. "getTaskCompletedListByJob": function(callback, error){
  324. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  325. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  326. var list;
  327. o2.Actions.get("x_processplatform_assemble_surface").listTaskCompletedByJob(ev.work.job, function(json){
  328. list = json.data;
  329. if (cb) cb(list);
  330. }, ecb, !!cb);
  331. return list;
  332. },
  333. "getReadCompletedList": function(callback, error){
  334. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  335. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  336. var list;
  337. o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByWork(ev.work.id, function(json){
  338. list = json.data;
  339. if (cb) cb(list);
  340. }, ecb, !!cb);
  341. return list;
  342. },
  343. "getReadCompletedListByJob": function(callback, error){
  344. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  345. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  346. var list;
  347. o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByJob(ev.work.job, function(json){
  348. list = json.data;
  349. if (cb) cb(list);
  350. }, ecb, !!cb);
  351. return list;
  352. },
  353. "getJobTaskList": this.getTaskListByJob,
  354. "getJobReadList": this.getReadListByJob,
  355. "getJobTaskCompletedList": this.getTaskCompletedListByJob,
  356. "getJobReadCompletedList": this.getReadCompletedListByJob,
  357. "getControl": function(){return ev.control;},
  358. "getWorkLogList": function(){return ev.workLogList;},
  359. "getRecordList": function(){return ev.recordList;},
  360. "getAttachmentList": function(){return ev.attachmentList;},
  361. "getRouteList": function(){return (ev.task) ? ev.task.routeNameList: null;},
  362. "getInquiredRouteList": function(){return null;},
  363. "setTitle": function(title){
  364. if (!this.workAction){
  365. MWF.require("MWF.xScript.Actions.WorkActions", null, false);
  366. this.workAction = new MWF.xScript.Actions.WorkActions();
  367. }
  368. this.workAction.setTitle(ev.work.id, {"title": title});
  369. }
  370. };
  371. this.workContent = this.workContext;
  372. var _redefineWorkProperties = function(work){
  373. if (work){
  374. work.creatorPersonDn = work.creatorPerson ||"";
  375. work.creatorUnitDn = work.creatorUnit ||"";
  376. work.creatorUnitDnList = work.creatorUnitList ||"";
  377. work.creatorIdentityDn = work.creatorIdentity ||"";
  378. var o = {
  379. "creatorPerson": {"get": function(){return this.creatorPersonDn.substring(0, this.creatorPersonDn.indexOf("@"));}},
  380. "creatorUnit": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  381. "creatorDepartment": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  382. "creatorIdentity": {"get": function(){return this.creatorIdentityDn.substring(0, this.creatorIdentityDn.indexOf("@"));}},
  383. // "creatorUnitList": {
  384. // "get": function(){
  385. // var v = [];
  386. // this.creatorUnitDnList.each(function(dn){
  387. // v.push(dn.substring(0, dn.indexOf("@")))
  388. // });
  389. // return v;
  390. // }
  391. // },
  392. "creatorCompany": {"get": function(){
  393. if (this.creatorUnitLevel){
  394. var level = this.creatorUnitLevel.split("/");
  395. return level[0];
  396. }else{
  397. return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));
  398. }
  399. }}
  400. };
  401. MWF.defineProperties(work, o);
  402. }
  403. return work;
  404. };
  405. var _redefineTaskProperties = function(task){
  406. if (task){
  407. task.personDn = task.person || "";
  408. task.unitDn = task.unit || "";
  409. task.unitDnList = task.unitList || "";
  410. task.identityDn = task.identity || "";
  411. var o = {
  412. "person": {"get": function(){return this.personDn.substring(0, this.personDn.indexOf("@"));}},
  413. "unit": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  414. "department": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  415. "identity": {"get": function(){return this.identityDn.substring(0, this.identityDn.indexOf("@"));}},
  416. // "unitList": {
  417. // "get": function(){
  418. // var v = [];
  419. // this.unitDnList.each(function(dn){
  420. // v.push(dn.substring(0, dn.indexOf("@")))
  421. // });
  422. // return v;
  423. // }
  424. // },
  425. "company": {"get": function(){return this.unitList[0];}}
  426. };
  427. MWF.defineProperties(task, o);
  428. }
  429. return task;
  430. };
  431. _redefineWorkProperties(this.workContext.getWork());
  432. _redefineTaskProperties(_redefineWorkProperties(this.workContext.getTask()));
  433. //dict
  434. this.Dict = MWF.xScript.createDict(_form.json.application);
  435. //unit
  436. var orgActions = null;
  437. var getOrgActions = function(){
  438. // if (!orgActions){
  439. // MWF.xDesktop.requireApp("Org", "Actions.RestActions", null, false);
  440. // orgActions = new MWF.xApplication.Org.Actions.RestActions ();
  441. // }
  442. if (!orgActions){
  443. MWF.require("MWF.xScript.Actions.UnitActions", null, false);
  444. orgActions = new MWF.xScript.Actions.UnitActions();
  445. }
  446. };
  447. var getNameFlag = function(name){
  448. var t = typeOf(name);
  449. if (t==="array"){
  450. var v = [];
  451. name.each(function(id){
  452. v.push((typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  453. });
  454. return v;
  455. }else{
  456. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  457. }
  458. };
  459. /**
  460. * 你可以通过workContext获取和流程相关的流程实例对象数据。
  461. * @module this.org
  462. * @example
  463. * //您可以在表单或流程的各个嵌入脚本中,通过this来获取当前流程实例数据,如下:
  464. * var context = this.workContext;
  465. */
  466. this.org = {
  467. //群组***************
  468. //获取群组--返回群组的对象数组
  469. /**
  470. 根据群组标识获取对应的群组对象数组:group对象数组
  471. */
  472. getGroup: function(name, async){
  473. getOrgActions();
  474. var data = {"groupList": getNameFlag(name)};
  475. var v = null;
  476. var cb = function(json){
  477. v = json.data;
  478. v = (v && v.length===1) ? v[0] : v
  479. if (async && o2.typeOf(async)=="function") return async(v);
  480. return v;
  481. };
  482. var promise = orgActions.listGroup(data, cb, null, !!async);
  483. return (!!async) ? promise : v;
  484. // var v = null;
  485. // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  486. // return (v && v.length===1) ? v[0] : v;
  487. },
  488. //查询下级群组--返回群组的对象数组
  489. //nested 布尔 true嵌套下级;false直接下级;默认false;
  490. listSubGroup: function(name, nested, async){
  491. getOrgActions();
  492. var data = {"groupList": getNameFlag(name)};
  493. var v = null;
  494. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  495. // v = json.data;
  496. // return v;
  497. // }.ag().catch(function(json){ return json; });
  498. var cb = function(json){
  499. v = json.data;
  500. if (async && o2.typeOf(async)=="function") return async(v);
  501. return v;
  502. };
  503. var promise;
  504. if (nested){
  505. promise = orgActions.listSubGroupNested(data, cb, null, !!async);
  506. }else{
  507. promise = orgActions.listSubGroupDirect(data, cb, null, !!async);
  508. }
  509. return (!!async) ? promise : v;
  510. // var v = null;
  511. // if (nested){
  512. // orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  513. // }else{
  514. // orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  515. // }
  516. // return v;
  517. },
  518. //查询上级群组--返回群组的对象数组
  519. //nested 布尔 true嵌套上级;false直接上级;默认false;
  520. listSupGroup:function(name, nested, async){
  521. getOrgActions();
  522. var data = {"groupList": getNameFlag(name)};
  523. var v = null;
  524. var cb = function(json){
  525. v = json.data;
  526. if (async && o2.typeOf(async)=="function") return async(v);
  527. return v;
  528. };
  529. var promise
  530. if (nested){
  531. var promise = orgActions.listSupGroupNested(data, cb, null, !!async);
  532. }else{
  533. var promise = orgActions.listSupGroupDirect(data, cb, null, !!async);
  534. }
  535. return (!!async) ? promise : v;
  536. // var v = null;
  537. // if (nested){
  538. // orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  539. // }else{
  540. // orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  541. // }
  542. // return v;
  543. },
  544. //人员所在群组(嵌套)--返回群组的对象数组
  545. listGroupWithPerson:function(name, async){
  546. getOrgActions();
  547. var data = {"personList": getNameFlag(name)};
  548. var v = null;
  549. var cb = function(json){
  550. v = json.data;
  551. if (async && o2.typeOf(async)=="function") return async(v);
  552. return v;
  553. };
  554. var promise = orgActions.listGroupWithPerson(data, cb, null, !!async);
  555. return (!!async) ? promise : v;
  556. // var v = null;
  557. // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  558. // return v;
  559. },
  560. //群组是否拥有角色--返回true, false
  561. groupHasRole: function(name, role, async){
  562. getOrgActions();
  563. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  564. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  565. var v = false;
  566. var cb = function(json){
  567. v = json.data.value;
  568. if (async && o2.typeOf(async)=="function") return async(v);
  569. return v;
  570. };
  571. var promise = orgActions.groupHasRole(data, cb, null, !!async);
  572. return (!!async) ? promise : v;
  573. // var v = false;
  574. // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  575. // return v;
  576. },
  577. //角色***************
  578. //获取角色--返回角色的对象数组
  579. getRole: function(name, async){
  580. getOrgActions();
  581. var data = {"roleList": getNameFlag(name)};
  582. var v = null;
  583. var cb = function(json){
  584. v = json.data;
  585. v = (v && v.length===1) ? v[0] : v;
  586. if (async && o2.typeOf(async)=="function") return async(v);
  587. return v;
  588. };
  589. var promise = orgActions.listRole(data, cb, null, !!async);
  590. return (!!async) ? promise : v;
  591. // var v = null;
  592. // orgActions.listRole(data, function(json){v = json.data;}, null, false);
  593. // return (v && v.length===1) ? v[0] : v;
  594. },
  595. //人员所有角色(嵌套)--返回角色的对象数组
  596. listRoleWithPerson:function(name, async){
  597. getOrgActions();
  598. var data = {"personList": getNameFlag(name)};
  599. var v = null;
  600. var cb = function(json){
  601. v = json.data;
  602. if (async && o2.typeOf(async)=="function") return async(v);
  603. return v;
  604. };
  605. var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
  606. return (!!async) ? promise : v;
  607. // var v = null;
  608. // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  609. // return v;
  610. },
  611. //人员***************
  612. //人员是否拥有角色--返回true, false
  613. personHasRole: function(name, role, async){
  614. getOrgActions();
  615. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  616. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  617. var v = false;
  618. var cb = function(json){
  619. v = json.data.value;
  620. if (async && o2.typeOf(async)=="function") return async(v);
  621. return v;
  622. };
  623. var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
  624. return (!!async) ? promise : v;
  625. // var v = false;
  626. // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  627. // return v;
  628. },
  629. //获取人员--返回人员的对象数组
  630. getPerson: function(name, async){
  631. getOrgActions();
  632. var data = {"personList": getNameFlag(name)};
  633. var v = null;
  634. var cb = function(json){
  635. v = json.data;
  636. v = (v && v.length===1) ? v[0] : v;
  637. if (async && o2.typeOf(async)=="function") return async(v);
  638. return v;
  639. };
  640. var promise = orgActions.listPerson(data, cb, null, !!async);
  641. return (!!async) ? promise : v;
  642. // var v = null;
  643. // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  644. // return (v && v.length===1) ? v[0] : v;
  645. },
  646. //查询下级人员--返回人员的对象数组
  647. //nested 布尔 true嵌套下级;false直接下级;默认false;
  648. listSubPerson: function(name, nested, async){
  649. getOrgActions();
  650. var data = {"personList": getNameFlag(name)};
  651. var v = null;
  652. var cb = function(json){
  653. v = json.data;
  654. if (async && o2.typeOf(async)=="function") return async(v);
  655. return v;
  656. };
  657. var promise;
  658. if (nested){
  659. promise = orgActions.listPersonSubNested(data, cb, null, !!async);
  660. }else{
  661. promise = orgActions.listPersonSubDirect(data, cb, null, !!async);
  662. }
  663. return (!!async) ? promise : v;
  664. },
  665. //查询上级人员--返回人员的对象数组
  666. //nested 布尔 true嵌套上级;false直接上级;默认false;
  667. listSupPerson: function(name, nested, async){
  668. getOrgActions();
  669. var data = {"personList": getNameFlag(name)};
  670. var v = null;
  671. var cb = function(json){
  672. v = json.data;
  673. if (async && o2.typeOf(async)=="function") return async(v);
  674. return v;
  675. };
  676. var promise;
  677. if (nested){
  678. promise = orgActions.listPersonSupNested(data, cb, null, !!async);
  679. }else{
  680. promise = orgActions.listPersonSupDirect(data, cb, null, !!async);
  681. }
  682. return (!!async) ? promise : v;
  683. },
  684. //获取群组的所有人员--返回人员的对象数组
  685. listPersonWithGroup: function(name, async){
  686. getOrgActions();
  687. var data = {"groupList": getNameFlag(name)};
  688. var v = null;
  689. var cb = function(json){
  690. v = json.data;
  691. if (async && o2.typeOf(async)=="function") return async(v);
  692. return v;
  693. };
  694. var promise = orgActions.listPersonWithGroup(data, cb, null, !!async);
  695. return (!!async) ? promise : v;
  696. },
  697. //获取角色的所有人员--返回人员的对象数组
  698. listPersonWithRole: function(name, async){
  699. getOrgActions();
  700. var data = {"roleList": getNameFlag(name)};
  701. var v = null;
  702. var cb = function(json){
  703. v = json.data;
  704. if (async && o2.typeOf(async)=="function") return async(v);
  705. return v;
  706. };
  707. var promise
  708. promise = orgActions.listPersonWithRole(data, cb, null, !!async);
  709. return (!!async) ? promise : v;
  710. },
  711. //获取身份的所有人员--返回人员的对象数组
  712. listPersonWithIdentity: function(name, async){
  713. getOrgActions();
  714. var data = {"identityList": getNameFlag(name)};
  715. var v = null;
  716. var cb = function(json){
  717. v = json.data;
  718. if (async && o2.typeOf(async)=="function") return async(v);
  719. return v;
  720. };
  721. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  722. return (!!async) ? promise : v;
  723. },
  724. //获取身份的所有人员--返回人员的对象数组或人员对象
  725. getPersonWithIdentity: function(name, async){
  726. getOrgActions();
  727. var data = {"identityList": getNameFlag(name)};
  728. var v = null;
  729. var cb = function(json){
  730. v = json.data;
  731. v = (v && v.length===1) ? v[0] : v;
  732. if (async && o2.typeOf(async)=="function") return async(v);
  733. return v;
  734. };
  735. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  736. return (!!async) ? promise : v;
  737. },
  738. //查询组织成员的人员--返回人员的对象数组
  739. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  740. listPersonWithUnit: function(name, nested, async){
  741. getOrgActions();
  742. var data = {"unitList": getNameFlag(name)};
  743. var v = null;
  744. var cb = function(json){
  745. v = json.data;
  746. if (async && o2.typeOf(async)=="function") return async(v);
  747. return v;
  748. };
  749. var promise;
  750. if (nested){
  751. promise = orgActions.listPersonWithUnitNested(data, cb, null, !!async);
  752. }else{
  753. promise = orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
  754. }
  755. return (!!async) ? promise : v;
  756. },
  757. //根据属性查询人员--返回人员的对象数组
  758. //name string 属性名
  759. //value string 属性值
  760. listPersonWithAttribute: function(name, value, async){
  761. getOrgActions();
  762. var data = {"name": name, "attribute": value};
  763. var v = null;
  764. var cb = function(json){
  765. v = json.data;
  766. if (async && o2.typeOf(async)=="function") return async(v);
  767. return v;
  768. };
  769. var promise = orgActions.listPersonWithAttribute(data, cb, null, !!async);
  770. return (!!async) ? promise : v;
  771. },
  772. //根据属性查询人员--返回人员的全称数组
  773. //name string 属性名
  774. //value string 属性值
  775. listPersonNameWithAttribute: function(name, value, async){
  776. getOrgActions();
  777. var data = {"name": name, "attribute": value};
  778. var v = null;
  779. var cb = function(json){
  780. v = json.data.personList;
  781. if (async && o2.typeOf(async)=="function") return async(v);
  782. return v;
  783. };
  784. var promise = orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
  785. return (!!async) ? promise : v;
  786. },
  787. //人员属性************
  788. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  789. appendPersonAttribute: function(person, attr, values, success, failure, async){
  790. getOrgActions();
  791. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  792. var data = {"attributeList":values,"name":attr,"person":personFlag};
  793. var cb = function(json){
  794. if (success) return success(json);
  795. }.ag().catch(function(xhr, text, error){
  796. if (failure) return failure(xhr, text, error);
  797. });
  798. orgActions.appendPersonAttribute(data, cb, null, !!async);
  799. },
  800. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  801. setPersonAttribute: function(person, attr, values, success, failure, async){
  802. getOrgActions();
  803. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  804. var data = {"attributeList":values,"name":attr,"person":personFlag};
  805. var cb = function(json){
  806. if (success) return success(json);
  807. }.ag().catch(function(xhr, text, error){
  808. if (failure) return failure(xhr, text, error);
  809. });
  810. orgActions.setPersonAttribute(data, cb, null, !!async);
  811. },
  812. //获取人员属性值
  813. getPersonAttribute: function(person, attr, async){
  814. getOrgActions();
  815. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  816. var data = {"name":attr,"person":personFlag};
  817. var v = null;
  818. var cb = function(json){
  819. v = json.data.attributeList;
  820. if (async && o2.typeOf(async)=="function") return async(v);
  821. return v;
  822. };
  823. var promise = orgActions.getPersonAttribute(data, cb, null, !!async);
  824. return (!!async) ? promise : v;
  825. },
  826. //列出人员所有属性的名称
  827. listPersonAttributeName: function(name, async){
  828. getOrgActions();
  829. var data = {"personList":getNameFlag(name)};
  830. var v = null;
  831. var cb = function(json){
  832. v = json.data.nameList;
  833. if (async && o2.typeOf(async)=="function") return async(v);
  834. return v;
  835. };
  836. var promise = orgActions.listPersonAttributeName(data, cb, null, !!async);
  837. return (!!async) ? promise : v;
  838. },
  839. //列出人员的所有属性
  840. listPersonAllAttribute: function(name, async){
  841. getOrgActions();
  842. var data = {"personList":getNameFlag(name)};
  843. var v = null;
  844. var cb = function(json){
  845. v = json.data;
  846. if (async && o2.typeOf(async)=="function") return async(v);
  847. return v;
  848. };
  849. var promise = orgActions.listPersonAllAttribute(data, cb, null, !!async);
  850. return (!!async) ? promise : v;
  851. },
  852. //身份**********
  853. //获取身份
  854. getIdentity: function(name, async){
  855. getOrgActions();
  856. var data = {"identityList":getNameFlag(name)};
  857. var v = null;
  858. var cb = function(json){
  859. v = json.data;
  860. v = (v && v.length===1) ? v[0] : v;
  861. if (async && o2.typeOf(async)=="function") return async(v);
  862. return v;
  863. };
  864. var promise = orgActions.listIdentity(data, cb, null, !!async);
  865. return (!!async) ? promise : v;
  866. },
  867. //列出人员的身份
  868. listIdentityWithPerson: function(name, async){
  869. getOrgActions();
  870. var data = {"personList":getNameFlag(name)};
  871. var v = null;
  872. var cb = function(json){
  873. v = json.data;
  874. if (async && o2.typeOf(async)=="function") return async(v);
  875. return v;
  876. };
  877. var promise = orgActions.listIdentityWithPerson(data, cb, null, !!async);
  878. return (!!async) ? promise : v;
  879. },
  880. //查询组织成员身份--返回身份的对象数组
  881. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  882. listIdentityWithUnit: function(name, nested, async){
  883. getOrgActions();
  884. var data = {"unitList": getNameFlag(name)};
  885. var v = null;
  886. // var cb = function(json){
  887. // v = json.data;
  888. // if (async && o2.typeOf(async)=="function") return async(v);
  889. // return v;
  890. // }.ag().catch(function(json){ return json; });
  891. var cb = function(json){
  892. v = json.data;
  893. if (async && o2.typeOf(async)=="function") return async(v);
  894. return v;
  895. };
  896. var method = (nested) ? "listIdentityWithUnitNested" : "listIdentityWithUnitDirect";
  897. var promise = orgActions[method](data, cb, null, !!async);
  898. promise.name = "org";
  899. //
  900. // if (nested){
  901. // orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
  902. // }else{
  903. // orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
  904. // }
  905. return (!!async) ? promise : v;
  906. },
  907. //组织**********
  908. //获取组织
  909. getUnit: function(name, async){
  910. getOrgActions();
  911. var data = {"unitList":getNameFlag(name)};
  912. var v = null;
  913. var cb = function(json){
  914. v = json.data;
  915. v = (v && v.length===1) ? v[0] : v;
  916. if (async && o2.typeOf(async)=="function") return async(v);
  917. return v;
  918. };
  919. var promise = orgActions.listUnit(data, cb, null, !!async);
  920. return (!!async) ? promise : v;
  921. },
  922. //查询组织的下级--返回组织的对象数组
  923. //nested 布尔 true嵌套下级;false直接下级;默认false;
  924. listSubUnit: function(name, nested, async){
  925. getOrgActions();
  926. var data = {"unitList": getNameFlag(name)};
  927. var v = null;
  928. var cb = function(json){
  929. v = json.data;
  930. if (async && o2.typeOf(async)=="function") return async(v);
  931. return v;
  932. };
  933. var promise;
  934. if (nested){
  935. promise = orgActions.listUnitSubNested(data, cb, null, !!async);
  936. }else{
  937. promise = orgActions.listUnitSubDirect(data, cb, null, !!async);
  938. }
  939. return (!!async) ? promise : v;
  940. },
  941. //查询组织的上级--返回组织的对象数组
  942. //nested 布尔 true嵌套上级;false直接上级;默认false;
  943. //async 布尔 true异步请求
  944. listSupUnit: function(name, nested, async){
  945. getOrgActions();
  946. var data = {"unitList": getNameFlag(name)};
  947. var v = null;
  948. var cb = function(json){
  949. v = json.data;
  950. if (async && o2.typeOf(async)=="function") return async(v);
  951. return v;
  952. };
  953. var promise;
  954. if (nested){
  955. promise = orgActions.listUnitSupNested(data, cb, null, !!async);
  956. }else{
  957. promise = orgActions.listUnitSupDirect(data, cb, null, !!async);
  958. }
  959. return (!!async) ? promise : v;
  960. // if (callback){
  961. // if (nested){
  962. // orgActions.listUnitSupNested(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  963. // }else{
  964. // orgActions.listUnitSupDirect(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  965. // }
  966. // }else{
  967. // var v = null;
  968. // if (nested){
  969. // orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  970. // }else{
  971. // orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  972. // }
  973. // return v;
  974. // }
  975. },
  976. //根据个人身份获取组织
  977. //flag 数字 表示获取第几层的组织
  978. // 字符串 表示获取指定类型的组织
  979. // 空 表示获取直接所在的组织
  980. getUnitByIdentity: function(name, flag, async){
  981. getOrgActions();
  982. var getUnitMethod = "current";
  983. var v;
  984. if (flag){
  985. if (typeOf(flag)==="string") getUnitMethod = "type";
  986. if (typeOf(flag)==="number") getUnitMethod = "level";
  987. }
  988. var cb;
  989. var promise;
  990. switch (getUnitMethod){
  991. case "current":
  992. var data = {"identityList":getNameFlag(name)};
  993. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  994. // v = json.data; v=(v&&v.length===1) ? v[0] : v; return v;
  995. // }.ag().catch(function(json){ return json; });
  996. cb = function(json){
  997. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  998. if (async && o2.typeOf(async)=="function") return async(v);
  999. return v;
  1000. };
  1001. promise = orgActions.listUnitWithIdentity(data, cb, null, !!async);
  1002. break;
  1003. case "type":
  1004. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  1005. cb = function(json){
  1006. v = json.data;
  1007. if (async && o2.typeOf(async)=="function") return async(v);
  1008. return v;
  1009. };
  1010. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  1011. // v = json.data; return v;
  1012. // }.ag().catch(function(json){ return json; });
  1013. promise = orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
  1014. break;
  1015. case "level":
  1016. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  1017. cb = function(json){
  1018. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  1019. if (async && o2.typeOf(async)=="function") return async(v);
  1020. return v;
  1021. };
  1022. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  1023. // v = json.data; return v;
  1024. // }.ag().catch(function(json){ return json; });
  1025. promise = orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
  1026. break;
  1027. }
  1028. return (!!async) ? promise : v;
  1029. },
  1030. //列出身份所在组织的所有上级组织
  1031. listAllSupUnitWithIdentity: function(name, async){
  1032. getOrgActions();
  1033. var data = {"identityList":getNameFlag(name)};
  1034. var v = null;
  1035. var cb = function(json){
  1036. v = json.data;
  1037. if (async && o2.typeOf(async)=="function") return async(v);
  1038. return v;
  1039. };
  1040. var promise = orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
  1041. return (!!async) ? promise : v;
  1042. },
  1043. //获取人员所在的所有组织
  1044. listUnitWithPerson: function(name, async){
  1045. getOrgActions();
  1046. var data = {"personList":getNameFlag(name)};
  1047. var v = null;
  1048. var cb = function(json){
  1049. v = json.data;
  1050. if (async && o2.typeOf(async)=="function") return async(v);
  1051. return v;
  1052. };
  1053. var promise = orgActions.listUnitWithPerson(data, cb, null, !!async);
  1054. return (!!async) ? promise : v;
  1055. },
  1056. //列出人员所在组织的所有上级组织
  1057. listAllSupUnitWithPerson: function(name, async){
  1058. getOrgActions();
  1059. var data = {"personList":getNameFlag(name)};
  1060. var v = null;
  1061. var cb = function(json){
  1062. v = json.data;
  1063. if (async && o2.typeOf(async)=="function") return async(v);
  1064. return v;
  1065. };
  1066. var promise = orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
  1067. return (!!async) ? promise : v;
  1068. },
  1069. //根据组织属性,获取所有符合的组织
  1070. listUnitWithAttribute: function(name, attribute, async){
  1071. getOrgActions();
  1072. var data = {"name":name,"attribute":attribute};
  1073. var v = null;
  1074. var cb = function(json){
  1075. v = json.data;
  1076. if (async && o2.typeOf(async)=="function") return async(v);
  1077. return v;
  1078. };
  1079. promise = orgActions.listUnitWithAttribute(data, cb, null, !!async);
  1080. return (!!async) ? promise : v;
  1081. },
  1082. //根据组织职务,获取所有符合的组织
  1083. listUnitWithDuty: function(name, id, async){
  1084. getOrgActions();
  1085. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  1086. var v = null;
  1087. var cb = function(json){
  1088. v = json.data;
  1089. if (async && o2.typeOf(async)=="function") return async(v);
  1090. return v;
  1091. };
  1092. var promise = orgActions.listUnitWithDuty(data, cb, null, !!async);
  1093. return (!!async) ? promise : v;
  1094. },
  1095. //组织职务***********
  1096. //获取指定的组织职务的身份
  1097. getDuty: function(duty, id, async){
  1098. getOrgActions();
  1099. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  1100. var v = null;
  1101. var cb = function(json){
  1102. v = json.data;
  1103. if (async && o2.typeOf(async)=="function") return async(v);
  1104. return v;
  1105. };
  1106. var promise = orgActions.getDuty(data, cb, null, !!async);
  1107. return (!!async) ? promise : v;
  1108. },
  1109. //获取身份的所有职务名称
  1110. listDutyNameWithIdentity: function(name, async){
  1111. getOrgActions();
  1112. var data = {"identityList":getNameFlag(name)};
  1113. var v = null;
  1114. var cb = function(json){
  1115. v = json.data.nameList;
  1116. if (async && o2.typeOf(async)=="function") return async(v);
  1117. return v;
  1118. };
  1119. var promise = orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
  1120. return (!!async) ? promise : v;
  1121. },
  1122. //获取组织的所有职务名称
  1123. listDutyNameWithUnit: function(name, async){
  1124. getOrgActions();
  1125. var data = {"unitList":getNameFlag(name)};
  1126. var v = null;
  1127. var cb = function(json){
  1128. v = json.data.nameList;
  1129. if (async && o2.typeOf(async)=="function") return async(v);
  1130. return v;
  1131. };
  1132. var promise = orgActions.listDutyNameWithUnit(data, cb, null, !!async);
  1133. return (!!async) ? promise : v;
  1134. },
  1135. //获取组织的所有职务
  1136. listUnitAllDuty: function(name, async){
  1137. getOrgActions();
  1138. var data = {"unitList":getNameFlag(name)};
  1139. var v = null;
  1140. var cb = function(json){
  1141. v = json.data;
  1142. if (async && o2.typeOf(async)=="function") return async(v);
  1143. return v;
  1144. };
  1145. var promise = orgActions.listUnitAllDuty(data, cb, null, !!async);
  1146. return (!!async) ? promise : v;
  1147. },
  1148. //列出顶层组织
  1149. listTopUnit: function(async){
  1150. var action = MWF.Actions.get("x_organization_assemble_control");
  1151. var v = null;
  1152. var cb = function(json){
  1153. v = json.data;
  1154. if (async && o2.typeOf(async)=="function") return async(v);
  1155. return v;
  1156. };
  1157. var promise = action.listTopUnit(cb, null, !!async);
  1158. return (!!async) ? promise : v;
  1159. },
  1160. //组织属性**************
  1161. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  1162. appendUnitAttribute: function(unit, attr, values, success, failure, async){
  1163. getOrgActions();
  1164. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1165. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  1166. var cb = function(json){
  1167. if (success) return success(json);
  1168. }.ag().catch(function(xhr, text, error){
  1169. if (failure) return failure(xhr, text, error);
  1170. });
  1171. orgActions.appendPersonAttribute(data, cb, null, !!async);
  1172. // orgActions.appendUnitAttribute(data, function(json){
  1173. // if (json.data.value){
  1174. // if (success) success();
  1175. // }else{
  1176. // if (failure) failure(null, "", "append values failed");
  1177. // }
  1178. // }, function(xhr, text, error){
  1179. // if (failure) failure(xhr, text, error);
  1180. // }, false);
  1181. },
  1182. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  1183. setUnitAttribute: function(unit, attr, values, success, failure, async){
  1184. getOrgActions();
  1185. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1186. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  1187. var cb = function(json){
  1188. if (success) return success(json);
  1189. }.ag().catch(function(xhr, text, error){
  1190. if (failure) return failure(xhr, text, error);
  1191. });
  1192. orgActions.setUnitAttribute(data, cb, null, !!async);
  1193. // orgActions.setUnitAttribute(data, function(json){
  1194. // if (json.data.value){
  1195. // if (success) success();
  1196. // }else{
  1197. // if (failure) failure(null, "", "append values failed");
  1198. // }
  1199. // }, function(xhr, text, error){
  1200. // if (failure) failure(xhr, text, error);
  1201. // }, false);
  1202. },
  1203. //获取组织属性值
  1204. getUnitAttribute: function(unit, attr, async){
  1205. getOrgActions();
  1206. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1207. var data = {"name":attr,"unit":unitFlag};
  1208. var v = null;
  1209. var cb = function(json){
  1210. v = json.data.attributeList;
  1211. if (async && o2.typeOf(async)=="function") return async(v);
  1212. return v;
  1213. };
  1214. var promise = orgActions.getUnitAttribute(data, cb, null, !!async);
  1215. return (!!async) ? promise : v;
  1216. },
  1217. //列出组织所有属性的名称
  1218. listUnitAttributeName: function(name, async){
  1219. getOrgActions();
  1220. var data = {"unitList":getNameFlag(name)};
  1221. var v = null;
  1222. var cb = function(json){
  1223. v = json.data.nameList;
  1224. if (async && o2.typeOf(async)=="function") return async(v);
  1225. return v;
  1226. };
  1227. var promise = orgActions.listUnitAttributeName(data, cb, null, !!async);
  1228. return (!!async) ? promise : v;
  1229. },
  1230. //列出组织的所有属性
  1231. listUnitAllAttribute: function(name, async){
  1232. getOrgActions();
  1233. var data = {"unitList":getNameFlag(name)};
  1234. var v = null;
  1235. var cb = function(json){
  1236. v = json.data;
  1237. if (async && o2.typeOf(async)=="function") return async(v);
  1238. return v;
  1239. };
  1240. var promise = orgActions.listUnitAllAttribute(data, cb, null, !!async);
  1241. return (!!async) ? promise : v;
  1242. }
  1243. };
  1244. this.Action = (function(){
  1245. var actions = [];
  1246. return function(root, json){
  1247. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  1248. action.getActions = function(callback){
  1249. if (!this.actions) this.actions = {};
  1250. Object.merge(this.actions, json);
  1251. if (callback) callback();
  1252. };
  1253. this.invoke = function(option){
  1254. action.invoke(option)
  1255. }
  1256. }
  1257. })();
  1258. this.service = {
  1259. "jaxwsClient":{},
  1260. "jaxrsClient":{}
  1261. };
  1262. var lookupAction = null;
  1263. var getLookupAction = function(callback){
  1264. if (!lookupAction){
  1265. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  1266. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  1267. lookupAction.getActions = function(actionCallback){
  1268. this.actions = {
  1269. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  1270. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  1271. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  1272. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  1273. };
  1274. if (actionCallback) actionCallback();
  1275. };
  1276. if (callback) callback();
  1277. });
  1278. }else{
  1279. if (callback) callback();
  1280. }
  1281. };
  1282. this.view = {
  1283. "lookup": function(view, callback, async){
  1284. var filterList = {"filterList": (view.filter || null)};
  1285. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function(json){
  1286. var data = {
  1287. "grid": json.data.grid || json.data.groupGrid,
  1288. "groupGrid": json.data.groupGrid
  1289. };
  1290. if (callback) callback(data);
  1291. }, null, async);
  1292. },
  1293. "lookupV1": function(view, callback){
  1294. getLookupAction(function(){
  1295. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  1296. var data = {
  1297. "grid": json.data.grid,
  1298. "groupGrid": json.data.groupGrid
  1299. };
  1300. if (callback) callback(data);
  1301. }.bind(this)});
  1302. }.bind(this));
  1303. },
  1304. "select": function(view, callback, options){
  1305. if (view.view){
  1306. var viewJson = {
  1307. "application": view.application || _form.json.application,
  1308. "viewName": view.view || "",
  1309. "isTitle": (view.isTitle===false) ? "no" : "yes",
  1310. "select": (view.isMulti===false) ? "single" : "multi",
  1311. "filter": view.filter
  1312. };
  1313. if (!options) options = {};
  1314. options.width = view.width;
  1315. options.height = view.height;
  1316. options.title = view.caption;
  1317. var width = options.width || "700";
  1318. var height = options.height || "400";
  1319. if (layout.mobile){
  1320. var size = document.body.getSize();
  1321. width = size.x;
  1322. height = size.y;
  1323. options.style = "viewmobile";
  1324. }
  1325. width = width.toInt();
  1326. height = height.toInt();
  1327. var size = _form.app.content.getSize();
  1328. var x = (size.x-width)/2;
  1329. var y = (size.y-height)/2;
  1330. if (x<0) x = 0;
  1331. if (y<0) y = 0;
  1332. if (layout.mobile){
  1333. x = 20;
  1334. y = 0;
  1335. }
  1336. var _self = this;
  1337. MWF.require("MWF.xDesktop.Dialog", function(){
  1338. var dlg = new MWF.xDesktop.Dialog({
  1339. "title": options.title || "select view",
  1340. "style": options.style || "view",
  1341. "top": y,
  1342. "left": x-20,
  1343. "fromTop":y,
  1344. "fromLeft": x-20,
  1345. "width": width,
  1346. "height": height,
  1347. "html": "<div style='height: 100%;'></div>",
  1348. "maskNode": _form.app.content,
  1349. "container": _form.app.content,
  1350. "buttonList": [
  1351. {
  1352. "text": MWF.LP.process.button.ok,
  1353. "action": function(){
  1354. //if (callback) callback(_self.view.selectedItems);
  1355. if (callback) callback(_self.view.getData());
  1356. this.close();
  1357. }
  1358. },
  1359. {
  1360. "text": MWF.LP.process.button.cancel,
  1361. "action": function(){this.close();}
  1362. }
  1363. ]
  1364. });
  1365. dlg.show();
  1366. if (layout.mobile){
  1367. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1368. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1369. if (backAction) backAction.addEvent("click", function(e){
  1370. dlg.close();
  1371. }.bind(this));
  1372. if (okAction) okAction.addEvent("click", function(e){
  1373. //if (callback) callback(this.view.selectedItems);
  1374. if (callback) callback(this.view.getData());
  1375. dlg.close();
  1376. }.bind(this));
  1377. }
  1378. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  1379. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"}, _form.app, _form.Macro);
  1380. }.bind(this));
  1381. }.bind(this));
  1382. }
  1383. }
  1384. };
  1385. this.statement = {
  1386. "execute": function (statement, callback, async) {
  1387. var parameter = this.parseParameter(statement.parameter);
  1388. var filterList = this.parseFilter(statement.filter, parameter);
  1389. var obj = {
  1390. "filterList": filterList,
  1391. "parameter" : parameter
  1392. };
  1393. MWF.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  1394. statement.name, statement.mode || "data", statement.page || 1, statement.pageSize || 20, obj,
  1395. function (json) {
  1396. if (callback) callback(json);
  1397. }, null, async);
  1398. },
  1399. parseFilter : function( filter, parameter ){
  1400. if( typeOf(filter) !== "array" )return [];
  1401. var filterList = [];
  1402. ( filter || [] ).each( function (d) {
  1403. var parameterName = d.path.replace(/\./g, "_");
  1404. var value = d.value;
  1405. if( d.comparison === "like" || d.comparison === "notLike" ){
  1406. if( value.substr(0, 1) !== "%" )value = "%"+value;
  1407. if( value.substr(value.length-1,1) !== "%" )value = value+"%";
  1408. parameter[ parameterName ] = value; //"%"+value+"%";
  1409. }else{
  1410. if( d.formatType === "dateTimeValue" || d.formatType === "datetimeValue"){
  1411. value = "{ts '"+value+"'}"
  1412. }else if( d.formatType === "dateValue" ){
  1413. value = "{d '"+value+"'}"
  1414. }else if( d.formatType === "timeValue" ){
  1415. value = "{t '"+value+"'}"
  1416. }
  1417. parameter[ parameterName ] = value;
  1418. }
  1419. d.value = parameterName;
  1420. filterList.push( d );
  1421. }.bind(this));
  1422. return filterList;
  1423. },
  1424. parseParameter : function( obj ){
  1425. if( typeOf(obj) !== "object" )return {};
  1426. var parameter = {};
  1427. //传入的参数
  1428. for( var p in obj ){
  1429. var value = obj[p];
  1430. if( typeOf( value ) === "date" ){
  1431. value = "{ts '"+value.format("db")+"'}"
  1432. }
  1433. parameter[ p ] = value;
  1434. }
  1435. return parameter;
  1436. },
  1437. "select": function (statement, callback, options) {
  1438. if (statement.name) {
  1439. // var parameter = this.parseParameter(statement.parameter);
  1440. // var filterList = this.parseFilter(statement.filter, parameter);
  1441. var statementJson = {
  1442. "statementId": statement.name || "",
  1443. "isTitle": (statement.isTitle === false) ? "no" : "yes",
  1444. "select": (statement.isMulti === false) ? "single" : "multi",
  1445. "filter": statement.filter,
  1446. "parameter": statement.parameter
  1447. };
  1448. if (!options) options = {};
  1449. options.width = statement.width;
  1450. options.height = statement.height;
  1451. options.title = statement.caption;
  1452. var width = options.width || "700";
  1453. var height = options.height || "400";
  1454. if (layout.mobile) {
  1455. var size = document.body.getSize();
  1456. width = size.x;
  1457. height = size.y;
  1458. options.style = "viewmobile";
  1459. }
  1460. width = width.toInt();
  1461. height = height.toInt();
  1462. var size = _form.app.content.getSize();
  1463. var x = (size.x - width) / 2;
  1464. var y = (size.y - height) / 2;
  1465. if (x < 0) x = 0;
  1466. if (y < 0) y = 0;
  1467. if (layout.mobile) {
  1468. x = 20;
  1469. y = 0;
  1470. }
  1471. var _self = this;
  1472. MWF.require("MWF.xDesktop.Dialog", function () {
  1473. var dlg = new MWF.xDesktop.Dialog({
  1474. "title": options.title || "select statement view",
  1475. "style": options.style || "view",
  1476. "top": y,
  1477. "left": x - 20,
  1478. "fromTop": y,
  1479. "fromLeft": x - 20,
  1480. "width": width,
  1481. "height": height,
  1482. "html": "<div style='height: 100%;'></div>",
  1483. "maskNode": _form.app.content,
  1484. "container": _form.app.content,
  1485. "buttonList": [
  1486. {
  1487. "text": MWF.LP.process.button.ok,
  1488. "action": function () {
  1489. //if (callback) callback(_self.view.selectedItems);
  1490. if (callback) callback(_self.statement.getData());
  1491. this.close();
  1492. }
  1493. },
  1494. {
  1495. "text": MWF.LP.process.button.cancel,
  1496. "action": function () { this.close(); }
  1497. }
  1498. ]
  1499. });
  1500. dlg.show();
  1501. if (layout.mobile) {
  1502. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1503. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1504. if (backAction) backAction.addEvent("click", function (e) {
  1505. dlg.close();
  1506. }.bind(this));
  1507. if (okAction) okAction.addEvent("click", function (e) {
  1508. //if (callback) callback(this.view.selectedItems);
  1509. if (callback) callback(this.statement.getData());
  1510. dlg.close();
  1511. }.bind(this));
  1512. }
  1513. MWF.xDesktop.requireApp("query.Query", "Statement", function () {
  1514. this.statement = new MWF.xApplication.query.Query.Statement(dlg.content.getFirst(), statementJson, { "style": "select" }, _form.app, _form.Macro);
  1515. }.bind(this));
  1516. }.bind(this));
  1517. }
  1518. }
  1519. };
  1520. //include 引用脚本
  1521. //optionsOrName : {
  1522. // type : "", 默认为process, 可以为 portal process cms
  1523. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  1524. // name : "" // 脚本名称/别名/id
  1525. //}
  1526. //或者name: "" // 脚本名称/别名/id
  1527. // if( !window.includedScripts ){
  1528. // var includedScripts = window.includedScripts = [];
  1529. // }else{
  1530. // var includedScripts = window.includedScripts;
  1531. // }
  1532. var includedScripts = [];
  1533. var _includeSingle = function( optionsOrName , callback, async){
  1534. var options = optionsOrName;
  1535. if( typeOf( options ) == "string" ){
  1536. options = { name : options };
  1537. }
  1538. var name = options.name;
  1539. var type = ( options.type && options.application ) ? options.type : "process";
  1540. var application = options.application || _form.json.application;
  1541. var key = type +"-" + application + "-" + name;
  1542. if (includedScripts.indexOf( key )> -1){
  1543. if (callback) callback.apply(this);
  1544. return;
  1545. }
  1546. //if (includedScripts.indexOf( name )> -1){
  1547. // if (callback) callback.apply(this);
  1548. // return;
  1549. //}
  1550. var scriptAction;
  1551. switch ( type ){
  1552. case "portal" :
  1553. if( this.scriptActionPortal ){
  1554. scriptAction = this.scriptActionPortal;
  1555. }else{
  1556. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  1557. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  1558. }
  1559. break;
  1560. case "process" :
  1561. if( this.scriptActionProcess ){
  1562. scriptAction = this.scriptActionProcess;
  1563. }else{
  1564. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  1565. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  1566. }
  1567. break;
  1568. case "cms" :
  1569. if( this.scriptActionCMS ){
  1570. scriptAction = this.scriptActionCMS;
  1571. }else{
  1572. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1573. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  1574. }
  1575. break;
  1576. }
  1577. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  1578. if (json.data){
  1579. includedScripts.push( key );
  1580. //名称、别名、id
  1581. json.data.importedList.each( function ( flag ) {
  1582. if( type === "portal" ){
  1583. includedScripts.push( type + "-" + json.data.portal + "-" + flag );
  1584. if( json.data.portalName )includedScripts.push( type + "-" + json.data.portalName + "-" + flag );
  1585. if( json.data.portalAlias )includedScripts.push( type + "-" + json.data.portalAlias + "-" + flag );
  1586. }else if( type === "cms" ){
  1587. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  1588. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1589. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1590. }else if( type === "process" ){
  1591. includedScripts.push( type + "-" + json.data.application + "-" + flag );
  1592. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1593. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1594. }
  1595. });
  1596. includedScripts = includedScripts.concat(json.data.importedList);
  1597. MWF.Macro.exec(json.data.text, this);
  1598. if (callback) callback.apply(this);
  1599. }else{
  1600. if (callback) callback.apply(this);
  1601. }
  1602. }.bind(this), null, !!async);
  1603. }
  1604. this.include = function( optionsOrName , callback, async){
  1605. if (o2.typeOf(optionsOrName)=="array"){
  1606. if (!!async){
  1607. var count = optionsOrName.length;
  1608. var loaded = 0;
  1609. optionsOrName.each(function(option){
  1610. _includeSingle.apply(this, [option, function(){
  1611. loaded++;
  1612. if (loaded>=count) if (callback) callback.apply(this);;
  1613. }.bind(this), true]);
  1614. }.bind(this));
  1615. }else{
  1616. optionsOrName.each(function(option){
  1617. _includeSingle.apply(this, [option]);
  1618. }.bind(this));
  1619. if (callback) callback.apply(this);
  1620. }
  1621. }else{
  1622. _includeSingle.apply(this, [optionsOrName , callback, async])
  1623. }
  1624. };
  1625. this.define = function(name, fun, overwrite){
  1626. var over = true;
  1627. if (overwrite===false) over = false;
  1628. var o = {};
  1629. o[name] = {"value": fun, "configurable": over};
  1630. MWF.defineProperties(this, o);
  1631. }.bind(this);
  1632. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  1633. //可在调用前执行 var resolve = this.wait();
  1634. //在异步调用结束后 执行 resolve.cb();
  1635. //目前只有表单的queryload事件支持此方法。
  1636. this.wait = function(){
  1637. var _self = this;
  1638. resolve = {"cb": _self.goon.bind(_self)};
  1639. var setResolve = function(callback){
  1640. resolve.cb = callback;
  1641. }.bind(this);
  1642. this.target.event_resolve = setResolve;
  1643. return resolve;
  1644. }
  1645. //和this.wait配合使用,
  1646. //如果没有异步,则resolve.cb方法不存在,
  1647. //所以在回调中中使用this.goon();使表单继续加载
  1648. this.goon = function(){
  1649. this.target.event_resolve = null;
  1650. }
  1651. //仅前台对象-----------------------------------------
  1652. //form
  1653. this.page = this.form = {
  1654. "getInfor": function(){return ev.formInfor;},
  1655. "infor": ev.formInfor,
  1656. "getApp": function(){return _form.app;},
  1657. "app": _form.app,
  1658. "node": function(){return _form.node;},
  1659. "readonly": _form.options.readonly,
  1660. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  1661. "getField": function(name){return _forms[name];},
  1662. "getAction": function(){return _form.workAction},
  1663. "getDesktop": function(){return _form.app.desktop},
  1664. "getData": function(){return new MWF.xScript.JSONData(_form.getData());},
  1665. "save": function(callback, silent){_form.saveWork(callback, silent); },
  1666. "close": function(){_form.closeWork();},
  1667. "verify": function(){
  1668. return !(!_form.formCustomValidation("", "") || !_form.formValidation("", ""));
  1669. },
  1670. "process": function(option){
  1671. var op = _form.getOpinion();
  1672. var mds = op.medias;
  1673. if (option){
  1674. _form.submitWork(option.routeName, option.opinion, mds, option.callback,
  1675. option.processor, null, option.appendTaskIdentityList, option.processorOrgList, option.callbackBeforeSave );
  1676. }else{
  1677. _form.processWork();
  1678. }
  1679. },
  1680. "reset": function(option){
  1681. if (!option){
  1682. if (_form.businessData.control["allowReset"]) _form.resetWork();
  1683. }else{
  1684. _form.resetWorkToPeson(option.names, option.opinion, option.keep, option.success, option.failure);
  1685. }
  1686. },
  1687. "retract": function(option){
  1688. if (!option){
  1689. if (_form.businessData.control["allowAddSplit"]) _form.addSplit();
  1690. }else{
  1691. _form.doRetractWork(option.success, option.failure);
  1692. }
  1693. },
  1694. "addSplit": function(option){
  1695. if (!option){
  1696. if (_form.businessData.control["allowRetract"]) _form.retractWork();
  1697. }else{
  1698. _form.addSplitWork(option.value, option.success, option.failure);
  1699. }
  1700. },
  1701. "rollback": function(option){
  1702. if (!option){
  1703. if (_form.businessData.control["allowRollback"]) _form.rollback();
  1704. }else{
  1705. _form.doRollbackActionInvoke(option.log, option.flow, option.success, option.failure);
  1706. }
  1707. },
  1708. "print": function(application, form){
  1709. if (arguments.length){
  1710. var app = (arguments.length>1) ? arguments[0] : null;
  1711. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1712. _form.printWork(app, formName);
  1713. }else{
  1714. _form.printWork();
  1715. }
  1716. },
  1717. "deleteWork": function(option){
  1718. if (!option){
  1719. if (_form.businessData.control["allowDelete"]) _form.deleteWork();
  1720. }else{
  1721. _form.doDeleteWork(option.success, option.failure);
  1722. }
  1723. },
  1724. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  1725. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  1726. var p = MWF.getCenter({"x": width, "y": height});
  1727. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1728. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1729. }else{
  1730. e = (arguments.length>1) ? arguments[1] : null;
  1731. title = (arguments.length>2) ? arguments[2] : null;
  1732. text = (arguments.length>3) ? arguments[3] : null;
  1733. width = (arguments.length>4) ? arguments[4] : null;
  1734. height = (arguments.length>5) ? arguments[5] : null;
  1735. ok = (arguments.length>6) ? arguments[6] : null;
  1736. cancel = (arguments.length>7) ? arguments[7] : null;
  1737. callback = (arguments.length>8) ? arguments[8] : null;
  1738. mask = (arguments.length>9) ? arguments[9] : null;
  1739. style = (arguments.length>10) ? arguments[10] : null;
  1740. // var p = MWF.getCenter({"x": width, "y": height});
  1741. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1742. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1743. }
  1744. },
  1745. "alert": function(type, title, text, width, height){
  1746. _form.alert(type, title, text, width, height);
  1747. },
  1748. "notice": function(content, type, target, where, offset, option){
  1749. _form.notice(content, type, target, where, offset, option);
  1750. },
  1751. "addEvent": function(e, f){_form.addEvent(e, f);},
  1752. "openWindow": function(application, form){
  1753. if (arguments.length){
  1754. var app = (arguments.length>1) ? arguments[0] : null;
  1755. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1756. _form.openWindow(formName, app);
  1757. }else{
  1758. _form.openWindow();
  1759. }
  1760. },
  1761. "openWork": function(id, completedId, title, options){
  1762. var op = options || {};
  1763. op.workId = id;
  1764. op.workCompletedId = completedId;
  1765. op.docTitle = title;
  1766. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1767. return layout.desktop.openApplication(this.event, "process.Work", op);
  1768. },
  1769. "openJob": function(id, choice, options){
  1770. var workData = null;
  1771. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  1772. if (json.data) workData = json.data;
  1773. }.bind(this), null, false);
  1774. if (workData){
  1775. var len = workData.workList.length + workData.workCompletedList.length;
  1776. if (len){
  1777. if (len>1 && choice){
  1778. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  1779. workData.workList.each(function(work){
  1780. var workNode = new Element("div", {
  1781. "styles": {
  1782. "background": "#ffffff",
  1783. "border-radius": "10px",
  1784. "clear": "both",
  1785. "margin-bottom": "10px",
  1786. "height": "40px",
  1787. "padding": "10px 10px"
  1788. }
  1789. }).inject(node);
  1790. 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>" +
  1791. "<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>"+
  1792. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1793. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  1794. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  1795. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  1796. workNode.set("html", html);
  1797. var action = workNode.getElement(".MWFAction");
  1798. action.store("work", work);
  1799. action.addEvent("click", function(e){
  1800. var work = e.target.retrieve("work");
  1801. if (work) this.openWork(work.id, null, work.title, options);
  1802. dlg.close();
  1803. }.bind(this));
  1804. }.bind(this));
  1805. workData.workCompletedList.each(function(work){
  1806. var workNode = new Element("div", {
  1807. "styles": {
  1808. "background": "#ffffff",
  1809. "border-radius": "10px",
  1810. "clear": "both",
  1811. "margin-bottom": "10px",
  1812. "height": "40px",
  1813. "padding": "10px 10px"
  1814. }
  1815. }).inject(node);
  1816. 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>" +
  1817. "<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>"+
  1818. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1819. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  1820. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  1821. workNode.set("html", html);
  1822. var action = workNode.getElement(".MWFAction");
  1823. action.store("work", work);
  1824. action.addEvent("click", function(e){
  1825. var work = e.target.retrieve("work");
  1826. if (work) this.openWork(null, work.id, work.title, options);
  1827. dlg.close();
  1828. }.bind(this));
  1829. }.bind(this));
  1830. var height = node.getSize().y+20;
  1831. if (height>600) height = 600;
  1832. var dlg = o2.DL.open({
  1833. "title": o2.LP.widget.choiceWork,
  1834. "style" : "user",
  1835. "isResize": false,
  1836. "content": node,
  1837. "buttonList": [
  1838. {
  1839. "type" : "cancel",
  1840. "text": o2.LP.widget.close,
  1841. "action": function(){dlg.close();}
  1842. }
  1843. ]
  1844. });
  1845. }else{
  1846. if (workData.workList.length){
  1847. var work = workData.workList[0];
  1848. return this.openWork(work.id, null, work.title, options);
  1849. }else{
  1850. var work = workData.workCompletedList[0];
  1851. return this.openWork(null, work.id, work.title, options);
  1852. }
  1853. }
  1854. }
  1855. }
  1856. // var op = options || {};
  1857. // op.workId = id;
  1858. // op.workCompletedId = completedId;
  1859. // op.docTitle = title;
  1860. // op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1861. // layout.desktop.openApplication(this.event, "process.Work", op);
  1862. },
  1863. "openDocument": function(id, title, options){
  1864. var op = options || {};
  1865. op.documentId = id;
  1866. op.docTitle = title;
  1867. layout.desktop.openApplication(this.event, "cms.Document", op);
  1868. },
  1869. "openPortal": function(name, page, par){
  1870. var action = MWF.Actions.get("x_portal_assemble_surface");
  1871. action.getApplication(name, function(json){
  1872. if (json.data){
  1873. if (page){
  1874. action.getPageByName(page, json.data.id, function(pageJson){
  1875. layout.desktop.openApplication(null, "portal.Portal", {
  1876. "portalId": json.data.id,
  1877. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1878. "parameters": par,
  1879. "appId": (par && par.appId) || ("portal.Portal" + json.data.id + ( pageJson.data.id || "" ))
  1880. })
  1881. });
  1882. }else{
  1883. layout.desktop.openApplication(null, "portal.Portal", {
  1884. "portalId": json.data.id,
  1885. "parameters": par,
  1886. "appId": (par && par.appId) || ("portal.Portal" + json.data.id)
  1887. })
  1888. }
  1889. }
  1890. });
  1891. },
  1892. "openCMS": function(name){
  1893. var action = MWF.Actions.get("x_cms_assemble_control");
  1894. action.getColumn(name, function(json){
  1895. if (json.data){
  1896. layout.desktop.openApplication(null, "cms.Module", {
  1897. "columnId": json.data.id,
  1898. "appId": "cms.Module"+json.data.id
  1899. });
  1900. }
  1901. });
  1902. },
  1903. "openProcess": function(name){
  1904. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1905. action.getApplication(name, function(json){
  1906. if (json.data){
  1907. layout.desktop.openApplication(null, "process.Application", {
  1908. "id": json.data.id,
  1909. "appId": "process.Application"+json.data.id
  1910. });
  1911. }
  1912. });
  1913. },
  1914. "openApplication":function(name, options){
  1915. layout.desktop.openApplication(null, name, options);
  1916. },
  1917. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  1918. var column = columnOrOptions;
  1919. var onAfterPublish, onPostPublish;
  1920. if (typeOf(columnOrOptions) == "object") {
  1921. column = columnOrOptions.column;
  1922. category = columnOrOptions.category;
  1923. data = columnOrOptions.data;
  1924. identity = columnOrOptions.identity;
  1925. callback = columnOrOptions.callback;
  1926. target = columnOrOptions.target;
  1927. latest = columnOrOptions.latest;
  1928. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1929. ignoreTitle = columnOrOptions.ignoreTitle;
  1930. onAfterPublish = columnOrOptions.onAfterPublish;
  1931. onPostPublish = columnOrOptions.onPostPublish;
  1932. }
  1933. if (target) {
  1934. if (layout.app && layout.app.inBrowser) {
  1935. layout.app.content.empty();
  1936. layout.app = null;
  1937. }
  1938. }
  1939. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  1940. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1941. "documentData": data,
  1942. "identity": identity,
  1943. "ignoreTitle": ignoreTitle === true,
  1944. "ignoreDrafted": latest === false,
  1945. "selectColumnEnable": !category || selectColumnEnable === true,
  1946. "restrictToColumn": !!category && selectColumnEnable !== true,
  1947. "categoryFlag": category, //category id or name
  1948. "columnFlag": column, //column id or name,
  1949. "onStarted": function (documentId, data) {
  1950. if (callback) callback();
  1951. },
  1952. "onPostPublish": function () {
  1953. if(onPostPublish)onPostPublish();
  1954. },
  1955. "onAfterPublish": function () {
  1956. if(onAfterPublish)onAfterPublish();
  1957. }
  1958. });
  1959. starter.load();
  1960. })
  1961. },
  1962. "startProcess": function(app, process, data, identity, callback, target, latest){
  1963. if (arguments.length>2){
  1964. for (var i=2; i<arguments.length; i++){
  1965. if (typeOf(arguments[i])=="boolean"){
  1966. target = arguments[i];
  1967. break;
  1968. }
  1969. }
  1970. }
  1971. if (target){
  1972. if (layout.app && layout.app.inBrowser){
  1973. //layout.app.content.empty();
  1974. layout.app.$openWithSelf = true;
  1975. }
  1976. }
  1977. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1978. if (json.data){
  1979. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1980. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1981. "workData": data,
  1982. "identity": identity,
  1983. "latest": latest,
  1984. "onStarted": function(data, title, processName){
  1985. if (data.work){
  1986. var work = data.work;
  1987. var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
  1988. layout.desktop.openApplication(null, "process.Work", options);
  1989. }else{
  1990. var currentTask = [];
  1991. data.each(function(work){
  1992. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1993. }.bind(this));
  1994. if (currentTask.length==1){
  1995. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1996. layout.desktop.openApplication(null, "process.Work", options);
  1997. }else{}
  1998. }
  1999. if (callback) callback(data);
  2000. }.bind(this)
  2001. });
  2002. starter.load();
  2003. }.bind(this));
  2004. }
  2005. });
  2006. }
  2007. };
  2008. this.form.currentRouteName = _form.json.currentRouteName;
  2009. this.form.opinion = _form.json.opinion;
  2010. this.target = ev.target;
  2011. this.event = ev.event;
  2012. this.status = ev.status;
  2013. this.session = layout.desktop.session;
  2014. this.Actions = o2.Actions;
  2015. this.query = function(option){
  2016. // options = {
  2017. // "name": "statementName",
  2018. // "data": "json data",
  2019. // "firstResult": 1,
  2020. // "maxResults": 100,
  2021. // "success": function(){},
  2022. // "error": function(){},
  2023. // "async": true or false, default is true
  2024. // }
  2025. if (option){
  2026. var json = (option.data) || {};
  2027. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  2028. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  2029. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  2030. }
  2031. }
  2032. this.Table = MWF.xScript.createTable();
  2033. };
  2034. MWF.xScript.createTable = function(){
  2035. return function(name){
  2036. this.name = name;
  2037. this.action = o2.Actions.get("x_query_assemble_surface");
  2038. this.listRowNext = function(id, count, success, error, async){
  2039. this.action.listRowNext(this.name, id, count, success, error, async);
  2040. };
  2041. this.listRowPrev = function(id, count, success, error, async){
  2042. this.action.listRowPrev(this.name, id, count, success, error, async);
  2043. };
  2044. this.listRowPrev = function(id, count, success, error, async){
  2045. this.action.listRowPrev(this.name, id, count, success, error, async);
  2046. };
  2047. this.listRowSelectWhere = function(where, success, error, async){
  2048. this.action.listRowSelectWhere(this.name, where, success, error, async);
  2049. };
  2050. this.listRowCountWhere = function(where, success, error, async){
  2051. this.action.listRowCountWhere(this.name, where, success, error, async);
  2052. };
  2053. this.deleteRow = function(id, success, error, async){
  2054. this.action.deleteRow(this.name, id, success, error, async);
  2055. };
  2056. this.deleteAllRow = function(success, error, async){
  2057. this.action.deleteAllRow(this.name, success, error, async);
  2058. };
  2059. this.getRow = function(id, success, error, async){
  2060. this.action.getRow(this.name, id, success, error, async);
  2061. };
  2062. this.insertRow = function(data, success, error, async){
  2063. this.action.insertRow(this.name, data, success, error, async);
  2064. };
  2065. this.updateRow = function(id, data, success, error, async){
  2066. this.action.updateRow(this.name, id, data, success, error, async);
  2067. };
  2068. }
  2069. };
  2070. MWF.xScript.JSONData = function(data, callback, key, parent, _form){
  2071. var getter = function(data, callback, k, _self){
  2072. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self, _form);};
  2073. };
  2074. var setter = function(data, callback, k, _self){
  2075. return function(v){
  2076. data[k] = v;
  2077. //debugger;
  2078. //this.add(k, v, true);
  2079. if (callback) callback(data, k, _self);
  2080. }
  2081. };
  2082. var define = function(){
  2083. var o = {};
  2084. 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])};
  2085. o["length"] = {"get": function(){return Object.keys(data).length;}};
  2086. o["some"] = {"get": function(){return data.some;}};
  2087. MWF.defineProperties(this, o);
  2088. var methods = {
  2089. "getKey": {"value": function(){ return key; }},
  2090. "getParent": {"value": function(){ return parent; }},
  2091. "toString": {"value": function() { return data.toString();}},
  2092. "setSection": {"value": function(newKey, newValue){
  2093. this.add(newKey, newValue, true);
  2094. try {
  2095. var path = [this.getKey()];
  2096. p = this.getParent();
  2097. while (p && p.getKey()){
  2098. path.unshift(p.getKey());
  2099. p = p.getParent();
  2100. }
  2101. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  2102. }catch(e){
  2103. }
  2104. }},
  2105. "add": {"value": function(newKey, newValue, overwrite){
  2106. var flag = true;
  2107. var type = typeOf(data);
  2108. if (type==="array"){
  2109. if (arguments.length<2){
  2110. data.push(newKey);
  2111. newValue = newKey;
  2112. newKey = data.length-1;
  2113. }else{
  2114. if (!newKey && newKey!==0){
  2115. data.push(newValue);
  2116. newKey = data.length-1;
  2117. }else{
  2118. flag = false;
  2119. }
  2120. }
  2121. if (flag){
  2122. var o = {};
  2123. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2124. MWF.defineProperties(this, o);
  2125. }
  2126. this[newKey] = newValue;
  2127. }else if (type==="object"){
  2128. if (!this.hasOwnProperty(newKey)){
  2129. data[newKey] = newValue;
  2130. if (flag){
  2131. var o = {};
  2132. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2133. MWF.defineProperties(this, o);
  2134. }
  2135. this[newKey] = newValue;
  2136. }else{
  2137. if (overwrite) this[newKey] = newValue;
  2138. }
  2139. }
  2140. return this[newKey];
  2141. }},
  2142. "del": {"value": function(delKey){
  2143. if (!this.hasOwnProperty(delKey)) return null;
  2144. // delete data[delKey];
  2145. // delete this[delKey];
  2146. data[delKey] = "";
  2147. this[delKey] = "";
  2148. return this;
  2149. }}
  2150. };
  2151. MWF.defineProperties(this, methods);
  2152. //this.getKey = function(){ return key; };
  2153. //this.getParent = function(){ return parent; };
  2154. //this.toString = function() { return data.toString();};
  2155. //this.add = function(newKey, newValue, overwrite){
  2156. // var flag = true;
  2157. // var type = typeOf(data);
  2158. // if (!this.hasOwnProperty(newKey)){
  2159. // if (type=="array"){
  2160. // if (arguments.length<2){
  2161. // data.push(newKey);
  2162. // newValue = newKey;
  2163. // newKey = data.length-1;
  2164. // }else{
  2165. // debugger;
  2166. // if (!newKey && newKey!=0){
  2167. // data.push(newValue);
  2168. // newKey = data.length-1;
  2169. // }else{
  2170. // flag == false;
  2171. // }
  2172. // }
  2173. // }else{
  2174. // data[newKey] = newValue;
  2175. // }
  2176. // //var valueType = typeOf(newValue);
  2177. // //var newValueData = newValue;
  2178. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  2179. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  2180. // if (flag){
  2181. // var o = {};
  2182. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2183. // MWF.defineProperties(this, o);
  2184. // }
  2185. // this[newKey] = newValue;
  2186. // }else{
  2187. // if (overwrite) this[newKey] = newValue;
  2188. // }
  2189. //
  2190. // //var valueType = typeOf(newValue);
  2191. // //var newValueData = newValue;
  2192. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  2193. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  2194. // //
  2195. // //this[newKey] = newValueData;
  2196. //
  2197. // return this[newKey];
  2198. //};
  2199. //this.del = function(delKey){
  2200. // if (!this.hasOwnProperty(delKey)) return null;
  2201. // delete data[newKey];
  2202. // delete this[newKey];
  2203. // return this;
  2204. //};
  2205. };
  2206. var type = typeOf(data);
  2207. if (type==="object" || type==="array") define.apply(this);
  2208. };
  2209. //MWF.xScript.createDict = function(application){
  2210. // return function(name){
  2211. // var applicationId = application;
  2212. // this.name = name;
  2213. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  2214. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  2215. //
  2216. // this.get = function(path, success, failure){
  2217. // debugger;
  2218. // var value = null;
  2219. // if (path){
  2220. // var arr = path.split(/\./g);
  2221. // var ar = arr.map(function(v){
  2222. // return encodeURIComponent(v);
  2223. // });
  2224. // //var p = path.replace(/\./g, "/");
  2225. // var p = ar.join("/");
  2226. // action.getDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2227. // value = json.data;
  2228. // if (success) success(json.data);
  2229. // }, function(xhr, text, error){
  2230. // if (failure) failure(xhr, text, error);
  2231. // }, false);
  2232. // }else{
  2233. // action.getDictRoot(encodeURIComponent(this.name), applicationId, function(json){
  2234. // value = json.data;
  2235. // if (success) success(json.data);
  2236. // }, function(xhr, text, error){
  2237. // if (failure) failure(xhr, text, error);
  2238. // }, false);
  2239. // }
  2240. //
  2241. // return value;
  2242. // };
  2243. //
  2244. // this.set = function(path, value, success, failure){
  2245. // var p = path.replace(/\./g, "/");
  2246. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2247. // if (success) success(json.data);
  2248. // }, function(xhr, text, error){
  2249. // if (failure) failure(xhr, text, error);
  2250. // });
  2251. // };
  2252. // this.add = function(path, value, success, failure){
  2253. // var p = path.replace(/\./g, "/");
  2254. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2255. // if (success) success(json.data);
  2256. // }, function(xhr, text, error){
  2257. // if (failure) failure(xhr, text, error);
  2258. // });
  2259. // };
  2260. // this["delete"] = function(path, success, failure){
  2261. // var p = path.replace(/\./g, "/");
  2262. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2263. // if (success) success(json.data);
  2264. // }, function(xhr, text, error){
  2265. // if (failure) failure(xhr, text, error);
  2266. // });
  2267. // };
  2268. // this.destory = this["delete"];
  2269. // }
  2270. //};
  2271. // var dictLoaded = {};
  2272. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  2273. MWF.xScript.addDictToCache = function ( options, path, json ) {
  2274. if( !path )path = "root";
  2275. if( path.indexOf("root") !== 0 )path = "root." + path ;
  2276. var type = options.appType || "process";
  2277. var enableAnonymous = options.enableAnonymous || false;
  2278. var appFlagList = [];
  2279. if( options.application )appFlagList.push( options.application );
  2280. if( options.appId )appFlagList.push( options.appId );
  2281. if( options.appName )appFlagList.push( options.appName );
  2282. if( options.appAlias )appFlagList.push( options.appAlias );
  2283. var dictFlagList = [];
  2284. if( options.id )dictFlagList.push( options.id );
  2285. if( options.name )dictFlagList.push( options.name );
  2286. if( options.alias )dictFlagList.push( options.alias );
  2287. var cache = {};
  2288. cache[path] = json;
  2289. for( var i=0; i<appFlagList.length; i++ ){
  2290. for( var j=0; j<dictFlagList.length; j++ ){
  2291. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  2292. if( !MWF.xScript.dictLoaded[k] ){
  2293. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  2294. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  2295. }else if( i===0 && j===0 ){
  2296. MWF.xScript.setDictToCache( k, path ,json );
  2297. var arr = path.split(/\./g);
  2298. var p;
  2299. var cache = MWF.xScript.dictLoaded[k];
  2300. for( var l=0 ; l<arr.length; l++ ){
  2301. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  2302. if( cache[ p ] )break;
  2303. }
  2304. if( p ){
  2305. var mathP = p+".";
  2306. Object.keys( cache ).each( function( path, idx){
  2307. if( path.indexOf( mathP ) === 0 )delete cache[path];
  2308. })
  2309. }
  2310. }
  2311. }
  2312. }
  2313. };
  2314. MWF.xScript.getMatchedDict = function(key, path){
  2315. if( !path )path = "root";
  2316. if( path.indexOf("root") !== 0 )path = "root." + path ;
  2317. var arr = path.split(/\./g);
  2318. if( MWF.xScript.dictLoaded[key] ){
  2319. var dicts = MWF.xScript.dictLoaded[key];
  2320. var list = Array.clone(arr);
  2321. var p;
  2322. var dict;
  2323. for( var i=0 ; i<arr.length; i++ ){
  2324. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  2325. list.shift();
  2326. if( dicts[ p ] ){
  2327. dict = dicts[ p ];
  2328. break;
  2329. }
  2330. }
  2331. return {
  2332. dict : dict,
  2333. unmatchedPathList : list
  2334. }
  2335. }
  2336. return {
  2337. dict : null,
  2338. unmatchedPathList : list
  2339. }
  2340. };
  2341. MWF.xScript.insertDictToCache = function(key, path, json){
  2342. if( MWF.xScript.dictLoaded[key] ){
  2343. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2344. var dict = matchedDict.dict;
  2345. var list = matchedDict.unmatchedPathList;
  2346. if( !dict ){
  2347. MWF.xScript.dictLoaded[key][path] = json;
  2348. }else{
  2349. for( var j=0; j<list.length-1; j++ ){
  2350. if( !dict[ list[j] ] ){
  2351. dict[ list[j] ] = {};
  2352. }
  2353. dict = dict[ list[j] ];
  2354. }
  2355. var lastPath = list[list.length-1];
  2356. if( !dict[lastPath] ){
  2357. dict[lastPath] = json;
  2358. }else if( typeOf( dict[lastPath] ) === "array" ){
  2359. dict[lastPath].push( json );
  2360. }
  2361. }
  2362. }else{
  2363. MWF.xScript.dictLoaded[key] = {};
  2364. MWF.xScript.dictLoaded[key][path] = json;
  2365. }
  2366. };
  2367. MWF.xScript.setDictToCache = function(key, path, json){
  2368. if( MWF.xScript.dictLoaded[key] ){
  2369. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2370. var dict = matchedDict.dict;
  2371. var list = matchedDict.unmatchedPathList;
  2372. if( !dict ){
  2373. MWF.xScript.dictLoaded[key][path] = json;
  2374. }else{
  2375. for( var j=0; j<list.length-1; j++ ){
  2376. if( !dict[ list[j] ] ){
  2377. dict[ list[j] ] = {};
  2378. }
  2379. dict = dict[ list[j] ];
  2380. }
  2381. dict[list[list.length-1]] = json;
  2382. }
  2383. }else{
  2384. MWF.xScript.dictLoaded[key] = {};
  2385. MWF.xScript.dictLoaded[key][path] = json;
  2386. }
  2387. };
  2388. MWF.xScript.getDictFromCache = function( key, path ){
  2389. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2390. var dict = matchedDict.dict;
  2391. var list = matchedDict.unmatchedPathList;
  2392. if( dict ){
  2393. for( var j=0; j<list.length; j++ ){
  2394. dict = dict[ list[j] ];
  2395. if( !dict )return null;
  2396. }
  2397. return dict;
  2398. }
  2399. return null;
  2400. };
  2401. MWF.xScript.deleteDictToCache = function(key, path){
  2402. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2403. var dict = matchedDict.dict;
  2404. var list = matchedDict.unmatchedPathList;
  2405. if( dict){
  2406. for( var j=0; j<list.length-1; j++ ){
  2407. dict = dict[ list[j] ];
  2408. if( !dict )return;
  2409. }
  2410. delete dict[list[list.length-1]];
  2411. }
  2412. };
  2413. MWF.xScript.createDict = function(application){
  2414. //optionsOrName : {
  2415. // type : "", //默认为process, 可以为 process cms
  2416. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  2417. // name : "", // 数据字典名称/别名/id
  2418. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  2419. //}
  2420. //或者name: "" // 数据字典名称/别名/id
  2421. return function(optionsOrName){
  2422. var options = optionsOrName;
  2423. if( typeOf( options ) == "string" ){
  2424. options = { name : options };
  2425. }
  2426. var name = this.name = options.name;
  2427. var type = ( options.type && options.application ) ? options.type : "process";
  2428. var applicationId = options.application || application;
  2429. var enableAnonymous = options.enableAnonymous || false;
  2430. var opt = {
  2431. "appType" : type,
  2432. "name" : name,
  2433. "appId" : applicationId,
  2434. "enableAnonymous" : enableAnonymous
  2435. };
  2436. var key = name+type+applicationId+enableAnonymous;
  2437. // if (!dictLoaded[key]) dictLoaded[key] = {};
  2438. // this.dictData = dictLoaded[key];
  2439. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  2440. if( type == "cms" ){
  2441. var action = MWF.Actions.get("x_cms_assemble_control");
  2442. }else{
  2443. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  2444. }
  2445. var encodePath = function( path ){
  2446. var arr = path.split(/\./g);
  2447. var ar = arr.map(function(v){
  2448. return encodeURIComponent(v);
  2449. });
  2450. return ar.join("/");
  2451. };
  2452. this.get = function(path, success, failure, async, refresh){
  2453. var value = null;
  2454. if (!refresh ){
  2455. var data = MWF.xScript.getDictFromCache( key, path );
  2456. if( data ){
  2457. if (success && o2.typeOf(success)=="function") success( data );
  2458. return data;
  2459. }
  2460. }
  2461. if (success===true) async=true;
  2462. if (failure===true) async=true;
  2463. // var cb = function(json){
  2464. // value = json.data;
  2465. // MWF.xScript.addDictToCache(opt, path, value);
  2466. // if (success && o2.typeOf(success)=="function") value = success(json.data);
  2467. // return value;
  2468. // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
  2469. var cb = function(json){
  2470. value = json.data;
  2471. MWF.xScript.addDictToCache(opt, path, value);
  2472. if (success && o2.typeOf(success)=="function") value = success(json.data);
  2473. return value;
  2474. };
  2475. var promise;
  2476. if (path){
  2477. var p = encodePath( path );
  2478. //var p = path.replace(/\./g, "/");
  2479. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async, false);
  2480. }else{
  2481. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async, false);
  2482. }
  2483. return (!!async) ? promise : value;
  2484. // if (path){
  2485. // var p = encodePath( path );
  2486. // //var p = path.replace(/\./g, "/");
  2487. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  2488. // value = json.data;
  2489. // // this.dictData[path] = value;
  2490. // MWF.xScript.addDictToCache(opt, path, value);
  2491. // if (success) success(json.data);
  2492. // }.bind(this), function(xhr, text, error){
  2493. // if (failure) failure(xhr, text, error);
  2494. // }, !!async);
  2495. // }else{
  2496. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  2497. // value = json.data;
  2498. // // this.dictData["root"] = value;
  2499. // MWF.xScript.addDictToCache(opt, path, value);
  2500. // if (success) success(json.data);
  2501. // }.bind(this), function(xhr, text, error){
  2502. // if (failure) failure(xhr, text, error);
  2503. // }, !!async);
  2504. // }
  2505. //return value;
  2506. };
  2507. this.set = function(path, value, success, failure){
  2508. var p = encodePath( path );
  2509. //var p = path.replace(/\./g, "/");
  2510. return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2511. MWF.xScript.setDictToCache(key, path, value);
  2512. if (success) return success(json.data);
  2513. }, function(xhr, text, error){
  2514. if (failure) return failure(xhr, text, error);
  2515. }, false, false);
  2516. };
  2517. this.add = function(path, value, success, failure){
  2518. var p = encodePath( path );
  2519. //var p = path.replace(/\./g, "/");
  2520. return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2521. MWF.xScript.insertDictToCache(key, path, value);
  2522. if (success) return success(json.data);
  2523. }, function(xhr, text, error){
  2524. if (failure) return failure(xhr, text, error);
  2525. }, false, false);
  2526. };
  2527. this["delete"] = function(path, success, failure){
  2528. var p = encodePath( path );
  2529. //var p = path.replace(/\./g, "/");
  2530. return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2531. MWF.xScript.deleteDictToCache(key, path);
  2532. if (success) return success(json.data);
  2533. }, function(xhr, text, error){
  2534. if (failure) return failure(xhr, text, error);
  2535. }, false, false);
  2536. };
  2537. this.destory = this["delete"];
  2538. }
  2539. };