PageEnvironment.js 88 KB

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