Viewer.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. MWF.xApplication.query = MWF.xApplication.query || {};
  2. MWF.xApplication.query.Query = MWF.xApplication.query.Query || {};
  3. MWF.require("MWF.widget.Common", null, false);
  4. MWF.require("MWF.xScript.Macro", null, false);
  5. MWF.xDesktop.requireApp("query.Query", "lp.zh-cn", null, false);
  6. MWF.xApplication.query.Query.Viewer = MWF.QViewer = new Class({
  7. Implements: [Options, Events],
  8. Extends: MWF.widget.Common,
  9. options: {
  10. "style": "default",
  11. "resizeNode": true,
  12. "paging" : "scroll",
  13. "perPageCount" : 50,
  14. "isload": "true",
  15. "export": false
  16. // "actions": {
  17. // "lookup": {"uri": "/jaxrs/view/flag/{view}/query/{application}/execute", "method":"PUT"},
  18. // "getView": {"uri": "/jaxrs/view/flag/{view}/query/{application}"}
  19. //
  20. // },
  21. // "actionRoot": "x_query_assemble_surface"
  22. },
  23. initialize: function(container, json, options){
  24. this.setOptions(options);
  25. this.path = "/x_component_query_Query/$Viewer/";
  26. this.cssPath = "/x_component_query_Query/$Viewer/"+this.options.style+"/css.wcss";
  27. this._loadCss();
  28. this.lp = MWF.xApplication.query.Query.LP;
  29. this.container = $(container);
  30. this.json = json;
  31. this.viewJson = null;
  32. this.filterItems = [];
  33. this.searchStatus = "none"; //none, custom, default
  34. this.items = [];
  35. this.selectedItems = [];
  36. this.hideColumns = [];
  37. this.openColumns = [];
  38. this.gridJson = null;
  39. if (this.options.isload){
  40. this.init(function(){
  41. this.load();
  42. }.bind(this));
  43. }
  44. },
  45. loadView: function(){
  46. if (this.viewJson){
  47. this.reload();
  48. }else{
  49. this.init(function(){
  50. this.load();
  51. }.bind(this));
  52. }
  53. },
  54. init: function(callback){
  55. if (this.json.data){
  56. this.viewJson = JSON.decode(this.json.data);
  57. if (callback) callback();
  58. }else{
  59. this.getView(callback);
  60. }
  61. },
  62. load: function(){
  63. this.loadLayout();
  64. this.createExportNode();
  65. this.createSearchNode();
  66. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  67. if (this.options.resizeNode){
  68. this.setContentHeightFun = this.setContentHeight.bind(this);
  69. this.container.addEvent("resize", this.setContentHeightFun);
  70. this.setContentHeightFun();
  71. }
  72. },
  73. loadLayout: function(){
  74. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  75. if (this.options.export) this.exportAreaNode = new Element("div", {"styles": this.css.exportAreaNode}).inject(this.node);
  76. this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.node);
  77. this.viewAreaNode = new Element("div", {"styles": this.css.viewAreaNode}).inject(this.node);
  78. },
  79. createExportNode: function(){
  80. if (this.options.export){
  81. MWF.require("MWF.widget.Toolbar", function(){
  82. this.toolbar = new MWF.widget.Toolbar(this.exportAreaNode, {"style": "simple"}, this);
  83. var actionNode = new Element("div", {
  84. "id": "",
  85. "MWFnodetype": "MWFToolBarButton",
  86. "MWFButtonImage": this.path+""+this.options.style+"/icon/export.png",
  87. "title": this.lp.exportExcel,
  88. "MWFButtonAction": "exportView",
  89. "MWFButtonText": this.lp.exportExcel
  90. }).inject(this.exportAreaNode);
  91. this.toolbar.load();
  92. }.bind(this));
  93. //this.exportNode = new Element("button", {"text": this.lp.exportExcel}).inject(this.exportAreaNode);
  94. }
  95. },
  96. exportView: function(){
  97. var action = MWF.Actions.get("x_query_assemble_surface");
  98. var filterData = this.json.filter ? this.json.filter.clone() : [];
  99. if (this.filterItems.length){
  100. this.filterItems.each(function(filter){
  101. filterData.push(filter.data);
  102. }.bind(this));
  103. }
  104. action.exportViewWithQuery(this.json.viewName, this.json.application, {"filterList": filterData}, function(json){
  105. var uri = action.action.actions.getViewExcel.uri;
  106. uri = uri.replace("{flag}", json.data.id);
  107. uri = action.action.address+uri;
  108. var a = new Element("a", {"href": uri, "target":"_blank"});
  109. a.click();
  110. a.destroy();
  111. }.bind(this));
  112. },
  113. createSearchNode: function(){
  114. if (this.viewJson.customFilterList && this.viewJson.customFilterList.length){
  115. this.searchStatus = "default";
  116. this.loadFilterSearch();
  117. }else{
  118. this.loadSimpleSearch();
  119. }
  120. },
  121. loadSimpleSearch: function(){
  122. this.searchSimpleNode = new Element("div", {"styles": this.css.searchSimpleNode}).inject(this.searchAreaNode);
  123. this.searchSimpleButtonNode = new Element("div", {"styles": this.css.searchSimpleButtonNode}).inject(this.searchSimpleNode);
  124. this.searchSimpleInputNode = new Element("input", {"type":"text", "styles": this.css.searchSimpleInputNode, "value": this.lp.searchKeywork}).inject(this.searchSimpleNode);
  125. this.searchSimpleButtonNode.addEvent("click", function(){
  126. this.search();
  127. }.bind(this));
  128. this.searchSimpleInputNode.addEvents({
  129. "focus": function(){
  130. if (this.searchSimpleInputNode.get("value")===this.lp.searchKeywork) this.searchSimpleInputNode.set("value", "");
  131. }.bind(this),
  132. "blur": function(){if (!this.searchSimpleInputNode.get("value")) this.searchSimpleInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  133. "keydown": function(e){
  134. if (e.code===13) this.search();
  135. }.bind(this)
  136. });
  137. },
  138. search: function(){
  139. if (this.gridJson){
  140. var key = this.searchSimpleInputNode.get("value");
  141. var rows = this.viewTable.rows;
  142. var first = (this.json.isTitle!=="no") ? 1 : 0;
  143. for (var i = first; i<rows.length; i++){
  144. var tr = rows[i];
  145. if (!key || key==this.lp.searchKeywork){
  146. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  147. }else{
  148. if (tr.get("text").indexOf(key)!==-1){
  149. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  150. }else{
  151. if (tr.getStyle("display")!=="none") tr.setStyle("display", "none");
  152. }
  153. }
  154. }
  155. }
  156. },
  157. loadFilterSearch: function(){
  158. this.viewSearchCustomActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomActionNode, "text": this.lp.customSearch}).inject(this.searchAreaNode);
  159. this.viewSearchInputAreaNode = new Element("div", {"styles": this.css.viewFilterSearchInputAreaNode}).inject(this.searchAreaNode);
  160. this.viewSearchIconNode = new Element("div", {"styles": this.css.viewFilterSearchIconNode}).inject(this.viewSearchInputAreaNode);
  161. this.viewSearchInputBoxNode = new Element("div", {"styles": this.css.viewFilterSearchInputBoxNode}).inject(this.viewSearchInputAreaNode);
  162. this.viewSearchInputNode = new Element("input", {"styles": this.css.viewFilterSearchInputNode, "value": this.lp.searchKeywork}).inject(this.viewSearchInputBoxNode);
  163. this.viewSearchInputNode.addEvents({
  164. "focus": function(){
  165. if (this.viewSearchInputNode.get("value")===this.lp.searchKeywork) this.viewSearchInputNode.set("value", "");
  166. }.bind(this),
  167. "blur": function(){if (!this.viewSearchInputNode.get("value")) this.viewSearchInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  168. "keydown": function(e){
  169. if (e.code===13) this.searchView();
  170. }.bind(this)
  171. });
  172. this.viewSearchIconNode.addEvents({
  173. "click": function(){this.searchView();}.bind(this)
  174. });
  175. this.viewSearchCustomActionNode.addEvents({
  176. "click": function(){this.loadCustomSearch();}.bind(this)
  177. });
  178. },
  179. searchView: function(){
  180. if (this.viewJson.customFilterList){
  181. var key = this.viewSearchInputNode.get("value");
  182. if (key && key!==this.lp.searchKeywork){
  183. var filterData = this.json.filter ? this.json.filter : [];
  184. this.viewJson.customFilterList.each(function(entry){
  185. if (entry.formatType==="textValue"){
  186. var d = {
  187. "path": entry.path,
  188. "value": key,
  189. "formatType": entry.formatType,
  190. "logic": "or",
  191. "comparison": "like"
  192. };
  193. filterData.push(d);
  194. }
  195. if (entry.formatType==="numberValue"){
  196. var v = key.toFloat();
  197. if (!isNaN(v)){
  198. var d = {
  199. "path": entry.path,
  200. "value": v,
  201. "formatType": entry.formatType,
  202. "logic": "or",
  203. "comparison": "like"
  204. };
  205. filterData.push(d);
  206. }
  207. }
  208. }.bind(this));
  209. this.createViewNode({"filterList": filterData});
  210. }
  211. }
  212. },
  213. searchCustomView: function(){
  214. if (this.filterItems.length){
  215. var filterData = this.json.filter ? this.json.filter.clone() : [];
  216. this.filterItems.each(function(filter){
  217. filterData.push(filter.data);
  218. }.bind(this));
  219. this.createViewNode({"filterList": filterData});
  220. }else{
  221. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  222. }
  223. },
  224. loadCustomSearch: function(){
  225. this.viewSearchIconNode.setStyle("display", "none");
  226. this.viewSearchInputBoxNode.setStyle("display", "none");
  227. this.viewSearchCustomActionNode.setStyle("display", "none");
  228. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  229. var x = this.viewSearchInputAreaNode.getParent().getSize().x-2-20;
  230. this.css.viewFilterSearchInputAreaNode_custom.width = ""+x+"px";
  231. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  232. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  233. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode_custom).chain(function(){
  234. this.searchStatus = "custom";
  235. this.css.viewFilterSearchInputAreaNode_custom.width = "auto";
  236. this.viewSearchInputAreaNode.setStyle("width", "auto");
  237. if (this.viewSearchCustomContentNode){
  238. this.viewSearchCustomCloseActionNode.setStyle("display", "block");
  239. this.viewSearchCustomContentNode.setStyle("display", "block");
  240. }else{
  241. this.loadCustomSearchContent();
  242. }
  243. this.setContentHeightFun();
  244. }.bind(this));
  245. this.searchCustomView();
  246. },
  247. loadCustomSearchContent: function(){
  248. this.viewSearchCustomCloseActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomCloseActionNode}).inject(this.viewSearchInputAreaNode);
  249. this.viewSearchCustomContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomContentNode}).inject(this.viewSearchInputAreaNode);
  250. this.viewSearchCustomPathContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomPathContentNode}).inject(this.viewSearchCustomContentNode);
  251. this.viewSearchCustomComparisonContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomComparisonContentNode}).inject(this.viewSearchCustomContentNode);
  252. this.viewSearchCustomValueContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomValueContentNode}).inject(this.viewSearchCustomContentNode);
  253. this.viewSearchCustomAddContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddContentNode}).inject(this.viewSearchCustomContentNode);
  254. this.viewSearchCustomAddIconNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddIconNode}).inject(this.viewSearchCustomAddContentNode);
  255. this.viewSearchCustomFilterContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomFilterContentNode}).inject(this.viewSearchCustomContentNode);
  256. this.loadViewSearchCustomList();
  257. this.viewSearchCustomCloseActionNode.addEvents({
  258. "click": function(){this.closeCustomSearch();}.bind(this)
  259. });
  260. this.viewSearchCustomAddIconNode.addEvents({
  261. "click": function(){this.viewSearchCustomAddToFilter();}.bind(this)
  262. });
  263. },
  264. loadViewSearchCustomList: function(){
  265. this.viewSearchCustomPathListNode = new Element("select", {
  266. "styles": this.css.viewFilterSearchCustomPathListNode,
  267. "multiple": true
  268. }).inject(this.viewSearchCustomPathContentNode);
  269. this.viewSearchCustomComparisonListNode = new Element("select", {
  270. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  271. "multiple": true
  272. }).inject(this.viewSearchCustomComparisonContentNode);
  273. this.viewJson.customFilterList.each(function(entry){
  274. var option = new Element("option", {
  275. "style": this.css.viewFilterSearchOptionNode,
  276. "value": entry.path,
  277. "text": entry.title
  278. }).inject(this.viewSearchCustomPathListNode);
  279. option.store("entry", entry);
  280. }.bind(this));
  281. this.viewSearchCustomPathListNode.addEvent("change", function(){
  282. this.loadViewSearchCustomComparisonList();
  283. }.bind(this));
  284. },
  285. loadViewSearchCustomComparisonList: function(){
  286. debugger;
  287. var idx = this.viewSearchCustomPathListNode.selectedIndex;
  288. var option = this.viewSearchCustomPathListNode.options[idx];
  289. var entry = option.retrieve("entry");
  290. if (entry){
  291. switch (entry.formatType){
  292. case "numberValue":
  293. this.loadComparisonSelect(this.lp.numberFilter);
  294. this.loadViewSearchCustomValueNumberInput();
  295. break;
  296. case "datetimeValue":
  297. this.loadComparisonSelect(this.lp.dateFilter);
  298. this.loadViewSearchCustomValueDateInput();
  299. break;
  300. case "booleanValue":
  301. this.loadComparisonSelect(this.lp.booleanFilter);
  302. this.loadViewSearchCustomValueBooleanInput();
  303. break;
  304. default:
  305. this.loadComparisonSelect(this.lp.textFilter);
  306. this.loadViewSearchCustomValueTextInput();
  307. }
  308. }
  309. },
  310. loadViewSearchCustomValueNumberInput: function(){
  311. this.viewSearchCustomValueContentNode.empty();
  312. this.viewSearchCustomValueNode = new Element("input", {
  313. "styles": this.css.viewFilterSearchCustomValueNode,
  314. "type": "number"
  315. }).inject(this.viewSearchCustomValueContentNode);
  316. },
  317. loadViewSearchCustomValueDateInput: function(){
  318. this.viewSearchCustomValueContentNode.empty();
  319. this.viewSearchCustomValueNode = new Element("input", {
  320. "styles": this.css.viewFilterSearchCustomValueNode,
  321. "type": "text",
  322. "readonly": true
  323. }).inject(this.viewSearchCustomValueContentNode);
  324. MWF.require("MWF.widget.Calendar", function(){
  325. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  326. "style": "xform",
  327. "isTime": true,
  328. "target": this.container,
  329. "format": "db"
  330. });
  331. }.bind(this));
  332. },
  333. loadViewSearchCustomValueBooleanInput: function(){
  334. this.viewSearchCustomValueContentNode.empty();
  335. this.viewSearchCustomValueNode = new Element("select", {
  336. "styles": this.css.viewFilterSearchCustomValueSelectNode,
  337. "multiple": true
  338. }).inject(this.viewSearchCustomValueContentNode);
  339. new Element("option", {"value": "true","text": this.lp.yes}).inject(this.viewSearchCustomValueNode);
  340. new Element("option", {"value": "false","text": this.lp.no}).inject(this.viewSearchCustomValueNode);
  341. },
  342. loadViewSearchCustomValueTextInput: function(){
  343. this.viewSearchCustomValueContentNode.empty();
  344. this.viewSearchCustomValueNode = new Element("textarea", {
  345. "styles": this.css.viewFilterSearchCustomValueNode
  346. }).inject(this.viewSearchCustomValueContentNode);
  347. },
  348. loadComparisonSelect:function(obj){
  349. this.viewSearchCustomComparisonListNode.empty();
  350. Object.each(obj, function(v, k){
  351. var option = new Element("option", {"value": k,"text": v}).inject(this.viewSearchCustomComparisonListNode);
  352. }.bind(this));
  353. },
  354. closeCustomSearch: function(){
  355. if (this.viewSearchCustomContentNode && this.viewSearchCustomContentNode.getStyle("display")==="block"){
  356. this.viewSearchCustomCloseActionNode.setStyle("display", "none");
  357. this.viewSearchCustomContentNode.setStyle("display", "none");
  358. var x = this.viewSearchInputAreaNode.getParent().getSize().x;
  359. x1 = x-2-10-90;
  360. this.css.viewFilterSearchInputAreaNode.width = ""+x1+"px";
  361. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  362. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  363. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  364. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode).chain(function(){
  365. this.searchStatus = "default";
  366. this.css.viewFilterSearchInputAreaNode.width = "auto";
  367. this.viewSearchInputAreaNode.setStyle("margin-right", "90px");
  368. this.viewSearchIconNode.setStyle("display", "block");
  369. this.viewSearchInputBoxNode.setStyle("display", "block");
  370. this.viewSearchCustomActionNode.setStyle("display", "block");
  371. this.setContentHeightFun();
  372. }.bind(this));
  373. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  374. }
  375. },
  376. viewSearchCustomAddToFilter: function(){
  377. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  378. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  379. if (pathIdx===-1){
  380. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  381. return false;
  382. }
  383. if (comparisonIdx===-1){
  384. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  385. return false;
  386. }
  387. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  388. var entry = pathOption.retrieve("entry");
  389. if (entry){
  390. var pathTitle = entry.title;
  391. var path = entry.path;
  392. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  393. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  394. var value = "";
  395. switch (entry.formatType){
  396. case "numberValue":
  397. value = this.viewSearchCustomValueNode.get("value");
  398. break;
  399. case "dateTimeValue":
  400. value = this.viewSearchCustomValueNode.get("value");
  401. break;
  402. case "booleanValue":
  403. var idx = this.viewSearchCustomValueNode.selectedIndex;
  404. if (idx!==-1){
  405. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  406. value = (v==="true");
  407. }
  408. break;
  409. default:
  410. value = this.viewSearchCustomValueNode.get("value");
  411. }
  412. if (value===""){
  413. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  414. return false;
  415. }
  416. this.filterItems.push(new MWF.xApplication.query.Query.Viewer.Filter(this, {
  417. "logic": "and",
  418. "path": path,
  419. "title": pathTitle,
  420. "comparison": comparison,
  421. "comparisonTitle": comparisonTitle,
  422. "value": value,
  423. "formatType": (entry.formatType=="datetimeValue") ? "dateTimeValue": entry.formatType
  424. }, this.viewSearchCustomFilterContentNode));
  425. this.searchCustomView();
  426. }
  427. },
  428. searchViewRemoveFilter: function(filter){
  429. this.filterItems.erase(filter);
  430. filter.destroy();
  431. this.searchCustomView()
  432. },
  433. setContentHeight: function(){
  434. var size = this.node.getSize();
  435. var searchSize = this.searchAreaNode.getComputedSize();
  436. var h = size.y-searchSize.totalHeight;
  437. if (this.exportAreaNode){
  438. var exportSize = this.exportAreaNode.getComputedSize();
  439. h = h-exportSize.totalHeight;
  440. }
  441. this.viewAreaNode.setStyle("height", ""+h+"px");
  442. },
  443. createLoadding: function(){
  444. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.contentAreaNode);
  445. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  446. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  447. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  448. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  449. loadingTextNode.set("text", "loading...");
  450. },
  451. createViewNode: function(data){
  452. this.viewAreaNode.empty();
  453. this.contentAreaNode = new Element("div", {"styles": this.css.contentAreaNode}).inject(this.viewAreaNode);
  454. this.viewTable = new Element("table", {
  455. "styles": this.css.viewTitleTableNode,
  456. "border": "0px",
  457. "cellPadding": "0",
  458. "cellSpacing": "0"
  459. }).inject(this.contentAreaNode);
  460. this.createLoadding();
  461. if (this.json.isTitle!=="no"){
  462. this.viewTitleLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
  463. //if (this.json.select==="single" || this.json.select==="multi") {
  464. this.selectTitleCell = new Element("td", {
  465. "styles": this.css.viewTitleCellNode
  466. }).inject(this.viewTitleLine);
  467. this.selectTitleCell.setStyle("width", "10px");
  468. if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
  469. //}
  470. this.entries = {};
  471. this.viewJson.selectList.each(function(column){
  472. this.entries[column.column] = column;
  473. if (!column.hideColumn){
  474. var viewCell = new Element("td", {
  475. "styles": this.css.viewTitleCellNode,
  476. "text": column.displayName
  477. }).inject(this.viewTitleLine);
  478. var size = MWF.getTextSize(column.displayName, this.css.viewTitleCellNode);
  479. viewCell.setStyle("min-width", ""+size.x+"px");
  480. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  481. }else{
  482. this.hideColumns.push(column.column);
  483. }
  484. if (column.allowOpen) this.openColumns.push(column.column);
  485. }.bind(this));
  486. this.lookup(data);
  487. }else{
  488. this.viewJson.selectList.each(function(column){
  489. if (column.hideColumn) this.hideColumns.push(column.column);
  490. if (!column.allowOpen) this.openColumns.push(column.column);
  491. }.bind(this));
  492. this.lookup(data);
  493. }
  494. },
  495. lookup: function(data){
  496. this.getLookupAction(function(){
  497. if (this.json.application){
  498. this.loadViewRes = this.lookupAction.loadView(this.json.name, this.json.application, (data || null), function(json){
  499. this.viewData = json.data;
  500. if (this.viewJson.group.column){
  501. this.gridJson = json.data.groupGrid;
  502. this.loadGroupData();
  503. }else{
  504. this.gridJson = json.data.grid;
  505. this.loadData();
  506. }
  507. if (this.loadingAreaNode){
  508. this.loadingAreaNode.destroy();
  509. this.loadingAreaNode = null;
  510. }
  511. this.fireEvent("loadView");
  512. }.bind(this));
  513. // this.lookupAction.invoke({"name": "lookup","async": true, "data": (data || null), "parameter": {"view": this.json.name, "application": this.json.application},"success": function(json){
  514. // this.viewData = json.data;
  515. // if (this.viewJson.group.column){
  516. // this.gridJson = json.data.groupGrid;
  517. // this.loadGroupData();
  518. // }else{
  519. // this.gridJson = json.data.grid;
  520. // this.loadData();
  521. // }
  522. // if (this.loadingAreaNode){
  523. // this.loadingAreaNode.destroy();
  524. // this.loadingAreaNode = null;
  525. // }
  526. // }.bind(this)});
  527. }
  528. }.bind(this));
  529. },
  530. loadData: function(){
  531. if (this.gridJson.length){
  532. if( !this.options.paging ){
  533. this.gridJson.each(function(line, i){
  534. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, line, null, i));
  535. }.bind(this));
  536. }else{
  537. this.loadPaging();
  538. }
  539. }
  540. },
  541. loadPaging : function(){
  542. this.isItemsLoading = false;
  543. this.pageNumber = 0;
  544. this.isItemsLoaded = false;
  545. this.isSetedScroll = false;
  546. this.setScroll();
  547. this.loadDataByPaging()
  548. },
  549. setScroll : function(){
  550. if( this.options.paging && !this.isSetedScroll ){
  551. this.contentAreaNode.setStyle("overflow","auto");
  552. this.scrollContainerFun = function(){
  553. var scrollSize = this.contentAreaNode.getScrollSize();
  554. var clientSize = this.contentAreaNode.getSize();
  555. var scrollHeight = scrollSize.y - clientSize.y;
  556. //alert( "clientSize.y=" + clientSize.y + " scrollSize.y="+scrollSize.y + " this.contentAreaNode.scrollTop="+this.contentAreaNode.scrollTop);
  557. if (this.contentAreaNode.scrollTop + 150 > scrollHeight ) {
  558. if (!this.isItemsLoaded) this.loadDataByPaging();
  559. }
  560. }.bind(this);
  561. this.isSetedScroll = true;
  562. this.contentAreaNode.addEvent("scroll", this.scrollContainerFun )
  563. }
  564. },
  565. loadDataByPaging : function(){
  566. if( this.isItemsLoading )return;
  567. if( !this.isItemsLoaded ){
  568. var from = Math.min( this.pageNumber * this.options.perPageCount , this.gridJson.length);
  569. var to = Math.min( ( this.pageNumber + 1 ) * this.options.perPageCount + 1 , this.gridJson.length);
  570. this.isItemsLoading = true;
  571. for( var i = from; i<to; i++ ){
  572. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, this.gridJson[i], null, i));
  573. }
  574. this.isItemsLoading = false;
  575. this.pageNumber ++;
  576. if( to == this.gridJson.length )this.isItemsLoaded = true;
  577. }
  578. },
  579. loadGroupData: function(){
  580. if (this.selectTitleCell){
  581. this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
  582. this.selectTitleCell.setStyle("cursor", "pointer");
  583. this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
  584. }
  585. if (this.gridJson.length){
  586. this.gridJson.each(function(data){
  587. this.items.push(new MWF.xApplication.query.Query.Viewer.ItemCategory(this, data));
  588. }.bind(this));
  589. if (this.json.isExpand=="yes") this.expandOrCollapseAll();
  590. }
  591. },
  592. expandOrCollapseAll: function(){
  593. var icon = this.selectTitleCell.getElement("span");
  594. if (icon.get("html").indexOf("expand.png")===-1){
  595. this.items.each(function(item){
  596. item.collapse();
  597. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>");
  598. }.bind(this));
  599. }else{
  600. this.items.each(function(item, i){
  601. window.setTimeout(function(){
  602. item.expand();
  603. }.bind(this), 10*i+5);
  604. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/down.png'/>");
  605. }.bind(this));
  606. }
  607. },
  608. getView: function(callback){
  609. this.getLookupAction(function(){
  610. if (this.json.application){
  611. this.getViewRes = this.lookupAction.getView(this.json.viewName, this.json.application, function(json){
  612. this.viewJson = JSON.decode(json.data.data);
  613. this.json = Object.merge(this.json, json.data);
  614. if (callback) callback();
  615. }.bind(this));
  616. // this.lookupAction.invoke({"name": "getView","async": true, "parameter": {"view": this.json.viewName, "application": this.json.application},"success": function(json){
  617. // this.viewJson = JSON.decode(json.data.data);
  618. // this.json = Object.merge(this.json, json.data);
  619. // //var viewData = JSON.decode(json.data.data);
  620. // if (callback) callback();
  621. // }.bind(this)});
  622. }else{
  623. this.getViewRes = this.lookupAction.getViewById(this.json.viewId, function(json){
  624. this.viewJson = JSON.decode(json.data.data);
  625. this.json.application = json.data.query;
  626. this.json = Object.merge(this.json, json.data);
  627. if (callback) callback();
  628. }.bind(this));
  629. }
  630. }.bind(this));
  631. },
  632. getLookupAction: function(callback){
  633. if (!this.lookupAction){
  634. this.lookupAction = MWF.Actions.get("x_query_assemble_surface");
  635. if (callback) callback();
  636. // var _self = this;
  637. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  638. // this.lookupAction = new MWF.xDesktop.Actions.RestActions("", this.options.actionRoot, "");
  639. // this.lookupAction.getActions = function(actionCallback){
  640. // this.actions = _self.options.actions;
  641. // if (actionCallback) actionCallback();
  642. // };
  643. // if (callback) callback();
  644. // }.bind(this));
  645. }else{
  646. if (callback) callback();
  647. }
  648. },
  649. hide: function(){
  650. this.node.setStyle("display", "none");
  651. },
  652. reload: function(){
  653. this.node.setStyle("display", "block");
  654. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  655. this.filterItems.each(function(filter){
  656. filter.destroy();
  657. }.bind(this));
  658. this.filterItems = [];
  659. if (this.viewSearchInputNode) this.viewSearchInputNode.set("text", this.lp.searchKeywork);
  660. this.closeCustomSearch();
  661. this.viewAreaNode.empty();
  662. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  663. },
  664. getFilter: function(){
  665. var filterData = [];
  666. if (this.searchStatus==="custom"){
  667. if (this.filterItems.length){
  668. this.filterItems.each(function(filter){
  669. filterData.push(filter.data);
  670. }.bind(this));
  671. }
  672. }
  673. if (this.searchStatus==="default"){
  674. var key = this.viewSearchInputNode.get("value");
  675. if (key && key!==this.lp.searchKeywork){
  676. this.viewJson.customFilterList.each(function(entry){
  677. if (entry.formatType==="textValue"){
  678. var d = {
  679. "path": entry.path,
  680. "value": key,
  681. "formatType": entry.formatType,
  682. "logic": "or",
  683. "comparison": "like"
  684. };
  685. filterData.push(d);
  686. }
  687. if (entry.formatType==="numberValue"){
  688. var v = key.toFloat();
  689. if (!isNaN(v)){
  690. var d = {
  691. "path": entry.path,
  692. "value": v,
  693. "formatType": entry.formatType,
  694. "logic": "or",
  695. "comparison": "like"
  696. };
  697. filterData.push(d);
  698. }
  699. }
  700. }.bind(this));
  701. }
  702. }
  703. return (filterData.length) ? filterData : null;
  704. },
  705. getData: function(){
  706. if (this.selectedItems.length){
  707. var arr = [];
  708. this.selectedItems.each(function(item){
  709. arr.push(item.data);
  710. });
  711. return arr;
  712. }else{
  713. return [];
  714. }
  715. }
  716. });
  717. MWF.xApplication.query.Query.Viewer.Item = new Class({
  718. initialize: function(view, data, prev, i){
  719. this.view = view;
  720. this.data = data;
  721. this.css = this.view.css;
  722. this.isSelected = false;
  723. this.prev = prev;
  724. this.load();
  725. },
  726. load: function(){
  727. this.node = new Element("tr", {"styles": this.css.viewContentTrNode});
  728. if (this.prev){
  729. this.node.inject(this.prev.node, "after");
  730. }else{
  731. this.node.inject(this.view.viewTable);
  732. }
  733. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  734. this.selectTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  735. this.selectTd.setStyles({"cursor": "pointer"});
  736. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  737. //}
  738. Object.each(this.view.entries, function(c, k){
  739. var cell = this.data.data[k];
  740. if (cell === undefined) cell = "";
  741. //if (cell){
  742. if (this.view.hideColumns.indexOf(k)===-1){
  743. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  744. if (k!== this.view.viewJson.group.column){
  745. //var v = (this.view.entries[k].code) ? MWF.Macro.exec(this.view.entries[k].code, {"value": cell, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : cell;
  746. var v = cell;
  747. td.set("text", v);
  748. }
  749. if (this.view.openColumns.indexOf(k)!==-1){
  750. this.setOpenWork(td)
  751. }
  752. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  753. }
  754. //}
  755. }.bind(this));
  756. // Object.each(this.data.data, function(cell, k){
  757. // if (this.view.hideColumns.indexOf(k)===-1){
  758. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  759. // if (k!== this.view.viewJson.group.column){
  760. // var v = (this.view.entries[k].code) ? MWF.Macro.exec(this.view.entries[k].code, {"value": cell, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : cell;
  761. // td.set("text", v);
  762. // }
  763. // if (this.view.openColumns.indexOf(k)!==-1){
  764. // this.setOpenWork(td)
  765. // }
  766. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  767. // }
  768. // }.bind(this));
  769. this.setEvent();
  770. },
  771. setOpenWork: function(td){
  772. debugger;
  773. td.setStyle("cursor", "pointer");
  774. if (this.view.json.type==="cms"){
  775. td.addEvent("click", this.openCms.bind(this));
  776. }else{
  777. td.addEvent("click", this.openWorkAndCompleted.bind(this));
  778. }
  779. },
  780. openCms: function(e){
  781. var options = {"documentId": this.data.bundle};
  782. this.view.fireEvent("openDocument", [options, this]);
  783. layout.desktop.openApplication(e, "cms.Document", options);
  784. },
  785. openWorkAndCompleted: function(e){
  786. MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(this.data.bundle, function(json){
  787. var workCompletedCount = json.data.workCompletedList.length;
  788. var workCount = json.data.workList.length;
  789. var count = workCount+workCompletedCount;
  790. if (count===1){
  791. if (workCompletedCount) {
  792. this.openWorkCompleted(json.data.workCompletedList[0].id, e);
  793. }else{
  794. this.openWork(json.data.workList[0].id, e);
  795. }
  796. }else if (count>1){
  797. var worksAreaNode = this.createWorksArea();
  798. json.data.workCompletedList.each(function(work){
  799. this.createWorkCompletedNode(work, worksAreaNode);
  800. }.bind(this));
  801. json.data.workList.each(function(work){
  802. this.createWorkNode(work, worksAreaNode);
  803. }.bind(this));
  804. this.showWorksArea(worksAreaNode, e);
  805. }else{
  806. }
  807. }.bind(this));
  808. },
  809. createWorkNode: function(work, worksAreaNode){
  810. var worksAreaContentNode = worksAreaNode.getLast();
  811. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  812. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  813. actionNode.store("workId", work.id);
  814. actionNode.addEvent("click", function(e){
  815. this.openWork(e.target.retrieve("workId"), e);
  816. this.mask.hide();
  817. worksAreaNode.destroy();
  818. }.bind(this));
  819. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  820. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  821. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  822. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  823. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": work.activityName}).inject(contentNode);
  824. var taskUsers = [];
  825. MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
  826. json.data.each(function(task){
  827. taskUsers.push(MWF.name.cn(task.person));
  828. }.bind(this));
  829. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.taskPeople+": "}).inject(contentNode);
  830. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": taskUsers.join(", ")}).inject(contentNode);
  831. }.bind(this));
  832. },
  833. createWorkCompletedNode: function(work, worksAreaNode){
  834. var worksAreaContentNode = worksAreaNode.getLast();
  835. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  836. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  837. actionNode.store("workId", work.id);
  838. actionNode.addEvent("click", function(e){
  839. this.mask.hide();
  840. worksAreaNode.destroy();
  841. this.openWorkCompleted(e.target.retrieve("workId"), e)
  842. }.bind(this));
  843. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  844. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  845. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  846. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  847. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": this.view.lp.processCompleted}).inject(contentNode);
  848. },
  849. createWorksArea: function(){
  850. var worksAreaNode = new Element("div", {"styles": this.css.worksAreaNode});
  851. var worksAreaTitleNode = new Element("div", {"styles": this.css.worksAreaTitleNode}).inject(worksAreaNode);
  852. var worksAreaTitleCloseNode = new Element("div", {"styles": this.css.worksAreaTitleCloseNode}).inject(worksAreaTitleNode);
  853. worksAreaTitleCloseNode.addEvent("click", function(e){
  854. this.mask.hide();
  855. e.target.getParent().getParent().destroy();
  856. }.bind(this));
  857. var worksAreaContentNode = new Element("div", {"styles": this.css.worksAreaContentNode}).inject(worksAreaNode);
  858. return worksAreaNode;
  859. },
  860. showWorksArea: function(node, e){
  861. this.mask = new MWF.widget.Mask({"style": "desktop", "loading": false});
  862. this.mask.loadNode(this.view.container);
  863. node.inject(this.view.node);
  864. this.setWorksAreaPosition(node, e.target);
  865. },
  866. setWorksAreaPosition: function(node, td){
  867. var p = td.getPosition(this.view.container);
  868. var containerS = this.view.container.getSize();
  869. var containerP = this.view.container.getPosition(this.view.container.getOffsetParent());
  870. var s = node.getSize();
  871. var offX = p.x+s.x-containerS.x;
  872. offX = (offX>0) ? offX+20 : 0;
  873. var offY = p.y+s.y-containerS.y;
  874. offY = (offY>0) ? offY+5 : 0;
  875. node.position({
  876. "relativeTo": td,
  877. "position": "lefttop",
  878. "edge": "lefttop",
  879. "offset": {
  880. "x": 0-offX,
  881. "y": 0-offY
  882. }
  883. });
  884. },
  885. openWork: function(id, e){
  886. var options = {"workId": id};
  887. this.view.fireEvent("openDocument", [options, this]);
  888. layout.desktop.openApplication(e, "process.Work", options);
  889. },
  890. openWorkCompleted: function(id, e){
  891. var options = {"workCompletedId": id};
  892. this.view.fireEvent("openDocument", [options, this]);
  893. layout.desktop.openApplication(e, "process.Work", options);
  894. },
  895. setEvent: function(){
  896. if (this.view.json.select==="single" || this.view.json.select==="multi"){
  897. this.node.addEvents({
  898. "mouseover": function(){
  899. if (!this.isSelected){
  900. var iconName = "checkbox";
  901. if (this.view.json.select==="single") iconName = "radiobox";
  902. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/"+iconName+".png) center center no-repeat"});
  903. }
  904. }.bind(this),
  905. "mouseout": function(){
  906. if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
  907. }.bind(this),
  908. "click": function(){this.select();}.bind(this)
  909. });
  910. }
  911. },
  912. select: function(){
  913. if (this.isSelected){
  914. if (this.view.json.select==="single"){
  915. this.unSelectedSingle();
  916. }else{
  917. this.unSelected();
  918. }
  919. }else{
  920. if (this.view.json.select==="single"){
  921. this.selectedSingle();
  922. }else{
  923. this.selected();
  924. }
  925. }
  926. this.view.fireEvent("select");
  927. },
  928. selected: function(){
  929. this.view.selectedItems.push(this);
  930. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
  931. this.node.setStyles(this.css.viewContentTrNode_selected);
  932. this.isSelected = true;
  933. },
  934. unSelected: function(){
  935. this.view.selectedItems.erase(this);
  936. this.selectTd.setStyles({"background": "transparent"});
  937. this.node.setStyles(this.css.viewContentTrNode);
  938. this.isSelected = false;
  939. },
  940. selectedSingle: function(){
  941. if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
  942. this.view.selectedItems = [this];
  943. this.view.currentSelectedItem = this;
  944. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/radiobox_checked.png) center center no-repeat"});
  945. this.node.setStyles(this.css.viewContentTrNode_selected);
  946. this.isSelected = true;
  947. },
  948. unSelectedSingle: function(){
  949. this.view.selectedItems = [];
  950. this.view.currentSelectedItem = null;
  951. this.selectTd.setStyles({"background": "transparent"});
  952. this.node.setStyles(this.css.viewContentTrNode);
  953. this.isSelected = false;
  954. }
  955. });
  956. MWF.xApplication.query.Query.Viewer.ItemCategory = new Class({
  957. initialize: function(view, data){
  958. this.view = view;
  959. this.data = data;
  960. this.css = this.view.css;
  961. this.items = [];
  962. this.loadChild = false;
  963. this.load();
  964. },
  965. load: function(){
  966. this.node = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.view.viewTable);
  967. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  968. this.selectTd = new Element("td", {"styles": this.css.viewContentCategoryTdNode}).inject(this.node);
  969. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  970. //}
  971. this.categoryTd = new Element("td", {
  972. "styles": this.css.viewContentCategoryTdNode,
  973. "colspan": this.view.viewJson.selectList.length
  974. }).inject(this.node);
  975. this.groupColumn = null;
  976. for (var c = 0; c<this.view.viewJson.selectList.length; c++){
  977. if (this.view.viewJson.selectList[c].column === this.view.viewJson.group.column){
  978. this.groupColumn = this.view.viewJson.selectList[c];
  979. break;
  980. }
  981. }
  982. if (this.groupColumn){
  983. //var text = (this.groupColumn.code) ? MWF.Macro.exec(this.groupColumn.code, {"value": this.data.group, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : this.data.group;
  984. var text = this.data.group;
  985. }else{
  986. var text = this.data.group;
  987. }
  988. this.categoryTd.set("html", "<span style='font-family: Webdings'><img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/></span> "+text);
  989. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  990. this.setEvent();
  991. },
  992. setEvent: function(){
  993. //if (this.selectTd){
  994. this.node.addEvents({
  995. "click": function(){this.expandOrCollapse();}.bind(this)
  996. });
  997. //}
  998. },
  999. expandOrCollapse: function(){
  1000. var t = this.node.getElement("span").get("html");
  1001. if (t.indexOf("expand.png")===-1){
  1002. this.collapse();
  1003. }else{
  1004. this.expand();
  1005. }
  1006. },
  1007. collapse: function(){
  1008. this.items.each(function(item){
  1009. item.node.setStyle("display", "none");
  1010. }.bind(this));
  1011. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/>");
  1012. },
  1013. expand: function(){
  1014. this.items.each(function(item){
  1015. item.node.setStyle("display", "table-row");
  1016. }.bind(this));
  1017. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
  1018. if (!this.loadChild){
  1019. //window.setTimeout(function(){
  1020. this.data.list.each(function(line){
  1021. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this.view, line, this));
  1022. }.bind(this));
  1023. this.loadChild = true;
  1024. //}.bind(this), 10);
  1025. }
  1026. }
  1027. });
  1028. MWF.xApplication.query.Query.Viewer.Filter = new Class({
  1029. initialize: function(viewer, data, node){
  1030. this.viewer = viewer;
  1031. this.data = data;
  1032. this.css = this.viewer.css;
  1033. this.content = node;
  1034. this.load();
  1035. },
  1036. load: function(){
  1037. this.node = new Element("div", {"styles": this.css.viewSearchFilterNode}).inject(this.content);
  1038. if (this.viewer.filterItems.length){
  1039. this.logicNode = new Element("div", {"styles": this.css.viewSearchFilterSelectAreaNode}).inject(this.node);
  1040. this.logicSelectNode = new Element("div", {
  1041. "styles": this.css.viewSearchFilterSelectNode,
  1042. "text": this.viewer.lp.and,
  1043. "value": "and"
  1044. }).inject(this.logicNode);
  1045. this.logicSelectButtonNode = new Element("div", {"styles": this.css.viewSearchFilterSelectButtonNode}).inject(this.logicNode);
  1046. this.logicNode.addEvents({
  1047. "click": function(){
  1048. var v = this.logicSelectNode.get("value");
  1049. if (v==="and"){
  1050. this.logicSelectButtonNode.setStyle("float", "left");
  1051. this.logicSelectNode.setStyle("float", "right");
  1052. this.logicSelectNode.set({
  1053. "text": this.viewer.lp.or,
  1054. "value": "or"
  1055. });
  1056. this.data.logic = "or";
  1057. }else{
  1058. this.logicSelectButtonNode.setStyle("float", "right");
  1059. this.logicSelectNode.setStyle("float", "left");
  1060. this.logicSelectNode.set({
  1061. "text": this.viewer.lp.and,
  1062. "value": "and"
  1063. });
  1064. this.data.logic = "and";
  1065. }
  1066. this.viewer.searchCustomView();
  1067. }.bind(this)
  1068. });
  1069. }
  1070. this.titleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.title}).inject(this.node);
  1071. this.comparisonTitleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.comparisonTitle}).inject(this.node);
  1072. this.valueNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": "\""+this.data.value+"\""}).inject(this.node);
  1073. this.deleteNode = new Element("div", {"styles": this.css.viewSearchFilterDeleteNode}).inject(this.node);
  1074. this.node.addEvents({
  1075. "mouseover": function(){
  1076. this.node.setStyles(this.css.viewSearchFilterNode_over);
  1077. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode_over);
  1078. }.bind(this),
  1079. "mouseout": function(){
  1080. this.node.setStyles(this.css.viewSearchFilterNode);
  1081. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode);
  1082. }.bind(this)
  1083. });
  1084. this.deleteNode.addEvent("click", function(){
  1085. this.viewer.searchViewRemoveFilter(this);
  1086. }.bind(this));
  1087. },
  1088. destroy: function(){
  1089. this.node.destroy();
  1090. MWF.release(this);
  1091. }
  1092. });