ViewSelector.js 16 KB

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