PageEnvironment.js 141 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133
  1. if (!MWF.xScript || !MWF.xScript.PageEnvironment) {
  2. MWF.xScript = MWF.xScript || {};
  3. MWF.xScript.PageEnvironment = function (ev) {
  4. var _data = ev.data;
  5. var _form = ev.form;
  6. var _forms = ev.forms;
  7. this.appType = "portal";
  8. this.library = COMMON;
  9. //this.library.version = "4.0";
  10. //data
  11. var getJSONData = function (jData) {
  12. return new MWF.xScript.JSONData(jData, function (data, key, _self) {
  13. var p = {
  14. "getKey": function () {
  15. return key;
  16. }, "getParent": function () {
  17. return _self;
  18. }
  19. };
  20. while (p && !_forms[p.getKey()]) p = p.getParent();
  21. var k = (p) ? p.getKey() : "";
  22. if (k) if (_forms[k]) if (_forms[k].resetData) _forms[k].resetData();
  23. //if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
  24. });
  25. };
  26. this.setData = function (data) {
  27. this.data = getJSONData(data);
  28. this.data.save = function (callback) {
  29. var formData = {
  30. "data": data,
  31. "sectionList": _form.getSectionList()
  32. };
  33. form.workAction.saveData(function (json) {
  34. if (callback) callback();
  35. }.bind(this), null, work.id, jData);
  36. }
  37. };
  38. this.setData(_data);
  39. //workContext
  40. this.workContext = {
  41. "getTask": function () {
  42. return ev.task;
  43. },
  44. "getWork": function () {
  45. return ev.work || ev.workCompleted;
  46. },
  47. "getActivity": function () {
  48. return ev.activity;
  49. },
  50. "getTaskList": function () {
  51. return ev.taskList;
  52. },
  53. "getControl": function () {
  54. return ev.control;
  55. },
  56. "getWorkLogList": function () {
  57. return ev.workLogList;
  58. },
  59. "getAttachmentList": function () {
  60. return ev.attachmentList;
  61. },
  62. "getRouteList": function () {
  63. return (ev.task) ? ev.task.routeNameList : null;
  64. },
  65. "getInquiredRouteList": function () {
  66. return null;
  67. },
  68. "setTitle": function (title) {
  69. //if (!this.workAction){
  70. // MWF.require("MWF.xScript.Actions.WorkActions", null, false);
  71. // this.workAction = new MWF.xScript.Actions.WorkActions();
  72. //}
  73. //this.workAction.setTitle(ev.work.id, {"title": title});
  74. }
  75. };
  76. var _redefineWorkProperties = function (work) {
  77. if (work) {
  78. work.creatorPersonDn = work.creatorPerson;
  79. work.creatorUnitDn = work.creatorUnit;
  80. work.creatorUnitDnList = work.creatorUnitList;
  81. work.creatorIdentityDn = work.creatorIdentity;
  82. var o = {
  83. "creatorPerson": {
  84. "get": function () {
  85. return this.creatorPersonDn.substring(0, this.creatorPersonDn.indexOf("@"));
  86. }
  87. },
  88. "creatorUnit": {
  89. "get": function () {
  90. return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));
  91. }
  92. },
  93. "creatorDepartment": {
  94. "get": function () {
  95. return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));
  96. }
  97. },
  98. "creatorIdentity": {
  99. "get": function () {
  100. return this.creatorIdentityDn.substring(0, this.creatorIdentityDn.indexOf("@"));
  101. }
  102. },
  103. "creatorUnitList": {
  104. "get": function () {
  105. var v = [];
  106. this.creatorUnitDnList.each(function (dn) {
  107. v.push(dn.substring(0, dn.indexOf("@")))
  108. });
  109. return v;
  110. }
  111. },
  112. "creatorCompany": {
  113. "get": function () {
  114. return this.creatorUnitList[0]
  115. }
  116. }
  117. };
  118. MWF.defineProperties(work, o);
  119. }
  120. return work;
  121. };
  122. var _redefineTaskProperties = function (task) {
  123. if (task) {
  124. task.personDn = task.person;
  125. task.unitDn = task.unit;
  126. task.unitDnList = task.unitList;
  127. task.identityDn = task.identity;
  128. var o = {
  129. "person": {
  130. "get": function () {
  131. return this.personDn.substring(0, this.personDn.indexOf("@"));
  132. }
  133. },
  134. "unit": {
  135. "get": function () {
  136. return this.unitDn.substring(0, this.unitDn.indexOf("@"));
  137. }
  138. },
  139. "department": {
  140. "get": function () {
  141. return this.unitDn.substring(0, this.unitDn.indexOf("@"));
  142. }
  143. },
  144. "identity": {
  145. "get": function () {
  146. return this.identityDn.substring(0, this.identityDn.indexOf("@"));
  147. }
  148. },
  149. "unitList": {
  150. "get": function () {
  151. var v = [];
  152. this.unitDnList.each(function (dn) {
  153. v.push(dn.substring(0, dn.indexOf("@")))
  154. });
  155. return v;
  156. }
  157. },
  158. "company": {
  159. "get": function () {
  160. return this.unitList[0];
  161. }
  162. }
  163. };
  164. MWF.defineProperties(task, o);
  165. }
  166. return task;
  167. };
  168. _redefineWorkProperties(this.workContext.getWork());
  169. _redefineTaskProperties(_redefineWorkProperties(this.workContext.getTask()));
  170. //dict
  171. this.Dict = MWF.xScript.createDict(_form.json.application, "portal");
  172. //org
  173. var orgActions = null;
  174. var getOrgActions = function () {
  175. if (!orgActions) {
  176. MWF.require("MWF.xScript.Actions.UnitActions", null, false);
  177. orgActions = new MWF.xScript.Actions.UnitActions();
  178. }
  179. };
  180. var getNameFlag = function (name) {
  181. var t = typeOf(name);
  182. if (t === "array") {
  183. var v = [];
  184. name.each(function (id) {
  185. v.push((typeOf(id) === "object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  186. });
  187. return v;
  188. } else {
  189. return [(t === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  190. }
  191. };
  192. this.org = {
  193. //群组***************
  194. //获取群组--返回群组的对象数组
  195. getGroup: function (name, async) {
  196. getOrgActions();
  197. var data = {"groupList": getNameFlag(name)};
  198. var v = null;
  199. var cb = function (json) {
  200. v = json.data;
  201. v = (v && v.length === 1) ? v[0] : v
  202. if (async && o2.typeOf(async) == "function") return async(v);
  203. return v;
  204. };
  205. var promise = orgActions.listGroup(data, cb, null, !!async);
  206. return (!!async) ? promise : v;
  207. // var v = null;
  208. // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  209. // return (v && v.length===1) ? v[0] : v;
  210. },
  211. //查询下级群组--返回群组的对象数组
  212. //nested 布尔 true嵌套下级;false直接下级;默认false;
  213. listSubGroup: function (name, nested, async) {
  214. getOrgActions();
  215. var data = {"groupList": getNameFlag(name)};
  216. var v = null;
  217. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  218. // v = json.data;
  219. // return v;
  220. // }.ag().catch(function(json){ return json; });
  221. var cb = function (json) {
  222. v = json.data;
  223. if (async && o2.typeOf(async) == "function") return async(v);
  224. return v;
  225. };
  226. var promise;
  227. if (nested) {
  228. promise = orgActions.listSubGroupNested(data, cb, null, !!async);
  229. } else {
  230. promise = orgActions.listSubGroupDirect(data, cb, null, !!async);
  231. }
  232. return (!!async) ? promise : v;
  233. // var v = null;
  234. // if (nested){
  235. // orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  236. // }else{
  237. // orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  238. // }
  239. // return v;
  240. },
  241. //查询上级群组--返回群组的对象数组
  242. //nested 布尔 true嵌套上级;false直接上级;默认false;
  243. listSupGroup: function (name, nested, async) {
  244. getOrgActions();
  245. var data = {"groupList": getNameFlag(name)};
  246. var v = null;
  247. var cb = function (json) {
  248. v = json.data;
  249. if (async && o2.typeOf(async) == "function") return async(v);
  250. return v;
  251. };
  252. var promise
  253. if (nested) {
  254. var promise = orgActions.listSupGroupNested(data, cb, null, !!async);
  255. } else {
  256. var promise = orgActions.listSupGroupDirect(data, cb, null, !!async);
  257. }
  258. return (!!async) ? promise : v;
  259. // var v = null;
  260. // if (nested){
  261. // orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  262. // }else{
  263. // orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  264. // }
  265. // return v;
  266. },
  267. //人员所在群组(嵌套)--返回群组的对象数组
  268. listGroupWithPerson: function (name, async) {
  269. getOrgActions();
  270. var data = {"personList": getNameFlag(name)};
  271. var v = null;
  272. var cb = function (json) {
  273. v = json.data;
  274. if (async && o2.typeOf(async) == "function") return async(v);
  275. return v;
  276. };
  277. var promise = orgActions.listGroupWithPerson(data, cb, null, !!async);
  278. return (!!async) ? promise : v;
  279. // var v = null;
  280. // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  281. // return v;
  282. },
  283. //身份所在群组(嵌套)--返回群组的对象数组
  284. listGroupWithIdentity:function(identity, async){
  285. getOrgActions();
  286. var data = {"identityList": getNameFlag(identity)};
  287. var v = null;
  288. var cb = function(json){
  289. v = json.data;
  290. if (async && o2.typeOf(async)=="function") return async(v);
  291. return v;
  292. };
  293. var promise = orgActions.listGroupWithIdentity(data, cb, null, !!async);
  294. return (!!async) ? promise : v;
  295. },
  296. //群组是否拥有角色--返回true, false
  297. groupHasRole: function (name, role, async) {
  298. getOrgActions();
  299. nameFlag = (typeOf(name) === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  300. var data = {"group": nameFlag, "roleList": getNameFlag(role)};
  301. var v = false;
  302. var cb = function (json) {
  303. v = json.data.value;
  304. if (async && o2.typeOf(async) == "function") return async(v);
  305. return v;
  306. };
  307. var promise = orgActions.groupHasRole(data, cb, null, !!async);
  308. return (!!async) ? promise : v;
  309. // var v = false;
  310. // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  311. // return v;
  312. },
  313. //角色***************
  314. //获取角色--返回角色的对象数组
  315. getRole: function (name, async) {
  316. getOrgActions();
  317. var data = {"roleList": getNameFlag(name)};
  318. var v = null;
  319. var cb = function (json) {
  320. v = json.data;
  321. v = (v && v.length === 1) ? v[0] : v;
  322. if (async && o2.typeOf(async) == "function") return async(v);
  323. return v;
  324. };
  325. var promise = orgActions.listRole(data, cb, null, !!async);
  326. return (!!async) ? promise : v;
  327. // var v = null;
  328. // orgActions.listRole(data, function(json){v = json.data;}, null, false);
  329. // return (v && v.length===1) ? v[0] : v;
  330. },
  331. //人员所有角色(嵌套)--返回角色的对象数组
  332. listRoleWithPerson: function (name, async) {
  333. getOrgActions();
  334. var data = {"personList": getNameFlag(name)};
  335. var v = null;
  336. var cb = function (json) {
  337. v = json.data;
  338. if (async && o2.typeOf(async) == "function") return async(v);
  339. return v;
  340. };
  341. var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
  342. return (!!async) ? promise : v;
  343. // var v = null;
  344. // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  345. // return v;
  346. },
  347. //人员***************
  348. //人员是否拥有角色--返回true, false
  349. personHasRole: function (name, role, async) {
  350. getOrgActions();
  351. nameFlag = (typeOf(name) === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  352. var data = {"person": nameFlag, "roleList": getNameFlag(role)};
  353. var v = false;
  354. var cb = function (json) {
  355. v = json.data.value;
  356. if (async && o2.typeOf(async) == "function") return async(v);
  357. return v;
  358. };
  359. var promise = orgActions.personHasRole(data, cb, null, !!async);
  360. return (!!async) ? promise : v;
  361. // var v = false;
  362. // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  363. // return v;
  364. },
  365. //获取人员,附带身份,身份所在的组织,个人所在群组,个人拥有角色.
  366. getPersonData: function(name, async){
  367. getOrgActions();
  368. var v = null;
  369. var cb = function(json){
  370. v = json.data;
  371. if (async && o2.typeOf(async)=="function") return async(v);
  372. return v;
  373. };
  374. var promise = orgActions.getPerson(null, cb, null, !!async, {"flag": name});
  375. return (!!async) ? promise : v;
  376. },
  377. //获取人员--返回人员的对象数组
  378. getPerson: function (name, async, findCN) {
  379. getOrgActions();
  380. var data = {"personList": getNameFlag(name)};
  381. if( o2.typeOf(findCN) === "boolean"){
  382. data.useNameFind = findCN;
  383. }
  384. var v = null;
  385. var cb = function (json) {
  386. v = json.data;
  387. v = (v && v.length === 1) ? v[0] : v;
  388. if (async && o2.typeOf(async) == "function") return async(v);
  389. return v;
  390. };
  391. var promise = orgActions.listPerson(data, cb, null, !!async);
  392. return (!!async) ? promise : v;
  393. // var v = null;
  394. // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  395. // return (v && v.length===1) ? v[0] : v;
  396. },
  397. //查询下级人员--返回人员的对象数组
  398. //nested 布尔 true嵌套下级;false直接下级;默认false;
  399. listSubPerson: function (name, nested, async) {
  400. getOrgActions();
  401. var data = {"personList": getNameFlag(name)};
  402. var v = null;
  403. var cb = function (json) {
  404. v = json.data;
  405. if (async && o2.typeOf(async) == "function") return async(v);
  406. return v;
  407. };
  408. var promise;
  409. if (nested) {
  410. promise = orgActions.listPersonSubNested(data, cb, null, !!async);
  411. } else {
  412. promise = orgActions.listPersonSubDirect(data, cb, null, !!async);
  413. }
  414. return (!!async) ? promise : v;
  415. },
  416. //查询上级人员--返回人员的对象数组
  417. //nested 布尔 true嵌套上级;false直接上级;默认false;
  418. listSupPerson: function (name, nested, async) {
  419. getOrgActions();
  420. var data = {"personList": getNameFlag(name)};
  421. var v = null;
  422. var cb = function (json) {
  423. v = json.data;
  424. if (async && o2.typeOf(async) == "function") return async(v);
  425. return v;
  426. };
  427. var promise;
  428. if (nested) {
  429. promise = orgActions.listPersonSupNested(data, cb, null, !!async);
  430. } else {
  431. promise = orgActions.listPersonSupDirect(data, cb, null, !!async);
  432. }
  433. return (!!async) ? promise : v;
  434. },
  435. //获取群组的所有人员--返回人员的对象数组
  436. listPersonWithGroup: function (name, async) {
  437. getOrgActions();
  438. var data = {"groupList": getNameFlag(name)};
  439. var v = null;
  440. var cb = function (json) {
  441. v = json.data;
  442. if (async && o2.typeOf(async) == "function") return async(v);
  443. return v;
  444. };
  445. var promise = orgActions.listPersonWithGroup(data, cb, null, !!async);
  446. return (!!async) ? promise : v;
  447. },
  448. //获取角色的所有人员--返回人员的对象数组
  449. listPersonWithRole: function (name, async) {
  450. getOrgActions();
  451. var data = {"roleList": getNameFlag(name)};
  452. var v = null;
  453. var cb = function (json) {
  454. v = json.data;
  455. if (async && o2.typeOf(async) == "function") return async(v);
  456. return v;
  457. };
  458. var promise
  459. promise = orgActions.listPersonWithRole(data, cb, null, !!async);
  460. return (!!async) ? promise : v;
  461. },
  462. //获取身份的所有人员--返回人员的对象数组
  463. listPersonWithIdentity: function (name, async) {
  464. getOrgActions();
  465. var data = {"identityList": getNameFlag(name)};
  466. var v = null;
  467. var cb = function (json) {
  468. v = json.data;
  469. if (async && o2.typeOf(async) == "function") return async(v);
  470. return v;
  471. };
  472. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  473. return (!!async) ? promise : v;
  474. },
  475. //获取身份的所有人员--返回人员的对象数组或人员对象
  476. getPersonWithIdentity: function (name, async) {
  477. getOrgActions();
  478. var data = {"identityList": getNameFlag(name)};
  479. var v = null;
  480. var cb = function (json) {
  481. v = json.data;
  482. v = (v && v.length === 1) ? v[0] : v;
  483. if (async && o2.typeOf(async) == "function") return async(v);
  484. return v;
  485. };
  486. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  487. return (!!async) ? promise : v;
  488. },
  489. //查询组织成员的人员--返回人员的对象数组
  490. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  491. listPersonWithUnit: function (name, nested, async) {
  492. getOrgActions();
  493. var data = {"unitList": getNameFlag(name)};
  494. var v = null;
  495. var cb = function (json) {
  496. v = json.data;
  497. if (async && o2.typeOf(async) == "function") return async(v);
  498. return v;
  499. };
  500. var promise;
  501. if (nested) {
  502. promise = orgActions.listPersonWithUnitNested(data, cb, null, !!async);
  503. } else {
  504. promise = orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
  505. }
  506. return (!!async) ? promise : v;
  507. },
  508. //根据属性查询人员--返回人员的对象数组
  509. //name string 属性名
  510. //value string 属性值
  511. listPersonWithAttribute: function (name, value, async) {
  512. getOrgActions();
  513. var data = {"name": name, "attribute": value};
  514. var v = null;
  515. var cb = function (json) {
  516. v = json.data;
  517. if (async && o2.typeOf(async) == "function") return async(v);
  518. return v;
  519. };
  520. var promise = orgActions.listPersonWithAttribute(data, cb, null, !!async);
  521. return (!!async) ? promise : v;
  522. },
  523. //根据属性查询人员--返回人员的全称数组
  524. //name string 属性名
  525. //value string 属性值
  526. listPersonNameWithAttribute: function (name, value, async) {
  527. getOrgActions();
  528. var data = {"name": name, "attribute": value};
  529. var v = null;
  530. var cb = function (json) {
  531. v = json.data.personList;
  532. if (async && o2.typeOf(async) == "function") return async(v);
  533. return v;
  534. };
  535. var promise = orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
  536. return (!!async) ? promise : v;
  537. },
  538. //人员属性************
  539. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  540. appendPersonAttribute: function (person, attr, values, success, failure, async) {
  541. getOrgActions();
  542. var personFlag = (typeOf(person) === "object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  543. var data = {"attributeList": values, "name": attr, "person": personFlag};
  544. var v = null;
  545. var cb = function (json) {
  546. v = json.data;
  547. if (async && o2.typeOf(async) == "function") return async(v);
  548. return v;
  549. };
  550. var promise = orgActions.appendPersonAttribute(data, cb, null, !!async);
  551. return (!!async) ? promise : v;
  552. // var cb = function(json){
  553. // if (success) return success(json);
  554. // }.ag().catch(function(xhr, text, error){
  555. // if (failure) return failure(xhr, text, error);
  556. // });
  557. //
  558. // orgActions.appendPersonAttribute(data, cb, null, !!async);
  559. },
  560. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  561. setPersonAttribute: function (person, attr, values, success, failure, async) {
  562. getOrgActions();
  563. var personFlag = (typeOf(person) === "object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  564. var data = {"attributeList": values, "name": attr, "person": personFlag};
  565. var v = null;
  566. var cb = function (json) {
  567. v = json.data;
  568. if (async && o2.typeOf(async) == "function") return async(v);
  569. return v;
  570. };
  571. var promise = orgActions.setPersonAttribute(data, cb, null, !!async);
  572. return (!!async) ? promise : v;
  573. // var cb = function(json){
  574. // if (success) return success(json);
  575. // }.ag().catch(function(xhr, text, error){
  576. // if (failure) return failure(xhr, text, error);
  577. // });
  578. //
  579. // orgActions.setPersonAttribute(data, cb, null, !!async);
  580. },
  581. //获取人员属性值
  582. getPersonAttribute: function (person, attr, async) {
  583. getOrgActions();
  584. var personFlag = (typeOf(person) === "object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  585. var data = {"name": attr, "person": personFlag};
  586. var v = null;
  587. var cb = function (json) {
  588. v = json.data.attributeList;
  589. if (async && o2.typeOf(async) == "function") return async(v);
  590. return v;
  591. };
  592. var promise = orgActions.getPersonAttribute(data, cb, null, !!async);
  593. return (!!async) ? promise : v;
  594. },
  595. //列出人员所有属性的名称
  596. listPersonAttributeName: function (name, async) {
  597. getOrgActions();
  598. var data = {"personList": getNameFlag(name)};
  599. var v = null;
  600. var cb = function (json) {
  601. v = json.data.nameList;
  602. if (async && o2.typeOf(async) == "function") return async(v);
  603. return v;
  604. };
  605. var promise = orgActions.listPersonAttributeName(data, cb, null, !!async);
  606. return (!!async) ? promise : v;
  607. },
  608. //列出人员的所有属性
  609. listPersonAllAttribute: function (name, async) {
  610. getOrgActions();
  611. var data = {"personList": getNameFlag(name)};
  612. var v = null;
  613. var cb = function (json) {
  614. v = json.data;
  615. if (async && o2.typeOf(async) == "function") return async(v);
  616. return v;
  617. };
  618. var promise = orgActions.listPersonAllAttribute(data, cb, null, !!async);
  619. return (!!async) ? promise : v;
  620. },
  621. //身份**********
  622. //获取身份
  623. getIdentity: function (name, async) {
  624. getOrgActions();
  625. var data = {"identityList": getNameFlag(name)};
  626. var v = null;
  627. var cb = function (json) {
  628. v = json.data;
  629. v = (v && v.length === 1) ? v[0] : v;
  630. if (async && o2.typeOf(async) == "function") return async(v);
  631. return v;
  632. };
  633. var promise = orgActions.listIdentity(data, cb, null, !!async);
  634. return (!!async) ? promise : v;
  635. },
  636. //列出人员的身份
  637. listIdentityWithPerson: function (name, async, findCN) {
  638. getOrgActions();
  639. var data = {"personList": getNameFlag(name)};
  640. if( o2.typeOf(findCN) === "boolean"){
  641. data.useNameFind = findCN;
  642. }
  643. var v = null;
  644. var cb = function (json) {
  645. v = json.data;
  646. if (async && o2.typeOf(async) == "function") return async(v);
  647. return v;
  648. };
  649. var promise = orgActions.listIdentityWithPerson(data, cb, null, !!async);
  650. return (!!async) ? promise : v;
  651. },
  652. //查询组织成员身份--返回身份的对象数组
  653. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  654. listIdentityWithUnit: function (name, nested, async) {
  655. getOrgActions();
  656. var data = {"unitList": getNameFlag(name)};
  657. var v = null;
  658. // var cb = function(json){
  659. // v = json.data;
  660. // if (async && o2.typeOf(async)=="function") return async(v);
  661. // return v;
  662. // }.ag().catch(function(json){ return json; });
  663. var cb = function (json) {
  664. v = json.data;
  665. if (async && o2.typeOf(async) == "function") return async(v);
  666. return v;
  667. };
  668. var method = (nested) ? "listIdentityWithUnitNested" : "listIdentityWithUnitDirect";
  669. var promise = orgActions[method](data, cb, null, !!async);
  670. promise.name = "org";
  671. //
  672. // if (nested){
  673. // orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
  674. // }else{
  675. // orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
  676. // }
  677. return (!!async) ? promise : v;
  678. },
  679. //组织**********
  680. //获取组织
  681. getUnit: function (name, async, findCN) {
  682. getOrgActions();
  683. var data = {"unitList": getNameFlag(name)};
  684. if( o2.typeOf(findCN) === "boolean"){
  685. data.useNameFind = findCN;
  686. }
  687. var v = null;
  688. var cb = function (json) {
  689. v = json.data;
  690. v = (v && v.length === 1) ? v[0] : v;
  691. if (async && o2.typeOf(async) == "function") return async(v);
  692. return v;
  693. };
  694. var promise = orgActions.listUnit(data, cb, null, !!async);
  695. return (!!async) ? promise : v;
  696. },
  697. //查询组织的下级--返回组织的对象数组
  698. //nested 布尔 true嵌套下级;false直接下级;默认false;
  699. listSubUnit: function (name, nested, async) {
  700. getOrgActions();
  701. var data = {"unitList": getNameFlag(name)};
  702. var v = null;
  703. var cb = function (json) {
  704. v = json.data;
  705. if (async && o2.typeOf(async) == "function") return async(v);
  706. return v;
  707. };
  708. var promise;
  709. if (nested) {
  710. promise = orgActions.listUnitSubNested(data, cb, null, !!async);
  711. } else {
  712. promise = orgActions.listUnitSubDirect(data, cb, null, !!async);
  713. }
  714. return (!!async) ? promise : v;
  715. },
  716. //查询组织的上级--返回组织的对象数组
  717. //nested 布尔 true嵌套上级;false直接上级;默认false;
  718. //async 布尔 true异步请求
  719. listSupUnit: function (name, nested, async) {
  720. getOrgActions();
  721. var data = {"unitList": getNameFlag(name)};
  722. var v = null;
  723. var cb = function (json) {
  724. v = json.data;
  725. if (async && o2.typeOf(async) == "function") return async(v);
  726. return v;
  727. };
  728. var promise;
  729. if (nested) {
  730. promise = orgActions.listUnitSupNested(data, cb, null, !!async);
  731. } else {
  732. promise = orgActions.listUnitSupDirect(data, cb, null, !!async);
  733. }
  734. return (!!async) ? promise : v;
  735. // if (callback){
  736. // if (nested){
  737. // orgActions.listUnitSupNested(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  738. // }else{
  739. // orgActions.listUnitSupDirect(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  740. // }
  741. // }else{
  742. // var v = null;
  743. // if (nested){
  744. // orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  745. // }else{
  746. // orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  747. // }
  748. // return v;
  749. // }
  750. },
  751. //根据个人身份获取组织
  752. //flag 数字 表示获取第几层的组织
  753. // 字符串 表示获取指定类型的组织
  754. // 空 表示获取直接所在的组织
  755. getUnitByIdentity: function (name, flag, async) {
  756. getOrgActions();
  757. var getUnitMethod = "current";
  758. var v;
  759. if (flag) {
  760. if (typeOf(flag) === "string") getUnitMethod = "type";
  761. if (typeOf(flag) === "number") getUnitMethod = "level";
  762. }
  763. var cb;
  764. var promise;
  765. switch (getUnitMethod) {
  766. case "current":
  767. var data = {"identityList": getNameFlag(name)};
  768. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  769. // v = json.data; v=(v&&v.length===1) ? v[0] : v; return v;
  770. // }.ag().catch(function(json){ return json; });
  771. cb = function (json) {
  772. v = json.data;
  773. v = (v && v.length === 1) ? v[0] : v;
  774. if (async && o2.typeOf(async) == "function") return async(v);
  775. return v;
  776. };
  777. promise = orgActions.listUnitWithIdentity(data, cb, null, !!async);
  778. break;
  779. case "type":
  780. var data = {
  781. "identity": (typeOf(name) === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,
  782. "type": flag
  783. };
  784. cb = function (json) {
  785. v = json.data;
  786. if (async && o2.typeOf(async) == "function") return async(v);
  787. return v;
  788. };
  789. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  790. // v = json.data; return v;
  791. // }.ag().catch(function(json){ return json; });
  792. promise = orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
  793. break;
  794. case "level":
  795. var data = {
  796. "identity": (typeOf(name) === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,
  797. "level": flag
  798. };
  799. cb = function (json) {
  800. v = json.data;
  801. v = (v && v.length === 1) ? v[0] : v;
  802. if (async && o2.typeOf(async) == "function") return async(v);
  803. return v;
  804. };
  805. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  806. // v = json.data; return v;
  807. // }.ag().catch(function(json){ return json; });
  808. promise = orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
  809. break;
  810. }
  811. return (!!async) ? promise : v;
  812. },
  813. //列出身份所在组织的所有上级组织
  814. listAllSupUnitWithIdentity: function (name, async) {
  815. getOrgActions();
  816. var data = {"identityList": getNameFlag(name)};
  817. var v = null;
  818. var cb = function (json) {
  819. v = json.data;
  820. if (async && o2.typeOf(async) == "function") return async(v);
  821. return v;
  822. };
  823. var promise = orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
  824. return (!!async) ? promise : v;
  825. },
  826. //获取人员所在的所有组织
  827. listUnitWithPerson: function (name, async) {
  828. getOrgActions();
  829. var data = {"personList": getNameFlag(name)};
  830. var v = null;
  831. var cb = function (json) {
  832. v = json.data;
  833. if (async && o2.typeOf(async) == "function") return async(v);
  834. return v;
  835. };
  836. var promise = orgActions.listUnitWithPerson(data, cb, null, !!async);
  837. return (!!async) ? promise : v;
  838. },
  839. //列出人员所在组织的所有上级组织
  840. listAllSupUnitWithPerson: function (name, async) {
  841. getOrgActions();
  842. var data = {"personList": getNameFlag(name)};
  843. var v = null;
  844. var cb = function (json) {
  845. v = json.data;
  846. if (async && o2.typeOf(async) == "function") return async(v);
  847. return v;
  848. };
  849. var promise = orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
  850. return (!!async) ? promise : v;
  851. },
  852. //根据组织属性,获取所有符合的组织
  853. listUnitWithAttribute: function (name, attribute, async) {
  854. getOrgActions();
  855. var data = {"name": name, "attribute": attribute};
  856. var v = null;
  857. var cb = function (json) {
  858. v = json.data;
  859. if (async && o2.typeOf(async) == "function") return async(v);
  860. return v;
  861. };
  862. promise = orgActions.listUnitWithAttribute(data, cb, null, !!async);
  863. return (!!async) ? promise : v;
  864. },
  865. //根据组织职务,获取所有符合的组织
  866. listUnitWithDuty: function (name, id, async) {
  867. getOrgActions();
  868. var data = {
  869. "name": name,
  870. "identity": (typeOf(id) === "object") ? (id.distinguishedName || id.id || id.unique || id.name) : id
  871. };
  872. var v = null;
  873. var cb = function (json) {
  874. v = json.data;
  875. if (async && o2.typeOf(async) == "function") return async(v);
  876. return v;
  877. };
  878. var promise = orgActions.listUnitWithDuty(data, cb, null, !!async);
  879. return (!!async) ? promise : v;
  880. },
  881. //组织职务***********
  882. //获取指定的组织职务的身份
  883. getDuty: function (duty, id, async) {
  884. getOrgActions();
  885. var data = {
  886. "name": duty,
  887. "unit": (typeOf(id) === "object") ? (id.distinguishedName || id.id || id.unique || id.name) : id
  888. };
  889. var v = null;
  890. var cb = function (json) {
  891. v = json.data;
  892. if (async && o2.typeOf(async) == "function") return async(v);
  893. return v;
  894. };
  895. var promise = orgActions.getDuty(data, cb, null, !!async);
  896. return (!!async) ? promise : v;
  897. },
  898. //获取身份的所有职务名称
  899. listDutyNameWithIdentity: function (name, async) {
  900. getOrgActions();
  901. var data = {"identityList": getNameFlag(name)};
  902. var v = null;
  903. var cb = function (json) {
  904. v = json.data.nameList;
  905. if (async && o2.typeOf(async) == "function") return async(v);
  906. return v;
  907. };
  908. var promise = orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
  909. return (!!async) ? promise : v;
  910. },
  911. //获取组织的所有职务名称
  912. listDutyNameWithUnit: function (name, async) {
  913. getOrgActions();
  914. var data = {"unitList": getNameFlag(name)};
  915. var v = null;
  916. var cb = function (json) {
  917. v = json.data.nameList;
  918. if (async && o2.typeOf(async) == "function") return async(v);
  919. return v;
  920. };
  921. var promise = orgActions.listDutyNameWithUnit(data, cb, null, !!async);
  922. return (!!async) ? promise : v;
  923. },
  924. //获取组织的所有职务
  925. listUnitAllDuty: function (name, async) {
  926. getOrgActions();
  927. var data = {"unitList": getNameFlag(name)};
  928. var v = null;
  929. var cb = function (json) {
  930. v = json.data;
  931. if (async && o2.typeOf(async) == "function") return async(v);
  932. return v;
  933. };
  934. var promise = orgActions.listUnitAllDuty(data, cb, null, !!async);
  935. return (!!async) ? promise : v;
  936. },
  937. //列出顶层组织
  938. listTopUnit: function (async) {
  939. var action = MWF.Actions.get("x_organization_assemble_control");
  940. var v = null;
  941. var cb = function (json) {
  942. v = json.data;
  943. if (async && o2.typeOf(async) == "function") return async(v);
  944. return v;
  945. };
  946. var promise = action.listTopUnit(cb, null, !!async);
  947. return (!!async) ? promise : v;
  948. },
  949. //组织属性**************
  950. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  951. appendUnitAttribute: function (unit, attr, values, success, failure, async) {
  952. getOrgActions();
  953. var unitFlag = (typeOf(unit) === "object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  954. var data = {"attributeList": values, "name": attr, "unit": unitFlag};
  955. var v = null;
  956. var cb = function (json) {
  957. v = json.data;
  958. if (async && o2.typeOf(async) == "function") return async(v);
  959. return v;
  960. };
  961. var promise = orgActions.appendUnitAttribute(data, cb, null, !!async);
  962. return (!!async) ? promise : v;
  963. // var cb = function(json){
  964. // if (success) return success(json);
  965. // }.ag().catch(function(xhr, text, error){
  966. // if (failure) return failure(xhr, text, error);
  967. // });
  968. //
  969. // orgActions.appendPersonAttribute(data, cb, null, !!async);
  970. // orgActions.appendUnitAttribute(data, function(json){
  971. // if (json.data.value){
  972. // if (success) success();
  973. // }else{
  974. // if (failure) failure(null, "", "append values failed");
  975. // }
  976. // }, function(xhr, text, error){
  977. // if (failure) failure(xhr, text, error);
  978. // }, false);
  979. },
  980. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  981. setUnitAttribute: function (unit, attr, values, success, failure, async) {
  982. getOrgActions();
  983. var unitFlag = (typeOf(unit) === "object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  984. var data = {"attributeList": values, "name": attr, "unit": unitFlag};
  985. var v = null;
  986. var cb = function (json) {
  987. v = json.data;
  988. if (async && o2.typeOf(async) == "function") return async(v);
  989. return v;
  990. };
  991. var promise = orgActions.setUnitAttribute(data, cb, null, !!async);
  992. return (!!async) ? promise : v;
  993. // var cb = function(json){
  994. // if (success) return success(json);
  995. // }.ag().catch(function(xhr, text, error){
  996. // if (failure) return failure(xhr, text, error);
  997. // });
  998. // orgActions.setUnitAttribute(data, cb, null, !!async);
  999. // orgActions.setUnitAttribute(data, function(json){
  1000. // if (json.data.value){
  1001. // if (success) success();
  1002. // }else{
  1003. // if (failure) failure(null, "", "append values failed");
  1004. // }
  1005. // }, function(xhr, text, error){
  1006. // if (failure) failure(xhr, text, error);
  1007. // }, false);
  1008. },
  1009. //获取组织属性值
  1010. getUnitAttribute: function (unit, attr, async) {
  1011. getOrgActions();
  1012. var unitFlag = (typeOf(unit) === "object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1013. var data = {"name": attr, "unit": unitFlag};
  1014. var v = null;
  1015. var cb = function (json) {
  1016. v = json.data.attributeList;
  1017. if (async && o2.typeOf(async) == "function") return async(v);
  1018. return v;
  1019. };
  1020. var promise = orgActions.getUnitAttribute(data, cb, null, !!async);
  1021. return (!!async) ? promise : v;
  1022. },
  1023. //列出组织所有属性的名称
  1024. listUnitAttributeName: function (name, async) {
  1025. getOrgActions();
  1026. var data = {"unitList": getNameFlag(name)};
  1027. var v = null;
  1028. var cb = function (json) {
  1029. v = json.data.nameList;
  1030. if (async && o2.typeOf(async) == "function") return async(v);
  1031. return v;
  1032. };
  1033. var promise = orgActions.listUnitAttributeName(data, cb, null, !!async);
  1034. return (!!async) ? promise : v;
  1035. },
  1036. //列出组织的所有属性
  1037. listUnitAllAttribute: function (name, async) {
  1038. getOrgActions();
  1039. var data = {"unitList": getNameFlag(name)};
  1040. var v = null;
  1041. var cb = function (json) {
  1042. v = json.data;
  1043. if (async && o2.typeOf(async) == "function") return async(v);
  1044. return v;
  1045. };
  1046. var promise = orgActions.listUnitAllAttribute(data, cb, null, !!async);
  1047. return (!!async) ? promise : v;
  1048. }
  1049. };
  1050. this.Action = (function () {
  1051. var actions = [];
  1052. return function (root, json) {
  1053. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  1054. action.getActions = function (callback) {
  1055. if (!this.actions) this.actions = {};
  1056. Object.merge(this.actions, json);
  1057. if (callback) callback();
  1058. };
  1059. this.invoke = function (option) {
  1060. action.invoke(option)
  1061. }
  1062. }
  1063. })();
  1064. // this.service = {
  1065. // "jaxwsClient": {},
  1066. // "jaxrsClient": {}
  1067. // };
  1068. var lookupAction = null;
  1069. var getLookupAction = function (callback) {
  1070. if (!lookupAction) {
  1071. MWF.require("MWF.xDesktop.Actions.RestActions", function () {
  1072. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  1073. lookupAction.getActions = function (actionCallback) {
  1074. this.actions = {
  1075. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  1076. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  1077. "lookup": {
  1078. "uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute",
  1079. "method": "PUT"
  1080. },
  1081. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  1082. };
  1083. if (actionCallback) actionCallback();
  1084. }
  1085. if (callback) callback();
  1086. });
  1087. } else {
  1088. if (callback) callback();
  1089. }
  1090. };
  1091. this.view = {
  1092. "lookup": function (view, callback, async) {
  1093. var filterList = {"filterList": (view.filter || null)};
  1094. return MWF.Actions.load("x_query_assemble_surface").ViewAction.executeWithQuery(view.view, view.application, filterList, function (json) {
  1095. var data = {
  1096. "grid": json.data.grid || json.data.groupGrid,
  1097. "groupGrid": json.data.groupGrid
  1098. };
  1099. if (callback) callback(data);
  1100. return data;
  1101. }, null, async);
  1102. },
  1103. "lookupV1": function (view, callback) {
  1104. getLookupAction(function () {
  1105. lookupAction.invoke({
  1106. "name": "lookup",
  1107. "async": true,
  1108. "parameter": {"view": view.view, "application": view.application},
  1109. "success": function (json) {
  1110. var data = {
  1111. "grid": json.data.grid,
  1112. "groupGrid": json.data.groupGrid
  1113. };
  1114. if (callback) callback(data);
  1115. }.bind(this)
  1116. });
  1117. }.bind(this));
  1118. },
  1119. "select": function (view, callback, options) {
  1120. if (view.view) {
  1121. var viewJson = {
  1122. "application": view.application || _form.json.application,
  1123. "viewName": view.view || "",
  1124. "isTitle": (view.isTitle === false) ? "no" : "yes",
  1125. "select": (view.isMulti === false) ? "single" : "multi",
  1126. "filter": view.filter
  1127. };
  1128. if (!options) options = {};
  1129. options.width = view.width;
  1130. options.height = view.height;
  1131. options.title = view.caption;
  1132. var width = options.width || "700";
  1133. var height = options.height || "400";
  1134. if (layout.mobile) {
  1135. var size = document.body.getSize();
  1136. width = size.x;
  1137. height = size.y;
  1138. options.style = "viewmobile";
  1139. }
  1140. width = width.toInt();
  1141. height = height.toInt();
  1142. var size = _form.app.content.getSize();
  1143. var x = (size.x - width) / 2;
  1144. var y = (size.y - height) / 2;
  1145. if (x < 0) x = 0;
  1146. if (y < 0) y = 0;
  1147. if (layout.mobile) {
  1148. x = 20;
  1149. y = 0;
  1150. }
  1151. var _self = this;
  1152. MWF.require("MWF.xDesktop.Dialog", function () {
  1153. var dlg = new MWF.xDesktop.Dialog({
  1154. "title": options.title || "select view",
  1155. "style": options.style || "view",
  1156. "top": y,
  1157. "left": x - 20,
  1158. "fromTop": y,
  1159. "fromLeft": x - 20,
  1160. "width": width,
  1161. "height": height,
  1162. "html": "<div style='height: 100%;'></div>",
  1163. "maskNode": _form.app.content,
  1164. "container": _form.app.content,
  1165. "buttonList": [
  1166. {
  1167. "text": MWF.LP.process.button.ok,
  1168. "action": function () {
  1169. //if (callback) callback(_self.view.selectedItems);
  1170. if (callback) callback(_self.view.getData());
  1171. this.close();
  1172. }
  1173. },
  1174. {
  1175. "text": MWF.LP.process.button.cancel,
  1176. "action": function () {
  1177. this.close();
  1178. }
  1179. }
  1180. ]
  1181. });
  1182. dlg.show();
  1183. if (layout.mobile) {
  1184. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1185. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1186. if (backAction) backAction.addEvent("click", function (e) {
  1187. dlg.close();
  1188. }.bind(this));
  1189. if (okAction) okAction.addEvent("click", function (e) {
  1190. //if (callback) callback(this.view.selectedItems);
  1191. if (callback) callback(this.view.getData());
  1192. dlg.close();
  1193. }.bind(this));
  1194. }
  1195. MWF.xDesktop.requireApp("query.Query", "Viewer", function () {
  1196. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"}, _form.app, _form.Macro);
  1197. }.bind(this));
  1198. }.bind(this));
  1199. }
  1200. }
  1201. };
  1202. this.statement = {
  1203. execute: function (obj, callback, async) {
  1204. if( obj.format ){
  1205. return this._execute(obj, callback, async, obj.format);
  1206. }else{
  1207. if( this.needCheckFormat(obj) ){
  1208. var result;
  1209. var p = MWF.Actions.load("x_query_assemble_surface").StatementAction.getFormat(obj.name, function(json){
  1210. result = this._execute(obj, callback, async, json.data.format);
  1211. return result;
  1212. }.bind(this), null, async);
  1213. return result || p;
  1214. }else{
  1215. return this._execute(obj, callback, async, "");
  1216. }
  1217. }
  1218. },
  1219. needCheckFormat: function(s){
  1220. if( s.format )return false;
  1221. if( typeOf(s.parameter) === "object" ){
  1222. for( var p in s.parameter ){
  1223. if( typeOf( s.parameter[p] ) === "date" )return true;
  1224. }
  1225. }
  1226. if( typeOf(s.filter) === "array" ){
  1227. for( var i=0; i< s.filter.length; i++){
  1228. var fType = s.filter[i].formatType;
  1229. if( ["dateTimeValue", "datetimeValue", "dateValue", "timeValue"].contains( fType ) )return true;
  1230. }
  1231. }
  1232. return false;
  1233. },
  1234. _execute: function(statement, callback, async, format){
  1235. var parameter = this.parseParameter(statement.parameter, format);
  1236. var filterList = this.parseFilter(statement.filter, parameter, format);
  1237. var obj = {
  1238. "filterList": filterList,
  1239. "parameter" : parameter
  1240. };
  1241. return MWF.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  1242. statement.name, statement.mode || "data", statement.page || 1, statement.pageSize || 20, obj,
  1243. function (json) {
  1244. if (callback) callback(json);
  1245. return json;
  1246. }, null, async);
  1247. },
  1248. parseFilter: function (filter, parameter, format) {
  1249. if (typeOf(filter) !== "array") return [];
  1250. if( !parameter )parameter = {};
  1251. var filterList = [];
  1252. (filter || []).each(function (d) {
  1253. if( !d.logic )d.logic = "and";
  1254. //var parameterName = d.path.replace(/\./g, "_");
  1255. var pName = d.path.replace(/\./g, "_");
  1256. var parameterName = pName;
  1257. var suffix = 1;
  1258. while( parameter[parameterName] ){
  1259. parameterName = pName + "_" + suffix;
  1260. suffix++;
  1261. }
  1262. var value = d.value;
  1263. if (d.comparison === "like" || d.comparison === "notLike") {
  1264. if (value.substr(0, 1) !== "%") value = "%" + value;
  1265. if (value.substr(value.length - 1, 1) !== "%") value = value + "%";
  1266. parameter[parameterName] = value; //"%"+value+"%";
  1267. } else {
  1268. if( ["sql", "sqlScript"].contains(format) ) {
  1269. if (d.formatType === "numberValue") {
  1270. value = parseFloat(value);
  1271. }
  1272. }else{
  1273. if (d.formatType === "dateTimeValue" || d.formatType === "datetimeValue") {
  1274. value = "{ts '" + value + "'}"
  1275. } else if (d.formatType === "dateValue") {
  1276. value = "{d '" + value + "'}"
  1277. } else if (d.formatType === "timeValue") {
  1278. value = "{t '" + value + "'}"
  1279. } else if (d.formatType === "numberValue") {
  1280. value = parseFloat(value);
  1281. }
  1282. }
  1283. parameter[parameterName] = value;
  1284. }
  1285. d.value = parameterName;
  1286. filterList.push(d);
  1287. }.bind(this));
  1288. return filterList;
  1289. },
  1290. parseParameter : function( obj, format ){
  1291. if( typeOf(obj) !== "object" )return {};
  1292. var parameter = {};
  1293. //传入的参数
  1294. for( var p in obj ){
  1295. var value = obj[p];
  1296. if( typeOf( value ) === "date" ){
  1297. if( ["sql", "sqlScript"].contains(format) ){
  1298. value = value.format("db");
  1299. }else{
  1300. value = "{ts '"+value.format("db")+"'}"
  1301. }
  1302. }
  1303. parameter[ p ] = value;
  1304. }
  1305. return parameter;
  1306. },
  1307. "select": function (statement, callback, options) {
  1308. if (statement.name) {
  1309. // var parameter = this.parseParameter(statement.parameter);
  1310. // var filterList = this.parseFilter(statement.filter, parameter);
  1311. var statementJson = {
  1312. "statementId": statement.name || "",
  1313. "isTitle": (statement.isTitle === false) ? "no" : "yes",
  1314. "select": (statement.isMulti === false) ? "single" : "multi",
  1315. "filter": statement.filter,
  1316. "parameter": statement.parameter
  1317. };
  1318. if (!options) options = {};
  1319. options.width = statement.width;
  1320. options.height = statement.height;
  1321. options.title = statement.caption;
  1322. var width = options.width || "700";
  1323. var height = options.height || "400";
  1324. if (layout.mobile) {
  1325. var size = document.body.getSize();
  1326. width = size.x;
  1327. height = size.y;
  1328. options.style = "viewmobile";
  1329. }
  1330. width = width.toInt();
  1331. height = height.toInt();
  1332. var size = _form.app.content.getSize();
  1333. var x = (size.x - width) / 2;
  1334. var y = (size.y - height) / 2;
  1335. if (x < 0) x = 0;
  1336. if (y < 0) y = 0;
  1337. if (layout.mobile) {
  1338. x = 20;
  1339. y = 0;
  1340. }
  1341. var _self = this;
  1342. MWF.require("MWF.xDesktop.Dialog", function () {
  1343. var dlg = new MWF.xDesktop.Dialog({
  1344. "title": options.title || "select statement view",
  1345. "style": options.style || "view",
  1346. "top": y,
  1347. "left": x - 20,
  1348. "fromTop": y,
  1349. "fromLeft": x - 20,
  1350. "width": width,
  1351. "height": height,
  1352. "html": "<div style='height: 100%;'></div>",
  1353. "maskNode": _form.app.content,
  1354. "container": _form.app.content,
  1355. "buttonList": [
  1356. {
  1357. "text": MWF.LP.process.button.ok,
  1358. "action": function () {
  1359. //if (callback) callback(_self.view.selectedItems);
  1360. if (callback) callback(_self.statement.getData());
  1361. this.close();
  1362. }
  1363. },
  1364. {
  1365. "text": MWF.LP.process.button.cancel,
  1366. "action": function () {
  1367. this.close();
  1368. }
  1369. }
  1370. ]
  1371. });
  1372. dlg.show();
  1373. if (layout.mobile) {
  1374. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1375. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1376. if (backAction) backAction.addEvent("click", function (e) {
  1377. dlg.close();
  1378. }.bind(this));
  1379. if (okAction) okAction.addEvent("click", function (e) {
  1380. //if (callback) callback(this.view.selectedItems);
  1381. if (callback) callback(this.statement.getData());
  1382. dlg.close();
  1383. }.bind(this));
  1384. }
  1385. MWF.xDesktop.requireApp("query.Query", "Statement", function () {
  1386. this.statement = new MWF.xApplication.query.Query.Statement(dlg.content.getFirst(), statementJson, {"style": "select"}, _form.app, _form.Macro);
  1387. }.bind(this));
  1388. }.bind(this));
  1389. }
  1390. }
  1391. };
  1392. this.importer = {
  1393. "upload": function (options, callback, async) {
  1394. MWF.xDesktop.requireApp("query.Query", "Importer", function () {
  1395. var importer = new MWF.xApplication.query.Query.Importer(_form.app.content, options, {}, _form.app, _form.Macro);
  1396. importer.addEvent("afterImport", function (data) {
  1397. if(callback)callback(data);
  1398. });
  1399. importer.load();
  1400. }.bind(this));
  1401. },
  1402. "downloadTemplate": function (options, fileName, callback) {
  1403. MWF.xDesktop.requireApp("query.Query", "Importer", function () {
  1404. var importer = new MWF.xApplication.query.Query.Importer(_form.app.content, options, {}, _form.app, _form.Macro);
  1405. importer.downloadTemplate(fileName, callback);
  1406. }.bind(this));
  1407. }
  1408. };
  1409. //include 引用脚本
  1410. //optionsOrName : {
  1411. // type : "", 默认为portal, 可以为 portal process cms
  1412. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  1413. // name : "" // 脚本名称/别名/id
  1414. //}
  1415. //或者name: "" // 脚本名称/别名/id
  1416. // if( !window.includedScripts ){
  1417. // var includedScripts = window.includedScripts = [];
  1418. // }else{
  1419. // var includedScripts = window.includedScripts;
  1420. // }
  1421. var includedScripts = [];
  1422. var _includeSingle = function (optionsOrName, callback, async) {
  1423. var options = optionsOrName;
  1424. if (typeOf(options) == "string") {
  1425. options = {name: options};
  1426. }
  1427. var name = options.name;
  1428. var type;
  1429. if( options.type === "service" ){
  1430. type = options.type;
  1431. }else{
  1432. type = (options.type && options.application) ? options.type : "portal";
  1433. }
  1434. var application = options.application || _form.json.application;
  1435. var key = type + "-" + application + "-" + name;
  1436. if( type === "service" ){
  1437. key = type + "-" + name;
  1438. }
  1439. if (includedScripts.indexOf(key) > -1) {
  1440. if (callback) callback.apply(this);
  1441. return;
  1442. }
  1443. //if (includedScripts.indexOf( name )> -1){
  1444. // if (callback) callback.apply(this);
  1445. // return;
  1446. //}
  1447. if (( options.enableAnonymous || options.anonymous ) && type === "cms") {
  1448. o2.Actions.load("x_cms_assemble_control").ScriptAnonymousAction.getWithAppWithName(application, name, function (json) {
  1449. if (json.data) {
  1450. includedScripts.push(key);
  1451. //名称、别名、id
  1452. (json.data.importedList || []).each(function (flag) {
  1453. includedScripts.push(type + "-" + json.data.appId + "-" + flag);
  1454. if (json.data.appName) includedScripts.push(type + "-" + json.data.appName + "-" + flag);
  1455. if (json.data.appAlias) includedScripts.push(type + "-" + json.data.appAlias + "-" + flag);
  1456. });
  1457. includedScripts = includedScripts.concat(json.data.importedList || []);
  1458. MWF.CMSMacro.exec(json.data.text, this);
  1459. if (callback) callback.apply(this);
  1460. } else {
  1461. if (callback) callback.apply(this);
  1462. }
  1463. }.bind(this), null, false);
  1464. } else {
  1465. var scriptAction;
  1466. switch (type) {
  1467. case "portal" :
  1468. if (this.scriptActionPortal) {
  1469. scriptAction = this.scriptActionPortal;
  1470. } else {
  1471. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  1472. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  1473. }
  1474. break;
  1475. case "process" :
  1476. if (this.scriptActionProcess) {
  1477. scriptAction = this.scriptActionProcess;
  1478. } else {
  1479. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  1480. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  1481. }
  1482. break;
  1483. case "cms" :
  1484. if (this.scriptActionCMS) {
  1485. scriptAction = this.scriptActionCMS;
  1486. } else {
  1487. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1488. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  1489. }
  1490. break;
  1491. case "service" :
  1492. if (this.scriptActionService) {
  1493. scriptAction = this.scriptActionService;
  1494. } else {
  1495. MWF.require("MWF.xScript.Actions.ServiceScriptActions", null, false);
  1496. scriptAction = this.scriptActionService = new MWF.xScript.Actions.ServiceScriptActions();
  1497. }
  1498. break;
  1499. }
  1500. var successCallback = function (json) {
  1501. if (json.data) {
  1502. includedScripts.push(key);
  1503. //名称、别名、id
  1504. json.data.importedList.each(function (flag) {
  1505. if (type === "portal") {
  1506. includedScripts.push(type + "-" + json.data.portal + "-" + flag);
  1507. if (json.data.portalName) includedScripts.push(type + "-" + json.data.portalName + "-" + flag);
  1508. if (json.data.portalAlias) includedScripts.push(type + "-" + json.data.portalAlias + "-" + flag);
  1509. } else if (type === "cms") {
  1510. includedScripts.push(type + "-" + json.data.appId + "-" + flag);
  1511. if (json.data.appName) includedScripts.push(type + "-" + json.data.appName + "-" + flag);
  1512. if (json.data.appAlias) includedScripts.push(type + "-" + json.data.appAlias + "-" + flag);
  1513. } else if (type === "process") {
  1514. includedScripts.push(type + "-" + json.data.application + "-" + flag);
  1515. if (json.data.appName) includedScripts.push(type + "-" + json.data.appName + "-" + flag);
  1516. if (json.data.appAlias) includedScripts.push(type + "-" + json.data.appAlias + "-" + flag);
  1517. }else if (type === "service") {
  1518. includedScripts.push(type + "-" + flag);
  1519. }
  1520. });
  1521. includedScripts = includedScripts.concat(json.data.importedList);
  1522. MWF.Macro.exec(json.data.text, this);
  1523. if (callback) callback.apply(this);
  1524. } else {
  1525. if (callback) callback.apply(this);
  1526. }
  1527. }.bind(this);
  1528. if( type === "service" ){
  1529. scriptAction.getScriptByName(name, includedScripts, successCallback, null, !!async);
  1530. }else{
  1531. scriptAction.getScriptByName(application, name, includedScripts, successCallback, null, !!async);
  1532. }
  1533. }
  1534. };
  1535. this.include = function (optionsOrName, callback, async) {
  1536. if (o2.typeOf(optionsOrName) == "array") {
  1537. if (!!async) {
  1538. var count = optionsOrName.length;
  1539. var loaded = 0;
  1540. optionsOrName.each(function (option) {
  1541. _includeSingle.apply(this, [option, function () {
  1542. loaded++;
  1543. if (loaded >= count) if (callback) callback.apply(this);
  1544. }.bind(this), true]);
  1545. }.bind(this));
  1546. } else {
  1547. optionsOrName.each(function (option) {
  1548. _includeSingle.apply(this, [option]);
  1549. }.bind(this));
  1550. if (callback) callback.apply(this);
  1551. }
  1552. } else {
  1553. _includeSingle.apply(this, [optionsOrName, callback, async])
  1554. }
  1555. };
  1556. this.define = function (name, fun, overwrite) {
  1557. var over = true;
  1558. if (overwrite === false) over = false;
  1559. var o = {};
  1560. o[name] = {"value": fun, "configurable": over};
  1561. MWF.defineProperties(this, o);
  1562. }.bind(this);
  1563. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  1564. //可在调用前执行 var resolve = this.wait();
  1565. //在异步调用结束后 执行 resolve.cb();
  1566. //目前只有表单的queryload事件支持此方法。
  1567. this.wait = function () {
  1568. resolve = {};
  1569. var setResolve = function (callback) {
  1570. resolve.cb = callback;
  1571. }.bind(this);
  1572. this.target.event_resolve = setResolve;
  1573. return resolve;
  1574. };
  1575. //和this.wait配合使用,
  1576. //如果没有异步,则resolve.cb方法不存在,
  1577. //所以在回调中中使用this.goon();使表单继续加载
  1578. this.goon = function () {
  1579. this.target.event_resolve = null;
  1580. };
  1581. //仅前台对象-----------------------------------------
  1582. //form
  1583. /**
  1584. * page对象可在门户页面中可用。它的很多方法与form类似。<b>(仅前端脚本可用)</b><br/>
  1585. * @module page
  1586. * @o2cn 门户页面
  1587. * @o2category web
  1588. * @o2range {Portal}
  1589. * @o2ordernumber 50
  1590. * @o2syntax
  1591. * //您可以在门户表单中,通过this来获取page对象,如下:
  1592. * var page = this.page;
  1593. */
  1594. this.page = this.form = {
  1595. /** 跳转到当前门户的指定页面。<b>(仅门户页面脚本可用)</b>
  1596. * @method toPage
  1597. * @static
  1598. * @param {String} name - 要跳转的页面名称
  1599. * @param {Object} [par] - 要传入被打开页面的数据。在被打开的页面可以用this.page.parameters获取
  1600. * @param {Boolean} [nohis] - 页面跳转的时候,不往History里增加历史状态,默认为false
  1601. * @o2syntax
  1602. * //跳转到当前门户的指定页面。
  1603. * this.page.toPage( name, par, nohis );
  1604. * @example
  1605. * this.page.toPage("列表页面", {"key": "发文列表"});//打开“列表页面”,并传入一个json数据。
  1606. *
  1607. * //在列表页面中,通过this.page.parameters获取传入的数据。
  1608. * var key = this.page.parameters.key; //key="发文列表"
  1609. */
  1610. "toPage": function (name, par, nohis) {
  1611. _form.app.toPage(name, par, nohis);
  1612. },
  1613. /** 跳转到指定门户页面。<b>(仅门户页面脚本可用)</b>
  1614. * @method toPortal
  1615. * @static
  1616. * @param {String} portal - 要跳转的门户名称。
  1617. * @param {String} [page] - 要打开的门户的页面名称。为空则打开指定门户的默认首页。
  1618. * @param {String} [par] - 在被打开的页面可以用this.page.parameters获取。
  1619. * @o2syntax
  1620. * this.page.toPortal( portal, page, par );
  1621. * @example
  1622. * this.page.toPortal("公文门户", "列表页面", {"key": "发文列表"});//打开“公文门户”的“列表页面”,并传入一个json数据。
  1623. *
  1624. * //在列表页面中,通过this.page.parameters获取传入的数据。
  1625. * var key = this.page.parameters.key; //key="发文列表"
  1626. */
  1627. "toPortal": function (portal, page, par) {
  1628. _form.app.toPortal(portal, page, par);
  1629. },
  1630. /**获取当前页面的基本信息
  1631. * @method getInfor
  1632. * @static
  1633. * @see module:form.getInfor
  1634. */
  1635. "getInfor": function () {
  1636. return ev.pageInfor;
  1637. },
  1638. "infor": ev.pageInfor,
  1639. /**获取打开当前页面的component对象。
  1640. * @method getApp
  1641. * @static
  1642. * @see module:form.getApp
  1643. */
  1644. "getApp": function () {
  1645. return _form.app;
  1646. },
  1647. "app": _form.app,
  1648. /**获取page对应的DOM对象。
  1649. * @method node
  1650. * @static
  1651. * @see module:form.node
  1652. */
  1653. "node": function () {
  1654. return _form.node;
  1655. },
  1656. //"readonly": _form.options.readonly,
  1657. /**获取页面元素对象。
  1658. * @method get
  1659. * @static
  1660. * @see module:form.get
  1661. */
  1662. "get": function(name,subformName ){
  1663. if( !_form.all )return null;
  1664. if( subformName ){
  1665. if( _form.all[subformName +"_"+ name] )return _form.all[subformName +"_"+ name];
  1666. return _form.all[name];
  1667. }else{
  1668. return _form.all[name];
  1669. }
  1670. // return (_form.all) ? _form.all[name] : null;
  1671. },
  1672. /**获取指定部件元素对象。<br/>
  1673. * @method getWidgetModule
  1674. * @static
  1675. * @param {String} widgetId - 在主页面嵌入部件时用的标识。
  1676. * @param {String} fieldId - 部件内组件标识。
  1677. * @return {FormComponent} 请查看本文档的Classes导航下的FormComponents。
  1678. * @see module:form.get
  1679. * @o2syntax
  1680. * this.page.getWidgetModule( widgetId, fieldId );
  1681. * @example
  1682. * <caption>
  1683. * 1、设计了一个部件,包含一个设计元素subject。<br/>
  1684. * 2、在主页面里两次嵌入1步骤创建的部件,一个标识是widget_1, widget_2。
  1685. * </caption>
  1686. * var module = this.page.getWidgetModule( "widget_1", "subject"); //部件widget_1的subject组件
  1687. * var data2 = this.page.getWidgetModule( "widget_2", "subject").getData(); //部件widget_2的subject组件的值
  1688. */
  1689. "getWidgetModule": function (widget, moduleName) {
  1690. if (!_form.widgetModules || !_form.widgetModules[widget]) return null;
  1691. var module = _form.widgetModules[widget][moduleName];
  1692. return module || null;
  1693. },
  1694. /**获取页面中可输入的字段元素对象
  1695. * @method getField
  1696. * @static
  1697. * @see module:form.getField
  1698. */
  1699. "getField": function (name) {
  1700. return _forms[name];
  1701. },
  1702. "getAction": function () {
  1703. return _form.workAction
  1704. },
  1705. "getDesktop": function () {
  1706. return _form.app.desktop
  1707. },
  1708. "getData": function () {
  1709. return new MWF.xScript.JSONData(_form.getData());
  1710. },
  1711. //"save": function(callback){_form.saveWork(callback);},
  1712. /**关闭当前页面
  1713. * @method close
  1714. * @static
  1715. * @see module:form.close
  1716. */
  1717. "close": function () {
  1718. _form.closeWork();
  1719. },
  1720. "print": function (application, form) {
  1721. _form.printWork(application, form);
  1722. },
  1723. /**弹出一个确认框
  1724. * @method confirm
  1725. * @static
  1726. * @see module:form.confirm
  1727. */
  1728. "confirm": function (type, title, text, width, height, ok, cancel, callback, mask, style) {
  1729. // var p = MWF.getCenter({"x": width, "y": height});
  1730. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1731. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1732. if ((arguments.length <= 1) || o2.typeOf(arguments[1]) === "string") {
  1733. var p = MWF.getCenter({"x": width, "y": height});
  1734. e = {"event": {"clientX": p.x, "x": p.x, "clientY": p.y, "y": p.y}};
  1735. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1736. } else {
  1737. e = (arguments.length > 1) ? arguments[1] : null;
  1738. title = (arguments.length > 2) ? arguments[2] : null;
  1739. text = (arguments.length > 3) ? arguments[3] : null;
  1740. width = (arguments.length > 4) ? arguments[4] : null;
  1741. height = (arguments.length > 5) ? arguments[5] : null;
  1742. ok = (arguments.length > 6) ? arguments[6] : null;
  1743. cancel = (arguments.length > 7) ? arguments[7] : null;
  1744. callback = (arguments.length > 8) ? arguments[8] : null;
  1745. mask = (arguments.length > 9) ? arguments[9] : null;
  1746. style = (arguments.length > 10) ? arguments[10] : null;
  1747. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1748. }
  1749. },
  1750. /**显示一个带关闭按钮的信息框
  1751. * @method alert
  1752. * @static
  1753. * @see module:form.alert
  1754. */
  1755. "alert": function (type, title, text, width, height) {
  1756. _form.alert(type, title, text, width, height);
  1757. },
  1758. /**显示一个信息框
  1759. * @method notice
  1760. * @static
  1761. * @see module:form.notice
  1762. */
  1763. "notice": function (content, type, target, where, offset, option) {
  1764. _form.notice(content, type, target, where, offset, option);
  1765. },
  1766. /**打开一个对话框
  1767. * @method dialog
  1768. * @static
  1769. * @see module:form.dialog
  1770. */
  1771. "dialog": function ( options ) {
  1772. return _form.dialog( options );
  1773. },
  1774. /**打开人员组织选择界面
  1775. * @method selectOrg
  1776. * @static
  1777. * @see module:form.selectOrg
  1778. */
  1779. "selectOrg": function ( container, options, delayLoad) {
  1780. if( !container )container = _form.app.content;
  1781. return new MWF.O2Selector(container, options, delayLoad);
  1782. },
  1783. /**给页面添加事件。
  1784. * @method addEvent
  1785. * @static
  1786. * @see module:form.addEvent
  1787. */
  1788. "addEvent": function (e, f) {
  1789. _form.addEvent(e, f);
  1790. },
  1791. "openWindow": function (form, app) {
  1792. _form.openWindow(form, app);
  1793. },
  1794. /**打开一个在流转或已完成的流程实例
  1795. * @method openWork
  1796. * @static
  1797. * @see module:form.openWork
  1798. */
  1799. "openWork": function (id, completedId, title, options) {
  1800. var op = options || {};
  1801. op.workId = id;
  1802. op.workCompletedId = completedId;
  1803. op.docTitle = title;
  1804. op.appId = "process.Work" + (op.workId || op.workCompletedId);
  1805. return layout.desktop.openApplication(this.event, "process.Work", op);
  1806. },
  1807. /**使用流程的jobId打开工作
  1808. * @method openJob
  1809. * @static
  1810. * @see module:form.openJob
  1811. */
  1812. "openJob": function (id, choice, options, callback) {
  1813. var workData = null, handel;
  1814. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  1815. if (json.data) workData = json.data;
  1816. }.bind(this), null, false);
  1817. if( !layout.inBrowser && o2.typeOf(callback) === "function" ){
  1818. if( !options )options = {};
  1819. var queryLoad = options.onQueryLoad;
  1820. options.onQueryLoad = function () {
  1821. if( o2.typeOf(queryLoad) === "function" )queryLoad.call(this);
  1822. callback(this);
  1823. }
  1824. }
  1825. runCallback = function ( handel ) {
  1826. if( o2.typeOf(callback) === "function" ) {
  1827. if (layout.inBrowser) {
  1828. callback(handel);
  1829. } else if (options && options.appId) {
  1830. if (layout.desktop && layout.desktop.apps && layout.desktop.apps[options.appId]) {
  1831. callback(layout.desktop.apps[options.appId], true);
  1832. }else{
  1833. callback(handel, false);
  1834. }
  1835. }else{
  1836. callback(handel, false);
  1837. }
  1838. }
  1839. };
  1840. if (workData){
  1841. var len = workData.workList.length + workData.workCompletedList.length;
  1842. if (len){
  1843. if (len>1 && choice){
  1844. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  1845. workData.workList.each(function(work){
  1846. var workNode = new Element("div", {
  1847. "styles": {
  1848. "background": "#ffffff",
  1849. "border-radius": "10px",
  1850. "clear": "both",
  1851. "margin-bottom": "10px",
  1852. "height": "40px",
  1853. "padding": "10px 10px"
  1854. }
  1855. }).inject(node);
  1856. 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>" +
  1857. "<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>"+
  1858. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1859. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  1860. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  1861. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  1862. workNode.set("html", html);
  1863. var action = workNode.getElement(".MWFAction");
  1864. action.store("work", work);
  1865. action.addEvent("click", function(e){
  1866. var work = e.target.retrieve("work");
  1867. if (work){
  1868. handel = this.openWork(work.id, null, work.title, options);
  1869. runCallback( handel );
  1870. }
  1871. dlg.close();
  1872. }.bind(this));
  1873. }.bind(this));
  1874. workData.workCompletedList.each(function(work){
  1875. var workNode = new Element("div", {
  1876. "styles": {
  1877. "background": "#ffffff",
  1878. "border-radius": "10px",
  1879. "clear": "both",
  1880. "margin-bottom": "10px",
  1881. "height": "40px",
  1882. "padding": "10px 10px"
  1883. }
  1884. }).inject(node);
  1885. 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>" +
  1886. "<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>"+
  1887. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1888. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  1889. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  1890. workNode.set("html", html);
  1891. var action = workNode.getElement(".MWFAction");
  1892. action.store("work", work);
  1893. action.addEvent("click", function(e){
  1894. var work = e.target.retrieve("work");
  1895. if (work){
  1896. handel = this.openWork(null, work.id, work.title, options);
  1897. runCallback( handel );
  1898. }
  1899. dlg.close();
  1900. }.bind(this));
  1901. }.bind(this));
  1902. var height = node.getSize().y+20;
  1903. if (height>600) height = 600;
  1904. var dlg = o2.DL.open({
  1905. "title": o2.LP.widget.choiceWork,
  1906. "style" : "user",
  1907. "isResize": false,
  1908. "content": node,
  1909. "buttonList": [
  1910. {
  1911. "type" : "cancel",
  1912. "text": o2.LP.widget.close,
  1913. "action": function(){dlg.close();}
  1914. }
  1915. ]
  1916. });
  1917. }else{
  1918. if (workData.workList.length){
  1919. var work = workData.workList[0];
  1920. handel = this.openWork(work.id, null, work.title, options);
  1921. runCallback( handel );
  1922. return handel;
  1923. }else{
  1924. var work = workData.workCompletedList[0];
  1925. handel = this.openWork(null, work.id, work.title, options);
  1926. runCallback( handel );
  1927. return handel;
  1928. }
  1929. }
  1930. }else{
  1931. runCallback(new Error("Can't open this Job", {
  1932. cause: workData
  1933. }));
  1934. }
  1935. }else{
  1936. runCallback(new Error("Can't open this Job", {
  1937. cause: workData
  1938. }));
  1939. }
  1940. },
  1941. /**打开一个内容管理文档
  1942. * @method openDocument
  1943. * @static
  1944. * @see module:form.openDocument
  1945. */
  1946. "openDocument": function (id, title, options) {
  1947. var op = options || {};
  1948. op.documentId = id;
  1949. op.docTitle = title || "";
  1950. op.appId = (op.appId) || ("cms.Document"+id);
  1951. if( op.onPostPublish ){
  1952. op.postPublish = op.onPostPublish;
  1953. delete op.onPostPublish;
  1954. }
  1955. if( op.onAfterPublish ){
  1956. op.afterPublish = op.onAfterPublish;
  1957. delete op.onAfterPublish;
  1958. }
  1959. if( op.onAfterSave ){
  1960. op.afterSave = op.onAfterSave;
  1961. delete op.onAfterSave;
  1962. }
  1963. if( op.onBeforeClose ){
  1964. op.beforeClose = op.onBeforeClose;
  1965. delete op.onBeforeClose;
  1966. }
  1967. if( op.onPostDelete ){
  1968. op.postDelete = op.onPostDelete;
  1969. delete op.onPostDelete;
  1970. }
  1971. return layout.desktop.openApplication(this.event, "cms.Document", op);
  1972. },
  1973. /**打开一个门户页面
  1974. * @method openPortal
  1975. * @static
  1976. * @see module:form.openPortal
  1977. */
  1978. "openPortal": function (name, page, par) {
  1979. var action = MWF.Actions.get("x_portal_assemble_surface");
  1980. action.getApplication(name, function (json) {
  1981. if (json.data) {
  1982. if (page) {
  1983. action.getPageByName(page, json.data.id, function (pageJson) {
  1984. var pageId = (pageJson.data) ? pageJson.data.id : "";
  1985. layout.desktop.openApplication(null, "portal.Portal", {
  1986. "portalId": json.data.id,
  1987. "pageId": pageId,
  1988. "parameters": par,
  1989. "appId": (par && par.appId) || ("portal.Portal" + json.data.id + pageId)
  1990. })
  1991. });
  1992. } else {
  1993. layout.desktop.openApplication(null, "portal.Portal", {
  1994. "portalId": json.data.id,
  1995. "parameters": par,
  1996. "appId": (par && par.appId) || ("portal.Portal" + json.data.id)
  1997. })
  1998. }
  1999. }
  2000. });
  2001. },
  2002. /**打开一个内容管理栏目(应用)
  2003. * @method openCMS
  2004. * @static
  2005. * @see module:form.openCMS
  2006. */
  2007. "openCMS": function (name) {
  2008. var action = MWF.Actions.get("x_cms_assemble_control");
  2009. action.getColumn(name, function (json) {
  2010. if (json.data) {
  2011. layout.desktop.openApplication(null, "cms.Module", {
  2012. "columnId": json.data.id,
  2013. "appId": "cms.Module" + json.data.id
  2014. });
  2015. }
  2016. });
  2017. },
  2018. /**打开一个流程应用
  2019. * @method openProcess
  2020. * @static
  2021. * @see module:form.openProcess
  2022. */
  2023. "openProcess": function (name) {
  2024. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  2025. action.getApplication(name, function (json) {
  2026. if (json.data) {
  2027. layout.desktop.openApplication(null, "process.Application", {
  2028. "id": json.data.id,
  2029. "appId": "process.Application" + json.data.id
  2030. });
  2031. }
  2032. });
  2033. },
  2034. /**打开一个任意一个component应用
  2035. * @method openApplication
  2036. * @static
  2037. * @see module:form.openApplication
  2038. */
  2039. "openApplication": function (name, options, status) {
  2040. return layout.desktop.openApplication(null, name, options, status);
  2041. },
  2042. /**创建一个内容管理文档
  2043. * @method createDocument
  2044. * @static
  2045. * @see module:form.createDocument
  2046. */
  2047. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle, restrictToColumn) {
  2048. var column = columnOrOptions;
  2049. var onAfterPublish, onPostPublish;
  2050. if (typeOf(columnOrOptions) == "object") {
  2051. column = columnOrOptions.column;
  2052. category = columnOrOptions.category;
  2053. data = columnOrOptions.data;
  2054. identity = columnOrOptions.identity;
  2055. callback = columnOrOptions.callback;
  2056. target = columnOrOptions.target;
  2057. latest = columnOrOptions.latest;
  2058. selectColumnEnable = columnOrOptions.selectColumnEnable;
  2059. ignoreTitle = columnOrOptions.ignoreTitle;
  2060. restrictToColumn = columnOrOptions.restrictToColumn;
  2061. onAfterPublish = columnOrOptions.onAfterPublish;
  2062. onPostPublish = columnOrOptions.onPostPublish;
  2063. }
  2064. // 移动端 app相关的实现
  2065. if (layout.mobile) {
  2066. var options = {};
  2067. if (column) {
  2068. options["column"] = column
  2069. }
  2070. if (category) {
  2071. options["category"] = category
  2072. }
  2073. if (data) {
  2074. options["data"] = data
  2075. }
  2076. if (identity) {
  2077. options["identity"] = identity
  2078. }
  2079. if (typeof(latest) == 'undefined' || latest === null) {
  2080. options["latest"] = true
  2081. } else {
  2082. options["latest"] = latest
  2083. }
  2084. if (typeof(ignoreTitle) == 'undefined' || ignoreTitle === null) {
  2085. options["ignoreTitle"] = false
  2086. } else {
  2087. options["ignoreTitle"] = ignoreTitle
  2088. }
  2089. if (window.o2android && window.o2android.postMessage) {
  2090. var body = {
  2091. type: "createO2CmsDocument",
  2092. data: options
  2093. };
  2094. window.o2android.postMessage(JSON.stringify(body));
  2095. return;
  2096. } else if (window.o2android && window.o2android.createO2CmsDocument){
  2097. window.o2android.createO2CmsDocument(JSON.stringify(options));
  2098. return;
  2099. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.createO2CmsDocument) {
  2100. window.webkit.messageHandlers.createO2CmsDocument.postMessage(options);
  2101. return;
  2102. }
  2103. }
  2104. // 下面是pc端
  2105. if (target) {
  2106. if (layout.app && layout.app.inBrowser) {
  2107. layout.app.content.empty();
  2108. layout.app = null;
  2109. }
  2110. }
  2111. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  2112. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  2113. "documentData": data,
  2114. "identity": identity,
  2115. "ignoreTitle": ignoreTitle === true,
  2116. "ignoreDrafted": latest === false,
  2117. "selectColumnEnable": !category || selectColumnEnable === true,
  2118. "restrictToColumn": restrictToColumn === true || (!!category && selectColumnEnable !== true),
  2119. "categoryFlag": category, //category id or name
  2120. "columnFlag": column, //column id or name,
  2121. "onStarted": function (documentId, data, windowHandle) {
  2122. if (callback) callback(documentId, data, windowHandle);
  2123. },
  2124. "onPostPublish": function () {
  2125. if (onPostPublish) onPostPublish();
  2126. },
  2127. "onAfterPublish": function () {
  2128. if (onAfterPublish) onAfterPublish();
  2129. }
  2130. });
  2131. starter.load();
  2132. })
  2133. },
  2134. /**启动一个流程实例
  2135. * @method startProcess
  2136. * @static
  2137. * @see module:form.startProcess
  2138. */
  2139. "startProcess": function (app, process, data, identity, callback, target, latest, afterCreated, skipDraftCheck) {
  2140. if (arguments.length > 2) {
  2141. for (var i = 2; i < arguments.length; i++) {
  2142. if (typeOf(arguments[i]) == "boolean") {
  2143. target = arguments[i];
  2144. break;
  2145. }
  2146. }
  2147. }
  2148. if (target) {
  2149. if (layout.app && layout.app.inBrowser) {
  2150. //layout.app.content.empty();
  2151. layout.app.$openWithSelf = true;
  2152. }
  2153. }
  2154. if (!app || !process){
  2155. var cmpt = this.getApp();
  2156. o2.requireApp([["process.TaskCenter", "lp."+o2.language], ["process.TaskCenter", ""]],"", function(){
  2157. var obj = {
  2158. "lp": o2.xApplication.process.TaskCenter.LP,
  2159. "content": cmpt.content,
  2160. "addEvent": function(type, fun){
  2161. cmpt.addEvent(type, fun);
  2162. },
  2163. "getAction": function (callback) {
  2164. if (!this.action) {
  2165. this.action = o2.Actions.get("x_processplatform_assemble_surface");
  2166. if (callback) callback();
  2167. } else {
  2168. if (callback) callback();
  2169. }
  2170. },
  2171. "desktop": layout.desktop,
  2172. "refreshAll": function(){},
  2173. "notice": cmpt.notice,
  2174. }
  2175. o2.JSON.get("../x_component_process_TaskCenter/$Main/default/css.wcss", function(data){
  2176. obj.css = data;
  2177. }, false);
  2178. if (!cmpt.processStarter) cmpt.processStarter = new o2.xApplication.process.TaskCenter.Starter(obj);
  2179. cmpt.processStarter.load();
  2180. }, true, true);
  2181. return "";
  2182. }
  2183. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function (json) {
  2184. if (json.data) {
  2185. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function () {
  2186. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  2187. "workData": data,
  2188. "identity": identity,
  2189. "latest": latest,
  2190. "skipDraftCheck": skipDraftCheck,
  2191. "onStarted": function (data, title, processName) {
  2192. var application;
  2193. if (data.work) {
  2194. var work = data.work;
  2195. var options = {
  2196. "draft": work,
  2197. "draftData":data.data||{},
  2198. "appId": "process.Work" + (new o2.widget.UUID).toString(),
  2199. "desktopReload": false
  2200. };
  2201. if( !layout.inBrowser && afterCreated )options.onPostLoadForm = afterCreated;
  2202. application = layout.desktop.openApplication(null, "process.Work", options);
  2203. } else {
  2204. var currentTask = [];
  2205. data.each(function (work) {
  2206. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  2207. }.bind(this));
  2208. if (currentTask.length == 1) {
  2209. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  2210. if( !layout.inBrowser && afterCreated )options.onPostLoadForm = afterCreated;
  2211. application = layout.desktop.openApplication(null, "process.Work", options);
  2212. } else {
  2213. }
  2214. }
  2215. // var currentTask = [];
  2216. // data.each(function (work) {
  2217. // if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  2218. // }.bind(this));
  2219. //
  2220. // if (currentTask.length == 1) {
  2221. // var options = { "workId": currentTask[0], "appId": currentTask[0] };
  2222. // layout.desktop.openApplication(null, "process.Work", options);
  2223. // } else { }
  2224. if (callback) callback(data);
  2225. if(layout.inBrowser && afterCreated){
  2226. afterCreated(application)
  2227. }
  2228. }.bind(this)
  2229. });
  2230. starter.load();
  2231. }.bind(this));
  2232. }
  2233. });
  2234. },
  2235. /**
  2236. * 在打开的页面的任意脚本中,获取传入的参数。
  2237. * @member parameters
  2238. * @static
  2239. * @return {Boolean} 任意数据类型,根据传入的参数决定。
  2240. * @o2syntax
  2241. * var par = this.page.parameters
  2242. * @example
  2243. * //打开页面时传入参数:
  2244. * this.form.openPortal(id, "", {"type": "my type"});
  2245. *
  2246. * //在打开的页面的任意脚本中,可以获取parameters:
  2247. * var par = this.page.parameters;
  2248. * //par的内容:{"type": "my type"}
  2249. */
  2250. "parameters": _form.options.parameters,
  2251. /**
  2252. * 在嵌入部件的时候,可以在主页面上传入参数。通过本方法,可以在对应部件或者部件元素的脚本中获取传入的参数。
  2253. * @method getWidgetPrameters
  2254. * @static
  2255. * @return {Object} 任意数据类型,根据传入的参数决定。
  2256. * @o2syntax
  2257. * var par = this.page.getWidgetPrameters();
  2258. * @example
  2259. * //在主页面嵌入部件的地方传入参数:
  2260. * return {"type": "my type"};
  2261. *
  2262. * //在对应部件脚本中,可以获取parameters:
  2263. * var par = this.page.getWidgetPrameters();
  2264. * //par的内容:{"type": "my type"}
  2265. */
  2266. "getWidgetPrameters": function () {
  2267. if (!this.target) return null;
  2268. if (!this.target.widget) return null;
  2269. if (!this.widgetParameters) return null;
  2270. var pageId = this.target.widget.json.id;
  2271. return this.widgetParameters[pageId];
  2272. }.bind(this)
  2273. //"app": _form.app
  2274. };
  2275. this.form.currentRouteName = _form.json.currentRouteName;
  2276. this.form.opinion = _form.json.opinion;
  2277. this.target = ev.target;
  2278. this.event = ev.event;
  2279. this.status = ev.status;
  2280. this.session = layout.desktop.session;
  2281. this.Actions = o2.Actions;
  2282. this.query = function (option) {
  2283. // options = {
  2284. // "name": "statementName",
  2285. // "data": "json data",
  2286. // "firstResult": 1,
  2287. // "maxResults": 100,
  2288. // "success": function(){},
  2289. // "error": function(){},
  2290. // "async": true or false, default is true
  2291. // }
  2292. if (option) {
  2293. var json = (option.data) || {};
  2294. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  2295. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  2296. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  2297. }
  2298. };
  2299. this.Table = MWF.xScript.createTable();
  2300. };
  2301. }
  2302. if (!MWF.xScript.createTable) MWF.xScript.createTable = function(){
  2303. return function(name){
  2304. this.name = name;
  2305. this.action = o2.Actions.load("x_query_assemble_surface").TableAction;
  2306. this.listRowNext = function(id, count, success, error, async){
  2307. return this.action.listRowNext(this.name, id, count, success, error, async);
  2308. };
  2309. this.listRowPrev = function(id, count, success, error, async){
  2310. return this.action.listRowPrev(this.name, id, count, success, error, async);
  2311. };
  2312. this.listRowSelect = function(where, orderBy, size, success, error, async){
  2313. return this.action.listRowSelect(this.name, {"where": where, "orderBy": orderBy, "size": size || ""}, success, error, async);
  2314. };
  2315. this.listRowSelectWhere = function(where, success, error, async){
  2316. return this.action.listRowSelectWhere(this.name, where, success, error, async);
  2317. };
  2318. this.rowCountWhere = function(where, success, error, async){
  2319. return this.action.rowCountWhere(this.name, where, success, error, async);
  2320. };
  2321. this.deleteRow = function(id, success, error, async){
  2322. return this.action.rowDelete(this.name, id, success, error, async);
  2323. };
  2324. this.deleteAllRow = function(success, error, async){
  2325. return this.action.rowDeleteAll(this.name, success, error, async);
  2326. };
  2327. this.getRow = function(id, success, error, async){
  2328. return this.action.rowGet(this.name, id, success, error, async);
  2329. };
  2330. this.insertRow = function(data, success, error, async){
  2331. return this.action.rowInsert(this.name, data, success, error, async);
  2332. };
  2333. this.addRow = function(data, success, error, async){
  2334. return this.action.rowInsertOne(this.name, data, success, error, async);
  2335. };
  2336. this.updateRow = function(id, data, success, error, async){
  2337. return this.action.rowUpdate(this.name, id, data, success, error, async);
  2338. };
  2339. }
  2340. };
  2341. if (!MWF.xScript.JSONData) {
  2342. var getArrayJSONData = function (jData, p, _form) {
  2343. return new MWF.xScript.JSONData(jData, function (data, key, _self) {
  2344. var p = {
  2345. "getKey": function () {
  2346. return key;
  2347. }, "getParent": function () {
  2348. return _self;
  2349. }
  2350. };
  2351. while (p && !_form.forms[p.getKey()]) p = p.getParent();
  2352. //if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
  2353. var k = (p) ? p.getKey() : "";
  2354. if (k) if (_form.forms[k]) if (_form.forms[k].resetData) _form.forms[k].resetData();
  2355. //if(p) if(p.getKey()) if(_forms[p.getKey()]) if(_forms[p.getKey()].render) _forms[p.getKey()].render();
  2356. }, "", p, _form);
  2357. };
  2358. MWF.xScript.JSONData = function (data, callback, key, parent, _form) {
  2359. var getter = function (data, callback, k, _self) {
  2360. return function () {
  2361. var t = typeOf(data[k]);
  2362. if (["array", "object"].indexOf(t) === -1) {
  2363. return data[k]
  2364. } else {
  2365. if (t === "array") {
  2366. if (window.Proxy){
  2367. var arr = new Proxy(data[k], {
  2368. get: function(o, k){
  2369. return (o2.typeOf(o[k])==="object") ? getArrayJSONData(o[k], _self, _form) : o[k];
  2370. },
  2371. set: function(o, k, v){
  2372. o[k] = v;
  2373. if (callback) callback(o, k, _self);
  2374. return true;
  2375. }
  2376. });
  2377. return arr;
  2378. }else{
  2379. var arr =[];
  2380. data[k].forEach(function(d, i){
  2381. arr.push((o2.typeOf(d)==="object") ? getArrayJSONData(d, _self, _form) : d);
  2382. });
  2383. return arr;
  2384. }
  2385. } else {
  2386. return new MWF.xScript.JSONData(data[k], callback, k, _self, _form);
  2387. }
  2388. // var obj =
  2389. // if (t==="array") obj.constructor = Array;
  2390. // return obj;
  2391. }
  2392. //return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self, _form);
  2393. };
  2394. };
  2395. var setter = function (data, callback, k, _self) {
  2396. return function (v) {
  2397. data[k] = v;
  2398. //debugger;
  2399. //this.add(k, v, true);
  2400. if (callback) callback(data, k, _self);
  2401. }
  2402. };
  2403. var define = function () {
  2404. var o = {};
  2405. for (var k in data) o[k] = {
  2406. "configurable": true,
  2407. "enumerable": true,
  2408. "get": getter.apply(this, [data, callback, k, this]),
  2409. "set": setter.apply(this, [data, callback, k, this])
  2410. };
  2411. o["length"] = {
  2412. "get": function () {
  2413. return Object.keys(data).length;
  2414. }
  2415. };
  2416. o["some"] = {
  2417. "get": function () {
  2418. return data.some;
  2419. }
  2420. };
  2421. MWF.defineProperties(this, o);
  2422. var methods = {
  2423. "getKey": {
  2424. "value": function () {
  2425. return key;
  2426. }
  2427. },
  2428. "getParent": {
  2429. "value": function () {
  2430. return parent;
  2431. }
  2432. },
  2433. "toString": {
  2434. "value": function () {
  2435. return data.toString();
  2436. }
  2437. },
  2438. "setSection": {
  2439. "value": function (newKey, newValue) {
  2440. this.add(newKey, newValue, true);
  2441. try {
  2442. var path = [this.getKey()];
  2443. p = this.getParent();
  2444. while (p && p.getKey()) {
  2445. path.unshift(p.getKey());
  2446. p = p.getParent();
  2447. }
  2448. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  2449. } catch (e) {
  2450. }
  2451. }
  2452. },
  2453. "add": {
  2454. "value": function (newKey, newValue, overwrite, noreset) {
  2455. if( newKey.test(/^\d+$/) ){
  2456. throw new Error("Field name '"+newKey+"' cannot contain only numbers" );
  2457. }
  2458. if (arguments.length < 2 || newKey.indexOf("..") === -1) {
  2459. var flag = true;
  2460. var type = typeOf(data);
  2461. if (type === "array") {
  2462. if (arguments.length < 2) {
  2463. data.push(newKey);
  2464. newValue = newKey;
  2465. newKey = data.length - 1;
  2466. } else {
  2467. if (!newKey && newKey !== 0) {
  2468. data.push(newValue);
  2469. newKey = data.length - 1;
  2470. } else {
  2471. if (newKey >= data.length) {
  2472. data.push(newValue);
  2473. newKey = data.length - 1;
  2474. } else {
  2475. if (overwrite) data[newKey] = newValue;
  2476. newValue = data[newKey];
  2477. flag = false;
  2478. }
  2479. }
  2480. }
  2481. if (flag) {
  2482. var o = {};
  2483. o[newKey] = {
  2484. "configurable": true,
  2485. "enumerable": true,
  2486. "get": getter.apply(this, [data, callback, newKey, this]),
  2487. "set": setter.apply(this, [data, callback, newKey, this])
  2488. };
  2489. MWF.defineProperties(this, o);
  2490. }
  2491. if (!noreset) this[newKey] = newValue;
  2492. } else if (type === "object") {
  2493. if (!this.hasOwnProperty(newKey)) {
  2494. if (!data[newKey] || overwrite) {
  2495. data[newKey] = newValue;
  2496. }
  2497. newValue = data[newKey];
  2498. if (flag) {
  2499. var o = {};
  2500. o[newKey] = {
  2501. "configurable": true,
  2502. "enumerable": true,
  2503. "get": getter.apply(this, [data, callback, newKey, this]),
  2504. "set": setter.apply(this, [data, callback, newKey, this])
  2505. };
  2506. MWF.defineProperties(this, o);
  2507. }
  2508. if (!noreset) this[newKey] = newValue;
  2509. } else {
  2510. if (!Object.getOwnPropertyDescriptor(this, newKey).get){
  2511. var o = {};
  2512. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2513. MWF.defineProperties(this, o);
  2514. }
  2515. if (overwrite) {
  2516. data[newKey] = newValue;
  2517. if (!noreset) this[newKey] = newValue;
  2518. }
  2519. }
  2520. }
  2521. return this[newKey];
  2522. } else {
  2523. var keys = newKey.split("..");
  2524. var kk = keys.shift();
  2525. var d = this.add(kk, {}, false, true);
  2526. if (keys.length) return d.add(keys.join(".."), newValue, overwrite, noreset);
  2527. return d;
  2528. }
  2529. }
  2530. },
  2531. "check": {
  2532. "value": function (kk, v) {
  2533. var value = typeOf( v ) === "null" ? "" : v;
  2534. this.add(kk, value, false, true);
  2535. }
  2536. },
  2537. "del": {
  2538. "value": function (delKey) {
  2539. if (!this.hasOwnProperty(delKey)) return null;
  2540. // delete data[delKey];
  2541. // delete this[delKey];
  2542. data[delKey] = "";
  2543. this[delKey] = "";
  2544. return this;
  2545. }
  2546. }
  2547. };
  2548. MWF.defineProperties(this, methods);
  2549. //this.getKey = function(){ return key; };
  2550. //this.getParent = function(){ return parent; };
  2551. //this.toString = function() { return data.toString();};
  2552. //this.add = function(newKey, newValue, overwrite){
  2553. // var flag = true;
  2554. // var type = typeOf(data);
  2555. // if (!this.hasOwnProperty(newKey)){
  2556. // if (type=="array"){
  2557. // if (arguments.length<2){
  2558. // data.push(newKey);
  2559. // newValue = newKey;
  2560. // newKey = data.length-1;
  2561. // }else{
  2562. // debugger;
  2563. // if (!newKey && newKey!=0){
  2564. // data.push(newValue);
  2565. // newKey = data.length-1;
  2566. // }else{
  2567. // flag == false;
  2568. // }
  2569. // }
  2570. // }else{
  2571. // data[newKey] = newValue;
  2572. // }
  2573. // //var valueType = typeOf(newValue);
  2574. // //var newValueData = newValue;
  2575. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  2576. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  2577. // if (flag){
  2578. // var o = {};
  2579. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2580. // MWF.defineProperties(this, o);
  2581. // }
  2582. // this[newKey] = newValue;
  2583. // }else{
  2584. // if (overwrite) this[newKey] = newValue;
  2585. // }
  2586. //
  2587. // //var valueType = typeOf(newValue);
  2588. // //var newValueData = newValue;
  2589. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  2590. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  2591. // //
  2592. // //this[newKey] = newValueData;
  2593. //
  2594. // return this[newKey];
  2595. //};
  2596. //this.del = function(delKey){
  2597. // if (!this.hasOwnProperty(delKey)) return null;
  2598. // delete data[newKey];
  2599. // delete this[newKey];
  2600. // return this;
  2601. //};
  2602. };
  2603. var type = typeOf(data);
  2604. if (type === "object" || type === "array") define.apply(this);
  2605. };
  2606. }
  2607. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  2608. if (!MWF.xScript.createDict) {
  2609. MWF.xScript.addDictToCache = function (options, path, json) {
  2610. if (!path) path = "root";
  2611. if (path.indexOf("root") !== 0) path = "root." + path;
  2612. var type = options.appType || "process";
  2613. var enableAnonymous = ( options.enableAnonymous || options.anonymous ) || false;
  2614. var appFlagList = [];
  2615. if (options.application) appFlagList.push(options.application);
  2616. if (options.appId) appFlagList.push(options.appId);
  2617. if (options.appName) appFlagList.push(options.appName);
  2618. if (options.appAlias) appFlagList.push(options.appAlias);
  2619. var dictFlagList = [];
  2620. if (options.id) dictFlagList.push(options.id);
  2621. if (options.name) dictFlagList.push(options.name);
  2622. if (options.alias) dictFlagList.push(options.alias);
  2623. var cache = {};
  2624. cache[path] = json;
  2625. for (var i = 0; i < appFlagList.length; i++) {
  2626. for (var j = 0; j < dictFlagList.length; j++) {
  2627. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  2628. if (!MWF.xScript.dictLoaded[k]) {
  2629. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  2630. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  2631. } else if (i === 0 && j === 0) {
  2632. MWF.xScript.setDictToCache(k, path, json);
  2633. var arr = path.split(/\./g);
  2634. var p;
  2635. var cache = MWF.xScript.dictLoaded[k];
  2636. for (var l = 0; l < arr.length; l++) {
  2637. p = l === 0 ? arr[0] : (p + "." + arr[l]);
  2638. if (cache[p]) break;
  2639. }
  2640. if (p) {
  2641. var mathP = p + ".";
  2642. Object.keys(cache).each(function (path, idx) {
  2643. if (path.indexOf(mathP) === 0) delete cache[path];
  2644. })
  2645. }
  2646. }
  2647. }
  2648. }
  2649. };
  2650. MWF.xScript.getMatchedDict = function (key, path) {
  2651. if (!path) path = "root";
  2652. if (path.indexOf("root") !== 0) path = "root." + path;
  2653. var arr = path.split(/\./g);
  2654. if (MWF.xScript.dictLoaded[key]) {
  2655. var dicts = MWF.xScript.dictLoaded[key];
  2656. var list = Array.clone(arr);
  2657. var p;
  2658. var dict;
  2659. for (var i = 0; i < arr.length; i++) {
  2660. p = i === 0 ? arr[0] : (p + "." + arr[i]);
  2661. list.shift();
  2662. if (dicts[p]) {
  2663. dict = dicts[p];
  2664. break;
  2665. }
  2666. }
  2667. return {
  2668. dict: dict,
  2669. unmatchedPathList: list
  2670. }
  2671. }
  2672. return {
  2673. dict: null,
  2674. unmatchedPathList: list
  2675. }
  2676. };
  2677. MWF.xScript.insertDictToCache = function (key, path, json) {
  2678. var p = path;
  2679. if( !p )p = "root";
  2680. if( p.indexOf("root") !== 0 )p = "root." + p ;
  2681. if (MWF.xScript.dictLoaded[key]) {
  2682. var matchedDict = MWF.xScript.getMatchedDict(key, path);
  2683. var dict = matchedDict.dict;
  2684. var list = matchedDict.unmatchedPathList;
  2685. if (!dict) {
  2686. MWF.xScript.dictLoaded[key][p] = json;
  2687. }else if( !list || list.length === 0 ){
  2688. MWF.xScript.dictLoaded[key][p] = json;
  2689. } else {
  2690. for (var j = 0; j < list.length - 1; j++) {
  2691. if (!dict[list[j]]) {
  2692. dict[list[j]] = {};
  2693. }
  2694. dict = dict[list[j]];
  2695. }
  2696. var lastPath = list[list.length - 1];
  2697. if (!dict[lastPath]) {
  2698. dict[lastPath] = json;
  2699. } else if (typeOf(dict[lastPath]) === "array") {
  2700. dict[lastPath].push(json);
  2701. }
  2702. }
  2703. } else {
  2704. MWF.xScript.dictLoaded[key] = {};
  2705. MWF.xScript.dictLoaded[key][p] = json;
  2706. }
  2707. };
  2708. MWF.xScript.setDictToCache = function (key, path, json) {
  2709. var p = path;
  2710. if( !p )p = "root";
  2711. if( p.indexOf("root") !== 0 )p = "root." + p ;
  2712. if (MWF.xScript.dictLoaded[key]) {
  2713. var matchedDict = MWF.xScript.getMatchedDict(key, path);
  2714. var dict = matchedDict.dict;
  2715. var list = matchedDict.unmatchedPathList;
  2716. if (!dict) {
  2717. MWF.xScript.dictLoaded[key][p] = json;
  2718. }else if( !list || list.length === 0 ){
  2719. MWF.xScript.dictLoaded[key][p] = json;
  2720. } else {
  2721. for (var j = 0; j < list.length - 1; j++) {
  2722. if (!dict[list[j]]) {
  2723. dict[list[j]] = {};
  2724. }
  2725. dict = dict[list[j]];
  2726. }
  2727. dict[list[list.length - 1]] = json;
  2728. }
  2729. } else {
  2730. MWF.xScript.dictLoaded[key] = {};
  2731. MWF.xScript.dictLoaded[key][p] = json;
  2732. }
  2733. };
  2734. MWF.xScript.getDictFromCache = function (key, path) {
  2735. var matchedDict = MWF.xScript.getMatchedDict(key, path);
  2736. var dict = matchedDict.dict;
  2737. var list = matchedDict.unmatchedPathList;
  2738. if (dict) {
  2739. for (var j = 0; j < list.length; j++) {
  2740. dict = dict[list[j]];
  2741. if (!dict) return null;
  2742. }
  2743. return dict;
  2744. }
  2745. return null;
  2746. };
  2747. MWF.xScript.deleteDictToCache = function (key, path) {
  2748. var matchedDict = MWF.xScript.getMatchedDict(key, path);
  2749. var dict = matchedDict.dict;
  2750. var list = matchedDict.unmatchedPathList;
  2751. if (dict) {
  2752. for (var j = 0; j < list.length - 1; j++) {
  2753. dict = dict[list[j]];
  2754. if (!dict) return;
  2755. }
  2756. if( list.length ){
  2757. delete dict[list[list.length - 1]];
  2758. }
  2759. }
  2760. };
  2761. MWF.xScript.createDict = function (application, appType) {
  2762. //optionsOrName : {
  2763. // type : "", //默认为process, 可以为 process cms
  2764. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  2765. // name : "", // 数据字典名称/别名/id
  2766. // anonymous : false //允许在未登录的情况下读取CMS的数据字典, 该参数名也可以是 enableAnonymous
  2767. //}
  2768. //或者name: "" // 数据字典名称/别名/id
  2769. return function (optionsOrName) {
  2770. var options = optionsOrName;
  2771. if (typeOf(options) == "string") {
  2772. options = {
  2773. name: options,
  2774. type: appType,
  2775. application: application
  2776. };
  2777. }
  2778. var name = this.name = options.name;
  2779. var type;
  2780. if( options.type === "service"){
  2781. type = options.type;
  2782. }else{
  2783. type = ( options.type && options.application ) ? options.type : "process";
  2784. }
  2785. var applicationId = options.application || application;
  2786. var enableAnonymous = ( options.enableAnonymous || options.anonymous ) || false;
  2787. var opt = {
  2788. "appType": type,
  2789. "name": name,
  2790. "appId": applicationId,
  2791. "enableAnonymous": enableAnonymous
  2792. };
  2793. var key = name + type + applicationId + enableAnonymous;
  2794. // if (!dictLoaded[key]) dictLoaded[key] = {};
  2795. // this.dictData = dictLoaded[key];
  2796. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  2797. var action;
  2798. if (type === "cms") {
  2799. action = MWF.Actions.get("x_cms_assemble_control");
  2800. } else if( type === "portal" ){
  2801. action = MWF.Actions.get("x_portal_assemble_surface");
  2802. }else if( type === "service" ){
  2803. key = name+type+enableAnonymous;
  2804. action = MWF.Actions.get("x_program_center");
  2805. } else {
  2806. action = MWF.Actions.get("x_processplatform_assemble_surface");
  2807. }
  2808. var encodePath = function (path) {
  2809. var arr = path.split(/\./g);
  2810. var ar = arr.map(function (v) {
  2811. return encodeURIComponent(v);
  2812. });
  2813. return ( type === "portal" || type === "service" ) ? ar.join(".") : ar.join("/");
  2814. };
  2815. this.get = function (path, success, failure, async, refresh) {
  2816. var value = null;
  2817. if (success === true) async = true;
  2818. if (failure === true) async = true;
  2819. if (!refresh) {
  2820. var data = MWF.xScript.getDictFromCache(key, path);
  2821. if (data) {
  2822. if (success && o2.typeOf(success) == "function") success(data);
  2823. if (!!async) {
  2824. return Promise.resolve(data);
  2825. } else {
  2826. return data;
  2827. }
  2828. }
  2829. }
  2830. // var cb = function(json){
  2831. // value = json.data;
  2832. // MWF.xScript.addDictToCache(opt, path, value);
  2833. // if (success && o2.typeOf(success)=="function") value = success(json.data);
  2834. // return value;
  2835. // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
  2836. var cb = function (json) {
  2837. value = json.data;
  2838. MWF.xScript.addDictToCache(opt, path, value);
  2839. if (success && o2.typeOf(success) == "function") value = success(json.data);
  2840. return value;
  2841. };
  2842. var promise;
  2843. if( type === "service" ){
  2844. if (path){
  2845. var p = encodePath( path );
  2846. promise = action.getDictData(encodeURIComponent(this.name), p, cb, null, !!async, false);
  2847. }else{
  2848. promise = action.getDictRoot(this.name, cb, null, !!async, false);
  2849. }
  2850. }else{
  2851. if (path) {
  2852. var p = encodePath(path);
  2853. promise = action[((enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData")](encodeURIComponent(this.name), applicationId, p, cb, null, !!async, false);
  2854. } else {
  2855. promise = action[((enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot")](this.name, applicationId, cb, null, !!async, false);
  2856. }
  2857. }
  2858. return (!!async) ? promise : value;
  2859. // if (path){
  2860. // var p = encodePath( path );
  2861. // //var p = path.replace(/\./g, "/");
  2862. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  2863. // value = json.data;
  2864. // // this.dictData[path] = value;
  2865. // MWF.xScript.addDictToCache(opt, path, value);
  2866. // if (success) success(json.data);
  2867. // }.bind(this), function(xhr, text, error){
  2868. // if (failure) failure(xhr, text, error);
  2869. // }, !!async);
  2870. // }else{
  2871. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  2872. // value = json.data;
  2873. // // this.dictData["root"] = value;
  2874. // MWF.xScript.addDictToCache(opt, path, value);
  2875. // if (success) success(json.data);
  2876. // }.bind(this), function(xhr, text, error){
  2877. // if (failure) failure(xhr, text, error);
  2878. // }, !!async);
  2879. // }
  2880. //return value;
  2881. };
  2882. this.set = function (path, value, success, failure) {
  2883. var p = encodePath(path);
  2884. //var p = path.replace(/\./g, "/");
  2885. var successCallback = function(json){
  2886. MWF.xScript.setDictToCache(key, path, value);
  2887. if (success) return success(json.data);
  2888. };
  2889. var failureCallback = function(xhr, text, error){
  2890. if (failure) return failure(xhr, text, error);
  2891. };
  2892. if( type === "service" ){
  2893. return action.setDictData(encodeURIComponent(this.name), p, value, successCallback, failureCallback, false, false);
  2894. }else{
  2895. return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, successCallback, failureCallback, false, false);
  2896. }
  2897. };
  2898. this.add = function (path, value, success, failure) {
  2899. var p = encodePath(path);
  2900. //var p = path.replace(/\./g, "/");
  2901. var successCallback = function(json){
  2902. MWF.xScript.insertDictToCache(key, path, value);
  2903. if (success) return success(json.data);
  2904. };
  2905. var failureCallback = function(xhr, text, error){
  2906. if (failure) return failure(xhr, text, error);
  2907. };
  2908. if( type === "service" ) {
  2909. return action.addDictData(encodeURIComponent(this.name), p, value, successCallback, failureCallback, false, false);
  2910. }else{
  2911. return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, successCallback, failureCallback, false, false);
  2912. }
  2913. };
  2914. this["delete"] = function (path, success, failure) {
  2915. var p = encodePath(path);
  2916. //var p = path.replace(/\./g, "/");
  2917. var successCallback = function(json){
  2918. MWF.xScript.deleteDictToCache(key, path);
  2919. if (success) return success(json.data);
  2920. };
  2921. var failureCallback = function(xhr, text, error){
  2922. if (failure) return failure(xhr, text, error);
  2923. };
  2924. if( type === "service" ) {
  2925. return action.deleteDictData(encodeURIComponent(this.name), p, successCallback, failureCallback, false, false);
  2926. }else{
  2927. return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, successCallback, failureCallback, false, false);
  2928. }
  2929. };
  2930. this.destory = this["delete"];
  2931. }
  2932. };
  2933. }