Environment.js 166 KB

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