ViewEnvironment.js 95 KB

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