Environment.js 162 KB

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