ViewSelector.js 15 KB

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