Environment.js 118 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731
  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. var pageId = (pageJson.data) ? pageJson.data.id : "";
  1876. layout.desktop.openApplication(null, "portal.Portal", {
  1877. "portalId": json.data.id,
  1878. "pageId": pageId,
  1879. "parameters": par,
  1880. "appId": (par && par.appId) || ("portal.Portal" + json.data.id + pageId)
  1881. })
  1882. });
  1883. } else {
  1884. layout.desktop.openApplication(null, "portal.Portal", {
  1885. "portalId": json.data.id,
  1886. "parameters": par,
  1887. "appId": (par && par.appId) || ("portal.Portal" + json.data.id)
  1888. })
  1889. }
  1890. }
  1891. });
  1892. },
  1893. "openCMS": function(name){
  1894. var action = MWF.Actions.get("x_cms_assemble_control");
  1895. action.getColumn(name, function(json){
  1896. if (json.data){
  1897. layout.desktop.openApplication(null, "cms.Module", {
  1898. "columnId": json.data.id,
  1899. "appId": "cms.Module"+json.data.id
  1900. });
  1901. }
  1902. });
  1903. },
  1904. "openProcess": function(name){
  1905. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1906. action.getApplication(name, function(json){
  1907. if (json.data){
  1908. layout.desktop.openApplication(null, "process.Application", {
  1909. "id": json.data.id,
  1910. "appId": "process.Application"+json.data.id
  1911. });
  1912. }
  1913. });
  1914. },
  1915. "openApplication":function(name, options){
  1916. layout.desktop.openApplication(null, name, options);
  1917. },
  1918. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  1919. var column = columnOrOptions;
  1920. var onAfterPublish, onPostPublish;
  1921. if (typeOf(columnOrOptions) == "object") {
  1922. column = columnOrOptions.column;
  1923. category = columnOrOptions.category;
  1924. data = columnOrOptions.data;
  1925. identity = columnOrOptions.identity;
  1926. callback = columnOrOptions.callback;
  1927. target = columnOrOptions.target;
  1928. latest = columnOrOptions.latest;
  1929. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1930. ignoreTitle = columnOrOptions.ignoreTitle;
  1931. onAfterPublish = columnOrOptions.onAfterPublish;
  1932. onPostPublish = columnOrOptions.onPostPublish;
  1933. }
  1934. if (target) {
  1935. if (layout.app && layout.app.inBrowser) {
  1936. layout.app.content.empty();
  1937. layout.app = null;
  1938. }
  1939. }
  1940. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  1941. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1942. "documentData": data,
  1943. "identity": identity,
  1944. "ignoreTitle": ignoreTitle === true,
  1945. "ignoreDrafted": latest === false,
  1946. "selectColumnEnable": !category || selectColumnEnable === true,
  1947. "restrictToColumn": !!category && selectColumnEnable !== true,
  1948. "categoryFlag": category, //category id or name
  1949. "columnFlag": column, //column id or name,
  1950. "onStarted": function (documentId, data) {
  1951. if (callback) callback();
  1952. },
  1953. "onPostPublish": function () {
  1954. if(onPostPublish)onPostPublish();
  1955. },
  1956. "onAfterPublish": function () {
  1957. if(onAfterPublish)onAfterPublish();
  1958. }
  1959. });
  1960. starter.load();
  1961. })
  1962. },
  1963. "startProcess": function(app, process, data, identity, callback, target, latest){
  1964. if (arguments.length>2){
  1965. for (var i=2; i<arguments.length; i++){
  1966. if (typeOf(arguments[i])=="boolean"){
  1967. target = arguments[i];
  1968. break;
  1969. }
  1970. }
  1971. }
  1972. if (target){
  1973. if (layout.app && layout.app.inBrowser){
  1974. //layout.app.content.empty();
  1975. layout.app.$openWithSelf = true;
  1976. }
  1977. }
  1978. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1979. if (json.data){
  1980. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1981. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1982. "workData": data,
  1983. "identity": identity,
  1984. "latest": latest,
  1985. "onStarted": function(data, title, processName){
  1986. if (data.work){
  1987. var work = data.work;
  1988. var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
  1989. layout.desktop.openApplication(null, "process.Work", options);
  1990. }else{
  1991. var currentTask = [];
  1992. data.each(function(work){
  1993. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1994. }.bind(this));
  1995. if (currentTask.length==1){
  1996. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1997. layout.desktop.openApplication(null, "process.Work", options);
  1998. }else{}
  1999. }
  2000. if (callback) callback(data);
  2001. }.bind(this)
  2002. });
  2003. starter.load();
  2004. }.bind(this));
  2005. }
  2006. });
  2007. }
  2008. };
  2009. this.form.currentRouteName = _form.json.currentRouteName;
  2010. this.form.opinion = _form.json.opinion;
  2011. this.target = ev.target;
  2012. this.event = ev.event;
  2013. this.status = ev.status;
  2014. this.session = layout.desktop.session;
  2015. this.Actions = o2.Actions;
  2016. this.query = function(option){
  2017. // options = {
  2018. // "name": "statementName",
  2019. // "data": "json data",
  2020. // "firstResult": 1,
  2021. // "maxResults": 100,
  2022. // "success": function(){},
  2023. // "error": function(){},
  2024. // "async": true or false, default is true
  2025. // }
  2026. if (option){
  2027. var json = (option.data) || {};
  2028. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  2029. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  2030. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  2031. }
  2032. }
  2033. this.Table = MWF.xScript.createTable();
  2034. };
  2035. MWF.xScript.createTable = function(){
  2036. return function(name){
  2037. this.name = name;
  2038. this.action = o2.Actions.get("x_query_assemble_surface");
  2039. this.listRowNext = function(id, count, success, error, async){
  2040. this.action.listRowNext(this.name, id, count, success, error, async);
  2041. };
  2042. this.listRowPrev = function(id, count, success, error, async){
  2043. this.action.listRowPrev(this.name, id, count, success, error, async);
  2044. };
  2045. this.listRowPrev = function(id, count, success, error, async){
  2046. this.action.listRowPrev(this.name, id, count, success, error, async);
  2047. };
  2048. this.listRowSelectWhere = function(where, success, error, async){
  2049. this.action.listRowSelectWhere(this.name, where, success, error, async);
  2050. };
  2051. this.listRowCountWhere = function(where, success, error, async){
  2052. this.action.listRowCountWhere(this.name, where, success, error, async);
  2053. };
  2054. this.deleteRow = function(id, success, error, async){
  2055. this.action.deleteRow(this.name, id, success, error, async);
  2056. };
  2057. this.deleteAllRow = function(success, error, async){
  2058. this.action.deleteAllRow(this.name, success, error, async);
  2059. };
  2060. this.getRow = function(id, success, error, async){
  2061. this.action.getRow(this.name, id, success, error, async);
  2062. };
  2063. this.insertRow = function(data, success, error, async){
  2064. this.action.insertRow(this.name, data, success, error, async);
  2065. };
  2066. this.updateRow = function(id, data, success, error, async){
  2067. this.action.updateRow(this.name, id, data, success, error, async);
  2068. };
  2069. }
  2070. };
  2071. MWF.xScript.JSONData = function(data, callback, key, parent, _form){
  2072. var getter = function(data, callback, k, _self){
  2073. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self, _form);};
  2074. };
  2075. var setter = function(data, callback, k, _self){
  2076. return function(v){
  2077. data[k] = v;
  2078. //debugger;
  2079. //this.add(k, v, true);
  2080. if (callback) callback(data, k, _self);
  2081. }
  2082. };
  2083. var define = function(){
  2084. var o = {};
  2085. 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])};
  2086. o["length"] = {"get": function(){return Object.keys(data).length;}};
  2087. o["some"] = {"get": function(){return data.some;}};
  2088. MWF.defineProperties(this, o);
  2089. var methods = {
  2090. "getKey": {"value": function(){ return key; }},
  2091. "getParent": {"value": function(){ return parent; }},
  2092. "toString": {"value": function() { return data.toString();}},
  2093. "setSection": {"value": function(newKey, newValue){
  2094. this.add(newKey, newValue, true);
  2095. try {
  2096. var path = [this.getKey()];
  2097. p = this.getParent();
  2098. while (p && p.getKey()){
  2099. path.unshift(p.getKey());
  2100. p = p.getParent();
  2101. }
  2102. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  2103. }catch(e){
  2104. }
  2105. }},
  2106. "add": {"value": function(newKey, newValue, overwrite){
  2107. var flag = true;
  2108. var type = typeOf(data);
  2109. if (type==="array"){
  2110. if (arguments.length<2){
  2111. data.push(newKey);
  2112. newValue = newKey;
  2113. newKey = data.length-1;
  2114. }else{
  2115. if (!newKey && newKey!==0){
  2116. data.push(newValue);
  2117. newKey = data.length-1;
  2118. }else{
  2119. flag = false;
  2120. }
  2121. }
  2122. if (flag){
  2123. var o = {};
  2124. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2125. MWF.defineProperties(this, o);
  2126. }
  2127. this[newKey] = newValue;
  2128. }else if (type==="object"){
  2129. if (!this.hasOwnProperty(newKey)){
  2130. data[newKey] = newValue;
  2131. if (flag){
  2132. var o = {};
  2133. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2134. MWF.defineProperties(this, o);
  2135. }
  2136. this[newKey] = newValue;
  2137. }else{
  2138. if (overwrite) this[newKey] = newValue;
  2139. }
  2140. }
  2141. return this[newKey];
  2142. }},
  2143. "del": {"value": function(delKey){
  2144. if (!this.hasOwnProperty(delKey)) return null;
  2145. // delete data[delKey];
  2146. // delete this[delKey];
  2147. data[delKey] = "";
  2148. this[delKey] = "";
  2149. return this;
  2150. }}
  2151. };
  2152. MWF.defineProperties(this, methods);
  2153. //this.getKey = function(){ return key; };
  2154. //this.getParent = function(){ return parent; };
  2155. //this.toString = function() { return data.toString();};
  2156. //this.add = function(newKey, newValue, overwrite){
  2157. // var flag = true;
  2158. // var type = typeOf(data);
  2159. // if (!this.hasOwnProperty(newKey)){
  2160. // if (type=="array"){
  2161. // if (arguments.length<2){
  2162. // data.push(newKey);
  2163. // newValue = newKey;
  2164. // newKey = data.length-1;
  2165. // }else{
  2166. // debugger;
  2167. // if (!newKey && newKey!=0){
  2168. // data.push(newValue);
  2169. // newKey = data.length-1;
  2170. // }else{
  2171. // flag == false;
  2172. // }
  2173. // }
  2174. // }else{
  2175. // data[newKey] = newValue;
  2176. // }
  2177. // //var valueType = typeOf(newValue);
  2178. // //var newValueData = newValue;
  2179. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  2180. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  2181. // if (flag){
  2182. // var o = {};
  2183. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2184. // MWF.defineProperties(this, o);
  2185. // }
  2186. // this[newKey] = newValue;
  2187. // }else{
  2188. // if (overwrite) this[newKey] = newValue;
  2189. // }
  2190. //
  2191. // //var valueType = typeOf(newValue);
  2192. // //var newValueData = newValue;
  2193. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  2194. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  2195. // //
  2196. // //this[newKey] = newValueData;
  2197. //
  2198. // return this[newKey];
  2199. //};
  2200. //this.del = function(delKey){
  2201. // if (!this.hasOwnProperty(delKey)) return null;
  2202. // delete data[newKey];
  2203. // delete this[newKey];
  2204. // return this;
  2205. //};
  2206. };
  2207. var type = typeOf(data);
  2208. if (type==="object" || type==="array") define.apply(this);
  2209. };
  2210. //MWF.xScript.createDict = function(application){
  2211. // return function(name){
  2212. // var applicationId = application;
  2213. // this.name = name;
  2214. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  2215. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  2216. //
  2217. // this.get = function(path, success, failure){
  2218. // debugger;
  2219. // var value = null;
  2220. // if (path){
  2221. // var arr = path.split(/\./g);
  2222. // var ar = arr.map(function(v){
  2223. // return encodeURIComponent(v);
  2224. // });
  2225. // //var p = path.replace(/\./g, "/");
  2226. // var p = ar.join("/");
  2227. // action.getDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2228. // value = json.data;
  2229. // if (success) success(json.data);
  2230. // }, function(xhr, text, error){
  2231. // if (failure) failure(xhr, text, error);
  2232. // }, false);
  2233. // }else{
  2234. // action.getDictRoot(encodeURIComponent(this.name), applicationId, function(json){
  2235. // value = json.data;
  2236. // if (success) success(json.data);
  2237. // }, function(xhr, text, error){
  2238. // if (failure) failure(xhr, text, error);
  2239. // }, false);
  2240. // }
  2241. //
  2242. // return value;
  2243. // };
  2244. //
  2245. // this.set = function(path, value, success, failure){
  2246. // var p = path.replace(/\./g, "/");
  2247. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2248. // if (success) success(json.data);
  2249. // }, function(xhr, text, error){
  2250. // if (failure) failure(xhr, text, error);
  2251. // });
  2252. // };
  2253. // this.add = function(path, value, success, failure){
  2254. // var p = path.replace(/\./g, "/");
  2255. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2256. // if (success) success(json.data);
  2257. // }, function(xhr, text, error){
  2258. // if (failure) failure(xhr, text, error);
  2259. // });
  2260. // };
  2261. // this["delete"] = function(path, success, failure){
  2262. // var p = path.replace(/\./g, "/");
  2263. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2264. // if (success) success(json.data);
  2265. // }, function(xhr, text, error){
  2266. // if (failure) failure(xhr, text, error);
  2267. // });
  2268. // };
  2269. // this.destory = this["delete"];
  2270. // }
  2271. //};
  2272. // var dictLoaded = {};
  2273. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  2274. MWF.xScript.addDictToCache = function ( options, path, json ) {
  2275. if( !path )path = "root";
  2276. if( path.indexOf("root") !== 0 )path = "root." + path ;
  2277. var type = options.appType || "process";
  2278. var enableAnonymous = options.enableAnonymous || false;
  2279. var appFlagList = [];
  2280. if( options.application )appFlagList.push( options.application );
  2281. if( options.appId )appFlagList.push( options.appId );
  2282. if( options.appName )appFlagList.push( options.appName );
  2283. if( options.appAlias )appFlagList.push( options.appAlias );
  2284. var dictFlagList = [];
  2285. if( options.id )dictFlagList.push( options.id );
  2286. if( options.name )dictFlagList.push( options.name );
  2287. if( options.alias )dictFlagList.push( options.alias );
  2288. var cache = {};
  2289. cache[path] = json;
  2290. for( var i=0; i<appFlagList.length; i++ ){
  2291. for( var j=0; j<dictFlagList.length; j++ ){
  2292. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  2293. if( !MWF.xScript.dictLoaded[k] ){
  2294. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  2295. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  2296. }else if( i===0 && j===0 ){
  2297. MWF.xScript.setDictToCache( k, path ,json );
  2298. var arr = path.split(/\./g);
  2299. var p;
  2300. var cache = MWF.xScript.dictLoaded[k];
  2301. for( var l=0 ; l<arr.length; l++ ){
  2302. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  2303. if( cache[ p ] )break;
  2304. }
  2305. if( p ){
  2306. var mathP = p+".";
  2307. Object.keys( cache ).each( function( path, idx){
  2308. if( path.indexOf( mathP ) === 0 )delete cache[path];
  2309. })
  2310. }
  2311. }
  2312. }
  2313. }
  2314. };
  2315. MWF.xScript.getMatchedDict = function(key, path){
  2316. if( !path )path = "root";
  2317. if( path.indexOf("root") !== 0 )path = "root." + path ;
  2318. var arr = path.split(/\./g);
  2319. if( MWF.xScript.dictLoaded[key] ){
  2320. var dicts = MWF.xScript.dictLoaded[key];
  2321. var list = Array.clone(arr);
  2322. var p;
  2323. var dict;
  2324. for( var i=0 ; i<arr.length; i++ ){
  2325. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  2326. list.shift();
  2327. if( dicts[ p ] ){
  2328. dict = dicts[ p ];
  2329. break;
  2330. }
  2331. }
  2332. return {
  2333. dict : dict,
  2334. unmatchedPathList : list
  2335. }
  2336. }
  2337. return {
  2338. dict : null,
  2339. unmatchedPathList : list
  2340. }
  2341. };
  2342. MWF.xScript.insertDictToCache = function(key, path, json){
  2343. if( MWF.xScript.dictLoaded[key] ){
  2344. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2345. var dict = matchedDict.dict;
  2346. var list = matchedDict.unmatchedPathList;
  2347. if( !dict ){
  2348. MWF.xScript.dictLoaded[key][path] = json;
  2349. }else{
  2350. for( var j=0; j<list.length-1; j++ ){
  2351. if( !dict[ list[j] ] ){
  2352. dict[ list[j] ] = {};
  2353. }
  2354. dict = dict[ list[j] ];
  2355. }
  2356. var lastPath = list[list.length-1];
  2357. if( !dict[lastPath] ){
  2358. dict[lastPath] = json;
  2359. }else if( typeOf( dict[lastPath] ) === "array" ){
  2360. dict[lastPath].push( json );
  2361. }
  2362. }
  2363. }else{
  2364. MWF.xScript.dictLoaded[key] = {};
  2365. MWF.xScript.dictLoaded[key][path] = json;
  2366. }
  2367. };
  2368. MWF.xScript.setDictToCache = function(key, path, json){
  2369. if( MWF.xScript.dictLoaded[key] ){
  2370. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2371. var dict = matchedDict.dict;
  2372. var list = matchedDict.unmatchedPathList;
  2373. if( !dict ){
  2374. MWF.xScript.dictLoaded[key][path] = json;
  2375. }else{
  2376. for( var j=0; j<list.length-1; j++ ){
  2377. if( !dict[ list[j] ] ){
  2378. dict[ list[j] ] = {};
  2379. }
  2380. dict = dict[ list[j] ];
  2381. }
  2382. dict[list[list.length-1]] = json;
  2383. }
  2384. }else{
  2385. MWF.xScript.dictLoaded[key] = {};
  2386. MWF.xScript.dictLoaded[key][path] = json;
  2387. }
  2388. };
  2389. MWF.xScript.getDictFromCache = function( key, path ){
  2390. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2391. var dict = matchedDict.dict;
  2392. var list = matchedDict.unmatchedPathList;
  2393. if( dict ){
  2394. for( var j=0; j<list.length; j++ ){
  2395. dict = dict[ list[j] ];
  2396. if( !dict )return null;
  2397. }
  2398. return dict;
  2399. }
  2400. return null;
  2401. };
  2402. MWF.xScript.deleteDictToCache = function(key, path){
  2403. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2404. var dict = matchedDict.dict;
  2405. var list = matchedDict.unmatchedPathList;
  2406. if( dict){
  2407. for( var j=0; j<list.length-1; j++ ){
  2408. dict = dict[ list[j] ];
  2409. if( !dict )return;
  2410. }
  2411. delete dict[list[list.length-1]];
  2412. }
  2413. };
  2414. MWF.xScript.createDict = function(application){
  2415. //optionsOrName : {
  2416. // type : "", //默认为process, 可以为 process cms
  2417. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  2418. // name : "", // 数据字典名称/别名/id
  2419. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  2420. //}
  2421. //或者name: "" // 数据字典名称/别名/id
  2422. return function(optionsOrName){
  2423. var options = optionsOrName;
  2424. if( typeOf( options ) == "string" ){
  2425. options = { name : options };
  2426. }
  2427. var name = this.name = options.name;
  2428. var type = ( options.type && options.application ) ? options.type : "process";
  2429. var applicationId = options.application || application;
  2430. var enableAnonymous = options.enableAnonymous || false;
  2431. var opt = {
  2432. "appType" : type,
  2433. "name" : name,
  2434. "appId" : applicationId,
  2435. "enableAnonymous" : enableAnonymous
  2436. };
  2437. var key = name+type+applicationId+enableAnonymous;
  2438. // if (!dictLoaded[key]) dictLoaded[key] = {};
  2439. // this.dictData = dictLoaded[key];
  2440. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  2441. if( type == "cms" ){
  2442. var action = MWF.Actions.get("x_cms_assemble_control");
  2443. }else{
  2444. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  2445. }
  2446. var encodePath = function( path ){
  2447. var arr = path.split(/\./g);
  2448. var ar = arr.map(function(v){
  2449. return encodeURIComponent(v);
  2450. });
  2451. return ar.join("/");
  2452. };
  2453. this.get = function(path, success, failure, async, refresh){
  2454. var value = null;
  2455. if (!refresh ){
  2456. var data = MWF.xScript.getDictFromCache( key, path );
  2457. if( data ){
  2458. if (success && o2.typeOf(success)=="function") success( data );
  2459. return data;
  2460. }
  2461. }
  2462. if (success===true) async=true;
  2463. if (failure===true) async=true;
  2464. // var cb = function(json){
  2465. // value = json.data;
  2466. // MWF.xScript.addDictToCache(opt, path, value);
  2467. // if (success && o2.typeOf(success)=="function") value = success(json.data);
  2468. // return value;
  2469. // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
  2470. var cb = function(json){
  2471. value = json.data;
  2472. MWF.xScript.addDictToCache(opt, path, value);
  2473. if (success && o2.typeOf(success)=="function") value = success(json.data);
  2474. return value;
  2475. };
  2476. var promise;
  2477. if (path){
  2478. var p = encodePath( path );
  2479. //var p = path.replace(/\./g, "/");
  2480. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async, false);
  2481. }else{
  2482. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async, false);
  2483. }
  2484. return (!!async) ? promise : value;
  2485. // if (path){
  2486. // var p = encodePath( path );
  2487. // //var p = path.replace(/\./g, "/");
  2488. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  2489. // value = json.data;
  2490. // // this.dictData[path] = value;
  2491. // MWF.xScript.addDictToCache(opt, path, value);
  2492. // if (success) success(json.data);
  2493. // }.bind(this), function(xhr, text, error){
  2494. // if (failure) failure(xhr, text, error);
  2495. // }, !!async);
  2496. // }else{
  2497. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  2498. // value = json.data;
  2499. // // this.dictData["root"] = value;
  2500. // MWF.xScript.addDictToCache(opt, path, value);
  2501. // if (success) success(json.data);
  2502. // }.bind(this), function(xhr, text, error){
  2503. // if (failure) failure(xhr, text, error);
  2504. // }, !!async);
  2505. // }
  2506. //return value;
  2507. };
  2508. this.set = function(path, value, success, failure){
  2509. var p = encodePath( path );
  2510. //var p = path.replace(/\./g, "/");
  2511. return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2512. MWF.xScript.setDictToCache(key, path, value);
  2513. if (success) return success(json.data);
  2514. }, function(xhr, text, error){
  2515. if (failure) return failure(xhr, text, error);
  2516. }, false, false);
  2517. };
  2518. this.add = function(path, value, success, failure){
  2519. var p = encodePath( path );
  2520. //var p = path.replace(/\./g, "/");
  2521. return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2522. MWF.xScript.insertDictToCache(key, path, value);
  2523. if (success) return success(json.data);
  2524. }, function(xhr, text, error){
  2525. if (failure) return failure(xhr, text, error);
  2526. }, false, false);
  2527. };
  2528. this["delete"] = function(path, success, failure){
  2529. var p = encodePath( path );
  2530. //var p = path.replace(/\./g, "/");
  2531. return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2532. MWF.xScript.deleteDictToCache(key, path);
  2533. if (success) return success(json.data);
  2534. }, function(xhr, text, error){
  2535. if (failure) return failure(xhr, text, error);
  2536. }, false, false);
  2537. };
  2538. this.destory = this["delete"];
  2539. }
  2540. };