Environment.js 166 KB

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