Viewer.js 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817
  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. "moduleEvents": ["queryLoad", "postLoad", "postLoadPageData", "postLoadPage", "selectRow", "unselectRow",
  17. "queryLoadItemRow", "postLoadItemRow", "queryLoadCategoryRow", "postLoadCategoryRow"]
  18. // "actions": {
  19. // "lookup": {"uri": "/jaxrs/view/flag/{view}/query/{application}/execute", "method":"PUT"},
  20. // "getView": {"uri": "/jaxrs/view/flag/{view}/query/{application}"}
  21. //
  22. // },
  23. // "actionRoot": "x_query_assemble_surface"
  24. },
  25. initialize: function(container, json, options, app, parentMacro){
  26. //本类有三种事件,
  27. //一种是通过 options 传进来的事件,包括 loadView、openDocument、select
  28. //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
  29. //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件
  30. this.setOptions(options);
  31. this.path = "/x_component_query_Query/$Viewer/";
  32. this.cssPath = "/x_component_query_Query/$Viewer/"+this.options.style+"/css.wcss";
  33. this._loadCss();
  34. this.lp = MWF.xApplication.query.Query.LP;
  35. this.app = app;
  36. this.container = $(container);
  37. this.json = json;
  38. this.parentMacro = parentMacro;
  39. debugger;
  40. this.originalJson = Object.clone(json);
  41. this.viewJson = null;
  42. this.filterItems = [];
  43. this.searchStatus = "none"; //none, custom, default
  44. this.items = [];
  45. this.selectedItems = [];
  46. this.hideColumns = [];
  47. this.openColumns = [];
  48. this.gridJson = null;
  49. if (this.options.isload){
  50. this.init(function(){
  51. this.load();
  52. }.bind(this));
  53. }
  54. },
  55. loadView: function(){
  56. if (this.viewJson){
  57. this.reload();
  58. }else{
  59. this.init(function(){
  60. this.load();
  61. }.bind(this));
  62. }
  63. },
  64. init: function(callback){
  65. if (this.json.data){
  66. this.viewJson = JSON.decode(this.json.data);
  67. if (callback) callback();
  68. }else{
  69. this.getView(callback);
  70. }
  71. },
  72. load: function(){
  73. this.loadMacro( function () {
  74. this._loadModuleEvents();
  75. if (this.fireEvent("queryLoad")){
  76. this._loadUserInterface();
  77. //this._loadStyles();
  78. this._loadDomEvents();
  79. }
  80. }.bind(this))
  81. },
  82. _loadUserInterface : function(){
  83. this.loadLayout();
  84. this.createActionbarNode();
  85. this.createSearchNode();
  86. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  87. if (this.options.resizeNode){
  88. this.setContentHeightFun = this.setContentHeight.bind(this);
  89. this.container.addEvent("resize", this.setContentHeightFun);
  90. this.setContentHeightFun();
  91. }
  92. },
  93. loadLayout: function(){
  94. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  95. this.actionbarAreaNode = new Element("div", {"styles": this.css.actionbarAreaNode}).inject(this.node);
  96. //if (this.options.export) this.exportAreaNode = new Element("div", {"styles": this.css.exportAreaNode}).inject(this.node);
  97. this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.node);
  98. this.viewAreaNode = new Element("div", {"styles": this.css.viewAreaNode}).inject(this.node);
  99. this.viewPageNode = new Element("div", {"styles": this.css.viewPageNode}).inject(this.node);
  100. this.viewPageAreaNode = new Element("div", {"styles": this.css.viewPageAreaNode}).inject(this.viewPageNode);
  101. },
  102. loadMacro: function (callback) {
  103. MWF.require("MWF.xScript.Macro", function () {
  104. this.Macro = new MWF.Macro.ViewContext(this);
  105. if (callback) callback();
  106. }.bind(this));
  107. },
  108. createExportNode: function(){
  109. if (this.options.export){
  110. MWF.require("MWF.widget.Toolbar", function(){
  111. this.toolbar = new MWF.widget.Toolbar(this.actionbarAreaNode, {"style": "simple"}, this); //this.exportAreaNode
  112. var actionNode = new Element("div", {
  113. "id": "",
  114. "MWFnodetype": "MWFToolBarButton",
  115. "MWFButtonImage": this.path+""+this.options.style+"/icon/export.png",
  116. "title": this.lp.exportExcel,
  117. "MWFButtonAction": "exportView",
  118. "MWFButtonText": this.lp.exportExcel
  119. }).inject(this.actionbarAreaNode); //this.exportAreaNode
  120. this.toolbar.load();
  121. }.bind(this));
  122. //this.exportNode = new Element("button", {"text": this.lp.exportExcel}).inject(this.exportAreaNode);
  123. }
  124. },
  125. exportView: function(){
  126. var action = MWF.Actions.get("x_query_assemble_surface");
  127. var filterData = this.json.filter ? this.json.filter.clone() : [];
  128. if (this.filterItems.length){
  129. this.filterItems.each(function(filter){
  130. filterData.push(filter.data);
  131. }.bind(this));
  132. }
  133. action.exportViewWithQuery(this.json.viewName, this.json.application, {"filterList": filterData}, function(json){
  134. var uri = action.action.actions.getViewExcel.uri;
  135. uri = uri.replace("{flag}", json.data.id);
  136. uri = action.action.address+uri;
  137. var a = new Element("a", {"href": uri, "target":"_blank"});
  138. a.click();
  139. a.destroy();
  140. }.bind(this));
  141. },
  142. createSearchNode: function(){
  143. if (this.viewJson.customFilterList && this.viewJson.customFilterList.length){
  144. this.searchStatus = "default";
  145. this.loadFilterSearch();
  146. }else{
  147. this.loadSimpleSearch();
  148. }
  149. },
  150. loadSimpleSearch: function(){
  151. return false;
  152. this.searchSimpleNode = new Element("div", {"styles": this.css.searchSimpleNode}).inject(this.searchAreaNode);
  153. this.searchSimpleButtonNode = new Element("div", {"styles": this.css.searchSimpleButtonNode}).inject(this.searchSimpleNode);
  154. this.searchSimpleInputNode = new Element("input", {"type":"text", "styles": this.css.searchSimpleInputNode, "value": this.lp.searchKeywork}).inject(this.searchSimpleNode);
  155. this.searchSimpleButtonNode.addEvent("click", function(){
  156. this.search();
  157. }.bind(this));
  158. this.searchSimpleInputNode.addEvents({
  159. "focus": function(){
  160. if (this.searchSimpleInputNode.get("value")===this.lp.searchKeywork) this.searchSimpleInputNode.set("value", "");
  161. }.bind(this),
  162. "blur": function(){if (!this.searchSimpleInputNode.get("value")) this.searchSimpleInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  163. "keydown": function(e){
  164. if (e.code===13) this.search();
  165. }.bind(this)
  166. });
  167. },
  168. search: function(){
  169. if (this.gridJson){
  170. var key = this.searchSimpleInputNode.get("value");
  171. var rows = this.viewTable.rows;
  172. var first = (this.json.isTitle!=="no") ? 1 : 0;
  173. for (var i = first; i<rows.length; i++){
  174. var tr = rows[i];
  175. if (!key || key==this.lp.searchKeywork){
  176. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  177. }else{
  178. if (tr.get("text").indexOf(key)!==-1){
  179. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  180. }else{
  181. if (tr.getStyle("display")!=="none") tr.setStyle("display", "none");
  182. }
  183. }
  184. }
  185. //if (this.viewPageAreaNode) this.viewPageAreaNode.hide();
  186. }
  187. },
  188. loadFilterSearch: function(){
  189. this.viewSearchCustomActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomActionNode, "text": this.lp.customSearch}).inject(this.searchAreaNode);
  190. this.viewSearchInputAreaNode = new Element("div", {"styles": this.css.viewFilterSearchInputAreaNode}).inject(this.searchAreaNode);
  191. this.viewSearchIconNode = new Element("div", {"styles": this.css.viewFilterSearchIconNode}).inject(this.viewSearchInputAreaNode);
  192. this.viewSearchInputBoxNode = new Element("div", {"styles": this.css.viewFilterSearchInputBoxNode}).inject(this.viewSearchInputAreaNode);
  193. this.viewSearchInputNode = new Element("input", {"styles": this.css.viewFilterSearchInputNode, "value": this.lp.searchKeywork}).inject(this.viewSearchInputBoxNode);
  194. this.viewSearchInputNode.addEvents({
  195. "focus": function(){
  196. if (this.viewSearchInputNode.get("value")===this.lp.searchKeywork) this.viewSearchInputNode.set("value", "");
  197. }.bind(this),
  198. "blur": function(){if (!this.viewSearchInputNode.get("value")) this.viewSearchInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  199. "keydown": function(e){
  200. if (e.code===13) this.searchView();
  201. }.bind(this)
  202. });
  203. this.viewSearchIconNode.addEvents({
  204. "click": function(){this.searchView();}.bind(this)
  205. });
  206. this.viewSearchCustomActionNode.addEvents({
  207. "click": function(){this.loadCustomSearch();}.bind(this)
  208. });
  209. },
  210. searchView: function(){
  211. if (this.viewJson.customFilterList) {
  212. var key = this.viewSearchInputNode.get("value");
  213. if (key && key !== this.lp.searchKeywork) {
  214. var filterData = this.json.filter ? this.json.filter : [];
  215. this.filterItems = [];
  216. this.viewJson.customFilterList.each(function (entry) {
  217. if (entry.formatType === "textValue") {
  218. var d = {
  219. "path": entry.path,
  220. "value": key,
  221. "formatType": entry.formatType,
  222. "logic": "or",
  223. "comparison": "like"
  224. };
  225. filterData.push(d);
  226. this.filterItems.push({"data":d});
  227. }
  228. if (entry.formatType === "numberValue") {
  229. var v = key.toFloat();
  230. if (!isNaN(v)) {
  231. var d = {
  232. "path": entry.path,
  233. "value": v,
  234. "formatType": entry.formatType,
  235. "logic": "or",
  236. "comparison": "like"
  237. };
  238. filterData.push(d);
  239. this.filterItems.push({"data":d});
  240. }
  241. }
  242. }.bind(this));
  243. this.createViewNode({"filterList": filterData});
  244. }else{
  245. this.createViewNode();
  246. }
  247. }
  248. },
  249. searchCustomView: function(){
  250. if (this.filterItems.length){
  251. var filterData = this.json.filter ? this.json.filter.clone() : [];
  252. this.filterItems.each(function(filter){
  253. filterData.push(filter.data);
  254. }.bind(this));
  255. this.createViewNode({"filterList": filterData});
  256. }else{
  257. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  258. }
  259. },
  260. loadCustomSearch: function(){
  261. this.viewSearchIconNode.setStyle("display", "none");
  262. this.viewSearchInputBoxNode.setStyle("display", "none");
  263. this.viewSearchCustomActionNode.setStyle("display", "none");
  264. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  265. var x = this.viewSearchInputAreaNode.getParent().getSize().x-2-20;
  266. this.css.viewFilterSearchInputAreaNode_custom.width = ""+x+"px";
  267. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  268. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  269. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode_custom).chain(function(){
  270. this.searchStatus = "custom";
  271. this.css.viewFilterSearchInputAreaNode_custom.width = "auto";
  272. this.viewSearchInputAreaNode.setStyle("width", "auto");
  273. if (this.viewSearchCustomContentNode){
  274. this.viewSearchCustomCloseActionNode.setStyle("display", "block");
  275. this.viewSearchCustomContentNode.setStyle("display", "block");
  276. }else{
  277. this.loadCustomSearchContent();
  278. }
  279. this.setContentHeightFun();
  280. }.bind(this));
  281. this.searchCustomView();
  282. },
  283. loadCustomSearchContent: function(){
  284. this.viewSearchCustomCloseActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomCloseActionNode}).inject(this.viewSearchInputAreaNode);
  285. this.viewSearchCustomContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomContentNode}).inject(this.viewSearchInputAreaNode);
  286. this.viewSearchCustomPathContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomPathContentNode}).inject(this.viewSearchCustomContentNode);
  287. this.viewSearchCustomComparisonContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomComparisonContentNode}).inject(this.viewSearchCustomContentNode);
  288. this.viewSearchCustomValueContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomValueContentNode}).inject(this.viewSearchCustomContentNode);
  289. this.viewSearchCustomAddContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddContentNode}).inject(this.viewSearchCustomContentNode);
  290. this.viewSearchCustomAddIconNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddIconNode}).inject(this.viewSearchCustomAddContentNode);
  291. this.viewSearchCustomFilterContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomFilterContentNode}).inject(this.viewSearchCustomContentNode);
  292. this.loadViewSearchCustomList();
  293. this.viewSearchCustomCloseActionNode.addEvents({
  294. "click": function(){this.closeCustomSearch();}.bind(this)
  295. });
  296. this.viewSearchCustomAddIconNode.addEvents({
  297. "click": function(){this.viewSearchCustomAddToFilter();}.bind(this)
  298. });
  299. },
  300. loadViewSearchCustomList: function(){
  301. this.viewSearchCustomPathListNode = new Element("select", {
  302. "styles": this.css.viewFilterSearchCustomPathListNode,
  303. "multiple": true
  304. }).inject(this.viewSearchCustomPathContentNode);
  305. this.viewSearchCustomComparisonListNode = new Element("select", {
  306. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  307. "multiple": true
  308. }).inject(this.viewSearchCustomComparisonContentNode);
  309. this.viewJson.customFilterList.each(function(entry){
  310. var option = new Element("option", {
  311. "style": this.css.viewFilterSearchOptionNode,
  312. "value": entry.path,
  313. "text": entry.title
  314. }).inject(this.viewSearchCustomPathListNode);
  315. option.store("entry", entry);
  316. }.bind(this));
  317. this.viewSearchCustomPathListNode.addEvent("change", function(){
  318. this.loadViewSearchCustomComparisonList();
  319. }.bind(this));
  320. },
  321. loadViewSearchCustomComparisonList: function(){
  322. var idx = this.viewSearchCustomPathListNode.selectedIndex;
  323. var option = this.viewSearchCustomPathListNode.options[idx];
  324. var entry = option.retrieve("entry");
  325. if (entry){
  326. switch (entry.formatType){
  327. case "numberValue":
  328. this.loadComparisonSelect(this.lp.numberFilter);
  329. this.loadViewSearchCustomValueNumberInput();
  330. break;
  331. case "dateTimeValue":
  332. this.loadComparisonSelect(this.lp.dateFilter);
  333. this.loadViewSearchCustomValueDateTimeInput();
  334. break;
  335. case "dateValue":
  336. this.loadComparisonSelect(this.lp.dateFilter);
  337. this.loadViewSearchCustomValueDateInput();
  338. break;
  339. case "timeValue":
  340. this.loadComparisonSelect(this.lp.dateFilter);
  341. this.loadViewSearchCustomValueTimeInput();
  342. break;
  343. case "booleanValue":
  344. this.loadComparisonSelect(this.lp.booleanFilter);
  345. this.loadViewSearchCustomValueBooleanInput();
  346. break;
  347. default:
  348. this.loadComparisonSelect(this.lp.textFilter);
  349. this.loadViewSearchCustomValueTextInput();
  350. }
  351. }
  352. },
  353. loadViewSearchCustomValueNumberInput: function(){
  354. this.viewSearchCustomValueContentNode.empty();
  355. this.viewSearchCustomValueNode = new Element("input", {
  356. "styles": this.css.viewFilterSearchCustomValueNode,
  357. "type": "number"
  358. }).inject(this.viewSearchCustomValueContentNode);
  359. },
  360. loadViewSearchCustomValueDateTimeInput: function(){
  361. this.viewSearchCustomValueContentNode.empty();
  362. this.viewSearchCustomValueNode = new Element("input", {
  363. "styles": this.css.viewFilterSearchCustomValueNode,
  364. "type": "text",
  365. "readonly": true
  366. }).inject(this.viewSearchCustomValueContentNode);
  367. MWF.require("MWF.widget.Calendar", function(){
  368. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  369. "style": "xform",
  370. "isTime": true,
  371. "target": this.container,
  372. "format": "db"
  373. });
  374. }.bind(this));
  375. },
  376. loadViewSearchCustomValueDateInput: function(){
  377. this.viewSearchCustomValueContentNode.empty();
  378. this.viewSearchCustomValueNode = new Element("input", {
  379. "styles": this.css.viewFilterSearchCustomValueNode,
  380. "type": "text",
  381. "readonly": true
  382. }).inject(this.viewSearchCustomValueContentNode);
  383. MWF.require("MWF.widget.Calendar", function(){
  384. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  385. "style": "xform",
  386. "isTime": false,
  387. "target": this.container,
  388. "format": "%Y-%m-%d"
  389. });
  390. }.bind(this));
  391. },
  392. loadViewSearchCustomValueTimeInput: function(){
  393. this.viewSearchCustomValueContentNode.empty();
  394. this.viewSearchCustomValueNode = new Element("input", {
  395. "styles": this.css.viewFilterSearchCustomValueNode,
  396. "type": "text",
  397. "readonly": true
  398. }).inject(this.viewSearchCustomValueContentNode);
  399. MWF.require("MWF.widget.Calendar", function(){
  400. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  401. "style": "xform",
  402. "timeOnly": true,
  403. "target": this.container,
  404. "format": "%H:%M:%S"
  405. });
  406. }.bind(this));
  407. },
  408. loadViewSearchCustomValueBooleanInput: function(){
  409. this.viewSearchCustomValueContentNode.empty();
  410. this.viewSearchCustomValueNode = new Element("select", {
  411. "styles": this.css.viewFilterSearchCustomValueSelectNode,
  412. "multiple": true
  413. }).inject(this.viewSearchCustomValueContentNode);
  414. new Element("option", {"value": "true","text": this.lp.yes}).inject(this.viewSearchCustomValueNode);
  415. new Element("option", {"value": "false","text": this.lp.no}).inject(this.viewSearchCustomValueNode);
  416. },
  417. loadViewSearchCustomValueTextInput: function(){
  418. this.viewSearchCustomValueContentNode.empty();
  419. this.viewSearchCustomValueNode = new Element("textarea", {
  420. "styles": this.css.viewFilterSearchCustomValueNode
  421. }).inject(this.viewSearchCustomValueContentNode);
  422. },
  423. loadComparisonSelect:function(obj){
  424. this.viewSearchCustomComparisonListNode.empty();
  425. Object.each(obj, function(v, k){
  426. var option = new Element("option", {"value": k,"text": v}).inject(this.viewSearchCustomComparisonListNode);
  427. }.bind(this));
  428. },
  429. closeCustomSearch: function(){
  430. if (this.viewSearchCustomContentNode && this.viewSearchCustomContentNode.getStyle("display")==="block"){
  431. this.viewSearchCustomCloseActionNode.setStyle("display", "none");
  432. this.viewSearchCustomContentNode.setStyle("display", "none");
  433. var x = this.viewSearchInputAreaNode.getParent().getSize().x;
  434. x1 = x-2-10-90;
  435. this.css.viewFilterSearchInputAreaNode.width = ""+x1+"px";
  436. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  437. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  438. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  439. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode).chain(function(){
  440. this.searchStatus = "default";
  441. this.css.viewFilterSearchInputAreaNode.width = "auto";
  442. this.viewSearchInputAreaNode.setStyle("margin-right", "90px");
  443. this.viewSearchIconNode.setStyle("display", "block");
  444. this.viewSearchInputBoxNode.setStyle("display", "block");
  445. this.viewSearchCustomActionNode.setStyle("display", "block");
  446. this.setContentHeightFun();
  447. }.bind(this));
  448. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  449. }
  450. },
  451. viewSearchCustomAddToFilter: function(){
  452. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  453. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  454. if (pathIdx===-1){
  455. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  456. return false;
  457. }
  458. if (comparisonIdx===-1){
  459. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  460. return false;
  461. }
  462. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  463. var entry = pathOption.retrieve("entry");
  464. if (entry){
  465. var pathTitle = entry.title;
  466. var path = entry.path;
  467. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  468. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  469. var value = "";
  470. switch (entry.formatType){
  471. case "numberValue":
  472. value = this.viewSearchCustomValueNode.get("value");
  473. break;
  474. case "dateTimeValue":
  475. value = this.viewSearchCustomValueNode.get("value");
  476. break;
  477. case "booleanValue":
  478. var idx = this.viewSearchCustomValueNode.selectedIndex;
  479. if (idx!==-1){
  480. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  481. value = (v==="true");
  482. }
  483. break;
  484. default:
  485. value = this.viewSearchCustomValueNode.get("value");
  486. }
  487. if (value===""){
  488. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  489. return false;
  490. }
  491. this.filterItems.push(new MWF.xApplication.query.Query.Viewer.Filter(this, {
  492. "logic": "and",
  493. "path": path,
  494. "title": pathTitle,
  495. "comparison": comparison,
  496. "comparisonTitle": comparisonTitle,
  497. "value": value,
  498. "formatType": (entry.formatType=="datetimeValue") ? "dateTimeValue": entry.formatType
  499. }, this.viewSearchCustomFilterContentNode));
  500. this.searchCustomView();
  501. }
  502. },
  503. searchViewRemoveFilter: function(filter){
  504. this.filterItems.erase(filter);
  505. filter.destroy();
  506. this.searchCustomView()
  507. },
  508. setContentHeight: function(){
  509. var size = this.node.getSize();
  510. var searchSize = this.searchAreaNode.getComputedSize();
  511. var h = size.y-searchSize.totalHeight;
  512. //if (this.exportAreaNode){
  513. // var exportSize = this.exportAreaNode.getComputedSize();
  514. // h = h-exportSize.totalHeight;
  515. //}
  516. if( this.actionbarAreaNode ){
  517. var exportSize = this.actionbarAreaNode.getComputedSize();
  518. h = h-exportSize.totalHeight;
  519. }
  520. var pageSize = this.viewPageNode.getComputedSize();
  521. h = h-pageSize.totalHeight;
  522. this.viewAreaNode.setStyle("height", ""+h+"px");
  523. },
  524. createLoadding: function(){
  525. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.contentAreaNode);
  526. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  527. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  528. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  529. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  530. loadingTextNode.set("text", "loading...");
  531. },
  532. createActionbarNode : function(){
  533. this.actionbarAreaNode.empty();
  534. if( typeOf( this.viewJson.actionbarHidden ) === "boolean" ){
  535. if( this.viewJson.actionbarHidden === true || !this.viewJson.actionbarList || !this.viewJson.actionbarList.length )return;
  536. this.actionbar = new MWF.xApplication.query.Query.Viewer.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
  537. this.actionbar.load();
  538. }else{ //兼容以前的ExportNode
  539. this.createExportNode();
  540. }
  541. },
  542. createViewNode: function(data){
  543. this.viewAreaNode.empty();
  544. this.contentAreaNode = new Element("div", {"styles": this.css.contentAreaNode}).inject(this.viewAreaNode);
  545. this.viewTable = new Element("table", {
  546. "styles": this.css.viewTitleTableNode,
  547. "border": "0px",
  548. "cellPadding": "0",
  549. "cellSpacing": "0"
  550. }).inject(this.contentAreaNode);
  551. this.createLoadding();
  552. if (this.json.isTitle!=="no"){
  553. this.viewTitleLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
  554. //if (this.json.select==="single" || this.json.select==="multi") {
  555. this.selectTitleCell = new Element("td", {
  556. "styles": this.css.viewTitleCellNode
  557. }).inject(this.viewTitleLine);
  558. this.selectTitleCell.setStyle("width", "10px");
  559. if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
  560. //}
  561. //序号
  562. if (this.viewJson.isSequence==="yes"){
  563. this.sequenceTitleCell = new Element("td", {
  564. "styles": this.css.viewTitleCellNode
  565. }).inject(this.viewTitleLine);
  566. this.sequenceTitleCell.setStyle("width", "10px");
  567. if (this.json.titleStyles) this.sequenceTitleCell.setStyles(this.json.titleStyles);
  568. }
  569. this.entries = {};
  570. this.viewJson.selectList.each(function(column){
  571. this.entries[column.column] = column;
  572. if (!column.hideColumn){
  573. var viewCell = new Element("td", {
  574. "styles": this.css.viewTitleCellNode,
  575. "text": column.displayName
  576. }).inject(this.viewTitleLine);
  577. var size = MWF.getTextSize(column.displayName, this.css.viewTitleCellNode);
  578. viewCell.setStyle("min-width", ""+size.x+"px");
  579. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  580. }else{
  581. this.hideColumns.push(column.column);
  582. }
  583. if (column.allowOpen) this.openColumns.push(column.column);
  584. }.bind(this));
  585. this.lookup(data);
  586. }else{
  587. this.viewJson.selectList.each(function(column){
  588. if (column.hideColumn) this.hideColumns.push(column.column);
  589. if (!column.allowOpen) this.openColumns.push(column.column);
  590. }.bind(this));
  591. this.lookup(data);
  592. }
  593. },
  594. _loadPageCountNode: function(){
  595. this.viewPageContentNode.empty();
  596. var size = this.viewPageAreaNode.getSize();
  597. var w1 = this.viewPageFirstNode.getSize().x*2;
  598. var w2 = this.viewPageContentNode.getStyle("margin-left").toInt();
  599. var w = size.x-w1-w2;
  600. var bw = this.css.viewPageButtonNode.width.toInt()+this.css.viewPageButtonNode["margin-right"].toInt();
  601. var count = (w/bw).toInt()-2;
  602. if (count>10) count = 10;
  603. this.showPageCount = Math.min(count, this.pages);
  604. var tmp = this.showPageCount/2;
  605. var n = tmp.toInt();
  606. var left = this.currentPage-n;
  607. if (left<=0) left = 1;
  608. var right = this.showPageCount + left-1;
  609. if (right>this.pages) right = this.pages;
  610. left = right-this.showPageCount+1;
  611. if (left<=1) left = 1;
  612. this.viewPagePrevNode = new Element("div", {"styles": this.css.viewPagePrevButtonNode}).inject(this.viewPageContentNode);
  613. this.loadPageButtonEvent(this.viewPagePrevNode, "viewPagePrevButtonNode_over", "viewPagePrevButtonNode_up", "viewPagePrevButtonNode_down", function(){
  614. if (this.currentPage>1) this.currentPage--;
  615. this.loadCurrentPageData();
  616. }.bind(this));
  617. for (i=left; i<=right; i++){
  618. var node = new Element("div", {"styles": this.css.viewPageButtonNode, "text": i}).inject(this.viewPageContentNode);
  619. if (i==this.currentPage){
  620. node.setStyles(this.css.viewPageButtonNode_current);
  621. }else{
  622. this.loadPageButtonEvent(node, "viewPageButtonNode_over", "viewPageButtonNode_up", "viewPageButtonNode_down", function(e){
  623. this.currentPage = e.target.get("text").toInt();
  624. this.loadCurrentPageData();
  625. }.bind(this));
  626. }
  627. }
  628. this.viewPageNextNode = new Element("div", {"styles": this.css.viewPageNextButtonNode}).inject(this.viewPageContentNode);
  629. this.loadPageButtonEvent(this.viewPageNextNode, "viewPageNextButtonNode_over", "viewPageNextButtonNode_up", "viewPageNextButtonNode_down", function(){
  630. if (this.currentPage<=this.pages-1) this.currentPage++;
  631. this.loadCurrentPageData();
  632. }.bind(this));
  633. },
  634. loadPageButtonEvent: function(node, over, out, down, click){
  635. node.addEvents({
  636. "mouseover": function(){node.setStyles(this.css[over])}.bind(this),
  637. "mouseout": function(){node.setStyles(this.css[out])}.bind(this),
  638. "mousedown": function(){node.setStyles(this.css[down])}.bind(this),
  639. "mouseup": function(){node.setStyles(this.css[out])}.bind(this),
  640. "click": click
  641. });
  642. },
  643. _loadPageNode: function(){
  644. this.viewPageAreaNode.empty();
  645. this.viewPageFirstNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.firstPage}).inject(this.viewPageAreaNode);
  646. this.viewPageContentNode = new Element("div", {"styles": this.css.viewPageContentNode}).inject(this.viewPageAreaNode);
  647. this.viewPageLastNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.lastPage}).inject(this.viewPageAreaNode);
  648. this._loadPageCountNode();
  649. this.loadPageButtonEvent(this.viewPageFirstNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  650. this.currentPage = 1;
  651. this.loadCurrentPageData();
  652. }.bind(this));
  653. this.loadPageButtonEvent(this.viewPageLastNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  654. this.currentPage = this.pages;
  655. this.loadCurrentPageData();
  656. }.bind(this));
  657. },
  658. _initPage: function(){
  659. this.count = this.bundleItems.length;
  660. var i = this.count/this.json.pageSize;
  661. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  662. this.currentPage = 1;
  663. },
  664. lookup: function(data){
  665. this.getLookupAction(function(){
  666. if (this.json.application){
  667. var d = data || {};
  668. d.count = this.json.count;
  669. this.lookupAction.bundleView(this.json.id, d, function(json){
  670. this.bundleItems = json.data.valueList;
  671. this._initPage();
  672. if (this.bundleItems.length){
  673. this.loadCurrentPageData( function () {
  674. this.fireEvent("postLoad"); //用户配置的事件
  675. }.bind(this));
  676. }else{
  677. //this._loadPageNode();
  678. this.viewPageAreaNode.empty();
  679. if (this.loadingAreaNode){
  680. this.loadingAreaNode.destroy();
  681. this.loadingAreaNode = null;
  682. }
  683. this.fireEvent("postLoad"); //用户配置的事件
  684. }
  685. }.bind(this));
  686. }
  687. }.bind(this));
  688. },
  689. //api 使用 开始
  690. getParentEnvironment : function(){
  691. return this.parentMacro ? this.parentMacro.environment : null;
  692. },
  693. getViewInfor : function(){
  694. return this.json;
  695. },
  696. getPageInfor : function(){
  697. return {
  698. pages : this.pages,
  699. perPageCount : this.options.perPageCount,
  700. currentPageNumber : this.currentPage
  701. };
  702. },
  703. getPageData : function () {
  704. return this.gridJson;
  705. },
  706. toPage : function( pageNumber, callback ){
  707. this.currentPage = pageNumber;
  708. this.loadCurrentPageData( callback );
  709. },
  710. selectAll : function(){
  711. var flag = this.json.select || this.viewJson.select || "none";
  712. if ( flag==="multi"){
  713. this.items.each( function (item) {
  714. if( item.clazzType === "item" ){
  715. item.selected();
  716. }else{
  717. item.expand();
  718. item.items.each( function (it) {
  719. item.selected();
  720. })
  721. }
  722. })
  723. }
  724. },
  725. unSelectAll : function(){
  726. var flag = this.json.select || this.viewJson.select || "none";
  727. if ( flag==="multi"){
  728. this.items.each( function (item) {
  729. if( item.clazzType === "item" ){
  730. item.unSelected();
  731. }else{
  732. if(item.items)item.items.each( function (it) {
  733. item.unSelected();
  734. })
  735. }
  736. })
  737. }
  738. },
  739. setFilter : function( filter ){
  740. if( !filter )filter = [];
  741. if( typeOf( filter ) === "object" )filter = [ filter ];
  742. this.json.filter = filter;
  743. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  744. },
  745. switchView : function( json ){
  746. debugger;
  747. // json = {
  748. // "application": application,
  749. // "viewName": viewName,
  750. // "isTitle": "yes",
  751. // "select": "none",
  752. // "titleStyles": titleStyles,
  753. // "itemStyles": itemStyles,
  754. // "isExpand": "no",
  755. // "filter": filter
  756. // }
  757. this.node.setStyle("display", "block");
  758. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  759. this.searchMorph = null;
  760. this.viewSearchCustomContentNode = null;
  761. var newJson = Object.merge( Object.clone(this.originalJson), json );
  762. this.container.empty();
  763. this.initialize( this.container, newJson, Object.clone(this.options), this.app, this.parentMacro);
  764. },
  765. confirm: function (type, e, title, text, width, height, ok, cancel, callback, mask, style) {
  766. this.app.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style)
  767. },
  768. alert: function (type, title, text, width, height) {
  769. this.app.alert(type, "center", title, text, width, height);
  770. },
  771. notice: function (content, type, target, where, offset, option) {
  772. this.app.notice(content, type, target, where, offset, option)
  773. },
  774. //api 使用 结束
  775. loadCurrentPageData: function( callback ){
  776. debugger;
  777. //是否需要在翻页的时候清空之前的items ?
  778. this.items = [];
  779. var p = this.currentPage;
  780. var d = {};
  781. var valueList = this.bundleItems.slice((p-1)*this.json.pageSize,this.json.pageSize*p);
  782. d.bundleList = valueList;
  783. while (this.viewTable.rows.length>1){
  784. this.viewTable.deleteRow(-1);
  785. }
  786. //this.createLoadding();
  787. this.loadViewRes = this.lookupAction.loadView(this.json.name, this.json.application, d, function(json){
  788. this.viewData = json.data;
  789. this.fireEvent("postLoadPageData");
  790. if (this.viewJson.group.column){
  791. this.gridJson = json.data.groupGrid;
  792. this.loadGroupData();
  793. }else{
  794. this.gridJson = json.data.grid;
  795. this.loadData();
  796. }
  797. if (this.gridJson.length) this._loadPageNode();
  798. if (this.loadingAreaNode){
  799. this.loadingAreaNode.destroy();
  800. this.loadingAreaNode = null;
  801. }
  802. this.fireEvent("loadView"); //options 传入的事件
  803. this.fireEvent("postLoadPage");
  804. if(callback)callback();
  805. }.bind(this));
  806. },
  807. loadData: function(){
  808. if (this.gridJson.length){
  809. // if( !this.options.paging ){
  810. this.gridJson.each(function(line, i){
  811. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, line, null, i));
  812. }.bind(this));
  813. // }else{
  814. // this.loadPaging();
  815. // }
  816. }else{
  817. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  818. }
  819. },
  820. loadPaging : function(){
  821. this.isItemsLoading = false;
  822. this.pageNumber = 0;
  823. this.isItemsLoaded = false;
  824. this.isSetedScroll = false;
  825. this.setScroll();
  826. this.loadDataByPaging()
  827. },
  828. setScroll : function(){
  829. if( this.options.paging && !this.isSetedScroll ){
  830. this.contentAreaNode.setStyle("overflow","auto");
  831. this.scrollContainerFun = function(){
  832. var scrollSize = this.contentAreaNode.getScrollSize();
  833. var clientSize = this.contentAreaNode.getSize();
  834. var scrollHeight = scrollSize.y - clientSize.y;
  835. //alert( "clientSize.y=" + clientSize.y + " scrollSize.y="+scrollSize.y + " this.contentAreaNode.scrollTop="+this.contentAreaNode.scrollTop);
  836. if (this.contentAreaNode.scrollTop + 150 > scrollHeight ) {
  837. if (!this.isItemsLoaded) this.loadDataByPaging();
  838. }
  839. }.bind(this);
  840. this.isSetedScroll = true;
  841. this.contentAreaNode.addEvent("scroll", this.scrollContainerFun )
  842. }
  843. },
  844. loadDataByPaging : function(){
  845. if( this.isItemsLoading )return;
  846. if( !this.isItemsLoaded ){
  847. var from = Math.min( this.pageNumber * this.options.perPageCount , this.gridJson.length);
  848. var to = Math.min( ( this.pageNumber + 1 ) * this.options.perPageCount + 1 , this.gridJson.length);
  849. this.isItemsLoading = true;
  850. for( var i = from; i<to; i++ ){
  851. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, this.gridJson[i], null, i));
  852. }
  853. this.isItemsLoading = false;
  854. this.pageNumber ++;
  855. if( to == this.gridJson.length )this.isItemsLoaded = true;
  856. }
  857. },
  858. loadGroupData: function(){
  859. if (this.selectTitleCell){
  860. this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
  861. this.selectTitleCell.setStyle("cursor", "pointer");
  862. this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
  863. }
  864. if (this.gridJson.length){
  865. var i = 0;
  866. this.gridJson.each(function(data){
  867. this.items.push(new MWF.xApplication.query.Query.Viewer.ItemCategory(this, data, i));
  868. i += data.list.length;
  869. }.bind(this));
  870. if (this.json.isExpand=="yes") this.expandOrCollapseAll();
  871. }else{
  872. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  873. }
  874. },
  875. expandOrCollapseAll: function(){
  876. var icon = this.selectTitleCell.getElement("span");
  877. if (icon.get("html").indexOf("expand.png")===-1){
  878. this.items.each(function(item){
  879. item.collapse();
  880. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>");
  881. }.bind(this));
  882. }else{
  883. this.items.each(function(item, i){
  884. window.setTimeout(function(){
  885. item.expand();
  886. }.bind(this), 10*i+5);
  887. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/down.png'/>");
  888. }.bind(this));
  889. }
  890. },
  891. getView: function(callback){
  892. this.getLookupAction(function(){
  893. if (this.json.application){
  894. this.getViewRes = this.lookupAction.getView(this.json.viewName, this.json.application, function(json){
  895. this.viewJson = JSON.decode(json.data.data);
  896. this.json = Object.merge(this.json, json.data);
  897. if (callback) callback();
  898. }.bind(this));
  899. // this.lookupAction.invoke({"name": "getView","async": true, "parameter": {"view": this.json.viewName, "application": this.json.application},"success": function(json){
  900. // this.viewJson = JSON.decode(json.data.data);
  901. // this.json = Object.merge(this.json, json.data);
  902. // //var viewData = JSON.decode(json.data.data);
  903. // if (callback) callback();
  904. // }.bind(this)});
  905. }else{
  906. this.getViewRes = this.lookupAction.getViewById(this.json.viewId, function(json){
  907. this.viewJson = JSON.decode(json.data.data);
  908. this.json.application = json.data.query;
  909. this.json = Object.merge(this.json, json.data);
  910. if (callback) callback();
  911. }.bind(this));
  912. }
  913. }.bind(this));
  914. },
  915. getLookupAction: function(callback){
  916. if (!this.lookupAction){
  917. this.lookupAction = MWF.Actions.get("x_query_assemble_surface");
  918. if (callback) callback();
  919. // var _self = this;
  920. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  921. // this.lookupAction = new MWF.xDesktop.Actions.RestActions("", this.options.actionRoot, "");
  922. // this.lookupAction.getActions = function(actionCallback){
  923. // this.actions = _self.options.actions;
  924. // if (actionCallback) actionCallback();
  925. // };
  926. // if (callback) callback();
  927. // }.bind(this));
  928. }else{
  929. if (callback) callback();
  930. }
  931. },
  932. hide: function(){
  933. this.node.setStyle("display", "none");
  934. },
  935. reload: function(){
  936. this.node.setStyle("display", "block");
  937. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  938. this.filterItems.each(function(filter){
  939. filter.destroy();
  940. }.bind(this));
  941. this.filterItems = [];
  942. if (this.viewSearchInputNode) this.viewSearchInputNode.set("text", this.lp.searchKeywork);
  943. this.closeCustomSearch();
  944. this.viewAreaNode.empty();
  945. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  946. },
  947. getFilter: function(){
  948. var filterData = [];
  949. if (this.searchStatus==="custom"){
  950. if (this.filterItems.length){
  951. this.filterItems.each(function(filter){
  952. filterData.push(filter.data);
  953. }.bind(this));
  954. }
  955. }
  956. if (this.searchStatus==="default"){
  957. var key = this.viewSearchInputNode.get("value");
  958. if (key && key!==this.lp.searchKeywork){
  959. this.viewJson.customFilterList.each(function(entry){
  960. if (entry.formatType==="textValue"){
  961. var d = {
  962. "path": entry.path,
  963. "value": key,
  964. "formatType": entry.formatType,
  965. "logic": "or",
  966. "comparison": "like"
  967. };
  968. filterData.push(d);
  969. }
  970. if (entry.formatType==="numberValue"){
  971. var v = key.toFloat();
  972. if (!isNaN(v)){
  973. var d = {
  974. "path": entry.path,
  975. "value": v,
  976. "formatType": entry.formatType,
  977. "logic": "or",
  978. "comparison": "like"
  979. };
  980. filterData.push(d);
  981. }
  982. }
  983. }.bind(this));
  984. }
  985. }
  986. return (filterData.length) ? filterData : null;
  987. },
  988. getSelectedData : function(){
  989. return this.getData();
  990. },
  991. getData: function(){
  992. if (this.selectedItems.length){
  993. var arr = [];
  994. this.selectedItems.each(function(item){
  995. arr.push(item.data);
  996. });
  997. return arr;
  998. }else{
  999. return [];
  1000. }
  1001. },
  1002. _loadModuleEvents : function(){
  1003. debugger;
  1004. Object.each(this.viewJson.events, function(e, key){
  1005. if (e.code){
  1006. if (this.options.moduleEvents.indexOf(key)!==-1){
  1007. this.addEvent(key, function(event, target){
  1008. debugger;
  1009. return this.Macro.fire(e.code, target || this, event);
  1010. }.bind(this));
  1011. }
  1012. }
  1013. }.bind(this));
  1014. },
  1015. _loadDomEvents: function(){
  1016. Object.each(this.viewJson.events, function(e, key){
  1017. if (e.code){
  1018. if (this.options.moduleEvents.indexOf(key)===-1){
  1019. this.node.addEvent(key, function(event){
  1020. return this.Macro.fire(e.code, this, event);
  1021. }.bind(this));
  1022. }
  1023. }
  1024. }.bind(this));
  1025. }
  1026. });
  1027. MWF.xApplication.query.Query.Viewer.Item = new Class({
  1028. initialize: function(view, data, prev, i){
  1029. this.view = view;
  1030. this.data = data;
  1031. this.css = this.view.css;
  1032. this.isSelected = false;
  1033. this.prev = prev;
  1034. this.idx = i;
  1035. this.clazzType = "item";
  1036. this.load();
  1037. },
  1038. load: function(){
  1039. this.view.fireEvent("queryLoadItemRow", [null, this]);
  1040. this.node = new Element("tr", {"styles": this.css.viewContentTrNode});
  1041. if (this.prev){
  1042. this.node.inject(this.prev.node, "after");
  1043. }else{
  1044. this.node.inject(this.view.viewTable);
  1045. }
  1046. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1047. this.selectTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1048. this.selectTd.setStyles({"cursor": "pointer"});
  1049. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1050. //}
  1051. //序号
  1052. if (this.view.viewJson.isSequence==="yes"){
  1053. this.sequenceTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1054. this.sequenceTd.setStyle("width", "10px");
  1055. var s= 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
  1056. this.sequenceTd.set("text", s);
  1057. }
  1058. Object.each(this.view.entries, function(c, k){
  1059. var cell = this.data.data[k];
  1060. if (cell === undefined) cell = "";
  1061. //if (cell){
  1062. if (this.view.hideColumns.indexOf(k)===-1){
  1063. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1064. if (k!== this.view.viewJson.group.column){
  1065. //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;
  1066. var v = cell;
  1067. if (c.isHtml){
  1068. td.set("html", v);
  1069. }else{
  1070. td.set("text", v);
  1071. }
  1072. }
  1073. if (this.view.openColumns.indexOf(k)!==-1){
  1074. this.setOpenWork(td, c)
  1075. }
  1076. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1077. }
  1078. //}
  1079. }.bind(this));
  1080. // Object.each(this.data.data, function(cell, k){
  1081. // if (this.view.hideColumns.indexOf(k)===-1){
  1082. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1083. // if (k!== this.view.viewJson.group.column){
  1084. // 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;
  1085. // td.set("text", v);
  1086. // }
  1087. // if (this.view.openColumns.indexOf(k)!==-1){
  1088. // this.setOpenWork(td)
  1089. // }
  1090. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1091. // }
  1092. // }.bind(this));
  1093. this.setEvent();
  1094. this.view.fireEvent("postLoadItemRow", [null, this]);
  1095. },
  1096. setOpenWork: function(td, column){
  1097. td.setStyle("cursor", "pointer");
  1098. if( column.clickCode ){
  1099. // if( !this.view.Macro ){
  1100. // MWF.require("MWF.xScript.Macro", function () {
  1101. // this.view.businessData = {};
  1102. // this.view.Macro = new MWF.Macro.PageContext(this.view);
  1103. // }.bind(this), false);
  1104. // }
  1105. td.addEvent("click", function( ev ){
  1106. var result = this.view.Macro.fire(column.clickCode, this, ev);
  1107. ev.stopPropagation();
  1108. return result;
  1109. }.bind(this));
  1110. }else{
  1111. if (this.view.json.type==="cms"){
  1112. td.addEvent("click", function(ev){
  1113. this.openCms(ev)
  1114. ev.stopPropagation();
  1115. }.bind(this));
  1116. }else{
  1117. td.addEvent("click", function(ev){
  1118. this.openWorkAndCompleted(ev)
  1119. ev.stopPropagation();
  1120. }.bind(this));
  1121. }
  1122. }
  1123. },
  1124. openCms: function(e){
  1125. var options = {"documentId": this.data.bundle};
  1126. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1127. layout.desktop.openApplication(e, "cms.Document", options);
  1128. },
  1129. openWorkAndCompleted: function(e){
  1130. MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(this.data.bundle, function(json){
  1131. var workCompletedCount = json.data.workCompletedList.length;
  1132. var workCount = json.data.workList.length;
  1133. var count = workCount+workCompletedCount;
  1134. if (count===1){
  1135. if (workCompletedCount) {
  1136. this.openWorkCompleted(json.data.workCompletedList[0].id, e);
  1137. }else{
  1138. this.openWork(json.data.workList[0].id, e);
  1139. }
  1140. }else if (count>1){
  1141. var worksAreaNode = this.createWorksArea();
  1142. json.data.workCompletedList.each(function(work){
  1143. this.createWorkCompletedNode(work, worksAreaNode);
  1144. }.bind(this));
  1145. json.data.workList.each(function(work){
  1146. this.createWorkNode(work, worksAreaNode);
  1147. }.bind(this));
  1148. this.showWorksArea(worksAreaNode, e);
  1149. }else{
  1150. }
  1151. }.bind(this));
  1152. },
  1153. createWorkNode: function(work, worksAreaNode){
  1154. var worksAreaContentNode = worksAreaNode.getLast();
  1155. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  1156. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  1157. actionNode.store("workId", work.id);
  1158. actionNode.addEvent("click", function(e){
  1159. this.openWork(e.target.retrieve("workId"), e);
  1160. this.mask.hide();
  1161. worksAreaNode.destroy();
  1162. }.bind(this));
  1163. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  1164. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  1165. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  1166. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  1167. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": work.activityName}).inject(contentNode);
  1168. var taskUsers = [];
  1169. MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
  1170. json.data.each(function(task){
  1171. taskUsers.push(MWF.name.cn(task.person));
  1172. }.bind(this));
  1173. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.taskPeople+": "}).inject(contentNode);
  1174. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": taskUsers.join(", ")}).inject(contentNode);
  1175. }.bind(this));
  1176. },
  1177. createWorkCompletedNode: function(work, worksAreaNode){
  1178. var worksAreaContentNode = worksAreaNode.getLast();
  1179. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  1180. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  1181. actionNode.store("workId", work.id);
  1182. actionNode.addEvent("click", function(e){
  1183. this.mask.hide();
  1184. var id = e.target.retrieve("workId");
  1185. worksAreaNode.destroy();
  1186. this.openWorkCompleted(id, e);
  1187. }.bind(this));
  1188. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  1189. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  1190. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  1191. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  1192. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": this.view.lp.processCompleted}).inject(contentNode);
  1193. },
  1194. createWorksArea: function(){
  1195. var worksAreaNode = new Element("div", {"styles": this.css.worksAreaNode});
  1196. var worksAreaTitleNode = new Element("div", {"styles": this.css.worksAreaTitleNode}).inject(worksAreaNode);
  1197. var worksAreaTitleCloseNode = new Element("div", {"styles": this.css.worksAreaTitleCloseNode}).inject(worksAreaTitleNode);
  1198. worksAreaTitleCloseNode.addEvent("click", function(e){
  1199. this.mask.hide();
  1200. e.target.getParent().getParent().destroy();
  1201. }.bind(this));
  1202. var worksAreaContentNode = new Element("div", {"styles": this.css.worksAreaContentNode}).inject(worksAreaNode);
  1203. return worksAreaNode;
  1204. },
  1205. showWorksArea: function(node, e){
  1206. MWF.require("MWF.widget.Mask", null, false);
  1207. this.mask = new MWF.widget.Mask({"style": "desktop", "loading": false});
  1208. this.mask.loadNode(this.view.container);
  1209. node.inject(this.view.node);
  1210. this.setWorksAreaPosition(node, e.target);
  1211. },
  1212. setWorksAreaPosition: function(node, td){
  1213. var p = td.getPosition(this.view.container);
  1214. var containerS = this.view.container.getSize();
  1215. var containerP = this.view.container.getPosition(this.view.container.getOffsetParent());
  1216. var s = node.getSize();
  1217. var offX = p.x+s.x-containerS.x;
  1218. offX = (offX>0) ? offX+20 : 0;
  1219. var offY = p.y+s.y-containerS.y;
  1220. offY = (offY>0) ? offY+5 : 0;
  1221. node.position({
  1222. "relativeTo": td,
  1223. "position": "lefttop",
  1224. "edge": "lefttop",
  1225. "offset": {
  1226. "x": 0-offX,
  1227. "y": 0-offY
  1228. }
  1229. });
  1230. },
  1231. openWork: function(id, e){
  1232. var options = {"workId": id};
  1233. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1234. layout.desktop.openApplication(e, "process.Work", options);
  1235. },
  1236. openWorkCompleted: function(id, e){
  1237. var options = {"workCompletedId": id};
  1238. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1239. layout.desktop.openApplication(e, "process.Work", options);
  1240. },
  1241. setEvent: function(){
  1242. var flag = this.view.json.select || this.view.viewJson.select || "none";
  1243. if ( flag ==="single" || flag==="multi"){
  1244. this.node.addEvents({
  1245. "mouseover": function(){
  1246. if (!this.isSelected){
  1247. var iconName = "checkbox";
  1248. if (flag==="single") iconName = "radiobox";
  1249. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/"+iconName+".png) center center no-repeat"});
  1250. }
  1251. }.bind(this),
  1252. "mouseout": function(){
  1253. if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
  1254. }.bind(this),
  1255. "click": function(){this.select();}.bind(this)
  1256. });
  1257. }
  1258. },
  1259. select: function(){
  1260. var flag = this.view.json.select || this.view.viewJson.select || "none";
  1261. if (this.isSelected){
  1262. if (flag==="single"){
  1263. this.unSelectedSingle();
  1264. }else{
  1265. this.unSelected();
  1266. }
  1267. }else{
  1268. if (flag==="single"){
  1269. this.selectedSingle();
  1270. }else{
  1271. this.selected();
  1272. }
  1273. }
  1274. this.view.fireEvent("select"); //options 传入的事件
  1275. },
  1276. selected: function(){
  1277. this.view.selectedItems.push(this);
  1278. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
  1279. this.node.setStyles(this.css.viewContentTrNode_selected);
  1280. this.isSelected = true;
  1281. this.view.fireEvent("selectRow", [this]);
  1282. },
  1283. unSelected: function(){
  1284. this.view.selectedItems.erase(this);
  1285. this.selectTd.setStyles({"background": "transparent"});
  1286. this.node.setStyles(this.css.viewContentTrNode);
  1287. this.isSelected = false;
  1288. this.view.fireEvent("unselectRow", [this]);
  1289. },
  1290. selectedSingle: function(){
  1291. if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
  1292. this.view.selectedItems = [this];
  1293. this.view.currentSelectedItem = this;
  1294. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/radiobox_checked.png) center center no-repeat"});
  1295. this.node.setStyles(this.css.viewContentTrNode_selected);
  1296. this.isSelected = true;
  1297. this.view.fireEvent("selectRow", [this]);
  1298. },
  1299. unSelectedSingle: function(){
  1300. this.view.selectedItems = [];
  1301. this.view.currentSelectedItem = null;
  1302. this.selectTd.setStyles({"background": "transparent"});
  1303. this.node.setStyles(this.css.viewContentTrNode);
  1304. this.isSelected = false;
  1305. this.view.fireEvent("unselectRow", [this]);
  1306. }
  1307. });
  1308. MWF.xApplication.query.Query.Viewer.ItemCategory = new Class({
  1309. initialize: function(view, data, i){
  1310. this.view = view;
  1311. this.data = data;
  1312. this.css = this.view.css;
  1313. this.items = [];
  1314. this.loadChild = false;
  1315. this.idx = i;
  1316. this.clazzType = "category";
  1317. this.load();
  1318. },
  1319. load: function(){
  1320. this.view.fireEvent("queryLoadCategoryRow", [null, this]);
  1321. this.node = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.view.viewTable);
  1322. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1323. this.selectTd = new Element("td", {"styles": this.css.viewContentCategoryTdNode}).inject(this.node);
  1324. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1325. //}
  1326. this.categoryTd = new Element("td", {
  1327. "styles": this.css.viewContentCategoryTdNode,
  1328. "colspan": this.view.viewJson.selectList.length+1
  1329. }).inject(this.node);
  1330. this.groupColumn = null;
  1331. for (var c = 0; c<this.view.viewJson.selectList.length; c++){
  1332. if (this.view.viewJson.selectList[c].column === this.view.viewJson.group.column){
  1333. this.groupColumn = this.view.viewJson.selectList[c];
  1334. break;
  1335. }
  1336. }
  1337. if (this.groupColumn){
  1338. //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;
  1339. var text = this.data.group;
  1340. }else{
  1341. var text = this.data.group;
  1342. }
  1343. 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);
  1344. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  1345. this.setEvent();
  1346. this.view.fireEvent("postLoadCategoryRow", [null, this]);
  1347. },
  1348. setEvent: function(){
  1349. //if (this.selectTd){
  1350. this.node.addEvents({
  1351. "click": function(){this.expandOrCollapse();}.bind(this)
  1352. });
  1353. //}
  1354. },
  1355. expandOrCollapse: function(){
  1356. var t = this.node.getElement("span").get("html");
  1357. if (t.indexOf("expand.png")===-1){
  1358. this.collapse();
  1359. }else{
  1360. this.expand();
  1361. }
  1362. },
  1363. collapse: function(){
  1364. this.items.each(function(item){
  1365. item.node.setStyle("display", "none");
  1366. }.bind(this));
  1367. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/>");
  1368. },
  1369. expand: function(){
  1370. this.items.each(function(item){
  1371. item.node.setStyle("display", "table-row");
  1372. }.bind(this));
  1373. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
  1374. if (!this.loadChild){
  1375. //window.setTimeout(function(){
  1376. this.data.list.each(function(line, i){
  1377. var s = this.idx+i;
  1378. this.lastItem = new MWF.xApplication.query.Query.Viewer.Item(this.view, line, (this.lastItem || this), s);
  1379. this.items.push(this.lastItem);
  1380. }.bind(this));
  1381. this.loadChild = true;
  1382. //}.bind(this), 10);
  1383. }
  1384. }
  1385. });
  1386. MWF.xApplication.query.Query.Viewer.Filter = new Class({
  1387. initialize: function(viewer, data, node){
  1388. this.viewer = viewer;
  1389. this.data = data;
  1390. this.css = this.viewer.css;
  1391. this.content = node;
  1392. this.load();
  1393. },
  1394. load: function(){
  1395. this.node = new Element("div", {"styles": this.css.viewSearchFilterNode}).inject(this.content);
  1396. if (this.viewer.filterItems.length){
  1397. this.logicNode = new Element("div", {"styles": this.css.viewSearchFilterSelectAreaNode}).inject(this.node);
  1398. this.logicSelectNode = new Element("div", {
  1399. "styles": this.css.viewSearchFilterSelectNode,
  1400. "text": this.viewer.lp.and,
  1401. "value": "and"
  1402. }).inject(this.logicNode);
  1403. this.logicSelectButtonNode = new Element("div", {"styles": this.css.viewSearchFilterSelectButtonNode}).inject(this.logicNode);
  1404. this.logicNode.addEvents({
  1405. "click": function(){
  1406. var v = this.logicSelectNode.get("value");
  1407. if (v==="and"){
  1408. this.logicSelectButtonNode.setStyle("float", "left");
  1409. this.logicSelectNode.setStyle("float", "right");
  1410. this.logicSelectNode.set({
  1411. "text": this.viewer.lp.or,
  1412. "value": "or"
  1413. });
  1414. this.data.logic = "or";
  1415. }else{
  1416. this.logicSelectButtonNode.setStyle("float", "right");
  1417. this.logicSelectNode.setStyle("float", "left");
  1418. this.logicSelectNode.set({
  1419. "text": this.viewer.lp.and,
  1420. "value": "and"
  1421. });
  1422. this.data.logic = "and";
  1423. }
  1424. this.viewer.searchCustomView();
  1425. }.bind(this)
  1426. });
  1427. }
  1428. this.titleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.title}).inject(this.node);
  1429. this.comparisonTitleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.comparisonTitle}).inject(this.node);
  1430. this.valueNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": "\""+this.data.value+"\""}).inject(this.node);
  1431. this.deleteNode = new Element("div", {"styles": this.css.viewSearchFilterDeleteNode}).inject(this.node);
  1432. this.node.addEvents({
  1433. "mouseover": function(){
  1434. this.node.setStyles(this.css.viewSearchFilterNode_over);
  1435. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode_over);
  1436. }.bind(this),
  1437. "mouseout": function(){
  1438. this.node.setStyles(this.css.viewSearchFilterNode);
  1439. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode);
  1440. }.bind(this)
  1441. });
  1442. this.deleteNode.addEvent("click", function(){
  1443. this.viewer.searchViewRemoveFilter(this);
  1444. }.bind(this));
  1445. },
  1446. destroy: function(){
  1447. this.node.destroy();
  1448. MWF.release(this);
  1449. }
  1450. });
  1451. MWF.xApplication.query.Query.Viewer.Actionbar = new Class({
  1452. Implements: [Events],
  1453. options: {
  1454. "style" : "default",
  1455. "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad"]
  1456. },
  1457. initialize: function(node, json, form, options){
  1458. this.node = $(node);
  1459. this.node.store("module", this);
  1460. this.json = json;
  1461. this.form = form;
  1462. this.view = form;
  1463. },
  1464. hide: function(){
  1465. var dsp = this.node.getStyle("display");
  1466. if (dsp!=="none") this.node.store("mwf_display", dsp);
  1467. this.node.setStyle("display", "none");
  1468. },
  1469. show: function(){
  1470. var dsp = this.node.retrieve("mwf_display", dsp);
  1471. this.node.setStyle("display", dsp);
  1472. },
  1473. load: function(){
  1474. this._loadModuleEvents();
  1475. if (this.fireEvent("queryLoad")){
  1476. //this._queryLoaded();
  1477. this._loadUserInterface();
  1478. this._loadStyles();
  1479. this._loadDomEvents();
  1480. //this._loadEvents();
  1481. //this._afterLoaded();
  1482. this.fireEvent("postLoad");
  1483. this.fireEvent("load");
  1484. }
  1485. },
  1486. _loadStyles: function(){
  1487. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  1488. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  1489. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1490. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1491. var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  1492. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  1493. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1494. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  1495. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1496. }
  1497. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  1498. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1499. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  1500. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1501. }
  1502. if (value.indexOf("/x_cms_assemble_control")!==-1){
  1503. value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1504. }else if (value.indexOf("x_cms_assemble_control")!==-1){
  1505. value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1506. }
  1507. }
  1508. this.node.setStyle(key, value);
  1509. }.bind(this));
  1510. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  1511. // var host = MWF.Actions.getHost(root);
  1512. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  1513. // }
  1514. //if (this.json.styles) this.node.setStyles(this.json.styles);
  1515. },
  1516. _loadModuleEvents : function(){
  1517. Object.each(this.json.events, function(e, key){
  1518. if (e.code){
  1519. if (this.options.moduleEvents.indexOf(key)!==-1){
  1520. this.addEvent(key, function(event){
  1521. return this.form.Macro.fire(e.code, this, event);
  1522. }.bind(this));
  1523. }
  1524. }
  1525. }.bind(this));
  1526. },
  1527. _loadDomEvents: function(){
  1528. Object.each(this.json.events, function(e, key){
  1529. if (e.code){
  1530. if (this.options.moduleEvents.indexOf(key)===-1){
  1531. this.node.addEvent(key, function(event){
  1532. return this.form.Macro.fire(e.code, this, event);
  1533. }.bind(this));
  1534. }
  1535. }
  1536. }.bind(this));
  1537. },
  1538. _loadEvents: function(){
  1539. Object.each(this.json.events, function(e, key){
  1540. if (e.code){
  1541. if (this.options.moduleEvents.indexOf(key)!==-1){
  1542. this.addEvent(key, function(event){
  1543. return this.form.Macro.fire(e.code, this, event);
  1544. }.bind(this));
  1545. }else{
  1546. this.node.addEvent(key, function(event){
  1547. return this.form.Macro.fire(e.code, this, event);
  1548. }.bind(this));
  1549. }
  1550. }
  1551. }.bind(this));
  1552. },
  1553. addModuleEvent: function(key, fun){
  1554. if (this.options.moduleEvents.indexOf(key)!==-1){
  1555. this.addEvent(key, function(event){
  1556. return (fun) ? fun(this, event) : null;
  1557. }.bind(this));
  1558. }else{
  1559. this.node.addEvent(key, function(event){
  1560. return (fun) ? fun(this, event) : null;
  1561. }.bind(this));
  1562. }
  1563. },
  1564. _loadUserInterface: function(){
  1565. // if (this.form.json.mode == "Mobile"){
  1566. // this.node.empty();
  1567. // }else if (COMMON.Browser.Platform.isMobile){
  1568. // this.node.empty();
  1569. // }else{
  1570. this.toolbarNode = this.node.getFirst("div");
  1571. if( !this.toolbarNode ){
  1572. this.toolbarNode = new Element("div").inject( this.node );
  1573. }
  1574. this.toolbarNode.empty();
  1575. MWF.require("MWF.widget.Toolbar", function(){
  1576. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
  1577. "style": this.json.style,
  1578. "onPostLoad" : function(){
  1579. this.fireEvent("afterLoad");
  1580. }.bind(this)
  1581. }, this);
  1582. if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
  1583. //alert(this.readonly)
  1584. if (this.json.hideSystemTools){
  1585. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1586. this.toolbarWidget.load();
  1587. }else{
  1588. if (this.json.defaultTools){
  1589. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  1590. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1591. this.toolbarWidget.load();
  1592. }else{
  1593. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  1594. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  1595. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1596. this.toolbarWidget.load();
  1597. }.bind(this), null);
  1598. }
  1599. }
  1600. }.bind(this));
  1601. // }
  1602. },
  1603. setCustomToolbars: function(tools, node){
  1604. var path = "/x_component_process_FormDesigner/Module/Actionbar/";
  1605. var iconPath = "";
  1606. if( this.json.customIconStyle ){
  1607. iconPath = this.json.customIconStyle+"/";
  1608. }
  1609. tools.each(function(tool){
  1610. var flag = true;
  1611. if (this.readonly){
  1612. flag = tool.readShow;
  1613. }else{
  1614. flag = tool.editShow;
  1615. }
  1616. if (flag){
  1617. flag = true;
  1618. // if (tool.control){
  1619. // flag = this.form.businessData.control[tool.control]
  1620. // }
  1621. if (tool.condition){
  1622. var hideFlag = this.form.Macro.exec(tool.condition, this);
  1623. flag = !hideFlag;
  1624. }
  1625. if (flag){
  1626. var actionNode = new Element("div", {
  1627. "id": tool.id,
  1628. "MWFnodetype": tool.type,
  1629. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+iconPath+tool.img,
  1630. "title": tool.title,
  1631. "MWFButtonAction": "runCustomAction",
  1632. "MWFButtonText": tool.text
  1633. }).inject(node);
  1634. if( this.json.customIconOverStyle ){
  1635. actionNode.set("MWFButtonImageOver" , path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  1636. }
  1637. if( tool.properties ){
  1638. actionNode.set(tool.properties);
  1639. }
  1640. if (tool.actionScript){
  1641. actionNode.store("script", tool.actionScript);
  1642. }
  1643. if (tool.sub){
  1644. var subNode = node.getLast();
  1645. this.setCustomToolbars(tool.sub, subNode);
  1646. }
  1647. }
  1648. }
  1649. }.bind(this));
  1650. },
  1651. setToolbarItem: function(tool, node, readonly, noCondition){
  1652. //var path = "/x_component_process_FormDesigner/Module/Actionbar/";
  1653. var path = "/x_component_query_ViewDesigner/$View/";
  1654. var flag = true;
  1655. // if (tool.control){
  1656. // flag = this.form.businessData.control[tool.control]
  1657. // }
  1658. if (!noCondition) if (tool.condition){
  1659. var hideFlag = this.form.Macro.exec(tool.condition, this);
  1660. flag = flag && (!hideFlag);
  1661. }
  1662. if (readonly) if (!tool.read) flag = false;
  1663. if (flag){
  1664. var actionNode = new Element("div", {
  1665. "id": tool.id,
  1666. "MWFnodetype": tool.type,
  1667. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  1668. //"MWFButtonImage": path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  1669. "MWFButtonImage": path+this.options.style+"/actionbar/"+tool.img,
  1670. "title": tool.title,
  1671. "MWFButtonAction": tool.action,
  1672. "MWFButtonText": tool.text
  1673. }).inject(node);
  1674. if( this.json.iconOverStyle ){
  1675. actionNode.set("MWFButtonImageOver" , path+""+this.options.style+"/actionbar/"+this.json.iconOverStyle+"/"+tool.img );
  1676. //actionNode.set("MWFButtonImageOver" , path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+tool.img );
  1677. }
  1678. if( tool.properties ){
  1679. actionNode.set(tool.properties);
  1680. }
  1681. if (tool.sub){
  1682. var subNode = node.getLast();
  1683. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  1684. }
  1685. }
  1686. },
  1687. setToolbars: function(tools, node, readonly, noCondition){
  1688. tools.each(function(tool){
  1689. this.setToolbarItem(tool, node, readonly, noCondition);
  1690. }.bind(this));
  1691. },
  1692. runCustomAction: function(bt){
  1693. var script = bt.node.retrieve("script");
  1694. this.form.Macro.exec(script, this);
  1695. },
  1696. exportView : function(){
  1697. this.form.exportView();
  1698. },
  1699. deleteWork: function(){
  1700. this.form.deleteWork();
  1701. }
  1702. });