Statement.js 70 KB

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