Environment.js 166 KB

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