Statement.js 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827
  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. this.json.table = "";
  532. this.json.tableObj = null;
  533. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  534. // var className = e.target.options[e.target.selectedIndex].value;
  535. // if (this.json.type=="select"){
  536. // this.json.data
  537. // /(select)*(where|)/g
  538. // }
  539. // }.bind(this));
  540. // this.jpqlTypeSelect.addEvent("change", function(){
  541. // var type = e.target.options[e.target.selectedIndex].value;
  542. // switch (entityCategory) {
  543. // case "update":
  544. // this.jpqlSelectEditor.hide();
  545. // this.jpqlUpdateEditor.show();
  546. // this.jpqlDeleteEditor.hide();
  547. // this.loadJpqlUpdateEditor();
  548. // break;
  549. // case "delete":
  550. // this.jpqlSelectEditor.hide();
  551. // this.jpqlUpdateEditor.hide();
  552. // this.jpqlDeleteEditor.show();
  553. // break;
  554. // default:
  555. // this.jpqlSelectEditor.show();
  556. // this.jpqlUpdateEditor.hide();
  557. // this.jpqlDeleteEditor.hide();
  558. // break;
  559. // }
  560. }.bind(this));
  561. this.runActionNode.getFirst().addEvent("click", this.runStatement.bind(this));
  562. this.dynamicTableSelect.addEvent("click", this.selectTable.bind(this));
  563. this.jpqlTypeSelect.addEvent("change", function () {
  564. var t = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value;
  565. if (t != this.json.type) {
  566. this.json.type = t;
  567. }
  568. if (t != "select") {
  569. this.jpqlPage.showTabIm();
  570. this.countJpqlPage.disableTab();
  571. this.runPage.showTabIm();
  572. this.viewPage.disableTab();
  573. } else {
  574. this.countJpqlPage.enableTab(true);
  575. this.viewPage.enableTab(true);
  576. }
  577. }.bind(this));
  578. this.fieldSelect.addEvent("change", function (ev) {
  579. var option = ev.target.options[ev.target.selectedIndex];
  580. var type = option.retrieve("type");
  581. var field = option.retrieve("field");
  582. if( !field )return;
  583. var text = field.name;
  584. if( this.countJpqlPage && this.countJpqlPage.isShow && !this.countJpqlPage.disabled ){
  585. if( this.data.format === "script" && this.countScriptEditor.jsEditor ){
  586. this.countScriptEditor.jsEditor.insertValue( text );
  587. }else{
  588. this.countEditor.insertValue( text );
  589. }
  590. }else{
  591. if( this.data.format === "script" && this.scriptEditor.jsEditor ){
  592. this.scriptEditor.jsEditor.insertValue( text );
  593. }else{
  594. this.editor.insertValue( text );
  595. }
  596. }
  597. }.bind(this))
  598. },
  599. changeEditorEntityClassName : function( entityClassName ){
  600. if (this.json.format == "jpql") {
  601. if (this.editor) {
  602. var re = /(.*from\s*)/ig;
  603. if (this.json.type == "update") re = /(.*update\s*)/ig;
  604. //if (this.json.type=="select" && this.editor){
  605. var v = this.json.data;
  606. var re2 = /(\s+)/ig;
  607. var arr = re.exec(v);
  608. if (arr && arr[0]) {
  609. var left = arr[0]
  610. v = v.substring(left.length, v.length);
  611. //var ar = re2.exec(v);
  612. var right = v.substring(v.indexOf(" "), v.length);
  613. this.json.data = left + entityClassName + right;
  614. this.editor.editor.setValue(this.json.data);
  615. }
  616. //}
  617. }
  618. if( this.countEditor ){
  619. var re = /(.*from\s*)/ig;
  620. var v = this.json.countData;
  621. var re2 = /(\s+)/ig;
  622. var arr = re.exec(v);
  623. if (arr && arr[0]) {
  624. var left = arr[0]
  625. v = v.substring(left.length, v.length);
  626. //var ar = re2.exec(v);
  627. var right = v.substring(v.indexOf(" "), v.length);
  628. this.json.countData = left + entityClassName + right;
  629. this.countEditor.editor.setValue(this.json.countData);
  630. }
  631. }
  632. }
  633. },
  634. selectTable: function () {
  635. new MWF.O2Selector(this.designer.content, {
  636. "type": "queryTable",
  637. "count": 1,
  638. "values": (this.json.table) ? [this.json.table] : [],
  639. "title": this.designer.lp.selectTable,
  640. "onComplete": function (items) {
  641. if (items.length) {
  642. var id = items[0].data.id;
  643. var name = items[0].data.name;
  644. this.dynamicTableContent.set("text", name);
  645. this.json.table = name;
  646. this.json.tableObj = items[0].data;
  647. this.officialTableSelect.options[0].set("selected", true);
  648. this.json.entityClassName = "";
  649. this.changeEditorEntityClassName( name );
  650. this.loadFieldSelect();
  651. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  652. } else {
  653. this.dynamicTableContent.set("text", "");
  654. this.json.table = "";
  655. this.loadFieldSelect();
  656. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  657. }
  658. }.bind(this)
  659. });
  660. },
  661. runStatement: function () {
  662. debugger;
  663. // if (!this.json.data){
  664. // this.designer.notice(this.designer.lp.inputStatementData, "error");
  665. // return false;
  666. // }
  667. // o2.require("o2.widget.Mask", null, false);
  668. // this.runMask = new o2.widget.Mask();
  669. // this.runMask.loadNode(this.node);
  670. this.saveSilence(function () {
  671. debugger;
  672. this.execute(function (json) {
  673. this.executeData = json;
  674. o2.require("o2.widget.JsonParse", function () {
  675. this.runResultNode.empty();
  676. var jsonResult = new o2.widget.JsonParse(json, this.runResultNode);
  677. jsonResult.load();
  678. }.bind(this));
  679. if (this.view) {
  680. var flag = true;
  681. if (this.data.type !== "select") flag = false;
  682. if (this.data.format === "script" && !this.data.scriptText) flag = false;
  683. if (this.data.format !== "script" && !this.data.data) flag = false;
  684. if (flag) this.view.loadViewData();
  685. }
  686. this.setColumnDataPath(json);
  687. // this.runMask.hide();
  688. }.bind(this), function () {
  689. // if (this.runMask) this.runMask.hide();
  690. }.bind(this))
  691. // var json = this.jsonEditor.editor.getValue();
  692. // var o = JSON.parse(json);
  693. //
  694. // var mode = "data";
  695. // if( this.data.type === "select" ){
  696. // if( this.data.format === "script" ){
  697. // if( this.data.scriptText && this.data.countScriptText ){
  698. // mode = "all"
  699. // }else if( this.data.scriptText && !this.data.countScriptText ){
  700. // mode = "data"
  701. // }else if( !this.data.scriptText && this.data.countScriptText ){
  702. // mode = "count"
  703. // }else{
  704. // this.designer.notice(this.designer.lp.inputStatementData, "error");
  705. // return false;
  706. // }
  707. // }else{
  708. // if( this.data.data && this.data.countData ){
  709. // mode = "all"
  710. // }else if( this.data.data && !this.data.countData ){
  711. // mode = "data"
  712. // }else if( !this.data.data && this.data.countData ){
  713. // mode = "count"
  714. // }else{
  715. // this.designer.notice(this.designer.lp.inputStatementData, "error");
  716. // return false;
  717. // }
  718. // }
  719. // }
  720. // o2.Actions.load("x_query_assemble_designer").StatementAction.executeV2(this.json.id, mode, 1, 50 , o, function(json){
  721. // o2.require("o2.widget.JsonParse", function(){
  722. // this.runResultNode.empty();
  723. // var jsonResult = new o2.widget.JsonParse(json, this.runResultNode);
  724. // jsonResult.load();
  725. // }.bind(this));
  726. // this.runMask.hide();
  727. // }.bind(this), function(xhr, text, error){
  728. // debugger;
  729. // if (this.runMask) this.runMask.hide();
  730. // var errorText = error;
  731. // if (xhr){
  732. // var json = JSON.decode(xhr.responseText);
  733. // if (json){
  734. // errorText = json.message.trim() || "request json error";
  735. // }else{
  736. // errorText = "request json error: "+xhr.responseText;
  737. // }
  738. // }
  739. // errorText = errorText.replace(/\</g, "&lt;");
  740. // errorText = errorText.replace(/\</g, "&gt;");
  741. // MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  742. // }.bind(this))
  743. }.bind(this));
  744. },
  745. setColumnDataPath: function (json) {
  746. if (this.data.type !== "select") return;
  747. if (this.data.format === "script" && !this.data.scriptText) return;
  748. if (this.data.format !== "script" && !this.data.data) return;
  749. this.columnDataPathList = [];
  750. debugger;
  751. var addPath = function (value, key) {
  752. if (typeOf(value) === "array") {
  753. Array.each(value, function (v, idx) {
  754. var path = (key || typeOf(key) === "number") ? (key + "." + idx) : idx.toString();
  755. if (!this.columnDataPathList.contains(path)) this.columnDataPathList.push(path);
  756. if (typeOf(v) === "array" || typeOf(v) === "object") addPath(v, path);
  757. }.bind(this))
  758. } else if (typeOf(value) === "object") {
  759. Object.each(value, function (v, k) {
  760. var path = (key || typeOf(key) === "number") ? (key + "." + k) : k;
  761. if (!this.columnDataPathList.contains(path)) this.columnDataPathList.push(path);
  762. if (typeOf(v) === "array" || typeOf(v) === "object") addPath(v, path);
  763. addPath(v, path);
  764. }.bind(this))
  765. } else {
  766. // if( key && !this.columnDataPathList.indexOf(key) )this.columnDataPathList.push(key);
  767. }
  768. }.bind(this);
  769. for (var i = 0; i < json.data.length && i < 10; i++) {
  770. var d = json.data[i];
  771. addPath(d);
  772. }
  773. this.columnDataPathList.sort();
  774. if (this.view && this.view.items) {
  775. this.view.items.each(function (column) {
  776. column.refreshColumnPathData()
  777. })
  778. }
  779. },
  780. getColumnDataPath: function () {
  781. return this.columnDataPathList || [];
  782. },
  783. execute: function (success, failure) {
  784. var json = this.jsonEditor.editor.getValue();
  785. var o = JSON.parse(json);
  786. var mode = "data";
  787. if (this.data.type === "select") {
  788. if (this.data.format === "script") {
  789. if (this.data.scriptText && this.data.countScriptText) {
  790. mode = "all"
  791. } else if (this.data.scriptText && !this.data.countScriptText) {
  792. mode = "data"
  793. } else if (!this.data.scriptText && this.data.countScriptText) {
  794. mode = "count"
  795. } else {
  796. this.designer.notice(this.designer.lp.inputStatementData, "error");
  797. return false;
  798. }
  799. } else {
  800. if (this.data.data && this.data.countData) {
  801. mode = "all"
  802. } else if (this.data.data && !this.data.countData) {
  803. mode = "data"
  804. } else if (!this.data.data && this.data.countData) {
  805. mode = "count"
  806. } else {
  807. this.designer.notice(this.designer.lp.inputStatementData, "error");
  808. return false;
  809. }
  810. }
  811. }
  812. o2.Actions.load("x_query_assemble_designer").StatementAction.executeV2(this.json.id, mode, 1, 50, o, function (json) {
  813. if (success) success(json)
  814. }.bind(this), function (xhr, text, error) {
  815. debugger;
  816. if (failure) failure();
  817. var errorText = error;
  818. if (xhr) {
  819. var json = JSON.decode(xhr.responseText);
  820. if (json) {
  821. errorText = json.message.trim() || "request json error";
  822. } else {
  823. errorText = "request json error: " + xhr.responseText;
  824. }
  825. }
  826. errorText = errorText.replace(/\</g, "&lt;");
  827. errorText = errorText.replace(/\</g, "&gt;");
  828. MWF.xDesktop.notice("error", {x: "right", y: "top"}, errorText);
  829. }.bind(this))
  830. },
  831. save: function (callback) {
  832. debugger;
  833. if (!this.data.name) {
  834. this.designer.notice(this.designer.lp.inputStatementName, "error");
  835. return false;
  836. }
  837. if (typeOf(this.viewJson) === "object") {
  838. this.data.view = JSON.stringify(this.viewJson);
  839. if(!this.data.view.group)this.data.view.group = {};
  840. }
  841. //if( !this.data.tableType ){
  842. // this.data.tableType = "dynamic";
  843. //}
  844. if (this.editor) this.data.data = this.editor.editor.getValue();
  845. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  846. if (this.jsonEditor) this.data.testParameters = this.jsonEditor.editor.getValue();
  847. this.designer.actions.saveStatement(this.data, function (json) {
  848. this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  849. this.data.id = json.data.id;
  850. if (this.lisNode) {
  851. this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
  852. }
  853. if (callback) callback();
  854. }.bind(this));
  855. },
  856. _setEditStyle: function () {
  857. },
  858. saveSilence: function (callback) {
  859. if (!this.data.name) {
  860. this.designer.notice(this.designer.lp.inputStatementName, "error");
  861. return false;
  862. }
  863. if (typeOf(this.viewJson) === "object") {
  864. this.data.view = JSON.stringify(this.viewJson);
  865. }
  866. if (this.editor) this.data.data = this.editor.editor.getValue();
  867. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  868. if (this.jsonEditor) this.data.testParameters = this.jsonEditor.editor.getValue();
  869. this.designer.actions.saveStatement(this.data, function (json) {
  870. //this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  871. this.data.id = json.data.id;
  872. if (this.lisNode) {
  873. this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
  874. }
  875. if (callback) callback();
  876. }.bind(this));
  877. },
  878. loadView: function (callback) {
  879. this.setViewSize();
  880. this.designer.addEvent("resize", this.setViewSize.bind(this));
  881. if (!this.data.view) {
  882. this.viewJson = {};
  883. } else {
  884. this.viewJson = JSON.parse(this.data.view)
  885. }
  886. this.view = new MWF.xApplication.query.StatementDesigner.View(this.designer, this, this.viewJson, {});
  887. this.view.load(function () {
  888. this.view.setContentHeight();
  889. }.bind(this));
  890. },
  891. setViewSize: function () {
  892. debugger;
  893. var size = this.areaNode.getSize();
  894. var designerSize = this.designerArea.getComputedSize();
  895. var reizeNodeSize = this.resizeNode.getComputedSize();
  896. var y = size.y - designerSize.totalHeight - reizeNodeSize.totalHeight;
  897. var mTop = this.viewArea.getStyle("margin-top").toInt();
  898. var mBottom = this.viewArea.getStyle("margin-bottom").toInt();
  899. var pTop = this.viewArea.getStyle("padding-top").toInt();
  900. var pBottom = this.viewArea.getStyle("padding-bottom").toInt();
  901. y = y - mTop - mBottom - pTop - pBottom - 1;
  902. var tabSize = this.tabNode.getComputedSize();
  903. y = y - tabSize.totalHeight;
  904. this.viewArea.setStyle("height", "" + y + "px");
  905. // var titleSize = this.runTitleNode.getComputedSize();
  906. // y = y - titleSize.totalHeight;
  907. // this.runContentNode.setStyle("height", ""+y+"px");
  908. },
  909. preview: function () {
  910. if (this.isNewStatement) {
  911. this.designer.notice(this.designer.lp.saveStatementNotice, "error");
  912. return;
  913. }
  914. if (this.data.type !== "select") {
  915. this.designer.notice(this.designer.lp.previewNotSelectStatementNotice, "error");
  916. return;
  917. }
  918. if (!this.data.view) {
  919. this.designer.notice(this.designer.lp.noViewNotice, "error");
  920. }
  921. this.saveSilence(function () {
  922. var url = "../x_desktop/app.html?app=query.Query&status=";
  923. url += JSON.stringify({
  924. id: this.data.application,
  925. statementId: this.data.id
  926. });
  927. window.open(o2.filterUrl(url), "_blank");
  928. }.bind(this));
  929. }
  930. });
  931. MWF.xApplication.query.StatementDesigner.View = new Class({
  932. Extends: MWF.xApplication.query.ViewDesigner.View,
  933. Implements: [Options, Events],
  934. options: {
  935. "style": "default",
  936. "isView": false,
  937. "showTab": true,
  938. "propertyPath": "../x_component_query_StatementDesigner/$Statement/view.html"
  939. },
  940. initialize: function (designer, statement, data, options) {
  941. this.setOptions(options);
  942. this.path = "../x_component_query_ViewDesigner/$View/";
  943. this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/css.wcss";
  944. this._loadCss();
  945. this.statement = statement;
  946. this.designer = designer;
  947. this.data = data;
  948. // if (!this.data.data) this.data.data = {};
  949. this.parseData();
  950. this.node = this.statement.viewArea;
  951. //this.tab = this.designer.tab;
  952. this.areaNode = new Element("div", {"styles": {"height": "calc(100% - 2px)", "overflow": "auto"}});
  953. this.areaNode.setStyles(this.css.areaNode);
  954. //MWF.require("MWF.widget.ScrollBar", function(){
  955. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  956. //}.bind(this));
  957. // this.propertyListNode = this.designer.propertyDomArea;
  958. //this.propertyNode = this.designer.propertyContentArea;
  959. // if(this.designer.application) this.data.applicationName = this.designer.application.name;
  960. // if(this.designer.application) this.data.application = this.designer.application.id;
  961. // this.isNewView = (this.data.name) ? false : true;
  962. this.items = [];
  963. this.view = this;
  964. // this.autoSave();
  965. // this.designer.addEvent("queryClose", function(){
  966. // if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  967. // }.bind(this));
  968. },
  969. load: function (callback) {
  970. this.setAreaNodeSize();
  971. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  972. this.areaNode.inject(this.node);
  973. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  974. this.loadTemplateStyle(function () {
  975. this.loadActionbar();
  976. this.loadView();
  977. this.loadPaging();
  978. // this.selected();
  979. this.setEvent();
  980. //if (this.options.showTab) this.page.showTabIm();
  981. this.setViewWidth();
  982. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  983. if (callback) callback();
  984. }.bind(this))
  985. },
  986. parseData: function () {
  987. this.json = this.data;
  988. if (!this.json.id) {
  989. this.json.id = (new o2.widget.UUID).id;
  990. }
  991. if (!this.json.data || !this.json.data.events) {
  992. var url = "../x_component_query_StatementDesigner/$Statement/view.json";
  993. MWF.getJSON(url, {
  994. "onSuccess": function (obj) {
  995. if (!this.json.data) this.json.data = obj.data;
  996. if (!this.json.data.events) this.json.data.events = obj.data.events;
  997. }.bind(this),
  998. "onerror": function (text) {
  999. this.notice(text, "error");
  1000. }.bind(this),
  1001. "onRequestFailure": function (xhr) {
  1002. this.notice(xhr.responseText, "error");
  1003. }.bind(this)
  1004. }, false);
  1005. }
  1006. },
  1007. setEvent: function () {
  1008. this.areaNode.addEvents({
  1009. "click": function (e) {
  1010. this.selected();
  1011. e.stopPropagation();
  1012. }.bind(this),
  1013. "mouseover": function () {
  1014. if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode_over)
  1015. }.bind(this),
  1016. "mouseout": function () {
  1017. if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode)
  1018. }.bind(this)
  1019. });
  1020. this.refreshNode.addEvent("click", function (e) {
  1021. this.statement.runStatement();
  1022. e.stopPropagation();
  1023. }.bind(this));
  1024. this.addColumnNode.addEvent("click", function (e) {
  1025. this.addColumn();
  1026. e.stopPropagation();
  1027. }.bind(this));
  1028. },
  1029. selected: function () {
  1030. debugger;
  1031. if (this.statement.currentSelectedModule) {
  1032. if (this.statement.currentSelectedModule == this) {
  1033. return true;
  1034. } else {
  1035. this.statement.currentSelectedModule.unSelected();
  1036. }
  1037. }
  1038. this.areaNode.setStyles(this.css.areaNode_selected);
  1039. this.statement.currentSelectedModule = this;
  1040. this.domListNode.show();
  1041. this.isSelected = true;
  1042. this.showProperty();
  1043. },
  1044. unSelected: function () {
  1045. this.statement.currentSelectedModule = null;
  1046. this.isSelected = false;
  1047. this.areaNode.setStyles(this.css.areaNode);
  1048. this.hideProperty();
  1049. },
  1050. showProperty: function () {
  1051. if (!this.property) {
  1052. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  1053. "path": this.options.propertyPath,
  1054. "onPostLoad": function () {
  1055. this.property.show();
  1056. }.bind(this)
  1057. });
  1058. this.property.load();
  1059. } else {
  1060. this.property.show();
  1061. }
  1062. },
  1063. hideProperty: function () {
  1064. if (this.property) this.property.hide();
  1065. },
  1066. loadViewData: function () {
  1067. debugger;
  1068. if (this.data.id) {
  1069. // this.statement.saveSilence(function () {
  1070. this.viewContentBodyNode.empty();
  1071. this.viewContentTableNode = new Element("table", {
  1072. "styles": this.css.viewContentTableNode,
  1073. "border": "0px",
  1074. "cellPadding": "0",
  1075. "cellSpacing": "0"
  1076. }).inject(this.viewContentBodyNode);
  1077. // this.statement.execute( function (json) {
  1078. // this.statement.setColumnDataPath( json );
  1079. var entries = {};
  1080. this.json.data.selectList.each(function (entry) {
  1081. entries[entry.column] = entry;
  1082. }.bind(this));
  1083. if (this.statement.executeData && this.statement.executeData.data && this.statement.executeData.data.length) {
  1084. this.statement.executeData.data.each(function (line, idx) {
  1085. var tr = new Element("tr", {
  1086. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
  1087. }).inject(this.viewContentTableNode);
  1088. //this.createViewCheckboxTd( tr );
  1089. Object.each(entries, function (c, k) {
  1090. debugger;
  1091. var path = c.path, code = c.code, obj = line;
  1092. if( path ){
  1093. var pathList = path.split(".");
  1094. for( var i=0; i<pathList.length; i++ ){
  1095. var p = pathList[i];
  1096. if( (/(^[1-9]\d*$)/.test(p)) )p = p.toInt();
  1097. if( obj[ p ] ){
  1098. obj = obj[ p ];
  1099. }else{
  1100. obj = "";
  1101. break;
  1102. }
  1103. }
  1104. }
  1105. if( code && code.trim())obj = MWF.Macro.exec( code, { "target" : {"value": obj, "data": line, "entry": c} });
  1106. var toName = function (value) {
  1107. if(typeOf(value) === "array"){
  1108. Array.each( value, function (v, idx) {
  1109. value[idx] = toName(v)
  1110. })
  1111. }else if( typeOf(value) === "object" ){
  1112. Object.each( value, function (v, key) {
  1113. value[key] = toName(v);
  1114. })
  1115. }else if( typeOf( value ) === "string" ){
  1116. value = o2.name.cn( value )
  1117. }
  1118. return value;
  1119. };
  1120. var d;
  1121. if( obj!= undefined && obj!= null ){
  1122. if( typeOf(obj) === "array" ) {
  1123. d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
  1124. }else if( typeOf(obj) === "object" ){
  1125. d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
  1126. }else{
  1127. d = c.isName ? o2.name.cn( obj.toString() ) : obj;
  1128. }
  1129. }
  1130. if (d != undefined && d != null ) {
  1131. var td = new Element("td", {
  1132. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  1133. }).inject(tr);
  1134. if (c.isHtml) {
  1135. td.set("html", d);
  1136. } else {
  1137. td.set("text", d);
  1138. }
  1139. }
  1140. }.bind(this));
  1141. }.bind(this));
  1142. this.setContentColumnWidth();
  1143. this.setContentHeight();
  1144. } else if (this.json.data.noDataText) {
  1145. var noDataTextNodeStyle = this.css.noDataTextNode;
  1146. if (this.json.data.viewStyles) {
  1147. if (this.json.data.viewStyles["noDataTextNode"]) {
  1148. noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
  1149. } else {
  1150. this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
  1151. }
  1152. }
  1153. this.noDataTextNode = new Element("div", {
  1154. "styles": noDataTextNodeStyle,
  1155. "text": this.json.data.noDataText
  1156. }).inject(this.viewContentBodyNode);
  1157. }
  1158. // }.bind(this));
  1159. // }.bind(this));
  1160. }
  1161. },
  1162. addColumn: function () {
  1163. debugger;
  1164. MWF.require("MWF.widget.UUID", function () {
  1165. var id = (new MWF.widget.UUID).id;
  1166. var json = {
  1167. "id": id,
  1168. "column": id,
  1169. "displayName": this.designer.lp.unnamed,
  1170. "orderType": "original"
  1171. };
  1172. if (!this.json.data.selectList) this.json.data.selectList = [];
  1173. this.json.data.selectList.push(json);
  1174. var column = new MWF.xApplication.query.StatementDesigner.View.Column(json, this);
  1175. this.items.push(column);
  1176. column.selected();
  1177. if (this.viewContentTableNode) {
  1178. var trs = this.viewContentTableNode.getElements("tr");
  1179. trs.each(function (tr) {
  1180. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  1181. }.bind(this));
  1182. //this.setContentColumnWidth();
  1183. }
  1184. this.setViewWidth();
  1185. this.addColumnNode.scrollIntoView(true);
  1186. }.bind(this));
  1187. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  1188. },
  1189. setContentHeight: function () {
  1190. var size = this.areaNode.getSize();
  1191. var titleSize = this.viewTitleNode.getSize();
  1192. var actionbarSize = this.actionbarNode ? this.actionbarNode.getSize() : {x: 0, y: 0};
  1193. var pagingSize = this.pagingNode ? this.pagingNode.getSize() : {x: 0, y: 0};
  1194. var height = size.y - titleSize.y - actionbarSize.y - pagingSize.y - 4;
  1195. this.viewContentScrollNode.setStyle("height", height);
  1196. var contentSize = this.viewContentBodyNode.getSize();
  1197. if (height < contentSize.y) height = contentSize.y + 10;
  1198. this.viewContentNode.setStyle("height", height);
  1199. this.contentLeftNode.setStyle("height", height);
  1200. this.contentRightNode.setStyle("height", height);
  1201. //this.viewContentBodyNode.setStyle("min-height", height);
  1202. },
  1203. loadViewColumns: function () {
  1204. // for (var i=0; i<10; i++){
  1205. if (this.json.data.selectList) {
  1206. this.json.data.selectList.each(function (json) {
  1207. this.items.push(new MWF.xApplication.query.StatementDesigner.View.Column(json, this));
  1208. }.bind(this));
  1209. }
  1210. // }
  1211. },
  1212. showActionbar: function (noSetHeight) {
  1213. this.actionbarNode.show();
  1214. if (!this.json.data.actionbarList) this.json.data.actionbarList = [];
  1215. if (!this.actionbarList || this.actionbarList.length == 0) {
  1216. if (this.json.data.actionbarList.length) {
  1217. this.json.data.actionbarList.each(function (json) {
  1218. this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(json, this.json.data.actionbarList, this))
  1219. }.bind(this));
  1220. } else {
  1221. this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(null, this.json.data.actionbarList, this))
  1222. }
  1223. }
  1224. if (!noSetHeight) this.setContentHeight();
  1225. },
  1226. loadPaging: function (noSetHeight) {
  1227. this.pagingNode = new Element("div#pagingNode", {"styles": this.css.pagingNode}).inject(this.areaNode);
  1228. this.pagingList = [];
  1229. if (!this.json.data.pagingList) this.json.data.pagingList = [];
  1230. if (!this.pagingList || this.pagingList.length == 0) {
  1231. if (this.json.data.pagingList.length) {
  1232. this.json.data.pagingList.each(function (json) {
  1233. this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(json, this.json.data.pagingList, this))
  1234. }.bind(this));
  1235. } else {
  1236. this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(null, this.json.data.pagingList, this))
  1237. }
  1238. }
  1239. // if( !noSetHeight )this.setContentHeight();
  1240. },
  1241. setViewWidth: function () {
  1242. if (!this.viewAreaNode) return;
  1243. this.viewAreaNode.setStyle("width", "auto");
  1244. this.viewTitleNode.setStyle("width", "auto");
  1245. var s1 = this.viewTitleTableNode.getSize();
  1246. var s2 = this.refreshNode.getSize();
  1247. var s3 = this.addColumnNode.getSize();
  1248. var width = s1.x + s2.x + s2.x;
  1249. var size = this.areaNode.getSize();
  1250. if (width > size.x) {
  1251. this.viewTitleNode.setStyle("width", "" + (width - 2) + "px");
  1252. this.viewAreaNode.setStyle("width", "" + (width - 2) + "px");
  1253. } else {
  1254. this.viewTitleNode.setStyle("width", "" + (size.x - 2) + "px");
  1255. this.viewAreaNode.setStyle("width", "" + (size.x - 2) + "px");
  1256. }
  1257. this.setContentColumnWidth();
  1258. this.setContentHeight();
  1259. },
  1260. _setEditStyle: function (name, input, oldValue) {
  1261. if (name == "data.actionbarHidden") {
  1262. if (this.json.data.actionbarHidden) {
  1263. this.hideActionbar()
  1264. } else {
  1265. this.showActionbar()
  1266. }
  1267. }
  1268. if (name == "data.selectAllEnable") {
  1269. if (this.json.data.selectAllEnable) {
  1270. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display", "table-cell");
  1271. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display", "table-cell");
  1272. } else {
  1273. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display", "none");
  1274. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display", "none");
  1275. }
  1276. }
  1277. if (name == "data.viewStyleType") {
  1278. var file = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].file : null;
  1279. var extendFile = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].extendFile : null;
  1280. this.loadTemplateStyles(file, extendFile, function (templateStyles) {
  1281. this.templateStyles = templateStyles;
  1282. var oldFile, oldExtendFile;
  1283. if (oldValue && this.stylesList[oldValue]) {
  1284. oldFile = this.stylesList[oldValue].file;
  1285. oldExtendFile = this.stylesList[oldValue].extendFile;
  1286. }
  1287. this.loadTemplateStyles(oldFile, oldExtendFile, function (oldTemplateStyles) {
  1288. this.json.data.styleConfig = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType] : null;
  1289. if (oldTemplateStyles["view"]) this.clearTemplateStyles(oldTemplateStyles["view"]);
  1290. if (this.templateStyles["view"]) this.setTemplateStyles(this.templateStyles["view"]);
  1291. this.setAllStyles();
  1292. this.actionbarList.each(function (module) {
  1293. if (oldTemplateStyles["actionbar"]) {
  1294. module.clearTemplateStyles(oldTemplateStyles["actionbar"]);
  1295. }
  1296. module.setStyleTemplate();
  1297. module.setAllStyles();
  1298. })
  1299. this.pagingList.each(function (module) {
  1300. if (oldTemplateStyles["paging"]) {
  1301. module.clearTemplateStyles(oldTemplateStyles["paging"]);
  1302. }
  1303. module.setStyleTemplate();
  1304. module.setAllStyles();
  1305. });
  1306. // this.moduleList.each(function(module){
  1307. // if (oldTemplateStyles[module.moduleName]){
  1308. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  1309. // }
  1310. // module.setStyleTemplate();
  1311. // module.setAllStyles();
  1312. // }.bind(this));
  1313. }.bind(this))
  1314. }.bind(this))
  1315. }
  1316. if (name == "data.viewStyles") {
  1317. this.setCustomStyles();
  1318. }
  1319. },
  1320. loadTemplateStyle: function (callback) {
  1321. this.loadStylesList(function () {
  1322. var oldStyleValue = "";
  1323. if ((!this.json.data.viewStyleType) || !this.stylesList[this.json.data.viewStyleType]) this.json.data.viewStyleType = "default";
  1324. this.loadTemplateStyles(this.stylesList[this.json.data.viewStyleType].file, this.stylesList[this.json.data.viewStyleType].extendFile,
  1325. function (templateStyles) {
  1326. this.templateStyles = templateStyles;
  1327. if (!this.json.data.viewStyleType) this.json.data.viewStyleType = "default";
  1328. if (this.templateStyles && this.templateStyles["view"]) {
  1329. var viewStyles = Object.clone(this.templateStyles["view"]);
  1330. if (viewStyles.contentGroupTd) delete viewStyles.contentGroupTd;
  1331. if (viewStyles.groupCollapseNode) delete viewStyles.groupCollapseNode;
  1332. if (viewStyles.groupExpandNode) delete viewStyles.groupExpandNode;
  1333. if (!this.json.data.viewStyles) {
  1334. this.json.data.viewStyles = viewStyles;
  1335. } else {
  1336. this.setTemplateStyles(viewStyles);
  1337. }
  1338. }
  1339. this.setCustomStyles();
  1340. if (callback) callback();
  1341. }.bind(this)
  1342. );
  1343. }.bind(this));
  1344. },
  1345. clearTemplateStyles: function (styles) {
  1346. if (styles) {
  1347. if (styles.container) this.removeStyles(styles.container, "container");
  1348. if (styles.table) this.removeStyles(styles.table, "table");
  1349. if (styles.titleTr) this.removeStyles(styles.titleTr, "titleTr");
  1350. if (styles.titleTd) this.removeStyles(styles.titleTd, "titleTd");
  1351. if (styles.contentTr) this.removeStyles(styles.contentTr, "contentTr");
  1352. if (styles.contentSelectedTr) this.removeStyles(styles.contentSelectedTr, "contentSelectedTr");
  1353. if (styles.contentTd) this.removeStyles(styles.contentTd, "contentTd");
  1354. // if (styles.contentGroupTd) this.removeStyles(styles.contentGroupTd, "contentGroupTd");
  1355. // if (styles.groupCollapseNode) this.removeStyles(styles.groupCollapseNode, "groupCollapseNode");
  1356. // if (styles.groupExpandNode) this.removeStyles(styles.groupExpandNode, "groupExpandNode");
  1357. if (styles.checkboxNode) this.removeStyles(styles.checkboxNode, "checkboxNode");
  1358. if (styles.checkedCheckboxNode) this.removeStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1359. if (styles.radioNode) this.removeStyles(styles.radioNode, "radioNode");
  1360. if (styles.checkedRadioNode) this.removeStyles(styles.checkedRadioNode, "checkedRadioNode");
  1361. if (styles.tableProperties) this.removeStyles(styles.tableProperties, "tableProperties");
  1362. }
  1363. },
  1364. setTemplateStyles: function (styles) {
  1365. if (styles.container) this.copyStyles(styles.container, "container");
  1366. if (styles.table) this.copyStyles(styles.table, "table");
  1367. if (styles.titleTr) this.copyStyles(styles.titleTr, "titleTr");
  1368. if (styles.titleTd) this.copyStyles(styles.titleTd, "titleTd");
  1369. if (styles.contentTr) this.copyStyles(styles.contentTr, "contentTr");
  1370. if (styles.contentSelectedTr) this.copyStyles(styles.contentSelectedTr, "contentSelectedTr");
  1371. if (styles.contentTd) this.copyStyles(styles.contentTd, "contentTd");
  1372. // if (styles.contentGroupTd) this.copyStyles(styles.contentGroupTd, "contentGroupTd");
  1373. // if (styles.groupCollapseNode) this.copyStyles(styles.groupCollapseNode, "groupCollapseNode");
  1374. // if (styles.groupExpandNode) this.copyStyles(styles.groupExpandNode, "groupExpandNode");
  1375. if (styles.checkboxNode) this.copyStyles(styles.checkboxNode, "checkboxNode");
  1376. if (styles.checkedCheckboxNode) this.copyStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1377. if (styles.radioNode) this.copyStyles(styles.radioNode, "radioNode");
  1378. if (styles.checkedRadioNode) this.copyStyles(styles.checkedRadioNode, "checkedRadioNode");
  1379. if (styles.tableProperties) this.copyStyles(styles.tableProperties, "tableProperties");
  1380. },
  1381. removeStyles: function (from, to) {
  1382. if (this.json.data.viewStyles[to]) {
  1383. Object.each(from, function (style, key) {
  1384. if (this.json.data.viewStyles[to][key] && this.json.data.viewStyles[to][key] == style) {
  1385. delete this.json.data.viewStyles[to][key];
  1386. }
  1387. }.bind(this));
  1388. }
  1389. },
  1390. copyStyles: function (from, to) {
  1391. if (!this.json.data.viewStyles[to]) this.json.data.viewStyles[to] = {};
  1392. Object.each(from, function (style, key) {
  1393. if (!this.json.data.viewStyles[to][key]) this.json.data.viewStyles[to][key] = style;
  1394. }.bind(this));
  1395. }
  1396. // preview: function(){
  1397. // if( this.isNewView ){
  1398. // this.designer.notice( this.designer.lp.saveViewNotice, "error" );
  1399. // return;
  1400. // }
  1401. // this.saveSilence( function () {
  1402. // var url = "../x_desktop/app.html?app=query.Query&status=";
  1403. // url += JSON.stringify({
  1404. // id : this.data.application,
  1405. // viewId : this.data.id
  1406. // });
  1407. // window.open(o2.filterUrl(url),"_blank");
  1408. // }.bind(this));
  1409. // },
  1410. // saveSilence: function(callback){
  1411. // if (!this.data.name){
  1412. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1413. // return false;
  1414. // }
  1415. //
  1416. // this.designer.actions.saveView(this.data, function(json){
  1417. // this.data.id = json.data.id;
  1418. // this.isNewView = false;
  1419. // //this.page.textNode.set("text", this.data.name);
  1420. // if (this.lisNode) {
  1421. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1422. // }
  1423. // if (callback) callback();
  1424. // }.bind(this));
  1425. // },
  1426. // save: function(callback){
  1427. // //if (this.designer.tab.showPage==this.page){
  1428. // if (!this.data.name){
  1429. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1430. // return false;
  1431. // }
  1432. // //}
  1433. // this.designer.actions.saveView(this.data, function(json){
  1434. // this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  1435. // this.isNewView = false;
  1436. // this.data.id = json.data.id;
  1437. // //this.page.textNode.set("text", this.data.name);
  1438. // if (this.lisNode) {
  1439. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1440. // }
  1441. // if (callback) callback();
  1442. // }.bind(this));
  1443. // },
  1444. // saveAs: function(){
  1445. // var form = new MWF.xApplication.query.StatementDesigner.View.NewNameForm(this, {
  1446. // name : this.data.name + "_" + MWF.xApplication.query.StatementDesigner.LP.copy,
  1447. // query : this.data.query || this.data.application,
  1448. // queryName : this.data.queryName || this.data.applicationName
  1449. // }, {
  1450. // onSave : function( data, callback ){
  1451. // this._saveAs( data, callback );
  1452. // }.bind(this)
  1453. // }, {
  1454. // app: this.designer
  1455. // });
  1456. // form.edit()
  1457. // },
  1458. // _saveAs : function( data , callback){
  1459. // var _self = this;
  1460. //
  1461. // var d = this.cloneObject( this.data );
  1462. //
  1463. // d.isNewView = true;
  1464. // d.id = this.designer.actions.getUUID();
  1465. // d.name = data.name;
  1466. // d.alias = "";
  1467. // d.query = data.query;
  1468. // d.queryName = data.queryName;
  1469. // d.application = data.query;
  1470. // d.applicationName = data.queryName;
  1471. // d.pid = d.id + d.id;
  1472. //
  1473. // delete d[this.data.id+"viewFilterType"];
  1474. // d[d.id+"viewFilterType"]="custom";
  1475. //
  1476. // d.data.selectList.each( function( entry ){
  1477. // entry.id = (new MWF.widget.UUID).id;
  1478. // }.bind(this));
  1479. //
  1480. // this.designer.actions.saveView(d, function(json){
  1481. // this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  1482. // if (callback) callback();
  1483. // }.bind(this));
  1484. // }
  1485. });
  1486. MWF.xApplication.query.StatementDesigner.View.Column = new Class({
  1487. Extends: MWF.xApplication.query.ViewDesigner.View.Column,
  1488. initialize: function (json, view, next) {
  1489. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/column.html";
  1490. this.view = view;
  1491. this.json = json;
  1492. this.next = next;
  1493. this.css = this.view.css;
  1494. this.content = this.view.viewTitleTrNode;
  1495. this.domListNode = this.view.domListNode;
  1496. this.load();
  1497. },
  1498. refreshColumnPathData: function () {
  1499. if (this.property) {
  1500. this.property.loadDataPathSelect();
  1501. }
  1502. },
  1503. getColumnDataPath: function () {
  1504. return this.view.statement.getColumnDataPath();
  1505. },
  1506. showProperty: function () {
  1507. if (!this.property) {
  1508. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  1509. "path": this.propertyPath,
  1510. "onPostLoad": function () {
  1511. this.property.show();
  1512. var processDiv = this.property.propertyContent.getElements("#" + this.json.id + "dataPathSelectedProcessArea");
  1513. var cmsDiv = this.property.propertyContent.getElements("#" + this.json.id + "dataPathSelectedCMSArea");
  1514. if (this.view.json.type == "cms") {
  1515. processDiv.setStyle("display", "none");
  1516. cmsDiv.setStyle("display", "block");
  1517. } else {
  1518. processDiv.setStyle("display", "block");
  1519. cmsDiv.setStyle("display", "none");
  1520. }
  1521. }.bind(this)
  1522. });
  1523. this.property.load();
  1524. } else {
  1525. this.property.show();
  1526. }
  1527. },
  1528. selected: function () {
  1529. if (this.view.statement.currentSelectedModule) {
  1530. if (this.view.statement.currentSelectedModule == this) {
  1531. return true;
  1532. } else {
  1533. this.view.statement.currentSelectedModule.unSelected();
  1534. }
  1535. }
  1536. this.view.domListNode.show();
  1537. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  1538. this.listNode.setStyles(this.css.cloumnListNode_selected);
  1539. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1540. new Fx.Scroll(this.view.designer.propertyDomArea, {
  1541. "wheelStops": false,
  1542. "duration": 100
  1543. }).toElement(this.listNode);
  1544. this.view.statement.currentSelectedModule = this;
  1545. this.isSelected = true;
  1546. this._showActions();
  1547. this.showProperty();
  1548. },
  1549. unSelected: function () {
  1550. this.view.statement.currentSelectedModule = null;
  1551. //this.node.setStyles(this.css.viewTitleColumnNode);
  1552. if (this.isError) {
  1553. this.node.setStyles(this.css.viewTitleColumnNode_error)
  1554. } else {
  1555. this.node.setStyles(this.css.viewTitleColumnNode)
  1556. }
  1557. this.listNode.setStyles(this.css.cloumnListNode);
  1558. this.isSelected = false;
  1559. this._hideActions();
  1560. this.hideProperty();
  1561. }
  1562. });
  1563. MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({
  1564. Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar,
  1565. initialize: function (json, jsonList, view, options) {
  1566. this.setOptions(options);
  1567. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/actionbar.html";
  1568. this.path = "../x_component_query_ViewDesigner/$View/";
  1569. this.imagePath_default = "../x_component_query_ViewDesigner/$View/";
  1570. this.imagePath_custom = "../x_component_process_FormDesigner/Module/Actionbar/";
  1571. this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/actionbar.wcss";
  1572. this.view = view;
  1573. this.json = json;
  1574. this.jsonList = jsonList;
  1575. this.css = this.view.css;
  1576. this.container = this.view.actionbarNode;
  1577. this.moduleName = "actionbar";
  1578. this.load();
  1579. },
  1580. getJsonPath: function () {
  1581. return "../x_component_query_StatementDesigner/$Statement/toolbars.json";
  1582. },
  1583. selected: function () {
  1584. if (this.view.statement.currentSelectedModule) {
  1585. if (this.view.statement.currentSelectedModule == this) {
  1586. return true;
  1587. } else {
  1588. this.view.statement.currentSelectedModule.unSelected();
  1589. }
  1590. }
  1591. this.view.domListNode.show();
  1592. this.node.setStyles(this.css.toolbarWarpNode_selected);
  1593. //this.listNode.setStyles(this.css.cloumnListNode_selected);
  1594. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1595. //new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  1596. this.view.statement.currentSelectedModule = this;
  1597. this.isSelected = true;
  1598. //this._showActions();
  1599. this.showProperty();
  1600. },
  1601. unSelected: function () {
  1602. this.view.statement.currentSelectedModule = null;
  1603. this.node.setStyles(this.css.toolbarWarpNode);
  1604. //this.listNode.setStyles(this.css.cloumnListNode);
  1605. this.isSelected = false;
  1606. //this._hideActions();
  1607. this.hideProperty();
  1608. },
  1609. });
  1610. MWF.xApplication.query.StatementDesigner.View.Paging = new Class({
  1611. Extends: MWF.xApplication.query.ViewDesigner.View.Paging,
  1612. selected: function () {
  1613. if (this.view.statement.currentSelectedModule) {
  1614. if (this.view.statement.currentSelectedModule == this) {
  1615. return true;
  1616. } else {
  1617. this.view.statement.currentSelectedModule.unSelected();
  1618. }
  1619. }
  1620. this.view.domListNode.show();
  1621. this.node.setStyles(this.css.pagingWarpNode_selected);
  1622. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1623. this.view.statement.currentSelectedModule = this;
  1624. this.isSelected = true;
  1625. this.showProperty();
  1626. },
  1627. unSelected: function () {
  1628. this.view.statement.currentSelectedModule = null;
  1629. this.node.setStyles(this.css.pagingWarpNode);
  1630. this.isSelected = false;
  1631. this.hideProperty();
  1632. }
  1633. });