PageEnvironment.js 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.xScript.PageEnvironment = function (ev) {
  3. var _data = ev.data;
  4. var _form = ev.form;
  5. var _forms = ev.forms;
  6. this.library = COMMON;
  7. //this.library.version = "4.0";
  8. //data
  9. var getJSONData = function (jData) {
  10. return new MWF.xScript.JSONData(jData, function (data, key, _self) {
  11. var p = { "getKey": function () { return key; }, "getParent": function () { return _self; } };
  12. while (p && !_forms[p.getKey()]) p = p.getParent();
  13. if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
  14. });
  15. };
  16. this.setData = function (data) {
  17. this.data = getJSONData(data);
  18. this.data.save = function (callback) {
  19. var formData = {
  20. "data": data,
  21. "sectionList": _form.getSectionList()
  22. };
  23. form.workAction.saveData(function (json) { if (callback) callback(); }.bind(this), null, work.id, jData);
  24. }
  25. };
  26. this.setData(_data);
  27. //workContext
  28. this.workContext = {
  29. "getTask": function () { return ev.task; },
  30. "getWork": function () { return ev.work || ev.workCompleted; },
  31. "getActivity": function () { return ev.activity; },
  32. "getTaskList": function () { return ev.taskList; },
  33. "getControl": function () { return ev.control; },
  34. "getWorkLogList": function () { return ev.workLogList; },
  35. "getAttachmentList": function () { return ev.attachmentList; },
  36. "getRouteList": function () { return (ev.task) ? ev.task.routeNameList : null; },
  37. "getInquiredRouteList": function () { return null; },
  38. "setTitle": function (title) {
  39. //if (!this.workAction){
  40. // MWF.require("MWF.xScript.Actions.WorkActions", null, false);
  41. // this.workAction = new MWF.xScript.Actions.WorkActions();
  42. //}
  43. //this.workAction.setTitle(ev.work.id, {"title": title});
  44. }
  45. };
  46. var _redefineWorkProperties = function (work) {
  47. if (work) {
  48. work.creatorPersonDn = work.creatorPerson;
  49. work.creatorUnitDn = work.creatorUnit;
  50. work.creatorUnitDnList = work.creatorUnitList;
  51. work.creatorIdentityDn = work.creatorIdentity;
  52. var o = {
  53. "creatorPerson": { "get": function () { return this.creatorPersonDn.substring(0, this.creatorPersonDn.indexOf("@")); } },
  54. "creatorUnit": { "get": function () { return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@")); } },
  55. "creatorDepartment": { "get": function () { return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@")); } },
  56. "creatorIdentity": { "get": function () { return this.creatorIdentityDn.substring(0, this.creatorIdentityDn.indexOf("@")); } },
  57. "creatorUnitList": {
  58. "get": function () {
  59. var v = [];
  60. this.creatorUnitDnList.each(function (dn) {
  61. v.push(dn.substring(0, dn.indexOf("@")))
  62. });
  63. return v;
  64. }
  65. },
  66. "creatorCompany": { "get": function () { return this.creatorUnitList[0] } }
  67. };
  68. MWF.defineProperties(work, o);
  69. }
  70. return work;
  71. };
  72. var _redefineTaskProperties = function (task) {
  73. if (task) {
  74. task.personDn = task.person;
  75. task.unitDn = task.unit;
  76. task.unitDnList = task.unitList;
  77. task.identityDn = task.identity;
  78. var o = {
  79. "person": { "get": function () { return this.personDn.substring(0, this.personDn.indexOf("@")); } },
  80. "unit": { "get": function () { return this.unitDn.substring(0, this.unitDn.indexOf("@")); } },
  81. "department": { "get": function () { return this.unitDn.substring(0, this.unitDn.indexOf("@")); } },
  82. "identity": { "get": function () { return this.identityDn.substring(0, this.identityDn.indexOf("@")); } },
  83. "unitList": {
  84. "get": function () {
  85. var v = [];
  86. this.unitDnList.each(function (dn) {
  87. v.push(dn.substring(0, dn.indexOf("@")))
  88. });
  89. return v;
  90. }
  91. },
  92. "company": { "get": function () { return this.unitList[0]; } }
  93. };
  94. MWF.defineProperties(task, o);
  95. }
  96. return task;
  97. };
  98. _redefineWorkProperties(this.workContext.getWork());
  99. _redefineTaskProperties(_redefineWorkProperties(this.workContext.getTask()));
  100. //dict
  101. this.Dict = MWF.xScript.createDict(_form.json.application);
  102. //org
  103. var orgActions = null;
  104. var getOrgActions = function () {
  105. if (!orgActions) {
  106. MWF.require("MWF.xScript.Actions.UnitActions", null, false);
  107. orgActions = new MWF.xScript.Actions.UnitActions();
  108. }
  109. };
  110. var getNameFlag = function (name) {
  111. var t = typeOf(name);
  112. if (t === "array") {
  113. var v = [];
  114. name.each(function (id) {
  115. v.push((typeOf(id) === "object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  116. });
  117. return v;
  118. } else {
  119. return [(t === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  120. }
  121. };
  122. this.org = {
  123. //群组***************
  124. //获取群组--返回群组的对象数组
  125. getGroup: function(name, async){
  126. getOrgActions();
  127. var data = {"groupList": getNameFlag(name)};
  128. var v = null;
  129. var cb = function(json){
  130. v = json.data;
  131. v = (v && v.length===1) ? v[0] : v
  132. return v;
  133. }.ag().catch(function(json){ return v; });
  134. orgActions.listGroup(data, cb, null, !!async);
  135. return (!!async) ? cb : v;
  136. // var v = null;
  137. // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  138. // return (v && v.length===1) ? v[0] : v;
  139. },
  140. //查询下级群组--返回群组的对象数组
  141. //nested 布尔 true嵌套下级;false直接下级;默认false;
  142. listSubGroup: function(name, nested, async){
  143. getOrgActions();
  144. var data = {"groupList": getNameFlag(name)};
  145. var v = null;
  146. var cb = function(json){
  147. v = json.data;
  148. return v;
  149. }.ag().catch(function(json){ return v; });
  150. if (nested){
  151. orgActions.listSubGroupNested(data, cb, null, !!async);
  152. }else{
  153. orgActions.listSubGroupDirect(data, cb, null, !!async);
  154. }
  155. return (!!async) ? cb : v;
  156. // var v = null;
  157. // if (nested){
  158. // orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  159. // }else{
  160. // orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  161. // }
  162. // return v;
  163. },
  164. //查询上级群组--返回群组的对象数组
  165. //nested 布尔 true嵌套上级;false直接上级;默认false;
  166. listSupGroup:function(name, nested, async){
  167. getOrgActions();
  168. var data = {"groupList": getNameFlag(name)};
  169. var v = null;
  170. var cb = function(json){
  171. v = json.data;
  172. return v;
  173. }.ag().catch(function(json){ return v; });
  174. if (nested){
  175. orgActions.listSupGroupNested(data, cb, null, !!async);
  176. }else{
  177. orgActions.listSupGroupDirect(data, cb, null, !!async);
  178. }
  179. return (!!async) ? cb : v;
  180. // var v = null;
  181. // if (nested){
  182. // orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  183. // }else{
  184. // orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  185. // }
  186. // return v;
  187. },
  188. //人员所在群组(嵌套)--返回群组的对象数组
  189. listGroupWithPerson:function(name, async){
  190. getOrgActions();
  191. var data = {"personList": getNameFlag(name)};
  192. var v = null;
  193. var cb = function(json){
  194. v = json.data;
  195. return v;
  196. }.ag().catch(function(json){ return v; });
  197. orgActions.listGroupWithPerson(data, cb, null, !!async);
  198. return (!!async) ? cb : v;
  199. // var v = null;
  200. // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  201. // return v;
  202. },
  203. //群组是否拥有角色--返回true, false
  204. groupHasRole: function(name, role, async){
  205. getOrgActions();
  206. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  207. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  208. var v = false;
  209. var cb = function(json){
  210. v = json.data.value;
  211. return v;
  212. }.ag().catch(function(json){ return v; });
  213. orgActions.groupHasRole(data, cb, null, !!async);
  214. return (!!async) ? cb : v;
  215. // var v = false;
  216. // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  217. // return v;
  218. },
  219. //角色***************
  220. //获取角色--返回角色的对象数组
  221. getRole: function(name, async){
  222. getOrgActions();
  223. var data = {"roleList": getNameFlag(name)};
  224. var v = null;
  225. var cb = function(json){
  226. v = json.data;
  227. v = (v && v.length===1) ? v[0] : v;
  228. return v;
  229. }.ag().catch(function(json){ return v; });
  230. orgActions.listRole(data, cb, null, !!async);
  231. return (!!async) ? cb : v;
  232. // var v = null;
  233. // orgActions.listRole(data, function(json){v = json.data;}, null, false);
  234. // return (v && v.length===1) ? v[0] : v;
  235. },
  236. //人员所有角色(嵌套)--返回角色的对象数组
  237. listRoleWithPerson:function(name, async){
  238. getOrgActions();
  239. var data = {"personList": getNameFlag(name)};
  240. var v = null;
  241. var cb = function(json){
  242. v = json.data;
  243. return v;
  244. }.ag().catch(function(json){ return v; });
  245. orgActions.listRoleWithPerson(data, cb, null, !!async);
  246. return (!!async) ? cb : v;
  247. // var v = null;
  248. // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  249. // return v;
  250. },
  251. //人员***************
  252. //人员是否拥有角色--返回true, false
  253. personHasRole: function(name, role, async){
  254. getOrgActions();
  255. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  256. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  257. var v = false;
  258. var cb = function(json){
  259. v = json.data.value;
  260. return v;
  261. }.ag().catch(function(json){ return v; });
  262. orgActions.listRoleWithPerson(data, cb, null, !!async);
  263. return (!!async) ? cb : v;
  264. // var v = false;
  265. // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  266. // return v;
  267. },
  268. //获取人员--返回人员的对象数组
  269. getPerson: function(name, async){
  270. getOrgActions();
  271. var data = {"personList": getNameFlag(name)};
  272. var v = null;
  273. var cb = function(json){
  274. v = json.data;
  275. v = (v && v.length===1) ? v[0] : v;
  276. return v;
  277. }.ag().catch(function(json){ return v; });
  278. orgActions.listPerson(data, cb, null, !!async);
  279. return (!!async) ? cb : v;
  280. // var v = null;
  281. // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  282. // return (v && v.length===1) ? v[0] : v;
  283. },
  284. //查询下级人员--返回人员的对象数组
  285. //nested 布尔 true嵌套下级;false直接下级;默认false;
  286. listSubPerson: function(name, nested, async){
  287. getOrgActions();
  288. var data = {"personList": getNameFlag(name)};
  289. var v = null;
  290. var cb = function(json){
  291. v = json.data;
  292. return v;
  293. }.ag().catch(function(json){ return v; });
  294. if (nested){
  295. orgActions.listPersonSubNested(data, cb, null, !!async);
  296. }else{
  297. orgActions.listPersonSubDirect(data, cb, null, !!async);
  298. }
  299. return (!!async) ? cb : v;
  300. },
  301. //查询上级人员--返回人员的对象数组
  302. //nested 布尔 true嵌套上级;false直接上级;默认false;
  303. listSupPerson: function(name, nested, async){
  304. getOrgActions();
  305. var data = {"personList": getNameFlag(name)};
  306. var v = null;
  307. var cb = function(json){
  308. v = json.data;
  309. return v;
  310. }.ag().catch(function(json){ return v; });
  311. if (nested){
  312. orgActions.listPersonSupNested(data, cb, null, !!async);
  313. }else{
  314. orgActions.listPersonSupDirect(data, cb, null, !!async);
  315. }
  316. return (!!async) ? cb : v;
  317. },
  318. //获取群组的所有人员--返回人员的对象数组
  319. listPersonWithGroup: function(name, async){
  320. getOrgActions();
  321. var data = {"groupList": getNameFlag(name)};
  322. var v = null;
  323. var cb = function(json){
  324. v = json.data;
  325. return v;
  326. }.ag().catch(function(json){ return v; });
  327. orgActions.listPersonWithGroup(data, cb, null, !!async);
  328. return (!!async) ? cb : v;
  329. },
  330. //获取角色的所有人员--返回人员的对象数组
  331. listPersonWithRole: function(name, async){
  332. getOrgActions();
  333. var data = {"roleList": getNameFlag(name)};
  334. var v = null;
  335. var cb = function(json){
  336. v = json.data;
  337. return v;
  338. }.ag().catch(function(json){ return v; });
  339. orgActions.listPersonWithRole(data, cb, null, !!async);
  340. return (!!async) ? cb : v;
  341. },
  342. //获取身份的所有人员--返回人员的对象数组
  343. listPersonWithIdentity: function(name, async){
  344. getOrgActions();
  345. var data = {"identityList": getNameFlag(name)};
  346. var v = null;
  347. var cb = function(json){
  348. v = json.data;
  349. return v;
  350. }.ag().catch(function(json){ return v; });
  351. orgActions.listPersonWithIdentity(data, cb, null, !!async);
  352. return (!!async) ? cb : v;
  353. },
  354. //获取身份的所有人员--返回人员的对象数组或人员对象
  355. getPersonWithIdentity: function(name, async){
  356. getOrgActions();
  357. var data = {"identityList": getNameFlag(name)};
  358. var v = null;
  359. var cb = function(json){
  360. v = json.data;
  361. v = (v && v.length===1) ? v[0] : v;
  362. return v;
  363. }.ag().catch(function(json){ return v; });
  364. orgActions.listPersonWithIdentity(data, cb, null, !!async);
  365. return (!!async) ? cb : v;
  366. },
  367. //查询组织成员的人员--返回人员的对象数组
  368. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  369. listPersonWithUnit: function(name, nested, async){
  370. getOrgActions();
  371. var data = {"unitList": getNameFlag(name)};
  372. var v = null;
  373. var cb = function(json){
  374. v = json.data;
  375. return v;
  376. }.ag().catch(function(json){ return v; });
  377. if (nested){
  378. orgActions.listPersonWithUnitNested(data, cb, null, !!async);
  379. }else{
  380. orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
  381. }
  382. return (!!async) ? cb : v;
  383. },
  384. //根据属性查询人员--返回人员的对象数组
  385. //name string 属性名
  386. //value string 属性值
  387. listPersonWithAttribute: function(name, value, async){
  388. getOrgActions();
  389. var data = {"name": name, "attribute": value};
  390. var v = null;
  391. var cb = function(json){
  392. v = json.data;
  393. return v;
  394. }.ag().catch(function(json){ return v; });
  395. orgActions.listPersonWithAttribute(data, cb, null, !!async);
  396. return (!!async) ? cb : v;
  397. },
  398. //根据属性查询人员--返回人员的全称数组
  399. //name string 属性名
  400. //value string 属性值
  401. listPersonNameWithAttribute: function(name, value, async){
  402. getOrgActions();
  403. var data = {"name": name, "attribute": value};
  404. var v = null;
  405. var cb = function(json){
  406. v = json.data.personList;
  407. return v;
  408. }.ag().catch(function(json){ return v; });
  409. orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
  410. return (!!async) ? cb : v;
  411. },
  412. //人员属性************
  413. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  414. appendPersonAttribute: function(person, attr, values, success, failure, async){
  415. getOrgActions();
  416. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  417. var data = {"attributeList":values,"name":attr,"person":personFlag};
  418. var cb = function(json){
  419. if (success) return success(json);
  420. }.ag().catch(function(xhr, text, error){
  421. if (failure) return failure(xhr, text, error);
  422. });
  423. orgActions.appendPersonAttribute(data, cb, null, !!async);
  424. },
  425. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  426. setPersonAttribute: function(person, attr, values, success, failure, async){
  427. getOrgActions();
  428. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  429. var data = {"attributeList":values,"name":attr,"person":personFlag};
  430. var cb = function(json){
  431. if (success) return success(json);
  432. }.ag().catch(function(xhr, text, error){
  433. if (failure) return failure(xhr, text, error);
  434. });
  435. orgActions.setPersonAttribute(data, cb, null, !!async);
  436. },
  437. //获取人员属性值
  438. getPersonAttribute: function(person, attr, async){
  439. getOrgActions();
  440. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  441. var data = {"name":attr,"person":personFlag};
  442. var v = null;
  443. var cb = function(json){
  444. v = json.data.attributeList;
  445. return v;
  446. }.ag().catch(function(json){ return v; });
  447. orgActions.getPersonAttribute(data, cb, null, !!async);
  448. return (!!async) ? cb : v;
  449. },
  450. //列出人员所有属性的名称
  451. listPersonAttributeName: function(name, async){
  452. getOrgActions();
  453. var data = {"personList":getNameFlag(name)};
  454. var v = null;
  455. var cb = function(json){
  456. v = json.data.nameList;
  457. return v;
  458. }.ag().catch(function(json){ return v; });
  459. orgActions.listPersonAttributeName(data, cb, null, !!async);
  460. return (!!async) ? cb : v;
  461. },
  462. //列出人员的所有属性
  463. listPersonAllAttribute: function(name, async){
  464. getOrgActions();
  465. var data = {"personList":getNameFlag(name)};
  466. var v = null;
  467. var cb = function(json){
  468. v = json.data;
  469. return v;
  470. }.ag().catch(function(json){ return v; });
  471. orgActions.listPersonAllAttribute(data, cb, null, !!async);
  472. return (!!async) ? cb : v;
  473. },
  474. //身份**********
  475. //获取身份
  476. getIdentity: 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. return v;
  484. }.ag().catch(function(json){ return v; });
  485. orgActions.listIdentity(data, cb, null, !!async);
  486. return (!!async) ? cb : v;
  487. },
  488. //列出人员的身份
  489. listIdentityWithPerson: function(name, async){
  490. getOrgActions();
  491. var data = {"personList":getNameFlag(name)};
  492. var v = null;
  493. var cb = function(json){
  494. v = json.data;
  495. return v;
  496. }.ag().catch(function(json){ return v; });
  497. orgActions.listIdentityWithPerson(data, cb, null, !!async);
  498. return (!!async) ? cb : v;
  499. },
  500. //查询组织成员身份--返回身份的对象数组
  501. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  502. listIdentityWithUnit: function(name, nested, async){
  503. getOrgActions();
  504. var data = {"unitList": getNameFlag(name)};
  505. var v = null;
  506. var cb = function(json){
  507. v = json.data;
  508. return v;
  509. }.ag().catch(function(json){ return v; });
  510. if (nested){
  511. orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
  512. }else{
  513. orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
  514. }
  515. return (!!async) ? cb : v;
  516. },
  517. //组织**********
  518. //获取组织
  519. getUnit: function(name, async){
  520. getOrgActions();
  521. var data = {"unitList":getNameFlag(name)};
  522. var v = null;
  523. var cb = function(json){
  524. v = json.data;
  525. v = (v && v.length===1) ? v[0] : v;
  526. return v;
  527. }.ag().catch(function(json){ return v; });
  528. orgActions.listUnit(data, cb, null, !!async);
  529. return (!!async) ? cb : v;
  530. },
  531. //查询组织的下级--返回组织的对象数组
  532. //nested 布尔 true嵌套下级;false直接下级;默认false;
  533. listSubUnit: function(name, nested){
  534. getOrgActions();
  535. var data = {"unitList": getNameFlag(name)};
  536. var v = null;
  537. var cb = function(json){
  538. v = json.data;
  539. return v;
  540. }.ag().catch(function(json){ return v; });
  541. if (nested){
  542. orgActions.listUnitSubNested(data, cb, null, !!async);
  543. }else{
  544. orgActions.listUnitSubDirect(data, cb, null, !!async);
  545. }
  546. return (!!async) ? cb : v;
  547. },
  548. //查询组织的上级--返回组织的对象数组
  549. //nested 布尔 true嵌套上级;false直接上级;默认false;
  550. //async 布尔 true异步请求
  551. listSupUnit: function(name, nested, async){
  552. getOrgActions();
  553. var data = {"unitList": getNameFlag(name)};
  554. var v = null;
  555. var cb = function(json){
  556. v = json.data;
  557. return v;
  558. }.ag().catch(function(json){ return v; });
  559. if (nested){
  560. orgActions.listUnitSupNested(data, cb, null, !!async);
  561. }else{
  562. orgActions.listUnitSupDirect(data, cb, null, !!async);
  563. }
  564. return (!!async) ? cb : v;
  565. // if (callback){
  566. // if (nested){
  567. // orgActions.listUnitSupNested(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  568. // }else{
  569. // orgActions.listUnitSupDirect(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  570. // }
  571. // }else{
  572. // var v = null;
  573. // if (nested){
  574. // orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  575. // }else{
  576. // orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  577. // }
  578. // return v;
  579. // }
  580. },
  581. //根据个人身份获取组织
  582. //flag 数字 表示获取第几层的组织
  583. // 字符串 表示获取指定类型的组织
  584. // 空 表示获取直接所在的组织
  585. getUnitByIdentity: function(name, flag, async){
  586. getOrgActions();
  587. var getUnitMethod = "current";
  588. var v;
  589. if (flag){
  590. if (typeOf(flag)==="string") getUnitMethod = "type";
  591. if (typeOf(flag)==="number") getUnitMethod = "level";
  592. }
  593. var cb;
  594. switch (getUnitMethod){
  595. case "current":
  596. var data = {"identityList":getNameFlag(name)};
  597. cb = function(json){ v = json.data; v=(v&&v.length===1) ? v[0] : v; return v; }.ag().catch(function(json){ return v; });
  598. orgActions.listUnitWithIdentity(data, cb, null, !!async);
  599. break;
  600. case "type":
  601. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  602. cb = function(json){ v = json.data; }.ag().catch(function(json){ return v; });
  603. orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
  604. break;
  605. case "level":
  606. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  607. cb = function(json){ v = json.data; }.ag().catch(function(json){ return v; });
  608. orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
  609. break;
  610. }
  611. return (!!async) ? cb : v;
  612. },
  613. //列出身份所在组织的所有上级组织
  614. listAllSupUnitWithIdentity: function(name, async){
  615. getOrgActions();
  616. var data = {"identityList":getNameFlag(name)};
  617. var v = null;
  618. var cb = function(json){
  619. v = json.data;
  620. return v;
  621. }.ag().catch(function(json){ return v; });
  622. orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
  623. return (!!async) ? cb : v;
  624. },
  625. //获取人员所在的所有组织
  626. listUnitWithPerson: function(name, async){
  627. getOrgActions();
  628. var data = {"personList":getNameFlag(name)};
  629. var v = null;
  630. var cb = function(json){
  631. v = json.data;
  632. return v;
  633. }.ag().catch(function(json){ return v; });
  634. orgActions.listUnitWithPerson(data, cb, null, !!async);
  635. return (!!async) ? cb : v;
  636. },
  637. //列出人员所在组织的所有上级组织
  638. listAllSupUnitWithPerson: function(name, async){
  639. getOrgActions();
  640. var data = {"personList":getNameFlag(name)};
  641. var v = null;
  642. var cb = function(json){
  643. v = json.data;
  644. return v;
  645. }.ag().catch(function(json){ return v; });
  646. orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
  647. return (!!async) ? cb : v;
  648. },
  649. //根据组织属性,获取所有符合的组织
  650. listUnitWithAttribute: function(name, attribute, async){
  651. getOrgActions();
  652. var data = {"name":name,"attribute":attribute};
  653. var v = null;
  654. var cb = function(json){
  655. v = json.data;
  656. return v;
  657. }.ag().catch(function(json){ return v; });
  658. orgActions.listUnitWithAttribute(data, cb, null, !!async);
  659. return (!!async) ? cb : v;
  660. },
  661. //根据组织职务,获取所有符合的组织
  662. listUnitWithDuty: function(name, id, async){
  663. getOrgActions();
  664. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  665. var v = null;
  666. var cb = function(json){
  667. v = json.data;
  668. return v;
  669. }.ag().catch(function(json){ return v; });
  670. orgActions.listUnitWithDuty(data, cb, null, !!async);
  671. return (!!async) ? cb : v;
  672. },
  673. //组织职务***********
  674. //获取指定的组织职务的身份
  675. getDuty: function(duty, id, async){
  676. getOrgActions();
  677. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  678. var v = null;
  679. var cb = function(json){
  680. v = json.data;
  681. return v;
  682. }.ag().catch(function(json){ return v; });
  683. orgActions.getDuty(data, cb, null, !!async);
  684. return (!!async) ? cb : v;
  685. },
  686. //获取身份的所有职务名称
  687. listDutyNameWithIdentity: function(name, async){
  688. getOrgActions();
  689. var data = {"identityList":getNameFlag(name)};
  690. var v = null;
  691. var cb = function(json){
  692. v = json.data.nameList;
  693. return v;
  694. }.ag().catch(function(json){ return v; });
  695. orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
  696. return (!!async) ? cb : v;
  697. },
  698. //获取组织的所有职务名称
  699. listDutyNameWithUnit: function(name, async){
  700. getOrgActions();
  701. var data = {"unitList":getNameFlag(name)};
  702. var v = null;
  703. var cb = function(json){
  704. v = json.data.nameList;
  705. return v;
  706. }.ag().catch(function(json){ return v; });
  707. orgActions.listDutyNameWithUnit(data, cb, null, !!async);
  708. return (!!async) ? cb : v;
  709. },
  710. //获取组织的所有职务
  711. listUnitAllDuty: function(name, async){
  712. getOrgActions();
  713. var data = {"unitList":getNameFlag(name)};
  714. var v = null;
  715. var cb = function(json){
  716. v = json.data;
  717. return v;
  718. }.ag().catch(function(json){ return v; });
  719. orgActions.listUnitAllDuty(data, cb, null, !!async);
  720. return (!!async) ? cb : v;
  721. },
  722. //列出顶层组织
  723. listTopUnit: function(async){
  724. var action = MWF.Actions.get("x_organization_assemble_control");
  725. var v = null;
  726. var cb = function(json){
  727. v = json.data;
  728. return v;
  729. }.ag().catch(function(json){ return v; });
  730. action.listTopUnit(cb, null, !!async);
  731. return (!!async) ? cb : v;
  732. },
  733. //组织属性**************
  734. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  735. appendUnitAttribute: function(unit, attr, values, success, failure, async){
  736. getOrgActions();
  737. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  738. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  739. var cb = function(json){
  740. if (success) return success(json);
  741. }.ag().catch(function(xhr, text, error){
  742. if (failure) return failure(xhr, text, error);
  743. });
  744. orgActions.appendPersonAttribute(data, cb, null, !!async);
  745. // orgActions.appendUnitAttribute(data, function(json){
  746. // if (json.data.value){
  747. // if (success) success();
  748. // }else{
  749. // if (failure) failure(null, "", "append values failed");
  750. // }
  751. // }, function(xhr, text, error){
  752. // if (failure) failure(xhr, text, error);
  753. // }, false);
  754. },
  755. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  756. setUnitAttribute: function(unit, attr, values, success, failure, async){
  757. getOrgActions();
  758. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  759. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  760. var cb = function(json){
  761. if (success) return success(json);
  762. }.ag().catch(function(xhr, text, error){
  763. if (failure) return failure(xhr, text, error);
  764. });
  765. orgActions.setUnitAttribute(data, cb, null, !!async);
  766. // orgActions.setUnitAttribute(data, function(json){
  767. // if (json.data.value){
  768. // if (success) success();
  769. // }else{
  770. // if (failure) failure(null, "", "append values failed");
  771. // }
  772. // }, function(xhr, text, error){
  773. // if (failure) failure(xhr, text, error);
  774. // }, false);
  775. },
  776. //获取组织属性值
  777. getUnitAttribute: function(unit, attr, async){
  778. getOrgActions();
  779. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  780. var data = {"name":attr,"unit":unitFlag};
  781. var v = null;
  782. var cb = function(json){
  783. v = json.data.attributeList;
  784. return v;
  785. }.ag().catch(function(json){ return v; });
  786. orgActions.getUnitAttribute(data, cb, null, !!async);
  787. return (!!async) ? cb : v;
  788. },
  789. //列出组织所有属性的名称
  790. listUnitAttributeName: function(name, async){
  791. getOrgActions();
  792. var data = {"unitList":getNameFlag(name)};
  793. var v = null;
  794. var cb = function(json){
  795. v = json.data.nameList;
  796. return v;
  797. }.ag().catch(function(json){ return v; });
  798. orgActions.listUnitAttributeName(data, cb, null, !!async);
  799. return (!!async) ? cb : v;
  800. },
  801. //列出组织的所有属性
  802. listUnitAllAttribute: function(name, async){
  803. getOrgActions();
  804. var data = {"unitList":getNameFlag(name)};
  805. var v = null;
  806. var cb = function(json){
  807. v = json.data;
  808. return v;
  809. }.ag().catch(function(json){ return v; });
  810. orgActions.listUnitAllAttribute(data, cb, null, !!async);
  811. return (!!async) ? cb : v;
  812. }
  813. };
  814. this.Action = (function () {
  815. var actions = [];
  816. return function (root, json) {
  817. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  818. action.getActions = function (callback) {
  819. if (!this.actions) this.actions = {};
  820. Object.merge(this.actions, json);
  821. if (callback) callback();
  822. };
  823. this.invoke = function (option) {
  824. action.invoke(option)
  825. }
  826. }
  827. })();
  828. this.service = {
  829. "jaxwsClient": {},
  830. "jaxrsClient": {}
  831. };
  832. var lookupAction = null;
  833. var getLookupAction = function (callback) {
  834. if (!lookupAction) {
  835. MWF.require("MWF.xDesktop.Actions.RestActions", function () {
  836. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  837. lookupAction.getActions = function (actionCallback) {
  838. this.actions = {
  839. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  840. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  841. "lookup": { "uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method": "PUT" },
  842. "getView": { "uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}" }
  843. };
  844. if (actionCallback) actionCallback();
  845. }
  846. if (callback) callback();
  847. });
  848. } else {
  849. if (callback) callback();
  850. }
  851. };
  852. this.view = {
  853. "lookup": function (view, callback, async) {
  854. var filterList = { "filterList": (view.filter || null) };
  855. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function (json) {
  856. var data = {
  857. "grid": json.data.grid || json.data.groupGrid,
  858. "groupGrid": json.data.groupGrid
  859. };
  860. if (callback) callback(data);
  861. }, null, async);
  862. },
  863. "lookupV1": function (view, callback) {
  864. getLookupAction(function () {
  865. lookupAction.invoke({
  866. "name": "lookup", "async": true, "parameter": { "view": view.view, "application": view.application }, "success": function (json) {
  867. var data = {
  868. "grid": json.data.grid,
  869. "groupGrid": json.data.groupGrid
  870. };
  871. if (callback) callback(data);
  872. }.bind(this)
  873. });
  874. }.bind(this));
  875. },
  876. "select": function (view, callback, options) {
  877. if (view.view) {
  878. var viewJson = {
  879. "application": view.application || _form.json.application,
  880. "viewName": view.view || "",
  881. "isTitle": (view.isTitle === false) ? "no" : "yes",
  882. "select": (view.isMulti === false) ? "single" : "multi",
  883. "filter": view.filter
  884. };
  885. if (!options) options = {};
  886. options.width = view.width;
  887. options.height = view.height;
  888. options.title = view.caption;
  889. var width = options.width || "700";
  890. var height = options.height || "400";
  891. if (layout.mobile) {
  892. var size = document.body.getSize();
  893. width = size.x;
  894. height = size.y;
  895. options.style = "viewmobile";
  896. }
  897. width = width.toInt();
  898. height = height.toInt();
  899. var size = _form.app.content.getSize();
  900. var x = (size.x - width) / 2;
  901. var y = (size.y - height) / 2;
  902. if (x < 0) x = 0;
  903. if (y < 0) y = 0;
  904. if (layout.mobile) {
  905. x = 20;
  906. y = 0;
  907. }
  908. var _self = this;
  909. MWF.require("MWF.xDesktop.Dialog", function () {
  910. var dlg = new MWF.xDesktop.Dialog({
  911. "title": options.title || "select view",
  912. "style": options.style || "view",
  913. "top": y,
  914. "left": x - 20,
  915. "fromTop": y,
  916. "fromLeft": x - 20,
  917. "width": width,
  918. "height": height,
  919. "html": "<div style='height: 100%;'></div>",
  920. "maskNode": _form.app.content,
  921. "container": _form.app.content,
  922. "buttonList": [
  923. {
  924. "text": MWF.LP.process.button.ok,
  925. "action": function () {
  926. //if (callback) callback(_self.view.selectedItems);
  927. if (callback) callback(_self.view.getData());
  928. this.close();
  929. }
  930. },
  931. {
  932. "text": MWF.LP.process.button.cancel,
  933. "action": function () { this.close(); }
  934. }
  935. ]
  936. });
  937. dlg.show();
  938. if (layout.mobile) {
  939. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  940. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  941. if (backAction) backAction.addEvent("click", function (e) {
  942. dlg.close();
  943. }.bind(this));
  944. if (okAction) okAction.addEvent("click", function (e) {
  945. //if (callback) callback(this.view.selectedItems);
  946. if (callback) callback(this.view.getData());
  947. dlg.close();
  948. }.bind(this));
  949. }
  950. MWF.xDesktop.requireApp("query.Query", "Viewer", function () {
  951. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, { "style": "select" }, _form.app, _form.Macro);
  952. }.bind(this));
  953. }.bind(this));
  954. }
  955. }
  956. };
  957. //include 引用脚本
  958. //optionsOrName : {
  959. // type : "", 默认为portal, 可以为 portal process cms
  960. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  961. // name : "" // 脚本名称/别名/id
  962. //}
  963. //或者name: "" // 脚本名称/别名/id
  964. // if( !window.includedScripts ){
  965. // var includedScripts = window.includedScripts = [];
  966. // }else{
  967. // var includedScripts = window.includedScripts;
  968. // }
  969. var includedScripts = [];
  970. var _includeSingle = function( optionsOrName , callback, async){
  971. var options = optionsOrName;
  972. if( typeOf( options ) == "string" ){
  973. options = { name : options };
  974. }
  975. var name = options.name;
  976. var type = ( options.type && options.application ) ? options.type : "portal";
  977. var application = options.application || _form.json.application;
  978. var key = type +"-" + application + "-" + name;
  979. if (includedScripts.indexOf( key )> -1){
  980. if (callback) callback.apply(this);
  981. return;
  982. }
  983. //if (includedScripts.indexOf( name )> -1){
  984. // if (callback) callback.apply(this);
  985. // return;
  986. //}
  987. var scriptAction;
  988. switch ( type ){
  989. case "portal" :
  990. if( this.scriptActionPortal ){
  991. scriptAction = this.scriptActionPortal;
  992. }else{
  993. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  994. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  995. }
  996. break;
  997. case "process" :
  998. if( this.scriptActionProcess ){
  999. scriptAction = this.scriptActionProcess;
  1000. }else{
  1001. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  1002. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  1003. }
  1004. break;
  1005. case "cms" :
  1006. if( this.scriptActionCMS ){
  1007. scriptAction = this.scriptActionCMS;
  1008. }else{
  1009. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1010. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  1011. }
  1012. break;
  1013. }
  1014. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  1015. if (json.data){
  1016. includedScripts.push( key );
  1017. //名称、别名、id
  1018. json.data.importedList.each( function ( flag ) {
  1019. if( type === "portal" ){
  1020. includedScripts.push( type + "-" + json.data.portal + "-" + flag );
  1021. if( json.data.portalName )includedScripts.push( type + "-" + json.data.portalName + "-" + flag );
  1022. if( json.data.portalAlias )includedScripts.push( type + "-" + json.data.portalAlias + "-" + flag );
  1023. }else if( type === "cms" ){
  1024. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  1025. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1026. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1027. }else if( type === "process" ){
  1028. includedScripts.push( type + "-" + json.data.application + "-" + flag );
  1029. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1030. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1031. }
  1032. });
  1033. includedScripts = includedScripts.concat(json.data.importedList);
  1034. MWF.Macro.exec(json.data.text, this);
  1035. if (callback) callback.apply(this);
  1036. }else{
  1037. if (callback) callback.apply(this);
  1038. }
  1039. }.bind(this), null, !!async);
  1040. }
  1041. this.include = function( optionsOrName , callback, async){
  1042. if (o2.typeOf(optionsOrName)=="array"){
  1043. if (!!async){
  1044. var count = optionsOrName.length;
  1045. var loaded = 0;
  1046. optionsOrName.each(function(option){
  1047. _includeSingle.apply(this, [option, function(){
  1048. loaded++;
  1049. if (loaded>=count) if (callback) callback.apply(this);;
  1050. }.bind(this), true]);
  1051. }.bind(this));
  1052. }else{
  1053. optionsOrName.each(function(option){
  1054. _includeSingle.apply(this, [option]);
  1055. if (callback) callback.apply(this);
  1056. }.bind(this));
  1057. }
  1058. }else{
  1059. _includeSingle.apply(this, [optionsOrName , callback, async])
  1060. }
  1061. };
  1062. this.define = function (name, fun, overwrite) {
  1063. var over = true;
  1064. if (overwrite === false) over = false;
  1065. var o = {};
  1066. o[name] = { "value": fun, "configurable": over };
  1067. MWF.defineProperties(this, o);
  1068. }.bind(this);
  1069. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  1070. //可在调用前执行 var resolve = this.wait();
  1071. //在异步调用结束后 执行 resolve.cb();
  1072. //目前只有表单的queryload事件支持此方法。
  1073. this.wait = function(){
  1074. resolve = {};
  1075. var setResolve = function(callback){
  1076. resolve.cb = callback;
  1077. }.bind(this);
  1078. this.target.event_resolve = setResolve;
  1079. return resolve;
  1080. };
  1081. //和this.wait配合使用,
  1082. //如果没有异步,则resolve.cb方法不存在,
  1083. //所以在回调中中使用this.goon();使表单继续加载
  1084. this.goon = function(){
  1085. this.target.event_resolve = null;
  1086. };
  1087. //仅前台对象-----------------------------------------
  1088. //form
  1089. this.page = this.form = {
  1090. "getInfor": function () { return ev.pageInfor; },
  1091. "infor": ev.pageInfor,
  1092. "getApp": function () { return _form.app; },
  1093. "app": _form.app,
  1094. "node": function () { return _form.node; },
  1095. //"readonly": _form.options.readonly,
  1096. "get": function (name) { return (_form.all) ? _form.all[name] : null; },
  1097. "getWidgetModule": function (widget, moduleName) {
  1098. if (!_form.widgetModules || !_form.widgetModules[widget]) return null;
  1099. var module = _form.widgetModules[widget][moduleName];
  1100. return module || null;
  1101. },
  1102. "getField": function (name) { return _forms[name]; },
  1103. "getAction": function () { return _form.workAction },
  1104. "getDesktop": function () { return _form.app.desktop },
  1105. "getData": function () { return new MWF.xScript.JSONData(_form.getData()); },
  1106. //"save": function(callback){_form.saveWork(callback);},
  1107. "close": function () { _form.closeWork(); },
  1108. "print": function (application, form) {
  1109. _form.printWork(application, form);
  1110. },
  1111. "confirm": function (type, title, text, width, height, ok, cancel, callback, mask, style) {
  1112. // var p = MWF.getCenter({"x": width, "y": height});
  1113. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1114. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1115. if ((arguments.length <= 1) || o2.typeOf(arguments[1]) === "string") {
  1116. var p = MWF.getCenter({ "x": width, "y": height });
  1117. e = { "event": { "clientX": p.x, "x": p.x, "clientY": p.y, "y": p.y } };
  1118. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1119. } else {
  1120. e = (arguments.length > 1) ? arguments[1] : null;
  1121. title = (arguments.length > 2) ? arguments[2] : null;
  1122. text = (arguments.length > 3) ? arguments[3] : null;
  1123. width = (arguments.length > 4) ? arguments[4] : null;
  1124. height = (arguments.length > 5) ? arguments[5] : null;
  1125. ok = (arguments.length > 6) ? arguments[6] : null;
  1126. cancel = (arguments.length > 7) ? arguments[7] : null;
  1127. callback = (arguments.length > 8) ? arguments[8] : null;
  1128. mask = (arguments.length > 9) ? arguments[9] : null;
  1129. style = (arguments.length > 10) ? arguments[10] : null;
  1130. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1131. }
  1132. },
  1133. "alert": function(type, title, text, width, height){
  1134. _form.alert(type, title, text, width, height);
  1135. },
  1136. "notice": function (content, type, target, where, offset, option) {
  1137. _form.notice(content, type, target, where, offset, option);
  1138. },
  1139. "addEvent": function (e, f) { _form.addEvent(e, f); },
  1140. "openWindow": function (form, app) {
  1141. _form.openWindow(form, app);
  1142. },
  1143. "toPage": function (name, par, nohis) {
  1144. _form.app.toPage(name, par, nohis);
  1145. },
  1146. "toPortal": function (portal, page, par) {
  1147. _form.app.toPortal(portal, page, par);
  1148. },
  1149. "openWork": function (id, completedId, title, options) {
  1150. var op = options || {};
  1151. op.workId = id;
  1152. op.workCompletedId = completedId;
  1153. op.docTitle = title;
  1154. op.appId = "process.Work" + (op.workId || op.workCompletedId);
  1155. return layout.desktop.openApplication(this.event, "process.Work", op);
  1156. },
  1157. "openJob": function (id, choice, options) {
  1158. var workData = null;
  1159. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function (json) {
  1160. if (json.data) workData = json.data;
  1161. }.bind(this), null, false);
  1162. if (workData) {
  1163. var len = workData.workList.length + workData.workCompletedList.length;
  1164. if (len) {
  1165. if (len > 1 && choice) {
  1166. var node = new Element("div", { "styles": { "padding": "20px", "width": "500px" } }).inject(_form.node);
  1167. workData.workList.each(function (work) {
  1168. var workNode = new Element("div", {
  1169. "styles": {
  1170. "background": "#ffffff",
  1171. "border-radius": "10px",
  1172. "clear": "both",
  1173. "margin-bottom": "10px",
  1174. "height": "40px",
  1175. "padding": "10px 10px"
  1176. }
  1177. }).inject(node);
  1178. 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>" +
  1179. "<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>" +
  1180. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>" + work.title + "</div>" +
  1181. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>" + work.activityName + "</div>" +
  1182. "<div style='color:#999999; float: left; margin-right: 10px'>" + work.activityArrivedTime + "</div>" +
  1183. "<div style='color:#999999; float: left; margin-right: 10px'>" + (work.manualTaskIdentityText || "") + "</div></div>";
  1184. workNode.set("html", html);
  1185. var action = workNode.getElement(".MWFAction");
  1186. action.store("work", work);
  1187. action.addEvent("click", function (e) {
  1188. var work = e.target.retrieve("work");
  1189. if (work) this.openWork(work.id, null, work.title, options);
  1190. dlg.close();
  1191. }.bind(this));
  1192. }.bind(this));
  1193. workData.workCompletedList.each(function (work) {
  1194. var workNode = new Element("div", {
  1195. "styles": {
  1196. "background": "#ffffff",
  1197. "border-radius": "10px",
  1198. "clear": "both",
  1199. "margin-bottom": "10px",
  1200. "height": "40px",
  1201. "padding": "10px 10px"
  1202. }
  1203. }).inject(node);
  1204. 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>" +
  1205. "<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>" +
  1206. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>" + work.title + "</div>" +
  1207. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>" + o2.LP.widget.workcompleted + "</div>" +
  1208. "<div style='color:#999999; float: left; margin-right: 10px'>" + work.completedTime + "</div>";
  1209. workNode.set("html", html);
  1210. var action = workNode.getElement(".MWFAction");
  1211. action.store("work", work);
  1212. action.addEvent("click", function (e) {
  1213. var work = e.target.retrieve("work");
  1214. if (work) this.openWork(null, work.id, work.title, options);
  1215. dlg.close();
  1216. }.bind(this));
  1217. }.bind(this));
  1218. var height = node.getSize().y + 20;
  1219. if (height > 600) height = 600;
  1220. var dlg = o2.DL.open({
  1221. "title": o2.LP.widget.choiceWork,
  1222. "style": "user",
  1223. "isResize": false,
  1224. "content": node,
  1225. "buttonList": [
  1226. {
  1227. "type": "cancel",
  1228. "text": o2.LP.widget.close,
  1229. "action": function () { dlg.close(); }
  1230. }
  1231. ]
  1232. });
  1233. } else {
  1234. if (workData.workList.length) {
  1235. var work = workData.workList[0];
  1236. return this.openWork(work.id, null, work.title, options);
  1237. } else {
  1238. var work = workData.workCompletedList[0];
  1239. return this.openWork(null, work.id, work.title, options);
  1240. }
  1241. }
  1242. }
  1243. }
  1244. },
  1245. "openDocument": function (id, title, options) {
  1246. var op = options || {};
  1247. op.documentId = id;
  1248. op.docTitle = title || "";
  1249. layout.desktop.openApplication(this.event, "cms.Document", op);
  1250. },
  1251. "openPortal": function (name, page, par) {
  1252. var action = MWF.Actions.get("x_portal_assemble_surface");
  1253. action.getApplication(name, function (json) {
  1254. if (json.data) {
  1255. if (page) {
  1256. action.getPageByName(page, json.data.id, function (pageJson) {
  1257. layout.desktop.openApplication(null, "portal.Portal", {
  1258. "portalId": json.data.id,
  1259. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1260. "parameters": par,
  1261. "appId": "portal.Portal" + json.data.id
  1262. })
  1263. });
  1264. } else {
  1265. layout.desktop.openApplication(null, "portal.Portal", {
  1266. "portalId": json.data.id,
  1267. "parameters": par,
  1268. "appId": "portal.Portal" + json.data.id
  1269. })
  1270. }
  1271. }
  1272. });
  1273. },
  1274. "openCMS": function (name) {
  1275. var action = MWF.Actions.get("x_cms_assemble_control");
  1276. action.getColumn(name, function (json) {
  1277. if (json.data) {
  1278. layout.desktop.openApplication(null, "cms.Module", {
  1279. "columnId": json.data.id,
  1280. "appId": "cms.Module" + json.data.id
  1281. });
  1282. }
  1283. });
  1284. },
  1285. "openProcess": function (name) {
  1286. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1287. action.getApplication(name, function (json) {
  1288. if (json.data) {
  1289. layout.desktop.openApplication(null, "process.Application", {
  1290. "id": json.data.id,
  1291. "appId": "process.Application" + json.data.id
  1292. });
  1293. }
  1294. });
  1295. },
  1296. "openApplication": function (name, options) {
  1297. layout.desktop.openApplication(null, name, options);
  1298. },
  1299. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  1300. var column = columnOrOptions;
  1301. var onAfterPublish, onPostPublish;
  1302. if (typeOf(columnOrOptions) == "object") {
  1303. column = columnOrOptions.column;
  1304. category = columnOrOptions.category;
  1305. data = columnOrOptions.data;
  1306. identity = columnOrOptions.identity;
  1307. callback = columnOrOptions.callback;
  1308. target = columnOrOptions.target;
  1309. latest = columnOrOptions.latest;
  1310. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1311. ignoreTitle = columnOrOptions.ignoreTitle;
  1312. onAfterPublish = columnOrOptions.onAfterPublish;
  1313. onPostPublish = columnOrOptions.onPostPublish;
  1314. }
  1315. if (target) {
  1316. if (layout.app && layout.app.inBrowser) {
  1317. layout.app.content.empty();
  1318. layout.app = null;
  1319. }
  1320. }
  1321. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  1322. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1323. "documentData": data,
  1324. "identity": identity,
  1325. "ignoreTitle": ignoreTitle === true,
  1326. "ignoreDrafted": latest === false,
  1327. "selectColumnEnable": !category || selectColumnEnable === true,
  1328. "restrictToColumn": !!category && selectColumnEnable !== true,
  1329. "categoryFlag": category, //category id or name
  1330. "columnFlag": column, //column id or name,
  1331. "onStarted": function (documentId, data) {
  1332. if (callback) callback();
  1333. },
  1334. "onPostPublish": function () {
  1335. if(onPostPublish)onPostPublish();
  1336. },
  1337. "onAfterPublish": function () {
  1338. if(onAfterPublish)onAfterPublish();
  1339. }
  1340. });
  1341. starter.load();
  1342. })
  1343. },
  1344. "startProcess": function (app, process, data, identity, callback, target, latest) {
  1345. if (arguments.length > 2) {
  1346. for (var i = 2; i < arguments.length; i++) {
  1347. if (typeOf(arguments[i]) == "boolean") {
  1348. target = arguments[i];
  1349. break;
  1350. }
  1351. }
  1352. }
  1353. if (target) {
  1354. if (layout.app && layout.app.inBrowser) {
  1355. //layout.app.content.empty();
  1356. layout.app.$openWithSelf = true;
  1357. }
  1358. }
  1359. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function (json) {
  1360. if (json.data) {
  1361. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function () {
  1362. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1363. "workData": data,
  1364. "identity": identity,
  1365. "latest": latest,
  1366. "onStarted": function (data, title, processName) {
  1367. if (data.work){
  1368. var work = data.work;
  1369. var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
  1370. layout.desktop.openApplication(null, "process.Work", options);
  1371. }else{
  1372. var currentTask = [];
  1373. data.each(function(work){
  1374. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1375. }.bind(this));
  1376. if (currentTask.length==1){
  1377. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1378. layout.desktop.openApplication(null, "process.Work", options);
  1379. }else{}
  1380. }
  1381. // var currentTask = [];
  1382. // data.each(function (work) {
  1383. // if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1384. // }.bind(this));
  1385. //
  1386. // if (currentTask.length == 1) {
  1387. // var options = { "workId": currentTask[0], "appId": currentTask[0] };
  1388. // layout.desktop.openApplication(null, "process.Work", options);
  1389. // } else { }
  1390. if (callback) callback(data);
  1391. }.bind(this)
  1392. });
  1393. starter.load();
  1394. }.bind(this));
  1395. }
  1396. });
  1397. },
  1398. "parameters": _form.options.parameters,
  1399. "getWidgetPrameters": function () {
  1400. if (!this.target) return null;
  1401. if (!this.target.widget) return null;
  1402. if (!this.widgetParameters) return null;
  1403. var pageId = this.target.widget.json.id;
  1404. return this.widgetParameters[pageId];
  1405. }.bind(this)
  1406. //"app": _form.app
  1407. };
  1408. this.form.currentRouteName = _form.json.currentRouteName;
  1409. this.form.opinion = _form.json.opinion;
  1410. this.target = ev.target;
  1411. this.event = ev.event;
  1412. this.status = ev.status;
  1413. this.session = layout.desktop.session;
  1414. this.Actions = o2.Actions;
  1415. this.query = function (option) {
  1416. // options = {
  1417. // "name": "statementName",
  1418. // "data": "json data",
  1419. // "firstResult": 1,
  1420. // "maxResults": 100,
  1421. // "success": function(){},
  1422. // "error": function(){},
  1423. // "async": true or false, default is true
  1424. // }
  1425. if (option) {
  1426. var json = (option.data) || {};
  1427. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1428. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1429. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1430. }
  1431. };
  1432. this.Table = MWF.xScript.createTable();
  1433. };
  1434. MWF.xScript.createTable = function(){
  1435. return function(name){
  1436. this.name = name;
  1437. this.action = o2.Actions.get("x_query_assemble_surface");
  1438. this.listRowNext = function(id, count, success, error, async){
  1439. this.action.listRowNext(this.name, id, count, success, error, async);
  1440. };
  1441. this.listRowPrev = function(id, count, success, error, async){
  1442. this.action.listRowPrev(this.name, id, count, success, error, async);
  1443. };
  1444. this.listRowPrev = function(id, count, success, error, async){
  1445. this.action.listRowPrev(this.name, id, count, success, error, async);
  1446. };
  1447. this.listRowSelectWhere = function(where, success, error, async){
  1448. this.action.listRowSelectWhere(this.name, where, success, error, async);
  1449. };
  1450. this.listRowCountWhere = function(where, success, error, async){
  1451. this.action.listRowCountWhere(this.name, where, success, error, async);
  1452. };
  1453. this.deleteRow = function(id, success, error, async){
  1454. this.action.deleteRow(this.name, id, success, error, async);
  1455. };
  1456. this.deleteAllRow = function(success, error, async){
  1457. this.action.deleteAllRow(this.name, success, error, async);
  1458. };
  1459. this.getRow = function(id, success, error, async){
  1460. this.action.getRow(this.name, id, success, error, async);
  1461. };
  1462. this.insertRow = function(data, success, error, async){
  1463. this.action.insertRow(this.name, data, success, error, async);
  1464. };
  1465. this.updateRow = function(id, data, success, error, async){
  1466. this.action.updateRow(this.name, id, data, success, error, async);
  1467. };
  1468. }
  1469. };
  1470. MWF.xScript.JSONData = function(data, callback, key, parent, _form){
  1471. var getter = function(data, callback, k, _self){
  1472. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self, _form);};
  1473. };
  1474. var setter = function(data, callback, k, _self){
  1475. return function(v){
  1476. data[k] = v;
  1477. //debugger;
  1478. //this.add(k, v, true);
  1479. if (callback) callback(data, k, _self);
  1480. }
  1481. };
  1482. var define = function(){
  1483. var o = {};
  1484. for (var k in data) o[k] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, k, this]),"set": setter.apply(this, [data, callback, k, this])};
  1485. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1486. MWF.defineProperties(this, o);
  1487. var methods = {
  1488. "getKey": {"value": function(){ return key; }},
  1489. "getParent": {"value": function(){ return parent; }},
  1490. "toString": {"value": function() { return data.toString();}},
  1491. "setSection": {"value": function(newKey, newValue){
  1492. this.add(newKey, newValue, true);
  1493. try {
  1494. var path = [this.getKey()];
  1495. p = this.getParent();
  1496. while (p && p.getKey()){
  1497. path.unshift(p.getKey());
  1498. p = p.getParent();
  1499. }
  1500. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  1501. }catch(e){
  1502. debugger;
  1503. }
  1504. }},
  1505. "add": {"value": function(newKey, newValue, overwrite){
  1506. var flag = true;
  1507. var type = typeOf(data);
  1508. if (type==="array"){
  1509. if (arguments.length<2){
  1510. data.push(newKey);
  1511. newValue = newKey;
  1512. newKey = data.length-1;
  1513. }else{
  1514. if (!newKey && newKey!==0){
  1515. data.push(newValue);
  1516. newKey = data.length-1;
  1517. }else{
  1518. flag = false;
  1519. }
  1520. }
  1521. if (flag){
  1522. var o = {};
  1523. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1524. MWF.defineProperties(this, o);
  1525. }
  1526. this[newKey] = newValue;
  1527. }else if (type==="object"){
  1528. if (!this.hasOwnProperty(newKey)){
  1529. data[newKey] = newValue;
  1530. if (flag){
  1531. var o = {};
  1532. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1533. MWF.defineProperties(this, o);
  1534. }
  1535. this[newKey] = newValue;
  1536. }else{
  1537. if (overwrite) this[newKey] = newValue;
  1538. }
  1539. }
  1540. return this[newKey];
  1541. }},
  1542. "del": {"value": function(delKey){
  1543. if (!this.hasOwnProperty(delKey)) return null;
  1544. delete data[delKey];
  1545. delete this[delKey];
  1546. return this;
  1547. }}
  1548. };
  1549. MWF.defineProperties(this, methods);
  1550. };
  1551. var type = typeOf(data);
  1552. if (type==="object" || type==="array") define.apply(this);
  1553. };
  1554. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  1555. MWF.xScript.addDictToCache = function ( options, path, json ) {
  1556. if( !path )path = "root";
  1557. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1558. var type = options.appType || "process";
  1559. var enableAnonymous = options.enableAnonymous || false;
  1560. var appFlagList = [];
  1561. if( options.application )appFlagList.push( options.application );
  1562. if( options.appId )appFlagList.push( options.appId );
  1563. if( options.appName )appFlagList.push( options.appName );
  1564. if( options.appAlias )appFlagList.push( options.appAlias );
  1565. var dictFlagList = [];
  1566. if( options.id )dictFlagList.push( options.id );
  1567. if( options.name )dictFlagList.push( options.name );
  1568. if( options.alias )dictFlagList.push( options.alias );
  1569. var cache = {};
  1570. cache[path] = json;
  1571. for( var i=0; i<appFlagList.length; i++ ){
  1572. for( var j=0; j<dictFlagList.length; j++ ){
  1573. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  1574. if( !MWF.xScript.dictLoaded[k] ){
  1575. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  1576. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  1577. }else if( i===0 && j===0 ){
  1578. MWF.xScript.setDictToCache( k, path ,json );
  1579. var arr = path.split(/\./g);
  1580. var p;
  1581. var cache = MWF.xScript.dictLoaded[k];
  1582. for( var l=0 ; l<arr.length; l++ ){
  1583. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  1584. if( cache[ p ] )break;
  1585. }
  1586. if( p ){
  1587. var mathP = p+".";
  1588. Object.keys( cache ).each( function( path, idx){
  1589. if( path.indexOf( mathP ) === 0 )delete cache[path];
  1590. })
  1591. }
  1592. }
  1593. }
  1594. }
  1595. };
  1596. MWF.xScript.getMatchedDict = function(key, path){
  1597. if( !path )path = "root";
  1598. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1599. var arr = path.split(/\./g);
  1600. if( MWF.xScript.dictLoaded[key] ){
  1601. var dicts = MWF.xScript.dictLoaded[key];
  1602. var list = Array.clone(arr);
  1603. var p;
  1604. var dict;
  1605. for( var i=0 ; i<arr.length; i++ ){
  1606. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  1607. list.shift();
  1608. if( dicts[ p ] ){
  1609. dict = dicts[ p ];
  1610. break;
  1611. }
  1612. }
  1613. return {
  1614. dict : dict,
  1615. unmatchedPathList : list
  1616. }
  1617. }
  1618. return {
  1619. dict : null,
  1620. unmatchedPathList : list
  1621. }
  1622. };
  1623. MWF.xScript.insertDictToCache = function(key, path, json){
  1624. if( MWF.xScript.dictLoaded[key] ){
  1625. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1626. var dict = matchedDict.dict;
  1627. var list = matchedDict.unmatchedPathList;
  1628. if( !dict ){
  1629. MWF.xScript.dictLoaded[key][path] = json;
  1630. }else{
  1631. for( var j=0; j<list.length-1; j++ ){
  1632. if( !dict[ list[j] ] ){
  1633. dict[ list[j] ] = {};
  1634. }
  1635. dict = dict[ list[j] ];
  1636. }
  1637. var lastPath = list[list.length-1];
  1638. if( !dict[lastPath] ){
  1639. dict[lastPath] = json;
  1640. }else if( typeOf( dict[lastPath] ) === "array" ){
  1641. dict[lastPath].push( json );
  1642. }
  1643. }
  1644. }else{
  1645. MWF.xScript.dictLoaded[key] = {};
  1646. MWF.xScript.dictLoaded[key][path] = json;
  1647. }
  1648. };
  1649. MWF.xScript.setDictToCache = function(key, path, json){
  1650. if( MWF.xScript.dictLoaded[key] ){
  1651. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1652. var dict = matchedDict.dict;
  1653. var list = matchedDict.unmatchedPathList;
  1654. if( !dict ){
  1655. MWF.xScript.dictLoaded[key][path] = json;
  1656. }else{
  1657. for( var j=0; j<list.length-1; j++ ){
  1658. if( !dict[ list[j] ] ){
  1659. dict[ list[j] ] = {};
  1660. }
  1661. dict = dict[ list[j] ];
  1662. }
  1663. dict[list[list.length-1]] = json;
  1664. }
  1665. }else{
  1666. MWF.xScript.dictLoaded[key] = {};
  1667. MWF.xScript.dictLoaded[key][path] = json;
  1668. }
  1669. };
  1670. MWF.xScript.getDictFromCache = function( key, path ){
  1671. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1672. var dict = matchedDict.dict;
  1673. var list = matchedDict.unmatchedPathList;
  1674. if( dict ){
  1675. for( var j=0; j<list.length; j++ ){
  1676. dict = dict[ list[j] ];
  1677. if( !dict )return null;
  1678. }
  1679. return dict;
  1680. }
  1681. return null;
  1682. };
  1683. MWF.xScript.deleteDictToCache = function(key, path){
  1684. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1685. var dict = matchedDict.dict;
  1686. var list = matchedDict.unmatchedPathList;
  1687. if( dict){
  1688. for( var j=0; j<list.length-1; j++ ){
  1689. dict = dict[ list[j] ];
  1690. if( !dict )return;
  1691. }
  1692. delete dict[list[list.length-1]];
  1693. }
  1694. };
  1695. MWF.xScript.createDict = function(application){
  1696. //optionsOrName : {
  1697. // type : "", //默认为process, 可以为 process cms
  1698. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1699. // name : "", // 数据字典名称/别名/id
  1700. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1701. //}
  1702. //或者name: "" // 数据字典名称/别名/id
  1703. return function(optionsOrName){
  1704. var options = optionsOrName;
  1705. if( typeOf( options ) == "string" ){
  1706. options = { name : options };
  1707. }
  1708. var name = this.name = options.name;
  1709. var type = ( options.type && options.application ) ? options.type : "process";
  1710. var applicationId = options.application || application;
  1711. var enableAnonymous = options.enableAnonymous || false;
  1712. var opt = {
  1713. "appType" : type,
  1714. "name" : name,
  1715. "appId" : applicationId,
  1716. "enableAnonymous" : enableAnonymous
  1717. };
  1718. var key = name+type+applicationId+enableAnonymous;
  1719. // if (!dictLoaded[key]) dictLoaded[key] = {};
  1720. // this.dictData = dictLoaded[key];
  1721. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1722. if( type == "cms" ){
  1723. var action = MWF.Actions.get("x_cms_assemble_control");
  1724. }else{
  1725. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1726. }
  1727. var encodePath = function( path ){
  1728. var arr = path.split(/\./g);
  1729. var ar = arr.map(function(v){
  1730. return encodeURIComponent(v);
  1731. });
  1732. return ar.join("/");
  1733. };
  1734. this.get = function(path, success, failure, async, refresh){
  1735. var value = null;
  1736. if (!refresh ){
  1737. var data = MWF.xScript.getDictFromCache( key, path );
  1738. if( data ){
  1739. if (success && o2.typeOf(success)=="function") success( data );
  1740. return data;
  1741. }
  1742. }
  1743. if (success===true) async=true;
  1744. if (failure===true) async=true;
  1745. var cb = function(json){
  1746. value = json.data;
  1747. MWF.xScript.addDictToCache(opt, path, value);
  1748. if (success && o2.typeOf(success)=="function") value = success(json.data);
  1749. return value;
  1750. }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
  1751. if (path){
  1752. var p = encodePath( path );
  1753. //var p = path.replace(/\./g, "/");
  1754. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async);
  1755. }else{
  1756. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async);
  1757. }
  1758. return (!!async) ? cb : value;
  1759. // if (path){
  1760. // var p = encodePath( path );
  1761. // //var p = path.replace(/\./g, "/");
  1762. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1763. // value = json.data;
  1764. // // this.dictData[path] = value;
  1765. // MWF.xScript.addDictToCache(opt, path, value);
  1766. // if (success) success(json.data);
  1767. // }.bind(this), function(xhr, text, error){
  1768. // if (failure) failure(xhr, text, error);
  1769. // }, !!async);
  1770. // }else{
  1771. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  1772. // value = json.data;
  1773. // // this.dictData["root"] = value;
  1774. // MWF.xScript.addDictToCache(opt, path, value);
  1775. // if (success) success(json.data);
  1776. // }.bind(this), function(xhr, text, error){
  1777. // if (failure) failure(xhr, text, error);
  1778. // }, !!async);
  1779. // }
  1780. //return value;
  1781. };
  1782. this.set = function(path, value, success, failure){
  1783. var p = encodePath( path );
  1784. //var p = path.replace(/\./g, "/");
  1785. return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1786. MWF.xScript.setDictToCache(key, path, value);
  1787. if (success) return success(json.data);
  1788. }, function(xhr, text, error){
  1789. if (failure) return failure(xhr, text, error);
  1790. }, false, false);
  1791. };
  1792. this.add = function(path, value, success, failure){
  1793. var p = encodePath( path );
  1794. //var p = path.replace(/\./g, "/");
  1795. return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1796. MWF.xScript.insertDictToCache(key, path, value);
  1797. if (success) return success(json.data);
  1798. }, function(xhr, text, error){
  1799. if (failure) return failure(xhr, text, error);
  1800. }, false, false);
  1801. };
  1802. this["delete"] = function(path, success, failure){
  1803. var p = encodePath( path );
  1804. //var p = path.replace(/\./g, "/");
  1805. return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1806. MWF.xScript.deleteDictToCache(key, path);
  1807. if (success) return success(json.data);
  1808. }, function(xhr, text, error){
  1809. if (failure) return failure(xhr, text, error);
  1810. }, false, false);
  1811. };
  1812. this.destory = this["delete"];
  1813. }
  1814. };