View.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. MWF.xApplication.process.Xform.widget = MWF.xApplication.process.Xform.widget || {};
  2. MWF.require("MWF.widget.Common", null, false);
  3. MWF.xApplication.process.Xform.widget.View = new Class({
  4. Implements: [Options, Events],
  5. Extends: MWF.widget.Common,
  6. options: {
  7. "style": "default"
  8. },
  9. initialize: function(container, json, options){
  10. this.setOptions(options);
  11. this.path = "/x_component_process_Xform/widget/$View/";
  12. this.cssPath = "/x_component_process_Xform/widget/$View/"+this.options.style+"/css.wcss";
  13. this._loadCss();
  14. this.container = $(container);
  15. this.items = [];
  16. this.selectedItems = [];
  17. this.json = json;
  18. this.viewJson = null;
  19. this.gridJson = null;
  20. this.load();
  21. },
  22. load: function(){
  23. debugger;
  24. this.container.empty();
  25. this.container.setStyles(this.css.viewNode);
  26. this.createViewNode();
  27. },
  28. createViewNode: function(){
  29. this.viewTable = new Element("table", {
  30. "styles": this.css.viewTitleTableNode,
  31. "border": "0px",
  32. "cellPadding": "0",
  33. "cellSpacing": "0"
  34. }).inject(this.container);
  35. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.container);
  36. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  37. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  38. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  39. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  40. loadingTextNode.set("text", "loading...");
  41. if (this.json.isTitle!="no"){
  42. this.viewTitleLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
  43. //if (this.json.select!="no"){
  44. this.selectTitleCell = new Element("td", {
  45. "styles": this.css.viewTitleCellNode
  46. }).inject(this.viewTitleLine);
  47. this.selectTitleCell.setStyle("width", "10px");
  48. if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
  49. //}
  50. this.getView(function(){
  51. this.viewJson.selectEntryList.each(function(column){
  52. //if (column.export){
  53. var viewCell = new Element("td", {
  54. "styles": this.css.viewTitleCellNode,
  55. "text": column.displayName
  56. }).inject(this.viewTitleLine);
  57. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  58. //}
  59. }.bind(this));
  60. this.lookup();
  61. }.bind(this));
  62. }else{
  63. this.getView(function(){
  64. this.lookup();
  65. }.bind(this));
  66. //this.lookup();
  67. }
  68. },
  69. lookup: function(){
  70. this.getLookupAction(function(){
  71. if (this.json.application){
  72. this.lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": this.json.viewName, "application": this.json.application},"success": function(json){
  73. if (this.viewJson.groupEntry.column){
  74. this.gridJson = json.data.groupGrid;
  75. this.loadGroupData();
  76. }else{
  77. this.gridJson = json.data.grid;
  78. this.loadData();
  79. }
  80. if (this.loadingAreaNode){
  81. this.loadingAreaNode.destroy();
  82. this.loadingAreaNode = null;
  83. }
  84. //if (json.data.length){
  85. // json.data.each(function(line, idx){
  86. // this.items.push(new MWF.xApplication.process.Xform.widget.View.Item(this, line));
  87. // }.bind(this));
  88. //}
  89. }.bind(this)});
  90. }else{
  91. //this.lookupAction.invoke({"name": "lookup","async": true, "parameter": {"id": this.json.view},"success": function(json){
  92. // if (json.data.length){
  93. // json.data.each(function(line, idx){
  94. // this.items.push(new MWF.xApplication.process.Xform.widget.View.Item(this, line));
  95. // }.bind(this));
  96. // }
  97. //}.bind(this)});
  98. }
  99. }.bind(this));
  100. },
  101. loadData: function(){
  102. if (this.gridJson.length){
  103. this.gridJson.each(function(line, idx){
  104. this.items.push(new MWF.xApplication.process.Xform.widget.View.Item(this, line));
  105. }.bind(this));
  106. }
  107. },
  108. loadGroupData: function(){
  109. if (this.selectTitleCell){
  110. this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='/x_component_process_Xform/widget/$View/"+this.options.style+"/icon/right.png'/>"+"</span>");
  111. this.selectTitleCell.setStyle("cursor", "pointer");
  112. this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
  113. }
  114. if (this.gridJson.length){
  115. this.gridJson.each(function(data, idx){
  116. this.items.push(new MWF.xApplication.process.Xform.widget.View.ItemCategory(this, data));
  117. }.bind(this));
  118. }
  119. },
  120. expandOrCollapseAll: function(){
  121. var icon = this.selectTitleCell.getElement("span");
  122. if (icon.get("html").indexOf("right.png")==-1){
  123. this.items.each(function(item){
  124. item.collapse();
  125. icon.set("html", "<img src='/x_component_process_Xform/widget/$View/"+this.options.style+"/icon/right.png'/>");
  126. }.bind(this));
  127. }else{
  128. this.items.each(function(item, i){
  129. window.setTimeout(function(){
  130. item.expand();
  131. }.bind(this), 10*i+5);
  132. icon.set("html", "<img src='/x_component_process_Xform/widget/$View/"+this.options.style+"/icon/down.png'/>");
  133. }.bind(this));
  134. }
  135. },
  136. getView: function(callback){
  137. this.getLookupAction(function(){
  138. if (this.json.application){
  139. this.lookupAction.invoke({"name": "getView","async": true, "parameter": {"view": this.json.viewName, "application": this.json.application},"success": function(json){
  140. this.viewJson = JSON.decode(json.data.data);
  141. //var viewData = JSON.decode(json.data.data);
  142. if (callback) callback();
  143. }.bind(this)});
  144. }else{
  145. //this.lookupAction.invoke({"name": "getView","async": true, "parameter": {"id": this.json.view},"success": function(json){
  146. // var viewData = JSON.decode(json.data.data);
  147. // viewData.columnList.each(function(column){
  148. // if (column.export){
  149. // var viewCell = new Element("td", {
  150. // "styles": this.css.viewTitleCellNode,
  151. // "text": column.text
  152. // }).inject(this.viewTitleLine);
  153. // if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  154. // }
  155. // }.bind(this));
  156. //
  157. // if (callback) callback();
  158. //}.bind(this)});
  159. }
  160. }.bind(this));
  161. },
  162. getLookupAction: function(callback){
  163. if (!this.lookupAction){
  164. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  165. this.lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  166. this.lookupAction.getActions = function(actionCallback){
  167. this.actions = {
  168. //"lookup": {"uri": "/jaxrs/view/{id}"},
  169. //"lookupName": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  170. //"getView": {"uri": "/jaxrs/view/{id}/design"},
  171. //"getViewName": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}/design"}
  172. //"lookup": {"uri": "/jaxrs/view/{id}"},
  173. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  174. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  175. //"getViewName": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}/design"}
  176. };
  177. if (actionCallback) actionCallback();
  178. }
  179. if (callback) callback();
  180. }.bind(this));
  181. }else{
  182. if (callback) callback();
  183. }
  184. },
  185. getData: function(){
  186. if (this.selectedItems.length){
  187. var arr = [];
  188. this.selectedItems.each(function(item){
  189. arr.push(item.data);
  190. });
  191. return arr;
  192. }else{
  193. return [];
  194. }
  195. }
  196. });
  197. MWF.xApplication.process.Xform.widget.View.Item = new Class({
  198. initialize: function(view, data, prev){
  199. this.view = view;
  200. this.data = data;
  201. this.css = this.view.css;
  202. this.isSelected = false;
  203. this.prev = prev;
  204. this.load();
  205. },
  206. load: function(){
  207. this.node = new Element("tr", {"styles": this.css.viewContentTrNode});
  208. if (this.prev){
  209. this.node.inject(this.prev.node, "after");
  210. }else{
  211. this.node.inject(this.view.viewTable);
  212. }
  213. //if (this.view.json.select!="no"){
  214. this.selectTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  215. //if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  216. this.selectTd.setStyles({"cursor": "pointer"});
  217. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  218. //}
  219. Object.each(this.data.data, function(cell, k){
  220. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  221. if (k!= this.view.viewJson.groupEntry.column) td.set("text", cell);
  222. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  223. }.bind(this));
  224. //this.data.each(function(cell, i){
  225. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  226. // td.set("text", cell);
  227. // //if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  228. //}.bind(this));
  229. this.setEvent();
  230. },
  231. setEvent: function(){
  232. if (this.view.json.select!="no"){
  233. this.node.addEvents({
  234. "mouseover": function(){
  235. if (!this.isSelected){
  236. var iconName = "checkbox";
  237. if (this.view.json.select=="single") iconName = "radiobox";
  238. this.selectTd.setStyles({"background": "url("+"/x_component_process_Xform/$Form/default/icon/"+iconName+".png) center center no-repeat"});
  239. }
  240. }.bind(this),
  241. "mouseout": function(){
  242. if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
  243. }.bind(this),
  244. "click": function(){this.select();}.bind(this)
  245. });
  246. }
  247. },
  248. select: function(){
  249. if (this.isSelected){
  250. if (this.view.json.select=="single"){
  251. this.unSelectedSingle();
  252. }else{
  253. this.unSelected();
  254. }
  255. }else{
  256. if (this.view.json.select=="single"){
  257. this.selectedSingle();
  258. }else{
  259. this.selected();
  260. }
  261. }
  262. this.view.fireEvent("select");
  263. },
  264. selected: function(){
  265. this.view.selectedItems.push(this);
  266. this.selectTd.setStyles({"background": "url("+"/x_component_process_Xform/$Form/default/icon/checkbox_checked.png) center center no-repeat"});
  267. this.node.setStyles(this.css.viewContentTrNode_selected);
  268. this.isSelected = true;
  269. },
  270. unSelected: function(){
  271. this.view.selectedItems.erase(this);
  272. this.selectTd.setStyles({"background": "transparent"});
  273. this.node.setStyles(this.css.viewContentTrNode);
  274. this.isSelected = false;
  275. },
  276. selectedSingle: function(){
  277. if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
  278. this.view.selectedItems = [this];
  279. this.view.currentSelectedItem = this;
  280. this.selectTd.setStyles({"background": "url("+"/x_component_process_Xform/$Form/default/icon/radiobox_checked.png) center center no-repeat"});
  281. this.node.setStyles(this.css.viewContentTrNode_selected);
  282. this.isSelected = true;
  283. },
  284. unSelectedSingle: function(){
  285. this.view.selectedItems = [];
  286. this.view.currentSelectedItem = null;
  287. this.selectTd.setStyles({"background": "transparent"});
  288. this.node.setStyles(this.css.viewContentTrNode);
  289. this.isSelected = false;
  290. }
  291. });
  292. MWF.xApplication.process.Xform.widget.View.ItemCategory = new Class({
  293. initialize: function(view, data){
  294. this.view = view;
  295. this.data = data;
  296. this.css = this.view.css;
  297. this.items = [];
  298. this.loadChild = false;
  299. this.load();
  300. },
  301. load: function(){
  302. this.node = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.view.viewTable);
  303. //if (this.view.json.select!="no"){
  304. this.selectTd = new Element("td", {"styles": this.css.viewContentCategoryTdNode}).inject(this.node);
  305. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  306. //}
  307. this.categoryTd = new Element("td", {
  308. "styles": this.css.viewContentCategoryTdNode,
  309. "colspan": this.view.viewJson.selectEntryList.length
  310. }).inject(this.node);
  311. //this.categoryIconNode = new Element("div", {"styles": this.css.viewContentCategoryIconNode}).inject(this.categoryTd);
  312. this.categoryTd.set("html", "<span style='font-family: Webdings'><img src='/x_component_process_Xform/widget/$View/"+this.view.options.style+"/icon/right.png'/></span> "+this.data.group);
  313. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  314. //this.data.list.each(function(line){
  315. // this.items.push(new MWF.xApplication.process.Xform.widget.View.Item(this.view, line));
  316. //}.bind(this));
  317. this.setEvent();
  318. },
  319. setEvent: function(){
  320. if (this.selectTd){
  321. this.node.addEvents({
  322. //"mouseover": function(){
  323. // if (!this.isSelected){
  324. // var iconName = "checkbox";
  325. // if (this.view.json.select=="single") iconName = "radiobox";
  326. // this.selectTd.setStyles({"background": "url("+"/x_component_process_Xform/$Form/default/icon/"+iconName+".png) center center no-repeat"});
  327. // }
  328. //}.bind(this),
  329. //"mouseout": function(){
  330. // if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
  331. //}.bind(this),
  332. "click": function(){this.expandOrCollapse();}.bind(this)
  333. });
  334. }
  335. },
  336. expandOrCollapse: function(){
  337. var t = this.node.getElement("span").get("html");
  338. if (t.indexOf("right.png")==-1){
  339. this.collapse();
  340. }else{
  341. this.expand();
  342. }
  343. },
  344. collapse: function(){
  345. this.items.each(function(item){
  346. item.node.setStyle("display", "none");
  347. }.bind(this));
  348. this.node.getElement("span").set("html", "<img src='/x_component_process_Xform/widget/$View/"+this.view.options.style+"/icon/right.png'/>");
  349. },
  350. expand: function(){
  351. this.items.each(function(item){
  352. item.node.setStyle("display", "table-row");
  353. }.bind(this));
  354. this.node.getElement("span").set("html", "<img src='/x_component_process_Xform/widget/$View/"+this.view.options.style+"/icon/down.png'/>");
  355. if (!this.loadChild){
  356. //window.setTimeout(function(){
  357. this.data.list.each(function(line){
  358. this.items.push(new MWF.xApplication.process.Xform.widget.View.Item(this.view, line, this));
  359. }.bind(this));
  360. this.loadChild = true;
  361. //}.bind(this), 10);
  362. }
  363. }
  364. });