ViewSelector.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xDesktop.requireApp("process.Xform", "Button", null, false);
  3. /** @class ViewSelector 视图选择组件。
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var sourceText = this.form.get("fieldId"); //获取组件
  8. * //方法2
  9. * var sourceText = this.target; //在组件本身的脚本中获取
  10. * @extends MWF.xApplication.process.Xform.Button
  11. * @o2category FormComponents
  12. * @o2range {Process|CMS}
  13. * @hideconstructor
  14. */
  15. MWF.xApplication.process.Xform.ViewSelector = MWF.APPViewSelector = new Class({
  16. Implements: [Events],
  17. Extends: MWF.xApplication.process.Xform.Button,
  18. _loadUserInterface: function(){
  19. var button = this.node.getElement("button");
  20. if (!button) button = new Element("button");
  21. button.inject(this.node, "after");
  22. this.node.destroy();
  23. this.node = button;
  24. this.node.set({
  25. "id": this.json.id,
  26. "text": this.json.name || this.json.id,
  27. "styles": this.form.css.buttonStyles,
  28. "MWFType": this.json.type
  29. });
  30. this.node.addEvent("click", function(){
  31. this.selectedData = null;
  32. this.selectView(function(data){
  33. this.doResult(data);
  34. }.bind(this));
  35. }.bind(this));
  36. },
  37. doResult: function(data){
  38. if (this.json.result === "script"){
  39. this.selectedData = data;
  40. return (this.json.selectedScript.code) ? this.form.Macro.exec(this.json.selectedScript.code, this) : "";
  41. }else{
  42. Object.each(this.json.selectedSetValues, function(v, k){
  43. var value = "";
  44. data.each(function(d, idx){
  45. Object.each(d.data, function(dv, dk){
  46. if (dk===v) value = (value) ? (value+", "+dv) : dv;
  47. }.bind(this));
  48. }.bind(this));
  49. var field = this.form.all[k];
  50. if (field){
  51. field.setData(value);
  52. if (value){
  53. if (field.descriptionNode) field.descriptionNode.setStyle("display", "none");
  54. }else{
  55. if (field.descriptionNode) field.descriptionNode.setStyle("display", "block");
  56. }
  57. }
  58. }.bind(this));
  59. }
  60. },
  61. selectCMSView: function(callback){
  62. var viewData = this.json.cmsViewName;
  63. if (viewData){
  64. var filter = null;
  65. if (this.json.filterList && this.json.filterList.length){
  66. filter = [];
  67. this.json.filterList.each(function(entry){
  68. entry.value = this.form.Macro.exec(entry.code.code, this);
  69. //delete entry.code;
  70. filter.push(entry);
  71. }.bind(this));
  72. }
  73. var viewJson = {
  74. "application": viewData.appId,
  75. "viewName": viewData.name,
  76. "isTitle": this.json.isTitle || "yes",
  77. "select": this.json.select || "single",
  78. "titleStyles": this.json.titleStyles,
  79. "itemStyles": this.json.itemStyles,
  80. "isExpand": this.json.isExpand || "no",
  81. "showActionbar" : this.json.actionbar === "show",
  82. "filter": filter
  83. };
  84. var options = {};
  85. var width = options.width || "800";
  86. var height = options.height || "450";
  87. var size;
  88. if (layout.mobile){
  89. size = document.body.getSize();
  90. width = size.x;
  91. height = size.y;
  92. options.style = "viewmobile";
  93. }
  94. width = width.toInt();
  95. height = height.toInt();
  96. size = this.form.app.content.getSize();
  97. var x = (size.x-width)/2;
  98. var y = (size.y-height)/2;
  99. if (x<0) x = 0;
  100. if (y<0) y = 0;
  101. if (layout.mobile){
  102. x = 20;
  103. y = 0;
  104. }
  105. var _self = this;
  106. MWF.require("MWF.xDesktop.Dialog", function(){
  107. var dlg = new MWF.xDesktop.Dialog({
  108. "title": this.json.title || "select view",
  109. "style": options.style || "view",
  110. "top": y,
  111. "left": x-20,
  112. "fromTop":y,
  113. "fromLeft": x-20,
  114. "width": width,
  115. "height": height,
  116. "html": "<div></div>",
  117. "maskNode": this.form.app.content,
  118. "container": this.form.app.content,
  119. "buttonList": [
  120. {
  121. "text": MWF.LP.process.button.ok,
  122. "action": function(){
  123. //if (callback) callback(_self.view.selectedItems);
  124. if (callback) callback(_self.view.getData());
  125. this.close();
  126. }
  127. },
  128. {
  129. "text": MWF.LP.process.button.cancel,
  130. "action": function(){this.close();}
  131. }
  132. ]
  133. });
  134. dlg.show();
  135. if (layout.mobile){
  136. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  137. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  138. if (backAction) backAction.addEvent("click", function(e){
  139. dlg.close();
  140. }.bind(this));
  141. if (okAction) okAction.addEvent("click", function(e){
  142. //if (callback) callback(this.view.selectedItems);
  143. if (callback) callback(this.view.getData());
  144. dlg.close();
  145. }.bind(this));
  146. }
  147. // MWF.xDesktop.requireApp("process.Xform", "widget.CMSView", function(){
  148. // this.view = new MWF.xApplication.process.Xform.widget.CMSView(dlg.content.getFirst(), viewJson, {"style": "select"});
  149. // }.bind(this));
  150. MWF.xDesktop.requireApp("process.Application", "Viewer", function(){
  151. this.view = new MWF.xApplication.process.Application.Viewer(dlg.content, viewJson, {
  152. "actions": {
  153. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  154. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  155. },
  156. "actionRoot": "x_cms_assemble_control"
  157. });
  158. }.bind(this));
  159. }.bind(this));
  160. }
  161. },
  162. selectProcessView: function(callback){
  163. var viewData = this.json.processViewName;
  164. if (viewData){
  165. var filter = null;
  166. if (this.json.filterList && this.json.filterList.length){
  167. filter = [];
  168. this.json.filterList.each(function(entry){
  169. entry.value = this.form.Macro.exec(entry.code.code, this);
  170. //delete entry.code;
  171. filter.push(entry);
  172. }.bind(this));
  173. }
  174. var viewJson = {
  175. "application": viewData.application,
  176. "viewName": viewData.name,
  177. "isTitle": this.json.isTitle || "yes",
  178. "select": this.json.select || "single",
  179. "titleStyles": this.json.titleStyles,
  180. "itemStyles": this.json.itemStyles,
  181. "isExpand": this.json.isExpand || "no",
  182. "showActionbar" : this.json.actionbar === "show",
  183. "filter": filter
  184. };
  185. var options = {};
  186. var width = options.width || "800";
  187. var height = options.height || "600";
  188. var size;
  189. if (layout.mobile){
  190. size = document.body.getSize();
  191. width = size.x;
  192. height = size.y;
  193. options.style = "viewmobile";
  194. }
  195. width = width.toInt();
  196. height = height.toInt();
  197. size = this.form.app.content.getSize();
  198. var x = (size.x-width)/2;
  199. var y = (size.y-height)/2;
  200. if (x<0) x = 0;
  201. if (y<0) y = 0;
  202. if (layout.mobile){
  203. x = 20;
  204. y = 0;
  205. }
  206. var _self = this;
  207. MWF.require("MWF.xDesktop.Dialog", function(){
  208. var dlg = new MWF.xDesktop.Dialog({
  209. "title": this.json.title || "select view",
  210. "style": options.style || "view",
  211. "top": y,
  212. "left": x-20,
  213. "fromTop":y,
  214. "fromLeft": x-20,
  215. "width": width,
  216. "height": height,
  217. "html": "",
  218. "maskNode": this.form.app.content,
  219. "container": this.form.app.content,
  220. "buttonList": [
  221. {
  222. "text": MWF.LP.process.button.ok,
  223. "action": function(){
  224. //if (callback) callback(_self.view.selectedItems);
  225. if (callback) callback(_self.view.getData());
  226. this.close();
  227. }
  228. },
  229. {
  230. "text": MWF.LP.process.button.cancel,
  231. "action": function(){this.close();}
  232. }
  233. ]
  234. });
  235. dlg.show();
  236. if (layout.mobile){
  237. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  238. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  239. if (backAction) backAction.addEvent("click", function(e){
  240. dlg.close();
  241. }.bind(this));
  242. if (okAction) okAction.addEvent("click", function(e){
  243. //if (callback) callback(this.view.selectedItems);
  244. if (callback) callback(this.view.getData());
  245. dlg.close();
  246. }.bind(this));
  247. }
  248. // MWF.xDesktop.requireApp("process.Xform", "widget.View", function(){
  249. // this.view = new MWF.xApplication.process.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  250. // }.bind(this));
  251. MWF.xDesktop.requireApp("process.Application", "Viewer", function(){
  252. this.view = new MWF.xApplication.process.Application.Viewer(dlg.content, viewJson);
  253. }.bind(this));
  254. }.bind(this));
  255. }
  256. },
  257. selectQueryView: function(callback){
  258. var viewData = this.json.queryView;
  259. if (viewData){
  260. var filter = null;
  261. if (this.json.filterList && this.json.filterList.length){
  262. filter = [];
  263. this.json.filterList.each(function(entry){
  264. entry.value = this.form.Macro.exec(entry.code.code, this);
  265. //delete entry.code;
  266. filter.push(entry);
  267. }.bind(this));
  268. }
  269. var viewJson = {
  270. "application": viewData.appName,
  271. "viewName": viewData.name,
  272. "viewId": viewData.id,
  273. "isTitle": this.json.isTitle || "yes",
  274. "select": this.json.select || "single",
  275. "titleStyles": this.json.titleStyles,
  276. "itemStyles": this.json.itemStyles,
  277. "isExpand": this.json.isExpand || "no",
  278. "showActionbar" : this.json.actionbar === "show",
  279. "filter": filter,
  280. "defaultSelectedScript" : this.json.defaultSelectedScript ? this.json.defaultSelectedScript.code : null,
  281. "selectedAbleScript" : this.json.selectedAbleScript ? this.json.selectedAbleScript.code : null
  282. };
  283. var options = {};
  284. var width = options.width || "850";
  285. var height = options.height || "700";
  286. if (layout.mobile){
  287. var size = document.body.getSize();
  288. width = size.x;
  289. height = size.y;
  290. options.style = "viewmobile";
  291. }
  292. width = width.toInt();
  293. height = height.toInt();
  294. var size = this.form.app.content.getSize();
  295. var x = (size.x-width)/2;
  296. var y = (size.y-height)/2;
  297. if (x<0) x = 0;
  298. if (y<0) y = 0;
  299. if (layout.mobile){
  300. x = 20;
  301. y = 0;
  302. }
  303. var _self = this;
  304. MWF.require("MWF.xDesktop.Dialog", function(){
  305. var dlg = new MWF.xDesktop.Dialog({
  306. "title": this.json.title || "select view",
  307. "style": options.style || "view",
  308. "top": y,
  309. "left": x-20,
  310. "fromTop":y,
  311. "fromLeft": x-20,
  312. "width": width,
  313. "height": height,
  314. "html": "",
  315. "maskNode": layout.mobile?$(document.body) : this.form.app.content,
  316. "container": layout.mobile?$(document.body) : this.form.app.content,
  317. "buttonList": [
  318. {
  319. "text": MWF.LP.process.button.ok,
  320. "action": function(){
  321. //if (callback) callback(_self.view.selectedItems);
  322. if (callback) callback(_self.view.getData());
  323. this.close();
  324. }
  325. },
  326. {
  327. "text": MWF.LP.process.button.cancel,
  328. "action": function(){this.close();}
  329. }
  330. ],
  331. "onPostShow": function(){
  332. if(layout.mobile){
  333. dlg.node.setStyle("z-index",200);
  334. }
  335. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  336. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content, viewJson, {"style": "select"}, this.form.app, this.form.Macro );
  337. }.bind(this));
  338. }.bind(this)
  339. });
  340. dlg.show();
  341. if (layout.mobile){
  342. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  343. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  344. if (backAction) backAction.addEvent("click", function(e){
  345. dlg.close();
  346. }.bind(this));
  347. if (okAction) okAction.addEvent("click", function(e){
  348. //if (callback) callback(this.view.selectedItems);
  349. if (callback) callback(this.view.getData());
  350. dlg.close();
  351. }.bind(this));
  352. }
  353. // MWF.xDesktop.requireApp("process.Xform", "widget.View", function(){
  354. // this.view = new MWF.xApplication.process.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  355. // }.bind(this));
  356. // MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  357. // this.view = new MWF.xApplication.query.Query.Viewer(dlg.content, viewJson, {"style": "select"});
  358. // }.bind(this));
  359. }.bind(this));
  360. }
  361. },
  362. selectView: function(callback){
  363. if (this.json.queryView){
  364. this.selectQueryView(callback);
  365. }else{
  366. if (this.json.selectViewType==="cms"){
  367. this.selectCMSView(callback);
  368. }else{
  369. this.selectProcessView(callback);
  370. }
  371. }
  372. }
  373. });