Statement.js 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830
  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. if(this.viewJson.data && !this.viewJson.data.group)this.viewJson.data.group = {};
  839. if(!this.viewJson.pageSize)this.viewJson.pageSize = "20";
  840. this.data.view = JSON.stringify(this.viewJson);
  841. }
  842. //if( !this.data.tableType ){
  843. // this.data.tableType = "dynamic";
  844. //}
  845. if (this.editor) this.data.data = this.editor.editor.getValue();
  846. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  847. if (this.jsonEditor) this.data.testParameters = this.jsonEditor.editor.getValue();
  848. this.designer.actions.saveStatement(this.data, function (json) {
  849. this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  850. this.data.id = json.data.id;
  851. if (this.lisNode) {
  852. this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
  853. }
  854. if (callback) callback();
  855. }.bind(this));
  856. },
  857. _setEditStyle: function () {
  858. },
  859. saveSilence: function (callback) {
  860. if (!this.data.name) {
  861. this.designer.notice(this.designer.lp.inputStatementName, "error");
  862. return false;
  863. }
  864. if (typeOf(this.viewJson) === "object") {
  865. if(this.viewJson.data && !this.viewJson.data.group)this.viewJson.data.group = {};
  866. if( !this.viewJson.pageSize )this.viewJson.pageSize = "20";
  867. this.data.view = JSON.stringify(this.viewJson);
  868. }
  869. if (this.editor) this.data.data = this.editor.editor.getValue();
  870. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  871. if (this.jsonEditor) this.data.testParameters = this.jsonEditor.editor.getValue();
  872. this.designer.actions.saveStatement(this.data, function (json) {
  873. //this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  874. this.data.id = json.data.id;
  875. if (this.lisNode) {
  876. this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
  877. }
  878. if (callback) callback();
  879. }.bind(this));
  880. },
  881. loadView: function (callback) {
  882. this.setViewSize();
  883. this.designer.addEvent("resize", this.setViewSize.bind(this));
  884. if (!this.data.view) {
  885. this.viewJson = {};
  886. } else {
  887. this.viewJson = JSON.parse(this.data.view)
  888. }
  889. this.view = new MWF.xApplication.query.StatementDesigner.View(this.designer, this, this.viewJson, {});
  890. this.view.load(function () {
  891. this.view.setContentHeight();
  892. }.bind(this));
  893. },
  894. setViewSize: function () {
  895. debugger;
  896. var size = this.areaNode.getSize();
  897. var designerSize = this.designerArea.getComputedSize();
  898. var reizeNodeSize = this.resizeNode.getComputedSize();
  899. var y = size.y - designerSize.totalHeight - reizeNodeSize.totalHeight;
  900. var mTop = this.viewArea.getStyle("margin-top").toInt();
  901. var mBottom = this.viewArea.getStyle("margin-bottom").toInt();
  902. var pTop = this.viewArea.getStyle("padding-top").toInt();
  903. var pBottom = this.viewArea.getStyle("padding-bottom").toInt();
  904. y = y - mTop - mBottom - pTop - pBottom - 1;
  905. var tabSize = this.tabNode.getComputedSize();
  906. y = y - tabSize.totalHeight;
  907. this.viewArea.setStyle("height", "" + y + "px");
  908. // var titleSize = this.runTitleNode.getComputedSize();
  909. // y = y - titleSize.totalHeight;
  910. // this.runContentNode.setStyle("height", ""+y+"px");
  911. },
  912. preview: function () {
  913. if (this.isNewStatement) {
  914. this.designer.notice(this.designer.lp.saveStatementNotice, "error");
  915. return;
  916. }
  917. if (this.data.type !== "select") {
  918. this.designer.notice(this.designer.lp.previewNotSelectStatementNotice, "error");
  919. return;
  920. }
  921. if (!this.data.view) {
  922. this.designer.notice(this.designer.lp.noViewNotice, "error");
  923. }
  924. this.saveSilence(function () {
  925. var url = "../x_desktop/app.html?app=query.Query&status=";
  926. url += JSON.stringify({
  927. id: this.data.application,
  928. statementId: this.data.id
  929. });
  930. window.open(o2.filterUrl(url), "_blank");
  931. }.bind(this));
  932. }
  933. });
  934. MWF.xApplication.query.StatementDesigner.View = new Class({
  935. Extends: MWF.xApplication.query.ViewDesigner.View,
  936. Implements: [Options, Events],
  937. options: {
  938. "style": "default",
  939. "isView": false,
  940. "showTab": true,
  941. "propertyPath": "../x_component_query_StatementDesigner/$Statement/view.html"
  942. },
  943. initialize: function (designer, statement, data, options) {
  944. this.setOptions(options);
  945. this.path = "../x_component_query_ViewDesigner/$View/";
  946. this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/css.wcss";
  947. this._loadCss();
  948. this.statement = statement;
  949. this.designer = designer;
  950. this.data = data;
  951. // if (!this.data.data) this.data.data = {};
  952. this.parseData();
  953. this.node = this.statement.viewArea;
  954. //this.tab = this.designer.tab;
  955. this.areaNode = new Element("div", {"styles": {"height": "calc(100% - 2px)", "overflow": "auto"}});
  956. this.areaNode.setStyles(this.css.areaNode);
  957. //MWF.require("MWF.widget.ScrollBar", function(){
  958. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  959. //}.bind(this));
  960. // this.propertyListNode = this.designer.propertyDomArea;
  961. //this.propertyNode = this.designer.propertyContentArea;
  962. // if(this.designer.application) this.data.applicationName = this.designer.application.name;
  963. // if(this.designer.application) this.data.application = this.designer.application.id;
  964. // this.isNewView = (this.data.name) ? false : true;
  965. this.items = [];
  966. this.view = this;
  967. // this.autoSave();
  968. // this.designer.addEvent("queryClose", function(){
  969. // if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  970. // }.bind(this));
  971. },
  972. load: function (callback) {
  973. this.setAreaNodeSize();
  974. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  975. this.areaNode.inject(this.node);
  976. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  977. this.loadTemplateStyle(function () {
  978. this.loadActionbar();
  979. this.loadView();
  980. this.loadPaging();
  981. // this.selected();
  982. this.setEvent();
  983. //if (this.options.showTab) this.page.showTabIm();
  984. this.setViewWidth();
  985. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  986. if (callback) callback();
  987. }.bind(this))
  988. },
  989. parseData: function () {
  990. this.json = this.data;
  991. if (!this.json.id) {
  992. this.json.id = (new o2.widget.UUID).id;
  993. }
  994. if (!this.json.data || !this.json.data.events) {
  995. var url = "../x_component_query_StatementDesigner/$Statement/view.json";
  996. MWF.getJSON(url, {
  997. "onSuccess": function (obj) {
  998. if (!this.json.data) this.json.data = obj.data;
  999. if (!this.json.data.events) this.json.data.events = obj.data.events;
  1000. }.bind(this),
  1001. "onerror": function (text) {
  1002. this.notice(text, "error");
  1003. }.bind(this),
  1004. "onRequestFailure": function (xhr) {
  1005. this.notice(xhr.responseText, "error");
  1006. }.bind(this)
  1007. }, false);
  1008. }
  1009. },
  1010. setEvent: function () {
  1011. this.areaNode.addEvents({
  1012. "click": function (e) {
  1013. this.selected();
  1014. e.stopPropagation();
  1015. }.bind(this),
  1016. "mouseover": function () {
  1017. if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode_over)
  1018. }.bind(this),
  1019. "mouseout": function () {
  1020. if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode)
  1021. }.bind(this)
  1022. });
  1023. this.refreshNode.addEvent("click", function (e) {
  1024. this.statement.runStatement();
  1025. e.stopPropagation();
  1026. }.bind(this));
  1027. this.addColumnNode.addEvent("click", function (e) {
  1028. this.addColumn();
  1029. e.stopPropagation();
  1030. }.bind(this));
  1031. },
  1032. selected: function () {
  1033. debugger;
  1034. if (this.statement.currentSelectedModule) {
  1035. if (this.statement.currentSelectedModule == this) {
  1036. return true;
  1037. } else {
  1038. this.statement.currentSelectedModule.unSelected();
  1039. }
  1040. }
  1041. this.areaNode.setStyles(this.css.areaNode_selected);
  1042. this.statement.currentSelectedModule = this;
  1043. this.domListNode.show();
  1044. this.isSelected = true;
  1045. this.showProperty();
  1046. },
  1047. unSelected: function () {
  1048. this.statement.currentSelectedModule = null;
  1049. this.isSelected = false;
  1050. this.areaNode.setStyles(this.css.areaNode);
  1051. this.hideProperty();
  1052. },
  1053. showProperty: function () {
  1054. if (!this.property) {
  1055. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  1056. "path": this.options.propertyPath,
  1057. "onPostLoad": function () {
  1058. this.property.show();
  1059. }.bind(this)
  1060. });
  1061. this.property.load();
  1062. } else {
  1063. this.property.show();
  1064. }
  1065. },
  1066. hideProperty: function () {
  1067. if (this.property) this.property.hide();
  1068. },
  1069. loadViewData: function () {
  1070. debugger;
  1071. if (this.data.id) {
  1072. // this.statement.saveSilence(function () {
  1073. this.viewContentBodyNode.empty();
  1074. this.viewContentTableNode = new Element("table", {
  1075. "styles": this.css.viewContentTableNode,
  1076. "border": "0px",
  1077. "cellPadding": "0",
  1078. "cellSpacing": "0"
  1079. }).inject(this.viewContentBodyNode);
  1080. // this.statement.execute( function (json) {
  1081. // this.statement.setColumnDataPath( json );
  1082. var entries = {};
  1083. this.json.data.selectList.each(function (entry) {
  1084. entries[entry.column] = entry;
  1085. }.bind(this));
  1086. if (this.statement.executeData && this.statement.executeData.data && this.statement.executeData.data.length) {
  1087. this.statement.executeData.data.each(function (line, idx) {
  1088. var tr = new Element("tr", {
  1089. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
  1090. }).inject(this.viewContentTableNode);
  1091. //this.createViewCheckboxTd( tr );
  1092. Object.each(entries, function (c, k) {
  1093. debugger;
  1094. var path = c.path, code = c.code, obj = line;
  1095. if( path ){
  1096. var pathList = path.split(".");
  1097. for( var i=0; i<pathList.length; i++ ){
  1098. var p = pathList[i];
  1099. if( (/(^[1-9]\d*$)/.test(p)) )p = p.toInt();
  1100. if( obj[ p ] ){
  1101. obj = obj[ p ];
  1102. }else{
  1103. obj = "";
  1104. break;
  1105. }
  1106. }
  1107. }
  1108. if( code && code.trim())obj = MWF.Macro.exec( code, { "target" : {"value": obj, "data": line, "entry": c} });
  1109. var toName = function (value) {
  1110. if(typeOf(value) === "array"){
  1111. Array.each( value, function (v, idx) {
  1112. value[idx] = toName(v)
  1113. })
  1114. }else if( typeOf(value) === "object" ){
  1115. Object.each( value, function (v, key) {
  1116. value[key] = toName(v);
  1117. })
  1118. }else if( typeOf( value ) === "string" ){
  1119. value = o2.name.cn( value )
  1120. }
  1121. return value;
  1122. };
  1123. var d;
  1124. if( obj!= undefined && obj!= null ){
  1125. if( typeOf(obj) === "array" ) {
  1126. d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
  1127. }else if( typeOf(obj) === "object" ){
  1128. d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
  1129. }else{
  1130. d = c.isName ? o2.name.cn( obj.toString() ) : obj;
  1131. }
  1132. }
  1133. if (d != undefined && d != null ) {
  1134. var td = new Element("td", {
  1135. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  1136. }).inject(tr);
  1137. if (c.isHtml) {
  1138. td.set("html", d);
  1139. } else {
  1140. td.set("text", d);
  1141. }
  1142. }
  1143. }.bind(this));
  1144. }.bind(this));
  1145. this.setContentColumnWidth();
  1146. this.setContentHeight();
  1147. } else if (this.json.data.noDataText) {
  1148. var noDataTextNodeStyle = this.css.noDataTextNode;
  1149. if (this.json.data.viewStyles) {
  1150. if (this.json.data.viewStyles["noDataTextNode"]) {
  1151. noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
  1152. } else {
  1153. this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
  1154. }
  1155. }
  1156. this.noDataTextNode = new Element("div", {
  1157. "styles": noDataTextNodeStyle,
  1158. "text": this.json.data.noDataText
  1159. }).inject(this.viewContentBodyNode);
  1160. }
  1161. // }.bind(this));
  1162. // }.bind(this));
  1163. }
  1164. },
  1165. addColumn: function () {
  1166. debugger;
  1167. MWF.require("MWF.widget.UUID", function () {
  1168. var id = (new MWF.widget.UUID).id;
  1169. var json = {
  1170. "id": id,
  1171. "column": id,
  1172. "displayName": this.designer.lp.unnamed,
  1173. "orderType": "original"
  1174. };
  1175. if (!this.json.data.selectList) this.json.data.selectList = [];
  1176. this.json.data.selectList.push(json);
  1177. var column = new MWF.xApplication.query.StatementDesigner.View.Column(json, this);
  1178. this.items.push(column);
  1179. column.selected();
  1180. if (this.viewContentTableNode) {
  1181. var trs = this.viewContentTableNode.getElements("tr");
  1182. trs.each(function (tr) {
  1183. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  1184. }.bind(this));
  1185. //this.setContentColumnWidth();
  1186. }
  1187. this.setViewWidth();
  1188. this.addColumnNode.scrollIntoView(true);
  1189. }.bind(this));
  1190. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  1191. },
  1192. setContentHeight: function () {
  1193. var size = this.areaNode.getSize();
  1194. var titleSize = this.viewTitleNode.getSize();
  1195. var actionbarSize = this.actionbarNode ? this.actionbarNode.getSize() : {x: 0, y: 0};
  1196. var pagingSize = this.pagingNode ? this.pagingNode.getSize() : {x: 0, y: 0};
  1197. var height = size.y - titleSize.y - actionbarSize.y - pagingSize.y - 4;
  1198. this.viewContentScrollNode.setStyle("height", height);
  1199. var contentSize = this.viewContentBodyNode.getSize();
  1200. if (height < contentSize.y) height = contentSize.y + 10;
  1201. this.viewContentNode.setStyle("height", height);
  1202. this.contentLeftNode.setStyle("height", height);
  1203. this.contentRightNode.setStyle("height", height);
  1204. //this.viewContentBodyNode.setStyle("min-height", height);
  1205. },
  1206. loadViewColumns: function () {
  1207. // for (var i=0; i<10; i++){
  1208. if (this.json.data.selectList) {
  1209. this.json.data.selectList.each(function (json) {
  1210. this.items.push(new MWF.xApplication.query.StatementDesigner.View.Column(json, this));
  1211. }.bind(this));
  1212. }
  1213. // }
  1214. },
  1215. showActionbar: function (noSetHeight) {
  1216. this.actionbarNode.show();
  1217. if (!this.json.data.actionbarList) this.json.data.actionbarList = [];
  1218. if (!this.actionbarList || this.actionbarList.length == 0) {
  1219. if (this.json.data.actionbarList.length) {
  1220. this.json.data.actionbarList.each(function (json) {
  1221. this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(json, this.json.data.actionbarList, this))
  1222. }.bind(this));
  1223. } else {
  1224. this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(null, this.json.data.actionbarList, this))
  1225. }
  1226. }
  1227. if (!noSetHeight) this.setContentHeight();
  1228. },
  1229. loadPaging: function (noSetHeight) {
  1230. this.pagingNode = new Element("div#pagingNode", {"styles": this.css.pagingNode}).inject(this.areaNode);
  1231. this.pagingList = [];
  1232. if (!this.json.data.pagingList) this.json.data.pagingList = [];
  1233. if (!this.pagingList || this.pagingList.length == 0) {
  1234. if (this.json.data.pagingList.length) {
  1235. this.json.data.pagingList.each(function (json) {
  1236. this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(json, this.json.data.pagingList, this))
  1237. }.bind(this));
  1238. } else {
  1239. this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(null, this.json.data.pagingList, this))
  1240. }
  1241. }
  1242. // if( !noSetHeight )this.setContentHeight();
  1243. },
  1244. setViewWidth: function () {
  1245. if (!this.viewAreaNode) return;
  1246. this.viewAreaNode.setStyle("width", "auto");
  1247. this.viewTitleNode.setStyle("width", "auto");
  1248. var s1 = this.viewTitleTableNode.getSize();
  1249. var s2 = this.refreshNode.getSize();
  1250. var s3 = this.addColumnNode.getSize();
  1251. var width = s1.x + s2.x + s2.x;
  1252. var size = this.areaNode.getSize();
  1253. if (width > size.x) {
  1254. this.viewTitleNode.setStyle("width", "" + (width - 2) + "px");
  1255. this.viewAreaNode.setStyle("width", "" + (width - 2) + "px");
  1256. } else {
  1257. this.viewTitleNode.setStyle("width", "" + (size.x - 2) + "px");
  1258. this.viewAreaNode.setStyle("width", "" + (size.x - 2) + "px");
  1259. }
  1260. this.setContentColumnWidth();
  1261. this.setContentHeight();
  1262. },
  1263. _setEditStyle: function (name, input, oldValue) {
  1264. if (name == "data.actionbarHidden") {
  1265. if (this.json.data.actionbarHidden) {
  1266. this.hideActionbar()
  1267. } else {
  1268. this.showActionbar()
  1269. }
  1270. }
  1271. if (name == "data.selectAllEnable") {
  1272. if (this.json.data.selectAllEnable) {
  1273. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display", "table-cell");
  1274. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display", "table-cell");
  1275. } else {
  1276. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display", "none");
  1277. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display", "none");
  1278. }
  1279. }
  1280. if (name == "data.viewStyleType") {
  1281. var file = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].file : null;
  1282. var extendFile = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].extendFile : null;
  1283. this.loadTemplateStyles(file, extendFile, function (templateStyles) {
  1284. this.templateStyles = templateStyles;
  1285. var oldFile, oldExtendFile;
  1286. if (oldValue && this.stylesList[oldValue]) {
  1287. oldFile = this.stylesList[oldValue].file;
  1288. oldExtendFile = this.stylesList[oldValue].extendFile;
  1289. }
  1290. this.loadTemplateStyles(oldFile, oldExtendFile, function (oldTemplateStyles) {
  1291. this.json.data.styleConfig = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType] : null;
  1292. if (oldTemplateStyles["view"]) this.clearTemplateStyles(oldTemplateStyles["view"]);
  1293. if (this.templateStyles["view"]) this.setTemplateStyles(this.templateStyles["view"]);
  1294. this.setAllStyles();
  1295. this.actionbarList.each(function (module) {
  1296. if (oldTemplateStyles["actionbar"]) {
  1297. module.clearTemplateStyles(oldTemplateStyles["actionbar"]);
  1298. }
  1299. module.setStyleTemplate();
  1300. module.setAllStyles();
  1301. })
  1302. this.pagingList.each(function (module) {
  1303. if (oldTemplateStyles["paging"]) {
  1304. module.clearTemplateStyles(oldTemplateStyles["paging"]);
  1305. }
  1306. module.setStyleTemplate();
  1307. module.setAllStyles();
  1308. });
  1309. // this.moduleList.each(function(module){
  1310. // if (oldTemplateStyles[module.moduleName]){
  1311. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  1312. // }
  1313. // module.setStyleTemplate();
  1314. // module.setAllStyles();
  1315. // }.bind(this));
  1316. }.bind(this))
  1317. }.bind(this))
  1318. }
  1319. if (name == "data.viewStyles") {
  1320. this.setCustomStyles();
  1321. }
  1322. },
  1323. loadTemplateStyle: function (callback) {
  1324. this.loadStylesList(function () {
  1325. var oldStyleValue = "";
  1326. if ((!this.json.data.viewStyleType) || !this.stylesList[this.json.data.viewStyleType]) this.json.data.viewStyleType = "default";
  1327. this.loadTemplateStyles(this.stylesList[this.json.data.viewStyleType].file, this.stylesList[this.json.data.viewStyleType].extendFile,
  1328. function (templateStyles) {
  1329. this.templateStyles = templateStyles;
  1330. if (!this.json.data.viewStyleType) this.json.data.viewStyleType = "default";
  1331. if (this.templateStyles && this.templateStyles["view"]) {
  1332. var viewStyles = Object.clone(this.templateStyles["view"]);
  1333. if (viewStyles.contentGroupTd) delete viewStyles.contentGroupTd;
  1334. if (viewStyles.groupCollapseNode) delete viewStyles.groupCollapseNode;
  1335. if (viewStyles.groupExpandNode) delete viewStyles.groupExpandNode;
  1336. if (!this.json.data.viewStyles) {
  1337. this.json.data.viewStyles = viewStyles;
  1338. } else {
  1339. this.setTemplateStyles(viewStyles);
  1340. }
  1341. }
  1342. this.setCustomStyles();
  1343. if (callback) callback();
  1344. }.bind(this)
  1345. );
  1346. }.bind(this));
  1347. },
  1348. clearTemplateStyles: function (styles) {
  1349. if (styles) {
  1350. if (styles.container) this.removeStyles(styles.container, "container");
  1351. if (styles.table) this.removeStyles(styles.table, "table");
  1352. if (styles.titleTr) this.removeStyles(styles.titleTr, "titleTr");
  1353. if (styles.titleTd) this.removeStyles(styles.titleTd, "titleTd");
  1354. if (styles.contentTr) this.removeStyles(styles.contentTr, "contentTr");
  1355. if (styles.contentSelectedTr) this.removeStyles(styles.contentSelectedTr, "contentSelectedTr");
  1356. if (styles.contentTd) this.removeStyles(styles.contentTd, "contentTd");
  1357. // if (styles.contentGroupTd) this.removeStyles(styles.contentGroupTd, "contentGroupTd");
  1358. // if (styles.groupCollapseNode) this.removeStyles(styles.groupCollapseNode, "groupCollapseNode");
  1359. // if (styles.groupExpandNode) this.removeStyles(styles.groupExpandNode, "groupExpandNode");
  1360. if (styles.checkboxNode) this.removeStyles(styles.checkboxNode, "checkboxNode");
  1361. if (styles.checkedCheckboxNode) this.removeStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1362. if (styles.radioNode) this.removeStyles(styles.radioNode, "radioNode");
  1363. if (styles.checkedRadioNode) this.removeStyles(styles.checkedRadioNode, "checkedRadioNode");
  1364. if (styles.tableProperties) this.removeStyles(styles.tableProperties, "tableProperties");
  1365. }
  1366. },
  1367. setTemplateStyles: function (styles) {
  1368. if (styles.container) this.copyStyles(styles.container, "container");
  1369. if (styles.table) this.copyStyles(styles.table, "table");
  1370. if (styles.titleTr) this.copyStyles(styles.titleTr, "titleTr");
  1371. if (styles.titleTd) this.copyStyles(styles.titleTd, "titleTd");
  1372. if (styles.contentTr) this.copyStyles(styles.contentTr, "contentTr");
  1373. if (styles.contentSelectedTr) this.copyStyles(styles.contentSelectedTr, "contentSelectedTr");
  1374. if (styles.contentTd) this.copyStyles(styles.contentTd, "contentTd");
  1375. // if (styles.contentGroupTd) this.copyStyles(styles.contentGroupTd, "contentGroupTd");
  1376. // if (styles.groupCollapseNode) this.copyStyles(styles.groupCollapseNode, "groupCollapseNode");
  1377. // if (styles.groupExpandNode) this.copyStyles(styles.groupExpandNode, "groupExpandNode");
  1378. if (styles.checkboxNode) this.copyStyles(styles.checkboxNode, "checkboxNode");
  1379. if (styles.checkedCheckboxNode) this.copyStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1380. if (styles.radioNode) this.copyStyles(styles.radioNode, "radioNode");
  1381. if (styles.checkedRadioNode) this.copyStyles(styles.checkedRadioNode, "checkedRadioNode");
  1382. if (styles.tableProperties) this.copyStyles(styles.tableProperties, "tableProperties");
  1383. },
  1384. removeStyles: function (from, to) {
  1385. if (this.json.data.viewStyles[to]) {
  1386. Object.each(from, function (style, key) {
  1387. if (this.json.data.viewStyles[to][key] && this.json.data.viewStyles[to][key] == style) {
  1388. delete this.json.data.viewStyles[to][key];
  1389. }
  1390. }.bind(this));
  1391. }
  1392. },
  1393. copyStyles: function (from, to) {
  1394. if (!this.json.data.viewStyles[to]) this.json.data.viewStyles[to] = {};
  1395. Object.each(from, function (style, key) {
  1396. if (!this.json.data.viewStyles[to][key]) this.json.data.viewStyles[to][key] = style;
  1397. }.bind(this));
  1398. }
  1399. // preview: function(){
  1400. // if( this.isNewView ){
  1401. // this.designer.notice( this.designer.lp.saveViewNotice, "error" );
  1402. // return;
  1403. // }
  1404. // this.saveSilence( function () {
  1405. // var url = "../x_desktop/app.html?app=query.Query&status=";
  1406. // url += JSON.stringify({
  1407. // id : this.data.application,
  1408. // viewId : this.data.id
  1409. // });
  1410. // window.open(o2.filterUrl(url),"_blank");
  1411. // }.bind(this));
  1412. // },
  1413. // saveSilence: function(callback){
  1414. // if (!this.data.name){
  1415. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1416. // return false;
  1417. // }
  1418. //
  1419. // this.designer.actions.saveView(this.data, function(json){
  1420. // this.data.id = json.data.id;
  1421. // this.isNewView = false;
  1422. // //this.page.textNode.set("text", this.data.name);
  1423. // if (this.lisNode) {
  1424. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1425. // }
  1426. // if (callback) callback();
  1427. // }.bind(this));
  1428. // },
  1429. // save: function(callback){
  1430. // //if (this.designer.tab.showPage==this.page){
  1431. // if (!this.data.name){
  1432. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1433. // return false;
  1434. // }
  1435. // //}
  1436. // this.designer.actions.saveView(this.data, function(json){
  1437. // this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  1438. // this.isNewView = false;
  1439. // this.data.id = json.data.id;
  1440. // //this.page.textNode.set("text", this.data.name);
  1441. // if (this.lisNode) {
  1442. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1443. // }
  1444. // if (callback) callback();
  1445. // }.bind(this));
  1446. // },
  1447. // saveAs: function(){
  1448. // var form = new MWF.xApplication.query.StatementDesigner.View.NewNameForm(this, {
  1449. // name : this.data.name + "_" + MWF.xApplication.query.StatementDesigner.LP.copy,
  1450. // query : this.data.query || this.data.application,
  1451. // queryName : this.data.queryName || this.data.applicationName
  1452. // }, {
  1453. // onSave : function( data, callback ){
  1454. // this._saveAs( data, callback );
  1455. // }.bind(this)
  1456. // }, {
  1457. // app: this.designer
  1458. // });
  1459. // form.edit()
  1460. // },
  1461. // _saveAs : function( data , callback){
  1462. // var _self = this;
  1463. //
  1464. // var d = this.cloneObject( this.data );
  1465. //
  1466. // d.isNewView = true;
  1467. // d.id = this.designer.actions.getUUID();
  1468. // d.name = data.name;
  1469. // d.alias = "";
  1470. // d.query = data.query;
  1471. // d.queryName = data.queryName;
  1472. // d.application = data.query;
  1473. // d.applicationName = data.queryName;
  1474. // d.pid = d.id + d.id;
  1475. //
  1476. // delete d[this.data.id+"viewFilterType"];
  1477. // d[d.id+"viewFilterType"]="custom";
  1478. //
  1479. // d.data.selectList.each( function( entry ){
  1480. // entry.id = (new MWF.widget.UUID).id;
  1481. // }.bind(this));
  1482. //
  1483. // this.designer.actions.saveView(d, function(json){
  1484. // this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  1485. // if (callback) callback();
  1486. // }.bind(this));
  1487. // }
  1488. });
  1489. MWF.xApplication.query.StatementDesigner.View.Column = new Class({
  1490. Extends: MWF.xApplication.query.ViewDesigner.View.Column,
  1491. initialize: function (json, view, next) {
  1492. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/column.html";
  1493. this.view = view;
  1494. this.json = json;
  1495. this.next = next;
  1496. this.css = this.view.css;
  1497. this.content = this.view.viewTitleTrNode;
  1498. this.domListNode = this.view.domListNode;
  1499. this.load();
  1500. },
  1501. refreshColumnPathData: function () {
  1502. if (this.property) {
  1503. this.property.loadDataPathSelect();
  1504. }
  1505. },
  1506. getColumnDataPath: function () {
  1507. return this.view.statement.getColumnDataPath();
  1508. },
  1509. showProperty: function () {
  1510. if (!this.property) {
  1511. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  1512. "path": this.propertyPath,
  1513. "onPostLoad": function () {
  1514. this.property.show();
  1515. var processDiv = this.property.propertyContent.getElements("#" + this.json.id + "dataPathSelectedProcessArea");
  1516. var cmsDiv = this.property.propertyContent.getElements("#" + this.json.id + "dataPathSelectedCMSArea");
  1517. if (this.view.json.type == "cms") {
  1518. processDiv.setStyle("display", "none");
  1519. cmsDiv.setStyle("display", "block");
  1520. } else {
  1521. processDiv.setStyle("display", "block");
  1522. cmsDiv.setStyle("display", "none");
  1523. }
  1524. }.bind(this)
  1525. });
  1526. this.property.load();
  1527. } else {
  1528. this.property.show();
  1529. }
  1530. },
  1531. selected: function () {
  1532. if (this.view.statement.currentSelectedModule) {
  1533. if (this.view.statement.currentSelectedModule == this) {
  1534. return true;
  1535. } else {
  1536. this.view.statement.currentSelectedModule.unSelected();
  1537. }
  1538. }
  1539. this.view.domListNode.show();
  1540. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  1541. this.listNode.setStyles(this.css.cloumnListNode_selected);
  1542. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1543. new Fx.Scroll(this.view.designer.propertyDomArea, {
  1544. "wheelStops": false,
  1545. "duration": 100
  1546. }).toElement(this.listNode);
  1547. this.view.statement.currentSelectedModule = this;
  1548. this.isSelected = true;
  1549. this._showActions();
  1550. this.showProperty();
  1551. },
  1552. unSelected: function () {
  1553. this.view.statement.currentSelectedModule = null;
  1554. //this.node.setStyles(this.css.viewTitleColumnNode);
  1555. if (this.isError) {
  1556. this.node.setStyles(this.css.viewTitleColumnNode_error)
  1557. } else {
  1558. this.node.setStyles(this.css.viewTitleColumnNode)
  1559. }
  1560. this.listNode.setStyles(this.css.cloumnListNode);
  1561. this.isSelected = false;
  1562. this._hideActions();
  1563. this.hideProperty();
  1564. }
  1565. });
  1566. MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({
  1567. Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar,
  1568. initialize: function (json, jsonList, view, options) {
  1569. this.setOptions(options);
  1570. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/actionbar.html";
  1571. this.path = "../x_component_query_ViewDesigner/$View/";
  1572. this.imagePath_default = "../x_component_query_ViewDesigner/$View/";
  1573. this.imagePath_custom = "../x_component_process_FormDesigner/Module/Actionbar/";
  1574. this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/actionbar.wcss";
  1575. this.view = view;
  1576. this.json = json;
  1577. this.jsonList = jsonList;
  1578. this.css = this.view.css;
  1579. this.container = this.view.actionbarNode;
  1580. this.moduleName = "actionbar";
  1581. this.load();
  1582. },
  1583. getJsonPath: function () {
  1584. return "../x_component_query_StatementDesigner/$Statement/toolbars.json";
  1585. },
  1586. selected: function () {
  1587. if (this.view.statement.currentSelectedModule) {
  1588. if (this.view.statement.currentSelectedModule == this) {
  1589. return true;
  1590. } else {
  1591. this.view.statement.currentSelectedModule.unSelected();
  1592. }
  1593. }
  1594. this.view.domListNode.show();
  1595. this.node.setStyles(this.css.toolbarWarpNode_selected);
  1596. //this.listNode.setStyles(this.css.cloumnListNode_selected);
  1597. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1598. //new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  1599. this.view.statement.currentSelectedModule = this;
  1600. this.isSelected = true;
  1601. //this._showActions();
  1602. this.showProperty();
  1603. },
  1604. unSelected: function () {
  1605. this.view.statement.currentSelectedModule = null;
  1606. this.node.setStyles(this.css.toolbarWarpNode);
  1607. //this.listNode.setStyles(this.css.cloumnListNode);
  1608. this.isSelected = false;
  1609. //this._hideActions();
  1610. this.hideProperty();
  1611. },
  1612. });
  1613. MWF.xApplication.query.StatementDesigner.View.Paging = new Class({
  1614. Extends: MWF.xApplication.query.ViewDesigner.View.Paging,
  1615. selected: function () {
  1616. if (this.view.statement.currentSelectedModule) {
  1617. if (this.view.statement.currentSelectedModule == this) {
  1618. return true;
  1619. } else {
  1620. this.view.statement.currentSelectedModule.unSelected();
  1621. }
  1622. }
  1623. this.view.domListNode.show();
  1624. this.node.setStyles(this.css.pagingWarpNode_selected);
  1625. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1626. this.view.statement.currentSelectedModule = this;
  1627. this.isSelected = true;
  1628. this.showProperty();
  1629. },
  1630. unSelected: function () {
  1631. this.view.statement.currentSelectedModule = null;
  1632. this.node.setStyles(this.css.pagingWarpNode);
  1633. this.isSelected = false;
  1634. this.hideProperty();
  1635. }
  1636. });