Environment.js 160 KB

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