Statement.js 77 KB

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