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. * @namespace
  224. * @module workContext
  225. * @example
  226. * //您可以在表单或流程的各个嵌入脚本中,通过this来获取当前流程实例数据,如下:
  227. * var context = this.workContext;
  228. */
  229. this.workContext = {
  230. /**
  231. * 当前流程实例正在流转中,并且当前用户有待办,则返回当前用户的待办对象,否则返回null。
  232. * @summary 获取当前流程与当前用户相关的待办对象:task对象。
  233. * @method getTask
  234. * @static
  235. * @return {(Task|Null)} 当前用户的待办任务对象:task。当前用户没有对此流程实例的待办时,或流程实例已经流转结束,返回null.
  236. * @example
  237. * var task = this.workContext.getTask();
  238. */
  239. "getTask": function(){return ev.task || null;},
  240. /**
  241. * 获取当前流程实例对象:work对象或workCompleted对象。
  242. * @method getWork
  243. * @static
  244. * @return {(Work|WorkCompleted)} 流程实例对象;如果流程已结束,返回已结束的流程实例对象.
  245. * @example
  246. * var work = this.workContext.getWork();
  247. */
  248. "getWork": function(){return ev.work || ev.workCompleted;},
  249. /**
  250. * 获取当前流程实例所在的活动节点对象:activity对象。
  251. * @method getActivity
  252. * @static
  253. * @return {(Activity|Null)} 当前流程实例所在的活动节点对象,如果当前流程实例已流转完成,则返回null.
  254. * @example
  255. * var activity = this.workContext.getActivity();
  256. */
  257. "getActivity": function(){return ev.activity || null;},
  258. /**
  259. * 获取当前流程实例的所有待办对象。如果流程实例已流转完成,则返回一个空数组。
  260. * @method getTaskList
  261. * @static
  262. * @return {(Task[])} 待办任务列表.
  263. * @example
  264. * var taskList = this.workContext.getTaskList();
  265. */
  266. "getTaskList": function(callback, error){
  267. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  268. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  269. var list;
  270. o2.Actions.get("x_processplatform_assemble_surface").listTaskByWork(ev.work.id, function(json){
  271. list = json.data;
  272. if (cb) cb(list);
  273. }, ecb, !!cb);
  274. return list;
  275. },
  276. /**
  277. * 根据当前工作的job获取当前流程实例的所有待办对象。如果流程实例已流转完成,则返回一个空数组。
  278. * @method getTaskListByJob
  279. * @static
  280. * @return {(Task[])} 待办任务列表.
  281. * @example
  282. * var taskList = this.workContext.getTaskListByJob();
  283. */
  284. "getTaskListByJob": function(callback, error){
  285. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  286. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  287. var list;
  288. o2.Actions.get("x_processplatform_assemble_surface").listTaskByJob(ev.work.job, function(json){
  289. list = json.data;
  290. if (cb) cb(list);
  291. }, ecb, !!cb);
  292. return list;
  293. },
  294. "getReadList": function(callback, error){
  295. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  296. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  297. var list;
  298. o2.Actions.get("x_processplatform_assemble_surface").listReadByWork(ev.work.id, function(json){
  299. list = json.data;
  300. if (cb) cb(list);
  301. }, ecb, !!cb);
  302. return list;
  303. },
  304. "getReadListByJob": function(callback, error){
  305. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  306. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  307. var list;
  308. o2.Actions.get("x_processplatform_assemble_surface").listReadByJob(ev.work.job, function(json){
  309. list = json.data;
  310. if (cb) cb(list);
  311. }, ecb, !!cb);
  312. return list;
  313. },
  314. "getTaskCompletedList": function(callback, error){
  315. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  316. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  317. var list;
  318. o2.Actions.get("x_processplatform_assemble_surface").listTaskCompletedByWork(ev.work.id, function(json){
  319. list = json.data;
  320. if (cb) cb(list);
  321. }, ecb, !!cb);
  322. return list;
  323. },
  324. "getTaskCompletedListByJob": function(callback, error){
  325. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  326. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  327. var list;
  328. o2.Actions.get("x_processplatform_assemble_surface").listTaskCompletedByJob(ev.work.job, function(json){
  329. list = json.data;
  330. if (cb) cb(list);
  331. }, ecb, !!cb);
  332. return list;
  333. },
  334. "getReadCompletedList": function(callback, error){
  335. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  336. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  337. var list;
  338. o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByWork(ev.work.id, function(json){
  339. list = json.data;
  340. if (cb) cb(list);
  341. }, ecb, !!cb);
  342. return list;
  343. },
  344. "getReadCompletedListByJob": function(callback, error){
  345. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  346. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  347. var list;
  348. o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByJob(ev.work.job, function(json){
  349. list = json.data;
  350. if (cb) cb(list);
  351. }, ecb, !!cb);
  352. return list;
  353. },
  354. "getJobTaskList": this.getTaskListByJob,
  355. "getJobReadList": this.getReadListByJob,
  356. "getJobTaskCompletedList": this.getTaskCompletedListByJob,
  357. "getJobReadCompletedList": this.getReadCompletedListByJob,
  358. "getControl": function(){return ev.control;},
  359. "getWorkLogList": function(){return ev.workLogList;},
  360. "getRecordList": function(){return ev.recordList;},
  361. "getAttachmentList": function(){return ev.attachmentList;},
  362. "getRouteList": function(){return (ev.task) ? ev.task.routeNameList: null;},
  363. "getInquiredRouteList": function(){return null;},
  364. "setTitle": function(title){
  365. if (!this.workAction){
  366. MWF.require("MWF.xScript.Actions.WorkActions", null, false);
  367. this.workAction = new MWF.xScript.Actions.WorkActions();
  368. }
  369. this.workAction.setTitle(ev.work.id, {"title": title});
  370. }
  371. };
  372. this.workContent = this.workContext;
  373. var _redefineWorkProperties = function(work){
  374. if (work){
  375. work.creatorPersonDn = work.creatorPerson ||"";
  376. work.creatorUnitDn = work.creatorUnit ||"";
  377. work.creatorUnitDnList = work.creatorUnitList ||"";
  378. work.creatorIdentityDn = work.creatorIdentity ||"";
  379. var o = {
  380. "creatorPerson": {"get": function(){return this.creatorPersonDn.substring(0, this.creatorPersonDn.indexOf("@"));}},
  381. "creatorUnit": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  382. "creatorDepartment": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  383. "creatorIdentity": {"get": function(){return this.creatorIdentityDn.substring(0, this.creatorIdentityDn.indexOf("@"));}},
  384. // "creatorUnitList": {
  385. // "get": function(){
  386. // var v = [];
  387. // this.creatorUnitDnList.each(function(dn){
  388. // v.push(dn.substring(0, dn.indexOf("@")))
  389. // });
  390. // return v;
  391. // }
  392. // },
  393. "creatorCompany": {"get": function(){
  394. if (this.creatorUnitLevel){
  395. var level = this.creatorUnitLevel.split("/");
  396. return level[0];
  397. }else{
  398. return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));
  399. }
  400. }}
  401. };
  402. MWF.defineProperties(work, o);
  403. }
  404. return work;
  405. };
  406. var _redefineTaskProperties = function(task){
  407. if (task){
  408. task.personDn = task.person || "";
  409. task.unitDn = task.unit || "";
  410. task.unitDnList = task.unitList || "";
  411. task.identityDn = task.identity || "";
  412. var o = {
  413. "person": {"get": function(){return this.personDn.substring(0, this.personDn.indexOf("@"));}},
  414. "unit": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  415. "department": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  416. "identity": {"get": function(){return this.identityDn.substring(0, this.identityDn.indexOf("@"));}},
  417. // "unitList": {
  418. // "get": function(){
  419. // var v = [];
  420. // this.unitDnList.each(function(dn){
  421. // v.push(dn.substring(0, dn.indexOf("@")))
  422. // });
  423. // return v;
  424. // }
  425. // },
  426. "company": {"get": function(){return this.unitList[0];}}
  427. };
  428. MWF.defineProperties(task, o);
  429. }
  430. return task;
  431. };
  432. _redefineWorkProperties(this.workContext.getWork());
  433. _redefineTaskProperties(_redefineWorkProperties(this.workContext.getTask()));
  434. //dict
  435. this.Dict = MWF.xScript.createDict(_form.json.application);
  436. //unit
  437. var orgActions = null;
  438. var getOrgActions = function(){
  439. // if (!orgActions){
  440. // MWF.xDesktop.requireApp("Org", "Actions.RestActions", null, false);
  441. // orgActions = new MWF.xApplication.Org.Actions.RestActions ();
  442. // }
  443. if (!orgActions){
  444. MWF.require("MWF.xScript.Actions.UnitActions", null, false);
  445. orgActions = new MWF.xScript.Actions.UnitActions();
  446. }
  447. };
  448. var getNameFlag = function(name){
  449. var t = typeOf(name);
  450. if (t==="array"){
  451. var v = [];
  452. name.each(function(id){
  453. v.push((typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  454. });
  455. return v;
  456. }else{
  457. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  458. }
  459. };
  460. /**
  461. * 你可以通过workContext获取和流程相关的流程实例对象数据。
  462. * @module this.org
  463. * @example
  464. * //您可以在表单或流程的各个嵌入脚本中,通过this来获取当前流程实例数据,如下:
  465. * var context = this.workContext;
  466. */
  467. this.org = {
  468. //群组***************
  469. //获取群组--返回群组的对象数组
  470. /**
  471. 根据群组标识获取对应的群组对象数组:group对象数组
  472. */
  473. getGroup: function(name, async){
  474. getOrgActions();
  475. var data = {"groupList": getNameFlag(name)};
  476. var v = null;
  477. var cb = function(json){
  478. v = json.data;
  479. v = (v && v.length===1) ? v[0] : v
  480. if (async && o2.typeOf(async)=="function") return async(v);
  481. return v;
  482. };
  483. var promise = orgActions.listGroup(data, cb, null, !!async);
  484. return (!!async) ? promise : v;
  485. // var v = null;
  486. // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  487. // return (v && v.length===1) ? v[0] : v;
  488. },
  489. //查询下级群组--返回群组的对象数组
  490. //nested 布尔 true嵌套下级;false直接下级;默认false;
  491. listSubGroup: function(name, nested, async){
  492. getOrgActions();
  493. var data = {"groupList": getNameFlag(name)};
  494. var v = null;
  495. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  496. // v = json.data;
  497. // return v;
  498. // }.ag().catch(function(json){ return json; });
  499. var cb = function(json){
  500. v = json.data;
  501. if (async && o2.typeOf(async)=="function") return async(v);
  502. return v;
  503. };
  504. var promise;
  505. if (nested){
  506. promise = orgActions.listSubGroupNested(data, cb, null, !!async);
  507. }else{
  508. promise = orgActions.listSubGroupDirect(data, cb, null, !!async);
  509. }
  510. return (!!async) ? promise : v;
  511. // var v = null;
  512. // if (nested){
  513. // orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  514. // }else{
  515. // orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  516. // }
  517. // return v;
  518. },
  519. //查询上级群组--返回群组的对象数组
  520. //nested 布尔 true嵌套上级;false直接上级;默认false;
  521. listSupGroup:function(name, nested, async){
  522. getOrgActions();
  523. var data = {"groupList": getNameFlag(name)};
  524. var v = null;
  525. var cb = function(json){
  526. v = json.data;
  527. if (async && o2.typeOf(async)=="function") return async(v);
  528. return v;
  529. };
  530. var promise
  531. if (nested){
  532. var promise = orgActions.listSupGroupNested(data, cb, null, !!async);
  533. }else{
  534. var promise = orgActions.listSupGroupDirect(data, cb, null, !!async);
  535. }
  536. return (!!async) ? promise : v;
  537. // var v = null;
  538. // if (nested){
  539. // orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  540. // }else{
  541. // orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  542. // }
  543. // return v;
  544. },
  545. //人员所在群组(嵌套)--返回群组的对象数组
  546. listGroupWithPerson:function(name, async){
  547. getOrgActions();
  548. var data = {"personList": getNameFlag(name)};
  549. var v = null;
  550. var cb = function(json){
  551. v = json.data;
  552. if (async && o2.typeOf(async)=="function") return async(v);
  553. return v;
  554. };
  555. var promise = orgActions.listGroupWithPerson(data, cb, null, !!async);
  556. return (!!async) ? promise : v;
  557. // var v = null;
  558. // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  559. // return v;
  560. },
  561. //群组是否拥有角色--返回true, false
  562. groupHasRole: function(name, role, async){
  563. getOrgActions();
  564. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  565. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  566. var v = false;
  567. var cb = function(json){
  568. v = json.data.value;
  569. if (async && o2.typeOf(async)=="function") return async(v);
  570. return v;
  571. };
  572. var promise = orgActions.groupHasRole(data, cb, null, !!async);
  573. return (!!async) ? promise : v;
  574. // var v = false;
  575. // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  576. // return v;
  577. },
  578. //角色***************
  579. //获取角色--返回角色的对象数组
  580. getRole: function(name, async){
  581. getOrgActions();
  582. var data = {"roleList": getNameFlag(name)};
  583. var v = null;
  584. var cb = function(json){
  585. v = json.data;
  586. v = (v && v.length===1) ? v[0] : v;
  587. if (async && o2.typeOf(async)=="function") return async(v);
  588. return v;
  589. };
  590. var promise = orgActions.listRole(data, cb, null, !!async);
  591. return (!!async) ? promise : v;
  592. // var v = null;
  593. // orgActions.listRole(data, function(json){v = json.data;}, null, false);
  594. // return (v && v.length===1) ? v[0] : v;
  595. },
  596. //人员所有角色(嵌套)--返回角色的对象数组
  597. listRoleWithPerson:function(name, async){
  598. getOrgActions();
  599. var data = {"personList": getNameFlag(name)};
  600. var v = null;
  601. var cb = function(json){
  602. v = json.data;
  603. if (async && o2.typeOf(async)=="function") return async(v);
  604. return v;
  605. };
  606. var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
  607. return (!!async) ? promise : v;
  608. // var v = null;
  609. // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  610. // return v;
  611. },
  612. //人员***************
  613. //人员是否拥有角色--返回true, false
  614. personHasRole: function(name, role, async){
  615. getOrgActions();
  616. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  617. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  618. var v = false;
  619. var cb = function(json){
  620. v = json.data.value;
  621. if (async && o2.typeOf(async)=="function") return async(v);
  622. return v;
  623. };
  624. var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
  625. return (!!async) ? promise : v;
  626. // var v = false;
  627. // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  628. // return v;
  629. },
  630. //获取人员--返回人员的对象数组
  631. getPerson: function(name, async){
  632. getOrgActions();
  633. var data = {"personList": getNameFlag(name)};
  634. var v = null;
  635. var cb = function(json){
  636. v = json.data;
  637. v = (v && v.length===1) ? v[0] : v;
  638. if (async && o2.typeOf(async)=="function") return async(v);
  639. return v;
  640. };
  641. var promise = orgActions.listPerson(data, cb, null, !!async);
  642. return (!!async) ? promise : v;
  643. // var v = null;
  644. // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  645. // return (v && v.length===1) ? v[0] : v;
  646. },
  647. //查询下级人员--返回人员的对象数组
  648. //nested 布尔 true嵌套下级;false直接下级;默认false;
  649. listSubPerson: function(name, nested, async){
  650. getOrgActions();
  651. var data = {"personList": getNameFlag(name)};
  652. var v = null;
  653. var cb = function(json){
  654. v = json.data;
  655. if (async && o2.typeOf(async)=="function") return async(v);
  656. return v;
  657. };
  658. var promise;
  659. if (nested){
  660. promise = orgActions.listPersonSubNested(data, cb, null, !!async);
  661. }else{
  662. promise = orgActions.listPersonSubDirect(data, cb, null, !!async);
  663. }
  664. return (!!async) ? promise : v;
  665. },
  666. //查询上级人员--返回人员的对象数组
  667. //nested 布尔 true嵌套上级;false直接上级;默认false;
  668. listSupPerson: function(name, nested, async){
  669. getOrgActions();
  670. var data = {"personList": getNameFlag(name)};
  671. var v = null;
  672. var cb = function(json){
  673. v = json.data;
  674. if (async && o2.typeOf(async)=="function") return async(v);
  675. return v;
  676. };
  677. var promise;
  678. if (nested){
  679. promise = orgActions.listPersonSupNested(data, cb, null, !!async);
  680. }else{
  681. promise = orgActions.listPersonSupDirect(data, cb, null, !!async);
  682. }
  683. return (!!async) ? promise : v;
  684. },
  685. //获取群组的所有人员--返回人员的对象数组
  686. listPersonWithGroup: function(name, async){
  687. getOrgActions();
  688. var data = {"groupList": getNameFlag(name)};
  689. var v = null;
  690. var cb = function(json){
  691. v = json.data;
  692. if (async && o2.typeOf(async)=="function") return async(v);
  693. return v;
  694. };
  695. var promise = orgActions.listPersonWithGroup(data, cb, null, !!async);
  696. return (!!async) ? promise : v;
  697. },
  698. //获取角色的所有人员--返回人员的对象数组
  699. listPersonWithRole: function(name, async){
  700. getOrgActions();
  701. var data = {"roleList": getNameFlag(name)};
  702. var v = null;
  703. var cb = function(json){
  704. v = json.data;
  705. if (async && o2.typeOf(async)=="function") return async(v);
  706. return v;
  707. };
  708. var promise
  709. promise = orgActions.listPersonWithRole(data, cb, null, !!async);
  710. return (!!async) ? promise : v;
  711. },
  712. //获取身份的所有人员--返回人员的对象数组
  713. listPersonWithIdentity: function(name, async){
  714. getOrgActions();
  715. var data = {"identityList": getNameFlag(name)};
  716. var v = null;
  717. var cb = function(json){
  718. v = json.data;
  719. if (async && o2.typeOf(async)=="function") return async(v);
  720. return v;
  721. };
  722. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  723. return (!!async) ? promise : v;
  724. },
  725. //获取身份的所有人员--返回人员的对象数组或人员对象
  726. getPersonWithIdentity: function(name, async){
  727. getOrgActions();
  728. var data = {"identityList": getNameFlag(name)};
  729. var v = null;
  730. var cb = function(json){
  731. v = json.data;
  732. v = (v && v.length===1) ? v[0] : v;
  733. if (async && o2.typeOf(async)=="function") return async(v);
  734. return v;
  735. };
  736. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  737. return (!!async) ? promise : v;
  738. },
  739. //查询组织成员的人员--返回人员的对象数组
  740. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  741. listPersonWithUnit: function(name, nested, async){
  742. getOrgActions();
  743. var data = {"unitList": getNameFlag(name)};
  744. var v = null;
  745. var cb = function(json){
  746. v = json.data;
  747. if (async && o2.typeOf(async)=="function") return async(v);
  748. return v;
  749. };
  750. var promise;
  751. if (nested){
  752. promise = orgActions.listPersonWithUnitNested(data, cb, null, !!async);
  753. }else{
  754. promise = orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
  755. }
  756. return (!!async) ? promise : v;
  757. },
  758. //根据属性查询人员--返回人员的对象数组
  759. //name string 属性名
  760. //value string 属性值
  761. listPersonWithAttribute: function(name, value, async){
  762. getOrgActions();
  763. var data = {"name": name, "attribute": value};
  764. var v = null;
  765. var cb = function(json){
  766. v = json.data;
  767. if (async && o2.typeOf(async)=="function") return async(v);
  768. return v;
  769. };
  770. var promise = orgActions.listPersonWithAttribute(data, cb, null, !!async);
  771. return (!!async) ? promise : v;
  772. },
  773. //根据属性查询人员--返回人员的全称数组
  774. //name string 属性名
  775. //value string 属性值
  776. listPersonNameWithAttribute: function(name, value, async){
  777. getOrgActions();
  778. var data = {"name": name, "attribute": value};
  779. var v = null;
  780. var cb = function(json){
  781. v = json.data.personList;
  782. if (async && o2.typeOf(async)=="function") return async(v);
  783. return v;
  784. };
  785. var promise = orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
  786. return (!!async) ? promise : v;
  787. },
  788. //人员属性************
  789. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  790. appendPersonAttribute: function(person, attr, values, success, failure, async){
  791. getOrgActions();
  792. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  793. var data = {"attributeList":values,"name":attr,"person":personFlag};
  794. var cb = function(json){
  795. if (success) return success(json);
  796. }.ag().catch(function(xhr, text, error){
  797. if (failure) return failure(xhr, text, error);
  798. });
  799. orgActions.appendPersonAttribute(data, cb, null, !!async);
  800. },
  801. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  802. setPersonAttribute: function(person, attr, values, success, failure, async){
  803. getOrgActions();
  804. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  805. var data = {"attributeList":values,"name":attr,"person":personFlag};
  806. var cb = function(json){
  807. if (success) return success(json);
  808. }.ag().catch(function(xhr, text, error){
  809. if (failure) return failure(xhr, text, error);
  810. });
  811. orgActions.setPersonAttribute(data, cb, null, !!async);
  812. },
  813. //获取人员属性值
  814. getPersonAttribute: function(person, attr, async){
  815. getOrgActions();
  816. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  817. var data = {"name":attr,"person":personFlag};
  818. var v = null;
  819. var cb = function(json){
  820. v = json.data.attributeList;
  821. if (async && o2.typeOf(async)=="function") return async(v);
  822. return v;
  823. };
  824. var promise = orgActions.getPersonAttribute(data, cb, null, !!async);
  825. return (!!async) ? promise : v;
  826. },
  827. //列出人员所有属性的名称
  828. listPersonAttributeName: function(name, async){
  829. getOrgActions();
  830. var data = {"personList":getNameFlag(name)};
  831. var v = null;
  832. var cb = function(json){
  833. v = json.data.nameList;
  834. if (async && o2.typeOf(async)=="function") return async(v);
  835. return v;
  836. };
  837. var promise = orgActions.listPersonAttributeName(data, cb, null, !!async);
  838. return (!!async) ? promise : v;
  839. },
  840. //列出人员的所有属性
  841. listPersonAllAttribute: function(name, async){
  842. getOrgActions();
  843. var data = {"personList":getNameFlag(name)};
  844. var v = null;
  845. var cb = function(json){
  846. v = json.data;
  847. if (async && o2.typeOf(async)=="function") return async(v);
  848. return v;
  849. };
  850. var promise = orgActions.listPersonAllAttribute(data, cb, null, !!async);
  851. return (!!async) ? promise : v;
  852. },
  853. //身份**********
  854. //获取身份
  855. getIdentity: function(name, async){
  856. getOrgActions();
  857. var data = {"identityList":getNameFlag(name)};
  858. var v = null;
  859. var cb = function(json){
  860. v = json.data;
  861. v = (v && v.length===1) ? v[0] : v;
  862. if (async && o2.typeOf(async)=="function") return async(v);
  863. return v;
  864. };
  865. var promise = orgActions.listIdentity(data, cb, null, !!async);
  866. return (!!async) ? promise : v;
  867. },
  868. //列出人员的身份
  869. listIdentityWithPerson: function(name, async){
  870. getOrgActions();
  871. var data = {"personList":getNameFlag(name)};
  872. var v = null;
  873. var cb = function(json){
  874. v = json.data;
  875. if (async && o2.typeOf(async)=="function") return async(v);
  876. return v;
  877. };
  878. var promise = orgActions.listIdentityWithPerson(data, cb, null, !!async);
  879. return (!!async) ? promise : v;
  880. },
  881. //查询组织成员身份--返回身份的对象数组
  882. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  883. listIdentityWithUnit: function(name, nested, async){
  884. getOrgActions();
  885. var data = {"unitList": getNameFlag(name)};
  886. var v = null;
  887. // var cb = function(json){
  888. // v = json.data;
  889. // if (async && o2.typeOf(async)=="function") return async(v);
  890. // return v;
  891. // }.ag().catch(function(json){ return json; });
  892. var cb = function(json){
  893. v = json.data;
  894. if (async && o2.typeOf(async)=="function") return async(v);
  895. return v;
  896. };
  897. var method = (nested) ? "listIdentityWithUnitNested" : "listIdentityWithUnitDirect";
  898. var promise = orgActions[method](data, cb, null, !!async);
  899. promise.name = "org";
  900. //
  901. // if (nested){
  902. // orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
  903. // }else{
  904. // orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
  905. // }
  906. return (!!async) ? promise : v;
  907. },
  908. //组织**********
  909. //获取组织
  910. getUnit: function(name, async){
  911. getOrgActions();
  912. var data = {"unitList":getNameFlag(name)};
  913. var v = null;
  914. var cb = function(json){
  915. v = json.data;
  916. v = (v && v.length===1) ? v[0] : v;
  917. if (async && o2.typeOf(async)=="function") return async(v);
  918. return v;
  919. };
  920. var promise = orgActions.listUnit(data, cb, null, !!async);
  921. return (!!async) ? promise : v;
  922. },
  923. //查询组织的下级--返回组织的对象数组
  924. //nested 布尔 true嵌套下级;false直接下级;默认false;
  925. listSubUnit: function(name, nested, async){
  926. getOrgActions();
  927. var data = {"unitList": getNameFlag(name)};
  928. var v = null;
  929. var cb = function(json){
  930. v = json.data;
  931. if (async && o2.typeOf(async)=="function") return async(v);
  932. return v;
  933. };
  934. var promise;
  935. if (nested){
  936. promise = orgActions.listUnitSubNested(data, cb, null, !!async);
  937. }else{
  938. promise = orgActions.listUnitSubDirect(data, cb, null, !!async);
  939. }
  940. return (!!async) ? promise : v;
  941. },
  942. //查询组织的上级--返回组织的对象数组
  943. //nested 布尔 true嵌套上级;false直接上级;默认false;
  944. //async 布尔 true异步请求
  945. listSupUnit: function(name, nested, async){
  946. getOrgActions();
  947. var data = {"unitList": getNameFlag(name)};
  948. var v = null;
  949. var cb = function(json){
  950. v = json.data;
  951. if (async && o2.typeOf(async)=="function") return async(v);
  952. return v;
  953. };
  954. var promise;
  955. if (nested){
  956. promise = orgActions.listUnitSupNested(data, cb, null, !!async);
  957. }else{
  958. promise = orgActions.listUnitSupDirect(data, cb, null, !!async);
  959. }
  960. return (!!async) ? promise : v;
  961. // if (callback){
  962. // if (nested){
  963. // orgActions.listUnitSupNested(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  964. // }else{
  965. // orgActions.listUnitSupDirect(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  966. // }
  967. // }else{
  968. // var v = null;
  969. // if (nested){
  970. // orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  971. // }else{
  972. // orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  973. // }
  974. // return v;
  975. // }
  976. },
  977. //根据个人身份获取组织
  978. //flag 数字 表示获取第几层的组织
  979. // 字符串 表示获取指定类型的组织
  980. // 空 表示获取直接所在的组织
  981. getUnitByIdentity: function(name, flag, async){
  982. getOrgActions();
  983. var getUnitMethod = "current";
  984. var v;
  985. if (flag){
  986. if (typeOf(flag)==="string") getUnitMethod = "type";
  987. if (typeOf(flag)==="number") getUnitMethod = "level";
  988. }
  989. var cb;
  990. var promise;
  991. switch (getUnitMethod){
  992. case "current":
  993. var data = {"identityList":getNameFlag(name)};
  994. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  995. // v = json.data; v=(v&&v.length===1) ? v[0] : v; return v;
  996. // }.ag().catch(function(json){ return json; });
  997. cb = function(json){
  998. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  999. if (async && o2.typeOf(async)=="function") return async(v);
  1000. return v;
  1001. };
  1002. promise = orgActions.listUnitWithIdentity(data, cb, null, !!async);
  1003. break;
  1004. case "type":
  1005. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  1006. cb = function(json){
  1007. v = json.data;
  1008. if (async && o2.typeOf(async)=="function") return async(v);
  1009. return v;
  1010. };
  1011. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  1012. // v = json.data; return v;
  1013. // }.ag().catch(function(json){ return json; });
  1014. promise = orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
  1015. break;
  1016. case "level":
  1017. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  1018. cb = function(json){
  1019. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  1020. if (async && o2.typeOf(async)=="function") return async(v);
  1021. return v;
  1022. };
  1023. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  1024. // v = json.data; return v;
  1025. // }.ag().catch(function(json){ return json; });
  1026. promise = orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
  1027. break;
  1028. }
  1029. return (!!async) ? promise : v;
  1030. },
  1031. //列出身份所在组织的所有上级组织
  1032. listAllSupUnitWithIdentity: function(name, async){
  1033. getOrgActions();
  1034. var data = {"identityList":getNameFlag(name)};
  1035. var v = null;
  1036. var cb = function(json){
  1037. v = json.data;
  1038. if (async && o2.typeOf(async)=="function") return async(v);
  1039. return v;
  1040. };
  1041. var promise = orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
  1042. return (!!async) ? promise : v;
  1043. },
  1044. //获取人员所在的所有组织
  1045. listUnitWithPerson: function(name, async){
  1046. getOrgActions();
  1047. var data = {"personList":getNameFlag(name)};
  1048. var v = null;
  1049. var cb = function(json){
  1050. v = json.data;
  1051. if (async && o2.typeOf(async)=="function") return async(v);
  1052. return v;
  1053. };
  1054. var promise = orgActions.listUnitWithPerson(data, cb, null, !!async);
  1055. return (!!async) ? promise : v;
  1056. },
  1057. //列出人员所在组织的所有上级组织
  1058. listAllSupUnitWithPerson: function(name, async){
  1059. getOrgActions();
  1060. var data = {"personList":getNameFlag(name)};
  1061. var v = null;
  1062. var cb = function(json){
  1063. v = json.data;
  1064. if (async && o2.typeOf(async)=="function") return async(v);
  1065. return v;
  1066. };
  1067. var promise = orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
  1068. return (!!async) ? promise : v;
  1069. },
  1070. //根据组织属性,获取所有符合的组织
  1071. listUnitWithAttribute: function(name, attribute, async){
  1072. getOrgActions();
  1073. var data = {"name":name,"attribute":attribute};
  1074. var v = null;
  1075. var cb = function(json){
  1076. v = json.data;
  1077. if (async && o2.typeOf(async)=="function") return async(v);
  1078. return v;
  1079. };
  1080. promise = orgActions.listUnitWithAttribute(data, cb, null, !!async);
  1081. return (!!async) ? promise : v;
  1082. },
  1083. //根据组织职务,获取所有符合的组织
  1084. listUnitWithDuty: function(name, id, async){
  1085. getOrgActions();
  1086. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  1087. var v = null;
  1088. var cb = function(json){
  1089. v = json.data;
  1090. if (async && o2.typeOf(async)=="function") return async(v);
  1091. return v;
  1092. };
  1093. var promise = orgActions.listUnitWithDuty(data, cb, null, !!async);
  1094. return (!!async) ? promise : v;
  1095. },
  1096. //组织职务***********
  1097. //获取指定的组织职务的身份
  1098. getDuty: function(duty, id, async){
  1099. getOrgActions();
  1100. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  1101. var v = null;
  1102. var cb = function(json){
  1103. v = json.data;
  1104. if (async && o2.typeOf(async)=="function") return async(v);
  1105. return v;
  1106. };
  1107. var promise = orgActions.getDuty(data, cb, null, !!async);
  1108. return (!!async) ? promise : v;
  1109. },
  1110. //获取身份的所有职务名称
  1111. listDutyNameWithIdentity: function(name, async){
  1112. getOrgActions();
  1113. var data = {"identityList":getNameFlag(name)};
  1114. var v = null;
  1115. var cb = function(json){
  1116. v = json.data.nameList;
  1117. if (async && o2.typeOf(async)=="function") return async(v);
  1118. return v;
  1119. };
  1120. var promise = orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
  1121. return (!!async) ? promise : v;
  1122. },
  1123. //获取组织的所有职务名称
  1124. listDutyNameWithUnit: function(name, async){
  1125. getOrgActions();
  1126. var data = {"unitList":getNameFlag(name)};
  1127. var v = null;
  1128. var cb = function(json){
  1129. v = json.data.nameList;
  1130. if (async && o2.typeOf(async)=="function") return async(v);
  1131. return v;
  1132. };
  1133. var promise = orgActions.listDutyNameWithUnit(data, cb, null, !!async);
  1134. return (!!async) ? promise : v;
  1135. },
  1136. //获取组织的所有职务
  1137. listUnitAllDuty: function(name, async){
  1138. getOrgActions();
  1139. var data = {"unitList":getNameFlag(name)};
  1140. var v = null;
  1141. var cb = function(json){
  1142. v = json.data;
  1143. if (async && o2.typeOf(async)=="function") return async(v);
  1144. return v;
  1145. };
  1146. var promise = orgActions.listUnitAllDuty(data, cb, null, !!async);
  1147. return (!!async) ? promise : v;
  1148. },
  1149. //列出顶层组织
  1150. listTopUnit: function(async){
  1151. var action = MWF.Actions.get("x_organization_assemble_control");
  1152. var v = null;
  1153. var cb = function(json){
  1154. v = json.data;
  1155. if (async && o2.typeOf(async)=="function") return async(v);
  1156. return v;
  1157. };
  1158. var promise = action.listTopUnit(cb, null, !!async);
  1159. return (!!async) ? promise : v;
  1160. },
  1161. //组织属性**************
  1162. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  1163. appendUnitAttribute: function(unit, attr, values, success, failure, async){
  1164. getOrgActions();
  1165. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1166. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  1167. var cb = function(json){
  1168. if (success) return success(json);
  1169. }.ag().catch(function(xhr, text, error){
  1170. if (failure) return failure(xhr, text, error);
  1171. });
  1172. orgActions.appendPersonAttribute(data, cb, null, !!async);
  1173. // orgActions.appendUnitAttribute(data, function(json){
  1174. // if (json.data.value){
  1175. // if (success) success();
  1176. // }else{
  1177. // if (failure) failure(null, "", "append values failed");
  1178. // }
  1179. // }, function(xhr, text, error){
  1180. // if (failure) failure(xhr, text, error);
  1181. // }, false);
  1182. },
  1183. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  1184. setUnitAttribute: function(unit, attr, values, success, failure, async){
  1185. getOrgActions();
  1186. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1187. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  1188. var cb = function(json){
  1189. if (success) return success(json);
  1190. }.ag().catch(function(xhr, text, error){
  1191. if (failure) return failure(xhr, text, error);
  1192. });
  1193. orgActions.setUnitAttribute(data, cb, null, !!async);
  1194. // orgActions.setUnitAttribute(data, function(json){
  1195. // if (json.data.value){
  1196. // if (success) success();
  1197. // }else{
  1198. // if (failure) failure(null, "", "append values failed");
  1199. // }
  1200. // }, function(xhr, text, error){
  1201. // if (failure) failure(xhr, text, error);
  1202. // }, false);
  1203. },
  1204. //获取组织属性值
  1205. getUnitAttribute: function(unit, attr, async){
  1206. getOrgActions();
  1207. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1208. var data = {"name":attr,"unit":unitFlag};
  1209. var v = null;
  1210. var cb = function(json){
  1211. v = json.data.attributeList;
  1212. if (async && o2.typeOf(async)=="function") return async(v);
  1213. return v;
  1214. };
  1215. var promise = orgActions.getUnitAttribute(data, cb, null, !!async);
  1216. return (!!async) ? promise : v;
  1217. },
  1218. //列出组织所有属性的名称
  1219. listUnitAttributeName: function(name, async){
  1220. getOrgActions();
  1221. var data = {"unitList":getNameFlag(name)};
  1222. var v = null;
  1223. var cb = function(json){
  1224. v = json.data.nameList;
  1225. if (async && o2.typeOf(async)=="function") return async(v);
  1226. return v;
  1227. };
  1228. var promise = orgActions.listUnitAttributeName(data, cb, null, !!async);
  1229. return (!!async) ? promise : v;
  1230. },
  1231. //列出组织的所有属性
  1232. listUnitAllAttribute: function(name, async){
  1233. getOrgActions();
  1234. var data = {"unitList":getNameFlag(name)};
  1235. var v = null;
  1236. var cb = function(json){
  1237. v = json.data;
  1238. if (async && o2.typeOf(async)=="function") return async(v);
  1239. return v;
  1240. };
  1241. var promise = orgActions.listUnitAllAttribute(data, cb, null, !!async);
  1242. return (!!async) ? promise : v;
  1243. }
  1244. };
  1245. this.Action = (function(){
  1246. var actions = [];
  1247. return function(root, json){
  1248. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  1249. action.getActions = function(callback){
  1250. if (!this.actions) this.actions = {};
  1251. Object.merge(this.actions, json);
  1252. if (callback) callback();
  1253. };
  1254. this.invoke = function(option){
  1255. action.invoke(option)
  1256. }
  1257. }
  1258. })();
  1259. this.service = {
  1260. "jaxwsClient":{},
  1261. "jaxrsClient":{}
  1262. };
  1263. var lookupAction = null;
  1264. var getLookupAction = function(callback){
  1265. if (!lookupAction){
  1266. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  1267. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  1268. lookupAction.getActions = function(actionCallback){
  1269. this.actions = {
  1270. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  1271. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  1272. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  1273. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  1274. };
  1275. if (actionCallback) actionCallback();
  1276. };
  1277. if (callback) callback();
  1278. });
  1279. }else{
  1280. if (callback) callback();
  1281. }
  1282. };
  1283. this.view = {
  1284. "lookup": function(view, callback, async){
  1285. var filterList = {"filterList": (view.filter || null)};
  1286. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function(json){
  1287. var data = {
  1288. "grid": json.data.grid || json.data.groupGrid,
  1289. "groupGrid": json.data.groupGrid
  1290. };
  1291. if (callback) callback(data);
  1292. }, null, async);
  1293. },
  1294. "lookupV1": function(view, callback){
  1295. getLookupAction(function(){
  1296. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  1297. var data = {
  1298. "grid": json.data.grid,
  1299. "groupGrid": json.data.groupGrid
  1300. };
  1301. if (callback) callback(data);
  1302. }.bind(this)});
  1303. }.bind(this));
  1304. },
  1305. "select": function(view, callback, options){
  1306. if (view.view){
  1307. var viewJson = {
  1308. "application": view.application || _form.json.application,
  1309. "viewName": view.view || "",
  1310. "isTitle": (view.isTitle===false) ? "no" : "yes",
  1311. "select": (view.isMulti===false) ? "single" : "multi",
  1312. "filter": view.filter
  1313. };
  1314. if (!options) options = {};
  1315. options.width = view.width;
  1316. options.height = view.height;
  1317. options.title = view.caption;
  1318. var width = options.width || "700";
  1319. var height = options.height || "400";
  1320. if (layout.mobile){
  1321. var size = document.body.getSize();
  1322. width = size.x;
  1323. height = size.y;
  1324. options.style = "viewmobile";
  1325. }
  1326. width = width.toInt();
  1327. height = height.toInt();
  1328. var size = _form.app.content.getSize();
  1329. var x = (size.x-width)/2;
  1330. var y = (size.y-height)/2;
  1331. if (x<0) x = 0;
  1332. if (y<0) y = 0;
  1333. if (layout.mobile){
  1334. x = 20;
  1335. y = 0;
  1336. }
  1337. var _self = this;
  1338. MWF.require("MWF.xDesktop.Dialog", function(){
  1339. var dlg = new MWF.xDesktop.Dialog({
  1340. "title": options.title || "select view",
  1341. "style": options.style || "view",
  1342. "top": y,
  1343. "left": x-20,
  1344. "fromTop":y,
  1345. "fromLeft": x-20,
  1346. "width": width,
  1347. "height": height,
  1348. "html": "<div style='height: 100%;'></div>",
  1349. "maskNode": _form.app.content,
  1350. "container": _form.app.content,
  1351. "buttonList": [
  1352. {
  1353. "text": MWF.LP.process.button.ok,
  1354. "action": function(){
  1355. //if (callback) callback(_self.view.selectedItems);
  1356. if (callback) callback(_self.view.getData());
  1357. this.close();
  1358. }
  1359. },
  1360. {
  1361. "text": MWF.LP.process.button.cancel,
  1362. "action": function(){this.close();}
  1363. }
  1364. ]
  1365. });
  1366. dlg.show();
  1367. if (layout.mobile){
  1368. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1369. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1370. if (backAction) backAction.addEvent("click", function(e){
  1371. dlg.close();
  1372. }.bind(this));
  1373. if (okAction) okAction.addEvent("click", function(e){
  1374. //if (callback) callback(this.view.selectedItems);
  1375. if (callback) callback(this.view.getData());
  1376. dlg.close();
  1377. }.bind(this));
  1378. }
  1379. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  1380. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"}, _form.app, _form.Macro);
  1381. }.bind(this));
  1382. }.bind(this));
  1383. }
  1384. }
  1385. };
  1386. this.statement = {
  1387. "execute": function (statement, callback, async) {
  1388. var parameter = this.parseParameter(statement.parameter);
  1389. var filterList = this.parseFilter(statement.filter, parameter);
  1390. var obj = {
  1391. "filterList": filterList,
  1392. "parameter" : parameter
  1393. };
  1394. MWF.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  1395. statement.name, statement.mode || "data", statement.page || 1, statement.pageSize || 20, obj,
  1396. function (json) {
  1397. if (callback) callback(json);
  1398. }, null, async);
  1399. },
  1400. parseFilter : function( filter, parameter ){
  1401. if( typeOf(filter) !== "array" )return [];
  1402. var filterList = [];
  1403. ( filter || [] ).each( function (d) {
  1404. var parameterName = d.path.replace(/\./g, "_");
  1405. var value = d.value;
  1406. if( d.comparison === "like" || d.comparison === "notLike" ){
  1407. if( value.substr(0, 1) !== "%" )value = "%"+value;
  1408. if( value.substr(value.length-1,1) !== "%" )value = value+"%";
  1409. parameter[ parameterName ] = value; //"%"+value+"%";
  1410. }else{
  1411. if( d.formatType === "dateTimeValue" || d.formatType === "datetimeValue"){
  1412. value = "{ts '"+value+"'}"
  1413. }else if( d.formatType === "dateValue" ){
  1414. value = "{d '"+value+"'}"
  1415. }else if( d.formatType === "timeValue" ){
  1416. value = "{t '"+value+"'}"
  1417. }
  1418. parameter[ parameterName ] = value;
  1419. }
  1420. d.value = parameterName;
  1421. filterList.push( d );
  1422. }.bind(this));
  1423. return filterList;
  1424. },
  1425. parseParameter : function( obj ){
  1426. if( typeOf(obj) !== "object" )return {};
  1427. var parameter = {};
  1428. //传入的参数
  1429. for( var p in obj ){
  1430. var value = obj[p];
  1431. if( typeOf( value ) === "date" ){
  1432. value = "{ts '"+value.format("db")+"'}"
  1433. }
  1434. parameter[ p ] = value;
  1435. }
  1436. return parameter;
  1437. },
  1438. "select": function (statement, callback, options) {
  1439. if (statement.name) {
  1440. // var parameter = this.parseParameter(statement.parameter);
  1441. // var filterList = this.parseFilter(statement.filter, parameter);
  1442. var statementJson = {
  1443. "statementId": statement.name || "",
  1444. "isTitle": (statement.isTitle === false) ? "no" : "yes",
  1445. "select": (statement.isMulti === false) ? "single" : "multi",
  1446. "filter": statement.filter,
  1447. "parameter": statement.parameter
  1448. };
  1449. if (!options) options = {};
  1450. options.width = statement.width;
  1451. options.height = statement.height;
  1452. options.title = statement.caption;
  1453. var width = options.width || "700";
  1454. var height = options.height || "400";
  1455. if (layout.mobile) {
  1456. var size = document.body.getSize();
  1457. width = size.x;
  1458. height = size.y;
  1459. options.style = "viewmobile";
  1460. }
  1461. width = width.toInt();
  1462. height = height.toInt();
  1463. var size = _form.app.content.getSize();
  1464. var x = (size.x - width) / 2;
  1465. var y = (size.y - height) / 2;
  1466. if (x < 0) x = 0;
  1467. if (y < 0) y = 0;
  1468. if (layout.mobile) {
  1469. x = 20;
  1470. y = 0;
  1471. }
  1472. var _self = this;
  1473. MWF.require("MWF.xDesktop.Dialog", function () {
  1474. var dlg = new MWF.xDesktop.Dialog({
  1475. "title": options.title || "select statement view",
  1476. "style": options.style || "view",
  1477. "top": y,
  1478. "left": x - 20,
  1479. "fromTop": y,
  1480. "fromLeft": x - 20,
  1481. "width": width,
  1482. "height": height,
  1483. "html": "<div style='height: 100%;'></div>",
  1484. "maskNode": _form.app.content,
  1485. "container": _form.app.content,
  1486. "buttonList": [
  1487. {
  1488. "text": MWF.LP.process.button.ok,
  1489. "action": function () {
  1490. //if (callback) callback(_self.view.selectedItems);
  1491. if (callback) callback(_self.statement.getData());
  1492. this.close();
  1493. }
  1494. },
  1495. {
  1496. "text": MWF.LP.process.button.cancel,
  1497. "action": function () { this.close(); }
  1498. }
  1499. ]
  1500. });
  1501. dlg.show();
  1502. if (layout.mobile) {
  1503. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1504. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1505. if (backAction) backAction.addEvent("click", function (e) {
  1506. dlg.close();
  1507. }.bind(this));
  1508. if (okAction) okAction.addEvent("click", function (e) {
  1509. //if (callback) callback(this.view.selectedItems);
  1510. if (callback) callback(this.statement.getData());
  1511. dlg.close();
  1512. }.bind(this));
  1513. }
  1514. MWF.xDesktop.requireApp("query.Query", "Statement", function () {
  1515. this.statement = new MWF.xApplication.query.Query.Statement(dlg.content.getFirst(), statementJson, { "style": "select" }, _form.app, _form.Macro);
  1516. }.bind(this));
  1517. }.bind(this));
  1518. }
  1519. }
  1520. };
  1521. //include 引用脚本
  1522. //optionsOrName : {
  1523. // type : "", 默认为process, 可以为 portal process cms
  1524. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  1525. // name : "" // 脚本名称/别名/id
  1526. //}
  1527. //或者name: "" // 脚本名称/别名/id
  1528. // if( !window.includedScripts ){
  1529. // var includedScripts = window.includedScripts = [];
  1530. // }else{
  1531. // var includedScripts = window.includedScripts;
  1532. // }
  1533. var includedScripts = [];
  1534. var _includeSingle = function( optionsOrName , callback, async){
  1535. var options = optionsOrName;
  1536. if( typeOf( options ) == "string" ){
  1537. options = { name : options };
  1538. }
  1539. var name = options.name;
  1540. var type = ( options.type && options.application ) ? options.type : "process";
  1541. var application = options.application || _form.json.application;
  1542. var key = type +"-" + application + "-" + name;
  1543. if (includedScripts.indexOf( key )> -1){
  1544. if (callback) callback.apply(this);
  1545. return;
  1546. }
  1547. //if (includedScripts.indexOf( name )> -1){
  1548. // if (callback) callback.apply(this);
  1549. // return;
  1550. //}
  1551. var scriptAction;
  1552. switch ( type ){
  1553. case "portal" :
  1554. if( this.scriptActionPortal ){
  1555. scriptAction = this.scriptActionPortal;
  1556. }else{
  1557. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  1558. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  1559. }
  1560. break;
  1561. case "process" :
  1562. if( this.scriptActionProcess ){
  1563. scriptAction = this.scriptActionProcess;
  1564. }else{
  1565. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  1566. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  1567. }
  1568. break;
  1569. case "cms" :
  1570. if( this.scriptActionCMS ){
  1571. scriptAction = this.scriptActionCMS;
  1572. }else{
  1573. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1574. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  1575. }
  1576. break;
  1577. }
  1578. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  1579. if (json.data){
  1580. includedScripts.push( key );
  1581. //名称、别名、id
  1582. json.data.importedList.each( function ( flag ) {
  1583. if( type === "portal" ){
  1584. includedScripts.push( type + "-" + json.data.portal + "-" + flag );
  1585. if( json.data.portalName )includedScripts.push( type + "-" + json.data.portalName + "-" + flag );
  1586. if( json.data.portalAlias )includedScripts.push( type + "-" + json.data.portalAlias + "-" + flag );
  1587. }else if( type === "cms" ){
  1588. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  1589. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1590. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1591. }else if( type === "process" ){
  1592. includedScripts.push( type + "-" + json.data.application + "-" + flag );
  1593. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1594. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1595. }
  1596. });
  1597. includedScripts = includedScripts.concat(json.data.importedList);
  1598. MWF.Macro.exec(json.data.text, this);
  1599. if (callback) callback.apply(this);
  1600. }else{
  1601. if (callback) callback.apply(this);
  1602. }
  1603. }.bind(this), null, !!async);
  1604. }
  1605. this.include = function( optionsOrName , callback, async){
  1606. if (o2.typeOf(optionsOrName)=="array"){
  1607. if (!!async){
  1608. var count = optionsOrName.length;
  1609. var loaded = 0;
  1610. optionsOrName.each(function(option){
  1611. _includeSingle.apply(this, [option, function(){
  1612. loaded++;
  1613. if (loaded>=count) if (callback) callback.apply(this);;
  1614. }.bind(this), true]);
  1615. }.bind(this));
  1616. }else{
  1617. optionsOrName.each(function(option){
  1618. _includeSingle.apply(this, [option]);
  1619. }.bind(this));
  1620. if (callback) callback.apply(this);
  1621. }
  1622. }else{
  1623. _includeSingle.apply(this, [optionsOrName , callback, async])
  1624. }
  1625. };
  1626. this.define = function(name, fun, overwrite){
  1627. var over = true;
  1628. if (overwrite===false) over = false;
  1629. var o = {};
  1630. o[name] = {"value": fun, "configurable": over};
  1631. MWF.defineProperties(this, o);
  1632. }.bind(this);
  1633. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  1634. //可在调用前执行 var resolve = this.wait();
  1635. //在异步调用结束后 执行 resolve.cb();
  1636. //目前只有表单的queryload事件支持此方法。
  1637. this.wait = function(){
  1638. var _self = this;
  1639. resolve = {"cb": _self.goon.bind(_self)};
  1640. var setResolve = function(callback){
  1641. resolve.cb = callback;
  1642. }.bind(this);
  1643. this.target.event_resolve = setResolve;
  1644. return resolve;
  1645. }
  1646. //和this.wait配合使用,
  1647. //如果没有异步,则resolve.cb方法不存在,
  1648. //所以在回调中中使用this.goon();使表单继续加载
  1649. this.goon = function(){
  1650. this.target.event_resolve = null;
  1651. }
  1652. //仅前台对象-----------------------------------------
  1653. //form
  1654. this.page = this.form = {
  1655. "getInfor": function(){return ev.formInfor;},
  1656. "infor": ev.formInfor,
  1657. "getApp": function(){return _form.app;},
  1658. "app": _form.app,
  1659. "node": function(){return _form.node;},
  1660. "readonly": _form.options.readonly,
  1661. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  1662. "getField": function(name){return _forms[name];},
  1663. "getAction": function(){return _form.workAction},
  1664. "getDesktop": function(){return _form.app.desktop},
  1665. "getData": function(){return new MWF.xScript.JSONData(_form.getData());},
  1666. "save": function(callback, silent){_form.saveWork(callback, silent); },
  1667. "close": function(){_form.closeWork();},
  1668. "verify": function(){
  1669. return !(!_form.formCustomValidation("", "") || !_form.formValidation("", ""));
  1670. },
  1671. "process": function(option){
  1672. var op = _form.getOpinion();
  1673. var mds = op.medias;
  1674. if (option){
  1675. _form.submitWork(option.routeName, option.opinion, mds, option.callback,
  1676. option.processor, null, option.appendTaskIdentityList, option.processorOrgList, option.callbackBeforeSave );
  1677. }else{
  1678. _form.processWork();
  1679. }
  1680. },
  1681. "reset": function(option){
  1682. if (!option){
  1683. if (_form.businessData.control["allowReset"]) _form.resetWork();
  1684. }else{
  1685. _form.resetWorkToPeson(option.names, option.opinion, option.keep, option.success, option.failure);
  1686. }
  1687. },
  1688. "retract": function(option){
  1689. if (!option){
  1690. if (_form.businessData.control["allowAddSplit"]) _form.addSplit();
  1691. }else{
  1692. _form.doRetractWork(option.success, option.failure);
  1693. }
  1694. },
  1695. "addSplit": function(option){
  1696. if (!option){
  1697. if (_form.businessData.control["allowRetract"]) _form.retractWork();
  1698. }else{
  1699. _form.addSplitWork(option.value, option.success, option.failure);
  1700. }
  1701. },
  1702. "rollback": function(option){
  1703. if (!option){
  1704. if (_form.businessData.control["allowRollback"]) _form.rollback();
  1705. }else{
  1706. _form.doRollbackActionInvoke(option.log, option.flow, option.success, option.failure);
  1707. }
  1708. },
  1709. "print": function(application, form){
  1710. if (arguments.length){
  1711. var app = (arguments.length>1) ? arguments[0] : null;
  1712. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1713. _form.printWork(app, formName);
  1714. }else{
  1715. _form.printWork();
  1716. }
  1717. },
  1718. "deleteWork": function(option){
  1719. if (!option){
  1720. if (_form.businessData.control["allowDelete"]) _form.deleteWork();
  1721. }else{
  1722. _form.doDeleteWork(option.success, option.failure);
  1723. }
  1724. },
  1725. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  1726. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  1727. var p = MWF.getCenter({"x": width, "y": height});
  1728. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1729. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1730. }else{
  1731. e = (arguments.length>1) ? arguments[1] : null;
  1732. title = (arguments.length>2) ? arguments[2] : null;
  1733. text = (arguments.length>3) ? arguments[3] : null;
  1734. width = (arguments.length>4) ? arguments[4] : null;
  1735. height = (arguments.length>5) ? arguments[5] : null;
  1736. ok = (arguments.length>6) ? arguments[6] : null;
  1737. cancel = (arguments.length>7) ? arguments[7] : null;
  1738. callback = (arguments.length>8) ? arguments[8] : null;
  1739. mask = (arguments.length>9) ? arguments[9] : null;
  1740. style = (arguments.length>10) ? arguments[10] : null;
  1741. // var p = MWF.getCenter({"x": width, "y": height});
  1742. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1743. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1744. }
  1745. },
  1746. "alert": function(type, title, text, width, height){
  1747. _form.alert(type, title, text, width, height);
  1748. },
  1749. "notice": function(content, type, target, where, offset, option){
  1750. _form.notice(content, type, target, where, offset, option);
  1751. },
  1752. "addEvent": function(e, f){_form.addEvent(e, f);},
  1753. "openWindow": function(application, form){
  1754. if (arguments.length){
  1755. var app = (arguments.length>1) ? arguments[0] : null;
  1756. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1757. _form.openWindow(formName, app);
  1758. }else{
  1759. _form.openWindow();
  1760. }
  1761. },
  1762. "openWork": function(id, completedId, title, options){
  1763. var op = options || {};
  1764. op.workId = id;
  1765. op.workCompletedId = completedId;
  1766. op.docTitle = title;
  1767. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1768. return layout.desktop.openApplication(this.event, "process.Work", op);
  1769. },
  1770. "openJob": function(id, choice, options){
  1771. var workData = null;
  1772. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  1773. if (json.data) workData = json.data;
  1774. }.bind(this), null, false);
  1775. if (workData){
  1776. var len = workData.workList.length + workData.workCompletedList.length;
  1777. if (len){
  1778. if (len>1 && choice){
  1779. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  1780. workData.workList.each(function(work){
  1781. var workNode = new Element("div", {
  1782. "styles": {
  1783. "background": "#ffffff",
  1784. "border-radius": "10px",
  1785. "clear": "both",
  1786. "margin-bottom": "10px",
  1787. "height": "40px",
  1788. "padding": "10px 10px"
  1789. }
  1790. }).inject(node);
  1791. 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>" +
  1792. "<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>"+
  1793. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1794. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  1795. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  1796. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  1797. workNode.set("html", html);
  1798. var action = workNode.getElement(".MWFAction");
  1799. action.store("work", work);
  1800. action.addEvent("click", function(e){
  1801. var work = e.target.retrieve("work");
  1802. if (work) this.openWork(work.id, null, work.title, options);
  1803. dlg.close();
  1804. }.bind(this));
  1805. }.bind(this));
  1806. workData.workCompletedList.each(function(work){
  1807. var workNode = new Element("div", {
  1808. "styles": {
  1809. "background": "#ffffff",
  1810. "border-radius": "10px",
  1811. "clear": "both",
  1812. "margin-bottom": "10px",
  1813. "height": "40px",
  1814. "padding": "10px 10px"
  1815. }
  1816. }).inject(node);
  1817. 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>" +
  1818. "<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>"+
  1819. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1820. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  1821. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  1822. workNode.set("html", html);
  1823. var action = workNode.getElement(".MWFAction");
  1824. action.store("work", work);
  1825. action.addEvent("click", function(e){
  1826. var work = e.target.retrieve("work");
  1827. if (work) this.openWork(null, work.id, work.title, options);
  1828. dlg.close();
  1829. }.bind(this));
  1830. }.bind(this));
  1831. var height = node.getSize().y+20;
  1832. if (height>600) height = 600;
  1833. var dlg = o2.DL.open({
  1834. "title": o2.LP.widget.choiceWork,
  1835. "style" : "user",
  1836. "isResize": false,
  1837. "content": node,
  1838. "buttonList": [
  1839. {
  1840. "type" : "cancel",
  1841. "text": o2.LP.widget.close,
  1842. "action": function(){dlg.close();}
  1843. }
  1844. ]
  1845. });
  1846. }else{
  1847. if (workData.workList.length){
  1848. var work = workData.workList[0];
  1849. return this.openWork(work.id, null, work.title, options);
  1850. }else{
  1851. var work = workData.workCompletedList[0];
  1852. return this.openWork(null, work.id, work.title, options);
  1853. }
  1854. }
  1855. }
  1856. }
  1857. // var op = options || {};
  1858. // op.workId = id;
  1859. // op.workCompletedId = completedId;
  1860. // op.docTitle = title;
  1861. // op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1862. // layout.desktop.openApplication(this.event, "process.Work", op);
  1863. },
  1864. "openDocument": function(id, title, options){
  1865. var op = options || {};
  1866. op.documentId = id;
  1867. op.docTitle = title;
  1868. layout.desktop.openApplication(this.event, "cms.Document", op);
  1869. },
  1870. "openPortal": function(name, page, par){
  1871. var action = MWF.Actions.get("x_portal_assemble_surface");
  1872. action.getApplication(name, function(json){
  1873. if (json.data){
  1874. if (page){
  1875. action.getPageByName(page, json.data.id, function(pageJson){
  1876. layout.desktop.openApplication(null, "portal.Portal", {
  1877. "portalId": json.data.id,
  1878. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1879. "parameters": par,
  1880. "appId": "portal.Portal"+json.data.id
  1881. })
  1882. });
  1883. }else{
  1884. layout.desktop.openApplication(null, "portal.Portal", {
  1885. "portalId": json.data.id,
  1886. "parameters": par,
  1887. "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. };