Environment.js 160 KB

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