Statement.js 78 KB

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