ViewSelector.js 16 KB

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