Statement.js 77 KB

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