Environment.js 229 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.xScript.Environment = function(ev){
  3. var _data = ev.data;
  4. var _form = ev.form;
  5. var _forms = ev.forms;
  6. this.appType = "process";
  7. this.library = COMMON;
  8. //this.library.version = "4.0";
  9. this.power = {
  10. "isManager": MWF.AC.isProcessManager() || _form.businessData.control.allowReroute,
  11. "isReseter": _form.businessData.control.allowReset,
  12. "isDelete": _form.businessData.control.allowDeleteWork,
  13. "isPront": true,
  14. "isPrint": true
  15. };
  16. //data
  17. var getJSONData = function(jData){
  18. return new MWF.xScript.JSONData(jData, function(data, key, _self){
  19. var p = {"getKey": function(){return key;}, "getParent": function(){return _self;}};
  20. while (p && !_forms[p.getKey()]) p = p.getParent();
  21. //if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
  22. var k = (p) ? p.getKey() : "";
  23. if (k) if(_forms[k]) if(_forms[k].resetData) _forms[k].resetData();
  24. //if(p) if(p.getKey()) if(_forms[p.getKey()]) if(_forms[p.getKey()].render) _forms[p.getKey()].render();
  25. }, "", null, _form);
  26. };
  27. this.setData = function(data){
  28. /**
  29. * data对象是流程平台中,流程实例的业务数据;以及内容管理平台中,文档实例的业务数据。<br/>
  30. * 这些数据一般情况下是通过您创建的表单收集而来的,也可以通过脚本进行创建和增删改查操作。<br/>
  31. * data对象基本上是一个Object对象,您可以用访问Object对象的方法访问data对象的所有数据,但增加和删除数据时略有不同。
  32. * @module data
  33. * @o2cn 业务数据
  34. * @o2category web
  35. * @o2ordernumber 10
  36. * @example
  37. * //您可以在表单或流程的各个嵌入脚本中,通过this来获取当前实例的业务数据,如下:
  38. * var data = this.data;
  39. */
  40. this.data = getJSONData(data);
  41. /**
  42. * 访问或修改data对象的数据。<br/><br/>
  43. * data数据用于存储表单获取的数据,所有属性都是动态的,其格式和访问方式都和JSON类似。<br/>
  44. * 在表单脚本中使用data对象,实现了data和表单可编辑元素的双向绑定。<br/>
  45. * 改变data对象,会自动更新表单元素,修改表单可编辑元素,也会自动修改data对象。<br/>
  46. * <b>数据赋值(this.data.subject = '')仅适用于表单上有该字段组件;建议使用this.data.add("subject","",true)方法,适用所有情况。</b>
  47. * @member {String|Number} [[property]]
  48. * @memberOf module:data
  49. * @instance
  50. * @example
  51. * var value = this.data.subject; //获取名为subject的数据值
  52. *
  53. * //将subject的值修改为'123'。
  54. * //需要注意的是,用这种方式创建新字段,必须要在当前表单上有一个名为‘subject’的字段组件。
  55. * //如果表单上没有该组件,可以使用this.data.add('subject','123',true)。给已有字段赋值则没有这个限制。
  56. * this.data.subject = '123';
  57. *
  58. * @example
  59. * <caption>
  60. * <b>获取流程文档中的数据网格的值</b>:<br/>
  61. * 如有以下数据网格:
  62. * <img src="img/module/data/datagrid.jpg">
  63. * 其数据网格设计如下(数据网格id为:datagrid):
  64. * <img src="img/module/data/datagridDesign.jpg">
  65. * </caption>
  66. * //获取流程文档中的数据网格的值
  67. * var data = this.data.datagrid;
  68. *
  69. * //获取到的data值格式如下:
  70. * {
  71. * "data": [
  72. * {
  73. * "amountCol": { "amount": "12000" },
  74. * "countCol": { "number": "10" },
  75. * "nameCol": { "name": "手机" },
  76. * "priceCol": { "price": "1200" }
  77. * },
  78. * {
  79. * "amountCol": { "amount": "15000" },
  80. * "countCol": { "number": "5" },
  81. * "nameCol": { "name": "电脑" },
  82. * "priceCol": { "price": "3000" }
  83. * }
  84. * ],
  85. * "total": {
  86. * "amountCol": "27000",
  87. * "countCol": "15"
  88. * }
  89. * }
  90. *
  91. *
  92. * //获取到数据网格中的其他数据:
  93. *
  94. * //获取数据网格中的第一条数据
  95. * var data = this.data.datagrid.data[0];
  96. *
  97. * //获取数据网格中的第一条数据的 nameCol 列的值
  98. * var data = this.data.datagrid.data[0].nameCol.name;
  99. *
  100. * //获取数据网格中的 amountCol 列的总计值
  101. * var data = this.data.datagrid.total.amountCol;
  102. *
  103. *@example
  104. * <caption>
  105. * <b>修改数据网格中的数据</b></br>
  106. * 经过本样例修改后,数据网格将变为:</br>
  107. * <img src="img/module/data/datagrid2.jpg">
  108. * </caption>
  109. * //修改数据网格中的第一条数据的 nameCol 列的值
  110. * this.data.datagrid.data[0].nameCol.name='平板电脑';
  111. */
  112. /**
  113. * 为data对象添加一个数据节点。
  114. * @instance
  115. * @method add
  116. * @memberOf module:data
  117. * @param {(String|Number)} key - 要添加的新的数据节点名称或数组索引号。
  118. * @param {(String|Number|Array|JsonObject)} value - 新的数据节点的值。
  119. * @param {Boolean} [overwrite] - 如果要添加的节点已经存在,是否覆盖。默认为 false。
  120. * @return {(String|Number|Array|JsonObject)} 新添加的数据节点或原有的同名节点。
  121. * @o2syntax
  122. * var newData = this.data.add(key, value, overwrite);
  123. * @example
  124. * //为data添加一个名为"remark"值为"I am remark"的数据
  125. * this.data.add("remark", "I am remark");
  126. * @example
  127. * //为data添加一个名为"person"的Object对象数据
  128. * var person = this.data.add("person", {});
  129. * person.add("name", "Tom");
  130. * person.add("age", 23);
  131. *
  132. * //或者可以这样
  133. * var person = this.data.add("person", {name: "Tom", "age": "23"});
  134. * @example
  135. * //为data添加一个名为"orders"的数组对象数据
  136. * var orders = this.data.add("orders", []);
  137. * orders.add({name: "phone", count: 5});
  138. * orders.add({name: "computer", count: 10});
  139. * orders[0].add("count", 10, true); //将第一条数据的count修改为10
  140. *
  141. * //或者可以这样
  142. * var orders = this.data.add("orders", [
  143. * {name: "phone", count: 5},
  144. * {name: "computer", count: 10}
  145. * ]);
  146. * //将第一条数据修改为name为mobile; count为10
  147. * orders.add(0, {name: "mobile", count: 10}, true);
  148. */
  149. /**保存data对象。不触发事件。
  150. * 不建议在queryLoad、beforeSave和afterSave中使用本方法。
  151. * @method save
  152. * @static
  153. * @memberOf module:data
  154. * @param {Function} [callback] - 保存成功后的回调函数。
  155. * @o2syntax
  156. * this.data.save(callback);
  157. * @example
  158. * this.data.save(function(json){
  159. * this.form.notice("save success!", "success")
  160. *});
  161. */
  162. this.data.save = function(callback){
  163. _form.saveFormData(callback)
  164. // var formData = {
  165. // "data": data,
  166. // "sectionList": _form.getSectionList()
  167. // };
  168. // _form.workAction.saveSectionData(function(){if (callback) callback();}.bind(this), null, (ev.work.id || ev.workCompleted.id), formData);
  169. }
  170. };
  171. this.setData(_data);
  172. //task
  173. //this.task = ev.task;
  174. //this.task.process = function(routeName, opinion, callback){
  175. // _form.submitWork(routeName, opinion, callback);
  176. //};
  177. //inquiredRouteList
  178. //this.inquiredRouteList = null;
  179. //workContext
  180. var _getWorkContextList = function(method, id, callback, error){
  181. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  182. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  183. var list;
  184. var p = o2.Actions.get("x_processplatform_assemble_surface")[method](id, function(json){
  185. list = json.data;
  186. if (cb) cb(list);
  187. return list;
  188. }, ecb, !!callback);
  189. return (!!callback) ? p : list;
  190. };
  191. /**
  192. * 您可以通过workContext获取和流程相关的流程实例对象数据。
  193. * @module workContext
  194. * @o2cn 流程实例
  195. * @o2category web
  196. * @o2range {Process}
  197. * @o2ordernumber 20
  198. * @o2syntax
  199. * //您可以在表单或流程的各个嵌入脚本中,通过this来获取当前流程实例数据,如下:
  200. * var context = this.workContext;
  201. */
  202. this.workContext = {
  203. // * <div><br/>
  204. // * 下面的Work对象和WorkCompleted对象为后台返回的数据,在前端脚本中我们对这两个对象进行了修改和补充,如下:
  205. // * </div>
  206. // * <pre><code class='language-js'>{
  207. // * "creatorPersonDn": "张三@zhangsan@P", //创建人,可能为空,如果由系统创建.
  208. // * "creatorPerson": "张三", //创建人姓名
  209. // * "creatorIdentityDn": "张三@481c9edc-5fb5-41f1-b5c2-6ea609082cdb@I", //创建人Identity,可能为空,如果由系统创建.
  210. // * "creatorIdentity": "张三" //创建人姓名
  211. // * "creatorUnitDn": "开发部@c448d8bb-98b8-4305-9d3f-12537723cfcc@U", //创建人组织全称,如果由系统创建。
  212. // * "creatorUnit": "开发部", //创建人组织名称
  213. // * "creatorDepartment": "开发部", //创建人组织名称,同creatorUnit
  214. // * "creatorCompany": "xx公司" //创建人顶层组织名称,creatorUnitLevelName的第一段
  215. // * }</code></pre>
  216. /**
  217. * 获取当前流程实例对象:work对象或workCompleted对象。
  218. * @method getWork
  219. * @static
  220. * @return {(Work|WorkCompleted)} 流程实例对象;如果流程已结束,返回已结束的流程实例对象。
  221. * @o2ActionOut x_processplatform_assemble_surface.WorkAction.manageGet|example=WorkParsed|extension=Work|ignoreNoDescr=true|ignoreProps=[properties,manualTaskIdentityMatrix]|Work对象:
  222. * @o2ActionOut x_processplatform_assemble_surface.WorkCompletedAction.get|example=WorkCompletedParsed|extension=Work|ignoreProps=[properties,data,taskCompletedList,readCompletedList,reviewList,recordList,workLogList,storeForm,mobileStoreForm]|WorkCompleted对象:
  223. * @o2syntax
  224. * var work = this.workContext.getWork();
  225. */
  226. "getWork": function(){return ev.work || ev.workCompleted;},
  227. /**
  228. * 获取当前流程实例所在的活动节点对象:activity对象。
  229. * @method getActivity
  230. * @static
  231. * @return {(Activity|Null)} 当前流程实例所在的活动节点对象,如果当前流程实例已流转完成,则返回null.
  232. * <pre><code class='language-js'>{
  233. * "id": "801087c5-a4e6-4b91-bf4d-a81cdaa04471", //节点ID
  234. * "name": "办理", //节点名称
  235. * "description": "", //节点描述
  236. * "alias": "", //节点别名
  237. * "resetRange": "department", //重置处理人范围
  238. * "resetCount": 0, //重置处理人数字
  239. * "allowReset": true, //是否允许重置
  240. * "manualMode": "single", //处理方式 单人single, 并行parallel, 串行queue, grab抢办
  241. * "customData": { //节点上的自定义属性,如果没有设置,不输出该值
  242. *
  243. * }
  244. * }</code></pre>
  245. * @o2syntax
  246. * var activity = this.workContext.getActivity();
  247. */
  248. "getActivity": function(){return ev.activity || null;},
  249. // * <div><br/>
  250. // * 下面的Task对象为后台返回的数据,脚本中我们对这它进行了修改和补充,如下:
  251. // * </div>
  252. // * <pre><code class='language-js'>{
  253. // * "personDn": "张三@zhangsan@P", //创建人,可能为空,如果由系统创建.
  254. // * "person": "张三", //创建人姓名
  255. // * "identityDn": "张三@481c9edc-5fb5-41f1-b5c2-6ea609082cdb@I", //创建人Identity,可能为空,如果由系统创建.
  256. // * "identity": "张三" //创建人姓名
  257. // * "unitDn": "开发部@c448d8bb-98b8-4305-9d3f-12537723cfcc@U", //创建人组织全称,如果由系统创建。
  258. // * "unit": "开发部", //创建人组织名称
  259. // * "department": "开发部", //创建人组织名称,unit
  260. // * "customData": {}, //流程活动上配置的自定义属性
  261. // * }</code></pre>
  262. /**
  263. * 当前流程实例正在流转中,并且当前用户有待办,则返回当前用户的待办对象,否则返回null。
  264. * @summary 获取当前流程与当前用户相关的待办对象:task对象。
  265. * @o2ActionOut x_processplatform_assemble_surface.TaskAction.get|example=TaskParsed|extension=Task|Task对象:
  266. * @method getTask
  267. * @static
  268. * @return {(Task|Null)} 当前用户的待办任务对象:task。当前用户没有对此流程实例的待办时,或流程实例已经流转结束,返回null。
  269. * @o2syntax
  270. * var task = this.workContext.getTask();
  271. */
  272. "getTask": function(){return ev.task || null;},
  273. /**
  274. * 获取当前流程实例的所有待办对象。如果流程实例已流转完成,则返回一个空数组。
  275. * @method getTaskList
  276. * @o2ActionOut x_processplatform_assemble_surface.TaskAction.listWithWork|example=Task
  277. * @static
  278. * @param {Function|Boolean} [callback] 正确获取待办数组的回调,或者一个布尔值,如果此参数判断为true,则本方法以异步执行,并返回Promise,否则同步执行
  279. * @param {Function} [error] 获取待办数组出错时的回调。
  280. * @return {(Task[]|Promise)} 待办任务列表,或resolve了待办对象列表的Promise对象.
  281. * @o2syntax
  282. * //本样例以同步执行
  283. * var taskList = this.workContext.getTaskList();
  284. * @o2syntax
  285. * //本样例以异步执行
  286. * this.workContext.getTaskList( function(taskList){
  287. * //taskList 为待办数组
  288. * });
  289. * @o2syntax
  290. * //本样例使用Promise
  291. * this.workContext.getTaskList(true).then(function(taskList){
  292. * //taskList 为待办数组
  293. * });
  294. */
  295. "getTaskList": function(callback, error){
  296. if( ev.work.completedTime )return [];
  297. return _getWorkContextList("listTaskByWork", ev.work.id, callback, error);
  298. // var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  299. // var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  300. // var list;
  301. // var p = o2.Actions.get("x_processplatform_assemble_surface").listTaskByWork(ev.work.id, function(json){
  302. // list = json.data;
  303. // if (cb) cb(list);
  304. // return list;
  305. // }, ecb, !!callback);
  306. // return (!!callback) ? p : list;
  307. },
  308. /**
  309. * 根据当前工作的job获取当前流程实例的所有待办对象。如果流程实例已流转完成,则返回一个空数组。
  310. * @method getTaskListByJob
  311. * @o2ActionOut x_processplatform_assemble_surface.TaskAction.listWithJob|example=Task
  312. * @static
  313. * @param {Function|Boolean} [callback] 正确获取待办数组的回调,或者一个布尔值,如果此参数判断为true,则本方法以异步执行,并返回Promise,否则同步执行
  314. * @param {Function} [error] 获取待办数组出错时的回调。
  315. * @return {(Task[]|Promise)} 待办任务列表,或resolve了待办对象列表的Promise对象.
  316. * @o2syntax
  317. * //本样例以同步执行
  318. * var taskList = this.workContext.getTaskListByJob();
  319. * @o2syntax
  320. * //本样例以异步执行
  321. * this.workContext.getTaskListByJob( function(taskList){
  322. * //taskList 为待办数组
  323. * });
  324. * @o2syntax
  325. * //本样例使用Promise
  326. * this.workContext.getTaskListByJob(true).then(function(taskList){
  327. * //taskList 为待办数组
  328. * });
  329. */
  330. "getTaskListByJob": function(callback, error){
  331. return _getWorkContextList("listTaskByJob", ev.work.job, callback, error);
  332. // var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  333. // var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  334. // var list;
  335. // var p = o2.Actions.get("x_processplatform_assemble_surface").listTaskByJob(ev.work.job, function(json){
  336. // list = json.data;
  337. // if (cb) cb(list);
  338. // return list;
  339. // }, ecb, !!callback);
  340. // return (!!callback) ? p : list;
  341. },
  342. /**
  343. * 获取当前流程实例的所有已办对象。如果流程实例没有任何人处理过,则返回一个空数组。
  344. * @method getTaskCompletedList
  345. * @static
  346. * @param {Function|Boolean} [callback] 正确获取已办数组的回调,或者一个布尔值,如果此参数判断为true,则本方法以异步执行,并返回Promise,否则同步执行
  347. * @param {Function} [error] 获取已办数组出错时的回调。
  348. * @return {(TaskCompleted[]|Promise)} 已办任务列表,或resolve了已办对象列表的Promise对象.
  349. * @o2ActionOut x_processplatform_assemble_surface.TaskCompletedAction.listWithWork|example=Task
  350. * @o2syntax
  351. * //本样例以同步执行
  352. * var taskCompletedList = this.workContext.getTaskCompletedList();
  353. * @o2syntax
  354. * //本样例以异步执行
  355. * this.workContext.getTaskCompletedList(function(taskCompletedList){
  356. * //taskCompletedList 为已办数组
  357. * });
  358. * @o2syntax
  359. * //本样例使用Promise
  360. * this.workContext.getTaskCompletedList(true).then(function(taskCompletedList){
  361. * //taskCompletedList 为已办数组
  362. * });
  363. */
  364. "getTaskCompletedList": function(callback, error){
  365. return _getWorkContextList("listTaskCompletedByWorkOrWorkCompleted", ev.work.id, callback, error);
  366. // var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  367. // var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  368. // var list;
  369. // var p = o2.Actions.get("x_processplatform_assemble_surface").listTaskCompletedByWork(ev.work.id, function(json){
  370. // list = json.data;
  371. // if (cb) cb(list);
  372. // }, ecb, !!callback);
  373. // return (!!callback) ? p : list;
  374. },
  375. /**
  376. * 根据当前工作的job获取当前流程实例的所有已办对象。如果流程实例没有任何人处理过,则返回一个空数组。
  377. * @method getTaskCompletedListByJob
  378. * @static
  379. * @param {Function|Boolean} [callback] 正确获取已办数组的回调,或者一个布尔值,如果此参数判断为true,则本方法以异步执行,并返回Promise,否则同步执行
  380. * @param {Function} [error] 获取已办数组出错时的回调。
  381. * @return {(TaskCompleted[]|Promise)} 已办任务列表,或resolve了已办对象列表的Promise对象.
  382. * @o2ActionOut x_processplatform_assemble_surface.TaskCompletedAction.listWithJob|example=Task
  383. * @o2syntax
  384. * //本样例以同步执行
  385. * var taskCompletedList = this.workContext.getTaskCompletedListByJob();
  386. * @o2syntax
  387. * //本样例以异步执行
  388. * this.workContext.getTaskCompletedListByJob( function(taskCompletedList){
  389. * //taskCompletedList 为已办数组
  390. * });
  391. * @o2syntax
  392. * //本样例使用Promise
  393. * this.workContext.getTaskCompletedListByJob(true).then(function(taskCompletedList){
  394. * //taskCompletedList 为已办数组
  395. * });
  396. */
  397. "getTaskCompletedListByJob": function(callback, error){
  398. return _getWorkContextList("listTaskCompletedByJob", ev.work.job, callback, error);
  399. // var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  400. // var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  401. // var list;
  402. // var p = o2.Actions.get("x_processplatform_assemble_surface").listTaskCompletedByJob(ev.work.job, function(json){
  403. // list = json.data;
  404. // if (cb) cb(list);
  405. // }, ecb, !!callback);
  406. // return (!!callback) ? p : list;
  407. },
  408. /**
  409. * @summary 获取当前流程实例的所有待阅对象数组。如果流程实例无待阅,则返回一个空数组。
  410. * @method getReadList
  411. * @static
  412. * @param {Function|Boolean} [callback] 正确获取待阅数组的回调,或者一个布尔值,如果此参数判断为true,则本方法以异步执行,并返回Promise,否则同步执行
  413. * @param {Function} [error] 获取待阅数组出错时的回调。
  414. * @return {(Read[]|Promise)} 当前流程实例的所有待阅对象数组, 或resolve了待阅对象列表的Promise对象.
  415. * @o2ActionOut x_processplatform_assemble_surface.ReadAction.get|example=Read
  416. * @o2syntax
  417. * //本样例以同步执行
  418. * var readList = this.workContext.getReadList();
  419. * @o2syntax
  420. * //本样例以异步执行
  421. * this.workContext.getReadList( function(readList){
  422. * //readList 为待阅数组
  423. * });
  424. * @o2syntax
  425. * //本样例使用Promise
  426. * this.workContext.getReadList(true).then(function(readList){
  427. * //readList 为待阅数组
  428. * });
  429. */
  430. "getReadList": function(callback, error){
  431. return _getWorkContextList("listReadByWorkOrWorkCompleted", ev.work.id, callback, error);
  432. // var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  433. // var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  434. // var list;
  435. // o2.Actions.get("x_processplatform_assemble_surface").listReadByWork(ev.work.id, function(json){
  436. // list = json.data;
  437. // if (cb) cb(list);
  438. // }, ecb, !!cb);
  439. // return list;
  440. },
  441. /**
  442. * @summary 根据当前工作的job获取当前流程实例的所有待阅对象。如果流程实例无待阅,则返回一个空数组。
  443. * @method getReadListByJob
  444. * @static
  445. * @param {Function|Boolean} [callback] 正确获取待阅数组的回调,或者一个布尔值,如果此参数判断为true,则本方法以异步执行,并返回Promise,否则同步执行
  446. * @param {Function} [error] 获取待阅数组出错时的回调。
  447. * @return {(Read[]|Promise)} 当前流程实例的所有待阅对象数组, 或resolve了待阅对象列表的Promise对象.
  448. * @o2ActionOut x_processplatform_assemble_surface.ReadAction.listWithJob|example=Read
  449. * @o2syntax
  450. * //本样例以同步执行
  451. * var readList = this.workContext.getReadListByJob();
  452. * @o2syntax
  453. * //本样例以异步执行
  454. * this.workContext.getReadListByJob( function(readList){
  455. * //readList 为待阅数组
  456. * });
  457. * @o2syntax
  458. * //本样例使用Promise
  459. * this.workContext.getReadListByJob(true).then(function(readList){
  460. * //readList 为待阅数组
  461. * });
  462. */
  463. "getReadListByJob": function(callback, error){
  464. return _getWorkContextList("listReadByJob", ev.work.job, callback, error);
  465. // var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  466. // var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  467. // var list;
  468. // o2.Actions.get("x_processplatform_assemble_surface").listReadByJob(ev.work.job, function(json){
  469. // list = json.data;
  470. // if (cb) cb(list);
  471. // }, ecb, !!cb);
  472. // return list;
  473. },
  474. /**
  475. * @summary 获取当前流程实例的所有已阅对象。如果流程实例没有已阅,则返回一个空数组。
  476. * @method getReadCompletedList
  477. * @static
  478. * @param {Function|Boolean} [callback] 正确获取已阅数组的回调,或者一个布尔值,如果此参数判断为true,则本方法以异步执行,并返回Promise,否则同步执行
  479. * @param {Function} [error] 获取已阅数组出错时的回调。
  480. * @return {(ReadCompleted[]|Promise)} 当前流程实例的所有已阅对象数组, 或resolve了已阅对象列表的Promise对象.
  481. * @o2ActionOut x_processplatform_assemble_surface.ReadCompletedAction.listWithWork|example=Read
  482. * @o2syntax
  483. * //本样例以同步执行
  484. * var readCompletedList = this.workContext.getReadCompletedList();
  485. * @o2syntax
  486. * //本样例以异步执行
  487. * this.workContext.getReadCompletedList( function(readCompletedList){
  488. * //readCompletedList 为已阅数组
  489. * });
  490. * @o2syntax
  491. * //本样例使用Promise
  492. * this.workContext.getReadCompletedList(true).then(function(readCompletedList){
  493. * //readCompletedList 为已阅数组
  494. * });
  495. */
  496. "getReadCompletedList": function(callback, error){
  497. return _getWorkContextList("listReadCompletedByWorkOrWorkCompleted", ev.work.id, callback, error);
  498. // var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  499. // var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  500. // var list;
  501. // o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByWork(ev.work.id, function(json){
  502. // list = json.data;
  503. // if (cb) cb(list);
  504. // }, ecb, !!cb);
  505. // return list;
  506. },
  507. /**
  508. * @summary 根据当前工作的job获取当前流程实例的所有已阅对象。如果流程实例没有已阅,则返回一个空数组。
  509. * @method getReadCompletedListByJob
  510. * @static
  511. * @param {Function|Boolean} [callback] 正确获取已阅数组的回调,或者一个布尔值,如果此参数判断为true,则本方法以异步执行,并返回Promise,否则同步执行
  512. * @param {Function} [error] 获取已阅数组出错时的回调。
  513. * @return {(ReadCompleted[]|Promise)} 当前流程实例的所有已阅对象数组, 或resolve了已阅对象列表的Promise对象.
  514. * @o2ActionOut x_processplatform_assemble_surface.ReadCompletedAction.listWithJob|example=Read
  515. * @o2syntax
  516. * //本样例以同步执行
  517. * var readCompletedList = this.workContext.getReadCompletedListByJob();
  518. * @o2syntax
  519. * //本样例以异步执行
  520. * this.workContext.getReadCompletedListByJob( function(readCompletedList){
  521. * //readCompletedList 为已阅数组
  522. * });
  523. * @o2syntax
  524. * //本样例使用Promise
  525. * this.workContext.getReadCompletedListByJob(true).then(function(readCompletedList){
  526. * //readCompletedList 为已阅数组
  527. * });
  528. */
  529. "getReadCompletedListByJob": function(callback, error){
  530. return _getWorkContextList("listReadCompletedByJob", ev.work.job, callback, error);
  531. // var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  532. // var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  533. // var list;
  534. // o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByJob(ev.work.job, function(json){
  535. // list = json.data;
  536. // if (cb) cb(list);
  537. // }, ecb, !!cb);
  538. // return list;
  539. },
  540. /**
  541. * @summary 根据当前工作的job获取当前流程实例的所有review对象。如果流程实例没有review,则返回一个空数组。
  542. * @method getReviewList
  543. * @static
  544. * @param {Function|Boolean} [callback] 正确获取review数组的回调,或者一个布尔值,如果此参数判断为true,则本方法以异步执行,并返回Promise,否则同步执行
  545. * @param {Function} [error] 获取已阅数组出错时的回调。
  546. * @return {(Review[]|Promise)} 当前流程实例的所有review对象数组, 或resolve了review对象列表的Promise对象.
  547. * @o2ActionOut x_processplatform_assemble_surface.ReviewAction.listWithJob|example=Review
  548. * @o2syntax
  549. * //本样例以同步执行
  550. * var reviewList = this.workContext.getReviewList();
  551. * @o2syntax
  552. * //本样例以异步执行
  553. * this.workContext.getReviewList( function(reviewList){
  554. * //reviewList 为review对象数组
  555. * });
  556. * @o2syntax
  557. * //本样例使用Promise
  558. * this.workContext.getReviewList(true).then(function(reviewList){
  559. * //reviewList 为review对象数组
  560. * });
  561. */
  562. "getReviewList": function(callback, error){
  563. return _getWorkContextList("listReviewByJob", ev.work.job, callback, error);
  564. // var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  565. // var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  566. // var list;
  567. // o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByJob(ev.work.job, function(json){
  568. // list = json.data;
  569. // if (cb) cb(list);
  570. // }, ecb, !!cb);
  571. // return list;
  572. },
  573. /**
  574. * @summary 与getReviewList方法相同。
  575. * @method getReviewListByJob
  576. * @static
  577. * @see module:workContext.getReviewList
  578. */
  579. "getReviewListByJob": this.getReviewList,
  580. /**
  581. * @summary getTaskListByJob方法的别名。
  582. * @method getJobTaskList
  583. * @static
  584. * @see module:workContext.getTaskListByJob
  585. */
  586. "getJobTaskList": this.getTaskListByJob,
  587. /**
  588. * @summary getReadListByJob方法的别名。
  589. * @method getJobReadList
  590. * @static
  591. * @see module:workContext.getReadListByJob
  592. */
  593. "getJobReadList": this.getReadListByJob,
  594. /**
  595. * @summary getTaskCompletedListByJob方法的别名。
  596. * @method getJobTaskCompletedList
  597. * @static
  598. * @see module:workContext.getTaskCompletedListByJob
  599. */
  600. "getJobTaskCompletedList": this.getTaskCompletedListByJob,
  601. /**
  602. * @summary getReadCompletedListByJob方法的别名。
  603. * @method getJobReadCompletedList
  604. * @static
  605. * @see module:workContext.getReadCompletedListByJob
  606. */
  607. "getJobReadCompletedList": this.getReadCompletedListByJob,
  608. /**
  609. * @summary 与getReviewList方法相同。
  610. * @method getJobReviewList
  611. * @static
  612. * @see module:workContext.getReviewList
  613. */
  614. "getJobReviewList": this.getReviewList,
  615. /**
  616. * @summary 获取当前人对流程实例的权限。
  617. * @method getControl
  618. * @static
  619. * @return {WorkControl} 流程实例权限对象.
  620. * <pre><code class='language-js'>{
  621. * "allowVisit": true, //是否允许访问工作
  622. * "allowFlow": true, //是否允许继续流转(允许提交或重置处理人或加签)
  623. * "allowProcessing": true, //是否允许提交
  624. * "allowReadProcessing": false, //是否有待阅
  625. * "allowSave": true, //是否允许保存业务数据
  626. * "allowReset": false, //是否允许重置处理人
  627. * "allowReroute": false, //是否允许调度
  628. * "allowDelete": true, //是否允许删除流程实例
  629. * "allowAddSplit": false, //是否允许添加拆分分支
  630. * "allowRetract": false, //是否允许撤回
  631. * "allowRollback": false, //是否允许回溯流程
  632. * "allowPress": false, //是否允许发送办理提醒
  633. * "allowGoBack": false, //是否允许回退
  634. * "allowAddTask": false, //是否允许加签
  635. * "allowPause": false, //是否允许待办挂起
  636. * "allowResume": false, //是否允许待办从挂起状态恢复
  637. * }</code></pre>
  638. * @o2syntax
  639. * var control = this.workContext.getControl();
  640. */
  641. "getControl": function(){return ev.control;},
  642. /**
  643. * @summary 获取当前流程实例的所有流程记录(WorkLog)。
  644. * @method getWorkLogList
  645. * @static
  646. * @return {WorkLog[]} 流程记录对象.
  647. * @o2ActionOut x_processplatform_assemble_surface.WorkLogAction.listWithJob|example=WorkLog|ignoreProps=[properties,goBackFromActivityType]
  648. * @o2syntax
  649. * var workLogList = this.workContext.getWorkLogList();
  650. */
  651. "getWorkLogList": function(){return ev.workLogList;},
  652. /**
  653. * @summary 获取当前流程实例的所有流程记录(Record)。
  654. * @method getRecordList
  655. * @o2ActionOut x_processplatform_assemble_surface.RecordAction.listWithJob|example=Record
  656. * @static
  657. * @return {Record[]} 流程记录(Record)对象.
  658. * @o2syntax
  659. * var recordList = this.workContext.getRecordList();
  660. */
  661. "getRecordList": function(){return ev.recordList;},
  662. /**
  663. * @summary 获取当前流程实例的附件对象列表。
  664. * @method getAttachmentList
  665. * @static
  666. * @param {Function|boolean} [callback] 如果传入Funcation, 则作为正确获取附件对象数组的异步调用的回调;
  667. * 如果传入true,则发起异步请求获取附件列表,返回Promise对象;如果传入false, 则发起同步请求获取附件列表;
  668. * 如果不传入参数,则直接返回本地缓存中的attachmentList对象。
  669. * @param {Function} [error] 获取附件对象数组出错时的回调。
  670. * @return {WorkAttachmentData[]} 附件数据.
  671. * @o2ActionOut x_processplatform_assemble_surface.AttachmentAction.getWithWorkOrWorkCompleted|example=Attachment|ignoreProps=[properties]
  672. * @o2syntax
  673. * //从本地缓存获取附件列表
  674. * var attachmentList = this.workContext.getAttachmentList();
  675. *
  676. * //同步请求获取附件列表
  677. * var attachmentList = this.workContext.getAttachmentList(false);
  678. *
  679. * //异步请求获取附件列表
  680. * var promise = this.workContext.getAttachmentList(true);
  681. * promise.then(function(attachmentList){
  682. * //attachmentList 附件对象数组
  683. * })
  684. *
  685. * //异步请求获取附件列表
  686. * this.workContext.getAttachmentList( function(attachmentList){
  687. * //attachmentList 附件对象数组
  688. * });
  689. */
  690. "getAttachmentList": function(callback, error){
  691. if (!callback && callback !== false) {
  692. return ev.attachmentList;
  693. }
  694. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  695. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  696. var list;
  697. var p = o2.Actions.load("x_processplatform_assemble_surface").AttachmentAction.listWithJob(ev.work.job, function(json){
  698. list = json.data;
  699. if (cb) cb(list);
  700. return list;
  701. }, ecb, !!callback);
  702. return (callback) ? p : list;
  703. },
  704. /**
  705. * @summary 获取当前待办的可选路由。与task对象中的routeNameList取值相同。
  706. * @method getRouteList
  707. * @static
  708. * @return {String[]} 路由字符串数组.
  709. * @o2syntax
  710. * var routeList = this.workContext.getRouteList();
  711. */
  712. "getRouteList": function(){return (ev.task) ? ev.task.routeNameList: null;},
  713. "getInquiredRouteList": function(){return null;}
  714. // /**
  715. // * @summary 重新设置流程实例标题。。
  716. // * @method setTitle
  717. // * @static
  718. // * @param {String} title - 标题字符串.
  719. // * @o2syntax
  720. // * this.workContext.setTitle(title);
  721. // * @example
  722. // * this.workContext.setTitle("标题");
  723. // */
  724. // "setTitle": function(title){
  725. // if (!this.workAction){
  726. // MWF.require("MWF.xScript.Actions.WorkActions", null, false);
  727. // this.workAction = new MWF.xScript.Actions.WorkActions();
  728. // }
  729. // this.workAction.setTitle(ev.work.id, {"title": title});
  730. // }
  731. };
  732. this.workContent = this.workContext;
  733. var _redefineWorkProperties = function(work){
  734. if (work){
  735. work.creatorPersonDn = work.creatorPerson ||"";
  736. work.creatorUnitDn = work.creatorUnit ||"";
  737. work.creatorUnitDnList = work.creatorUnitList ||"";
  738. work.creatorIdentityDn = work.creatorIdentity ||"";
  739. var o = {
  740. "creatorPerson": {"get": function(){return this.creatorPersonDn.substring(0, this.creatorPersonDn.indexOf("@"));}},
  741. "creatorUnit": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  742. "creatorDepartment": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  743. "creatorIdentity": {"get": function(){return this.creatorIdentityDn.substring(0, this.creatorIdentityDn.indexOf("@"));}},
  744. // "creatorUnitList": {
  745. // "get": function(){
  746. // var v = [];
  747. // this.creatorUnitDnList.each(function(dn){
  748. // v.push(dn.substring(0, dn.indexOf("@")))
  749. // });
  750. // return v;
  751. // }
  752. // },
  753. "creatorCompany": {"get": function(){
  754. if (this.creatorUnitLevel || this.creatorUnitLevelName){
  755. var level = (this.creatorUnitLevel || this.creatorUnitLevelName).split("/");
  756. return level[0];
  757. }else{
  758. return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));
  759. }
  760. }}
  761. };
  762. MWF.defineProperties(work, o);
  763. }
  764. return work;
  765. };
  766. var _redefineTaskProperties = function(task){
  767. if (task){
  768. task.personDn = task.person || "";
  769. task.unitDn = task.unit || "";
  770. task.unitDnList = task.unitList || "";
  771. task.identityDn = task.identity || "";
  772. var o = {
  773. "person": {"get": function(){return this.personDn.substring(0, this.personDn.indexOf("@"));}},
  774. "unit": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  775. "department": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  776. "identity": {"get": function(){return this.identityDn.substring(0, this.identityDn.indexOf("@"));}},
  777. // "unitList": {
  778. // "get": function(){
  779. // var v = [];
  780. // this.unitDnList.each(function(dn){
  781. // v.push(dn.substring(0, dn.indexOf("@")))
  782. // });
  783. // return v;
  784. // }
  785. // },
  786. "company": {"get": function(){return this.unitList[0];}}
  787. };
  788. MWF.defineProperties(task, o);
  789. }
  790. return task;
  791. };
  792. _redefineWorkProperties(this.workContext.getWork());
  793. _redefineTaskProperties(_redefineWorkProperties(this.workContext.getTask()));
  794. //dict
  795. this.Dict = MWF.xScript.createDict((_form.businessData.work || _form.businessData.workCompleted).application, "process");
  796. //unit
  797. var orgActions = null;
  798. var getOrgActions = function(){
  799. // if (!orgActions){
  800. // MWF.xDesktop.requireApp("Org", "Actions.RestActions", null, false);
  801. // orgActions = new MWF.xApplication.Org.Actions.RestActions ();
  802. // }
  803. if (!orgActions){
  804. MWF.require("MWF.xScript.Actions.UnitActions", null, false);
  805. orgActions = new MWF.xScript.Actions.UnitActions();
  806. }
  807. };
  808. var getNameFlag = function(name){
  809. var t = typeOf(name);
  810. if (t==="array"){
  811. var v = [];
  812. name.each(function(id){
  813. v.push((typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  814. });
  815. return v;
  816. }else{
  817. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  818. }
  819. };
  820. this.org = {
  821. //群组***************
  822. //获取群组--返回群组的对象数组
  823. /**
  824. 根据群组标识获取对应的群组对象数组:group对象数组
  825. */
  826. getGroup: function(name, async){
  827. getOrgActions();
  828. var data = {"groupList": getNameFlag(name)};
  829. var v = null;
  830. var cb = function(json){
  831. v = json.data;
  832. v = (v && v.length===1) ? v[0] : v
  833. if (async && o2.typeOf(async)=="function") return async(v);
  834. return v;
  835. };
  836. var promise = orgActions.listGroup(data, cb, null, !!async);
  837. return (!!async) ? promise : v;
  838. // var v = null;
  839. // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  840. // return (v && v.length===1) ? v[0] : v;
  841. },
  842. //查询下级群组--返回群组的对象数组
  843. //nested 布尔 true嵌套下级;false直接下级;默认false;
  844. listSubGroup: function(name, nested, async){
  845. getOrgActions();
  846. var data = {"groupList": getNameFlag(name)};
  847. var v = null;
  848. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  849. // v = json.data;
  850. // return v;
  851. // }.ag().catch(function(json){ return json; });
  852. var cb = function(json){
  853. v = json.data;
  854. if (async && o2.typeOf(async)=="function") return async(v);
  855. return v;
  856. };
  857. var promise;
  858. if (nested){
  859. promise = orgActions.listSubGroupNested(data, cb, null, !!async);
  860. }else{
  861. promise = orgActions.listSubGroupDirect(data, cb, null, !!async);
  862. }
  863. return (!!async) ? promise : v;
  864. // var v = null;
  865. // if (nested){
  866. // orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  867. // }else{
  868. // orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  869. // }
  870. // return v;
  871. },
  872. //查询上级群组--返回群组的对象数组
  873. //nested 布尔 true嵌套上级;false直接上级;默认false;
  874. listSupGroup:function(name, nested, async){
  875. getOrgActions();
  876. var data = {"groupList": getNameFlag(name)};
  877. var v = null;
  878. var cb = function(json){
  879. v = json.data;
  880. if (async && o2.typeOf(async)=="function") return async(v);
  881. return v;
  882. };
  883. var promise
  884. if (nested){
  885. var promise = orgActions.listSupGroupNested(data, cb, null, !!async);
  886. }else{
  887. var promise = orgActions.listSupGroupDirect(data, cb, null, !!async);
  888. }
  889. return (!!async) ? promise : v;
  890. // var v = null;
  891. // if (nested){
  892. // orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  893. // }else{
  894. // orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  895. // }
  896. // return v;
  897. },
  898. //人员所在群组(嵌套)--返回群组的对象数组
  899. listGroupWithPerson:function(name, async){
  900. getOrgActions();
  901. var data = {"personList": getNameFlag(name)};
  902. var v = null;
  903. var cb = function(json){
  904. v = json.data;
  905. if (async && o2.typeOf(async)=="function") return async(v);
  906. return v;
  907. };
  908. var promise = orgActions.listGroupWithPerson(data, cb, null, !!async);
  909. return (!!async) ? promise : v;
  910. // var v = null;
  911. // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  912. // return v;
  913. },
  914. //身份所在群组(嵌套)--返回群组的对象数组
  915. listGroupWithIdentity:function(identity, async){
  916. getOrgActions();
  917. var data = {"identityList": getNameFlag(identity)};
  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.listGroupWithIdentity(data, cb, null, !!async);
  925. return (!!async) ? promise : v;
  926. },
  927. //群组是否拥有角色--返回true, false
  928. groupHasRole: function(name, role, async){
  929. getOrgActions();
  930. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  931. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  932. var v = false;
  933. var cb = function(json){
  934. v = json.data.value;
  935. if (async && o2.typeOf(async)=="function") return async(v);
  936. return v;
  937. };
  938. var promise = orgActions.groupHasRole(data, cb, null, !!async);
  939. return (!!async) ? promise : v;
  940. // var v = false;
  941. // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  942. // return v;
  943. },
  944. //角色***************
  945. //获取角色--返回角色的对象数组
  946. getRole: function(name, async){
  947. getOrgActions();
  948. var data = {"roleList": getNameFlag(name)};
  949. var v = null;
  950. var cb = function(json){
  951. v = json.data;
  952. v = (v && v.length===1) ? v[0] : v;
  953. if (async && o2.typeOf(async)=="function") return async(v);
  954. return v;
  955. };
  956. var promise = orgActions.listRole(data, cb, null, !!async);
  957. return (!!async) ? promise : v;
  958. // var v = null;
  959. // orgActions.listRole(data, function(json){v = json.data;}, null, false);
  960. // return (v && v.length===1) ? v[0] : v;
  961. },
  962. //人员所有角色(嵌套)--返回角色的对象数组
  963. listRoleWithPerson:function(name, async){
  964. getOrgActions();
  965. var data = {"personList": getNameFlag(name)};
  966. var v = null;
  967. var cb = function(json){
  968. v = json.data;
  969. if (async && o2.typeOf(async)=="function") return async(v);
  970. return v;
  971. };
  972. var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
  973. return (!!async) ? promise : v;
  974. // var v = null;
  975. // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  976. // return v;
  977. },
  978. //人员***************
  979. //人员是否拥有角色--返回true, false
  980. personHasRole: function(name, role, async){
  981. getOrgActions();
  982. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  983. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  984. var v = false;
  985. var cb = function(json){
  986. v = json.data.value;
  987. if (async && o2.typeOf(async)=="function") return async(v);
  988. return v;
  989. };
  990. var promise = orgActions.personHasRole(data, cb, null, !!async);
  991. return (!!async) ? promise : v;
  992. // var v = false;
  993. // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  994. // return v;
  995. },
  996. //获取人员,附带身份,身份所在的组织,个人所在群组,个人拥有角色.
  997. getPersonData: function(name, async){
  998. getOrgActions();
  999. var v = null;
  1000. var cb = function(json){
  1001. v = json.data;
  1002. if (async && o2.typeOf(async)=="function") return async(v);
  1003. return v;
  1004. };
  1005. var promise = orgActions.getPerson(null, cb, null, !!async, {"flag": name});
  1006. return (!!async) ? promise : v;
  1007. },
  1008. //获取人员--返回人员的对象数组
  1009. getPerson: function(name, async, findCN){
  1010. getOrgActions();
  1011. var data = {"personList": getNameFlag(name)};
  1012. if( o2.typeOf(findCN) === "boolean"){
  1013. data.useNameFind = findCN;
  1014. }
  1015. var v = null;
  1016. var cb = function(json){
  1017. v = json.data;
  1018. v = (v && v.length===1) ? v[0] : v;
  1019. if (async && o2.typeOf(async)=="function") return async(v);
  1020. return v;
  1021. };
  1022. var promise = orgActions.listPerson(data, cb, null, !!async);
  1023. return (!!async) ? promise : v;
  1024. },
  1025. //查询下级人员--返回人员的对象数组
  1026. //nested 布尔 true嵌套下级;false直接下级;默认false;
  1027. listSubPerson: function(name, nested, async){
  1028. getOrgActions();
  1029. var data = {"personList": getNameFlag(name)};
  1030. var v = null;
  1031. var cb = function(json){
  1032. v = json.data;
  1033. if (async && o2.typeOf(async)=="function") return async(v);
  1034. return v;
  1035. };
  1036. var promise;
  1037. if (nested){
  1038. promise = orgActions.listPersonSubNested(data, cb, null, !!async);
  1039. }else{
  1040. promise = orgActions.listPersonSubDirect(data, cb, null, !!async);
  1041. }
  1042. return (!!async) ? promise : v;
  1043. },
  1044. //查询上级人员--返回人员的对象数组
  1045. //nested 布尔 true嵌套上级;false直接上级;默认false;
  1046. listSupPerson: function(name, nested, async){
  1047. getOrgActions();
  1048. var data = {"personList": getNameFlag(name)};
  1049. var v = null;
  1050. var cb = function(json){
  1051. v = json.data;
  1052. if (async && o2.typeOf(async)=="function") return async(v);
  1053. return v;
  1054. };
  1055. var promise;
  1056. if (nested){
  1057. promise = orgActions.listPersonSupNested(data, cb, null, !!async);
  1058. }else{
  1059. promise = orgActions.listPersonSupDirect(data, cb, null, !!async);
  1060. }
  1061. return (!!async) ? promise : v;
  1062. },
  1063. //获取群组的所有人员--返回人员的对象数组
  1064. listPersonWithGroup: function(name, async){
  1065. getOrgActions();
  1066. var data = {"groupList": getNameFlag(name)};
  1067. var v = null;
  1068. var cb = function(json){
  1069. v = json.data;
  1070. if (async && o2.typeOf(async)=="function") return async(v);
  1071. return v;
  1072. };
  1073. var promise = orgActions.listPersonWithGroup(data, cb, null, !!async);
  1074. return (!!async) ? promise : v;
  1075. },
  1076. //获取角色的所有人员--返回人员的对象数组
  1077. listPersonWithRole: function(name, async){
  1078. getOrgActions();
  1079. var data = {"roleList": getNameFlag(name)};
  1080. var v = null;
  1081. var cb = function(json){
  1082. v = json.data;
  1083. if (async && o2.typeOf(async)=="function") return async(v);
  1084. return v;
  1085. };
  1086. var promise
  1087. promise = orgActions.listPersonWithRole(data, cb, null, !!async);
  1088. return (!!async) ? promise : v;
  1089. },
  1090. //获取身份的所有人员--返回人员的对象数组
  1091. listPersonWithIdentity: function(name, async){
  1092. getOrgActions();
  1093. var data = {"identityList": getNameFlag(name)};
  1094. var v = null;
  1095. var cb = function(json){
  1096. v = json.data;
  1097. if (async && o2.typeOf(async)=="function") return async(v);
  1098. return v;
  1099. };
  1100. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  1101. return (!!async) ? promise : v;
  1102. },
  1103. //获取身份的所有人员--返回人员的对象数组或人员对象
  1104. getPersonWithIdentity: function(name, async){
  1105. getOrgActions();
  1106. var data = {"identityList": getNameFlag(name)};
  1107. var v = null;
  1108. var cb = function(json){
  1109. v = json.data;
  1110. v = (v && v.length===1) ? v[0] : v;
  1111. if (async && o2.typeOf(async)=="function") return async(v);
  1112. return v;
  1113. };
  1114. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  1115. return (!!async) ? promise : v;
  1116. },
  1117. //查询组织成员的人员--返回人员的对象数组
  1118. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  1119. listPersonWithUnit: function(name, nested, async){
  1120. getOrgActions();
  1121. var data = {"unitList": getNameFlag(name)};
  1122. var v = null;
  1123. var cb = function(json){
  1124. v = json.data;
  1125. if (async && o2.typeOf(async)=="function") return async(v);
  1126. return v;
  1127. };
  1128. var promise;
  1129. if (nested){
  1130. promise = orgActions.listPersonWithUnitNested(data, cb, null, !!async);
  1131. }else{
  1132. promise = orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
  1133. }
  1134. return (!!async) ? promise : v;
  1135. },
  1136. //根据属性查询人员--返回人员的对象数组
  1137. //name string 属性名
  1138. //value string 属性值
  1139. listPersonWithAttribute: function(name, value, async){
  1140. getOrgActions();
  1141. var data = {"name": name, "attribute": value};
  1142. var v = null;
  1143. var cb = function(json){
  1144. v = json.data;
  1145. if (async && o2.typeOf(async)=="function") return async(v);
  1146. return v;
  1147. };
  1148. var promise = orgActions.listPersonWithAttribute(data, cb, null, !!async);
  1149. return (!!async) ? promise : v;
  1150. },
  1151. //根据属性查询人员--返回人员的全称数组
  1152. //name string 属性名
  1153. //value string 属性值
  1154. listPersonNameWithAttribute: function(name, value, async){
  1155. getOrgActions();
  1156. var data = {"name": name, "attribute": value};
  1157. var v = null;
  1158. var cb = function(json){
  1159. v = json.data.personList;
  1160. if (async && o2.typeOf(async)=="function") return async(v);
  1161. return v;
  1162. };
  1163. var promise = orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
  1164. return (!!async) ? promise : v;
  1165. },
  1166. //人员属性************
  1167. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  1168. appendPersonAttribute: function(person, attr, values, success, failure, async){
  1169. getOrgActions();
  1170. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  1171. var data = {"attributeList":values,"name":attr,"person":personFlag};
  1172. var v = null;
  1173. var cb = function(json){
  1174. v = json.data;
  1175. if (async && o2.typeOf(async)=="function") return async(v);
  1176. return v;
  1177. };
  1178. var promise = orgActions.appendPersonAttribute(data, cb, null, !!async);
  1179. return (!!async) ? promise : v;
  1180. //orgActions.appendPersonAttribute(data, cb, null, !!async);
  1181. },
  1182. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  1183. setPersonAttribute: function(person, attr, values, success, failure, async){
  1184. getOrgActions();
  1185. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  1186. var data = {"attributeList":values,"name":attr,"person":personFlag};
  1187. var v = null;
  1188. var cb = function(json){
  1189. v = json.data;
  1190. if (async && o2.typeOf(async)=="function") return async(v);
  1191. return v;
  1192. };
  1193. var promise = orgActions.setPersonAttribute(data, cb, null, !!async);
  1194. return (!!async) ? promise : v;
  1195. // var cb = function(json){
  1196. // if (success) return success(json);
  1197. // }.ag().catch(function(xhr, text, error){
  1198. // if (failure) return failure(xhr, text, error);
  1199. // });
  1200. //
  1201. // orgActions.setPersonAttribute(data, cb, null, !!async);
  1202. },
  1203. //获取人员属性值
  1204. getPersonAttribute: function(person, attr, async){
  1205. getOrgActions();
  1206. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  1207. var data = {"name":attr,"person":personFlag};
  1208. var v = null;
  1209. var cb = function(json){
  1210. v = json.data.attributeList;
  1211. if (async && o2.typeOf(async)=="function") return async(v);
  1212. return v;
  1213. };
  1214. var promise = orgActions.getPersonAttribute(data, cb, null, !!async);
  1215. return (!!async) ? promise : v;
  1216. },
  1217. //列出人员所有属性的名称
  1218. listPersonAttributeName: function(name, async){
  1219. getOrgActions();
  1220. var data = {"personList":getNameFlag(name)};
  1221. var v = null;
  1222. var cb = function(json){
  1223. v = json.data.nameList;
  1224. if (async && o2.typeOf(async)=="function") return async(v);
  1225. return v;
  1226. };
  1227. var promise = orgActions.listPersonAttributeName(data, cb, null, !!async);
  1228. return (!!async) ? promise : v;
  1229. },
  1230. //列出人员的所有属性
  1231. listPersonAllAttribute: function(name, async){
  1232. getOrgActions();
  1233. var data = {"personList":getNameFlag(name)};
  1234. var v = null;
  1235. var cb = function(json){
  1236. v = json.data;
  1237. if (async && o2.typeOf(async)=="function") return async(v);
  1238. return v;
  1239. };
  1240. var promise = orgActions.listPersonAllAttribute(data, cb, null, !!async);
  1241. return (!!async) ? promise : v;
  1242. },
  1243. //身份**********
  1244. //获取身份
  1245. getIdentity: function(name, async){
  1246. getOrgActions();
  1247. var data = {"identityList":getNameFlag(name)};
  1248. var v = null;
  1249. var cb = function(json){
  1250. v = json.data;
  1251. v = (v && v.length===1) ? v[0] : v;
  1252. if (async && o2.typeOf(async)=="function") return async(v);
  1253. return v;
  1254. };
  1255. var promise = orgActions.listIdentity(data, cb, null, !!async);
  1256. return (!!async) ? promise : v;
  1257. },
  1258. //列出人员的身份
  1259. listIdentityWithPerson: function(name, async, findCN){
  1260. getOrgActions();
  1261. var data = {"personList":getNameFlag(name)};
  1262. if( o2.typeOf(findCN) === "boolean"){
  1263. data.useNameFind = findCN;
  1264. }
  1265. var v = null;
  1266. var cb = function(json){
  1267. v = json.data;
  1268. if (async && o2.typeOf(async)=="function") return async(v);
  1269. return v;
  1270. };
  1271. var promise = orgActions.listIdentityWithPerson(data, cb, null, !!async);
  1272. return (!!async) ? promise : v;
  1273. },
  1274. //查询组织成员身份--返回身份的对象数组
  1275. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  1276. listIdentityWithUnit: function(name, nested, async){
  1277. getOrgActions();
  1278. var data = {"unitList": getNameFlag(name)};
  1279. var v = null;
  1280. // var cb = function(json){
  1281. // v = json.data;
  1282. // if (async && o2.typeOf(async)=="function") return async(v);
  1283. // return v;
  1284. // }.ag().catch(function(json){ return json; });
  1285. var cb = function(json){
  1286. v = json.data;
  1287. if (async && o2.typeOf(async)=="function") return async(v);
  1288. return v;
  1289. };
  1290. var method = (nested) ? "listIdentityWithUnitNested" : "listIdentityWithUnitDirect";
  1291. var promise = orgActions[method](data, cb, null, !!async);
  1292. promise.name = "org";
  1293. //
  1294. // if (nested){
  1295. // orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
  1296. // }else{
  1297. // orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
  1298. // }
  1299. return (!!async) ? promise : v;
  1300. },
  1301. //组织**********
  1302. //获取组织
  1303. getUnit: function(name, async, findCN){
  1304. getOrgActions();
  1305. var data = {"unitList":getNameFlag(name)};
  1306. if( o2.typeOf(findCN) === "boolean"){
  1307. data.useNameFind = findCN;
  1308. }
  1309. var v = null;
  1310. var cb = function(json){
  1311. v = json.data;
  1312. v = (v && v.length===1) ? v[0] : v;
  1313. if (async && o2.typeOf(async)=="function") return async(v);
  1314. return v;
  1315. };
  1316. var promise = orgActions.listUnit(data, cb, null, !!async);
  1317. return (!!async) ? promise : v;
  1318. },
  1319. //查询组织的下级--返回组织的对象数组
  1320. //nested 布尔 true嵌套下级;false直接下级;默认false;
  1321. listSubUnit: function(name, nested, async){
  1322. getOrgActions();
  1323. var data = {"unitList": getNameFlag(name)};
  1324. var v = null;
  1325. var cb = function(json){
  1326. v = json.data;
  1327. if (async && o2.typeOf(async)=="function") return async(v);
  1328. return v;
  1329. };
  1330. var promise;
  1331. if (nested){
  1332. promise = orgActions.listUnitSubNested(data, cb, null, !!async);
  1333. }else{
  1334. promise = orgActions.listUnitSubDirect(data, cb, null, !!async);
  1335. }
  1336. return (!!async) ? promise : v;
  1337. },
  1338. //查询组织的上级--返回组织的对象数组
  1339. //nested 布尔 true嵌套上级;false直接上级;默认false;
  1340. //async 布尔 true异步请求
  1341. listSupUnit: function(name, nested, async){
  1342. getOrgActions();
  1343. var data = {"unitList": getNameFlag(name)};
  1344. var v = null;
  1345. var cb = function(json){
  1346. v = json.data;
  1347. if (async && o2.typeOf(async)=="function") return async(v);
  1348. return v;
  1349. };
  1350. var promise;
  1351. if (nested){
  1352. promise = orgActions.listUnitSupNested(data, cb, null, !!async);
  1353. }else{
  1354. promise = orgActions.listUnitSupDirect(data, cb, null, !!async);
  1355. }
  1356. return (!!async) ? promise : v;
  1357. // if (callback){
  1358. // if (nested){
  1359. // orgActions.listUnitSupNested(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  1360. // }else{
  1361. // orgActions.listUnitSupDirect(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  1362. // }
  1363. // }else{
  1364. // var v = null;
  1365. // if (nested){
  1366. // orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  1367. // }else{
  1368. // orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  1369. // }
  1370. // return v;
  1371. // }
  1372. },
  1373. //根据个人身份获取组织
  1374. //flag 数字 表示获取第几层的组织
  1375. // 字符串 表示获取指定类型的组织
  1376. // 空 表示获取直接所在的组织
  1377. getUnitByIdentity: function(name, flag, async){
  1378. getOrgActions();
  1379. var getUnitMethod = "current";
  1380. var v;
  1381. if (flag){
  1382. if (typeOf(flag)==="string") getUnitMethod = "type";
  1383. if (typeOf(flag)==="number") getUnitMethod = "level";
  1384. }
  1385. var cb;
  1386. var promise;
  1387. switch (getUnitMethod){
  1388. case "current":
  1389. var data = {"identityList":getNameFlag(name)};
  1390. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  1391. // v = json.data; v=(v&&v.length===1) ? v[0] : v; return v;
  1392. // }.ag().catch(function(json){ return json; });
  1393. cb = function(json){
  1394. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  1395. if (async && o2.typeOf(async)=="function") return async(v);
  1396. return v;
  1397. };
  1398. promise = orgActions.listUnitWithIdentity(data, cb, null, !!async);
  1399. break;
  1400. case "type":
  1401. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  1402. cb = function(json){
  1403. v = json.data;
  1404. if (async && o2.typeOf(async)=="function") return async(v);
  1405. return v;
  1406. };
  1407. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  1408. // v = json.data; return v;
  1409. // }.ag().catch(function(json){ return json; });
  1410. promise = orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
  1411. break;
  1412. case "level":
  1413. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  1414. cb = function(json){
  1415. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  1416. if (async && o2.typeOf(async)=="function") return async(v);
  1417. return v;
  1418. };
  1419. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  1420. // v = json.data; return v;
  1421. // }.ag().catch(function(json){ return json; });
  1422. promise = orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
  1423. break;
  1424. }
  1425. return (!!async) ? promise : v;
  1426. },
  1427. //列出身份所在组织的所有上级组织
  1428. listAllSupUnitWithIdentity: function(name, async){
  1429. getOrgActions();
  1430. var data = {"identityList":getNameFlag(name)};
  1431. var v = null;
  1432. var cb = function(json){
  1433. v = json.data;
  1434. if (async && o2.typeOf(async)=="function") return async(v);
  1435. return v;
  1436. };
  1437. var promise = orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
  1438. return (!!async) ? promise : v;
  1439. },
  1440. //获取人员所在的所有组织
  1441. listUnitWithPerson: function(name, async){
  1442. getOrgActions();
  1443. var data = {"personList":getNameFlag(name)};
  1444. var v = null;
  1445. var cb = function(json){
  1446. v = json.data;
  1447. if (async && o2.typeOf(async)=="function") return async(v);
  1448. return v;
  1449. };
  1450. var promise = orgActions.listUnitWithPerson(data, cb, null, !!async);
  1451. return (!!async) ? promise : v;
  1452. },
  1453. //列出人员所在组织的所有上级组织
  1454. listAllSupUnitWithPerson: function(name, async){
  1455. getOrgActions();
  1456. var data = {"personList":getNameFlag(name)};
  1457. var v = null;
  1458. var cb = function(json){
  1459. v = json.data;
  1460. if (async && o2.typeOf(async)=="function") return async(v);
  1461. return v;
  1462. };
  1463. var promise = orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
  1464. return (!!async) ? promise : v;
  1465. },
  1466. //根据组织属性,获取所有符合的组织
  1467. listUnitWithAttribute: function(name, attribute, async){
  1468. getOrgActions();
  1469. var data = {"name":name,"attribute":attribute};
  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. promise = orgActions.listUnitWithAttribute(data, cb, null, !!async);
  1477. return (!!async) ? promise : v;
  1478. },
  1479. //根据组织职务,获取所有符合的组织
  1480. listUnitWithDuty: function(name, id, async){
  1481. getOrgActions();
  1482. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  1483. var v = null;
  1484. var cb = function(json){
  1485. v = json.data;
  1486. if (async && o2.typeOf(async)=="function") return async(v);
  1487. return v;
  1488. };
  1489. var promise = orgActions.listUnitWithDuty(data, cb, null, !!async);
  1490. return (!!async) ? promise : v;
  1491. },
  1492. //组织职务***********
  1493. //获取指定的组织职务的身份
  1494. getDuty: function(duty, id, async){
  1495. getOrgActions();
  1496. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  1497. var v = null;
  1498. var cb = function(json){
  1499. v = json.data;
  1500. if (async && o2.typeOf(async)=="function") return async(v);
  1501. return v;
  1502. };
  1503. var promise = orgActions.getDuty(data, cb, null, !!async);
  1504. return (!!async) ? promise : v;
  1505. },
  1506. //获取身份的所有职务名称
  1507. listDutyNameWithIdentity: function(name, async){
  1508. getOrgActions();
  1509. var data = {"identityList":getNameFlag(name)};
  1510. var v = null;
  1511. var cb = function(json){
  1512. v = json.data.nameList;
  1513. if (async && o2.typeOf(async)=="function") return async(v);
  1514. return v;
  1515. };
  1516. var promise = orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
  1517. return (!!async) ? promise : v;
  1518. },
  1519. //获取组织的所有职务名称
  1520. listDutyNameWithUnit: function(name, async){
  1521. getOrgActions();
  1522. var data = {"unitList":getNameFlag(name)};
  1523. var v = null;
  1524. var cb = function(json){
  1525. v = json.data.nameList;
  1526. if (async && o2.typeOf(async)=="function") return async(v);
  1527. return v;
  1528. };
  1529. var promise = orgActions.listDutyNameWithUnit(data, cb, null, !!async);
  1530. return (!!async) ? promise : v;
  1531. },
  1532. //获取组织的所有职务
  1533. listUnitAllDuty: function(name, async){
  1534. getOrgActions();
  1535. var data = {"unitList":getNameFlag(name)};
  1536. var v = null;
  1537. var cb = function(json){
  1538. v = json.data;
  1539. if (async && o2.typeOf(async)=="function") return async(v);
  1540. return v;
  1541. };
  1542. var promise = orgActions.listUnitAllDuty(data, cb, null, !!async);
  1543. return (!!async) ? promise : v;
  1544. },
  1545. //列出顶层组织
  1546. listTopUnit: function(async){
  1547. var action = MWF.Actions.get("x_organization_assemble_control");
  1548. var v = null;
  1549. var cb = function(json){
  1550. v = json.data;
  1551. if (async && o2.typeOf(async)=="function") return async(v);
  1552. return v;
  1553. };
  1554. var promise = action.listTopUnit(cb, null, !!async);
  1555. return (!!async) ? promise : v;
  1556. },
  1557. //组织属性**************
  1558. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  1559. appendUnitAttribute: function(unit, attr, values, success, failure, async){
  1560. getOrgActions();
  1561. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1562. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  1563. var v = null;
  1564. var cb = function(json){
  1565. v = json.data;
  1566. if (async && o2.typeOf(async)=="function") return async(v);
  1567. return v;
  1568. };
  1569. var promise = orgActions.appendUnitAttribute(data, cb, null, !!async);
  1570. return (!!async) ? promise : v;
  1571. // var cb = function(json){
  1572. // if (success) return success(json);
  1573. // }.ag().catch(function(xhr, text, error){
  1574. // if (failure) return failure(xhr, text, error);
  1575. // });
  1576. //
  1577. // orgActions.appendPersonAttribute(data, cb, null, !!async);
  1578. // orgActions.appendUnitAttribute(data, function(json){
  1579. // if (json.data.value){
  1580. // if (success) success();
  1581. // }else{
  1582. // if (failure) failure(null, "", "append values failed");
  1583. // }
  1584. // }, function(xhr, text, error){
  1585. // if (failure) failure(xhr, text, error);
  1586. // }, false);
  1587. },
  1588. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  1589. setUnitAttribute: function(unit, attr, values, success, failure, async){
  1590. getOrgActions();
  1591. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1592. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  1593. var v = null;
  1594. var cb = function(json){
  1595. v = json.data;
  1596. if (async && o2.typeOf(async)=="function") return async(v);
  1597. return v;
  1598. };
  1599. var promise = orgActions.setUnitAttribute(data, cb, null, !!async);
  1600. return (!!async) ? promise : v;
  1601. // var cb = function(json){
  1602. // if (success) return success(json);
  1603. // }.ag().catch(function(xhr, text, error){
  1604. // if (failure) return failure(xhr, text, error);
  1605. // });
  1606. // orgActions.setUnitAttribute(data, cb, null, !!async);
  1607. // orgActions.setUnitAttribute(data, function(json){
  1608. // if (json.data.value){
  1609. // if (success) success();
  1610. // }else{
  1611. // if (failure) failure(null, "", "append values failed");
  1612. // }
  1613. // }, function(xhr, text, error){
  1614. // if (failure) failure(xhr, text, error);
  1615. // }, false);
  1616. },
  1617. //获取组织属性值
  1618. getUnitAttribute: function(unit, attr, async){
  1619. getOrgActions();
  1620. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1621. var data = {"name":attr,"unit":unitFlag};
  1622. var v = null;
  1623. var cb = function(json){
  1624. v = json.data.attributeList;
  1625. if (async && o2.typeOf(async)=="function") return async(v);
  1626. return v;
  1627. };
  1628. var promise = orgActions.getUnitAttribute(data, cb, null, !!async);
  1629. return (!!async) ? promise : v;
  1630. },
  1631. //列出组织所有属性的名称
  1632. listUnitAttributeName: function(name, async){
  1633. getOrgActions();
  1634. var data = {"unitList":getNameFlag(name)};
  1635. var v = null;
  1636. var cb = function(json){
  1637. v = json.data.nameList;
  1638. if (async && o2.typeOf(async)=="function") return async(v);
  1639. return v;
  1640. };
  1641. var promise = orgActions.listUnitAttributeName(data, cb, null, !!async);
  1642. return (!!async) ? promise : v;
  1643. },
  1644. //列出组织的所有属性
  1645. listUnitAllAttribute: function(name, async){
  1646. getOrgActions();
  1647. var data = {"unitList":getNameFlag(name)};
  1648. var v = null;
  1649. var cb = function(json){
  1650. v = json.data;
  1651. if (async && o2.typeOf(async)=="function") return async(v);
  1652. return v;
  1653. };
  1654. var promise = orgActions.listUnitAllAttribute(data, cb, null, !!async);
  1655. return (!!async) ? promise : v;
  1656. }
  1657. };
  1658. this.Action = (function(){
  1659. var actions = [];
  1660. return function(root, json){
  1661. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  1662. action.getActions = function(callback){
  1663. if (!this.actions) this.actions = {};
  1664. Object.merge(this.actions, json);
  1665. if (callback) callback();
  1666. };
  1667. this.invoke = function(option){
  1668. action.invoke(option)
  1669. }
  1670. }
  1671. })();
  1672. // this.service = {
  1673. // "jaxwsClient":{},
  1674. // "jaxrsClient":{}
  1675. // };
  1676. var lookupAction = null;
  1677. var getLookupAction = function(callback){
  1678. if (!lookupAction){
  1679. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  1680. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  1681. lookupAction.getActions = function(actionCallback){
  1682. this.actions = {
  1683. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  1684. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  1685. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  1686. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  1687. };
  1688. if (actionCallback) actionCallback();
  1689. };
  1690. if (callback) callback();
  1691. });
  1692. }else{
  1693. if (callback) callback();
  1694. }
  1695. };
  1696. this.view = {
  1697. "lookup": function(view, callback, async){
  1698. var filterList = {"filterList": (view.filter || null)};
  1699. return MWF.Actions.load("x_query_assemble_surface").ViewAction.executeWithQuery(view.view, view.application, filterList, function(json){
  1700. var data = {
  1701. "grid": json.data.grid || json.data.groupGrid,
  1702. "groupGrid": json.data.groupGrid
  1703. };
  1704. if (callback) callback(data);
  1705. return data;
  1706. }, null, async);
  1707. },
  1708. "lookupV1": function(view, callback){
  1709. getLookupAction(function(){
  1710. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  1711. var data = {
  1712. "grid": json.data.grid,
  1713. "groupGrid": json.data.groupGrid
  1714. };
  1715. if (callback) callback(data);
  1716. }.bind(this)});
  1717. }.bind(this));
  1718. },
  1719. "select": function(view, callback, options){
  1720. if (view.view){
  1721. var viewJson = {
  1722. "application": view.application || _form.json.application,
  1723. "viewName": view.view || "",
  1724. "isTitle": (view.isTitle===false) ? "no" : "yes",
  1725. "select": (view.isMulti===false) ? "single" : "multi",
  1726. "filter": view.filter
  1727. };
  1728. if (!options) options = {};
  1729. options.width = view.width;
  1730. options.height = view.height;
  1731. options.title = view.caption;
  1732. var width = options.width || "700";
  1733. var height = options.height || "400";
  1734. if (layout.mobile){
  1735. var size = document.body.getSize();
  1736. width = size.x;
  1737. height = size.y;
  1738. options.style = "viewmobile";
  1739. }
  1740. width = width.toInt();
  1741. height = height.toInt();
  1742. var size = _form.app.content.getSize();
  1743. var x = (size.x-width)/2;
  1744. var y = (size.y-height)/2;
  1745. if (x<0) x = 0;
  1746. if (y<0) y = 0;
  1747. if (layout.mobile){
  1748. x = 20;
  1749. y = 0;
  1750. }
  1751. var _self = this;
  1752. MWF.require("MWF.xDesktop.Dialog", function(){
  1753. var dlg = new MWF.xDesktop.Dialog({
  1754. "title": options.title || "select view",
  1755. "style": options.style || "view",
  1756. "top": y,
  1757. "left": x-20,
  1758. "fromTop":y,
  1759. "fromLeft": x-20,
  1760. "width": width,
  1761. "height": height,
  1762. "html": "<div style='height: 100%;'></div>",
  1763. "maskNode": _form.app.content,
  1764. "container": _form.app.content,
  1765. "buttonList": [
  1766. {
  1767. "text": MWF.LP.process.button.ok,
  1768. "action": function(){
  1769. //if (callback) callback(_self.view.selectedItems);
  1770. if (callback) callback(_self.view.getData());
  1771. this.close();
  1772. }
  1773. },
  1774. {
  1775. "text": MWF.LP.process.button.cancel,
  1776. "action": function(){this.close();}
  1777. }
  1778. ]
  1779. });
  1780. dlg.show();
  1781. if (layout.mobile){
  1782. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1783. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1784. if (backAction) backAction.addEvent("click", function(e){
  1785. dlg.close();
  1786. }.bind(this));
  1787. if (okAction) okAction.addEvent("click", function(e){
  1788. //if (callback) callback(this.view.selectedItems);
  1789. if (callback) callback(this.view.getData());
  1790. dlg.close();
  1791. }.bind(this));
  1792. }
  1793. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  1794. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"}, _form.app, _form.Macro);
  1795. }.bind(this));
  1796. }.bind(this));
  1797. }
  1798. }
  1799. };
  1800. this.statement = {
  1801. execute: function (obj, callback, async) {
  1802. if( obj.format ){
  1803. return this._execute(obj, callback, async, obj.format);
  1804. }else{
  1805. if( this.needCheckFormat(obj) ){
  1806. var result;
  1807. var p = MWF.Actions.load("x_query_assemble_surface").StatementAction.getFormat(obj.name, function(json){
  1808. result = this._execute(obj, callback, async, json.data.format);
  1809. return result;
  1810. }.bind(this), null, async);
  1811. return result || p;
  1812. }else{
  1813. return this._execute(obj, callback, async, "");
  1814. }
  1815. }
  1816. },
  1817. needCheckFormat: function(s){
  1818. if( s.format )return false;
  1819. if( typeOf(s.parameter) === "object" ){
  1820. for( var p in s.parameter ){
  1821. if( typeOf( s.parameter[p] ) === "date" )return true;
  1822. }
  1823. }
  1824. if( typeOf(s.filter) === "array" ){
  1825. for( var i=0; i< s.filter.length; i++){
  1826. var fType = s.filter[i].formatType;
  1827. if( ["dateTimeValue", "datetimeValue", "dateValue", "timeValue"].contains( fType ) )return true;
  1828. }
  1829. }
  1830. return false;
  1831. },
  1832. _execute: function(statement, callback, async, format){
  1833. var parameter = this.parseParameter(statement.parameter, format);
  1834. var filterList = this.parseFilter(statement.filter, parameter, format);
  1835. var obj = {
  1836. "filterList": filterList,
  1837. "parameter" : parameter
  1838. };
  1839. return MWF.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  1840. statement.name, statement.mode || "data", statement.page || 1, statement.pageSize || 20, obj,
  1841. function (json) {
  1842. if (callback) callback(json);
  1843. return json;
  1844. }, null, async);
  1845. },
  1846. parseFilter : function( filter, parameter , format){
  1847. if( typeOf(filter) !== "array" )return [];
  1848. if( !parameter )parameter = {};
  1849. var filterList = [];
  1850. ( filter || [] ).each( function (d) {
  1851. if( !d.logic )d.logic = "and";
  1852. //var parameterName = d.path.replace(/\./g, "_");
  1853. var pName = d.path.replace(/\./g, "_");
  1854. var parameterName = pName;
  1855. var suffix = 1;
  1856. while( parameter[parameterName] ){
  1857. parameterName = pName + "_" + suffix;
  1858. suffix++;
  1859. }
  1860. var value = d.value;
  1861. if( d.comparison === "like" || d.comparison === "notLike" ){
  1862. if( value.substr(0, 1) !== "%" )value = "%"+value;
  1863. if( value.substr(value.length-1,1) !== "%" )value = value+"%";
  1864. parameter[ parameterName ] = value; //"%"+value+"%";
  1865. }else{
  1866. if( ["sql", "sqlScript"].contains(format) ) {
  1867. if (d.formatType === "numberValue") {
  1868. value = parseFloat(value);
  1869. }
  1870. }else{
  1871. if (d.formatType === "dateTimeValue" || d.formatType === "datetimeValue") {
  1872. value = "{ts '" + value + "'}"
  1873. } else if (d.formatType === "dateValue") {
  1874. value = "{d '" + value + "'}"
  1875. } else if (d.formatType === "timeValue") {
  1876. value = "{t '" + value + "'}"
  1877. } else if (d.formatType === "numberValue") {
  1878. value = parseFloat(value);
  1879. }
  1880. }
  1881. parameter[ parameterName ] = value;
  1882. }
  1883. d.value = parameterName;
  1884. filterList.push( d );
  1885. }.bind(this));
  1886. return filterList;
  1887. },
  1888. parseParameter : function( obj, format ){
  1889. if( typeOf(obj) !== "object" )return {};
  1890. var parameter = {};
  1891. //传入的参数
  1892. for( var p in obj ){
  1893. var value = obj[p];
  1894. if( typeOf( value ) === "date" ){
  1895. if( ["sql", "sqlScript"].contains(format) ){
  1896. value = value.format("db");
  1897. }else{
  1898. value = "{ts '"+value.format("db")+"'}"
  1899. }
  1900. }
  1901. parameter[ p ] = value;
  1902. }
  1903. return parameter;
  1904. },
  1905. "select": function (statement, callback, options) {
  1906. if (statement.name) {
  1907. // var parameter = this.parseParameter(statement.parameter);
  1908. // var filterList = this.parseFilter(statement.filter, parameter);
  1909. var statementJson = {
  1910. "statementId": statement.name || "",
  1911. "isTitle": (statement.isTitle === false) ? "no" : "yes",
  1912. "select": (statement.isMulti === false) ? "single" : "multi",
  1913. "filter": statement.filter,
  1914. "parameter": statement.parameter
  1915. };
  1916. if (!options) options = {};
  1917. options.width = statement.width;
  1918. options.height = statement.height;
  1919. options.title = statement.caption;
  1920. var width = options.width || "700";
  1921. var height = options.height || "400";
  1922. if (layout.mobile) {
  1923. var size = document.body.getSize();
  1924. width = size.x;
  1925. height = size.y;
  1926. options.style = "viewmobile";
  1927. }
  1928. width = width.toInt();
  1929. height = height.toInt();
  1930. var size = _form.app.content.getSize();
  1931. var x = (size.x - width) / 2;
  1932. var y = (size.y - height) / 2;
  1933. if (x < 0) x = 0;
  1934. if (y < 0) y = 0;
  1935. if (layout.mobile) {
  1936. x = 20;
  1937. y = 0;
  1938. }
  1939. var _self = this;
  1940. MWF.require("MWF.xDesktop.Dialog", function () {
  1941. var dlg = new MWF.xDesktop.Dialog({
  1942. "title": options.title || "select statement view",
  1943. "style": options.style || "view",
  1944. "top": y,
  1945. "left": x - 20,
  1946. "fromTop": y,
  1947. "fromLeft": x - 20,
  1948. "width": width,
  1949. "height": height,
  1950. "html": "<div style='height: 100%;'></div>",
  1951. "maskNode": _form.app.content,
  1952. "container": _form.app.content,
  1953. "buttonList": [
  1954. {
  1955. "text": MWF.LP.process.button.ok,
  1956. "action": function () {
  1957. //if (callback) callback(_self.view.selectedItems);
  1958. if (callback) callback(_self.statement.getData());
  1959. this.close();
  1960. }
  1961. },
  1962. {
  1963. "text": MWF.LP.process.button.cancel,
  1964. "action": function () { this.close(); }
  1965. }
  1966. ]
  1967. });
  1968. dlg.show();
  1969. if (layout.mobile) {
  1970. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1971. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1972. if (backAction) backAction.addEvent("click", function (e) {
  1973. dlg.close();
  1974. }.bind(this));
  1975. if (okAction) okAction.addEvent("click", function (e) {
  1976. //if (callback) callback(this.view.selectedItems);
  1977. if (callback) callback(this.statement.getData());
  1978. dlg.close();
  1979. }.bind(this));
  1980. }
  1981. MWF.xDesktop.requireApp("query.Query", "Statement", function () {
  1982. this.statement = new MWF.xApplication.query.Query.Statement(dlg.content.getFirst(), statementJson, { "style": "select" }, _form.app, _form.Macro);
  1983. }.bind(this));
  1984. }.bind(this));
  1985. }
  1986. }
  1987. };
  1988. this.importer = {
  1989. "upload": function (options, callback, async) {
  1990. MWF.xDesktop.requireApp("query.Query", "Importer", function () {
  1991. var importer = new MWF.xApplication.query.Query.Importer(_form.app.content, options, {}, _form.app, _form.Macro);
  1992. importer.addEvent("afterImport", function (data) {
  1993. if(callback)callback(data);
  1994. });
  1995. importer.load();
  1996. }.bind(this));
  1997. },
  1998. "downloadTemplate": function(options, fileName, callback){
  1999. MWF.xDesktop.requireApp("query.Query", "Importer", function () {
  2000. var importer = new MWF.xApplication.query.Query.Importer(_form.app.content, options, {}, _form.app, _form.Macro);
  2001. importer.downloadTemplate(fileName, callback);
  2002. }.bind(this));
  2003. }
  2004. };
  2005. //include 引用脚本
  2006. //optionsOrName : {
  2007. // type : "", 默认为process, 可以为 portal process cms
  2008. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  2009. // name : "" // 脚本名称/别名/id
  2010. //}
  2011. //或者name: "" // 脚本名称/别名/id
  2012. // if( !window.includedScripts ){
  2013. // var includedScripts = window.includedScripts = [];
  2014. // }else{
  2015. // var includedScripts = window.includedScripts;
  2016. // }
  2017. /**
  2018. * this.include是一个方法,当您在流程、门户、内容管理或服务管理中创建了脚本配置,可以使用this.include()用来引用脚本配置。<br/>
  2019. * v8.0及以后版本中增加了服务管理的脚本配置。<br/>
  2020. * <b>(建议使用表单中的预加载脚本,需要判断加载的时候才使用本方法加载脚本,此时建议异步加载有助于表单加载速度。)</b><br/>
  2021. * @module include
  2022. * @o2cn 脚本引用
  2023. * @o2category web
  2024. * @o2ordernumber 140
  2025. * @param {(String|Object|String[]|Object[])} optionsOrName 可以是脚本标识字符串(数组)或者是对象(数组)。
  2026. * <pre><code class='language-js'>
  2027. * //如果需要引用本应用的脚本配置,将options设置为String或者String Array。
  2028. * this.include("initScript") //脚本配置的名称、别名或id
  2029. * this.include(["initScript","initScript2"]) //可以是字符串数组
  2030. *
  2031. * //如果需要引用其他应用的脚本配置,将options设置为Object或者Object Array;
  2032. * this.include({
  2033. * //type: 应用类型。可以为 portal process cms service。
  2034. * //如果没有该选项或者值为空字符串,则表示应用脚本和被应用的脚本配置类型相同。
  2035. * //比如在门户的A应用脚本中引用门户B应用的脚本配置,则type可以省略。
  2036. * type : "portal",
  2037. * application : "首页", // 门户、流程、CMS的名称、别名、id。 默认为当前应用,如果脚本在服务管理中忽略该参数
  2038. * name : "initScript" // 脚本配置的名称、别名或id
  2039. * })
  2040. * this.include([ //也可以对象和字符串混合数组
  2041. * {
  2042. * type : "portal",
  2043. * application : "首页",
  2044. * name : "initScript"
  2045. * },
  2046. * "initScript2"
  2047. * ])
  2048. *
  2049. * //引用服务管理中的脚本
  2050. * this.include({
  2051. * "type": "service",
  2052. * "name": "scriptName"
  2053. * });
  2054. *
  2055. * //引用流程管理中的脚本
  2056. * this.include({
  2057. * "type": "process",
  2058. * "application": "appName",
  2059. * "name": "scriptName"
  2060. * });
  2061. *
  2062. * //引用内容管理中的脚本
  2063. * this.include({
  2064. * "type": "cms",
  2065. * "application": "appName",
  2066. * "name": "scriptName"
  2067. * });
  2068. *
  2069. * //引用门户管理中的脚本
  2070. * this.include({
  2071. * "type": "portal",
  2072. * "application": "appName",
  2073. * "name": "scriptName"
  2074. * });
  2075. * </code></pre>
  2076. * @param {Function} [callback] 加载后执行的回调方法
  2077. * @param {Boolean} [async] 是否异步加载
  2078. * @o2syntax
  2079. * //您可以在表单、流程、视图和查询视图的各个嵌入脚本中,通过this.include()来引用本应用或其他应用的脚本配置,如下:
  2080. * this.include( optionsOrName, callback, async )
  2081. * @example
  2082. * <caption>
  2083. * <b>样例一:</b>在通用脚本中定义返回当前人员名称的方法,在各个门户应用都使用这个方法显示人员名称。<br/>
  2084. * 1、在门户应用中有一个commonApp的应用,在该应用中创建一个脚本,命名为initScript,并定义方法。
  2085. * <img src='img/module/include/define1.png' />
  2086. * </caption>
  2087. * //定义一个方法
  2088. * this.define("getUserName", function(){
  2089. * return ( layout.desktop.session.user || layout.user ).name
  2090. * }.bind(this))
  2091. * @example
  2092. * <caption>
  2093. * 2、在门户页面中添加事件'queryLoad',在事件中引入 initScript 脚本配置。
  2094. * <img src='img/module/include/define2.png' style='max-width:700px;'/>
  2095. * </caption>
  2096. * this.include({
  2097. * type : "portal",
  2098. * application : "commonApp",
  2099. * name : "initScript"
  2100. * })
  2101. *
  2102. * @example
  2103. * <caption>
  2104. * 3、在门户页面的'load'事件中使用方法。<br/>
  2105. * <img src='img/module/include/define3.png' style='max-width:700px;'/>
  2106. * </caption>
  2107. * var userNameNode = this.page.get("userName").node; //获取Dom对象
  2108. * var urerName = this.getUserName(); //使用initScript脚本中的方法
  2109. * userNameNode.set("text", urerName ); //为DOM对象设置值
  2110. */
  2111. var includedScripts = [];
  2112. var _includeSingle = function( optionsOrName , callback, async){
  2113. var options = optionsOrName;
  2114. if( typeOf( options ) == "string" ){
  2115. options = { name : options };
  2116. }
  2117. var name = options.name;
  2118. var type;
  2119. if( options.type === "service" ){
  2120. type = options.type;
  2121. }else{
  2122. type = ( options.type && options.application ) ? options.type : "process";
  2123. }
  2124. var application = options.application || _form.json.application;
  2125. var key = type +"-" + application + "-" + name;
  2126. if( type === "service" ){
  2127. key = type + "-" + name;
  2128. }
  2129. if (includedScripts.indexOf( key )> -1){
  2130. if (callback) callback.apply(this);
  2131. return;
  2132. }
  2133. //if (includedScripts.indexOf( name )> -1){
  2134. // if (callback) callback.apply(this);
  2135. // return;
  2136. //}
  2137. if( (options.enableAnonymous || options.anonymous) && type === "cms" ){
  2138. o2.Actions.load("x_cms_assemble_control").ScriptAnonymousAction.getWithAppWithName( application, name, function(json){
  2139. if (json.data){
  2140. includedScripts.push( key );
  2141. //名称、别名、id
  2142. ( json.data.importedList || [] ).each( function ( flag ) {
  2143. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  2144. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  2145. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  2146. });
  2147. includedScripts = includedScripts.concat(json.data.importedList || []);
  2148. MWF.CMSMacro.exec(json.data.text, this);
  2149. if (callback) callback.apply(this);
  2150. }else{
  2151. if (callback) callback.apply(this);
  2152. }
  2153. }.bind(this), null, false);
  2154. }else {
  2155. var scriptAction;
  2156. switch (type) {
  2157. case "portal" :
  2158. if (this.scriptActionPortal) {
  2159. scriptAction = this.scriptActionPortal;
  2160. } else {
  2161. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  2162. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  2163. }
  2164. break;
  2165. case "process" :
  2166. if (this.scriptActionProcess) {
  2167. scriptAction = this.scriptActionProcess;
  2168. } else {
  2169. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  2170. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  2171. }
  2172. break;
  2173. case "cms" :
  2174. if (this.scriptActionCMS) {
  2175. scriptAction = this.scriptActionCMS;
  2176. } else {
  2177. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  2178. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  2179. }
  2180. break;
  2181. case "service" :
  2182. if (this.scriptActionService) {
  2183. scriptAction = this.scriptActionService;
  2184. } else {
  2185. MWF.require("MWF.xScript.Actions.ServiceScriptActions", null, false);
  2186. scriptAction = this.scriptActionService = new MWF.xScript.Actions.ServiceScriptActions();
  2187. }
  2188. break;
  2189. }
  2190. var successCallback = function (json) {
  2191. if (json.data) {
  2192. includedScripts.push(key);
  2193. //名称、别名、id
  2194. json.data.importedList.each(function (flag) {
  2195. if (type === "portal") {
  2196. includedScripts.push(type + "-" + json.data.portal + "-" + flag);
  2197. if (json.data.portalName) includedScripts.push(type + "-" + json.data.portalName + "-" + flag);
  2198. if (json.data.portalAlias) includedScripts.push(type + "-" + json.data.portalAlias + "-" + flag);
  2199. } else if (type === "cms") {
  2200. includedScripts.push(type + "-" + json.data.appId + "-" + flag);
  2201. if (json.data.appName) includedScripts.push(type + "-" + json.data.appName + "-" + flag);
  2202. if (json.data.appAlias) includedScripts.push(type + "-" + json.data.appAlias + "-" + flag);
  2203. } else if (type === "process") {
  2204. includedScripts.push(type + "-" + json.data.application + "-" + flag);
  2205. if (json.data.appName) includedScripts.push(type + "-" + json.data.appName + "-" + flag);
  2206. if (json.data.appAlias) includedScripts.push(type + "-" + json.data.appAlias + "-" + flag);
  2207. }else if (type === "service") {
  2208. includedScripts.push(type + "-" + flag);
  2209. }
  2210. });
  2211. includedScripts = includedScripts.concat(json.data.importedList);
  2212. MWF.Macro.exec(json.data.text, this);
  2213. if (callback) callback.apply(this);
  2214. } else {
  2215. if (callback) callback.apply(this);
  2216. }
  2217. }.bind(this);
  2218. if( type === "service" ){
  2219. scriptAction.getScriptByName(name, includedScripts, successCallback, null, !!async);
  2220. }else{
  2221. scriptAction.getScriptByName(application, name, includedScripts, successCallback, null, !!async);
  2222. }
  2223. }
  2224. };
  2225. this.include = function( optionsOrName , callback, async){
  2226. if (o2.typeOf(optionsOrName)=="array"){
  2227. if (!!async){
  2228. var count = optionsOrName.length;
  2229. var loaded = 0;
  2230. optionsOrName.each(function(option){
  2231. _includeSingle.apply(this, [option, function(){
  2232. loaded++;
  2233. if (loaded>=count) if (callback) callback.apply(this);
  2234. }.bind(this), true]);
  2235. }.bind(this));
  2236. }else{
  2237. optionsOrName.each(function(option){
  2238. _includeSingle.apply(this, [option]);
  2239. }.bind(this));
  2240. if (callback) callback.apply(this);
  2241. }
  2242. }else{
  2243. _includeSingle.apply(this, [optionsOrName , callback, async])
  2244. }
  2245. };
  2246. /**
  2247. * this.define是一个方法,您可以在流程、门户或者内容管理中创建脚本配置,在脚本配置中您可以通过this.define()来定义自己的方法。<br/>
  2248. * 通过这种方式定义方法,在不同的应用使用相同的方法名称也不会造成冲突。
  2249. * @module define
  2250. * @o2cn 方法定义
  2251. * @o2category web
  2252. * @o2ordernumber 150
  2253. * @param {(String)} name 定义的方法名称。
  2254. * @param {Function} fun 定义的方法
  2255. * @param {Boolean} [overwrite] 定义的方法是否能被覆盖重写。默认值为true。
  2256. * @o2syntax
  2257. * this.define(name, fun, overwrite)
  2258. * @example
  2259. * <caption>
  2260. * <b>样例:</b>在通用脚本中定义返回当前人员名称的方法,在各个门户应用都使用这个方法显示人员名称。<br/>
  2261. * 1、在门户应用中有一个commonApp的应用,在该应用中创建一个脚本,命名为initScript,并定义方法。
  2262. * <img src='img/module/include/define1.png' />
  2263. * </caption>
  2264. * //定义一个方法
  2265. * this.define("getUserName", function(){
  2266. * return ( layout.desktop.session.user || layout.user ).name
  2267. * }.bind(this))
  2268. * @example
  2269. * <caption>
  2270. * 2、在门户页面中添加事件'queryLoad',在事件中引入 initScript 脚本配置。
  2271. * <img src='img/module/include/define2.png' style='max-width:700px;'/>
  2272. * </caption>
  2273. * this.include({
  2274. * type : "portal",
  2275. * application : "commonApp",
  2276. * name : "initScript"
  2277. * })
  2278. *
  2279. * @example
  2280. * <caption>
  2281. * 3、在门户页面的'load'事件中使用方法。<br/>
  2282. * <img src='img/module/include/define3.png' style='max-width:700px;'/>
  2283. * </caption>
  2284. * var userNameNode = this.page.get("userName").node; //获取Dom对象
  2285. * var urerName = this.getUserName(); //使用initScript脚本中的方法
  2286. * userNameNode.set("text", urerName ); //为DOM对象设置值
  2287. */
  2288. this.define = function(name, fun, overwrite){
  2289. var over = true;
  2290. if (overwrite===false) over = false;
  2291. var o = {};
  2292. o[name] = {"value": fun, "configurable": over};
  2293. MWF.defineProperties(this, o);
  2294. }.bind(this);
  2295. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  2296. //可在调用前执行 var resolve = this.wait();
  2297. //在异步调用结束后 执行 resolve.cb();
  2298. //目前只有表单的queryload事件支持此方法。
  2299. /**
  2300. * this.wait是一个方法,可以用来处理异步调用时的页面加载。<br/>
  2301. * 该方法使用的具体场景:为了加快速度,需要一次性加载全部外部资源(如:数据字典、外部JS、内容管理文档等)后,再进行表单的加载。<br/>
  2302. * this.wait需和this.goon配合使用。<br/>
  2303. * <b>目前只有流程表单的queryload事件支持此方法。</b>
  2304. * @module wait
  2305. * @o2cn 表单等待
  2306. * @o2category web
  2307. * @o2range {Process}
  2308. * @o2syntax
  2309. * var resolve = this.wait(); //让表单停止加载页面
  2310. *
  2311. * if (resolve && resolve.cb){
  2312. * resolve.cb(); //通过 resolve.cb() 方法继续执行表单加载
  2313. * }else{
  2314. * //如果没有发生异步,则resolve.cb方法不存在,
  2315. * //所以在回调中中使用this.goon();使表单继续加载
  2316. * this.goon();
  2317. * }
  2318. * @example
  2319. * <caption>需要在加载数据字典,内容管理文档数据,按照条件获取的脚本后,再进行加载表单。</caption>
  2320. *
  2321. * var resolve = this.wait(); //this.wait()让表单加载等待回调
  2322. * var scriptLoaded = false; //脚本是否加载完成标识,按条件判断的脚本才建议用this.include(),否则使用预加载脚本更快。
  2323. * var documentLoaded = false; //内容管理文档是否加载完成标识
  2324. * var dictLoaded = true; //数据字典是否加载完成标识
  2325. *
  2326. * //检查是否全部资源已加载,如果是继续加载表单
  2327. * var checkLoad = function(){
  2328. * if (scriptLoaded && documentLoaded && dictLoaded){ //各种资源以及加载完成
  2329. * if (resolve && resolve.cb){
  2330. * resolve.cb(); //通过 resolve.cb() 方法继续执行表单加载
  2331. * }else{
  2332. * //如果没有发生异步,则resolve.cb方法不存在,
  2333. * //所以在回调中中使用this.goon();使表单继续加载
  2334. * this.goon();
  2335. * }
  2336. * }
  2337. * }.bind(this);
  2338. *
  2339. * //判断内容管理文档加载
  2340. * if( this.data.documentId ){
  2341. * //异步载入内容管理文档
  2342. * o2.Actions.get("x_cms_assemble_control").getDocument(this.data.documentId, function (json) {
  2343. * this.form.documentJson = json; //将数据存在this.form上,以便其他地方使用
  2344. * documentLoaded = true; //标记内容管理加载完成
  2345. * checkLoad(); //检查全部资源是否完成加载
  2346. * }.bind(this), null, true); //true 为异步加载标志
  2347. * }else{
  2348. * documentLoaded = true; ////标记内容管理加载完成
  2349. * checkLoad(); //检查全部资源是否完成加载
  2350. * }
  2351. *
  2352. * //判断脚本加载
  2353. * if( this.data.scriptName ){ //假设scriptName为判断条件
  2354. * //加载脚本
  2355. * this.include( this.data.scriptName, function(){ //第二个参数为异步加载后的回调
  2356. * scriptLoaded = true; //标记脚本加载完成
  2357. * checkLoad(); //检查全部资源是否完成加载
  2358. * }, true ); //第三个参数表示异步
  2359. * }else{
  2360. * scriptLoaded = true; ////标记脚本加载完成
  2361. * checkLoad(); //检查全部资源是否完成加载
  2362. * }
  2363. *
  2364. * //加载数据字典bulletinDictionary的category数据
  2365. * var dict = new Dict("bulletinDictionary");
  2366. * dict.get("category", function(data){ //成功的回调
  2367. * this.form.bulletinCategory = data; //将数据存在this.form上,以便其他地方使用
  2368. * dictLoaded = true; //标记数据字典加载完成
  2369. * checkLoad(); //检查全部资源是否完成加载
  2370. * }.bind(this), function(xhr){ //错误的回调
  2371. * dictLoaded = true; ////标记数据字典加载完成
  2372. * checkLoad(); //检查全部资源是否完成加载
  2373. * }, true //异步执行
  2374. * )
  2375. */
  2376. this.wait = function(){
  2377. var _self = this;
  2378. resolve = {"cb": _self.goon.bind(_self)};
  2379. var setResolve = function(callback){
  2380. resolve.cb = callback;
  2381. }.bind(this);
  2382. this.target.event_resolve = setResolve;
  2383. return resolve;
  2384. }
  2385. //和this.wait配合使用,
  2386. //如果没有异步,则resolve.cb方法不存在,
  2387. //所以在回调中中使用this.goon();使表单继续加载
  2388. this.goon = function(){
  2389. this.target.event_resolve = null;
  2390. }
  2391. //仅前台对象-----------------------------------------
  2392. //form
  2393. /**
  2394. * form对象可在流程表单或内容管理表单中可用。(仅前端脚本可用)。
  2395. * @module form
  2396. * @o2cn 流程及内容管理表单
  2397. * @o2category web
  2398. * @o2range {Process|CMS}
  2399. * @o2ordernumber 40
  2400. * @o2syntax
  2401. * //您可以在流程表单和内容管理的前端脚本中,通过this来获取form对象,如下:
  2402. * var form = this.form;
  2403. */
  2404. this.page = this.form = {
  2405. /**
  2406. * 获取当前表单的基本信息。
  2407. * @method getInfor
  2408. * @static
  2409. * @return {Object} 表单的基本信息.
  2410. * <pre><code class='language-js'>{
  2411. * "id": "db3b2766-93a1-4058-b522-0edb922bd84f", //表单ID
  2412. * "name": "报销申请表单", //表单名称
  2413. * "alias": "报销申请表单", //表单别名
  2414. * "description": "", //表单描述
  2415. * "application": "1dc23336-6be6-402b-bed6-36e707a1dd17", //应用ID
  2416. * "lastUpdatePerson": "XX@huqi@P", //最后修改人
  2417. * "lastUpdateTime": "2018-09-30 22:46:30", //最后修改时间
  2418. * "icon": "...", //表单图标
  2419. * }</code></pre>
  2420. * @o2syntax
  2421. * var form = this.form.getInfor();
  2422. */
  2423. "getInfor": function(){return ev.formInfor;},
  2424. "infor": ev.formInfor,
  2425. /**
  2426. * 获取打开当前文档的component对象。平台中每一个窗口应用,就是一个component对象。此处获取到的对象为x_component_process_Work。
  2427. * @method getApp
  2428. * @static
  2429. * @return {x_component_process_Work}打开当前文档的component对象.
  2430. * @o2syntax
  2431. * var app = this.form.getApp();
  2432. * @example
  2433. * var app = this.form.getApp();
  2434. //所有component对象都有以下方法。
  2435. app.openInNewWindow(); //在新窗口中打开当前应用
  2436. app.setCurrent(); //将当前应用设置为激活状态
  2437. app.minSize(); //应用窗口最小化
  2438. app.maxSize(); //应用窗口最大化
  2439. app.restoreSize(); //应用窗口还原
  2440. app.refresh(); //刷新应用
  2441. app.close(); //关闭应用
  2442. app.setTitle(str); //设置应用标题
  2443. app.dialog(option); //弹出一个对话框(详见MWF.widget.Dialog)
  2444. //显示一个通知消息
  2445. app.notice(content, type, target, where, offset);
  2446. //显示一个确认框
  2447. app.confirm(type, e, title, text, width, height, ok, cancel);
  2448. //弹出一个信息框
  2449. app.alert(type, e, title, text, width, height);
  2450. //为应用绑定一个事件
  2451. app.addEvent(type, fun);
  2452. */
  2453. "getApp": function(){return _form.app;},
  2454. "app": _form.app,
  2455. /**
  2456. * 获取Form对应的DOM对象。
  2457. * @method node
  2458. * @static
  2459. * @return {HTMLDivElement} 当前form对应的div对象.
  2460. * @o2syntax
  2461. * var node = this.form.node();
  2462. */
  2463. "node": function(){return _form.node;},
  2464. // "readonly": _form.options.readonly,
  2465. /**
  2466. * 获取表单元素对象。<br/>
  2467. * <table>
  2468. * <tr><td>Actionbar(操作条)</td><td>Address(地址输入框)</td><td>Attachment(附件框)</td><td>Button(按钮)</td></tr>
  2469. * <tr><td>Calendar(日期输入框)</td><td>Checkbox(多选按钮)</td><td>Combox(组合框)</td><td>Datagrid(数据网格)</td></tr>
  2470. * <tr><td>Div(容器)</td><td>Htmleditor(富文本编辑框)</td><td>Html(内置html)</td><td>Iframe(嵌入Iframe)</td></tr>
  2471. * <tr><td>Image(图片)</td><td>Label(文本)</td><td>Log(流程意见)</td><td>Monitor(流程监控)</td></tr>
  2472. * <tr><td>Number(数字输入框)</td><td>Office(office控件)</td><td>Opinion(意见框)</td><td>Org(人员组织选择)</td></tr>
  2473. * <tr><td>Radio(单选按钮)</td><td>Select(选择框)</td><td>Sidebar(侧边操作条)</td><td>Stat(统计组件)</td></tr>
  2474. * <tr><td>Subform(子表单)</td><td>Tab(分页)</td><td>Table(表格)</td><td>Textarea(多行输入)</td></tr>
  2475. * <tr><td>Textfield(文本输入框)</td><td>Tree(树状控件)</td><td>View(视图组件)</td><td>ViewSelector(视图选择组件)</td></tr>
  2476. * <tr><td>Documenteditor(公文编辑器)</td><td>ImageClipper(图片编辑器)</td><td></td><td></td></tr>
  2477. * </table>
  2478. * @method get
  2479. * @static
  2480. * @return {FormComponent} 请查看本文档的Classes导航下的FormComponents。
  2481. * @param {String} name 字段标识
  2482. * @param {String} [subformName] 子表单/部件标识。当开发人员在插入子表单的时候,系统会检查输入类型(会在后台存值)的组件是否重名,如果重名则不允许插入。
  2483. * 但是布局组件(如div)重名会被允许。系统在展现表单的时候会判断子表单中组件的标识是否被使用,如果是会自动在组件前加上"子表单标识_",如:主表单有一个"div_1",则子表单"subform1"的"div_1"组件标识则变为"subform1_div_1"。
  2484. * 本参数就是用在这种情况下,可以正确返回子表单中的组件。
  2485. * @o2syntax
  2486. * var field = this.form.get(name);
  2487. * @o2syntax
  2488. * var field = this.form.get(name, subformName);
  2489. * @example
  2490. * var field = this.form.get("subject");
  2491. * @example
  2492. * var field = this.form.get("div", "subform1"); //获取子表单“subform1”中的div,如果子表单无此组件,而主表单有,则返回主表单的组件。
  2493. */
  2494. "get": function(name,subformName ){
  2495. if( !_form.all )return null;
  2496. if( subformName ){
  2497. if( _form.all[subformName +"_"+ name] )return _form.all[subformName +"_"+ name];
  2498. return _form.all[name];
  2499. }else{
  2500. return _form.all[name];
  2501. }
  2502. // return (_form.all) ? _form.all[name] : null;
  2503. },
  2504. /**
  2505. * 获取表单中可输入的字段元素对象。<br/>
  2506. * <table>
  2507. * <tr><td>Address(地址输入框)</td><td>Attachment(附件框)</td><td>Calendar(日期输入框)</td><td>Checkbox(多选按钮)</td></tr>
  2508. * <tr><td>Combox(组合框)</td><td>Datagrid(数据网格)</td><td>Htmleditor(富文本编辑框)</td><td>Number(数字输入框)</td></tr>
  2509. * <tr><td>Org(人员组织选择)</td><td>Radio(单选按钮)</td><td>Select(选择框)</td><td>Textarea(多行输入)</td></tr>
  2510. * <tr><td>Textfield(文本输入框)</td><td></td><td></td><td></td></tr>
  2511. * </table>
  2512. * @method getField
  2513. * @static
  2514. * @return {FormComponent} 请查看本文档的Classes导航下的FormComponents。
  2515. * @param {String} name 字段标识
  2516. * @o2syntax
  2517. * var field = this.form.getField(name);
  2518. * @example
  2519. * var field = this.form.getField("subject");
  2520. */
  2521. "getField": function(name){return _forms[name];},
  2522. "getAction": function(){return _form.workAction},
  2523. "getDesktop": function(){return _form.app.desktop},
  2524. /**获取业务数据
  2525. * @method getData
  2526. * @static
  2527. * @see module:data
  2528. * @o2syntax
  2529. * var data = this.form.getData();
  2530. * @return {Object} 返回表单绑定的业务数据。
  2531. */
  2532. "getData": function(){return new MWF.xScript.JSONData(_form.getData());},
  2533. /**保存当前表单所绑定的业务数据。<br/>
  2534. * this.form.save()会触发 beforeSave和afterSave事件,因此在beforeSave和afterSave中不允许使用本方法。同时不建议在queryLoad里使用本方法。
  2535. * @method save
  2536. * @static
  2537. * @param {Function} [callback] - 保存后的回调
  2538. * @param {Boolean} [silent] - 是否静默,否提示保存成功,默认为false
  2539. * @o2syntax
  2540. * this.form.save(callback, silent);
  2541. * @example
  2542. * this.form.save(function(){
  2543. * //do someting
  2544. * }, true);
  2545. */
  2546. "save": function(callback, silent){_form.saveWork(callback, silent); },
  2547. /**
  2548. *关闭当前表单
  2549. * @method close
  2550. * @static
  2551. * @example
  2552. * this.form.close();
  2553. */
  2554. "close": function(){_form.closeWork();},
  2555. /**
  2556. *挂起当前待办
  2557. * @method pauseTask
  2558. * @static
  2559. * @example
  2560. * this.form.pauseTask();
  2561. */
  2562. "pauseTask": function(){_form.pauseTask();},
  2563. /**
  2564. *将待办从挂起状态恢复为正常状态
  2565. * @method resumeTask
  2566. * @static
  2567. * @example
  2568. * this.form.resumeTask();
  2569. */
  2570. "resumeTask": function(){_form.resumeTask();},
  2571. /**本校验不包括校验意见,校验路由;通常用在弹出提交界面时候的校验
  2572. * @summary 根据表单中所有组件的校验设置和“流转校验”脚本进行校验。
  2573. * @method verify
  2574. * @static
  2575. * @o2syntax
  2576. * this.form.verify()
  2577. * @example
  2578. * if( !this.form.verify() ){
  2579. * return false;
  2580. * }
  2581. * @return {Boolean} 是否通过校验
  2582. */
  2583. "verify": function(){
  2584. return !(!_form.formCustomValidation("", "") || !_form.formValidation("", ""));
  2585. },
  2586. /**对当前表单打开的流程实例进行流转。<b>(仅流程表单中可用)</b><br/>
  2587. * 可以通过this.workContext.getControl().allowProcessing来判断当前用户是否有权限进行流转。<br/>
  2588. * this.form.process()会触发 beforeSave、afterSave、beforeProcess、afterProcess事件,因此在上述事件中不允许使用本方法。
  2589. * @method process
  2590. * @static
  2591. * @param {Object} [option] - 流程的相关数据,如果不带此参数,则弹出路由选择和意见填写框<br/>
  2592. * 格式如下:
  2593. <pre><code class="language-js">
  2594. {
  2595. "routeName": "", //流转到下一步要选择的路由名称
  2596. "opinion": "", //流转意见
  2597. "callback": function(json){} //回调方法,有json参数表示正常流转,json参数为流转后返回的数据。
  2598. }
  2599. </code></pre>
  2600. * @example
  2601. //不带参数,弹出路由选择和意见填写框
  2602. this.form.process();
  2603. * @example
  2604. //带参数,流转
  2605. this.form.process({
  2606. "routeName": "送审批",
  2607. "opinion": "同意",
  2608. "callback": function(json){
  2609. if(json)this.form.notice("process success", "success");
  2610. }.bind(this)
  2611. });
  2612. */
  2613. "process": function(option){
  2614. var op = _form.getOpinion();
  2615. var mds = op.medias;
  2616. if (option){
  2617. _form.submitWork(option.routeName, option.opinion, mds, option.callback,
  2618. option.processor, null, option.appendTaskIdentityList, option.processorOrgList, option.callbackBeforeSave );
  2619. }else{
  2620. _form.processWork();
  2621. }
  2622. },
  2623. /**对当前文档的待办重新设定处理人。<b>(仅流程表单中可用)</b><br/>
  2624. * 可以通过this.workContext.getControl().allowReset来判断当前用户是否有权限重置处理人。<br/>
  2625. * @method reset
  2626. * @static
  2627. * @param {Object} [option] - 进行重置处理人的相关参数,如果不带此参数,弹出重置处理人对话框<br/>
  2628. * 格式如下:
  2629. <pre><code class="language-js">
  2630. {
  2631. "names": "", //{Array|String} 要重置给哪些身份
  2632. "opinion": "", //流转意见
  2633. "success": function(){}, //重置成功后的回调方法
  2634. "failure": function(){} //重置失败后的回调方法
  2635. }
  2636. </code></pre>
  2637. * @example
  2638. //不带参数,弹出重置处理人对话框,用户确定后会触发 beforeReset、afterReset事件,因此在这两个事件中不允许使用本方法。
  2639. this.form.reset();
  2640. * @example
  2641. //带参数,直接调用后台服务重置,不会触发 beforeReset、afterReset事件
  2642. this.form.reset({
  2643. "names": ["张三@zhangsan@I"],
  2644. "opinion": "授权处理",
  2645. "success": function(json){
  2646. this.form.notice("reset success", "success");
  2647. }.bind(this),
  2648. "failure": function(xhr, text, error){
  2649. //xhr--HttpRequest请求对象
  2650. //text--HttpResponse内容文本
  2651. //error--错误信息
  2652. this.form.notice("reset failure:"+error, "error");
  2653. }.bind(this)
  2654. });
  2655. */
  2656. "reset": function(option){
  2657. if (!option){
  2658. if (_form.businessData.control["allowReset"]) _form.resetWork();
  2659. }else{
  2660. _form.resetWorkToPeson(option.names, option.opinion, option.routeName || "", option.success, option.failure);
  2661. }
  2662. },
  2663. /**撤回文档操作,上一个处理人收回已经流转下去的文件。<b>(仅流程表单中可用)</b><br/>
  2664. * 这个操作只允许上一个处理人在流转文件之后,下一个处理人未处理的时候执行。<br/>
  2665. * 可以通过this.workContext.getControl().allowRetract来判断当前用户是否有权限撤回。<br/>
  2666. * @method retract
  2667. * @static
  2668. * @param {Object} [option] - 进行撤回的相关参数,如果不提供option参数,则弹出撤回对话框。<br/>
  2669. * 格式如下:
  2670. <pre><code class="language-js">
  2671. {
  2672. "success": function(){}, //撤回成功后的回调方法
  2673. "failure": function(){} //撤回失败后的回调方法
  2674. }
  2675. </code></pre>
  2676. * @example
  2677. //不带参数,则弹出撤回对话框,用户确定后会触发 beforeRetract、afterRetract事件,因此在这两个事件中不允许使用本方法。
  2678. this.form.retract();
  2679. * @example
  2680. //带参数,直接调用后台服务撤回,不会出发beforeRetract、afterRetract事件
  2681. this.form.retract({
  2682. "success": function(json){
  2683. this.form.notice("retract success", "success");
  2684. }.bind(this),
  2685. "failure": function(xhr, text, error){
  2686. //xhr--HttpRequest请求对象
  2687. //text--HttpResponse内容文本
  2688. //error--错误信息
  2689. this.form.notice("retract failure: "+error, "error");
  2690. }.bind(this)
  2691. });
  2692. */
  2693. "retract": function(option){
  2694. if (!option){
  2695. if (_form.businessData.control["allowRetract"]) _form.retractWork();
  2696. }else{
  2697. _form.doRetractWork(option.success, option.failure);
  2698. }
  2699. },
  2700. /**在已拆分的工作上添加分支。<b>(仅流程表单中可用)</b><br/>
  2701. * 可以通过this.workContext.getControl().allowAddSplit来判断当前用户是否有权限。<br/>
  2702. * @method addSplit
  2703. * @static
  2704. * @param {Object} [option] - 添加分支的相关参数,如果不提供option参数,则弹出添加分支对话框。<br/>
  2705. * 格式如下:
  2706. <pre><code class="language-js">
  2707. {
  2708. "value" : [], //splitValueList 添加的拆分值,拆分值取决于流程拆分节点的设置
  2709. "trimExist" : true, //排除已经存在的拆分值.
  2710. "success": function(){}, //执行成功后的回调方法
  2711. "failure": function(){} //执行失败后的回调方法
  2712. }
  2713. </code></pre>
  2714. * @example
  2715. //不带参数,则弹出添加分支对话框,用户确定后会触发beforeAddSplit、afterAddSplit事件
  2716. this.form.addSplit();
  2717. * @example
  2718. //带参数,直接调用后天服务添加分支,不会触发beforeAddSplit、afterAddSplit事件
  2719. this.form.addSplit({
  2720. "value" : ["开发部@kfb@U"],
  2721. "trimExist" : true,
  2722. "success": function(json){
  2723. this.form.notice("addSplit success", "success");
  2724. }.bind(this),
  2725. "failure": function(xhr, text, error){
  2726. //xhr--HttpRequest请求对象
  2727. //text--HttpResponse内容文本
  2728. //error--错误信息
  2729. this.form.notice("addSplit failure: "+error, "error");
  2730. }.bind(this)
  2731. });
  2732. */
  2733. "addSplit": function(option){
  2734. if (!option){
  2735. if (_form.businessData.control["allowAddSplit"]) _form.addSplit();
  2736. }else{
  2737. _form.addSplitWork(option.value, option.trimExist, option.success, option.failure);
  2738. }
  2739. },
  2740. "rollback": function(option){
  2741. if (!option){
  2742. if (_form.businessData.control["allowRollback"]) _form.rollback();
  2743. }else{
  2744. _form.doRollbackActionInvoke(option.log, option.flow, option.success, option.failure);
  2745. }
  2746. },
  2747. /**删除当前工作文档。<b>(仅流程表单中可用)</b><br/>
  2748. * 可以通过this.workContext.getControl().allowDeleteWork来判断当前用户是否有权限删除文档。<br/>
  2749. * @method deleteWork
  2750. * @static
  2751. * @param {Object} [option] - 删除相关参数,如果不提供option参数,则弹出删除对话框。<br/>
  2752. * 格式如下:
  2753. <pre><code class="language-js">
  2754. {
  2755. "success": function(){}, //执行成功后的回调方法
  2756. "failure": function(){} //执行失败后的回调方法
  2757. }
  2758. </code></pre>
  2759. * @example
  2760. //不带参数,则弹出删除提示对话框,用户确定后触发beforeDelete和afterDelete事件
  2761. this.form.deleteWork();
  2762. * @example
  2763. //带参数,直接调用服务删除,不触发beforeDelete和afterDelete事件
  2764. this.form.deleteWork({
  2765. "success": function(json){
  2766. this.form.notice("deleteWork success", "success");
  2767. }.bind(this),
  2768. "failure": function(xhr, text, error){
  2769. //xhr--HttpRequest请求对象
  2770. //text--HttpResponse内容文本
  2771. //error--错误信息
  2772. this.form.notice("deleteWork failure: "+error, "error");
  2773. }.bind(this)
  2774. });
  2775. */
  2776. "deleteWork": function(option){
  2777. if (!option){
  2778. if (_form.businessData.control["allowDelete"]) _form.deleteWork();
  2779. }else{
  2780. _form.doDeleteWork(option.success, option.failure);
  2781. }
  2782. },
  2783. /**对当前工作发送待阅。<b>(仅流程表单中可用)</b><br/>
  2784. * 能查看工作的人都有权限发送。<br/>
  2785. * this.form.sendRead()会触发 beforeSendRead、afterSendRead,因此在上述事件中不允许使用本方法。
  2786. * @method sendRead
  2787. * @static
  2788. * @param {Object} [option] - 发送待阅的相关参数,如果不带此参数,弹出发送待阅对话框<br/>
  2789. * 格式如下:
  2790. <pre><code class="language-js">
  2791. {
  2792. "identityList": "", //{Array|String} 要给哪些身份发送待阅
  2793. "notify": true, //是否发送待阅通知(需要服务器开启消息)
  2794. "success": function(){}, //成功后的回调方法
  2795. "failure": function(){} //失败后的回调方法
  2796. }
  2797. </code></pre>
  2798. * @example
  2799. //不带参数,弹出发送待阅对话框,确定后触发beforeSendRead,afterSendRead事件
  2800. this.form.sendRead();
  2801. * @example
  2802. //带参数,直接调用后台服务发送待阅,触发beforeSendRead,afterSendRead事件
  2803. this.form.sendRead({
  2804. "identityList": ["张三@zhangsan@I"],
  2805. "notify": false,
  2806. "success": function(json){
  2807. this.form.notice("send read success", "success");
  2808. }.bind(this),
  2809. "failure": function(xhr, text, error){
  2810. //xhr--HttpRequest请求对象
  2811. //text--HttpResponse内容文本
  2812. //error--错误信息
  2813. this.form.notice("send read failure:"+error, "error");
  2814. }.bind(this)
  2815. });
  2816. */
  2817. "sendRead": function(option){
  2818. if (!option){
  2819. _form.sendRead();
  2820. }else{
  2821. if( option.identityList && typeOf(option.identityList) === "string" ){
  2822. option.identityList = [option.identityList];
  2823. }
  2824. _form.doSendRead(option);
  2825. }
  2826. },
  2827. /**对当前工作添加阅读人(参阅)。<b>(仅流程表单中可用)</b><br/>
  2828. * 能查看工作的人都有权限添加。<br/>
  2829. * this.form.addReview()会触发 beforeAddReview、afterAddReview,因此在上述事件中不允许使用本方法。
  2830. * @method addReview
  2831. * @static
  2832. * @param {Object} [option] - 添加阅读人的相关参数,如果不带此参数,弹出添加阅读人对话框<br/>
  2833. * 格式如下:
  2834. <pre><code class="language-js">
  2835. {
  2836. "personList": "", //{Array|String} 要添加哪些阅读人
  2837. "success": function(){}, //成功后的回调方法
  2838. "failure": function(){} //失败后的回调方法
  2839. }
  2840. </code></pre>
  2841. * @example
  2842. //不带参数,弹出添加阅读人对话框,触发beforeAddReview和afterAddReview事件。
  2843. this.form.addReview();
  2844. * @example
  2845. //带参数,直接调用后台服务发送待阅,触发beforeAddReview和afterAddReview事件。
  2846. this.form.addReview({
  2847. "personList": ["张三@zhangsan@P"],
  2848. "success": function(json){
  2849. this.form.notice("add review success", "success");
  2850. }.bind(this),
  2851. "failure": function(xhr, text, error){
  2852. //xhr--HttpRequest请求对象
  2853. //text--HttpResponse内容文本
  2854. //error--错误信息
  2855. this.form.notice("add review failure:"+error, "error");
  2856. }.bind(this)
  2857. });
  2858. */
  2859. "addReview": function(option){
  2860. if (!option){
  2861. _form.addReview();
  2862. }else{
  2863. if( option.personList && typeOf(option.personList) === "string" ){
  2864. option.personList = [option.personList];
  2865. }
  2866. _form.doAddReview(option);
  2867. }
  2868. },
  2869. /**创建关联当前工作的聊天群。<b>(仅流程表单中可用)</b><br/>
  2870. * 根据当前工作的关联人员创建聊天群。<br/>
  2871. * @method startIM
  2872. * @static
  2873. * @param {String} [jobId] - 当前工作的jobId<br/>
  2874. *
  2875. * @example
  2876. //带参数,启动创建界面
  2877. this.form.startIM("jobId");
  2878. */
  2879. "startIM": function(jobId){
  2880. _form.openIMChatStarter(jobId);
  2881. },
  2882. /**分享当前工作到IM聊天会话中。<b>(仅流程表单中可用)</b><br/>
  2883. * @method shareToIMChat
  2884. * @static
  2885. *
  2886. * @example
  2887. //不带参数
  2888. this.form.shareToIMChat();
  2889. */
  2890. "shareToIMChat": function(){
  2891. _form.shareToIMChat();
  2892. },
  2893. /**添加待办人,可用于加签等操作。<b>(仅流程表单中可用)</b><br/>
  2894. * 可以通过this.workContext.getControl().allowAddTask来判断当前用户是否有权限。<br/>
  2895. * @method addTask
  2896. * @static
  2897. * @param {Object} [option] - 添加待办人的相关参数,如果不提供option参数,则弹出加签对话框。<br/>
  2898. * 格式如下:
  2899. * <pre><code class="language-js">
  2900. * {
  2901. * "mode" : "single", //加签模式:single,queue,parallel
  2902. * "before" : true, //是否是前加签,false后加签.
  2903. * "distinguishedNameList": [], //加签人的身份数组。
  2904. * "routeName" : "", //增加待办在流程记录中显示的路由.
  2905. * "opinion" : "", //加签意见
  2906. * "success": function(){}, //执行成功后的回调方法
  2907. * "failure": function(){} //执行失败后的回调方法
  2908. * }
  2909. </code></pre>
  2910. * @example
  2911. * //不带参数,则弹出加签对话框
  2912. * this.form.addTask();
  2913. * @example
  2914. * //带参数,根据参数执行添加待办操作
  2915. * this.form.addTask({
  2916. * "mode" : "single",
  2917. * "before": false,
  2918. * "distinguishedNameList": ["张三@XXXX@I", "李四@XXXX@I"],
  2919. * "routeName" : "添加审阅人",
  2920. * "opinion" : "请张三、李四审阅",
  2921. * "success": function(json){
  2922. * this.form.notice("addTask success", "success");
  2923. * }.bind(this),
  2924. * "failure": function(xhr, text, error){
  2925. * //xhr--HttpRequest请求对象
  2926. * //text--HttpResponse内容文本
  2927. * //error--错误信息
  2928. * this.form.notice("addTask failure: "+error, "error");
  2929. * }.bind(this)
  2930. * });
  2931. */
  2932. "addTask": function(option){
  2933. if (option){
  2934. (function(callback){
  2935. if (_form.businessData.control["allowSave"]){
  2936. _form.saveFormData(callback);
  2937. }else{
  2938. if (callback) callback();
  2939. }
  2940. })(function(){
  2941. // if (!option.identity){
  2942. // option.identity = (_form.businessData.task) && _form.businessData.task.identityDn;
  2943. // }
  2944. // var workId = _form.businessData.work.id;
  2945. // o2.Actions.load("x_processplatform_assemble_surface").WorkAction.V2AddManualTaskIdentityMatrix(workId, option, option.success, option.failure);
  2946. // var taskId = _form.businessData.task.id;
  2947. // o2.Actions.load("x_processplatform_assemble_surface").TaskAction.v3Add(taskId, option, option.success, option.failure);
  2948. _form.doAddTaskToPeople(option.distinguishedNameList, option.opinion, option.mode, option.before, option.routeName || "", option.success, option.failure)
  2949. });
  2950. }else{
  2951. if (_form.businessData.control["allowAddTask"]) _form.addTask();
  2952. }
  2953. },
  2954. /**弹出一个确认框,带确认和关闭按钮
  2955. * @method confirm
  2956. * @static
  2957. * @param {String} type - 要显示的信息类型。可选值:success 成功,info :信息,error :错误, wran : 警告
  2958. * @param {String} title - 确认框标题栏显示文本。
  2959. * @param {String|Object} text - 确认框的内容显示文本。值为html的时候见下面的样例“使用html传入内容”。
  2960. * @param {Number} width - 确认框的宽度。
  2961. * @param {String} height - 确认框的高度。
  2962. * @param {Function} ok - 点击“确定”按钮后的回调函数。
  2963. * @param {Function} cancel - 点击“取消”按钮后的回调函数。
  2964. * @example
  2965. *this.form.confirm("wran", "删除确认", "您确定要删除吗?", 300, 100,function(){
  2966. * //执行删除代码
  2967. * this.close();
  2968. *}, function(){
  2969. * this.close();
  2970. *});
  2971. * @example
  2972. * //使用html传入内容, v8.1开始支持
  2973. *this.form.confirm("wran", "删除确认", {
  2974. * html: "您确定要删除吗!<br/>"
  2975. *}, 300, 100,function(){
  2976. * //执行删除代码
  2977. * this.close();
  2978. *}, function(){
  2979. * this.close();
  2980. *});
  2981. */
  2982. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  2983. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  2984. var p = MWF.getCenter({"x": width, "y": height});
  2985. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  2986. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  2987. }else{
  2988. e = (arguments.length>1) ? arguments[1] : null;
  2989. title = (arguments.length>2) ? arguments[2] : null;
  2990. text = (arguments.length>3) ? arguments[3] : null;
  2991. width = (arguments.length>4) ? arguments[4] : null;
  2992. height = (arguments.length>5) ? arguments[5] : null;
  2993. ok = (arguments.length>6) ? arguments[6] : null;
  2994. cancel = (arguments.length>7) ? arguments[7] : null;
  2995. callback = (arguments.length>8) ? arguments[8] : null;
  2996. mask = (arguments.length>9) ? arguments[9] : null;
  2997. style = (arguments.length>10) ? arguments[10] : null;
  2998. // var p = MWF.getCenter({"x": width, "y": height});
  2999. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  3000. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  3001. }
  3002. },
  3003. /**弹出一个带关闭按钮的信息框
  3004. * @method alert
  3005. * @static
  3006. * @param {String} type - 要显示的信息类型。可选值:success 成功,info :信息,error :错误, wran : 警告
  3007. * @param {String} title - 信息框标题栏显示文本。
  3008. * @param {String|Object} text - 信息框的内容显示文本。值为html的时候见下面的样例“使用html传入内容”。
  3009. * @param {Number} width - 信息框宽度。
  3010. * @param {String} height - 信息框的高度。
  3011. * @example
  3012. * this.form.alert("wran", "必填提醒", "请填写标题!", 300, 100);
  3013. * @example
  3014. * //使用html传入内容
  3015. * this.form.alert("wran", "必填提醒", {
  3016. * html: "请填写标题!<br/>"
  3017. * }, 300, 100);
  3018. */
  3019. "alert": function(type, title, text, width, height){
  3020. _form.alert(type, title, text, width, height);
  3021. },
  3022. /**弹出一个提示框
  3023. * @method notice
  3024. * @static
  3025. * @param {String} content - 要显示的信息文本
  3026. * @param {String} [type] - 要显示的信息类型。可选值:success 成功,info :信息,error :错误, warn : 警告
  3027. * @param {Element} [target] - 信息框显示位置的参考DOM对象。
  3028. * @param {Object} [where] - 信息框显示相对于target的x轴和y轴位置。<br/>
  3029. * 如: {"x": "center", "y": "center"}<br/>
  3030. x : <br/>
  3031.  水平位置,可用“left”、“right”和“center”;可以用数组定义外部(outside)位置和内部(inside)位置,如:['right', 'inside']<br/>
  3032. y :<br/>
  3033.  垂直位置,可用“top”、“bottom”和“center”;可以用数组定义外部(outside)位置和内部(inside)位置,如:['top', 'outside']。
  3034. * @param {Object} [offset] - 相对位置的偏移量,允许负值。如:{"x": 10, "y": -10}
  3035. * @param {Object} [option] - 其他选项。如: { delayClose: 5000 } 在5秒后关闭
  3036. * @example
  3037. this.form.notice("this is my information", "info");
  3038. */
  3039. "notice": function(content, type, target, where, offset, option){
  3040. _form.notice(content, type, target, where, offset, option);
  3041. },
  3042. /**弹出一个对话框层。
  3043. * @method dialog
  3044. * @static
  3045. * @return {Object} 对话框对象。
  3046. * @param {(Object)} options
  3047. * 弹出框选项:<br/>
  3048. * 如果有buttonList参数,则ok,cancel参数无效。<br/>
  3049. * 对话框内容的优先级为moduleName、content、url、html、text,有前面的参数则后面的参数无效。<br/>
  3050. * 调用弹出框对象后各事件执行先后顺序 onQueryLoad-->onPostLoad-->onQueryShow-->onPostShow。<br/>
  3051. * 其他说明如下:
  3052. * <pre><code class="language-js">{
  3053. * "style" : "default", //(string)可选,弹出框使用的样式,默认是user,系统内置一些样式,比如:user,blue_flat,o2,flat等,对应样式文件位置:webserver\o2_core\o2\widget\$Dialog,用户也可以自己增加自定义样式风格,对应文件及结构参考已有样式风格。
  3054. * "title" : "", //(string)可选,弹出框头部标题,在isTitle参数为true时有效。
  3055. * "width" : 300, //(number)可选,弹出框宽度。 默认值:300
  3056. * "height" : 150, //(number)可选,弹出框高度。 默认值:150
  3057. * "isTitle" : true, //(boolean)可选,弹出框是否有标题栏。默认值:true。
  3058. * "isMax" : false, //(boolean)可选,标题栏是否有最大化按钮,相对应有还原按钮,默认值:false。
  3059. * "isClose" : false, //(boolean)可选,标题栏是否有关闭按钮。默认值:false。
  3060. * "isResize" : true, //(boolean)可选,弹出框大小是否可调整。默认值:true。
  3061. * "isMove" : true, //(boolean)可选,弹出框是否可移动。默认值:true。
  3062. * "offset" : {"x":-200, "y": -100}, //(object)可选,弹出框相对容器(container)的x轴y轴位置偏移量,空则居中。
  3063. * "mask" : true, //(boolean)可选,是否需要遮罩层。默认值:true。
  3064. * "duration" : true, //(number)可选,动画显示弹出框效果时间。默认值:200。
  3065. * "zindex": 100, //(number)可选,弹出框的z轴优先级,默认为100(日期控件的zindex为300,选人控件为1000,最好不要高于300)。
  3066. * "buttonList" : [
  3067. * {
  3068. * "type": "ok", //(string) 样式,彩色底的按钮
  3069. * "text": "确定", //(string)text:按钮显示名称
  3070. * "action": function(){ //(function) 按钮对应的点击事件
  3071. * //do something,this指向本对话框对象
  3072. * this.close();
  3073. * }
  3074. * },
  3075. * {
  3076. * "type": "cancel", //(string) 样式,灰色底的按钮
  3077. * "text": "取消",
  3078. * "action": function(){
  3079. * //do something
  3080. * this.close();
  3081. * }
  3082. * }
  3083. * ], //(Array)可选,定义底部按钮,数组列表。无该参数则默认有确定和取消两个按钮,这个时候options可以传入ok或者cancel方法作为回调。如果传入空数组“[]”则底部无按钮。
  3084. * "ok": function(){}, //(function) 可选,无options.buttonList参数的时候,该方法作为“确定”按钮的回调方法,返回true关闭对话框,options.buttonList不为空则忽略该方法。
  3085. * "close": function(){}, //(function) 可选,无options.buttonList参数的时候,该方法作为“取消”按钮的回调方法,返回true关闭对话框,options.buttonList不为空则忽略该方法。
  3086. * "container" : this.form.getApp().content, //(Element/Dom)可选,弹出框层dom对象的父dom,位置相对对象。移动端默认插入到body中,PC端默认插入到表单节点所在容器(this.form.getApp().content)。
  3087. * "moduleName": "div_1", //内容参数,优先级为1,(String)可选,表示表单组件名称,系统会获取该组件的node节点作为对话框内容,关闭对话框节点会插回到原来的位置。
  3088. * "content": this.form.get("div1").node, //内容参数,优先级为2,(Element/Dom)可选,对话框内容,如果节点在document中,关闭对话框节点会插回到原来的位置。
  3089. * "url": "http://xxx/xxx.html", //内容参数,优先级为3,(String)可选,该参数所指向的内容作为对话框的内容。
  3090. * "html": "<div>html内容</div>", //内容参数,优先级为4,(String)可选,对话框的html内容。
  3091. * "text": "文本内容", //内容参数,优先级为5,(String)可选,对话框的文本内容。
  3092. * "onQueryClose": function(){}, //(function) 可选,关闭弹出框前事件,this指向对话框对象。
  3093. * "onPostClose": function(){}, //(function) 可选,关闭弹出框后事件,this指向对话框对象。
  3094. * "onQueryLoad": function(){}, //(function) 可选,弹出框载入前事件,this指向对话框对象。
  3095. * "onPostLoad": function(){}, //(function) 可选,弹出框载入后事件,this指向对话框对象。
  3096. * "onQueryShow": function(){}, //(function) 可选,弹出框显示前事件,this指向对话框对象。
  3097. * "onPostShow": function(){} //(function) 可选,弹出框显示后事件,this指向对话框对象。
  3098. * }</code></pre>
  3099. * @example
  3100. * //打开一个对话框,使用html作为内容
  3101. * var _self = this;
  3102. * var dlg = this.form.dialog({
  3103. * "title": "填写内容",
  3104. * "width": "500",
  3105. * "height": "300",
  3106. * "html": "<div>内容:</div><div><input type='text'></div>",
  3107. * "ok": function(){
  3108. * var value = this.node.getElement("input").value; //this指向对话框对象
  3109. * if( !value ){
  3110. * _self.form.notice("请填写内容", "info");
  3111. * return false; //返回false不关闭对话框
  3112. * }else{
  3113. * return true; //返回true关闭对话框
  3114. * }
  3115. * }
  3116. *});
  3117. * @example
  3118. * //打开一个对话框,使用表单中的div_1组件作为内容
  3119. * var _self = this;
  3120. * this.form.dialog({
  3121. * "title": "填写内容",
  3122. * "width": "400",
  3123. * "height": "200",
  3124. * "moduleName": "div_1", //内容为表单上的组件,标识为div_1
  3125. * "buttonList" : [
  3126. * {
  3127. * "type": "ok", //(string) 样式,彩色底的按钮
  3128. * "text": "确定", //(string)text:按钮显示名称
  3129. * "action": function(){ //(function) 按钮对应的点击事件
  3130. * //do something,this指向本对话框对象
  3131. * var value = _self.form.get("textfield").getData(); //获取div_1中的组件textfield的值
  3132. * if( !value ){
  3133. * _self.form.notice("请填写内容","info");
  3134. * }else{
  3135. * this.close();
  3136. * }
  3137. * }
  3138. * },
  3139. * {
  3140. * "type": "cancel", //(string) 样式,灰色底的按钮
  3141. * "text": "取消",
  3142. * "action": function(){
  3143. * //do something
  3144. * this.close();
  3145. * }
  3146. * }
  3147. * ]
  3148. * });
  3149. * @example
  3150. * //打开一个对话框,创建Dom节点作为内容
  3151. * var _self = this;
  3152. * var content = new Element("div");
  3153. * new Element("label", {
  3154. * text: "内容:"
  3155. * }).inject(content);
  3156. * new Element("input", {
  3157. * type: "text"
  3158. * }).inject(content);
  3159. * this.form.dialog({
  3160. * "title": "填写内容",
  3161. * "width": "400",
  3162. * "height": "200",
  3163. * "zindex": 301, //z轴优先级为301
  3164. * "content": content, //new Element创建的内容,也可以使用 this.form.get(xx).node 作为内容
  3165. * "buttonList" : [
  3166. * {
  3167. * "type": "ok", //(string) 样式,彩色底的按钮
  3168. * "text": "确定", //(string)text:按钮显示名称
  3169. * "action": function(){ //(function) 按钮对应的点击事件
  3170. * //do something,this指向本对话框对象
  3171. * var value = this.node.getElement("input").get("value"); //获取对话框节点中的input的值
  3172. * if( !value ){
  3173. * _self.form.notice("请填写内容","info");
  3174. * }else{
  3175. * this.close();
  3176. * }
  3177. * }
  3178. * },
  3179. * {
  3180. * "type": "cancel", //(string) 样式,灰色底的按钮
  3181. * "text": "取消",
  3182. * "action": function(){
  3183. * //do something
  3184. * this.close();
  3185. * }
  3186. * }
  3187. * ],
  3188. * "onQueryClose": function(){
  3189. * console.log("-onQueryClose-");
  3190. * },
  3191. * "onPostClose": function(){
  3192. * console.log("-onPostClose-");
  3193. * },
  3194. * "onQueryLoad":function(){
  3195. * console.log("-onQueryLoad-");
  3196. * },
  3197. * "onPostLoad": function(){
  3198. * console.log("-onPostLoad-");
  3199. * },
  3200. * "onQueryShow": function(){
  3201. * console.log("-onQueryshow-");
  3202. * },
  3203. * "onPostShow": function(){
  3204. * console.log("-onPostShow-");
  3205. * }.bind(this)
  3206. * });
  3207. */
  3208. "dialog": function ( options ) {
  3209. return _form.dialog( options );
  3210. },
  3211. /**弹出人员组织选择界面,支持身份、个人、组织、群组的单个选择或复合选择。该方法参数适用于 new MWF.O2Selector()。
  3212. * @method selectOrg
  3213. * @static
  3214. * @return {Object} 人员组织选择器对象。
  3215. * @param {Element} container - 人员选择界面的所在容器,默认为当前应用的容器。
  3216. * @param {Object} options - 人员组织选择选项。<br/>
  3217. * <pre><code class="language-js">{
  3218. * "type": "", //选择类型,和types二选一,可选值为 identity(身份), person(个人), unit(组织), group(群组),
  3219. * "types": [], //复合选择,和type二选一,如 ["identity", "person", "unit", "group"]
  3220. * "count": 0, //选择数量,0表示不限制
  3221. * "title": "", //选择界面的title
  3222. * "values": [], //已选择的值
  3223. *
  3224. * "groups": [], //选择的群组范围,选择群组时有效。
  3225. *
  3226. * "units": [], //选择的组织范围,选择身份和组织时有效
  3227. * "resultType" : "", //可以设置成"person"(个人),那么结果返回个人。选择身份时有效。用在选择人员,但是需要按照组织层级展现的场景。
  3228. * "dutys": [], //选择的职务范围,选择身份时有效。
  3229. * "categoryType": "", //可使用unit或duty。如果指定了选择的职务范围(dutys不为空),按unit(组织)还是按duty(职务)来展现分类,默认为按unit。该参数在选择身份时有效。
  3230. *
  3231. * "noUnit" : false, //在选择身份的时候,是否只使用include选项。
  3232. * "include" : [], //增加的可选项。选择身份的时候,没有传units表示选中全员,include不生效,可以使用onUnit选项表示只使用include选项。
  3233. * "exclude" : [], //排除的可选项
  3234. *
  3235. * "expandSubEnable" : true, //是否允许展开下一层,选择身份和组织时有效
  3236. * "selectAllEnable" : true, //分类是否允许全选下一层,选择身份和组织时有效
  3237. *
  3238. * "level1Indent" : 10, //第一级的缩进
  3239. * "indent" : 10, //后续的缩进
  3240. * "zIndex": 1000, //选择界面的zIndex,
  3241. *
  3242. * "onComplete" : function( selectedItemList ){
  3243. * //点击确定时执行
  3244. * //selectedItemList为选中的item对象,下面的selectedDataList为选中的数据
  3245. * var selectedDataList = selectedItemList.map( function(item){
  3246. * return item.data;
  3247. * })
  3248. * },
  3249. * "onCancel" : function(selector) {
  3250. * //点击取消时的事件, selector 为选择器, this为选择器
  3251. * },
  3252. * "onQueryLoad" : function(selector) {
  3253. * //加载选择器前事件, selector 为选择器, this为选择器
  3254. * },
  3255. * "onLoad" : function(selector) {
  3256. * //加载选择器后事件, selector 为选择器, this为选择器
  3257. * },
  3258. * "onCancel" : function(selector) {
  3259. * //点击取消时的事件, selector 为选择器, this为选择器
  3260. * },
  3261. * "onQueryLoadCategory" : function(category) {
  3262. * //加载分类前事件, category 为 分类对象, this为选择器
  3263. * },
  3264. * "onPostLoadCategory" : function(category) {
  3265. * //加载分类后事件, category 为 分类对象, this为选择器
  3266. * },
  3267. * "onSelectCategory" : function(category){
  3268. * //选择分类, category 为 分类对象, this为选择器
  3269. * },
  3270. * "onUnselectCategory": function(category){
  3271. * //取消选择分类, category 为 分类对象, this为选择器
  3272. * },
  3273. * "onQueryLoadItem" : function(item){
  3274. * //加载项目前事件, item 为 项目对象, this为选择器
  3275. * },
  3276. * "onPostLoadItem" : function(item){
  3277. * //加载项目后事件, item 为 项目对象, this为选择器
  3278. * },
  3279. * "onSelectItem" : function(item){
  3280. * //选择项目事件, item 为 项目对象, this为选择器
  3281. * },
  3282. * "onUnselectItem" : function(item){
  3283. * //取消选择项目事件, item 为 项目对象, this为选择器
  3284. * },
  3285. * "onExpand" : function( obj ){
  3286. * //展开分类, obj 为分类/项目, this为选择器
  3287. * },
  3288. * "onCollapse" : function(obj){
  3289. * //折叠分类,obj 为分类/项目, this为选择器
  3290. * }
  3291. *}</code></pre>
  3292. * @example
  3293. * //选择身份
  3294. * var selector = this.form.selectOrg(null, {
  3295. * type: "identity",
  3296. * onComplete : function( selectedItemList ){
  3297. * //点击确定时执行
  3298. * //selectedItemList为选中的item对象,下面的selectedDataList为选中的数据
  3299. * var selectedDataList = selectedItemList.map( function(item){
  3300. * return item.data;
  3301. * })
  3302. * }
  3303. *});
  3304. * @example
  3305. * //在限定组织内选择身份
  3306. * var selector = this.form.selectOrg(null, {
  3307. * type: "identity",
  3308. * units: ["兰德纵横@landzone@U"],
  3309. * onComplete : function( selectedItemList ){
  3310. * }
  3311. *});
  3312. * @example
  3313. * //在限定职务时选择身份
  3314. * var selector = this.form.selectOrg(null, {
  3315. * type: "identity",
  3316. * dutys: ["部门正职"],
  3317. * onComplete : function( selectedItemList ){
  3318. * }
  3319. *});
  3320. * @example
  3321. * //同时选择组织、群组、身份、个人
  3322. * var selector = this.form.selectOrg(null, {
  3323. * types: ["unit", "group", "identity", "person"],
  3324. * onComplete : function( selectedItemList ){
  3325. * }
  3326. *});
  3327. */
  3328. "selectOrg": function ( container, options, delayLoad) {
  3329. if( !container )container = _form.app.content;
  3330. return new MWF.O2Selector(container, options, delayLoad);
  3331. },
  3332. /**给表单添加事件。
  3333. * @method addEvent
  3334. * @static
  3335. * @param {String} type - 事件名称,参考本API Classer->FormComponents->Form的事件
  3336. * @param {Function} event - 事件方法。
  3337. * @example
  3338. this.form.addEvent("afterLoad", function(){
  3339. this.form.notice("表单载入完成", "success");
  3340. }.bind(this));
  3341. */
  3342. "addEvent": function(type, event ){_form.addEvent(type, event );},
  3343. /**用一个新的浏览器窗口来打开当前文档,用于打印。<b>(仅流程表单中可用)</b><br/>
  3344. * 如不指定表单,则使用表单设计中指定的打印表单。<br/>
  3345. * @method print
  3346. * @static
  3347. * @param {String} [application] - 指定表单所在的流程应用ID或名称。省略此参数表示当前应用。
  3348. * @param {String} [form] - 指定表单ID或名称。
  3349. * @example
  3350. //在新窗口中使用当前表单中配置的打印表单打开当前文档
  3351. this.form.print();
  3352. * @example
  3353. //在新窗口中使用“订单打印表单”表单打开当前文档
  3354. this.form.print("订单打印表单");
  3355. * @example
  3356. //在新窗口中使用“订单管理”应用中的“订单打印表单”表单打开当前文档
  3357. this.form.print("订单管理", "订单打印表单");
  3358. */
  3359. "print": function(application, form){
  3360. if (arguments.length){
  3361. var app = (arguments.length>1) ? arguments[0] : null;
  3362. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  3363. _form.printWork(app, formName);
  3364. }else{
  3365. _form.printWork();
  3366. }
  3367. },
  3368. /**同print方法。<b>(仅流程表单中可用)</b><br/>
  3369. * @method openWindow
  3370. * @static
  3371. * @see this.form.print()
  3372. * @param {String} [application] - 指定表单所在的流程应用ID或名称。省略此参数表示当前应用。
  3373. * @param {String} [form] - 指定表单ID或名称。
  3374. * @example
  3375. this.form.openWindow();
  3376. */
  3377. "openWindow": function(application, form){
  3378. if (arguments.length){
  3379. var app = (arguments.length>1) ? arguments[0] : null;
  3380. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  3381. _form.openWindow(formName, app);
  3382. }else{
  3383. _form.openWindow();
  3384. }
  3385. },
  3386. /** 打开一个在流转或已完成的流程实例。<br/>
  3387. * @method openWork
  3388. * @static
  3389. * @param {String} [workId] - 在流转的流程实例ID。workId和workCompletedId两个参数必须提供其中一个
  3390. * @param {String} [workCompletedId] - 已完成的流程实例ID。
  3391. * @param {String} [title] - 手机端打开时的窗口标题。
  3392. * @param {Object} [options] - 其他选项,如只读参数。
  3393. * @example
  3394. * this.form.openWork(id, "", "work title");
  3395. * @example
  3396. * //以只读方式打开
  3397. * this.form.openWork(id, "", "work title", {
  3398. * readonly : true
  3399. * });
  3400. */
  3401. "openWork": function(workId, workCompletedId, title, options){
  3402. var op = options || {};
  3403. op.workId = workId;
  3404. op.workCompletedId = workCompletedId;
  3405. op.docTitle = title;
  3406. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  3407. return layout.desktop.openApplication(this.event, "process.Work", op);
  3408. },
  3409. /** 使用流程的jobId打开工作。<br/>
  3410. * @method openJob
  3411. * @static
  3412. * @param {String} id - 流程的jobId,如果流程拆分后,有多个流程实例(workId会有多个),但jobId是唯一的。
  3413. * @param {Boolean} [choice] - 如果有多个流程实例,是否弹出界面选择。如果传入false,则直接打开第一个工作。
  3414. * @param {Object} [options] - 打开工作时传入的选项。
  3415. * @param {Function} [callback] - 打开工作成功或失败的回调方法,如果打开成功,该方法可以获取打开的工作的对象(桌面模式)或窗口句柄(浏览器页签模式);如果打开失败,此方法第一个参数是一个Error,其cause属性可获取通过jobId查询到的work数据。
  3416. * @example
  3417. this.form.openJob(jobId, true);
  3418. * @example
  3419. this.form.openJob(jobId, true, {}, function(handel){
  3420. //通过Error.prototype.isPrototypeOf(handel)来判断handel是否是一个错误。
  3421. //如果打开成功,handel为打开的工作的对象(桌面模式)或窗口句柄(浏览器页签模式)
  3422. //如果打开错误,handel为为一个Error对象,其cause属性可获取通过jobId查询到的work数据
  3423. });
  3424. */
  3425. "openJob": function(id, choice, options, callback){
  3426. var workData = null, handel;
  3427. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  3428. if (json.data) workData = json.data;
  3429. }.bind(this), null, false);
  3430. if( !layout.inBrowser && o2.typeOf(callback) === "function" ){
  3431. if( !options )options = {};
  3432. var queryLoad = options.onQueryLoad;
  3433. options.onQueryLoad = function () {
  3434. if( o2.typeOf(queryLoad) === "function" )queryLoad.call(this);
  3435. callback(this);
  3436. }
  3437. }
  3438. runCallback = function ( handel ) {
  3439. if( o2.typeOf(callback) === "function" ) {
  3440. if (layout.inBrowser) {
  3441. callback(handel);
  3442. } else if (options && options.appId) {
  3443. if (layout.desktop && layout.desktop.apps && layout.desktop.apps[options.appId]) {
  3444. callback(layout.desktop.apps[options.appId], true);
  3445. }else{
  3446. callback(handel, false);
  3447. }
  3448. }else{
  3449. callback(handel, false);
  3450. }
  3451. }
  3452. };
  3453. if (workData){
  3454. var len = workData.workList.length + workData.workCompletedList.length;
  3455. if (len){
  3456. if (len>1 && choice){
  3457. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  3458. workData.workList.each(function(work){
  3459. var workNode = new Element("div", {
  3460. "styles": {
  3461. "background": "#ffffff",
  3462. "border-radius": "10px",
  3463. "clear": "both",
  3464. "margin-bottom": "10px",
  3465. "height": "40px",
  3466. "padding": "10px 10px"
  3467. }
  3468. }).inject(node);
  3469. 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>" +
  3470. "<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>"+
  3471. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  3472. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  3473. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  3474. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  3475. workNode.set("html", html);
  3476. var action = workNode.getElement(".MWFAction");
  3477. action.store("work", work);
  3478. action.addEvent("click", function(e){
  3479. var work = e.target.retrieve("work");
  3480. if (work){
  3481. handel = this.openWork(work.id, null, work.title, options);
  3482. runCallback( handel );
  3483. }
  3484. dlg.close();
  3485. }.bind(this));
  3486. }.bind(this));
  3487. workData.workCompletedList.each(function(work){
  3488. var workNode = new Element("div", {
  3489. "styles": {
  3490. "background": "#ffffff",
  3491. "border-radius": "10px",
  3492. "clear": "both",
  3493. "margin-bottom": "10px",
  3494. "height": "40px",
  3495. "padding": "10px 10px"
  3496. }
  3497. }).inject(node);
  3498. 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>" +
  3499. "<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>"+
  3500. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  3501. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  3502. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  3503. workNode.set("html", html);
  3504. var action = workNode.getElement(".MWFAction");
  3505. action.store("work", work);
  3506. action.addEvent("click", function(e){
  3507. var work = e.target.retrieve("work");
  3508. if (work){
  3509. handel = this.openWork(null, work.id, work.title, options);
  3510. runCallback( handel );
  3511. }
  3512. dlg.close();
  3513. }.bind(this));
  3514. }.bind(this));
  3515. var height = node.getSize().y+20;
  3516. if (height>600) height = 600;
  3517. var dlg = o2.DL.open({
  3518. "title": o2.LP.widget.choiceWork,
  3519. "style" : "user",
  3520. "isResize": false,
  3521. "content": node,
  3522. "buttonList": [
  3523. {
  3524. "type" : "cancel",
  3525. "text": o2.LP.widget.close,
  3526. "action": function(){dlg.close();}
  3527. }
  3528. ]
  3529. });
  3530. }else{
  3531. if (workData.workList.length){
  3532. var work = workData.workList[0];
  3533. handel = this.openWork(work.id, null, work.title, options);
  3534. runCallback( handel );
  3535. return handel;
  3536. }else{
  3537. var work = workData.workCompletedList[0];
  3538. handel = this.openWork(null, work.id, work.title, options);
  3539. runCallback( handel );
  3540. return handel;
  3541. }
  3542. }
  3543. }else{
  3544. runCallback(new Error("Can't open this Job", {
  3545. cause: workData
  3546. }));
  3547. }
  3548. }else{
  3549. runCallback(new Error("Can't open this Job", {
  3550. cause: workData
  3551. }));
  3552. }
  3553. // var op = options || {};
  3554. // op.workId = id;
  3555. // op.workCompletedId = completedId;
  3556. // op.docTitle = title;
  3557. // op.appId = "process.Work"+(op.workId || op.workCompletedId);
  3558. // layout.desktop.openApplication(this.event, "process.Work", op);
  3559. },
  3560. /** 打开一个内容管理文档。<br/>
  3561. * @method openDocument
  3562. * @static
  3563. * @param {String} id - 内容管理文档实例的ID。
  3564. * @param {Boolean} [title] - 手机APP端打开时的窗口标题。
  3565. * @param {Object} [options] - 其他参数,内容如下<br>
  3566. * <pre><code class="language-js">{
  3567. * "readonly": true, //是否以只读方式打开,默认为true
  3568. * "forceFormId": "xxxxxx", //不管编辑还是阅读都用此表单id打开,优先使用。6.0版本之前使用 printFormId。
  3569. * "readFormId": "xxxxxx", //强制的阅读表单id,优先于表单的readFormId。6.0版本之前使用 formId。
  3570. * "editFormId": "xxxxxx", //强制的编辑表单id,优先于表单的formId。6.0版本之前使用 formEditId。
  3571. * "saveOnClose" : true, //关闭草稿的时候是否自动保存
  3572. * "onPostPublish" : function( documentData ){ //发布前执行方法,但数据已经准备好,该事件在桌面模式打开有效
  3573. * //documentData 为文档数据
  3574. * },
  3575. * "onAfterPublish" : function( form, documentData ){ //发布后执行的方法,该事件在桌面模式打开有效
  3576. * //form为内容管理Form对象,documentData 为文档数据
  3577. * },
  3578. * "onAfterSave": function( form, documentData ){ //保存后执行的方法,该事件在桌面模式打开有效
  3579. * //form为内容管理Form对象,documentData 为文档数据
  3580. * },
  3581. * "onBeforeClose": function(){ //关闭前执行的方法,该事件在桌面模式打开有效
  3582. *
  3583. * },
  3584. * "onPostDelete" : function(){ //删除文档后执行的方法,该事件在桌面模式打开有效
  3585. * }
  3586. * }</code></pre>
  3587. * @example
  3588. this.form.openDocument(id, "document title");
  3589. */
  3590. "openDocument": function(id, title, options){
  3591. var op = options || {};
  3592. op.documentId = id;
  3593. op.docTitle = title || "";
  3594. op.appId = (op.appId) || ("cms.Document"+id);
  3595. if( op.onPostPublish ){
  3596. op.postPublish = op.onPostPublish;
  3597. delete op.onPostPublish;
  3598. }
  3599. if( op.onAfterPublish ){
  3600. op.afterPublish = op.onAfterPublish;
  3601. delete op.onAfterPublish;
  3602. }
  3603. if( op.onAfterSave ){
  3604. op.afterSave = op.onAfterSave;
  3605. delete op.onAfterSave;
  3606. }
  3607. if( op.onBeforeClose ){
  3608. op.beforeClose = op.onBeforeClose;
  3609. delete op.onBeforeClose;
  3610. }
  3611. if( op.onPostDelete ){
  3612. op.postDelete = op.onPostDelete;
  3613. delete op.onPostDelete;
  3614. }
  3615. return layout.desktop.openApplication(this.event, "cms.Document", op);
  3616. },
  3617. /**打开一个门户页面。<br/>
  3618. * @method openPortal
  3619. * @static
  3620. * @param {String} portal - 要打开的门户应用名称、别名或ID。
  3621. * @param {String} [page] - 要打开的页面名称、别名或ID。如果忽略,则打开门户的默认首页
  3622. * @param {Object} [par] - 打开页面可以传入参数。<br>在被打开的页面中,可以通过脚本this.page.parameters访问到此参数。
  3623. * @example
  3624. this.form.openPortal(id, "", {"type": "my type"});
  3625. */
  3626. "openPortal": function (portal, page, par) {
  3627. var action = MWF.Actions.get("x_portal_assemble_surface");
  3628. action.getApplication(portal, function (json) {
  3629. if (json.data) {
  3630. if (page) {
  3631. action.getPageByName(page, json.data.id, function (pageJson) {
  3632. var pageId = (pageJson.data) ? pageJson.data.id : "";
  3633. layout.desktop.openApplication(null, "portal.Portal", {
  3634. "portalId": json.data.id,
  3635. "pageId": pageId,
  3636. "parameters": par,
  3637. "appId": (par && par.appId) || ("portal.Portal" + json.data.id + pageId)
  3638. })
  3639. });
  3640. } else {
  3641. layout.desktop.openApplication(null, "portal.Portal", {
  3642. "portalId": json.data.id,
  3643. "parameters": par,
  3644. "appId": (par && par.appId) || ("portal.Portal" + json.data.id)
  3645. })
  3646. }
  3647. }
  3648. });
  3649. },
  3650. /**打开一个内容管理栏目(应用)。<br/>
  3651. * @method openCMS
  3652. * @static
  3653. * @param {String} name - 内容管理栏目的名称、别名或ID。
  3654. * @example
  3655. this.form.openCMS("通知公告");
  3656. */
  3657. "openCMS": function(name){
  3658. var action = MWF.Actions.get("x_cms_assemble_control");
  3659. action.getColumn(name, function(json){
  3660. if (json.data){
  3661. layout.desktop.openApplication(null, "cms.Module", {
  3662. "columnId": json.data.id,
  3663. "appId": "cms.Module"+json.data.id
  3664. });
  3665. }
  3666. });
  3667. },
  3668. /**打开一个流程应用。<br/>
  3669. * @method openProcess
  3670. * @static
  3671. * @param {String} name - 流程应用的名称、别名或ID。
  3672. * @example
  3673. this.form.openProcess("财务审批");
  3674. */
  3675. "openProcess": function(name){
  3676. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  3677. action.getApplication(name, function(json){
  3678. if (json.data){
  3679. layout.desktop.openApplication(null, "process.Application", {
  3680. "id": json.data.id,
  3681. "appId": "process.Application"+json.data.id
  3682. });
  3683. }
  3684. });
  3685. },
  3686. /**打开任意一个component应用。<br/>
  3687. * @method openApplication
  3688. * @static
  3689. * @param {String} name - 要打开的component的名称。component对应的名称可以在“控制面板-系统设置-界面设置-模块部署”中找到(即“组件路径”)。
  3690. * @param {Object} [options] - 打开的component的相关参数,对应该应用源码Main.js中的的options。
  3691. * @param {Object} [status] - 打开的component的状态,对应用户的操作后的状态。<b>请按照下面的方式获取该参数:</b>双击桌面模式的应用,在打开应用的浏览器地址上可以查到对应的status。
  3692. * @example
  3693. //打开会议管理
  3694. this.form.openApplication("Meeting");
  3695. * @example
  3696. //打开会议管理的周视图
  3697. this.form.openApplication("Meeting", null, {"action":"toWeek" });
  3698. * @example
  3699. //打开一个流转中的流程实例。与 this.form.openWork(id, "", "work title");效果相同
  3700. this.form.openApplication("process.Work", {
  3701. "workId": id, //流程实例ID
  3702. "width": "1200", //宽度
  3703. "height": "800", //高度
  3704. "docTitle": "work title", //APP端窗口标题
  3705. "appId": "process.Work"+id //给新打开的component实例一个唯一名称
  3706. });
  3707. */
  3708. "openApplication":function(name, options, status){
  3709. return layout.desktop.openApplication(null, name, options, status);
  3710. },
  3711. /**创建一条内容管理文档。
  3712. * @method createDocument
  3713. * @static
  3714. * @param {(String|Object)} [columnOrOptions]
  3715. * 如果不传参数,则弹出范围为平台所有栏目的选择界面。<br/>
  3716. * 当使用String时为内容管理应用(栏目)的名称、别名或ID。<br/>
  3717. * 当使用Object时,本参数后面的参数省略,传入如下格式的内容:
  3718. * <pre><code class="language-js">{
  3719. * "column" : column, //(string)可选,内容管理应用(栏目)的名称、别名或ID
  3720. * "category" : category, //(string)可选,要创建的文档所属的分类的名称、别名或ID
  3721. * "data" : data, //(json object)可选,创建文档时默认的业务数据
  3722. * "identity" : identity, //(string | Array)可选,创建文档所使用的身份。如果此参数为空,且当前人有多个身份的情况下,会弹出身份选择对话框;如果此参数为数组,则弹出数组范围内的身份供选择;否则使用默认身份。
  3723. * "callback" : callback, //(funcation)可选,文档创建后的回调函数。
  3724. * "target" : target, //(boolean)可选,为true时,在当前页面打开创建的文档;否则打开新窗口。默认false。(当前表单或页面在浏览器单独打开的时候该参数有效。)
  3725. * "latest" : latest, //(boolean)可选,为true时,如果当前用户已经创建了此分类的文档,并且没有发布过,直接调用此文档为新文档;否则创建一个新文档。默认true。
  3726. * "selectColumnEnable" : selectColumnEnable, //(boolean)可选,是否可以选择应用和分类进行创建文档。有category参数时为默认false,否则默认为true。
  3727. * "ignoreTitle" : ignoreTitle //(boolean)可选,值为false时,创建的时候需要强制填写标题,默认为false。
  3728. * "restrictToColumn" : restrictToColumn //(boolean)可选,值为true时,会限制在传入的栏目中选择分类,默认为false。
  3729. * }</code></pre>
  3730. * @param {String} [category] - 要创建的文档所属的分类的名称、别名或ID
  3731. * @param {Object} [data] - 创建文档时默认的业务数据
  3732. * @param {String} [identity | Array] - 可选,创建文档所使用的身份。如果此参数为空,且当前人有多个身份的情况下,会弹出身份选择对话框;如果此参数为数组,则弹出数组范围内的身份供选择;否则使用默认身份。
  3733. * @param {Function} [callback] - 文档创建后的回调函数
  3734. * @param {Boolean} [target] - 为true时,在当前页面打开创建的文档;否则打开新窗口。默认false。(当前表单或页面在浏览器单独打开的时候该参数有效。)
  3735. * @param {Boolean} [latest] - 为true时,如果当前用户已经创建了此分类的文档,并且没有发布过,直接调用此文档为新文档;否则创建一个新文档。默认true。
  3736. * @param {Boolean} [selectColumnEnable] - 是否可以选择应用和分类进行创建文档。有category参数时为默认false,否则默认为true。
  3737. * @param {Boolean} [ignoreTitle] - 值为false时,创建的时候需要强制填写标题,默认为false。
  3738. * @param {Boolean} [restrictToColumn] - 值为true时,会限制在传入的栏目中选择分类,默认为false。
  3739. * @example
  3740. //启动一个通知公告
  3741. this.form.createDocument("", "通知公告");
  3742. * @example
  3743. //启动一个通知公告,标题为:关于XX的通知,启动后提示
  3744. this.form.createDocument("", "通知公告", {"subject": "关于XX的通知"}, function(json){
  3745. this.form.notice("创建成功!", "success");
  3746. }.bind(this));
  3747. * @example
  3748. //启动一个通知公告,标题为:关于XX的通知,启动后提示
  3749. this.form.createDocument({
  3750. category : "通知公告",
  3751. data : {"subject": "关于XX的通知"},
  3752. callback : function(json){
  3753. this.form.notice("创建成功!", "success");
  3754. }.bind(this)
  3755. });
  3756. */
  3757. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle, restrictToColumn) {
  3758. var column = columnOrOptions;
  3759. var onAfterPublish, onPostPublish;
  3760. if (typeOf(columnOrOptions) == "object") {
  3761. column = columnOrOptions.column;
  3762. category = columnOrOptions.category;
  3763. data = columnOrOptions.data;
  3764. identity = columnOrOptions.identity;
  3765. callback = columnOrOptions.callback;
  3766. target = columnOrOptions.target;
  3767. latest = columnOrOptions.latest;
  3768. selectColumnEnable = columnOrOptions.selectColumnEnable;
  3769. ignoreTitle = columnOrOptions.ignoreTitle;
  3770. restrictToColumn = columnOrOptions.restrictToColumn;
  3771. onAfterPublish = columnOrOptions.onAfterPublish;
  3772. onPostPublish = columnOrOptions.onPostPublish;
  3773. }
  3774. if (target) {
  3775. if (layout.app && layout.app.inBrowser) {
  3776. layout.app.content.empty();
  3777. layout.app = null;
  3778. }
  3779. }
  3780. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  3781. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  3782. "documentData": data,
  3783. "identity": identity,
  3784. "ignoreTitle": ignoreTitle === true,
  3785. "ignoreDrafted": latest === false,
  3786. "selectColumnEnable": !category || selectColumnEnable === true,
  3787. "restrictToColumn": restrictToColumn === true || (!!category && selectColumnEnable !== true),
  3788. "categoryFlag": category, //category id or name
  3789. "columnFlag": column, //column id or name,
  3790. "onStarted": function (documentId, data, windowHandle) {
  3791. if (callback) callback(documentId, data, windowHandle);
  3792. },
  3793. "onPostPublish": function () {
  3794. if(onPostPublish)onPostPublish();
  3795. },
  3796. "onAfterPublish": function () {
  3797. if(onAfterPublish)onAfterPublish();
  3798. }
  3799. });
  3800. starter.load();
  3801. })
  3802. },
  3803. /**启动一个流程实例。<br/>
  3804. * @method startProcess
  3805. * @static
  3806. * @param {String} app - 流程应用的名称、别名或ID。
  3807. * @param {String} process - 要启动的流程的名称、别名或ID。
  3808. * @param {Object} [data] - 流程启动时默认的业务数据。
  3809. * @param {String | Array} [identity] - 流程启动所使用的身份。如果此参数为空/空字符串,且当前人有多个身份的情况下,会弹出身份选择对话框;如果此参数为数组,则弹出数组范围内的身份供选择;否则使用默认身份。
  3810. * @param {Function} [callback] - 流程启动后的回调函数,可以获取到启动的数据。
  3811. * @param {Boolean} [target] - 为true时,在当前页面打开启动的流程实例;否则打开新窗口。默认false。(当前表单或页面在浏览器单独打开的时候该参数有效。)
  3812. * @param {Boolean} [latest] - 为true时,如果当前用户已经创建了此流程的实例,并且没有流转过,直接调用此实例为新流程实例;否则创建一个新实例。默认false。
  3813. * @param {Function} [afterCreated] - 流程创建后的回调,可以获取到创建的流程Work对象(桌面模式)或者Window对象(浏览器模式)。
  3814. * @param {Boolean} [skipDraftCheck] - 是否跳过新建检查(默认根据流程的新建检查配置),设置true则不进行新建检查。
  3815. * @example
  3816. //启动一个发文管理实例
  3817. this.form.startProcess("公文管理", "发文管理");
  3818. * @example
  3819. //启动一个发文管理实例,标题为:my file title,启动后提示
  3820. this.form.startProcess("公文管理", "发文管理", {"title": "my file title"}, "张三@kfb_zhangsan@I", function(json){
  3821. this.form.notice("create file success!", "success");
  3822. }, false, false, function(workApp){
  3823. if( layout.inBrowser ){ //浏览器模式
  3824. //workApp 为流程的window对象
  3825. }else{
  3826. //workApp 为流程Work app对象
  3827. }
  3828. });
  3829. */
  3830. "startProcess": function(app, process, data, identity, callback, target, latest, afterCreated, skipDraftCheck){
  3831. if (arguments.length>2){
  3832. for (var i=2; i<arguments.length; i++){
  3833. if (typeOf(arguments[i])=="boolean"){
  3834. target = arguments[i];
  3835. break;
  3836. }
  3837. }
  3838. }
  3839. if (target){
  3840. if (layout.app && layout.app.inBrowser){
  3841. //layout.app.content.empty();
  3842. layout.app.$openWithSelf = true;
  3843. }
  3844. }
  3845. if (!app || !process){
  3846. var cmpt = this.getApp();
  3847. o2.requireApp([["process.TaskCenter", "lp."+o2.language], ["process.TaskCenter", ""]],"", function(){
  3848. var obj = {
  3849. "lp": o2.xApplication.process.TaskCenter.LP,
  3850. "content": cmpt.content,
  3851. "addEvent": function(type, fun){
  3852. cmpt.addEvent(type, fun);
  3853. },
  3854. "getAction": function (callback) {
  3855. if (!this.action) {
  3856. this.action = o2.Actions.get("x_processplatform_assemble_surface");
  3857. if (callback) callback();
  3858. } else {
  3859. if (callback) callback();
  3860. }
  3861. },
  3862. "desktop": layout.desktop,
  3863. "refreshAll": function(){},
  3864. "notice": cmpt.notice,
  3865. }
  3866. o2.JSON.get("../x_component_process_TaskCenter/$Main/default/css.wcss", function(data){
  3867. obj.css = data;
  3868. }, false);
  3869. if (!cmpt.processStarter) cmpt.processStarter = new o2.xApplication.process.TaskCenter.Starter(obj);
  3870. cmpt.processStarter.load();
  3871. }, true, true);
  3872. return "";
  3873. }
  3874. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  3875. if (json.data){
  3876. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  3877. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  3878. "workData": data,
  3879. "identity": identity,
  3880. "latest": latest,
  3881. "skipDraftCheck": skipDraftCheck,
  3882. "onStarted": function(data, title, processName){
  3883. var application;
  3884. if (data.work){
  3885. var work = data.work;
  3886. var options = {
  3887. "draft": work,
  3888. "draftData":data.data||{},
  3889. "appId": "process.Work"+(new o2.widget.UUID).toString(),
  3890. "desktopReload": false
  3891. };
  3892. if( !layout.inBrowser && afterCreated )options.onPostLoadForm = afterCreated;
  3893. application = layout.desktop.openApplication(null, "process.Work", options);
  3894. }else{
  3895. var currentTask = [];
  3896. data.each(function(work){
  3897. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  3898. }.bind(this));
  3899. if (currentTask.length==1){
  3900. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  3901. if( !layout.inBrowser && afterCreated )options.onPostLoadForm = afterCreated;
  3902. application = layout.desktop.openApplication(null, "process.Work", options);
  3903. }else{}
  3904. }
  3905. if (callback) callback(data);
  3906. if(layout.inBrowser && afterCreated){
  3907. afterCreated(application)
  3908. }
  3909. }.bind(this)
  3910. });
  3911. starter.load();
  3912. }.bind(this));
  3913. }
  3914. });
  3915. }
  3916. };
  3917. /**
  3918. * 获取表单是否可编辑。只读。
  3919. * @member readonly
  3920. * @static
  3921. * @return {Boolean} 是否只读.
  3922. * @o2syntax
  3923. * var readonly = this.form.readonly;
  3924. */
  3925. Object.defineProperty(this.form, "readonly", {
  3926. get: function(){ return !!_form.options.readonly; }
  3927. });
  3928. /**
  3929. * 在用户提交的时候,选择的路由。仅在表单的“校验意见”和“校验路由”脚本中可用。只读。<b>(仅流程表单中可用)</b>。
  3930. * @member currentRouteName
  3931. * @memberOf module:form
  3932. * @static
  3933. * @return {String} 用户选择的路由。
  3934. * @o2syntax
  3935. * var currentRouteName = this.form.currentRouteName;
  3936. */
  3937. //this.form.currentRouteName = _form.json.currentRouteName;
  3938. /**
  3939. * 在用户提交的时候,输入的意见。仅在表单的“校验意见”和“校验路由”脚本中可用。只读。<b>(仅流程表单中可用)</b>。
  3940. * @member opinion
  3941. * @memberOf module:form
  3942. * @static
  3943. * @return {String} 用户填写的意见.
  3944. * @o2syntax
  3945. * var opinion = this.form.opinion;
  3946. */
  3947. //this.form.opinion = _form.json.opinion;
  3948. /**
  3949. * 在提交的时候,用户的手写意见以及录音意见,仅在表单的“校验意见”和“校验路由”脚本中可用。只读。<b>(仅流程表单中可用)</b>。
  3950. * @member medias
  3951. * @memberOf module:form
  3952. * @static
  3953. * @return {Blob[]} 手写意见以及录音意见数组。手写意见和录音意见都是 HTML5的blob类型文件。
  3954. * @o2syntax
  3955. * var medias = this.form.medias;
  3956. */
  3957. this.form.medias = [];
  3958. this.target = ev.target;
  3959. this.event = ev.event;
  3960. this.status = ev.status;
  3961. this.session = layout.desktop.session;
  3962. this.Actions = o2.Actions;
  3963. this.query = function(option){
  3964. // options = {
  3965. // "name": "statementName",
  3966. // "data": "json data",
  3967. // "firstResult": 1,
  3968. // "maxResults": 100,
  3969. // "success": function(){},
  3970. // "error": function(){},
  3971. // "async": true or false, default is true
  3972. // }
  3973. if (option){
  3974. var json = (option.data) || {};
  3975. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  3976. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  3977. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  3978. }
  3979. }
  3980. this.Table = MWF.xScript.createTable();
  3981. };
  3982. if( !MWF.xScript.createTable )MWF.xScript.createTable = function(){
  3983. return function(name){
  3984. this.name = name;
  3985. this.action = o2.Actions.load("x_query_assemble_surface").TableAction;
  3986. this.listRowNext = function(id, count, success, error, async){
  3987. return this.action.listRowNext(this.name, id, count, success, error, async);
  3988. };
  3989. this.listRowPrev = function(id, count, success, error, async){
  3990. return this.action.listRowPrev(this.name, id, count, success, error, async);
  3991. };
  3992. this.listRowSelect = function(where, orderBy, size, success, error, async){
  3993. return this.action.listRowSelect(this.name, {"where": where, "orderBy": orderBy, "size": size || ""}, success, error, async);
  3994. };
  3995. this.listRowSelectWhere = function(where, success, error, async){
  3996. return this.action.listRowSelectWhere(this.name, where, success, error, async);
  3997. };
  3998. this.rowCountWhere = function(where, success, error, async){
  3999. return this.action.rowCountWhere(this.name, where, success, error, async);
  4000. };
  4001. this.deleteRow = function(id, success, error, async){
  4002. return this.action.rowDelete(this.name, id, success, error, async);
  4003. };
  4004. this.deleteAllRow = function(success, error, async){
  4005. return this.action.rowDeleteAll(this.name, success, error, async);
  4006. };
  4007. this.getRow = function(id, success, error, async){
  4008. return this.action.rowGet(this.name, id, success, error, async);
  4009. };
  4010. this.insertRow = function(data, success, error, async){
  4011. return this.action.rowInsert(this.name, data, success, error, async);
  4012. };
  4013. this.addRow = function(data, success, error, async){
  4014. return this.action.rowInsertOne(this.name, data, success, error, async);
  4015. };
  4016. this.updateRow = function(id, data, success, error, async){
  4017. return this.action.rowUpdate(this.name, id, data, success, error, async);
  4018. };
  4019. }
  4020. };
  4021. var getArrayJSONData = function(jData, p, _form){
  4022. return new MWF.xScript.JSONData(jData, function(data, key, _self){
  4023. var p = {"getKey": function(){return key;}, "getParent": function(){return _self;}};
  4024. while (p && !_form.forms[p.getKey()]) p = p.getParent();
  4025. //if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
  4026. var k = (p) ? p.getKey() : "";
  4027. if (k) if(_form.forms[k]) if(_form.forms[k].resetData) _form.forms[k].resetData();
  4028. //if(p) if(p.getKey()) if(_forms[p.getKey()]) if(_forms[p.getKey()].render) _forms[p.getKey()].render();
  4029. }, "", p, _form);
  4030. };
  4031. if ( !MWF.xScript.JSONData )MWF.xScript.JSONData = function(data, callback, key, parent, _form){
  4032. var getter = function(data, callback, k, _self){
  4033. return function(){
  4034. var t = typeOf(data[k]);
  4035. if (["array","object"].indexOf(t)===-1){
  4036. return data[k]
  4037. }else{
  4038. if (t==="array"){
  4039. //if (!MWF.xScript.ArrayData){
  4040. // var ArrayData = function(data, callback, key, parent, _form){
  4041. // MWF.xScript.JSONData.call(this, data, callback, key, parent, _form);
  4042. // Array.call(this, data);
  4043. // };
  4044. // Object.assign(ArrayData.prototype, MWF.xScript.JSONData.prototype);
  4045. // Object.assign(ArrayData.prototype, Array.prototype);
  4046. //}
  4047. //return new MWF.xScript.ArrayData(data[k], callback, k, _self, _form);
  4048. //return new ArrayData(data[k], callback, k, _self, _form)
  4049. // var arr = Array.clone(data[k]);
  4050. // for (x in arr){
  4051. // if (typeof x === 'number' && !isNaN(x)){
  4052. // arr
  4053. // }
  4054. // }
  4055. //return data[k];
  4056. if (window.Proxy){
  4057. var arr = new Proxy(data[k], {
  4058. get: function(o, k){
  4059. return (o2.typeOf(o[k])==="object") ? getArrayJSONData(o[k], _self, _form) : o[k];
  4060. },
  4061. set: function(o, k, v){
  4062. o[k] = v;
  4063. if (callback) callback(o, k, _self);
  4064. return true;
  4065. }
  4066. });
  4067. return arr;
  4068. }else{
  4069. var arr =[];
  4070. data[k].forEach(function(d, i){
  4071. arr.push((o2.typeOf(d)==="object") ? getArrayJSONData(d, _self, _form) : d);
  4072. });
  4073. return arr;
  4074. }
  4075. // var arr =[];
  4076. // data[k].forEach(function(d, i){
  4077. // arr.push((o2.typeOf(d)==="object") ? getArrayJSONData(d, _self, _form) : d);
  4078. // });
  4079. // return arr;
  4080. //return getArrayJSONData(data[k], _self, _form);
  4081. }else{
  4082. return new MWF.xScript.JSONData(data[k], callback, k, _self, _form);
  4083. }
  4084. // var obj =
  4085. // if (t==="array") obj.constructor = Array;
  4086. // return obj;
  4087. }
  4088. //return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self, _form);
  4089. };
  4090. };
  4091. var setter = function(data, callback, k, _self){
  4092. return function(v){
  4093. data[k] = v;
  4094. //debugger;
  4095. //this.add(k, v, true);
  4096. if (callback) callback(data, k, _self);
  4097. }
  4098. };
  4099. var define = function(){
  4100. var o = {};
  4101. 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])};
  4102. o["length"] = {"get": function(){return Object.keys(data).length;}};
  4103. o["some"] = {"get": function(){return data.some;}};
  4104. MWF.defineProperties(this, o);
  4105. var methods = {
  4106. "getKey": {"value": function(){ return key; }},
  4107. "getParent": {"value": function(){ return parent; }},
  4108. "toString": {"value": function() { return data.toString();}},
  4109. "setSection": {"value": function(newKey, newValue){
  4110. this.add(newKey, newValue, true);
  4111. try {
  4112. var path = [this.getKey()];
  4113. p = this.getParent();
  4114. while (p && p.getKey()){
  4115. path.unshift(p.getKey());
  4116. p = p.getParent();
  4117. }
  4118. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  4119. }catch(e){
  4120. }
  4121. }},
  4122. "add": {"value": function(newKey, newValue, overwrite, noreset){
  4123. if( newKey.test(/^\d+$/) ){
  4124. throw new Error("Field name '"+newKey+"' cannot contain only numbers" );
  4125. }
  4126. if (arguments.length<2 || newKey.indexOf("..")===-1){
  4127. var flag = true;
  4128. var type = typeOf(data);
  4129. if (type==="array"){
  4130. if (arguments.length<2){
  4131. data.push(newKey);
  4132. newValue = newKey;
  4133. newKey = data.length-1;
  4134. }else{
  4135. if (!newKey && newKey!==0){
  4136. data.push(newValue);
  4137. newKey = data.length-1;
  4138. }else{
  4139. if (newKey>=data.length){
  4140. data.push(newValue);
  4141. newKey = data.length-1;
  4142. }else{
  4143. if (overwrite) data[newKey] = newValue;
  4144. newValue = data[newKey];
  4145. flag = false;
  4146. }
  4147. }
  4148. }
  4149. if (flag){
  4150. var o = {};
  4151. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  4152. MWF.defineProperties(this, o);
  4153. }
  4154. if (!noreset) this[newKey] = newValue;
  4155. }else if (type==="object"){
  4156. if (!this.hasOwnProperty(newKey)){
  4157. if (!data[newKey] || overwrite){
  4158. data[newKey] = newValue;
  4159. }
  4160. newValue = data[newKey];
  4161. if (flag){
  4162. var o = {};
  4163. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  4164. MWF.defineProperties(this, o);
  4165. }
  4166. if (!noreset) this[newKey] = newValue;
  4167. }else{
  4168. if (!Object.getOwnPropertyDescriptor(this, newKey).get){
  4169. var o = {};
  4170. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  4171. MWF.defineProperties(this, o);
  4172. }
  4173. if (overwrite){
  4174. data[newKey] = newValue;
  4175. if (!noreset) this[newKey] = newValue;
  4176. }
  4177. }
  4178. }
  4179. return this[newKey];
  4180. }else{
  4181. var keys = newKey.split("..");
  4182. var kk = keys.shift();
  4183. var d = this.add(kk, {}, false, true);
  4184. if (keys.length) return d.add(keys.join(".."), newValue, overwrite, noreset);
  4185. return d;
  4186. }
  4187. }},
  4188. "check": {
  4189. "value": function(kk, v){
  4190. var value = typeOf( v ) === "null" ? "" : v;
  4191. this.add(kk, value, false, true);
  4192. }
  4193. },
  4194. "del": {"value": function(delKey){
  4195. if (!this.hasOwnProperty(delKey)) return null;
  4196. // delete data[delKey];
  4197. // delete this[delKey];
  4198. data[delKey] = "";
  4199. this[delKey] = "";
  4200. return this;
  4201. }}
  4202. };
  4203. MWF.defineProperties(this, methods);
  4204. //this.getKey = function(){ return key; };
  4205. //this.getParent = function(){ return parent; };
  4206. //this.toString = function() { return data.toString();};
  4207. //this.add = function(newKey, newValue, overwrite){
  4208. // var flag = true;
  4209. // var type = typeOf(data);
  4210. // if (!this.hasOwnProperty(newKey)){
  4211. // if (type=="array"){
  4212. // if (arguments.length<2){
  4213. // data.push(newKey);
  4214. // newValue = newKey;
  4215. // newKey = data.length-1;
  4216. // }else{
  4217. // debugger;
  4218. // if (!newKey && newKey!=0){
  4219. // data.push(newValue);
  4220. // newKey = data.length-1;
  4221. // }else{
  4222. // flag == false;
  4223. // }
  4224. // }
  4225. // }else{
  4226. // data[newKey] = newValue;
  4227. // }
  4228. // //var valueType = typeOf(newValue);
  4229. // //var newValueData = newValue;
  4230. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  4231. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  4232. // if (flag){
  4233. // var o = {};
  4234. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  4235. // MWF.defineProperties(this, o);
  4236. // }
  4237. // this[newKey] = newValue;
  4238. // }else{
  4239. // if (overwrite) this[newKey] = newValue;
  4240. // }
  4241. //
  4242. // //var valueType = typeOf(newValue);
  4243. // //var newValueData = newValue;
  4244. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  4245. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  4246. // //
  4247. // //this[newKey] = newValueData;
  4248. //
  4249. // return this[newKey];
  4250. //};
  4251. //this.del = function(delKey){
  4252. // if (!this.hasOwnProperty(delKey)) return null;
  4253. // delete data[newKey];
  4254. // delete this[newKey];
  4255. // return this;
  4256. //};
  4257. };
  4258. var type = typeOf(data);
  4259. if (type==="object" || type==="array") define.apply(this);
  4260. };
  4261. //MWF.xScript.createDict = function(application){
  4262. // return function(name){
  4263. // var applicationId = application;
  4264. // this.name = name;
  4265. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  4266. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  4267. //
  4268. // this.get = function(path, success, failure){
  4269. // debugger;
  4270. // var value = null;
  4271. // if (path){
  4272. // var arr = path.split(/\./g);
  4273. // var ar = arr.map(function(v){
  4274. // return encodeURIComponent(v);
  4275. // });
  4276. // //var p = path.replace(/\./g, "/");
  4277. // var p = ar.join("/");
  4278. // action.getDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  4279. // value = json.data;
  4280. // if (success) success(json.data);
  4281. // }, function(xhr, text, error){
  4282. // if (failure) failure(xhr, text, error);
  4283. // }, false);
  4284. // }else{
  4285. // action.getDictRoot(encodeURIComponent(this.name), applicationId, function(json){
  4286. // value = json.data;
  4287. // if (success) success(json.data);
  4288. // }, function(xhr, text, error){
  4289. // if (failure) failure(xhr, text, error);
  4290. // }, false);
  4291. // }
  4292. //
  4293. // return value;
  4294. // };
  4295. //
  4296. // this.set = function(path, value, success, failure){
  4297. // var p = path.replace(/\./g, "/");
  4298. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  4299. // if (success) success(json.data);
  4300. // }, function(xhr, text, error){
  4301. // if (failure) failure(xhr, text, error);
  4302. // });
  4303. // };
  4304. // this.add = function(path, value, success, failure){
  4305. // var p = path.replace(/\./g, "/");
  4306. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  4307. // if (success) success(json.data);
  4308. // }, function(xhr, text, error){
  4309. // if (failure) failure(xhr, text, error);
  4310. // });
  4311. // };
  4312. // this["delete"] = function(path, success, failure){
  4313. // var p = path.replace(/\./g, "/");
  4314. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  4315. // if (success) success(json.data);
  4316. // }, function(xhr, text, error){
  4317. // if (failure) failure(xhr, text, error);
  4318. // });
  4319. // };
  4320. // this.destory = this["delete"];
  4321. // }
  4322. //};
  4323. // var dictLoaded = {};
  4324. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  4325. if( !MWF.xScript.createDict ){
  4326. MWF.xScript.addDictToCache = function ( options, path, json ) {
  4327. if( !path )path = "root";
  4328. if( path.indexOf("root") !== 0 )path = "root." + path ;
  4329. var type = options.appType || "process";
  4330. var enableAnonymous = ( options.enableAnonymous || options.anonymous ) || false;
  4331. var appFlagList = [];
  4332. if( options.application )appFlagList.push( options.application );
  4333. if( options.appId )appFlagList.push( options.appId );
  4334. if( options.appName )appFlagList.push( options.appName );
  4335. if( options.appAlias )appFlagList.push( options.appAlias );
  4336. var dictFlagList = [];
  4337. if( options.id )dictFlagList.push( options.id );
  4338. if( options.name )dictFlagList.push( options.name );
  4339. if( options.alias )dictFlagList.push( options.alias );
  4340. var cache = {};
  4341. cache[path] = json;
  4342. for( var i=0; i<appFlagList.length; i++ ){
  4343. for( var j=0; j<dictFlagList.length; j++ ){
  4344. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  4345. if( !MWF.xScript.dictLoaded[k] ){
  4346. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  4347. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  4348. }else if( i===0 && j===0 ){
  4349. MWF.xScript.setDictToCache( k, path ,json );
  4350. var arr = path.split(/\./g);
  4351. var p;
  4352. var cache = MWF.xScript.dictLoaded[k];
  4353. for( var l=0 ; l<arr.length; l++ ){
  4354. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  4355. if( cache[ p ] )break;
  4356. }
  4357. if( p ){
  4358. var mathP = p+".";
  4359. Object.keys( cache ).each( function( path, idx){
  4360. if( path.indexOf( mathP ) === 0 )delete cache[path];
  4361. })
  4362. }
  4363. }
  4364. }
  4365. }
  4366. };
  4367. MWF.xScript.getMatchedDict = function(key, path){
  4368. if( !path )path = "root";
  4369. if( path.indexOf("root") !== 0 )path = "root." + path ;
  4370. var arr = path.split(/\./g);
  4371. if( MWF.xScript.dictLoaded[key] ){
  4372. var dicts = MWF.xScript.dictLoaded[key];
  4373. var list = Array.clone(arr);
  4374. var p;
  4375. var dict;
  4376. for( var i=0 ; i<arr.length; i++ ){
  4377. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  4378. list.shift();
  4379. if( dicts[ p ] ){
  4380. dict = dicts[ p ];
  4381. break;
  4382. }
  4383. }
  4384. return {
  4385. dict : dict,
  4386. unmatchedPathList : list
  4387. }
  4388. }
  4389. return {
  4390. dict : null,
  4391. unmatchedPathList : list
  4392. }
  4393. };
  4394. MWF.xScript.insertDictToCache = function(key, path, json){
  4395. var p = path;
  4396. if( !p )p = "root";
  4397. if( p.indexOf("root") !== 0 )p = "root." + p ;
  4398. if( MWF.xScript.dictLoaded[key] ){
  4399. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  4400. var dict = matchedDict.dict;
  4401. var list = matchedDict.unmatchedPathList;
  4402. if( !dict ) {
  4403. MWF.xScript.dictLoaded[key][p] = json;
  4404. }else if( !list || list.length === 0 ){
  4405. MWF.xScript.dictLoaded[key][p] = json;
  4406. }else{
  4407. for( var j=0; j<list.length-1; j++ ){
  4408. if( !dict[ list[j] ] ){
  4409. dict[ list[j] ] = {};
  4410. }
  4411. dict = dict[ list[j] ];
  4412. }
  4413. var lastPath = list[list.length-1];
  4414. if( !dict[lastPath] ){
  4415. dict[lastPath] = json;
  4416. }else if( typeOf( dict[lastPath] ) === "array" ){
  4417. dict[lastPath].push( json );
  4418. }
  4419. }
  4420. }else{
  4421. MWF.xScript.dictLoaded[key] = {};
  4422. MWF.xScript.dictLoaded[key][p] = json;
  4423. }
  4424. };
  4425. MWF.xScript.setDictToCache = function(key, path, json){
  4426. var p = path;
  4427. if( !p )p = "root";
  4428. if( p.indexOf("root") !== 0 )p = "root." + p ;
  4429. if( MWF.xScript.dictLoaded[key] ){
  4430. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  4431. var dict = matchedDict.dict;
  4432. var list = matchedDict.unmatchedPathList;
  4433. if( !dict ){
  4434. MWF.xScript.dictLoaded[key][p] = json;
  4435. }else if( !list || list.length === 0 ){
  4436. MWF.xScript.dictLoaded[key][p] = json;
  4437. }else{
  4438. for( var j=0; j<list.length-1; j++ ){
  4439. if( !dict[ list[j] ] ){
  4440. dict[ list[j] ] = {};
  4441. }
  4442. dict = dict[ list[j] ];
  4443. }
  4444. dict[list[list.length-1]] = json;
  4445. }
  4446. }else{
  4447. MWF.xScript.dictLoaded[key] = {};
  4448. MWF.xScript.dictLoaded[key][p] = json;
  4449. }
  4450. };
  4451. MWF.xScript.getDictFromCache = function( key, path ){
  4452. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  4453. var dict = matchedDict.dict;
  4454. var list = matchedDict.unmatchedPathList;
  4455. if( dict ){
  4456. for( var j=0; j<list.length; j++ ){
  4457. dict = dict[ list[j] ];
  4458. if( !dict )return null;
  4459. }
  4460. return dict;
  4461. }
  4462. return null;
  4463. };
  4464. MWF.xScript.deleteDictToCache = function(key, path){
  4465. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  4466. var dict = matchedDict.dict;
  4467. var list = matchedDict.unmatchedPathList;
  4468. if( dict){
  4469. for( var j=0; j<list.length-1; j++ ){
  4470. dict = dict[ list[j] ];
  4471. if( !dict )return;
  4472. }
  4473. if( list.length ){
  4474. delete dict[list[list.length-1]];
  4475. }
  4476. }
  4477. };
  4478. MWF.xScript.createDict = function(application, appType){
  4479. //optionsOrName : {
  4480. // type : "", //默认为process, 可以为 process cms portal
  4481. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  4482. // name : "", // 数据字典名称/别名/id
  4483. // anonymous : false //允许在未登录的情况下读取CMS的数据字典, 该参数名也可以是 enableAnonymous
  4484. //}
  4485. //或者name: "" // 数据字典名称/别名/id
  4486. return function(optionsOrName){
  4487. var options = optionsOrName;
  4488. if( typeOf( options ) == "string" ){
  4489. options = {
  4490. name : options,
  4491. type: appType,
  4492. application: application
  4493. };
  4494. }
  4495. var name = this.name = options.name;
  4496. var type;
  4497. if( options.type === "service"){
  4498. type = options.type;
  4499. }else{
  4500. type = ( options.type && options.application ) ? options.type : "process";
  4501. }
  4502. var applicationId = options.application || application;
  4503. var enableAnonymous = ( options.enableAnonymous || options.anonymous ) || false;
  4504. var opt = {
  4505. "appType" : type,
  4506. "name" : name,
  4507. "appId" : applicationId,
  4508. "enableAnonymous" : enableAnonymous
  4509. };
  4510. var key = name+type+applicationId+enableAnonymous;
  4511. // if (!dictLoaded[key]) dictLoaded[key] = {};
  4512. // this.dictData = dictLoaded[key];
  4513. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  4514. var action;
  4515. if( type === "cms" ) {
  4516. action = MWF.Actions.get("x_cms_assemble_control");
  4517. }else if( type === "portal" ){
  4518. action = MWF.Actions.get("x_portal_assemble_surface");
  4519. }else if( type === "service" ){
  4520. key = name+type+enableAnonymous;
  4521. action = MWF.Actions.get("x_program_center");
  4522. }else{
  4523. action = MWF.Actions.get("x_processplatform_assemble_surface");
  4524. }
  4525. var encodePath = function( path ){
  4526. var arr = path.split(/\./g);
  4527. var ar = arr.map(function(v){
  4528. return encodeURIComponent(v);
  4529. });
  4530. return ( type === "portal" || type === "service" ) ? ar.join(".") : ar.join("/");
  4531. };
  4532. this.get = function(path, success, failure, async, refresh){
  4533. var value = null;
  4534. if (success===true) async=true;
  4535. if (failure===true) async=true;
  4536. if (!refresh ){
  4537. var data = MWF.xScript.getDictFromCache( key, path );
  4538. if( data ){
  4539. if (success && o2.typeOf(success)=="function") success( data );
  4540. if( !!async ){
  4541. return Promise.resolve( data );
  4542. }else{
  4543. return data;
  4544. }
  4545. }
  4546. }
  4547. // var cb = function(json){
  4548. // value = json.data;
  4549. // MWF.xScript.addDictToCache(opt, path, value);
  4550. // if (success && o2.typeOf(success)=="function") value = success(json.data);
  4551. // return value;
  4552. // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
  4553. var cb = function(json){
  4554. value = json.data;
  4555. MWF.xScript.addDictToCache(opt, path, value);
  4556. if (success && o2.typeOf(success)=="function") value = success(json.data);
  4557. return value;
  4558. };
  4559. var promise;
  4560. if( type === "service" ){
  4561. if (path){
  4562. var p = encodePath( path );
  4563. promise = action.getDictData(encodeURIComponent(this.name), p, cb, null, !!async, false);
  4564. }else{
  4565. promise = action.getDictRoot(this.name, cb, null, !!async, false);
  4566. }
  4567. }else{
  4568. if (path){
  4569. var p = encodePath( path );
  4570. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async, false);
  4571. }else{
  4572. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async, false);
  4573. }
  4574. }
  4575. return (!!async) ? promise : value;
  4576. // if (path){
  4577. // var p = encodePath( path );
  4578. // //var p = path.replace(/\./g, "/");
  4579. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  4580. // value = json.data;
  4581. // // this.dictData[path] = value;
  4582. // MWF.xScript.addDictToCache(opt, path, value);
  4583. // if (success) success(json.data);
  4584. // }.bind(this), function(xhr, text, error){
  4585. // if (failure) failure(xhr, text, error);
  4586. // }, !!async);
  4587. // }else{
  4588. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  4589. // value = json.data;
  4590. // // this.dictData["root"] = value;
  4591. // MWF.xScript.addDictToCache(opt, path, value);
  4592. // if (success) success(json.data);
  4593. // }.bind(this), function(xhr, text, error){
  4594. // if (failure) failure(xhr, text, error);
  4595. // }, !!async);
  4596. // }
  4597. //return value;
  4598. };
  4599. this.set = function(path, value, success, failure){
  4600. var p = encodePath( path );
  4601. //var p = path.replace(/\./g, "/");
  4602. var successCallback = function(json){
  4603. MWF.xScript.setDictToCache(key, path, value);
  4604. if (success) return success(json.data);
  4605. };
  4606. var failureCallback = function(xhr, text, error){
  4607. if (failure) return failure(xhr, text, error);
  4608. };
  4609. if( type === "service" ){
  4610. return action.setDictData(encodeURIComponent(this.name), p, value, successCallback, failureCallback, false, false);
  4611. }else{
  4612. return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, successCallback, failureCallback, false, false);
  4613. }
  4614. };
  4615. this.add = function(path, value, success, failure){
  4616. var p = encodePath( path );
  4617. //var p = path.replace(/\./g, "/");
  4618. var successCallback = function(json){
  4619. MWF.xScript.insertDictToCache(key, path, value);
  4620. if (success) return success(json.data);
  4621. };
  4622. var failureCallback = function(xhr, text, error){
  4623. if (failure) return failure(xhr, text, error);
  4624. };
  4625. if( type === "service" ) {
  4626. return action.addDictData(encodeURIComponent(this.name), p, value, successCallback, failureCallback, false, false);
  4627. }else{
  4628. return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, successCallback, failureCallback, false, false);
  4629. }
  4630. };
  4631. this["delete"] = function(path, success, failure){
  4632. var p = encodePath( path );
  4633. //var p = path.replace(/\./g, "/");
  4634. var successCallback = function(json){
  4635. MWF.xScript.deleteDictToCache(key, path);
  4636. if (success) return success(json.data);
  4637. };
  4638. var failureCallback = function(xhr, text, error){
  4639. if (failure) return failure(xhr, text, error);
  4640. };
  4641. if( type === "service" ) {
  4642. return action.deleteDictData(encodeURIComponent(this.name), p, successCallback, failureCallback, false, false);
  4643. }else{
  4644. return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, successCallback, failureCallback, false, false);
  4645. }
  4646. };
  4647. this.destory = this["delete"];
  4648. }
  4649. };
  4650. }