Environment.js 141 KB

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