ViewEnvironment.js 105 KB

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