Environment.js 166 KB

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