PageEnvironment.js 146 KB

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