Environment.js 127 KB

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