Environment.js 166 KB

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