Statement.js 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  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("{}");
  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. o2.require("o2.widget.JsonParse", function () {
  537. this.runResultNode.empty();
  538. var jsonResult = new o2.widget.JsonParse(json, this.runResultNode);
  539. jsonResult.load();
  540. }.bind(this));
  541. this.runMask.hide();
  542. }.bind(this), function () {
  543. if (this.runMask) this.runMask.hide();
  544. }.bind(this))
  545. // var json = this.jsonEditor.editor.getValue();
  546. // var o = JSON.parse(json);
  547. //
  548. // var mode = "data";
  549. // if( this.data.type === "select" ){
  550. // if( this.data.format === "script" ){
  551. // if( this.data.scriptText && this.data.countScriptText ){
  552. // mode = "all"
  553. // }else if( this.data.scriptText && !this.data.countScriptText ){
  554. // mode = "data"
  555. // }else if( !this.data.scriptText && this.data.countScriptText ){
  556. // mode = "count"
  557. // }else{
  558. // this.designer.notice(this.designer.lp.inputStatementData, "error");
  559. // return false;
  560. // }
  561. // }else{
  562. // if( this.data.data && this.data.countData ){
  563. // mode = "all"
  564. // }else if( this.data.data && !this.data.countData ){
  565. // mode = "data"
  566. // }else if( !this.data.data && this.data.countData ){
  567. // mode = "count"
  568. // }else{
  569. // this.designer.notice(this.designer.lp.inputStatementData, "error");
  570. // return false;
  571. // }
  572. // }
  573. // }
  574. // o2.Actions.load("x_query_assemble_designer").StatementAction.executeV2(this.json.id, mode, 1, 50 , o, function(json){
  575. // o2.require("o2.widget.JsonParse", function(){
  576. // this.runResultNode.empty();
  577. // var jsonResult = new o2.widget.JsonParse(json, this.runResultNode);
  578. // jsonResult.load();
  579. // }.bind(this));
  580. // this.runMask.hide();
  581. // }.bind(this), function(xhr, text, error){
  582. // debugger;
  583. // if (this.runMask) this.runMask.hide();
  584. // var errorText = error;
  585. // if (xhr){
  586. // var json = JSON.decode(xhr.responseText);
  587. // if (json){
  588. // errorText = json.message.trim() || "request json error";
  589. // }else{
  590. // errorText = "request json error: "+xhr.responseText;
  591. // }
  592. // }
  593. // errorText = errorText.replace(/\</g, "&lt;");
  594. // errorText = errorText.replace(/\</g, "&gt;");
  595. // MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  596. // }.bind(this))
  597. }.bind(this));
  598. },
  599. execute: function (success, failure) {
  600. var json = this.jsonEditor.editor.getValue();
  601. var o = JSON.parse(json);
  602. var mode = "data";
  603. if (this.data.type === "select") {
  604. if (this.data.format === "script") {
  605. if (this.data.scriptText && this.data.countScriptText) {
  606. mode = "all"
  607. } else if (this.data.scriptText && !this.data.countScriptText) {
  608. mode = "data"
  609. } else if (!this.data.scriptText && this.data.countScriptText) {
  610. mode = "count"
  611. } else {
  612. this.designer.notice(this.designer.lp.inputStatementData, "error");
  613. return false;
  614. }
  615. } else {
  616. if (this.data.data && this.data.countData) {
  617. mode = "all"
  618. } else if (this.data.data && !this.data.countData) {
  619. mode = "data"
  620. } else if (!this.data.data && this.data.countData) {
  621. mode = "count"
  622. } else {
  623. this.designer.notice(this.designer.lp.inputStatementData, "error");
  624. return false;
  625. }
  626. }
  627. }
  628. o2.Actions.load("x_query_assemble_designer").StatementAction.executeV2(this.json.id, mode, 1, 50, o, function (json) {
  629. if (success) success(json)
  630. }.bind(this), function (xhr, text, error) {
  631. debugger;
  632. if (failure) failure();
  633. var errorText = error;
  634. if (xhr) {
  635. var json = JSON.decode(xhr.responseText);
  636. if (json) {
  637. errorText = json.message.trim() || "request json error";
  638. } else {
  639. errorText = "request json error: " + xhr.responseText;
  640. }
  641. }
  642. errorText = errorText.replace(/\</g, "&lt;");
  643. errorText = errorText.replace(/\</g, "&gt;");
  644. MWF.xDesktop.notice("error", {x: "right", y: "top"}, errorText);
  645. }.bind(this))
  646. },
  647. save: function (callback) {
  648. debugger;
  649. if (!this.data.name) {
  650. this.designer.notice(this.designer.lp.inputStatementName, "error");
  651. return false;
  652. }
  653. if (typeOf(this.viewJson) === "object") {
  654. this.data.view = JSON.stringify(this.viewJson);
  655. }
  656. //if( !this.data.tableType ){
  657. // this.data.tableType = "dynamic";
  658. //}
  659. if (this.editor) this.data.data = this.editor.editor.getValue();
  660. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  661. this.designer.actions.saveStatement(this.data, function (json) {
  662. this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  663. this.data.id = json.data.id;
  664. if (this.lisNode) {
  665. this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
  666. }
  667. if (callback) callback();
  668. }.bind(this));
  669. },
  670. _setEditStyle: function () {
  671. },
  672. saveSilence: function (callback) {
  673. if (!this.data.name) {
  674. this.designer.notice(this.designer.lp.inputStatementName, "error");
  675. return false;
  676. }
  677. if (typeOf(this.viewJson) === "object") {
  678. this.data.view = JSON.stringify(this.viewJson);
  679. }
  680. if (this.editor) this.data.data = this.editor.editor.getValue();
  681. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  682. this.designer.actions.saveStatement(this.data, function (json) {
  683. //this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  684. this.data.id = json.data.id;
  685. if (this.lisNode) {
  686. this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
  687. }
  688. if (callback) callback();
  689. }.bind(this));
  690. },
  691. loadView: function (callback) {
  692. this.setViewSize();
  693. this.designer.addEvent("resize", this.setViewSize.bind(this));
  694. if (!this.data.view) {
  695. this.viewJson = {};
  696. } else {
  697. this.viewJson = JSON.parse(this.data.view)
  698. }
  699. this.view = new MWF.xApplication.query.StatementDesigner.View(this.designer, this, this.viewJson, {});
  700. this.view.load(function () {
  701. this.view.setContentHeight();
  702. }.bind(this));
  703. },
  704. setViewSize: function () {
  705. debugger;
  706. var size = this.areaNode.getSize();
  707. var designerSize = this.designerArea.getComputedSize();
  708. var y = size.y - designerSize.totalHeight;
  709. var mTop = this.viewArea.getStyle("margin-top").toInt();
  710. var mBottom = this.viewArea.getStyle("margin-bottom").toInt();
  711. var pTop = this.viewArea.getStyle("padding-top").toInt();
  712. var pBottom = this.viewArea.getStyle("padding-bottom").toInt();
  713. y = y - mTop - mBottom - pTop - pBottom - 1;
  714. var tabSize = this.tabNode.getComputedSize();
  715. y = y - tabSize.totalHeight;
  716. this.viewArea.setStyle("height", "" + y + "px");
  717. // var titleSize = this.runTitleNode.getComputedSize();
  718. // y = y - titleSize.totalHeight;
  719. // this.runContentNode.setStyle("height", ""+y+"px");
  720. },
  721. preview: function () {
  722. if (this.isNewStatement) {
  723. this.designer.notice(this.designer.lp.saveStatementNotice, "error");
  724. return;
  725. }
  726. if (this.data.type !== "select") {
  727. this.designer.notice(this.designer.lp.previewNotSelectStatementNotice, "error");
  728. return;
  729. }
  730. if (!this.data.view) {
  731. this.designer.notice(this.designer.lp.noViewNotice, "error");
  732. }
  733. this.saveSilence(function () {
  734. var url = "../x_desktop/app.html?app=query.Query&status=";
  735. url += JSON.stringify({
  736. id: this.data.application,
  737. statementId: this.data.id
  738. });
  739. window.open(o2.filterUrl(url), "_blank");
  740. }.bind(this));
  741. }
  742. });
  743. MWF.xApplication.query.StatementDesigner.View = new Class({
  744. Extends: MWF.xApplication.query.ViewDesigner.View,
  745. Implements: [Options, Events],
  746. options: {
  747. "style": "default",
  748. "isView": false,
  749. "showTab": true,
  750. "propertyPath": "../x_component_query_StatementDesigner/$Statement/view.html"
  751. },
  752. initialize: function (designer, statement, data, options) {
  753. this.setOptions(options);
  754. this.path = "../x_component_query_ViewDesigner/$View/";
  755. this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/css.wcss";
  756. this._loadCss();
  757. this.statement = statement;
  758. this.designer = designer;
  759. this.data = data;
  760. // if (!this.data.data) this.data.data = {};
  761. this.parseData();
  762. this.node = this.statement.viewArea;
  763. //this.tab = this.designer.tab;
  764. this.areaNode = new Element("div", {"styles": {"height": "calc(100% - 2px)", "overflow": "auto"}});
  765. this.areaNode.setStyles(this.css.areaNode);
  766. //MWF.require("MWF.widget.ScrollBar", function(){
  767. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  768. //}.bind(this));
  769. // this.propertyListNode = this.designer.propertyDomArea;
  770. //this.propertyNode = this.designer.propertyContentArea;
  771. // if(this.designer.application) this.data.applicationName = this.designer.application.name;
  772. // if(this.designer.application) this.data.application = this.designer.application.id;
  773. // this.isNewView = (this.data.name) ? false : true;
  774. this.items = [];
  775. this.view = this;
  776. // this.autoSave();
  777. // this.designer.addEvent("queryClose", function(){
  778. // if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  779. // }.bind(this));
  780. },
  781. load: function (callback) {
  782. this.setAreaNodeSize();
  783. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  784. this.areaNode.inject(this.node);
  785. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  786. this.loadTemplateStyle(function () {
  787. this.loadActionbar();
  788. this.loadView();
  789. this.loadPaging();
  790. // this.selected();
  791. this.setEvent();
  792. //if (this.options.showTab) this.page.showTabIm();
  793. this.setViewWidth();
  794. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  795. if (callback) callback();
  796. }.bind(this))
  797. },
  798. parseData: function () {
  799. this.json = this.data;
  800. if (!this.json.id) {
  801. this.json.id = (new o2.widget.UUID).id;
  802. }
  803. if (!this.json.data || !this.json.data.events) {
  804. var url = "../x_component_query_StatementDesigner/$Statement/view.json";
  805. MWF.getJSON(url, {
  806. "onSuccess": function (obj) {
  807. if (!this.json.data) this.json.data = obj.data;
  808. if (!this.json.data.events) this.json.data.events = obj.data.events;
  809. }.bind(this),
  810. "onerror": function (text) {
  811. this.notice(text, "error");
  812. }.bind(this),
  813. "onRequestFailure": function (xhr) {
  814. this.notice(xhr.responseText, "error");
  815. }.bind(this)
  816. }, false);
  817. }
  818. },
  819. setEvent: function () {
  820. this.areaNode.addEvents({
  821. "click": function (e) {
  822. this.selected();
  823. e.stopPropagation();
  824. }.bind(this),
  825. "mouseover": function () {
  826. if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode_over)
  827. }.bind(this),
  828. "mouseout": function () {
  829. if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode)
  830. }.bind(this)
  831. });
  832. this.refreshNode.addEvent("click", function (e) {
  833. this.loadViewData();
  834. e.stopPropagation();
  835. }.bind(this));
  836. this.addColumnNode.addEvent("click", function (e) {
  837. this.addColumn();
  838. e.stopPropagation();
  839. }.bind(this));
  840. },
  841. selected: function () {
  842. debugger;
  843. if (this.statement.currentSelectedModule) {
  844. if (this.statement.currentSelectedModule == this) {
  845. return true;
  846. } else {
  847. this.statement.currentSelectedModule.unSelected();
  848. }
  849. }
  850. this.areaNode.setStyles(this.css.areaNode_selected);
  851. this.statement.currentSelectedModule = this;
  852. this.domListNode.show();
  853. this.isSelected = true;
  854. this.showProperty();
  855. },
  856. unSelected: function () {
  857. this.statement.currentSelectedModule = null;
  858. this.isSelected = false;
  859. this.areaNode.setStyles(this.css.areaNode);
  860. this.hideProperty();
  861. },
  862. showProperty: function () {
  863. if (!this.property) {
  864. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  865. "path": this.options.propertyPath,
  866. "onPostLoad": function () {
  867. this.property.show();
  868. }.bind(this)
  869. });
  870. this.property.load();
  871. } else {
  872. this.property.show();
  873. }
  874. },
  875. hideProperty: function () {
  876. if (this.property) this.property.hide();
  877. },
  878. loadViewData: function () {
  879. if (this.data.id) {
  880. this.statement.saveSilence(function () {
  881. this.viewContentBodyNode.empty();
  882. this.viewContentTableNode = new Element("table", {
  883. "styles": this.css.viewContentTableNode,
  884. "border": "0px",
  885. "cellPadding": "0",
  886. "cellSpacing": "0"
  887. }).inject(this.viewContentBodyNode);
  888. this.statement.execute( function (json) {
  889. var entries = {};
  890. json.data.selectList.each(function (entry) {
  891. entries[entry.column] = entry;
  892. }.bind(this));
  893. if (json.data.grid.length) {
  894. json.data.grid.each(function (line, idx) {
  895. var tr = new Element("tr", {
  896. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
  897. }).inject(this.viewContentTableNode);
  898. //this.createViewCheckboxTd( tr );
  899. Object.each(entries, function (c, k) {
  900. var d = line.data[k];
  901. if (d != undefined) {
  902. var td = new Element("td", {
  903. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  904. }).inject(tr);
  905. //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  906. if (c.isHtml) {
  907. td.set("html", d);
  908. } else {
  909. td.set("text", d);
  910. }
  911. //td.set("text", d);
  912. }
  913. }.bind(this));
  914. // Object.each(line.data, function(d, k){
  915. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  916. // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  917. // }.bind(this));
  918. }.bind(this));
  919. this.setContentColumnWidth();
  920. this.setContentHeight();
  921. } else if (this.json.data.noDataText) {
  922. var noDataTextNodeStyle = this.css.noDataTextNode;
  923. if (this.json.data.viewStyles) {
  924. if (this.json.data.viewStyles["noDataTextNode"]) {
  925. noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
  926. } else {
  927. this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
  928. }
  929. }
  930. this.noDataTextNode = new Element("div", {
  931. "styles": noDataTextNodeStyle,
  932. "text": this.json.data.noDataText
  933. }).inject(this.viewContentBodyNode);
  934. }
  935. }.bind(this));
  936. }.bind(this));
  937. }
  938. },
  939. addColumn: function () {
  940. debugger;
  941. MWF.require("MWF.widget.UUID", function () {
  942. var id = (new MWF.widget.UUID).id;
  943. var json = {
  944. "id": id,
  945. "column": id,
  946. "displayName": this.designer.lp.unnamed,
  947. "orderType": "original"
  948. };
  949. if (!this.json.data.selectList) this.json.data.selectList = [];
  950. this.json.data.selectList.push(json);
  951. var column = new MWF.xApplication.query.StatementDesigner.View.Column(json, this);
  952. this.items.push(column);
  953. column.selected();
  954. if (this.viewContentTableNode) {
  955. var trs = this.viewContentTableNode.getElements("tr");
  956. trs.each(function (tr) {
  957. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  958. }.bind(this));
  959. //this.setContentColumnWidth();
  960. }
  961. this.setViewWidth();
  962. this.addColumnNode.scrollIntoView(true);
  963. }.bind(this));
  964. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  965. },
  966. setContentHeight: function () {
  967. var size = this.areaNode.getSize();
  968. var titleSize = this.viewTitleNode.getSize();
  969. var actionbarSize = this.actionbarNode ? this.actionbarNode.getSize() : {x: 0, y: 0};
  970. var pagingSize = this.pagingNode ? this.pagingNode.getSize() : {x: 0, y: 0};
  971. var height = size.y - titleSize.y - actionbarSize.y - pagingSize.y - 4;
  972. this.viewContentScrollNode.setStyle("height", height);
  973. var contentSize = this.viewContentBodyNode.getSize();
  974. if (height < contentSize.y) height = contentSize.y + 10;
  975. this.viewContentNode.setStyle("height", height);
  976. this.contentLeftNode.setStyle("height", height);
  977. this.contentRightNode.setStyle("height", height);
  978. //this.viewContentBodyNode.setStyle("min-height", height);
  979. },
  980. loadViewColumns: function () {
  981. // for (var i=0; i<10; i++){
  982. if (this.json.data.selectList) {
  983. this.json.data.selectList.each(function (json) {
  984. this.items.push(new MWF.xApplication.query.StatementDesigner.View.Column(json, this));
  985. }.bind(this));
  986. }
  987. // }
  988. },
  989. showActionbar: function (noSetHeight) {
  990. this.actionbarNode.show();
  991. if (!this.json.data.actionbarList) this.json.data.actionbarList = [];
  992. if (!this.actionbarList || this.actionbarList.length == 0) {
  993. if (this.json.data.actionbarList.length) {
  994. this.json.data.actionbarList.each(function (json) {
  995. this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(json, this.json.data.actionbarList, this))
  996. }.bind(this));
  997. } else {
  998. this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(null, this.json.data.actionbarList, this))
  999. }
  1000. }
  1001. if (!noSetHeight) this.setContentHeight();
  1002. },
  1003. loadPaging: function (noSetHeight) {
  1004. this.pagingNode = new Element("div#pagingNode", {"styles": this.css.pagingNode}).inject(this.areaNode);
  1005. this.pagingList = [];
  1006. if (!this.json.data.pagingList) this.json.data.pagingList = [];
  1007. if (!this.pagingList || this.pagingList.length == 0) {
  1008. if (this.json.data.pagingList.length) {
  1009. this.json.data.pagingList.each(function (json) {
  1010. this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(json, this.json.data.pagingList, this))
  1011. }.bind(this));
  1012. } else {
  1013. this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(null, this.json.data.pagingList, this))
  1014. }
  1015. }
  1016. // if( !noSetHeight )this.setContentHeight();
  1017. },
  1018. setViewWidth: function () {
  1019. if (!this.viewAreaNode) return;
  1020. this.viewAreaNode.setStyle("width", "auto");
  1021. this.viewTitleNode.setStyle("width", "auto");
  1022. var s1 = this.viewTitleTableNode.getSize();
  1023. var s2 = this.refreshNode.getSize();
  1024. var s3 = this.addColumnNode.getSize();
  1025. var width = s1.x + s2.x + s2.x;
  1026. var size = this.areaNode.getSize();
  1027. if (width > size.x) {
  1028. this.viewTitleNode.setStyle("width", "" + (width - 2) + "px");
  1029. this.viewAreaNode.setStyle("width", "" + (width - 2) + "px");
  1030. } else {
  1031. this.viewTitleNode.setStyle("width", "" + (size.x - 2) + "px");
  1032. this.viewAreaNode.setStyle("width", "" + (size.x - 2) + "px");
  1033. }
  1034. this.setContentColumnWidth();
  1035. this.setContentHeight();
  1036. },
  1037. _setEditStyle: function (name, input, oldValue) {
  1038. if (name == "data.actionbarHidden") {
  1039. if (this.json.data.actionbarHidden) {
  1040. this.hideActionbar()
  1041. } else {
  1042. this.showActionbar()
  1043. }
  1044. }
  1045. if (name == "data.selectAllEnable") {
  1046. if (this.json.data.selectAllEnable) {
  1047. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display", "table-cell");
  1048. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display", "table-cell");
  1049. } else {
  1050. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display", "none");
  1051. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display", "none");
  1052. }
  1053. }
  1054. if (name == "data.viewStyleType") {
  1055. var file = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].file : null;
  1056. var extendFile = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].extendFile : null;
  1057. this.loadTemplateStyles(file, extendFile, function (templateStyles) {
  1058. this.templateStyles = templateStyles;
  1059. var oldFile, oldExtendFile;
  1060. if (oldValue && this.stylesList[oldValue]) {
  1061. oldFile = this.stylesList[oldValue].file;
  1062. oldExtendFile = this.stylesList[oldValue].extendFile;
  1063. }
  1064. this.loadTemplateStyles(oldFile, oldExtendFile, function (oldTemplateStyles) {
  1065. this.json.data.styleConfig = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType] : null;
  1066. if (oldTemplateStyles["view"]) this.clearTemplateStyles(oldTemplateStyles["view"]);
  1067. if (this.templateStyles["view"]) this.setTemplateStyles(this.templateStyles["view"]);
  1068. this.setAllStyles();
  1069. this.actionbarList.each(function (module) {
  1070. if (oldTemplateStyles["actionbar"]) {
  1071. module.clearTemplateStyles(oldTemplateStyles["actionbar"]);
  1072. }
  1073. module.setStyleTemplate();
  1074. module.setAllStyles();
  1075. })
  1076. this.pagingList.each(function (module) {
  1077. if (oldTemplateStyles["paging"]) {
  1078. module.clearTemplateStyles(oldTemplateStyles["paging"]);
  1079. }
  1080. module.setStyleTemplate();
  1081. module.setAllStyles();
  1082. });
  1083. // this.moduleList.each(function(module){
  1084. // if (oldTemplateStyles[module.moduleName]){
  1085. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  1086. // }
  1087. // module.setStyleTemplate();
  1088. // module.setAllStyles();
  1089. // }.bind(this));
  1090. }.bind(this))
  1091. }.bind(this))
  1092. }
  1093. if (name == "data.viewStyles") {
  1094. this.setCustomStyles();
  1095. }
  1096. },
  1097. loadTemplateStyle: function (callback) {
  1098. this.loadStylesList(function () {
  1099. var oldStyleValue = "";
  1100. if ((!this.json.data.viewStyleType) || !this.stylesList[this.json.data.viewStyleType]) this.json.data.viewStyleType = "default";
  1101. this.loadTemplateStyles(this.stylesList[this.json.data.viewStyleType].file, this.stylesList[this.json.data.viewStyleType].extendFile,
  1102. function (templateStyles) {
  1103. this.templateStyles = templateStyles;
  1104. if (!this.json.data.viewStyleType) this.json.data.viewStyleType = "default";
  1105. if (this.templateStyles && this.templateStyles["view"]) {
  1106. var viewStyles = Object.clone(this.templateStyles["view"]);
  1107. if (viewStyles.contentGroupTd) delete viewStyles.contentGroupTd;
  1108. if (viewStyles.groupCollapseNode) delete viewStyles.groupCollapseNode;
  1109. if (viewStyles.groupExpandNode) delete viewStyles.groupExpandNode;
  1110. if (!this.json.data.viewStyles) {
  1111. this.json.data.viewStyles = viewStyles;
  1112. } else {
  1113. this.setTemplateStyles(viewStyles);
  1114. }
  1115. }
  1116. this.setCustomStyles();
  1117. if (callback) callback();
  1118. }.bind(this)
  1119. );
  1120. }.bind(this));
  1121. },
  1122. clearTemplateStyles: function (styles) {
  1123. if (styles) {
  1124. if (styles.container) this.removeStyles(styles.container, "container");
  1125. if (styles.table) this.removeStyles(styles.table, "table");
  1126. if (styles.titleTr) this.removeStyles(styles.titleTr, "titleTr");
  1127. if (styles.titleTd) this.removeStyles(styles.titleTd, "titleTd");
  1128. if (styles.contentTr) this.removeStyles(styles.contentTr, "contentTr");
  1129. if (styles.contentSelectedTr) this.removeStyles(styles.contentSelectedTr, "contentSelectedTr");
  1130. if (styles.contentTd) this.removeStyles(styles.contentTd, "contentTd");
  1131. // if (styles.contentGroupTd) this.removeStyles(styles.contentGroupTd, "contentGroupTd");
  1132. // if (styles.groupCollapseNode) this.removeStyles(styles.groupCollapseNode, "groupCollapseNode");
  1133. // if (styles.groupExpandNode) this.removeStyles(styles.groupExpandNode, "groupExpandNode");
  1134. if (styles.checkboxNode) this.removeStyles(styles.checkboxNode, "checkboxNode");
  1135. if (styles.checkedCheckboxNode) this.removeStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1136. if (styles.radioNode) this.removeStyles(styles.radioNode, "radioNode");
  1137. if (styles.checkedRadioNode) this.removeStyles(styles.checkedRadioNode, "checkedRadioNode");
  1138. if (styles.tableProperties) this.removeStyles(styles.tableProperties, "tableProperties");
  1139. }
  1140. },
  1141. setTemplateStyles: function (styles) {
  1142. if (styles.container) this.copyStyles(styles.container, "container");
  1143. if (styles.table) this.copyStyles(styles.table, "table");
  1144. if (styles.titleTr) this.copyStyles(styles.titleTr, "titleTr");
  1145. if (styles.titleTd) this.copyStyles(styles.titleTd, "titleTd");
  1146. if (styles.contentTr) this.copyStyles(styles.contentTr, "contentTr");
  1147. if (styles.contentSelectedTr) this.copyStyles(styles.contentSelectedTr, "contentSelectedTr");
  1148. if (styles.contentTd) this.copyStyles(styles.contentTd, "contentTd");
  1149. // if (styles.contentGroupTd) this.copyStyles(styles.contentGroupTd, "contentGroupTd");
  1150. // if (styles.groupCollapseNode) this.copyStyles(styles.groupCollapseNode, "groupCollapseNode");
  1151. // if (styles.groupExpandNode) this.copyStyles(styles.groupExpandNode, "groupExpandNode");
  1152. if (styles.checkboxNode) this.copyStyles(styles.checkboxNode, "checkboxNode");
  1153. if (styles.checkedCheckboxNode) this.copyStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1154. if (styles.radioNode) this.copyStyles(styles.radioNode, "radioNode");
  1155. if (styles.checkedRadioNode) this.copyStyles(styles.checkedRadioNode, "checkedRadioNode");
  1156. if (styles.tableProperties) this.copyStyles(styles.tableProperties, "tableProperties");
  1157. },
  1158. removeStyles: function (from, to) {
  1159. if (this.json.data.viewStyles[to]) {
  1160. Object.each(from, function (style, key) {
  1161. if (this.json.data.viewStyles[to][key] && this.json.data.viewStyles[to][key] == style) {
  1162. delete this.json.data.viewStyles[to][key];
  1163. }
  1164. }.bind(this));
  1165. }
  1166. },
  1167. copyStyles: function (from, to) {
  1168. if (!this.json.data.viewStyles[to]) this.json.data.viewStyles[to] = {};
  1169. Object.each(from, function (style, key) {
  1170. if (!this.json.data.viewStyles[to][key]) this.json.data.viewStyles[to][key] = style;
  1171. }.bind(this));
  1172. }
  1173. // preview: function(){
  1174. // if( this.isNewView ){
  1175. // this.designer.notice( this.designer.lp.saveViewNotice, "error" );
  1176. // return;
  1177. // }
  1178. // this.saveSilence( function () {
  1179. // var url = "../x_desktop/app.html?app=query.Query&status=";
  1180. // url += JSON.stringify({
  1181. // id : this.data.application,
  1182. // viewId : this.data.id
  1183. // });
  1184. // window.open(o2.filterUrl(url),"_blank");
  1185. // }.bind(this));
  1186. // },
  1187. // saveSilence: function(callback){
  1188. // if (!this.data.name){
  1189. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1190. // return false;
  1191. // }
  1192. //
  1193. // this.designer.actions.saveView(this.data, function(json){
  1194. // this.data.id = json.data.id;
  1195. // this.isNewView = false;
  1196. // //this.page.textNode.set("text", this.data.name);
  1197. // if (this.lisNode) {
  1198. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1199. // }
  1200. // if (callback) callback();
  1201. // }.bind(this));
  1202. // },
  1203. // save: function(callback){
  1204. // //if (this.designer.tab.showPage==this.page){
  1205. // if (!this.data.name){
  1206. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1207. // return false;
  1208. // }
  1209. // //}
  1210. // this.designer.actions.saveView(this.data, function(json){
  1211. // this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  1212. // this.isNewView = false;
  1213. // this.data.id = json.data.id;
  1214. // //this.page.textNode.set("text", this.data.name);
  1215. // if (this.lisNode) {
  1216. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1217. // }
  1218. // if (callback) callback();
  1219. // }.bind(this));
  1220. // },
  1221. // saveAs: function(){
  1222. // var form = new MWF.xApplication.query.StatementDesigner.View.NewNameForm(this, {
  1223. // name : this.data.name + "_" + MWF.xApplication.query.StatementDesigner.LP.copy,
  1224. // query : this.data.query || this.data.application,
  1225. // queryName : this.data.queryName || this.data.applicationName
  1226. // }, {
  1227. // onSave : function( data, callback ){
  1228. // this._saveAs( data, callback );
  1229. // }.bind(this)
  1230. // }, {
  1231. // app: this.designer
  1232. // });
  1233. // form.edit()
  1234. // },
  1235. // _saveAs : function( data , callback){
  1236. // var _self = this;
  1237. //
  1238. // var d = this.cloneObject( this.data );
  1239. //
  1240. // d.isNewView = true;
  1241. // d.id = this.designer.actions.getUUID();
  1242. // d.name = data.name;
  1243. // d.alias = "";
  1244. // d.query = data.query;
  1245. // d.queryName = data.queryName;
  1246. // d.application = data.query;
  1247. // d.applicationName = data.queryName;
  1248. // d.pid = d.id + d.id;
  1249. //
  1250. // delete d[this.data.id+"viewFilterType"];
  1251. // d[d.id+"viewFilterType"]="custom";
  1252. //
  1253. // d.data.selectList.each( function( entry ){
  1254. // entry.id = (new MWF.widget.UUID).id;
  1255. // }.bind(this));
  1256. //
  1257. // this.designer.actions.saveView(d, function(json){
  1258. // this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  1259. // if (callback) callback();
  1260. // }.bind(this));
  1261. // }
  1262. });
  1263. MWF.xApplication.query.StatementDesigner.View.Column = new Class({
  1264. Extends: MWF.xApplication.query.ViewDesigner.View.Column,
  1265. initialize: function (json, view, next) {
  1266. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/column.html";
  1267. this.view = view;
  1268. this.json = json;
  1269. this.next = next;
  1270. this.css = this.view.css;
  1271. this.content = this.view.viewTitleTrNode;
  1272. this.domListNode = this.view.domListNode;
  1273. this.load();
  1274. },
  1275. selected: function () {
  1276. if (this.view.statement.currentSelectedModule) {
  1277. if (this.view.statement.currentSelectedModule == this) {
  1278. return true;
  1279. } else {
  1280. this.view.statement.currentSelectedModule.unSelected();
  1281. }
  1282. }
  1283. this.view.domListNode.show();
  1284. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  1285. this.listNode.setStyles(this.css.cloumnListNode_selected);
  1286. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1287. new Fx.Scroll(this.view.designer.propertyDomArea, {
  1288. "wheelStops": false,
  1289. "duration": 100
  1290. }).toElement(this.listNode);
  1291. this.view.statement.currentSelectedModule = this;
  1292. this.isSelected = true;
  1293. this._showActions();
  1294. this.showProperty();
  1295. },
  1296. unSelected: function () {
  1297. this.view.statement.currentSelectedModule = null;
  1298. //this.node.setStyles(this.css.viewTitleColumnNode);
  1299. if (this.isError) {
  1300. this.node.setStyles(this.css.viewTitleColumnNode_error)
  1301. } else {
  1302. this.node.setStyles(this.css.viewTitleColumnNode)
  1303. }
  1304. this.listNode.setStyles(this.css.cloumnListNode);
  1305. this.isSelected = false;
  1306. this._hideActions();
  1307. this.hideProperty();
  1308. }
  1309. });
  1310. MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({
  1311. Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar,
  1312. initialize: function (json, jsonList, view, options) {
  1313. this.setOptions(options);
  1314. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/actionbar.html";
  1315. this.path = "../x_component_query_ViewDesigner/$View/";
  1316. this.imagePath_default = "../x_component_query_ViewDesigner/$View/";
  1317. this.imagePath_custom = "../x_component_process_FormDesigner/Module/Actionbar/";
  1318. this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/actionbar.wcss";
  1319. this.view = view;
  1320. this.json = json;
  1321. this.jsonList = jsonList;
  1322. this.css = this.view.css;
  1323. this.container = this.view.actionbarNode;
  1324. this.moduleName = "actionbar";
  1325. this.load();
  1326. },
  1327. getJsonPath: function () {
  1328. return "../x_component_query_StatementDesigner/$Statement/toolbars.json";
  1329. },
  1330. selected: function () {
  1331. if (this.view.statement.currentSelectedModule) {
  1332. if (this.view.statement.currentSelectedModule == this) {
  1333. return true;
  1334. } else {
  1335. this.view.statement.currentSelectedModule.unSelected();
  1336. }
  1337. }
  1338. this.view.domListNode.show();
  1339. this.node.setStyles(this.css.toolbarWarpNode_selected);
  1340. //this.listNode.setStyles(this.css.cloumnListNode_selected);
  1341. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1342. //new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  1343. this.view.statement.currentSelectedModule = this;
  1344. this.isSelected = true;
  1345. //this._showActions();
  1346. this.showProperty();
  1347. },
  1348. unSelected: function () {
  1349. this.view.statement.currentSelectedModule = null;
  1350. this.node.setStyles(this.css.toolbarWarpNode);
  1351. //this.listNode.setStyles(this.css.cloumnListNode);
  1352. this.isSelected = false;
  1353. //this._hideActions();
  1354. this.hideProperty();
  1355. },
  1356. });
  1357. MWF.xApplication.query.StatementDesigner.View.Paging = new Class({
  1358. Extends: MWF.xApplication.query.ViewDesigner.View.Paging,
  1359. selected: function () {
  1360. if (this.view.statement.currentSelectedModule) {
  1361. if (this.view.statement.currentSelectedModule == this) {
  1362. return true;
  1363. } else {
  1364. this.view.statement.currentSelectedModule.unSelected();
  1365. }
  1366. }
  1367. this.view.domListNode.show();
  1368. this.node.setStyles(this.css.pagingWarpNode_selected);
  1369. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1370. this.view.statement.currentSelectedModule = this;
  1371. this.isSelected = true;
  1372. this.showProperty();
  1373. },
  1374. unSelected: function () {
  1375. this.view.statement.currentSelectedModule = null;
  1376. this.node.setStyles(this.css.pagingWarpNode);
  1377. this.isSelected = false;
  1378. this.hideProperty();
  1379. }
  1380. });