Statement.js 77 KB

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