Viewer.js 61 KB

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