Environment.js 158 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595
  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|true|Work对象:
  187. * @o2ActionOut x_processplatform_assemble_surface.WorkCompletedAction.get|[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
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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. this.wait = function(){
  1885. var _self = this;
  1886. resolve = {"cb": _self.goon.bind(_self)};
  1887. var setResolve = function(callback){
  1888. resolve.cb = callback;
  1889. }.bind(this);
  1890. this.target.event_resolve = setResolve;
  1891. return resolve;
  1892. }
  1893. //和this.wait配合使用,
  1894. //如果没有异步,则resolve.cb方法不存在,
  1895. //所以在回调中中使用this.goon();使表单继续加载
  1896. this.goon = function(){
  1897. this.target.event_resolve = null;
  1898. }
  1899. //仅前台对象-----------------------------------------
  1900. //form
  1901. /**
  1902. * form对象可在流程表单或内容管理表单中可用。(仅前端脚本可用)。
  1903. * @module form
  1904. * @o2range {Process|CMS}
  1905. * @o2ordernumber 40
  1906. * @o2syntax
  1907. * //您可以在流程表单和内容管理的前端脚本中,通过this来获取form对象,如下:
  1908. * var form = this.form;
  1909. */
  1910. this.page = this.form = {
  1911. /**
  1912. * 获取当前表单的基本信息。
  1913. * @method getInfor
  1914. * @static
  1915. * @return {Object} 表单的基本信息.
  1916. * <pre><code class='language-js'>{
  1917. * "id": "db3b2766-93a1-4058-b522-0edb922bd84f", //表单ID
  1918. * "name": "报销申请表单", //表单名称
  1919. * "alias": "报销申请表单", //表单别名
  1920. * "description": "", //表单描述
  1921. * "application": "1dc23336-6be6-402b-bed6-36e707a1dd17", //应用ID
  1922. * "lastUpdatePerson": "XX@huqi@P", //最后修改人
  1923. * "lastUpdateTime": "2018-09-30 22:46:30", //最后修改时间
  1924. * "icon": "...", //表单图标
  1925. * }</code></pre>
  1926. * @o2syntax
  1927. * var form = this.form.getInfor();
  1928. */
  1929. "getInfor": function(){return ev.formInfor;},
  1930. "infor": ev.formInfor,
  1931. /**
  1932. * 获取打开当前文档的component对象。平台中每一个窗口应用,就是一个component对象。此处获取到的对象为x_component_process_Work。
  1933. * @method getApp
  1934. * @static
  1935. * @return {x_component_process_Work}打开当前文档的component对象.
  1936. * @o2syntax
  1937. * var app = this.form.getApp();
  1938. * @example
  1939. * var app = this.form.getApp();
  1940. //所有component对象都有以下方法。
  1941. app.openInNewWindow(); //在新窗口中打开当前应用
  1942. app.setCurrent(); //将当前应用设置为激活状态
  1943. app.minSize(); //应用窗口最小化
  1944. app.maxSize(); //应用窗口最大化
  1945. app.restoreSize(); //应用窗口还原
  1946. app.refresh(); //刷新应用
  1947. app.close(); //关闭应用
  1948. app.setTitle(str); //设置应用标题
  1949. app.dialog(option); //弹出一个对话框(详见MWF.widget.Dialog)
  1950. //显示一个通知消息
  1951. app.notice(content, type, target, where, offset);
  1952. //显示一个确认框
  1953. app.confirm(type, e, title, text, width, height, ok, cancel);
  1954. //弹出一个信息框
  1955. app.alert(type, e, title, text, width, height);
  1956. //为应用绑定一个事件
  1957. app.addEvent(type, fun);
  1958. */
  1959. "getApp": function(){return _form.app;},
  1960. "app": _form.app,
  1961. /**
  1962. * 获取Form对应的DOM对象。
  1963. * @method node
  1964. * @static
  1965. * @return {HTMLDivElement} 当前form对应的div对象.
  1966. * @o2syntax
  1967. * var node = this.form.node();
  1968. */
  1969. "node": function(){return _form.node;},
  1970. /**
  1971. * 获取表单是否可编辑。只读。
  1972. * @member readonly
  1973. * @static
  1974. * @return {Boolean} 是否只读.
  1975. * @o2syntax
  1976. * var readonly = this.form.readonly;
  1977. */
  1978. "readonly": _form.options.readonly,
  1979. /**
  1980. * 获取表单元素对象。<br/>
  1981. * <table>
  1982. * <tr><td>Actionbar(操作条)</td><td>Address(地址输入框)</td><td>Attachment(附件框)</td><td>Button(按钮)</td></tr>
  1983. * <tr><td>Calendar(日期输入框)</td><td>Checkbox(多选按钮)</td><td>Combox(组合框)</td><td>Datagrid(数据网格)</td></tr>
  1984. * <tr><td>Div(容器)</td><td>Htmleditor(富文本编辑框)</td><td>Html(内置html)</td><td>Iframe(嵌入Iframe)</td></tr>
  1985. * <tr><td>Image(图片)</td><td>Label(文本)</td><td>Log(流程意见)</td><td>Monitor(流程监控)</td></tr>
  1986. * <tr><td>Number(数字输入框)</td><td>Office(office控件)</td><td>Opinion(意见框)</td><td>Org(人员组织选择)</td></tr>
  1987. * <tr><td>Radio(单选按钮)</td><td>Select(选择框)</td><td>Sidebar(侧边操作条)</td><td>Stat(统计组件)</td></tr>
  1988. * <tr><td>Subform(子表单)</td><td>Tab(分页)</td><td>Table(表格)</td><td>Textarea(多行输入)</td></tr>
  1989. * <tr><td>Textfield(文本输入框)</td><td>Tree(树状控件)</td><td>View(视图组件)</td><td>ViewSelector(视图选择组件)</td></tr>
  1990. * <tr><td>Documenteditor(公文编辑器)</td><td>ImageClipper(图片编辑器)</td><td></td><td></td></tr>
  1991. * </table>
  1992. * @method get
  1993. * @static
  1994. * @return {FormComponent} 请查看本文档的Classes导航下的FormComponents。
  1995. * @param {String} name 字段标识
  1996. * @o2syntax
  1997. * var field = this.form.get(name);
  1998. * @example
  1999. * var field = this.form.get("subject");
  2000. */
  2001. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  2002. /**
  2003. * 获取表单中可输入的字段元素对象。<br/>
  2004. * <table>
  2005. * <tr><td>Address(地址输入框)</td><td>Attachment(附件框)</td><td>Calendar(日期输入框)</td><td>Checkbox(多选按钮)</td></tr>
  2006. * <tr><td>Combox(组合框)</td><td>Datagrid(数据网格)</td><td>Htmleditor(富文本编辑框)</td><td>Number(数字输入框)</td></tr>
  2007. * <tr><td>Org(人员组织选择)</td><td>Radio(单选按钮)</td><td>Select(选择框)</td><td>Textarea(多行输入)</td></tr>
  2008. * <tr><td>Textfield(文本输入框)</td><td></td><td></td><td></td></tr>
  2009. * </table>
  2010. * @method getField
  2011. * @static
  2012. * @return {FormComponent} 请查看本文档的Classes导航下的FormComponents。
  2013. * @param {String} name 字段标识
  2014. * @o2syntax
  2015. * var field = this.form.getField(name);
  2016. * @example
  2017. * var field = this.form.getField("subject");
  2018. */
  2019. "getField": function(name){return _forms[name];},
  2020. "getAction": function(){return _form.workAction},
  2021. "getDesktop": function(){return _form.app.desktop},
  2022. /**获取业务数据
  2023. * @method getData
  2024. * @static
  2025. * @see module:data
  2026. * @o2syntax
  2027. * var data = this.form.getData();
  2028. * @return {Object} 返回表单绑定的业务数据。
  2029. */
  2030. "getData": function(){return new MWF.xScript.JSONData(_form.getData());},
  2031. /**保存当前表单所绑定的业务数据。<br/>
  2032. * this.form.save()会触发 beforeSave和afterSave事件,因此在beforeSave和afterSave中不允许使用本方法。
  2033. * @method save
  2034. * @static
  2035. * @param {Function} [callback] - 保存后的回调
  2036. * @param {Boolean} [silent] - 是否静默,否提示保存成功,默认为false
  2037. * @o2syntax
  2038. * this.form.save(callback, silent);
  2039. * @example
  2040. * this.form.save(function(){
  2041. * //do someting
  2042. * }, true);
  2043. */
  2044. "save": function(callback, silent){_form.saveWork(callback, silent); },
  2045. /**
  2046. *关闭当前表单
  2047. * @method close
  2048. * @static
  2049. * @example
  2050. * this.form.close();
  2051. */
  2052. "close": function(){_form.closeWork();},
  2053. /**本校验不包括校验意见,校验路由;通常用在弹出提交界面时候的校验
  2054. * @summary 根据表单中所有组件的校验设置和“流转校验”脚本进行校验。
  2055. * @method verify
  2056. * @static
  2057. * @o2syntax
  2058. * this.form.verify()
  2059. * @example
  2060. * if( !this.form.verify() ){
  2061. * return false;
  2062. * }
  2063. * @return {Boolean} 是否通过校验
  2064. */
  2065. "verify": function(){
  2066. return !(!_form.formCustomValidation("", "") || !_form.formValidation("", ""));
  2067. },
  2068. /**对当前表单打开的流程实例进行流转。<b>(仅流程表单中可用)</b><br/>
  2069. * 可以通过this.workContext.getControl().allowProcessing来判断当前用户是否有权限进行流转。<br/>
  2070. * this.form.process()会触发 beforeSave、afterSave、beforeProcess、afterProcess事件,因此在上述事件中不允许使用本方法。
  2071. * @method process
  2072. * @static
  2073. * @param {Object} [option] - 流程的相关数据,如果不带此参数,则弹出路由选择和意见填写框<br/>
  2074. * 格式如下:
  2075. <pre><code class="language-js">
  2076. {
  2077. "routeName": "", //流转到下一步要选择的路由名称
  2078. "opinion": "", //流转意见
  2079. "callback": function(){} //流转完成后的回调方法
  2080. }
  2081. </code></pre>
  2082. * @example
  2083. //不带参数,弹出路由选择和意见填写框
  2084. this.form.process();
  2085. * @example
  2086. //带参数,流转
  2087. this.form.process({
  2088. "routeName": "送审批",
  2089. "opinion": "同意",
  2090. "callback": function(json){
  2091. this.form.notice("process success", "success");
  2092. }.bind(this)
  2093. });
  2094. */
  2095. "process": function(option){
  2096. var op = _form.getOpinion();
  2097. var mds = op.medias;
  2098. if (option){
  2099. _form.submitWork(option.routeName, option.opinion, mds, option.callback,
  2100. option.processor, null, option.appendTaskIdentityList, option.processorOrgList, option.callbackBeforeSave );
  2101. }else{
  2102. _form.processWork();
  2103. }
  2104. },
  2105. /**对当前文档的待办重新设定处理人。<b>(仅流程表单中可用)</b><br/>
  2106. * 可以通过this.workContext.getControl().allowReset来判断当前用户是否有权限重置处理人。<br/>
  2107. * this.form.reset()会触发 beforeReset、afterReset事件,因此在上述事件中不允许使用本方法。
  2108. * @method reset
  2109. * @static
  2110. * @param {Object} [option] - 进行重置处理人的相关参数,如果不带此参数,弹出重置处理人对话框<br/>
  2111. * 格式如下:
  2112. <pre><code class="language-js">
  2113. {
  2114. "names": "", //{Array|String} 要重置给哪些身份
  2115. "opinion": "", //流转意见
  2116. "success ": function(){}, //重置成功后的回调方法
  2117. "failure ": function(){} //重置失败后的回调方法
  2118. }
  2119. </code></pre>
  2120. * @example
  2121. //不带参数,弹出重置处理人对话框
  2122. this.form.reset();
  2123. * @example
  2124. //带参数,直接调用后台服务重置
  2125. this.form.reset({
  2126. "names": ["张三(综合部)"],
  2127. "opinion": "授权处理",
  2128. "success": function(json){
  2129. this.form.notice("reset success", "success");
  2130. }.bind(this),
  2131. "failure": function(xhr, text, error){
  2132. //xhr--HttpRequest请求对象
  2133. //text--HttpResponse内容文本
  2134. //error--错误信息
  2135. this.form.notice("reset failure:"+error, "error");
  2136. }.bind(this)
  2137. });
  2138. */
  2139. "reset": function(option){
  2140. if (!option){
  2141. if (_form.businessData.control["allowReset"]) _form.resetWork();
  2142. }else{
  2143. _form.resetWorkToPeson(option.names, option.opinion, option.keep, option.success, option.failure);
  2144. }
  2145. },
  2146. /**撤回文档操作,上一个处理人收回已经流转下去的文件。<b>(仅流程表单中可用)</b><br/>
  2147. * 这个操作只允许上一个处理人在流转文件之后,下一个处理人未处理的时候执行。<br/>
  2148. * 可以通过this.workContext.getControl().allowRetract来判断当前用户是否有权限撤回。<br/>
  2149. * this.form.retract()会触发 beforeRetract、afterRetract事件,因此在上述事件中不允许使用本方法。
  2150. * @method retract
  2151. * @static
  2152. * @param {Object} [option] - 进行撤回的相关参数,如果不提供option参数,则弹出撤回对话框。<br/>
  2153. * 格式如下:
  2154. <pre><code class="language-js">
  2155. {
  2156. "success ": function(){}, //撤回成功后的回调方法
  2157. "failure ": function(){} //撤回失败后的回调方法
  2158. }
  2159. </code></pre>
  2160. * @example
  2161. //不带参数,则弹出撤回对话框
  2162. this.form.retract();
  2163. * @example
  2164. //带参数,直接调用后台服务撤回
  2165. this.form.retract({
  2166. "success": function(json){
  2167. this.form.notice("retract success", "success");
  2168. }.bind(this),
  2169. "failure": function(xhr, text, error){
  2170. //xhr--HttpRequest请求对象
  2171. //text--HttpResponse内容文本
  2172. //error--错误信息
  2173. this.form.notice("retract failure: "+error, "error");
  2174. }.bind(this)
  2175. });
  2176. */
  2177. "retract": function(option){
  2178. if (!option){
  2179. if (_form.businessData.control["allowRetract"]) _form.retractWork();
  2180. }else{
  2181. _form.doRetractWork(option.success, option.failure);
  2182. }
  2183. },
  2184. /**在已拆分的工作上添加分支。<b>(仅流程表单中可用)</b><br/>
  2185. * 可以通过this.workContext.getControl().allowAddSplit来判断当前用户是否有权限。<br/>
  2186. * @method addSplit
  2187. * @static
  2188. * @param {Object} [option] - 添加分支的相关参数,如果不提供option参数,则弹出添加分支对话框。<br/>
  2189. * 格式如下:
  2190. <pre><code class="language-js">
  2191. {
  2192. "value" : [], //splitValueList 添加的拆分值,拆分值取决于流程拆分节点的设置
  2193. "trimExist" : true, //排除已经存在的拆分值.
  2194. "success ": function(){}, //执行成功后的回调方法
  2195. "failure ": function(){} //执行失败后的回调方法
  2196. }
  2197. </code></pre>
  2198. * @example
  2199. //不带参数,则弹出添加分支对话框
  2200. this.form.addSplit();
  2201. * @example
  2202. //带参数,直接添加分支
  2203. this.form.addSplit({
  2204. "value" : ["开发部@kfb@U"],
  2205. "trimExist" : true,
  2206. "success": function(json){
  2207. this.form.notice("addSplit success", "success");
  2208. }.bind(this),
  2209. "failure": function(xhr, text, error){
  2210. //xhr--HttpRequest请求对象
  2211. //text--HttpResponse内容文本
  2212. //error--错误信息
  2213. this.form.notice("addSplit failure: "+error, "error");
  2214. }.bind(this)
  2215. });
  2216. */
  2217. "addSplit": function(option){
  2218. if (!option){
  2219. if (_form.businessData.control["allowAddSplit"]) _form.addSplit();
  2220. }else{
  2221. _form.addSplitWork(option.value, option.trimExist, option.success, option.failure);
  2222. }
  2223. },
  2224. "rollback": function(option){
  2225. if (!option){
  2226. if (_form.businessData.control["allowRollback"]) _form.rollback();
  2227. }else{
  2228. _form.doRollbackActionInvoke(option.log, option.flow, option.success, option.failure);
  2229. }
  2230. },
  2231. /**删除当前工作文档。<b>(仅流程表单中可用)</b><br/>
  2232. * 可以通过this.workContext.getControl().allowDeleteWork来判断当前用户是否有权限删除文档。<br/>
  2233. * @method deleteWork
  2234. * @static
  2235. * @param {Object} [option] - 删除相关参数,如果不提供option参数,则弹出删除对话框。<br/>
  2236. * 格式如下:
  2237. <pre><code class="language-js">
  2238. {
  2239. "success ": function(){}, //执行成功后的回调方法
  2240. "failure ": function(){} //执行失败后的回调方法
  2241. }
  2242. </code></pre>
  2243. * @example
  2244. //不带参数,则弹出添加分支对话框
  2245. this.form.deleteWork();
  2246. * @example
  2247. //带参数,直接调用服务删除
  2248. this.form.deleteWork({
  2249. "success": function(json){
  2250. this.form.notice("deleteWork success", "success");
  2251. }.bind(this),
  2252. "failure": function(xhr, text, error){
  2253. //xhr--HttpRequest请求对象
  2254. //text--HttpResponse内容文本
  2255. //error--错误信息
  2256. this.form.notice("deleteWork failure: "+error, "error");
  2257. }.bind(this)
  2258. });
  2259. */
  2260. "deleteWork": function(option){
  2261. if (!option){
  2262. if (_form.businessData.control["allowDelete"]) _form.deleteWork();
  2263. }else{
  2264. _form.doDeleteWork(option.success, option.failure);
  2265. }
  2266. },
  2267. /**弹出一个确认框,带确认和关闭按钮
  2268. * @method confirm
  2269. * @static
  2270. * @param {String} type - 要显示的信息类型。可选值:success 成功,info :信息,error :错误, wran : 警告
  2271. * @param {String} title - 确认框标题栏显示文本。
  2272. * @param {String} text - 确认框的内容显示文本。
  2273. * @param {Number} width - 确认框的宽度。
  2274. * @param {String} height - 确认框的高度。
  2275. * @param {Function} ok - 点击“确定”按钮后的回调函数。
  2276. * @param {Function} cancel - 点击“取消”按钮后的回调函数。
  2277. * @example
  2278. this.form.confirm("wran", "删除确认", "您确定要删除吗?", 300, 100,function(){
  2279. //执行删除代码
  2280. this.close();
  2281. }, function(){
  2282. this.close();
  2283. });
  2284. */
  2285. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  2286. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  2287. var p = MWF.getCenter({"x": width, "y": height});
  2288. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  2289. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  2290. }else{
  2291. e = (arguments.length>1) ? arguments[1] : null;
  2292. title = (arguments.length>2) ? arguments[2] : null;
  2293. text = (arguments.length>3) ? arguments[3] : null;
  2294. width = (arguments.length>4) ? arguments[4] : null;
  2295. height = (arguments.length>5) ? arguments[5] : null;
  2296. ok = (arguments.length>6) ? arguments[6] : null;
  2297. cancel = (arguments.length>7) ? arguments[7] : null;
  2298. callback = (arguments.length>8) ? arguments[8] : null;
  2299. mask = (arguments.length>9) ? arguments[9] : null;
  2300. style = (arguments.length>10) ? arguments[10] : null;
  2301. // var p = MWF.getCenter({"x": width, "y": height});
  2302. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  2303. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  2304. }
  2305. },
  2306. /**弹出一个带关闭按钮的信息框
  2307. * @method alert
  2308. * @static
  2309. * @param {String} type - 要显示的信息类型。可选值:success 成功,info :信息,error :错误, wran : 警告
  2310. * @param {String} title - 信息框标题栏显示文本。
  2311. * @param {String} text - 信息框的内容显示文本。
  2312. * @param {Number} width - 信息框宽度。
  2313. * @param {String} height - 信息框的高度。
  2314. * @example
  2315. this.form.alert("wran", "必填提醒", "请填写标题?", 300, 100);
  2316. */
  2317. "alert": function(type, title, text, width, height){
  2318. _form.alert(type, title, text, width, height);
  2319. },
  2320. /**弹出一个提示框
  2321. * @method notice
  2322. * @static
  2323. * @param {String} content - 要显示的信息文本
  2324. * @param {String} [type] - 要显示的信息类型。可选值:success 成功,info :信息,error :错误, wran : 警告
  2325. * @param {Element} [target] - 信息框显示位置的参考DOM对象。
  2326. * @param {Object} [where] - 信息框显示相对于target的x轴和y轴位置。<br/>
  2327. * 如: {"x": "center", "y": "center"}<br/>
  2328. x : <br/>
  2329.  水平位置,可用“left”、“right”和“center”;可以用数组定义外部(outside)位置和内部(inside)位置,如:['right', 'inside']<br/>
  2330. y :<br/>
  2331.  垂直位置,可用“top”、“bottom”和“center”;可以用数组定义外部(outside)位置和内部(inside)位置,如:['top', 'outside']。
  2332. * @param {Object} [offset] - 相对位置的偏移量,允许负值。如:{"x": 10, "y": -10}
  2333. * @param {Object} [option] - 其他选项。如: { delayClose: 5000 } 在5秒后关闭
  2334. * @example
  2335. this.form.notice("this is my information", "info");
  2336. */
  2337. "notice": function(content, type, target, where, offset, option){
  2338. _form.notice(content, type, target, where, offset, option);
  2339. },
  2340. /**给表单添加事件。
  2341. * @method addEvent
  2342. * @static
  2343. * @param {String} type - 事件名称,参考本API Classer->FormComponents->Form的事件
  2344. * @param {Function} event - 事件方法。
  2345. * @example
  2346. this.form.addEvent("load", function(){
  2347. this.form.notice("表单载入完成", "success");
  2348. }.bind(this));
  2349. */
  2350. "addEvent": function(type, event ){_form.addEvent(type, event );},
  2351. /**用一个新的浏览器窗口来打开当前文档,用于打印。<b>(仅流程表单中可用)</b><br/>
  2352. * 如不指定表单,则使用表单设计中指定的打印表单。<br/>
  2353. * @method print
  2354. * @static
  2355. * @param {String} [application] - 指定表单所在的流程应用ID或名称。省略此参数表示当前应用。
  2356. * @param {String} [form] - 指定表单ID或名称。
  2357. * @example
  2358. //在新窗口中使用当前表单中配置的打印表单打开当前文档
  2359. this.form.print();
  2360. * @example
  2361. //在新窗口中使用“订单打印表单”表单打开当前文档
  2362. this.form.print("订单打印表单");
  2363. * @example
  2364. //在新窗口中使用“订单管理”应用中的“订单打印表单”表单打开当前文档
  2365. this.form.print("订单管理", "订单打印表单");
  2366. */
  2367. "print": function(application, form){
  2368. if (arguments.length){
  2369. var app = (arguments.length>1) ? arguments[0] : null;
  2370. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  2371. _form.printWork(app, formName);
  2372. }else{
  2373. _form.printWork();
  2374. }
  2375. },
  2376. /**同print方法。<b>(仅流程表单中可用)</b><br/>
  2377. * @method openWindow
  2378. * @static
  2379. * @see this.form.print()
  2380. * @param {String} [application] - 指定表单所在的流程应用ID或名称。省略此参数表示当前应用。
  2381. * @param {String} [form] - 指定表单ID或名称。
  2382. * @example
  2383. this.form.openWindow();
  2384. */
  2385. "openWindow": function(application, form){
  2386. if (arguments.length){
  2387. var app = (arguments.length>1) ? arguments[0] : null;
  2388. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  2389. _form.openWindow(formName, app);
  2390. }else{
  2391. _form.openWindow();
  2392. }
  2393. },
  2394. /** 打开一个在流转或已完成的流程实例。<br/>
  2395. * @method openWork
  2396. * @static
  2397. * @param {String} [workId] - 在流转的流程实例ID。workId和workCompletedId两个参数必须提供其中一个
  2398. * @param {String} [workCompletedId] - 已完成的流程实例ID。
  2399. * @param {String} [title] - 手机端打开时的窗口标题。
  2400. * @example
  2401. this.form.openWork(id, "", "work title");
  2402. */
  2403. "openWork": function(workId, workCompletedId, title, options){
  2404. var op = options || {};
  2405. op.workId = workId;
  2406. op.workCompletedId = workCompletedId;
  2407. op.docTitle = title;
  2408. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  2409. return layout.desktop.openApplication(this.event, "process.Work", op);
  2410. },
  2411. /** 使用流程的jobId打开工作。<br/>
  2412. * @method openJob
  2413. * @static
  2414. * @param {String} id - 流程的jobId,如果流程拆分后,有多个流程实例(workId会有多个),但jobId是唯一的。
  2415. * @param {Boolean} [choice] - 如果有多个流程实例,是否弹出界面选择。如果传入false,则直接打开第一个工作。
  2416. * @example
  2417. this.form.openJob(jobId, true);
  2418. */
  2419. "openJob": function(id, choice, options){
  2420. var workData = null;
  2421. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  2422. if (json.data) workData = json.data;
  2423. }.bind(this), null, false);
  2424. if (workData){
  2425. var len = workData.workList.length + workData.workCompletedList.length;
  2426. if (len){
  2427. if (len>1 && choice){
  2428. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  2429. workData.workList.each(function(work){
  2430. var workNode = new Element("div", {
  2431. "styles": {
  2432. "background": "#ffffff",
  2433. "border-radius": "10px",
  2434. "clear": "both",
  2435. "margin-bottom": "10px",
  2436. "height": "40px",
  2437. "padding": "10px 10px"
  2438. }
  2439. }).inject(node);
  2440. 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>" +
  2441. "<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>"+
  2442. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  2443. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  2444. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  2445. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  2446. workNode.set("html", html);
  2447. var action = workNode.getElement(".MWFAction");
  2448. action.store("work", work);
  2449. action.addEvent("click", function(e){
  2450. var work = e.target.retrieve("work");
  2451. if (work) this.openWork(work.id, null, work.title, options);
  2452. dlg.close();
  2453. }.bind(this));
  2454. }.bind(this));
  2455. workData.workCompletedList.each(function(work){
  2456. var workNode = new Element("div", {
  2457. "styles": {
  2458. "background": "#ffffff",
  2459. "border-radius": "10px",
  2460. "clear": "both",
  2461. "margin-bottom": "10px",
  2462. "height": "40px",
  2463. "padding": "10px 10px"
  2464. }
  2465. }).inject(node);
  2466. 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>" +
  2467. "<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>"+
  2468. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  2469. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  2470. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  2471. workNode.set("html", html);
  2472. var action = workNode.getElement(".MWFAction");
  2473. action.store("work", work);
  2474. action.addEvent("click", function(e){
  2475. var work = e.target.retrieve("work");
  2476. if (work) this.openWork(null, work.id, work.title, options);
  2477. dlg.close();
  2478. }.bind(this));
  2479. }.bind(this));
  2480. var height = node.getSize().y+20;
  2481. if (height>600) height = 600;
  2482. var dlg = o2.DL.open({
  2483. "title": o2.LP.widget.choiceWork,
  2484. "style" : "user",
  2485. "isResize": false,
  2486. "content": node,
  2487. "buttonList": [
  2488. {
  2489. "type" : "cancel",
  2490. "text": o2.LP.widget.close,
  2491. "action": function(){dlg.close();}
  2492. }
  2493. ]
  2494. });
  2495. }else{
  2496. if (workData.workList.length){
  2497. var work = workData.workList[0];
  2498. return this.openWork(work.id, null, work.title, options);
  2499. }else{
  2500. var work = workData.workCompletedList[0];
  2501. return this.openWork(null, work.id, work.title, options);
  2502. }
  2503. }
  2504. }
  2505. }
  2506. // var op = options || {};
  2507. // op.workId = id;
  2508. // op.workCompletedId = completedId;
  2509. // op.docTitle = title;
  2510. // op.appId = "process.Work"+(op.workId || op.workCompletedId);
  2511. // layout.desktop.openApplication(this.event, "process.Work", op);
  2512. },
  2513. /** 打开一个内容管理文档。<br/>
  2514. * @method openDocument
  2515. * @static
  2516. * @param {String} id - 内容管理文档实例的ID。
  2517. * @param {Boolean} [title] - 手机APP端打开时的窗口标题。
  2518. * @param {Object} [options] - 其他参数,内容如下<br>
  2519. * <pre><code class="language-js">{
  2520. * "readonly": true, //是否以只读方式打开,默认为true
  2521. * "saveOnClose" : true, //关闭的时候是否自动保存
  2522. * "postPublish" : function( documentData ){ //发布前执行方法,但数据已经准备好
  2523. * //documentData 为文档数据
  2524. * },
  2525. * "afterPublish" : function( form, documentData ){ //发布后执行的方法
  2526. * //form为内容管理Form对象,documentData 为文档数据
  2527. * },
  2528. * "postDelete" : function(){ //删除文档后执行的方法
  2529. * }
  2530. * }</code></pre>
  2531. * @example
  2532. this.form.openDocument(id, "document title");
  2533. */
  2534. "openDocument": function(id, title, options){
  2535. var op = options || {};
  2536. op.documentId = id;
  2537. op.docTitle = title;
  2538. layout.desktop.openApplication(this.event, "cms.Document", op);
  2539. },
  2540. /**打开一个门户页面。<br/>
  2541. * @method openPortal
  2542. * @static
  2543. * @param {String} portal - 要打开的门户应用名称、别名或ID。
  2544. * @param {String} [page] - 要打开的页面名称、别名或ID。如果忽略,则打开门户的默认首页
  2545. * @param {Object} [par] - 打开页面可以传入参数。<br>在被打开的页面中,可以通过脚本this.page.parameters访问到此参数。
  2546. * @example
  2547. this.form.openPortal(id, "", {"type": "my type"});
  2548. */
  2549. "openPortal": function (portal, page, par) {
  2550. var action = MWF.Actions.get("x_portal_assemble_surface");
  2551. action.getApplication(portal, function (json) {
  2552. if (json.data) {
  2553. if (page) {
  2554. action.getPageByName(page, json.data.id, function (pageJson) {
  2555. var pageId = (pageJson.data) ? pageJson.data.id : "";
  2556. layout.desktop.openApplication(null, "portal.Portal", {
  2557. "portalId": json.data.id,
  2558. "pageId": pageId,
  2559. "parameters": par,
  2560. "appId": (par && par.appId) || ("portal.Portal" + json.data.id + pageId)
  2561. })
  2562. });
  2563. } else {
  2564. layout.desktop.openApplication(null, "portal.Portal", {
  2565. "portalId": json.data.id,
  2566. "parameters": par,
  2567. "appId": (par && par.appId) || ("portal.Portal" + json.data.id)
  2568. })
  2569. }
  2570. }
  2571. });
  2572. },
  2573. /**打开一个内容管理栏目(应用)。<br/>
  2574. * @method openCMS
  2575. * @static
  2576. * @param {String} name - 内容管理栏目的名称、别名或ID。
  2577. * @example
  2578. this.form.openCMS("通知公告");
  2579. */
  2580. "openCMS": function(name){
  2581. var action = MWF.Actions.get("x_cms_assemble_control");
  2582. action.getColumn(name, function(json){
  2583. if (json.data){
  2584. layout.desktop.openApplication(null, "cms.Module", {
  2585. "columnId": json.data.id,
  2586. "appId": "cms.Module"+json.data.id
  2587. });
  2588. }
  2589. });
  2590. },
  2591. /**打开一个流程应用。<br/>
  2592. * @method openProcess
  2593. * @static
  2594. * @param {String} name - 流程应用的名称、别名或ID。
  2595. * @example
  2596. this.form.openProcess("财务审批");
  2597. */
  2598. "openProcess": function(name){
  2599. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  2600. action.getApplication(name, function(json){
  2601. if (json.data){
  2602. layout.desktop.openApplication(null, "process.Application", {
  2603. "id": json.data.id,
  2604. "appId": "process.Application"+json.data.id
  2605. });
  2606. }
  2607. });
  2608. },
  2609. /**打开任意一个component应用。<br/>
  2610. * @method openApplication
  2611. * @static
  2612. * @param {String} name - 要打开的component的名称。component对应的名称可以在“控制面板-系统设置-界面设置-模块部署”中找到(即“组件路径”)。
  2613. * @param {Object} options - 打开的component的相关参数
  2614. * @example
  2615. //打开会议管理
  2616. this.form.openApplication("Meeting");
  2617. * @example
  2618. //打开一个流转中的流程实例。与 this.form.openWork(id, "", "work title");效果相同
  2619. this.form.openApplication("process.Work", {
  2620. "workId": id, //流程实例ID
  2621. "width": "1200", //宽度
  2622. "height": "800", //高度
  2623. "docTitle": "work title", //APP端窗口标题
  2624. "appId": "process.Work"+id //给新打开的component实例一个唯一名称
  2625. });
  2626. */
  2627. "openApplication":function(name, options){
  2628. layout.desktop.openApplication(null, name, options);
  2629. },
  2630. /**创建一条内容管理文档。
  2631. * @method createDocument
  2632. * @static
  2633. * @param {(String|Object)} [columnOrOptions]
  2634. * 如果不传参数,则弹出范围为平台所有栏目的选中界面。<br/>
  2635. * 当使用String时为内容管理应用(栏目)的名称、别名或ID。<br/>
  2636. * 当使用Object时,本参数后面的参数省略,传入如下格式的内容:
  2637. * <pre><code class="language-js">{
  2638. * "column" : column, //(string)可选,内容管理应用(栏目)的名称、别名或ID
  2639. * "category" : category, //(string)可选,要创建的文档所属的分类的名称、别名或ID
  2640. * "data" : data, //(json object)可选,创建文档时默认的业务数据
  2641. * "identity" : identity, //(string)可选,创建文档所使用的身份。如果此参数为空,且当前人有多个身份的情况下,会弹出身份选择对话框;否则使用默认身份。
  2642. * "callback" : callback, //(funcation)可选,文档创建后的回调函数。
  2643. * "target" : target, //(boolean)可选,为true时,在当前页面打开创建的文档;否则打开新窗口。默认false。
  2644. * "latest" : latest, //(boolean)可选,为true时,如果当前用户已经创建了此分类的文档,并且没有发布过,直接调用此文档为新文档;否则创建一个新文档。默认true。
  2645. * "selectColumnEnable" : selectColumnEnable, //(boolean)可选,是否可以选择应用和分类进行创建文档。有category参数时为默认false,否则默认为true。
  2646. * "ignoreTitle" : ignoreTitle //(boolean)可选,值为false时,创建的时候需要强制填写标题,默认为false。
  2647. * }</code></pre>
  2648. * @param {String} [category] - 要创建的文档所属的分类的名称、别名或ID
  2649. * @param {Object} [data] - 创建文档时默认的业务数据
  2650. * @param {String} [identity] - 可选,创建文档所使用的身份。如果此参数为空,且当前人有多个身份的情况下,会弹出身份选择对话框;否则使用默认身份。
  2651. * @param {Function} [callback] - 文档创建后的回调函数
  2652. * @param {Boolean} [target] - 为true时,在当前页面打开创建的文档;否则打开新窗口。默认false
  2653. * @param {Boolean} [latest] - 为true时,如果当前用户已经创建了此分类的文档,并且没有发布过,直接调用此文档为新文档;否则创建一个新文档。默认true。
  2654. * @param {Boolean} [selectColumnEnable] - 为true时,如果当前用户已经创建了此分类的文档,并且没有发布过,直接调用此文档为新文档;否则创建一个新文档。默认true。
  2655. * @param {Boolean} [ignoreTitle] - 值为false时,创建的时候需要强制填写标题,默认为false。
  2656. * @example
  2657. //启动一个通知公告
  2658. this.form.createDocument("", "通知公告");
  2659. * @example
  2660. //启动一个通知公告,标题为:关于XX的通知,启动后提示
  2661. this.form.createDocument("", "通知公告", {"subject": "关于XX的通知"}, function(json){
  2662. this.form.notice("创建成功!", "success");
  2663. }.bind(this));
  2664. * @example
  2665. //启动一个通知公告,标题为:关于XX的通知,启动后提示
  2666. this.form.createDocument({
  2667. category : "通知公告",
  2668. data : {"subject": "关于XX的通知"},
  2669. callback : function(json){
  2670. this.form.notice("创建成功!", "success");
  2671. }.bind(this)
  2672. });
  2673. */
  2674. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  2675. var column = columnOrOptions;
  2676. var onAfterPublish, onPostPublish;
  2677. if (typeOf(columnOrOptions) == "object") {
  2678. column = columnOrOptions.column;
  2679. category = columnOrOptions.category;
  2680. data = columnOrOptions.data;
  2681. identity = columnOrOptions.identity;
  2682. callback = columnOrOptions.callback;
  2683. target = columnOrOptions.target;
  2684. latest = columnOrOptions.latest;
  2685. selectColumnEnable = columnOrOptions.selectColumnEnable;
  2686. ignoreTitle = columnOrOptions.ignoreTitle;
  2687. onAfterPublish = columnOrOptions.onAfterPublish;
  2688. onPostPublish = columnOrOptions.onPostPublish;
  2689. }
  2690. if (target) {
  2691. if (layout.app && layout.app.inBrowser) {
  2692. layout.app.content.empty();
  2693. layout.app = null;
  2694. }
  2695. }
  2696. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  2697. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  2698. "documentData": data,
  2699. "identity": identity,
  2700. "ignoreTitle": ignoreTitle === true,
  2701. "ignoreDrafted": latest === false,
  2702. "selectColumnEnable": !category || selectColumnEnable === true,
  2703. "restrictToColumn": !!category && selectColumnEnable !== true,
  2704. "categoryFlag": category, //category id or name
  2705. "columnFlag": column, //column id or name,
  2706. "onStarted": function (documentId, data) {
  2707. if (callback) callback();
  2708. },
  2709. "onPostPublish": function () {
  2710. if(onPostPublish)onPostPublish();
  2711. },
  2712. "onAfterPublish": function () {
  2713. if(onAfterPublish)onAfterPublish();
  2714. }
  2715. });
  2716. starter.load();
  2717. })
  2718. },
  2719. /**启动一个流程实例。<br/>
  2720. * @method startProcess
  2721. * @static
  2722. * @param {String} app - 流程应用的名称、别名或ID。
  2723. * @param {String} process - 要启动的流程的名称、别名或ID。
  2724. * @param {Object} [data] - 流程启动时默认的业务数据。
  2725. * @param {String} [identity] - 流程启动所使用的身份。如果此参数为空,且当前人有多个身份的情况下,会弹出身份选择对话框;否则使用默认身份。。
  2726. * @param {Function} [callback] - 流程启动后的回调函数。
  2727. * @param {Boolean} [target] - 为true时,在当前页面打开启动的流程实例;否则打开新窗口。默认false。
  2728. * @param {Boolean} [latest] - 为true时,如果当前用户已经创建了此流程的实例,并且没有流转过,直接调用此实例为新流程实例;否则创建一个新实例。默认false。
  2729. * @example
  2730. //启动一个发文管理实例
  2731. this.form.startProcess("公文管理", "发文管理");
  2732. * @example
  2733. //启动一个发文管理实例,标题为:my file title,启动后提示
  2734. this.form.startProcess("公文管理", "发文管理", {"title": "my file title"}, function(json){
  2735. this.form.notice("create file success!", "success");
  2736. });
  2737. */
  2738. "startProcess": function(app, process, data, identity, callback, target, latest){
  2739. if (arguments.length>2){
  2740. for (var i=2; i<arguments.length; i++){
  2741. if (typeOf(arguments[i])=="boolean"){
  2742. target = arguments[i];
  2743. break;
  2744. }
  2745. }
  2746. }
  2747. if (target){
  2748. if (layout.app && layout.app.inBrowser){
  2749. //layout.app.content.empty();
  2750. layout.app.$openWithSelf = true;
  2751. }
  2752. }
  2753. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  2754. if (json.data){
  2755. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  2756. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  2757. "workData": data,
  2758. "identity": identity,
  2759. "latest": latest,
  2760. "onStarted": function(data, title, processName){
  2761. if (data.work){
  2762. var work = data.work;
  2763. var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
  2764. layout.desktop.openApplication(null, "process.Work", options);
  2765. }else{
  2766. var currentTask = [];
  2767. data.each(function(work){
  2768. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  2769. }.bind(this));
  2770. if (currentTask.length==1){
  2771. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  2772. layout.desktop.openApplication(null, "process.Work", options);
  2773. }else{}
  2774. }
  2775. if (callback) callback(data);
  2776. }.bind(this)
  2777. });
  2778. starter.load();
  2779. }.bind(this));
  2780. }
  2781. });
  2782. }
  2783. };
  2784. /**
  2785. * 在用户提交的时候,选择的路由。仅在表单的“校验意见”和“校验路由”脚本中可用。只读。<b>(仅流程表单中可用)</b>。
  2786. * @member currentRouteName
  2787. * @memberOf module:form
  2788. * @static
  2789. * @return {String} 用户选择的路由。
  2790. * @o2syntax
  2791. * var currentRouteName = this.form.currentRouteName;
  2792. */
  2793. this.form.currentRouteName = _form.json.currentRouteName;
  2794. /**
  2795. * 在用户提交的时候,输入的意见。仅在表单的“校验意见”和“校验路由”脚本中可用。只读。<b>(仅流程表单中可用)</b>。
  2796. * @member opinion
  2797. * @memberOf module:form
  2798. * @static
  2799. * @return {String} 用户填写的意见.
  2800. * @o2syntax
  2801. * var opinion = this.form.opinion;
  2802. */
  2803. this.form.opinion = _form.json.opinion;
  2804. /**
  2805. * 在提交的时候,用户的手写意见以及录音意见,仅在表单的“校验意见”和“校验路由”脚本中可用。只读。<b>(仅流程表单中可用)</b>。
  2806. * @member medias
  2807. * @memberOf module:form
  2808. * @static
  2809. * @return {Blob[]} 手写意见以及录音意见数组。手写意见和录音意见都是 HTML5的blob类型文件。
  2810. * @o2syntax
  2811. * var medias = this.form.medias;
  2812. */
  2813. this.form.medias = [];
  2814. this.target = ev.target;
  2815. this.event = ev.event;
  2816. this.status = ev.status;
  2817. this.session = layout.desktop.session;
  2818. this.Actions = o2.Actions;
  2819. this.query = function(option){
  2820. // options = {
  2821. // "name": "statementName",
  2822. // "data": "json data",
  2823. // "firstResult": 1,
  2824. // "maxResults": 100,
  2825. // "success": function(){},
  2826. // "error": function(){},
  2827. // "async": true or false, default is true
  2828. // }
  2829. if (option){
  2830. var json = (option.data) || {};
  2831. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  2832. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  2833. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  2834. }
  2835. }
  2836. this.Table = MWF.xScript.createTable();
  2837. };
  2838. MWF.xScript.createTable = function(){
  2839. return function(name){
  2840. this.name = name;
  2841. this.action = o2.Actions.get("x_query_assemble_surface");
  2842. this.listRowNext = function(id, count, success, error, async){
  2843. this.action.listRowNext(this.name, id, count, success, error, async);
  2844. };
  2845. this.listRowPrev = function(id, count, success, error, async){
  2846. this.action.listRowPrev(this.name, id, count, success, error, async);
  2847. };
  2848. this.listRowPrev = function(id, count, success, error, async){
  2849. this.action.listRowPrev(this.name, id, count, success, error, async);
  2850. };
  2851. this.listRowSelectWhere = function(where, success, error, async){
  2852. this.action.listRowSelectWhere(this.name, where, success, error, async);
  2853. };
  2854. this.listRowCountWhere = function(where, success, error, async){
  2855. this.action.listRowCountWhere(this.name, where, success, error, async);
  2856. };
  2857. this.deleteRow = function(id, success, error, async){
  2858. this.action.deleteRow(this.name, id, success, error, async);
  2859. };
  2860. this.deleteAllRow = function(success, error, async){
  2861. this.action.deleteAllRow(this.name, success, error, async);
  2862. };
  2863. this.getRow = function(id, success, error, async){
  2864. this.action.getRow(this.name, id, success, error, async);
  2865. };
  2866. this.insertRow = function(data, success, error, async){
  2867. this.action.insertRow(this.name, data, success, error, async);
  2868. };
  2869. this.updateRow = function(id, data, success, error, async){
  2870. this.action.updateRow(this.name, id, data, success, error, async);
  2871. };
  2872. }
  2873. };
  2874. MWF.xScript.JSONData = function(data, callback, key, parent, _form){
  2875. var getter = function(data, callback, k, _self){
  2876. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self, _form);};
  2877. };
  2878. var setter = function(data, callback, k, _self){
  2879. return function(v){
  2880. data[k] = v;
  2881. //debugger;
  2882. //this.add(k, v, true);
  2883. if (callback) callback(data, k, _self);
  2884. }
  2885. };
  2886. var define = function(){
  2887. var o = {};
  2888. 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])};
  2889. o["length"] = {"get": function(){return Object.keys(data).length;}};
  2890. o["some"] = {"get": function(){return data.some;}};
  2891. MWF.defineProperties(this, o);
  2892. var methods = {
  2893. "getKey": {"value": function(){ return key; }},
  2894. "getParent": {"value": function(){ return parent; }},
  2895. "toString": {"value": function() { return data.toString();}},
  2896. "setSection": {"value": function(newKey, newValue){
  2897. this.add(newKey, newValue, true);
  2898. try {
  2899. var path = [this.getKey()];
  2900. p = this.getParent();
  2901. while (p && p.getKey()){
  2902. path.unshift(p.getKey());
  2903. p = p.getParent();
  2904. }
  2905. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  2906. }catch(e){
  2907. }
  2908. }},
  2909. "add": {"value": function(newKey, newValue, overwrite){
  2910. var flag = true;
  2911. var type = typeOf(data);
  2912. if (type==="array"){
  2913. if (arguments.length<2){
  2914. data.push(newKey);
  2915. newValue = newKey;
  2916. newKey = data.length-1;
  2917. }else{
  2918. if (!newKey && newKey!==0){
  2919. data.push(newValue);
  2920. newKey = data.length-1;
  2921. }else{
  2922. flag = false;
  2923. }
  2924. }
  2925. if (flag){
  2926. var o = {};
  2927. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2928. MWF.defineProperties(this, o);
  2929. }
  2930. this[newKey] = newValue;
  2931. }else if (type==="object"){
  2932. if (!this.hasOwnProperty(newKey)){
  2933. data[newKey] = newValue;
  2934. if (flag){
  2935. var o = {};
  2936. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2937. MWF.defineProperties(this, o);
  2938. }
  2939. this[newKey] = newValue;
  2940. }else{
  2941. if (overwrite) this[newKey] = newValue;
  2942. }
  2943. }
  2944. return this[newKey];
  2945. }},
  2946. "del": {"value": function(delKey){
  2947. if (!this.hasOwnProperty(delKey)) return null;
  2948. // delete data[delKey];
  2949. // delete this[delKey];
  2950. data[delKey] = "";
  2951. this[delKey] = "";
  2952. return this;
  2953. }}
  2954. };
  2955. MWF.defineProperties(this, methods);
  2956. //this.getKey = function(){ return key; };
  2957. //this.getParent = function(){ return parent; };
  2958. //this.toString = function() { return data.toString();};
  2959. //this.add = function(newKey, newValue, overwrite){
  2960. // var flag = true;
  2961. // var type = typeOf(data);
  2962. // if (!this.hasOwnProperty(newKey)){
  2963. // if (type=="array"){
  2964. // if (arguments.length<2){
  2965. // data.push(newKey);
  2966. // newValue = newKey;
  2967. // newKey = data.length-1;
  2968. // }else{
  2969. // debugger;
  2970. // if (!newKey && newKey!=0){
  2971. // data.push(newValue);
  2972. // newKey = data.length-1;
  2973. // }else{
  2974. // flag == false;
  2975. // }
  2976. // }
  2977. // }else{
  2978. // data[newKey] = newValue;
  2979. // }
  2980. // //var valueType = typeOf(newValue);
  2981. // //var newValueData = newValue;
  2982. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  2983. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  2984. // if (flag){
  2985. // var o = {};
  2986. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2987. // MWF.defineProperties(this, o);
  2988. // }
  2989. // this[newKey] = newValue;
  2990. // }else{
  2991. // if (overwrite) this[newKey] = newValue;
  2992. // }
  2993. //
  2994. // //var valueType = typeOf(newValue);
  2995. // //var newValueData = newValue;
  2996. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  2997. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  2998. // //
  2999. // //this[newKey] = newValueData;
  3000. //
  3001. // return this[newKey];
  3002. //};
  3003. //this.del = function(delKey){
  3004. // if (!this.hasOwnProperty(delKey)) return null;
  3005. // delete data[newKey];
  3006. // delete this[newKey];
  3007. // return this;
  3008. //};
  3009. };
  3010. var type = typeOf(data);
  3011. if (type==="object" || type==="array") define.apply(this);
  3012. };
  3013. //MWF.xScript.createDict = function(application){
  3014. // return function(name){
  3015. // var applicationId = application;
  3016. // this.name = name;
  3017. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  3018. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  3019. //
  3020. // this.get = function(path, success, failure){
  3021. // debugger;
  3022. // var value = null;
  3023. // if (path){
  3024. // var arr = path.split(/\./g);
  3025. // var ar = arr.map(function(v){
  3026. // return encodeURIComponent(v);
  3027. // });
  3028. // //var p = path.replace(/\./g, "/");
  3029. // var p = ar.join("/");
  3030. // action.getDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  3031. // value = json.data;
  3032. // if (success) success(json.data);
  3033. // }, function(xhr, text, error){
  3034. // if (failure) failure(xhr, text, error);
  3035. // }, false);
  3036. // }else{
  3037. // action.getDictRoot(encodeURIComponent(this.name), applicationId, function(json){
  3038. // value = json.data;
  3039. // if (success) success(json.data);
  3040. // }, function(xhr, text, error){
  3041. // if (failure) failure(xhr, text, error);
  3042. // }, false);
  3043. // }
  3044. //
  3045. // return value;
  3046. // };
  3047. //
  3048. // this.set = function(path, value, success, failure){
  3049. // var p = path.replace(/\./g, "/");
  3050. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  3051. // if (success) success(json.data);
  3052. // }, function(xhr, text, error){
  3053. // if (failure) failure(xhr, text, error);
  3054. // });
  3055. // };
  3056. // this.add = function(path, value, success, failure){
  3057. // var p = path.replace(/\./g, "/");
  3058. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  3059. // if (success) success(json.data);
  3060. // }, function(xhr, text, error){
  3061. // if (failure) failure(xhr, text, error);
  3062. // });
  3063. // };
  3064. // this["delete"] = function(path, success, failure){
  3065. // var p = path.replace(/\./g, "/");
  3066. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  3067. // if (success) success(json.data);
  3068. // }, function(xhr, text, error){
  3069. // if (failure) failure(xhr, text, error);
  3070. // });
  3071. // };
  3072. // this.destory = this["delete"];
  3073. // }
  3074. //};
  3075. // var dictLoaded = {};
  3076. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  3077. MWF.xScript.addDictToCache = function ( options, path, json ) {
  3078. if( !path )path = "root";
  3079. if( path.indexOf("root") !== 0 )path = "root." + path ;
  3080. var type = options.appType || "process";
  3081. var enableAnonymous = options.enableAnonymous || false;
  3082. var appFlagList = [];
  3083. if( options.application )appFlagList.push( options.application );
  3084. if( options.appId )appFlagList.push( options.appId );
  3085. if( options.appName )appFlagList.push( options.appName );
  3086. if( options.appAlias )appFlagList.push( options.appAlias );
  3087. var dictFlagList = [];
  3088. if( options.id )dictFlagList.push( options.id );
  3089. if( options.name )dictFlagList.push( options.name );
  3090. if( options.alias )dictFlagList.push( options.alias );
  3091. var cache = {};
  3092. cache[path] = json;
  3093. for( var i=0; i<appFlagList.length; i++ ){
  3094. for( var j=0; j<dictFlagList.length; j++ ){
  3095. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  3096. if( !MWF.xScript.dictLoaded[k] ){
  3097. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  3098. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  3099. }else if( i===0 && j===0 ){
  3100. MWF.xScript.setDictToCache( k, path ,json );
  3101. var arr = path.split(/\./g);
  3102. var p;
  3103. var cache = MWF.xScript.dictLoaded[k];
  3104. for( var l=0 ; l<arr.length; l++ ){
  3105. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  3106. if( cache[ p ] )break;
  3107. }
  3108. if( p ){
  3109. var mathP = p+".";
  3110. Object.keys( cache ).each( function( path, idx){
  3111. if( path.indexOf( mathP ) === 0 )delete cache[path];
  3112. })
  3113. }
  3114. }
  3115. }
  3116. }
  3117. };
  3118. MWF.xScript.getMatchedDict = function(key, path){
  3119. if( !path )path = "root";
  3120. if( path.indexOf("root") !== 0 )path = "root." + path ;
  3121. var arr = path.split(/\./g);
  3122. if( MWF.xScript.dictLoaded[key] ){
  3123. var dicts = MWF.xScript.dictLoaded[key];
  3124. var list = Array.clone(arr);
  3125. var p;
  3126. var dict;
  3127. for( var i=0 ; i<arr.length; i++ ){
  3128. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  3129. list.shift();
  3130. if( dicts[ p ] ){
  3131. dict = dicts[ p ];
  3132. break;
  3133. }
  3134. }
  3135. return {
  3136. dict : dict,
  3137. unmatchedPathList : list
  3138. }
  3139. }
  3140. return {
  3141. dict : null,
  3142. unmatchedPathList : list
  3143. }
  3144. };
  3145. MWF.xScript.insertDictToCache = function(key, path, json){
  3146. if( MWF.xScript.dictLoaded[key] ){
  3147. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  3148. var dict = matchedDict.dict;
  3149. var list = matchedDict.unmatchedPathList;
  3150. if( !dict ){
  3151. MWF.xScript.dictLoaded[key][path] = json;
  3152. }else{
  3153. for( var j=0; j<list.length-1; j++ ){
  3154. if( !dict[ list[j] ] ){
  3155. dict[ list[j] ] = {};
  3156. }
  3157. dict = dict[ list[j] ];
  3158. }
  3159. var lastPath = list[list.length-1];
  3160. if( !dict[lastPath] ){
  3161. dict[lastPath] = json;
  3162. }else if( typeOf( dict[lastPath] ) === "array" ){
  3163. dict[lastPath].push( json );
  3164. }
  3165. }
  3166. }else{
  3167. MWF.xScript.dictLoaded[key] = {};
  3168. MWF.xScript.dictLoaded[key][path] = json;
  3169. }
  3170. };
  3171. MWF.xScript.setDictToCache = function(key, path, json){
  3172. if( MWF.xScript.dictLoaded[key] ){
  3173. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  3174. var dict = matchedDict.dict;
  3175. var list = matchedDict.unmatchedPathList;
  3176. if( !dict ){
  3177. MWF.xScript.dictLoaded[key][path] = json;
  3178. }else{
  3179. for( var j=0; j<list.length-1; j++ ){
  3180. if( !dict[ list[j] ] ){
  3181. dict[ list[j] ] = {};
  3182. }
  3183. dict = dict[ list[j] ];
  3184. }
  3185. dict[list[list.length-1]] = json;
  3186. }
  3187. }else{
  3188. MWF.xScript.dictLoaded[key] = {};
  3189. MWF.xScript.dictLoaded[key][path] = json;
  3190. }
  3191. };
  3192. MWF.xScript.getDictFromCache = function( key, path ){
  3193. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  3194. var dict = matchedDict.dict;
  3195. var list = matchedDict.unmatchedPathList;
  3196. if( dict ){
  3197. for( var j=0; j<list.length; j++ ){
  3198. dict = dict[ list[j] ];
  3199. if( !dict )return null;
  3200. }
  3201. return dict;
  3202. }
  3203. return null;
  3204. };
  3205. MWF.xScript.deleteDictToCache = function(key, path){
  3206. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  3207. var dict = matchedDict.dict;
  3208. var list = matchedDict.unmatchedPathList;
  3209. if( dict){
  3210. for( var j=0; j<list.length-1; j++ ){
  3211. dict = dict[ list[j] ];
  3212. if( !dict )return;
  3213. }
  3214. delete dict[list[list.length-1]];
  3215. }
  3216. };
  3217. MWF.xScript.createDict = function(application){
  3218. //optionsOrName : {
  3219. // type : "", //默认为process, 可以为 process cms
  3220. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  3221. // name : "", // 数据字典名称/别名/id
  3222. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  3223. //}
  3224. //或者name: "" // 数据字典名称/别名/id
  3225. return function(optionsOrName){
  3226. var options = optionsOrName;
  3227. if( typeOf( options ) == "string" ){
  3228. options = { name : options };
  3229. }
  3230. var name = this.name = options.name;
  3231. var type = ( options.type && options.application ) ? options.type : "process";
  3232. var applicationId = options.application || application;
  3233. var enableAnonymous = options.enableAnonymous || false;
  3234. var opt = {
  3235. "appType" : type,
  3236. "name" : name,
  3237. "appId" : applicationId,
  3238. "enableAnonymous" : enableAnonymous
  3239. };
  3240. var key = name+type+applicationId+enableAnonymous;
  3241. // if (!dictLoaded[key]) dictLoaded[key] = {};
  3242. // this.dictData = dictLoaded[key];
  3243. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  3244. if( type == "cms" ){
  3245. var action = MWF.Actions.get("x_cms_assemble_control");
  3246. }else{
  3247. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  3248. }
  3249. var encodePath = function( path ){
  3250. var arr = path.split(/\./g);
  3251. var ar = arr.map(function(v){
  3252. return encodeURIComponent(v);
  3253. });
  3254. return ar.join("/");
  3255. };
  3256. this.get = function(path, success, failure, async, refresh){
  3257. var value = null;
  3258. if (success===true) async=true;
  3259. if (failure===true) async=true;
  3260. if (!refresh ){
  3261. var data = MWF.xScript.getDictFromCache( key, path );
  3262. if( data ){
  3263. if (success && o2.typeOf(success)=="function") success( data );
  3264. if( !!async ){
  3265. return Promise.resolve( data );
  3266. }else{
  3267. return data;
  3268. }
  3269. }
  3270. }
  3271. // var cb = function(json){
  3272. // value = json.data;
  3273. // MWF.xScript.addDictToCache(opt, path, value);
  3274. // if (success && o2.typeOf(success)=="function") value = success(json.data);
  3275. // return value;
  3276. // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
  3277. var cb = function(json){
  3278. value = json.data;
  3279. MWF.xScript.addDictToCache(opt, path, value);
  3280. if (success && o2.typeOf(success)=="function") value = success(json.data);
  3281. return value;
  3282. };
  3283. var promise;
  3284. if (path){
  3285. var p = encodePath( path );
  3286. //var p = path.replace(/\./g, "/");
  3287. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async, false);
  3288. }else{
  3289. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async, false);
  3290. }
  3291. return (!!async) ? promise : value;
  3292. // if (path){
  3293. // var p = encodePath( path );
  3294. // //var p = path.replace(/\./g, "/");
  3295. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  3296. // value = json.data;
  3297. // // this.dictData[path] = value;
  3298. // MWF.xScript.addDictToCache(opt, path, value);
  3299. // if (success) success(json.data);
  3300. // }.bind(this), function(xhr, text, error){
  3301. // if (failure) failure(xhr, text, error);
  3302. // }, !!async);
  3303. // }else{
  3304. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  3305. // value = json.data;
  3306. // // this.dictData["root"] = value;
  3307. // MWF.xScript.addDictToCache(opt, path, value);
  3308. // if (success) success(json.data);
  3309. // }.bind(this), function(xhr, text, error){
  3310. // if (failure) failure(xhr, text, error);
  3311. // }, !!async);
  3312. // }
  3313. //return value;
  3314. };
  3315. this.set = function(path, value, success, failure){
  3316. var p = encodePath( path );
  3317. //var p = path.replace(/\./g, "/");
  3318. return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  3319. MWF.xScript.setDictToCache(key, path, value);
  3320. if (success) return success(json.data);
  3321. }, function(xhr, text, error){
  3322. if (failure) return failure(xhr, text, error);
  3323. }, false, false);
  3324. };
  3325. this.add = function(path, value, success, failure){
  3326. var p = encodePath( path );
  3327. //var p = path.replace(/\./g, "/");
  3328. return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  3329. MWF.xScript.insertDictToCache(key, path, value);
  3330. if (success) return success(json.data);
  3331. }, function(xhr, text, error){
  3332. if (failure) return failure(xhr, text, error);
  3333. }, false, false);
  3334. };
  3335. this["delete"] = function(path, success, failure){
  3336. var p = encodePath( path );
  3337. //var p = path.replace(/\./g, "/");
  3338. return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  3339. MWF.xScript.deleteDictToCache(key, path);
  3340. if (success) return success(json.data);
  3341. }, function(xhr, text, error){
  3342. if (failure) return failure(xhr, text, error);
  3343. }, false, false);
  3344. };
  3345. this.destory = this["delete"];
  3346. }
  3347. };