ViewSelector.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. "filter": filter
  69. };
  70. var options = {};
  71. var width = options.width || "800";
  72. var height = options.height || "450";
  73. var size;
  74. if (layout.mobile){
  75. size = document.body.getSize();
  76. width = size.x;
  77. height = size.y;
  78. options.style = "viewmobile";
  79. }
  80. width = width.toInt();
  81. height = height.toInt();
  82. size = this.form.app.content.getSize();
  83. var x = (size.x-width)/2;
  84. var y = (size.y-height)/2;
  85. if (x<0) x = 0;
  86. if (y<0) y = 0;
  87. if (layout.mobile){
  88. x = 20;
  89. y = 0;
  90. }
  91. var _self = this;
  92. MWF.require("MWF.xDesktop.Dialog", function(){
  93. var dlg = new MWF.xDesktop.Dialog({
  94. "title": this.json.title || "select view",
  95. "style": options.style || "view",
  96. "top": y,
  97. "left": x-20,
  98. "fromTop":y,
  99. "fromLeft": x-20,
  100. "width": width,
  101. "height": height,
  102. "html": "<div></div>",
  103. "maskNode": this.form.app.content,
  104. "container": this.form.app.content,
  105. "buttonList": [
  106. {
  107. "text": MWF.LP.process.button.ok,
  108. "action": function(){
  109. //if (callback) callback(_self.view.selectedItems);
  110. if (callback) callback(_self.view.getData());
  111. this.close();
  112. }
  113. },
  114. {
  115. "text": MWF.LP.process.button.cancel,
  116. "action": function(){this.close();}
  117. }
  118. ]
  119. });
  120. dlg.show();
  121. if (layout.mobile){
  122. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  123. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  124. if (backAction) backAction.addEvent("click", function(e){
  125. dlg.close();
  126. }.bind(this));
  127. if (okAction) okAction.addEvent("click", function(e){
  128. //if (callback) callback(this.view.selectedItems);
  129. if (callback) callback(this.view.getData());
  130. dlg.close();
  131. }.bind(this));
  132. }
  133. // MWF.xDesktop.requireApp("process.Xform", "widget.CMSView", function(){
  134. // this.view = new MWF.xApplication.process.Xform.widget.CMSView(dlg.content.getFirst(), viewJson, {"style": "select"});
  135. // }.bind(this));
  136. MWF.xDesktop.requireApp("process.Application", "Viewer", function(){
  137. this.view = new MWF.xApplication.process.Application.Viewer(dlg.content, viewJson, {
  138. "actions": {
  139. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  140. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  141. },
  142. "actionRoot": "x_cms_assemble_control"
  143. });
  144. }.bind(this));
  145. }.bind(this));
  146. }
  147. },
  148. selectProcessView: function(callback){
  149. var viewData = this.json.processViewName;
  150. if (viewData){
  151. var filter = null;
  152. if (this.json.filterList && this.json.filterList.length){
  153. filter = [];
  154. this.json.filterList.each(function(entry){
  155. entry.value = this.form.Macro.exec(entry.code.code, this);
  156. //delete entry.code;
  157. filter.push(entry);
  158. }.bind(this));
  159. }
  160. var viewJson = {
  161. "application": viewData.application,
  162. "viewName": viewData.name,
  163. "isTitle": this.json.isTitle || "yes",
  164. "select": this.json.select || "single",
  165. "titleStyles": this.json.titleStyles,
  166. "itemStyles": this.json.itemStyles,
  167. "isExpand": this.json.isExpand || "no",
  168. "filter": filter
  169. };
  170. var options = {};
  171. var width = options.width || "800";
  172. var height = options.height || "600";
  173. var size;
  174. if (layout.mobile){
  175. size = document.body.getSize();
  176. width = size.x;
  177. height = size.y;
  178. options.style = "viewmobile";
  179. }
  180. width = width.toInt();
  181. height = height.toInt();
  182. size = this.form.app.content.getSize();
  183. var x = (size.x-width)/2;
  184. var y = (size.y-height)/2;
  185. if (x<0) x = 0;
  186. if (y<0) y = 0;
  187. if (layout.mobile){
  188. x = 20;
  189. y = 0;
  190. }
  191. var _self = this;
  192. MWF.require("MWF.xDesktop.Dialog", function(){
  193. var dlg = new MWF.xDesktop.Dialog({
  194. "title": this.json.title || "select view",
  195. "style": options.style || "view",
  196. "top": y,
  197. "left": x-20,
  198. "fromTop":y,
  199. "fromLeft": x-20,
  200. "width": width,
  201. "height": height,
  202. "html": "",
  203. "maskNode": this.form.app.content,
  204. "container": this.form.app.content,
  205. "buttonList": [
  206. {
  207. "text": MWF.LP.process.button.ok,
  208. "action": function(){
  209. //if (callback) callback(_self.view.selectedItems);
  210. if (callback) callback(_self.view.getData());
  211. this.close();
  212. }
  213. },
  214. {
  215. "text": MWF.LP.process.button.cancel,
  216. "action": function(){this.close();}
  217. }
  218. ]
  219. });
  220. dlg.show();
  221. if (layout.mobile){
  222. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  223. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  224. if (backAction) backAction.addEvent("click", function(e){
  225. dlg.close();
  226. }.bind(this));
  227. if (okAction) okAction.addEvent("click", function(e){
  228. //if (callback) callback(this.view.selectedItems);
  229. if (callback) callback(this.view.getData());
  230. dlg.close();
  231. }.bind(this));
  232. }
  233. // MWF.xDesktop.requireApp("process.Xform", "widget.View", function(){
  234. // this.view = new MWF.xApplication.process.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  235. // }.bind(this));
  236. MWF.xDesktop.requireApp("process.Application", "Viewer", function(){
  237. this.view = new MWF.xApplication.process.Application.Viewer(dlg.content, viewJson);
  238. }.bind(this));
  239. }.bind(this));
  240. }
  241. },
  242. selectQueryView: function(callback){
  243. var viewData = this.json.queryView;
  244. if (viewData){
  245. var filter = null;
  246. if (this.json.filterList && this.json.filterList.length){
  247. filter = [];
  248. this.json.filterList.each(function(entry){
  249. entry.value = this.form.Macro.exec(entry.code.code, this);
  250. //delete entry.code;
  251. filter.push(entry);
  252. }.bind(this));
  253. }
  254. var viewJson = {
  255. "application": viewData.appName,
  256. "viewName": viewData.name,
  257. "viewId": viewData.id,
  258. "isTitle": this.json.isTitle || "yes",
  259. "select": this.json.select || "single",
  260. "titleStyles": this.json.titleStyles,
  261. "itemStyles": this.json.itemStyles,
  262. "isExpand": this.json.isExpand || "no",
  263. "filter": filter
  264. };
  265. var options = {};
  266. var width = options.width || "800";
  267. var height = options.height || "600";
  268. if (layout.mobile){
  269. var size = document.body.getSize();
  270. width = size.x;
  271. height = size.y;
  272. options.style = "viewmobile";
  273. }
  274. width = width.toInt();
  275. height = height.toInt();
  276. var size = this.form.app.content.getSize();
  277. var x = (size.x-width)/2;
  278. var y = (size.y-height)/2;
  279. if (x<0) x = 0;
  280. if (y<0) y = 0;
  281. if (layout.mobile){
  282. x = 20;
  283. y = 0;
  284. }
  285. var _self = this;
  286. MWF.require("MWF.xDesktop.Dialog", function(){
  287. var dlg = new MWF.xDesktop.Dialog({
  288. "title": this.json.title || "select view",
  289. "style": options.style || "view",
  290. "top": y,
  291. "left": x-20,
  292. "fromTop":y,
  293. "fromLeft": x-20,
  294. "width": width,
  295. "height": height,
  296. "html": "",
  297. "maskNode": this.form.app.content,
  298. "container": this.form.app.content,
  299. "buttonList": [
  300. {
  301. "text": MWF.LP.process.button.ok,
  302. "action": function(){
  303. //if (callback) callback(_self.view.selectedItems);
  304. if (callback) callback(_self.view.getData());
  305. this.close();
  306. }
  307. },
  308. {
  309. "text": MWF.LP.process.button.cancel,
  310. "action": function(){this.close();}
  311. }
  312. ],
  313. "onPostShow": function(){
  314. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  315. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content, viewJson, {"style": "select"});
  316. }.bind(this));
  317. }.bind(this)
  318. });
  319. dlg.show();
  320. if (layout.mobile){
  321. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  322. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  323. if (backAction) backAction.addEvent("click", function(e){
  324. dlg.close();
  325. }.bind(this));
  326. if (okAction) okAction.addEvent("click", function(e){
  327. //if (callback) callback(this.view.selectedItems);
  328. if (callback) callback(this.view.getData());
  329. dlg.close();
  330. }.bind(this));
  331. }
  332. // MWF.xDesktop.requireApp("process.Xform", "widget.View", function(){
  333. // this.view = new MWF.xApplication.process.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  334. // }.bind(this));
  335. // MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  336. // this.view = new MWF.xApplication.query.Query.Viewer(dlg.content, viewJson, {"style": "select"});
  337. // }.bind(this));
  338. }.bind(this));
  339. }
  340. },
  341. selectView: function(callback){
  342. if (this.json.queryView){
  343. this.selectQueryView(callback);
  344. }else{
  345. if (this.json.selectViewType==="cms"){
  346. this.selectCMSView(callback);
  347. }else{
  348. this.selectProcessView(callback);
  349. }
  350. }
  351. }
  352. });