Statement.js 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.query = MWF.xApplication.query || {};
  3. MWF.xApplication.query.StatementDesigner = MWF.xApplication.query.StatementDesigner || {};
  4. MWF.APPDSMD = MWF.xApplication.query.StatementDesigner;
  5. MWF.xDesktop.requireApp("query.StatementDesigner", "lp."+MWF.language, null, false);
  6. MWF.xDesktop.requireApp("query.StatementDesigner", "Property", null, false);
  7. MWF.xDesktop.requireApp("query.ViewDesigner", "View", null, false);
  8. o2.require("o2.widget.JavascriptEditor", null, false);
  9. o2.require("o2.widget.UUID", null, false);
  10. MWF.xApplication.query.StatementDesigner.Statement = new Class({
  11. Extends: MWF.widget.Common,
  12. Implements: [Options, Events],
  13. options: {
  14. "style": "default",
  15. "isView": false,
  16. "showTab": true,
  17. "propertyPath": "../x_component_query_StatementDesigner/$Statement/statement.html"
  18. },
  19. initialize: function(designer, data, options){
  20. this.setOptions(options);
  21. this.path = "../x_component_query_StatementDesigner/$Statement/";
  22. this.cssPath = "../x_component_query_StatementDesigner/$Statement/"+this.options.style+"/css.wcss";
  23. this._loadCss();
  24. this.designer = designer;
  25. this.data = data;
  26. this.parseData();
  27. this.node = this.designer.designNode;
  28. this.areaNode = new Element("div", {"styles": {"height": "100%", "overflow": "auto"}});
  29. //this.statementRunNode = this.designer.designerStatementArea;
  30. if(this.designer.application) this.data.applicationName = this.designer.application.name;
  31. if(this.designer.application) this.data.application = this.designer.application.id;
  32. this.isNewStatement = (this.data.id) ? false : true;
  33. this.view = this;
  34. this.autoSave();
  35. this.designer.addEvent("queryClose", function(){
  36. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  37. }.bind(this));
  38. },
  39. parseData: function(){
  40. this.json = this.data;
  41. if (!this.json.type) this.json.type = "select";
  42. if (!this.json.format) this.json.format = "jpql";
  43. if (!this.json.entityCategory) this.json.entityCategory = "official";
  44. if (!this.json.entityClassName) this.json.entityClassName = "com.x.processplatform.core.entity.content.Task";
  45. },
  46. autoSave: function(){
  47. this.autoSaveTimerID = window.setInterval(function(){
  48. if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFAutoSaveCheck");
  49. if (this.autoSaveCheckNode){
  50. if (this.autoSaveCheckNode.get("checked")){
  51. this.save();
  52. }
  53. }
  54. }.bind(this), 60000);
  55. },
  56. load : function(){
  57. // this.setAreaNodeSize();
  58. // this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  59. this.areaNode.inject(this.node);
  60. this.designer.statementListAreaNode.getChildren().each(function(node){
  61. var statement = node.retrieve("statement");
  62. if (statement.id==this.data.id){
  63. if (this.designer.currentListStatementItem){
  64. this.designer.currentListStatementItem.setStyles(this.designer.css.listStatementItem);
  65. }
  66. node.setStyles(this.designer.css.listStatementItem_current);
  67. this.designer.currentListStatementItem = node;
  68. this.lisNode = node;
  69. }
  70. }.bind(this));
  71. this.loadStatement();
  72. // this.showProperty();
  73. this.selected();
  74. },
  75. selected: function(){
  76. if (this.currentSelectedModule){
  77. if (this.currentSelectedModule==this){
  78. return true;
  79. }else{
  80. this.currentSelectedModule.unSelected();
  81. }
  82. }
  83. if( this.view && this.view.domListNode ){
  84. this.view.domListNode.hide();
  85. }
  86. this.currentSelectedModule = this;
  87. this.isSelected = true;
  88. this.showProperty();
  89. },
  90. unSelected: function(){
  91. this.currentSelectedModule = null;
  92. this.isSelected = false;
  93. this.hideProperty();
  94. },
  95. showProperty: function(){
  96. if (!this.property){
  97. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.designerContentArea, this.designer, {
  98. "path": this.options.propertyPath,
  99. "onPostLoad": function(){
  100. this.property.show();
  101. }.bind(this)
  102. });
  103. this.property.load();
  104. }else{
  105. this.property.show();
  106. }
  107. },
  108. hideProperty: function(){
  109. if (this.property) this.property.hide();
  110. },
  111. loadJpqlTab: function(callback){
  112. var _self = this;
  113. MWF.require("MWF.widget.Tab", null, false);
  114. this.jpqlTab = new MWF.widget.Tab(this.jpqlTabNode, {"style": "script"});
  115. this.jpqlTab.load();
  116. this.tabJpqlNode = Element("div");
  117. this.jpqlTabPageNode.inject( this.tabJpqlNode );
  118. this.tabCountJpqlNode = Element("div");
  119. this.countJpqlTabPageNode.inject( this.tabCountJpqlNode );
  120. this.jpqlPage = this.jpqlTab.addTab(this.tabJpqlNode, this.designer.lp.queryStatement);
  121. this.countJpqlPage = this.jpqlTab.addTab(this.tabCountJpqlNode, this.designer.lp.countStatement );
  122. this.jpqlPage.showTabIm();
  123. // this.jpqlPage.addEvent("postShow", function(){
  124. // if( this.view ){
  125. // this.view.setContentHeight();
  126. // this.view.selected();
  127. // }
  128. // }.bind(this));
  129. // this.countJpqlPage.addEvent("postShow", function(){
  130. // this.selected();
  131. // }.bind(this));
  132. },
  133. loadTab: function(callback){
  134. var _self = this;
  135. MWF.require("MWF.widget.Tab", null, false);
  136. this.tab = new MWF.widget.Tab(this.tabNode, {"style": "script"});
  137. this.tab.load();
  138. this.tabRunNode = Element("div");
  139. this.pageRunNode = new Element("div", {"styles": {"overflow": "auto","background-color":"#fff"}}).inject(this.tabRunNode);
  140. this.runArea.inject( this.pageRunNode );
  141. this.tabViewNode = Element("div", {"styles": { "height": "100%" }});
  142. this.pageViewNode = new Element("div.pageViewNode").inject(this.tabViewNode);
  143. this.viewArea.inject( this.pageViewNode );
  144. this.runPage = this.tab.addTab(this.tabRunNode, this.designer.lp.runTest);
  145. this.viewPage = this.tab.addTab(this.tabViewNode, this.designer.lp.view );
  146. this.runPage.showTabIm();
  147. this.viewPage.addEvent("postShow", function(){
  148. if( this.view ){
  149. this.view.setContentHeight();
  150. this.view.selected();
  151. }
  152. }.bind(this));
  153. this.runPage.addEvent("postShow", function(){
  154. this.selected();
  155. }.bind(this));
  156. },
  157. loadStatement: function(){
  158. //this.statementDesignerNode = new Element("div", {"styles": this.css.statementDesignerNode}).inject(this.areaNode);
  159. this.loadStatementHtml(function(){
  160. this.designerArea = this.areaNode.getElement(".o2_statement_statementDesignerNode");
  161. this.jpqlTabPageNode = this.areaNode.getElement(".o2_statement_statementJpqlTabPageNode");
  162. this.jpqlArea = this.areaNode.getElement(".o2_statement_statementDesignerJpql");
  163. this.scriptArea = this.areaNode.getElement(".o2_statement_statementDesignerScript");
  164. this.formatTypeArea = this.areaNode.getElement(".o2_statement_statementDesignerFormatContent");
  165. this.entityCategorySelect = this.areaNode.getElement(".o2_statement_statementDesignerCategoryContent").getElement("select");
  166. this.dynamicTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_dynamic");
  167. this.officialTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_official");
  168. this.customTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_custom");
  169. this.dynamicTableSelect = this.areaNode.getElement(".o2_statement_statementDesignerSelectTable");
  170. this.officialTableSelect = this.officialTableArea.getElement("select");
  171. this.dynamicTableContent = this.areaNode.getElement(".o2_statement_statementDesignerTableContent");
  172. this.jpqlTabNode = this.areaNode.getElement(".o2_statement_statementJpqlTabNode");
  173. this.jpqlTypeSelect = this.areaNode.getElement(".o2_statement_statementDesignerTypeContent").getElement("select");
  174. // this.jpqlSelectEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_select");
  175. // this.jpqlUpdateEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_update");
  176. // this.jpqlDeleteEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_sdelete");
  177. // this.jpqlSelectEditor_selectContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_selectContent");
  178. // this.jpqlSelectEditor_fromContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_fromContent");
  179. // this.jpqlSelectEditor_whereContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_whereContent");
  180. this.jpqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerJpqlLine");
  181. this.countJpqlTabPageNode = this.areaNode.getElement(".o2_statement_statementCountJpqlTabPageNode");
  182. this.countJpqlArea = this.areaNode.getElement(".o2_statement_statementDesignerCountJpql");
  183. this.countScriptArea = this.areaNode.getElement(".o2_statement_statementDesignerCountScript");
  184. this.countJpqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerCountJpqlLine");
  185. this.loadJpqlTab();
  186. this.tabNode = this.areaNode.getElement(".o2_statement_tabNode");
  187. this.runArea = this.areaNode.getElement(".o2_statement_statementRunNode");
  188. // this.runTitleNode = this.areaNode.getElement(".o2_statement_statementRunTitleNode");
  189. this.runContentNode = this.areaNode.getElement(".o2_statement_statementRunContentNode");
  190. this.runJsonNode = this.runContentNode.getFirst();
  191. this.runActionNode = this.runJsonNode.getNext();
  192. this.runResultNode = this.runContentNode.getLast();
  193. this.setRunnerSize();
  194. this.designer.addEvent("resize", this.setRunnerSize.bind(this));
  195. if (this.json.format=="script"){
  196. this.loadStatementScriptEditor();
  197. this.loadStatementCountScriptEditor();
  198. }else{
  199. this.loadStatementEditor();
  200. this.loadStatementCountEditor();
  201. }
  202. this.loadStatementRunner();
  203. this.viewArea = this.areaNode.getElement(".o2_statement_viewNode");
  204. this.loadView();
  205. this.loadTab();
  206. this.setEvent();
  207. }.bind(this));
  208. },
  209. loadStatementScriptEditor: function(){
  210. if (! this.scriptEditor){
  211. debugger;
  212. o2.require("o2.widget.ScriptArea", function(){
  213. this.scriptEditor = new o2.widget.ScriptArea(this.scriptArea, {
  214. "isbind": false,
  215. "maxObj": this.designer.designNode,
  216. "title": this.designer.lp.scriptTitle,
  217. "onChange": function(){
  218. this.json.scriptText = this.scriptEditor.toJson().code;
  219. }.bind(this)
  220. });
  221. this.scriptEditor.load({"code": this.json.scriptText})
  222. }.bind(this), false);
  223. }
  224. },
  225. loadStatementCountScriptEditor: function(){
  226. if (! this.countScriptEditor){
  227. debugger;
  228. o2.require("o2.widget.ScriptArea", function(){
  229. this.countScriptEditor = new o2.widget.ScriptArea(this.countScriptArea, {
  230. "isbind": false,
  231. "maxObj": this.designer.designNode,
  232. "title": this.designer.lp.scriptTitle,
  233. "onChange": function(){
  234. this.json.countScriptText = this.countScriptEditor.toJson().code;
  235. }.bind(this)
  236. });
  237. this.countScriptEditor.load({"code": this.json.countScriptText})
  238. }.bind(this), false);
  239. }
  240. },
  241. setRunnerSize: function(){
  242. debugger;
  243. var size = this.areaNode.getSize();
  244. var designerSize = this.designerArea.getComputedSize();
  245. var y = size.y-designerSize.totalHeight;
  246. var mTop = this.runArea.getStyle("margin-top").toInt();
  247. var mBottom = this.runArea.getStyle("margin-bottom").toInt();
  248. var pTop = this.runArea.getStyle("padding-top").toInt();
  249. var pBottom = this.runArea.getStyle("padding-bottom").toInt();
  250. y = y-mTop-mBottom-pTop-pBottom-1;
  251. var tabSize = this.tabNode.getComputedSize();
  252. y = y - tabSize.totalHeight;
  253. this.runArea.setStyle("height", ""+y+"px");
  254. // var titleSize = this.runTitleNode.getComputedSize();
  255. // y = y - titleSize.totalHeight;
  256. this.runContentNode.setStyle("height", ""+y+"px");
  257. },
  258. loadStatementEditor: function(){
  259. if (!this.editor){
  260. o2.require("o2.widget.JavascriptEditor", function(){
  261. this.editor = new o2.widget.JavascriptEditor(this.jpqlEditorNode, {"title": "JPQL", "option": {"mode": "sql"}});
  262. this.editor.load(function(){
  263. if (this.json.data){
  264. this.editor.editor.setValue(this.json.data);
  265. }else{
  266. var table = "table";
  267. switch (this.json.type) {
  268. case "update":
  269. this.editor.editor.setValue("UPDATE "+table+" o SET ");
  270. break;
  271. case "delete":
  272. this.editor.editor.setValue("DELETE "+table+" o WHERE ");
  273. break;
  274. default:
  275. this.editor.editor.setValue("SELECT * FROM "+table+" o");
  276. }
  277. }
  278. this.json.data = this.editor.editor.getValue();
  279. this.editor.addEditorEvent("change", function(){
  280. debugger;
  281. this.data.data = this.editor.getValue();
  282. this.checkJpqlType();
  283. }.bind(this));
  284. // this.editor.editor.on("change", function(){
  285. // this.data.data = this.editor.getValue();
  286. // this.checkJpqlType();
  287. // }.bind(this));
  288. }.bind(this));
  289. }.bind(this), false);
  290. }
  291. },
  292. loadStatementCountEditor: function(){
  293. if (!this.countEditor){
  294. o2.require("o2.widget.JavascriptEditor", function(){
  295. this.countEditor = new o2.widget.JavascriptEditor(this.countJpqlEditorNode, {"title": "JPQL", "option": {"mode": "sql"}});
  296. this.countEditor.load(function(){
  297. if (this.json.countData){
  298. this.countEditor.editor.setValue(this.json.countData);
  299. }else{
  300. var table = "table";
  301. this.countEditor.editor.setValue("SELECT count(o.id) FROM "+table+" o");
  302. }
  303. this.json.countData = this.countEditor.editor.getValue();
  304. this.countEditor.addEditorEvent("change", function(){
  305. debugger;
  306. this.data.countData = this.countEditor.getValue();
  307. }.bind(this));
  308. // this.editor.editor.on("change", function(){
  309. // this.data.data = this.editor.getValue();
  310. // this.checkJpqlType();
  311. // }.bind(this));
  312. }.bind(this));
  313. }.bind(this), false);
  314. }
  315. },
  316. setSatementTable: function(){
  317. if (!this.json.type) this.json.type = "select";
  318. this.changeType(this.json.type, true);
  319. if (this.json.data){
  320. this.editor.editor.setValue(this.json.data);
  321. }else{
  322. var table = (this.json.tableObj) ? this.json.tableObj.name : "table";
  323. switch (this.json.type) {
  324. case "update":
  325. this.editor.editor.setValue("UPDATE "+table+" o SET ");
  326. break;
  327. case "delete":
  328. this.editor.editor.setValue("DELETE "+table+" o WHERE ");
  329. break;
  330. default:
  331. this.editor.editor.setValue("SELECT * FROM "+table+" o");
  332. }
  333. }
  334. },
  335. checkJpqlType: function(){
  336. var str = this.json.data;
  337. this.json.data = str;
  338. var jpql_select = /^select/i;
  339. var jpql_update = /^update/i;
  340. var jpql_delete = /^delete/i;
  341. if (jpql_select.test(str)) return this.changeType("select");
  342. if (jpql_update.test(str)) return this.changeType("update");
  343. if (jpql_delete.test(str)) return this.changeType("delete");
  344. },
  345. changeType: function(type, force){
  346. if (this.json.type!=type) this.json.type=type;
  347. if (type != this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value || force){
  348. for (var i=0; i<this.jpqlTypeSelect.options.length; i++){
  349. if (this.jpqlTypeSelect.options[i].value==type){
  350. this.jpqlTypeSelect.options[i].set("selected", true);
  351. break;
  352. }
  353. }
  354. }
  355. },
  356. loadStatementHtml: function(callback){
  357. this.areaNode.loadAll({
  358. "css": this.path+this.options.style+"/statement.css",
  359. "html": this.path+"statementDesigner.html"
  360. }, {
  361. "bind": {"lp": this.designer.lp, "data": this.data}
  362. },function(){
  363. if (callback) callback();
  364. }.bind(this));
  365. },
  366. loadStatementRunner: function(){
  367. o2.require("o2.widget.JavascriptEditor", function(){
  368. this.jsonEditor = new o2.widget.JavascriptEditor(this.runJsonNode, {"title": "JPQL", "option": {"mode": "json"}});
  369. this.jsonEditor.load(function(){
  370. this.jsonEditor.editor.setValue("{}");
  371. }.bind(this));
  372. }.bind(this), false);
  373. },
  374. setEvent: function(){
  375. this.designerArea.addEvent("click", function (e) {
  376. this.selected();
  377. e.stopPropagation();
  378. }.bind(this));
  379. this.formatTypeArea.getElements("input").addEvent("click", function(e){
  380. if (e.target.checked){
  381. var v = e.target.get("value");
  382. if (v==="script"){
  383. this.scriptArea.show();
  384. this.jpqlArea.hide();
  385. this.loadStatementScriptEditor();
  386. this.countScriptArea.show();
  387. this.countJpqlArea.hide();
  388. this.loadStatementCountScriptEditor();
  389. }else{
  390. this.scriptArea.hide();
  391. this.jpqlArea.show();
  392. this.loadStatementEditor();
  393. this.countScriptArea.hide();
  394. this.countJpqlArea.show();
  395. this.loadStatementCountEditor();
  396. }
  397. this.json.format = v;
  398. }
  399. }.bind(this));
  400. this.entityCategorySelect.addEvent("change", function(e){
  401. var entityCategory = e.target.options[e.target.selectedIndex].value;
  402. switch (entityCategory) {
  403. case "dynamic":
  404. this.officialTableArea.hide();
  405. this.dynamicTableArea.show();
  406. this.customTableArea.hide();
  407. break;
  408. case "custom":
  409. this.officialTableArea.hide();
  410. this.dynamicTableArea.hide();
  411. this.customTableArea.show();
  412. break;
  413. default:
  414. this.officialTableArea.show();
  415. this.dynamicTableArea.hide();
  416. this.customTableArea.hide();
  417. break;
  418. }
  419. this.json.entityCategory = entityCategory
  420. }.bind(this));
  421. //@todo change table
  422. this.officialTableSelect.addEvent("change", function(e){
  423. debugger;
  424. var entityClassName = e.target.options[e.target.selectedIndex].value;
  425. this.json.entityClassName = entityClassName;
  426. if (this.json.format=="jpql"){
  427. if (this.editor){
  428. var re = /(.*from\s*)/ig;
  429. if (this.json.type=="update") re = /(.*update\s*)/ig;
  430. //if (this.json.type=="select" && this.editor){
  431. var v = this.json.data;
  432. var re2 = /(\s+)/ig;
  433. var arr = re.exec(v);
  434. if (arr && arr[0]){
  435. var left = arr[0]
  436. v = v.substring(left.length, v.length);
  437. //var ar = re2.exec(v);
  438. var right = v.substring(v.indexOf(" "),v.length);
  439. this.json.data = left+entityClassName+right;
  440. this.editor.editor.setValue(this.json.data);
  441. }
  442. //}
  443. }
  444. }
  445. // var className = e.target.options[e.target.selectedIndex].value;
  446. // if (this.json.type=="select"){
  447. // this.json.data
  448. // /(select)*(where|)/g
  449. // }
  450. // }.bind(this));
  451. // this.jpqlTypeSelect.addEvent("change", function(){
  452. // var type = e.target.options[e.target.selectedIndex].value;
  453. // switch (entityCategory) {
  454. // case "update":
  455. // this.jpqlSelectEditor.hide();
  456. // this.jpqlUpdateEditor.show();
  457. // this.jpqlDeleteEditor.hide();
  458. // this.loadJpqlUpdateEditor();
  459. // break;
  460. // case "delete":
  461. // this.jpqlSelectEditor.hide();
  462. // this.jpqlUpdateEditor.hide();
  463. // this.jpqlDeleteEditor.show();
  464. // break;
  465. // default:
  466. // this.jpqlSelectEditor.show();
  467. // this.jpqlUpdateEditor.hide();
  468. // this.jpqlDeleteEditor.hide();
  469. // break;
  470. // }
  471. }.bind(this));
  472. this.runActionNode.getFirst().addEvent("click", this.runStatement.bind(this));
  473. this.dynamicTableSelect.addEvent("click", this.selectTable.bind(this));
  474. this.jpqlTypeSelect.addEvent("change", function(){
  475. var t = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value;
  476. if (t!=this.json.type){
  477. this.json.type = t;
  478. }
  479. if( t!="select"){
  480. this.jpqlPage.showTabIm();
  481. this.countJpqlPage.disableTab();
  482. this.runPage.showTabIm();
  483. this.viewPage.disableTab();
  484. }else{
  485. this.countJpqlPage.enableTab( true );
  486. this.viewPage.enableTab( true );
  487. }
  488. }.bind(this));
  489. },
  490. selectTable: function(){
  491. new MWF.O2Selector(this.designer.content, {
  492. "type": "queryTable",
  493. "count": 1,
  494. "values": (this.json.table) ? [this.json.table] : [],
  495. "title": this.designer.lp.selectTable,
  496. "onComplete": function(items){
  497. if (items.length){
  498. var id = items[0].data.id;
  499. var name = items[0].data.name;
  500. this.dynamicTableContent.set("text", name);
  501. this.json.table = name;
  502. this.json.tableObj = items[0].data;
  503. }else{
  504. this.dynamicTableContent.set("text", "");
  505. this.json.table = "";
  506. }
  507. }.bind(this)
  508. });
  509. },
  510. runStatement:function(){
  511. debugger;
  512. // if (!this.json.data){
  513. // this.designer.notice(this.designer.lp.inputStatementData, "error");
  514. // return false;
  515. // }
  516. o2.require("o2.widget.Mask", null, false);
  517. this.runMask = new o2.widget.Mask();
  518. this.runMask.loadNode(this.node);
  519. this.saveSilence(function(){
  520. var json = this.jsonEditor.editor.getValue();
  521. var o = JSON.parse(json);
  522. o2.Actions.get("x_query_assemble_designer").executeStatement(this.json.id, 1, 50 , o, function(json){
  523. o2.require("o2.widget.JsonParse", function(){
  524. this.runResultNode.empty();
  525. var jsonResult = new o2.widget.JsonParse(json.data, this.runResultNode);
  526. jsonResult.load();
  527. }.bind(this));
  528. this.runMask.hide();
  529. }.bind(this), function(xhr, text, error){
  530. debugger;
  531. if (this.runMask) this.runMask.hide();
  532. var errorText = error;
  533. if (xhr){
  534. var json = JSON.decode(xhr.responseText);
  535. if (json){
  536. errorText = json.message.trim() || "request json error";
  537. }else{
  538. errorText = "request json error: "+xhr.responseText;
  539. }
  540. }
  541. errorText = errorText.replace(/\</g, "&lt;");
  542. errorText = errorText.replace(/\</g, "&gt;");
  543. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  544. }.bind(this))
  545. }.bind(this));
  546. },
  547. save: function(callback){
  548. debugger;
  549. if (!this.data.name){
  550. this.designer.notice(this.designer.lp.inputStatementName, "error");
  551. return false;
  552. }
  553. //if( !this.data.tableType ){
  554. // this.data.tableType = "dynamic";
  555. //}
  556. if (this.editor) this.data.data = this.editor.editor.getValue();
  557. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  558. this.designer.actions.saveStatement(this.data, function(json){
  559. this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  560. this.data.id = json.data.id;
  561. if (this.lisNode) {
  562. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  563. }
  564. if (callback) callback();
  565. }.bind(this));
  566. },
  567. _setEditStyle: function(){},
  568. saveSilence: function(callback){
  569. if (!this.data.name){
  570. this.designer.notice(this.designer.lp.inputStatementName, "error");
  571. return false;
  572. }
  573. if (this.editor) this.data.data = this.editor.editor.getValue();
  574. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  575. this.designer.actions.saveStatement(this.data, function(json){
  576. //this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  577. this.data.id = json.data.id;
  578. if (this.lisNode) {
  579. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  580. }
  581. if (callback) callback();
  582. }.bind(this));
  583. },
  584. loadView : function( callback ){
  585. this.setViewSize();
  586. this.designer.addEvent("resize", this.setViewSize.bind(this));
  587. if( !this.data.view )this.data.view = {};
  588. this.view = new MWF.xApplication.query.StatementDesigner.View(this.designer, this, this.data.view, {});
  589. this.view.load( function () {
  590. this.view.setContentHeight();
  591. }.bind(this));
  592. },
  593. setViewSize: function(){
  594. debugger;
  595. var size = this.areaNode.getSize();
  596. var designerSize = this.designerArea.getComputedSize();
  597. var y = size.y-designerSize.totalHeight;
  598. var mTop = this.viewArea.getStyle("margin-top").toInt();
  599. var mBottom = this.viewArea.getStyle("margin-bottom").toInt();
  600. var pTop = this.viewArea.getStyle("padding-top").toInt();
  601. var pBottom = this.viewArea.getStyle("padding-bottom").toInt();
  602. y = y-mTop-mBottom-pTop-pBottom-1;
  603. var tabSize = this.tabNode.getComputedSize();
  604. y = y - tabSize.totalHeight;
  605. this.viewArea.setStyle("height", ""+y+"px");
  606. // var titleSize = this.runTitleNode.getComputedSize();
  607. // y = y - titleSize.totalHeight;
  608. // this.runContentNode.setStyle("height", ""+y+"px");
  609. }
  610. });
  611. MWF.xApplication.query.StatementDesigner.View = new Class({
  612. Extends: MWF.xApplication.query.ViewDesigner.View,
  613. Implements: [Options, Events],
  614. options: {
  615. "style": "default",
  616. "isView": false,
  617. "showTab": true,
  618. "propertyPath": "../x_component_query_StatementDesigner/$Statement/view.html"
  619. },
  620. initialize: function(designer, statement, data, options){
  621. this.setOptions(options);
  622. this.path = "../x_component_query_ViewDesigner/$View/";
  623. this.cssPath = "../x_component_query_ViewDesigner/$View/"+this.options.style+"/css.wcss";
  624. this._loadCss();
  625. this.statement = statement;
  626. this.designer = designer;
  627. this.data = data;
  628. // if (!this.data.data) this.data.data = {};
  629. this.parseData();
  630. this.node = this.statement.viewArea;
  631. //this.tab = this.designer.tab;
  632. this.areaNode = new Element("div", {"styles": {"height": "calc(100% - 2px)", "overflow": "auto" }});
  633. this.areaNode.setStyles(this.css.areaNode);
  634. //MWF.require("MWF.widget.ScrollBar", function(){
  635. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  636. //}.bind(this));
  637. // this.propertyListNode = this.designer.propertyDomArea;
  638. //this.propertyNode = this.designer.propertyContentArea;
  639. // if(this.designer.application) this.data.applicationName = this.designer.application.name;
  640. // if(this.designer.application) this.data.application = this.designer.application.id;
  641. // this.isNewView = (this.data.name) ? false : true;
  642. this.items = [];
  643. this.view = this;
  644. // this.autoSave();
  645. // this.designer.addEvent("queryClose", function(){
  646. // if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  647. // }.bind(this));
  648. },
  649. load : function( callback ){
  650. this.setAreaNodeSize();
  651. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  652. this.areaNode.inject(this.node);
  653. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  654. this.loadTemplateStyle( function () {
  655. this.loadActionbar();
  656. this.loadView();
  657. this.loadPaging();
  658. // this.selected();
  659. this.setEvent();
  660. //if (this.options.showTab) this.page.showTabIm();
  661. this.setViewWidth();
  662. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  663. if(callback)callback();
  664. }.bind(this))
  665. },
  666. parseData: function(){
  667. this.json = this.data;
  668. if( !this.json.id ){
  669. this.json.id = (new o2.widget.UUID).id;
  670. }
  671. if( !this.json.data || !this.json.data.events ){
  672. var url = "../x_component_query_StatementDesigner/$Statement/view.json";
  673. MWF.getJSON(url, {
  674. "onSuccess": function(obj){
  675. if(!this.json.data)this.json.data = obj.data;
  676. if(!this.json.data.events)this.json.data.events = obj.data.events;
  677. }.bind(this),
  678. "onerror": function(text){
  679. this.notice(text, "error");
  680. }.bind(this),
  681. "onRequestFailure": function(xhr){
  682. this.notice(xhr.responseText, "error");
  683. }.bind(this)
  684. },false);
  685. }
  686. },
  687. setEvent: function(){
  688. this.areaNode.addEvents({
  689. "click": function(e){ this.selected(); e.stopPropagation(); }.bind(this),
  690. "mouseover": function(){ if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode_over)}.bind(this),
  691. "mouseout": function(){if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode)}.bind(this)
  692. });
  693. this.refreshNode.addEvent("click", function(e){
  694. this.loadViewData();
  695. e.stopPropagation();
  696. }.bind(this));
  697. this.addColumnNode.addEvent("click", function(e){
  698. this.addColumn();
  699. e.stopPropagation();
  700. }.bind(this));
  701. },
  702. selected: function(){
  703. debugger;
  704. if (this.statement.currentSelectedModule){
  705. if (this.statement.currentSelectedModule==this){
  706. return true;
  707. }else{
  708. this.statement.currentSelectedModule.unSelected();
  709. }
  710. }
  711. this.areaNode.setStyles(this.css.areaNode_selected);
  712. this.statement.currentSelectedModule = this;
  713. this.domListNode.show();
  714. this.isSelected = true;
  715. this.showProperty();
  716. },
  717. unSelected: function(){
  718. this.statement.currentSelectedModule = null;
  719. this.isSelected = false;
  720. this.areaNode.setStyles(this.css.areaNode);
  721. this.hideProperty();
  722. },
  723. showProperty: function(){
  724. if (!this.property){
  725. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  726. "path": this.options.propertyPath,
  727. "onPostLoad": function(){
  728. this.property.show();
  729. }.bind(this)
  730. });
  731. this.property.load();
  732. }else{
  733. this.property.show();
  734. }
  735. },
  736. hideProperty: function(){
  737. if (this.property) this.property.hide();
  738. },
  739. loadViewData: function(){
  740. if (this.data.id){
  741. this.saveSilence(function(){
  742. this.viewContentBodyNode.empty();
  743. this.viewContentTableNode = new Element("table", {
  744. "styles": this.css.viewContentTableNode,
  745. "border": "0px",
  746. "cellPadding": "0",
  747. "cellSpacing": "0"
  748. }).inject(this.viewContentBodyNode);
  749. this.designer.actions.loadView(this.data.id, null,function(json){
  750. var entries = {};
  751. json.data.selectList.each(function(entry){entries[entry.column] = entry;}.bind(this));
  752. if (this.json.data.group.column){
  753. if (json.data.groupGrid.length){
  754. var groupColumn = null;
  755. for (var c = 0; c<json.data.selectList.length; c++){
  756. if (json.data.selectList[c].column === json.data.group.column){
  757. groupColumn = json.data.selectList[c];
  758. break;
  759. }
  760. }
  761. json.data.groupGrid.each(function(line, idx){
  762. var groupTr = new Element("tr", {
  763. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode,
  764. "data-is-group" : "yes"
  765. }).inject(this.viewContentTableNode);
  766. var colSpan = this.items.length ;
  767. var td = new Element("td", {
  768. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentGroupTd"] : this.css.viewContentGroupTdNode,
  769. "colSpan": colSpan
  770. }).inject(groupTr);
  771. var groupAreaNode;
  772. if( this.json.data.viewStyles ){
  773. groupAreaNode = new Element("div", {"styles": this.json.data.viewStyles["groupCollapseNode"]}).inject(td);
  774. groupAreaNode.set("text", line.group);
  775. }else{
  776. groupAreaNode = new Element("div", {"styles": this.css.viewContentTdGroupNode}).inject(td);
  777. var groupIconNode = new Element("div", {"styles": this.css.viewContentTdGroupIconNode}).inject(groupAreaNode);
  778. var groupTextNode = new Element("div", {"styles": this.css.viewContentTdGroupTextNode}).inject(groupAreaNode);
  779. if (groupColumn){
  780. //groupTextNode.set("text", (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": line.group, "gridData": json.data.groupGrid, "data": json.data, "entry": line}) : line.group);
  781. groupTextNode.set("text", line.group);
  782. }else{
  783. groupTextNode.set("text", line.group);
  784. }
  785. }
  786. var subtrs = [];
  787. line.list.each(function(entry){
  788. var tr = new Element("tr", {
  789. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
  790. }).inject(this.viewContentTableNode);
  791. tr.setStyle("display", "none");
  792. //this.createViewCheckboxTd( tr );
  793. var td = new Element("td", {
  794. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  795. }).inject(tr);
  796. Object.each(entries, function(c, k){
  797. var d = entry.data[k];
  798. if (d!=undefined){
  799. if (k!=this.json.data.group.column){
  800. var td = new Element("td", {
  801. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  802. }).inject(tr);
  803. //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
  804. if (c.isHtml){
  805. td.set("html", d);
  806. }else{
  807. td.set("text", d);
  808. }
  809. }
  810. }
  811. }.bind(this));
  812. // Object.each(entry.data, function(d, k){
  813. // if (k!=this.json.data.group.column){
  814. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  815. // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
  816. // }
  817. // }.bind(this));
  818. subtrs.push(tr)
  819. }.bind(this));
  820. groupAreaNode.store("subtrs", subtrs);
  821. var _self = this;
  822. groupAreaNode.addEvent("click", function(){
  823. var subtrs = this.retrieve("subtrs");
  824. var iconNode = groupAreaNode.getFirst("div");
  825. if (subtrs[0]){
  826. if (subtrs[0].getStyle("display")=="none"){
  827. subtrs.each(function(subtr){ subtr.setStyle("display", "table-row"); });
  828. if( iconNode ) {
  829. iconNode.setStyle("background", "url(" + "../x_component_process_StatementDesigner/$View/default/icon/down.png) center center no-repeat");
  830. }else{
  831. this.setStyles( _self.json.data.viewStyles["groupExpandNode"] )
  832. }
  833. }else{
  834. subtrs.each(function(subtr){ subtr.setStyle("display", "none"); });
  835. if( iconNode ) {
  836. iconNode.setStyle("background", "url(" + "../x_component_process_StatementDesigner/$View/default/icon/right.png) center center no-repeat");
  837. }else{
  838. this.setStyles( _self.json.data.viewStyles["groupCollapseNode"] )
  839. }
  840. }
  841. }
  842. _self.setContentHeight();
  843. });
  844. }.bind(this));
  845. this.setContentColumnWidth();
  846. this.setContentHeight();
  847. }else if(this.json.data.noDataText){
  848. var noDataTextNodeStyle = this.css.noDataTextNode;
  849. if( this.json.data.viewStyles ){
  850. if( this.json.data.viewStyles["noDataTextNode"] ){
  851. noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
  852. }else{
  853. this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
  854. }
  855. }
  856. this.noDataTextNode = new Element( "div", {
  857. "styles": noDataTextNodeStyle,
  858. "text" : this.json.data.noDataText
  859. }).inject( this.viewContentBodyNode );
  860. }
  861. }else{
  862. if (json.data.grid.length){
  863. json.data.grid.each(function(line, idx){
  864. var tr = new Element("tr", {
  865. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
  866. }).inject(this.viewContentTableNode);
  867. //this.createViewCheckboxTd( tr );
  868. Object.each(entries, function(c, k){
  869. var d = line.data[k];
  870. if (d!=undefined){
  871. var td = new Element("td", {
  872. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  873. }).inject(tr);
  874. //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  875. if (c.isHtml){
  876. td.set("html", d);
  877. }else{
  878. td.set("text", d);
  879. }
  880. //td.set("text", d);
  881. }
  882. }.bind(this));
  883. // Object.each(line.data, function(d, k){
  884. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  885. // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  886. // }.bind(this));
  887. }.bind(this));
  888. this.setContentColumnWidth();
  889. this.setContentHeight();
  890. }else if(this.json.data.noDataText){
  891. var noDataTextNodeStyle = this.css.noDataTextNode;
  892. if( this.json.data.viewStyles ){
  893. if( this.json.data.viewStyles["noDataTextNode"] ){
  894. noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
  895. }else{
  896. this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
  897. }
  898. }
  899. this.noDataTextNode = new Element( "div", {
  900. "styles": noDataTextNodeStyle,
  901. "text" : this.json.data.noDataText
  902. }).inject( this.viewContentBodyNode );
  903. }
  904. }
  905. }.bind(this));
  906. }.bind(this));
  907. }
  908. },
  909. addColumn: function(){
  910. debugger;
  911. MWF.require("MWF.widget.UUID", function(){
  912. var id = (new MWF.widget.UUID).id;
  913. var json = {
  914. "id": id,
  915. "column": id,
  916. "displayName": this.designer.lp.unnamed,
  917. "orderType": "original"
  918. };
  919. if (!this.json.data.selectList) this.json.data.selectList = [];
  920. this.json.data.selectList.push(json);
  921. var column = new MWF.xApplication.query.StatementDesigner.View.Column(json, this);
  922. this.items.push(column);
  923. column.selected();
  924. if (this.viewContentTableNode){
  925. var trs = this.viewContentTableNode.getElements("tr");
  926. trs.each(function(tr){
  927. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  928. }.bind(this));
  929. //this.setContentColumnWidth();
  930. }
  931. this.setViewWidth();
  932. this.addColumnNode.scrollIntoView(true);
  933. }.bind(this));
  934. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  935. },
  936. setContentHeight: function(){
  937. var size = this.areaNode.getSize();
  938. var titleSize = this.viewTitleNode.getSize();
  939. var actionbarSize = this.actionbarNode ? this.actionbarNode.getSize() : {x:0, y:0};
  940. var pagingSize = this.pagingNode ? this.pagingNode.getSize() : {x:0, y:0};
  941. var height = size.y-titleSize.y-actionbarSize.y-pagingSize.y-4;
  942. this.viewContentScrollNode.setStyle("height", height);
  943. var contentSize = this.viewContentBodyNode.getSize();
  944. if (height<contentSize.y) height = contentSize.y+10;
  945. this.viewContentNode.setStyle("height", height);
  946. this.contentLeftNode.setStyle("height", height);
  947. this.contentRightNode.setStyle("height", height);
  948. //this.viewContentBodyNode.setStyle("min-height", height);
  949. },
  950. loadViewColumns: function(){
  951. // for (var i=0; i<10; i++){
  952. if (this.json.data.selectList) {
  953. this.json.data.selectList.each(function (json) {
  954. this.items.push(new MWF.xApplication.query.StatementDesigner.View.Column(json, this));
  955. }.bind(this));
  956. }
  957. // }
  958. },
  959. showActionbar : function( noSetHeight ){
  960. this.actionbarNode.show();
  961. if( !this.json.data.actionbarList )this.json.data.actionbarList = [];
  962. if( !this.actionbarList || this.actionbarList.length == 0 ){
  963. if( this.json.data.actionbarList.length ){
  964. this.json.data.actionbarList.each( function(json){
  965. this.actionbarList.push( new MWF.xApplication.query.StatementDesigner.View.Actionbar( json, this.json.data.actionbarList, this) )
  966. }.bind(this));
  967. }else{
  968. this.actionbarList.push( new MWF.xApplication.query.StatementDesigner.View.Actionbar( null, this.json.data.actionbarList, this) )
  969. }
  970. }
  971. if( !noSetHeight )this.setContentHeight();
  972. },
  973. loadPaging: function( noSetHeight ){
  974. this.pagingNode = new Element("div#pagingNode", {"styles": this.css.pagingNode}).inject(this.areaNode);
  975. this.pagingList = [];
  976. if( !this.json.data.pagingList )this.json.data.pagingList = [];
  977. if( !this.pagingList || this.pagingList.length == 0 ){
  978. if( this.json.data.pagingList.length ){
  979. this.json.data.pagingList.each( function(json){
  980. this.pagingList.push( new MWF.xApplication.query.StatementDesigner.View.Paging( json, this.json.data.pagingList, this) )
  981. }.bind(this));
  982. }else{
  983. this.pagingList.push( new MWF.xApplication.query.StatementDesigner.View.Paging( null, this.json.data.pagingList, this) )
  984. }
  985. }
  986. // if( !noSetHeight )this.setContentHeight();
  987. },
  988. setViewWidth: function(){
  989. if( !this.viewAreaNode )return;
  990. this.viewAreaNode.setStyle("width", "auto");
  991. this.viewTitleNode.setStyle("width", "auto");
  992. var s1 = this.viewTitleTableNode.getSize();
  993. var s2 = this.refreshNode.getSize();
  994. var s3 = this.addColumnNode.getSize();
  995. var width = s1.x+s2.x+s2.x;
  996. var size = this.areaNode.getSize();
  997. if (width>size.x){
  998. this.viewTitleNode.setStyle("width", ""+(width-2)+"px");
  999. this.viewAreaNode.setStyle("width", ""+(width-2)+"px");
  1000. }else{
  1001. this.viewTitleNode.setStyle("width", ""+(size.x-2)+"px");
  1002. this.viewAreaNode.setStyle("width", ""+(size.x-2)+"px");
  1003. }
  1004. this.setContentColumnWidth();
  1005. this.setContentHeight();
  1006. },
  1007. _setEditStyle: function(name, input, oldValue){
  1008. if( name=="data.actionbarHidden" ){
  1009. if( this.json.data.actionbarHidden ){
  1010. this.hideActionbar()
  1011. }else{
  1012. this.showActionbar()
  1013. }
  1014. }
  1015. if( name=="data.selectAllEnable" ){
  1016. if( this.json.data.selectAllEnable ){
  1017. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display","table-cell");
  1018. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display","table-cell");
  1019. }else{
  1020. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display","none");
  1021. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display","none");
  1022. }
  1023. }
  1024. if (name=="data.viewStyleType"){
  1025. var file = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].file : null;
  1026. var extendFile = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].extendFile : null;
  1027. this.loadTemplateStyles( file, extendFile, function( templateStyles ){
  1028. this.templateStyles = templateStyles;
  1029. var oldFile, oldExtendFile;
  1030. if( oldValue && this.stylesList[oldValue] ){
  1031. oldFile = this.stylesList[oldValue].file;
  1032. oldExtendFile = this.stylesList[oldValue].extendFile;
  1033. }
  1034. this.loadTemplateStyles( oldFile, oldExtendFile, function( oldTemplateStyles ){
  1035. this.json.data.styleConfig = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType] : null;
  1036. if (oldTemplateStyles["view"]) this.clearTemplateStyles(oldTemplateStyles["view"]);
  1037. if (this.templateStyles["view"]) this.setTemplateStyles(this.templateStyles["view"]);
  1038. this.setAllStyles();
  1039. this.actionbarList.each( function (module) {
  1040. if (oldTemplateStyles["actionbar"]){
  1041. module.clearTemplateStyles(oldTemplateStyles["actionbar"]);
  1042. }
  1043. module.setStyleTemplate();
  1044. module.setAllStyles();
  1045. })
  1046. this.pagingList.each( function (module) {
  1047. if (oldTemplateStyles["paging"]){
  1048. module.clearTemplateStyles(oldTemplateStyles["paging"]);
  1049. }
  1050. module.setStyleTemplate();
  1051. module.setAllStyles();
  1052. });
  1053. // this.moduleList.each(function(module){
  1054. // if (oldTemplateStyles[module.moduleName]){
  1055. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  1056. // }
  1057. // module.setStyleTemplate();
  1058. // module.setAllStyles();
  1059. // }.bind(this));
  1060. }.bind(this))
  1061. }.bind(this))
  1062. }
  1063. if (name=="data.viewStyles"){
  1064. this.setCustomStyles();
  1065. }
  1066. },
  1067. loadTemplateStyle : function( callback ){
  1068. this.loadStylesList(function(){
  1069. var oldStyleValue = "";
  1070. if ((!this.json.data.viewStyleType) || !this.stylesList[this.json.data.viewStyleType]) this.json.data.viewStyleType="default";
  1071. this.loadTemplateStyles( this.stylesList[this.json.data.viewStyleType].file, this.stylesList[this.json.data.viewStyleType].extendFile,
  1072. function( templateStyles ){
  1073. this.templateStyles = templateStyles;
  1074. if( !this.json.data.viewStyleType )this.json.data.viewStyleType = "default";
  1075. if ( this.templateStyles && this.templateStyles["view"]){
  1076. var viewStyles = Object.clone(this.templateStyles["view"]);
  1077. if( viewStyles.contentGroupTd )delete viewStyles.contentGroupTd;
  1078. if( viewStyles.groupCollapseNode )delete viewStyles.groupCollapseNode;
  1079. if( viewStyles.groupExpandNode )delete viewStyles.groupExpandNode;
  1080. if(!this.json.data.viewStyles){
  1081. this.json.data.viewStyles = viewStyles;
  1082. }else{
  1083. this.setTemplateStyles( viewStyles );
  1084. }
  1085. }
  1086. this.setCustomStyles();
  1087. if(callback)callback();
  1088. }.bind(this)
  1089. );
  1090. }.bind(this));
  1091. },
  1092. clearTemplateStyles: function(styles){
  1093. if (styles){
  1094. if (styles.container) this.removeStyles(styles.container, "container");
  1095. if (styles.table) this.removeStyles(styles.table, "table");
  1096. if (styles.titleTr) this.removeStyles(styles.titleTr, "titleTr");
  1097. if (styles.titleTd) this.removeStyles(styles.titleTd, "titleTd");
  1098. if (styles.contentTr) this.removeStyles(styles.contentTr, "contentTr");
  1099. if (styles.contentSelectedTr) this.removeStyles(styles.contentSelectedTr, "contentSelectedTr");
  1100. if (styles.contentTd) this.removeStyles(styles.contentTd, "contentTd");
  1101. // if (styles.contentGroupTd) this.removeStyles(styles.contentGroupTd, "contentGroupTd");
  1102. // if (styles.groupCollapseNode) this.removeStyles(styles.groupCollapseNode, "groupCollapseNode");
  1103. // if (styles.groupExpandNode) this.removeStyles(styles.groupExpandNode, "groupExpandNode");
  1104. if (styles.checkboxNode) this.removeStyles(styles.checkboxNode, "checkboxNode");
  1105. if (styles.checkedCheckboxNode) this.removeStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1106. if (styles.radioNode) this.removeStyles(styles.radioNode, "radioNode");
  1107. if (styles.checkedRadioNode) this.removeStyles(styles.checkedRadioNode, "checkedRadioNode");
  1108. if (styles.tableProperties) this.removeStyles(styles.tableProperties, "tableProperties");
  1109. }
  1110. },
  1111. setTemplateStyles: function(styles){
  1112. if (styles.container) this.copyStyles(styles.container, "container");
  1113. if (styles.table) this.copyStyles(styles.table, "table");
  1114. if (styles.titleTr) this.copyStyles(styles.titleTr, "titleTr");
  1115. if (styles.titleTd) this.copyStyles(styles.titleTd, "titleTd");
  1116. if (styles.contentTr) this.copyStyles(styles.contentTr, "contentTr");
  1117. if (styles.contentSelectedTr) this.copyStyles(styles.contentSelectedTr, "contentSelectedTr");
  1118. if (styles.contentTd) this.copyStyles(styles.contentTd, "contentTd");
  1119. // if (styles.contentGroupTd) this.copyStyles(styles.contentGroupTd, "contentGroupTd");
  1120. // if (styles.groupCollapseNode) this.copyStyles(styles.groupCollapseNode, "groupCollapseNode");
  1121. // if (styles.groupExpandNode) this.copyStyles(styles.groupExpandNode, "groupExpandNode");
  1122. if (styles.checkboxNode) this.copyStyles(styles.checkboxNode, "checkboxNode");
  1123. if (styles.checkedCheckboxNode) this.copyStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1124. if (styles.radioNode) this.copyStyles(styles.radioNode, "radioNode");
  1125. if (styles.checkedRadioNode) this.copyStyles(styles.checkedRadioNode, "checkedRadioNode");
  1126. if (styles.tableProperties) this.copyStyles(styles.tableProperties, "tableProperties");
  1127. },
  1128. removeStyles: function(from, to){
  1129. if (this.json.data.viewStyles[to]){
  1130. Object.each(from, function(style, key){
  1131. if (this.json.data.viewStyles[to][key] && this.json.data.viewStyles[to][key]==style){
  1132. delete this.json.data.viewStyles[to][key];
  1133. }
  1134. }.bind(this));
  1135. }
  1136. },
  1137. copyStyles: function(from, to){
  1138. if (!this.json.data.viewStyles[to]) this.json.data.viewStyles[to] = {};
  1139. Object.each(from, function(style, key){
  1140. if (!this.json.data.viewStyles[to][key]) this.json.data.viewStyles[to][key] = style;
  1141. }.bind(this));
  1142. }
  1143. // preview: function(){
  1144. // if( this.isNewView ){
  1145. // this.designer.notice( this.designer.lp.saveViewNotice, "error" );
  1146. // return;
  1147. // }
  1148. // this.saveSilence( function () {
  1149. // var url = "../x_desktop/app.html?app=query.Query&status=";
  1150. // url += JSON.stringify({
  1151. // id : this.data.application,
  1152. // viewId : this.data.id
  1153. // });
  1154. // window.open(o2.filterUrl(url),"_blank");
  1155. // }.bind(this));
  1156. // },
  1157. // saveSilence: function(callback){
  1158. // if (!this.data.name){
  1159. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1160. // return false;
  1161. // }
  1162. //
  1163. // this.designer.actions.saveView(this.data, function(json){
  1164. // this.data.id = json.data.id;
  1165. // this.isNewView = false;
  1166. // //this.page.textNode.set("text", this.data.name);
  1167. // if (this.lisNode) {
  1168. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1169. // }
  1170. // if (callback) callback();
  1171. // }.bind(this));
  1172. // },
  1173. // save: function(callback){
  1174. // //if (this.designer.tab.showPage==this.page){
  1175. // if (!this.data.name){
  1176. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1177. // return false;
  1178. // }
  1179. // //}
  1180. // this.designer.actions.saveView(this.data, function(json){
  1181. // this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  1182. // this.isNewView = false;
  1183. // this.data.id = json.data.id;
  1184. // //this.page.textNode.set("text", this.data.name);
  1185. // if (this.lisNode) {
  1186. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1187. // }
  1188. // if (callback) callback();
  1189. // }.bind(this));
  1190. // },
  1191. // saveAs: function(){
  1192. // var form = new MWF.xApplication.query.StatementDesigner.View.NewNameForm(this, {
  1193. // name : this.data.name + "_" + MWF.xApplication.query.StatementDesigner.LP.copy,
  1194. // query : this.data.query || this.data.application,
  1195. // queryName : this.data.queryName || this.data.applicationName
  1196. // }, {
  1197. // onSave : function( data, callback ){
  1198. // this._saveAs( data, callback );
  1199. // }.bind(this)
  1200. // }, {
  1201. // app: this.designer
  1202. // });
  1203. // form.edit()
  1204. // },
  1205. // _saveAs : function( data , callback){
  1206. // var _self = this;
  1207. //
  1208. // var d = this.cloneObject( this.data );
  1209. //
  1210. // d.isNewView = true;
  1211. // d.id = this.designer.actions.getUUID();
  1212. // d.name = data.name;
  1213. // d.alias = "";
  1214. // d.query = data.query;
  1215. // d.queryName = data.queryName;
  1216. // d.application = data.query;
  1217. // d.applicationName = data.queryName;
  1218. // d.pid = d.id + d.id;
  1219. //
  1220. // delete d[this.data.id+"viewFilterType"];
  1221. // d[d.id+"viewFilterType"]="custom";
  1222. //
  1223. // d.data.selectList.each( function( entry ){
  1224. // entry.id = (new MWF.widget.UUID).id;
  1225. // }.bind(this));
  1226. //
  1227. // this.designer.actions.saveView(d, function(json){
  1228. // this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  1229. // if (callback) callback();
  1230. // }.bind(this));
  1231. // }
  1232. });
  1233. MWF.xApplication.query.StatementDesigner.View.Column = new Class({
  1234. Extends: MWF.xApplication.query.ViewDesigner.View.Column,
  1235. initialize: function(json, view, next){
  1236. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/column.html";
  1237. this.view = view;
  1238. this.json = json;
  1239. this.next = next;
  1240. this.css = this.view.css;
  1241. this.content = this.view.viewTitleTrNode;
  1242. this.domListNode = this.view.domListNode;
  1243. this.load();
  1244. },
  1245. selected: function(){
  1246. if (this.view.statement.currentSelectedModule){
  1247. if (this.view.statement.currentSelectedModule==this){
  1248. return true;
  1249. }else{
  1250. this.view.statement.currentSelectedModule.unSelected();
  1251. }
  1252. }
  1253. this.view.domListNode.show();
  1254. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  1255. this.listNode.setStyles(this.css.cloumnListNode_selected);
  1256. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1257. new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  1258. this.view.statement.currentSelectedModule = this;
  1259. this.isSelected = true;
  1260. this._showActions();
  1261. this.showProperty();
  1262. },
  1263. unSelected: function(){
  1264. this.view.statement.currentSelectedModule = null;
  1265. //this.node.setStyles(this.css.viewTitleColumnNode);
  1266. if (this.isError){
  1267. this.node.setStyles(this.css.viewTitleColumnNode_error)
  1268. }else{
  1269. this.node.setStyles(this.css.viewTitleColumnNode)
  1270. }
  1271. this.listNode.setStyles(this.css.cloumnListNode);
  1272. this.isSelected = false;
  1273. this._hideActions();
  1274. this.hideProperty();
  1275. }
  1276. });
  1277. MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({
  1278. Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar,
  1279. initialize: function(json, jsonList, view, options){
  1280. this.setOptions( options );
  1281. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/actionbar.html";
  1282. this.path = "../x_component_query_ViewDesigner/$View/";
  1283. this.imagePath_default = "../x_component_query_ViewDesigner/$View/";
  1284. this.imagePath_custom = "../x_component_process_FormDesigner/Module/Actionbar/";
  1285. this.cssPath = "../x_component_query_ViewDesigner/$View/"+this.options.style+"/actionbar.wcss";
  1286. this.view = view;
  1287. this.json = json;
  1288. this.jsonList = jsonList;
  1289. this.css = this.view.css;
  1290. this.container = this.view.actionbarNode;
  1291. this.moduleName = "actionbar";
  1292. this.load();
  1293. },
  1294. getJsonPath : function(){
  1295. return "../x_component_query_StatementDesigner/$Statement/toolbars.json";
  1296. },
  1297. selected: function(){
  1298. if (this.view.statement.currentSelectedModule){
  1299. if (this.view.statement.currentSelectedModule==this){
  1300. return true;
  1301. }else{
  1302. this.view.statement.currentSelectedModule.unSelected();
  1303. }
  1304. }
  1305. this.view.domListNode.show();
  1306. this.node.setStyles(this.css.toolbarWarpNode_selected);
  1307. //this.listNode.setStyles(this.css.cloumnListNode_selected);
  1308. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1309. //new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  1310. this.view.statement.currentSelectedModule = this;
  1311. this.isSelected = true;
  1312. //this._showActions();
  1313. this.showProperty();
  1314. },
  1315. unSelected: function(){
  1316. this.view.statement.currentSelectedModule = null;
  1317. this.node.setStyles(this.css.toolbarWarpNode);
  1318. //this.listNode.setStyles(this.css.cloumnListNode);
  1319. this.isSelected = false;
  1320. //this._hideActions();
  1321. this.hideProperty();
  1322. },
  1323. });
  1324. MWF.xApplication.query.StatementDesigner.View.Paging = new Class({
  1325. Extends: MWF.xApplication.query.ViewDesigner.View.Paging,
  1326. selected: function(){
  1327. if (this.view.statement.currentSelectedModule){
  1328. if (this.view.statement.currentSelectedModule==this){
  1329. return true;
  1330. }else{
  1331. this.view.statement.currentSelectedModule.unSelected();
  1332. }
  1333. }
  1334. this.view.domListNode.show();
  1335. this.node.setStyles(this.css.pagingWarpNode_selected);
  1336. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1337. this.view.statement.currentSelectedModule = this;
  1338. this.isSelected = true;
  1339. this.showProperty();
  1340. },
  1341. unSelected: function(){
  1342. this.view.statement.currentSelectedModule = null;
  1343. this.node.setStyles(this.css.pagingWarpNode);
  1344. this.isSelected = false;
  1345. this.hideProperty();
  1346. }
  1347. });