Statement.js 109 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589
  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.countMethod){
  45. if( this.json.countData || this.json.countScriptText ){
  46. this.json.countMethod = "assign";
  47. }else{
  48. this.json.countMethod = "auto";
  49. }
  50. }
  51. if (!this.json.entityClassName) this.json.entityClassName = ""; //"com.x.processplatform.core.entity.content.Task";
  52. },
  53. autoSave: function () {
  54. this.autoSaveTimerID = window.setInterval(function () {
  55. if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFAutoSaveCheck");
  56. if (this.autoSaveCheckNode) {
  57. if (this.autoSaveCheckNode.get("checked")) {
  58. this.save();
  59. }
  60. }
  61. }.bind(this), 60000);
  62. },
  63. getDefaultEditorData: function(){
  64. return {
  65. "javascriptEditor": {
  66. "monaco_theme": "vs",
  67. "fontSize" : "12px",
  68. "editor": "monaco"
  69. }
  70. };
  71. // return {
  72. // "javascriptEditor": {
  73. // "theme": "tomorrow",
  74. // "fontSize" : "12px",
  75. // "editor": "ace"
  76. // }
  77. // };
  78. },
  79. getEditorTheme: function(callback){
  80. if (!o2.editorData){
  81. o2.UD.getData("editor", function(json){
  82. if (json.data){
  83. o2.editorData = JSON.decode(json.data);
  84. }else{
  85. o2.editorData = this.getDefaultEditorData();
  86. }
  87. if (callback) callback();
  88. }.bind(this));
  89. }else{
  90. if (callback) callback();
  91. }
  92. },
  93. load : function(){
  94. this.getEditorTheme( function () {
  95. this._load();
  96. }.bind(this))
  97. },
  98. _load: function () {
  99. // this.setAreaNodeSize();
  100. // this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  101. this.areaNode.inject(this.node);
  102. this.designer.statementListAreaNode.getChildren().each(function (node) {
  103. var statement = node.retrieve("statement");
  104. if (statement.id == this.data.id) {
  105. if (this.designer.currentListStatementItem) {
  106. this.designer.currentListStatementItem.setStyles(this.designer.css.listStatementItem);
  107. }
  108. node.setStyles(this.designer.css.listStatementItem_current);
  109. this.designer.currentListStatementItem = node;
  110. this.lisNode = node;
  111. }
  112. }.bind(this));
  113. this.loadStatement();
  114. // this.showProperty();
  115. this.selected();
  116. },
  117. selected: function () {
  118. if (this.currentSelectedModule) {
  119. if (this.currentSelectedModule == this) {
  120. return true;
  121. } else {
  122. this.currentSelectedModule.unSelected();
  123. }
  124. }
  125. if (this.view && this.view.domListNode) {
  126. this.view.domListNode.hide();
  127. }
  128. this.selectMode = "statement";
  129. this.currentSelectedModule = this;
  130. this.isSelected = true;
  131. this.showProperty();
  132. this.designer.setDesignerStatementResize();
  133. },
  134. unSelected: function () {
  135. this.currentSelectedModule = null;
  136. this.isSelected = false;
  137. this.hideProperty();
  138. },
  139. showProperty: function () {
  140. if (!this.property) {
  141. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.designerContentArea, this.designer, {
  142. "path": this.options.propertyPath,
  143. "onPostLoad": function () {
  144. this.property.show();
  145. }.bind(this)
  146. });
  147. this.property.load();
  148. } else {
  149. this.property.show();
  150. }
  151. },
  152. hideProperty: function () {
  153. if (this.property) this.property.hide();
  154. },
  155. loadStatementTab: function (callback) {
  156. var _self = this;
  157. MWF.require("MWF.widget.Tab", null, false);
  158. this.statementTab = new MWF.widget.Tab(this.statementTabNode, {"style": "script"});
  159. this.statementTab.load();
  160. this.tabQueryNode = Element("div");
  161. this.queryTabPageNode.inject(this.tabQueryNode);
  162. this.queryPage = this.statementTab.addTab(this.tabQueryNode, this.designer.lp.queryStatement);
  163. this.queryPage.addEvent("postShow", function(){
  164. switch (this.json.format) {
  165. case "script":
  166. if( this.jpqlScriptEditor ){
  167. this.jpqlScriptEditor.container.setStyle("height", ""+this.getEditorHeight()+"px");
  168. this.jpqlScriptEditor.resizeContentNodeSize();
  169. }
  170. break;
  171. case "sql":
  172. if(this.sqlEditor)this.sqlEditor.resize();
  173. break;
  174. case "sqlScript":
  175. if( this.sqlScriptEditor ){
  176. this.sqlScriptEditor.container.setStyle("height", ""+this.getEditorHeight()+"px");
  177. this.sqlScriptEditor.resizeContentNodeSize();
  178. }
  179. break;
  180. default:
  181. if(this.jpqlEditor)this.jpqlEditor.resize();
  182. }
  183. this.loadEditor();
  184. }.bind(this))
  185. this.tabCountNode = Element("div");
  186. this.countTabPageNode.inject(this.tabCountNode);
  187. this.countPage = this.statementTab.addTab(this.tabCountNode, this.designer.lp.countStatement);
  188. this.countPage.addEvent("postShow", function(){
  189. switch (this.json.format) {
  190. case "script":
  191. if( this.jpqlCountScriptEditor ){
  192. this.jpqlCountScriptEditor.container.setStyle("height", ""+this.getEditorHeight()+"px");
  193. this.jpqlCountScriptEditor.resizeContentNodeSize();
  194. }
  195. break;
  196. case "sql":
  197. if( this.sqlCountEditor )this.sqlCountEditor.resize();
  198. break;
  199. case "sqlScript":
  200. if( this.sqlCountScriptEditor ){
  201. this.sqlCountScriptEditor.container.setStyle("height", ""+this.getEditorHeight()+"px");
  202. this.sqlCountScriptEditor.resizeContentNodeSize();
  203. }
  204. break;
  205. default:
  206. if( this.jpqlCountEditor )this.jpqlCountEditor.resize();
  207. }
  208. this.loadEditor();
  209. }.bind(this))
  210. // this.tabSqlNode = Element("div");
  211. // this.sqlTabPageNode.inject(this.tabSqlNode);
  212. //
  213. // this.tabCountSqlNode = Element("div");
  214. // this.countSqlTabPageNode.inject(this.tabCountSqlNode);
  215. this.queryPage.showTabIm();
  216. if( ["auto", "ignore"].contains(this.json.countMethod) ){
  217. this.countPage.disableTab();
  218. }
  219. // this.queryPage.addEvent("postShow", function(){
  220. // if( this.view ){
  221. // this.view.setContentHeight();
  222. // this.view.selected();
  223. // }
  224. // }.bind(this));
  225. // this.countPage.addEvent("postShow", function(){
  226. // this.selected();
  227. // }.bind(this));
  228. },
  229. loadTab: function (callback) {
  230. var _self = this;
  231. MWF.require("MWF.widget.Tab", null, false);
  232. this.tab = new MWF.widget.Tab(this.tabNode, {"style": "script"});
  233. this.tab.load();
  234. this.tabRunNode = Element("div");
  235. this.pageRunNode = new Element("div", {
  236. "styles": {
  237. "overflow": "auto",
  238. "background-color": "#fff"
  239. }
  240. }).inject(this.tabRunNode);
  241. this.runArea.inject(this.pageRunNode);
  242. this.tabViewNode = Element("div", {"styles": {"height": "100%"}});
  243. this.pageViewNode = new Element("div.pageViewNode").inject(this.tabViewNode);
  244. this.viewArea.inject(this.pageViewNode);
  245. this.runPage = this.tab.addTab(this.tabRunNode, this.designer.lp.runTest);
  246. this.viewPage = this.tab.addTab(this.tabViewNode, this.designer.lp.view);
  247. this.runPage.showTabIm();
  248. this.viewPage.addEvent("postShow", function () {
  249. if (this.view) {
  250. //this.view.setContentHeight();
  251. this.view.setViewWidth();
  252. this.view.selected();
  253. }
  254. }.bind(this));
  255. this.runPage.addEvent("postShow", function () {
  256. this.selected();
  257. }.bind(this));
  258. if( this.options.viewEnable === false ){
  259. this.viewPage.disableTab();
  260. }
  261. },
  262. loadStatement: function () {
  263. //this.statementDesignerNode = new Element("div", {"styles": this.css.statementDesignerNode}).inject(this.areaNode);
  264. this.loadStatementHtml(function () {
  265. this.designerArea = this.areaNode.getElement(".o2_statement_statementDesignerNode");
  266. this.statementTabNode = this.areaNode.getElement(".o2_statement_statementTabNode");
  267. this.queryTabPageNode = this.areaNode.getElement(".o2_statement_statementQueryTabPageNode");
  268. this.jpqlArea = this.areaNode.getElement(".o2_statement_statementDesignerJpql");
  269. this.jpqlScriptArea = this.areaNode.getElement(".o2_statement_statementDesignerScript");
  270. this.jpqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerJpqlLine");
  271. this.sqlArea = this.areaNode.getElement(".o2_statement_statementDesignerSql");
  272. this.sqlScriptArea = this.areaNode.getElement(".o2_statement_statementDesignerSqlScript");
  273. this.sqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerSqlLine");
  274. this.countTabPageNode = this.areaNode.getElement(".o2_statement_statementCountTabPageNode");
  275. this.jpqlCountArea = this.areaNode.getElement(".o2_statement_statementDesignerCountJpql");
  276. this.jpqlCountScriptArea = this.areaNode.getElement(".o2_statement_statementDesignerCountScript");
  277. this.jpqlCountEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerCountJpqlLine");
  278. this.sqlCountArea = this.areaNode.getElement(".o2_statement_statementDesignerCountSql");
  279. this.sqlCountScriptArea = this.areaNode.getElement(".o2_statement_statementDesignerCountSqlScript");
  280. this.sqlCountEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerCountSqlLine");
  281. this.formatTypeArea = this.areaNode.getElement(".o2_statement_statementDesignerFormatContent");
  282. this.formatTypeArea.getElements("input").each(function (input) {
  283. input.set("name", input.get("name") + "_" +this.json.id);
  284. }.bind(this));
  285. this.entityCategorySelect = this.areaNode.getElement(".o2_statement_statementDesignerCategoryContent").getElement("select");
  286. this.dynamicTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_dynamic");
  287. this.officialTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_official");
  288. this.jpqlOfficalTable = this.areaNode.getElement(".o2_statement_statementDesignerOfficialTable_JPQL");
  289. this.sqlOfficalTable = this.areaNode.getElement(".o2_statement_statementDesignerOfficialTable_SQL");
  290. this.customTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_custom");
  291. this.dynamicTableSelect = this.areaNode.getElement(".o2_statement_statementDesignerSelectTable");
  292. this.officialTableSelectJPQL = this.jpqlOfficalTable.getElement("select");
  293. this.officialTableSelectSQL = this.sqlOfficalTable.getElement("select");
  294. this.fieldSelect = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_field").getElement("select");
  295. this.dynamicTableContent = this.areaNode.getElement(".o2_statement_statementDesignerTableContent");
  296. // this.statementTypeSelect = this.areaNode.getElement(".o2_statement_statementDesignerTypeContent").getElement("select");
  297. // this.loadStatementTypeSelect();
  298. this.countMethodSelect = this.areaNode.getElement(".o2_statement_statementDesignerCountMethodContent").getElement("select");
  299. this.loadCountMethodSelect();
  300. // this.jpqlSelectEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_select");
  301. // this.jpqlUpdateEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_update");
  302. // this.jpqlDeleteEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_sdelete");
  303. // this.jpqlSelectEditor_selectContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_selectContent");
  304. // this.jpqlSelectEditor_fromContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_fromContent");
  305. // this.jpqlSelectEditor_whereContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_whereContent");
  306. this.loadStatementTab();
  307. this.resizeNode = this.areaNode.getElement(".o2_statement_resizeNode");
  308. this.tabNode = this.areaNode.getElement(".o2_statement_tabNode");
  309. this.runArea = this.areaNode.getElement(".o2_statement_statementRunNode");
  310. // this.runTitleNode = this.areaNode.getElement(".o2_statement_statementRunTitleNode");
  311. this.runContentNode = this.areaNode.getElement(".o2_statement_statementRunContentNode");
  312. this.runJsonNode = this.runContentNode.getElement(".o2_statement_statementRunJsonNode");
  313. this.runFilterNode = this.runContentNode.getElement(".o2_statement_statementRunFilterNode");
  314. this.runPageNoInput = this.runContentNode.getElement(".o2_statement_statementRunPageNoInput");
  315. this.runPageSizeInput = this.runContentNode.getElement(".o2_statement_statementRunPageSizeInput");
  316. this.runActionNode = this.runContentNode.getElement(".o2_statement_statementRunActionNode");
  317. this.runResultNode = this.runContentNode.getElement(".o2_statement_statementRunResultNode");
  318. // this.runDefaultNode = this.runContentNode.getElement(".o2_statement_statementRunDefaultContent");
  319. this.setRunnerSize();
  320. this.designer.addEvent("resize", this.setRunnerSize.bind(this));
  321. debugger;
  322. this.loadFieldSelect();
  323. switch (this.json.format) {
  324. case "script":
  325. this.jpqlOfficalTable.show();
  326. this.sqlOfficalTable.hide();
  327. this.loadJpqlScriptEditor();
  328. this.loadJpqlCountScriptEditor();
  329. break;
  330. case "sql":
  331. this.jpqlOfficalTable.hide();
  332. this.sqlOfficalTable.show();
  333. this.loadSqlEditor();
  334. this.loadSqlCountEditor();
  335. break;
  336. case "sqlScript":
  337. this.jpqlOfficalTable.hide();
  338. this.sqlOfficalTable.show();
  339. this.loadSqlScriptEditor();
  340. this.loadSqlCountScriptEditor();
  341. break;
  342. default:
  343. this.jpqlOfficalTable.show();
  344. this.sqlOfficalTable.hide();
  345. this.loadJpqlEditor();
  346. this.loadJpqlCountEditor();
  347. }
  348. // this.loadDefaultCondition();
  349. this.loadStatementRunner();
  350. this.viewArea = this.areaNode.getElement(".o2_statement_viewNode");
  351. this.loadView();
  352. this.loadTab();
  353. if( this.json.table ){
  354. o2.Actions.load("x_query_assemble_designer").TableAction.get( this.json.table, function(json){
  355. this.json.tableObj = json.data;
  356. this.setDynamicTableName();
  357. }.bind(this), function(){
  358. return true;
  359. });
  360. }
  361. this.setEvent();
  362. this.loadVerticalResize();
  363. }.bind(this));
  364. },
  365. // loadDefaultCondition: function(){
  366. // var lp = ["currentPerson","currentIdentity","currentPersonDirectUnit","currentPersonAllUnit","currentPersonGroupList","currentPersonRoleList"];
  367. // ["person","identityList","unitList","unitAllList","groupList","roleList"].each(function (key, i) {
  368. // var div = new Element("div", {
  369. // style: "float:left;margin-right:10px;"
  370. // }).inject(this.runDefaultNode);
  371. // new Element("input", {
  372. // type: "checkbox",
  373. // value: "@"+key,
  374. // name: this.json.id + "defaultConditoin",
  375. // id: this.json.id + "defaultConditoin" + key
  376. // }).inject(div);
  377. // new Element("label", {
  378. // for: this.json.id + "defaultConditoin" + key,
  379. // text: this.designer.lp[lp[i]]
  380. // }).inject(div);
  381. // }.bind(this));
  382. // },
  383. loadCountMethodSelect: function(){
  384. this.countMethodSelect.getElements("option").each(function(o){
  385. if( this.json.countMethod === o.value ){
  386. o.selected = true;
  387. }
  388. }.bind(this));
  389. },
  390. // loadStatementTypeSelect : function(){
  391. // this.statementTypeSelect.empty();
  392. // var optionList = [{text:"SELECT", value:"select"}];
  393. // if( this.data.entityCategory === "dynamic" || (this.data.description && this.data.description.indexOf("update")>-1)){
  394. // optionList = optionList.concat([
  395. // {text:"UPDATE", value:"update"},
  396. // {text:"DELETE", value:"delete"}
  397. // ])
  398. // }
  399. //
  400. // var flag = true;
  401. // optionList.each( function ( field ) {
  402. // var option = new Element("option", {
  403. // "text": field.text,
  404. // "value": field.value
  405. // }).inject(this.statementTypeSelect);
  406. // if( this.json.type === field.value ){
  407. // flag = false;
  408. // option.selected = true;
  409. // }
  410. // }.bind(this));
  411. // if( flag ){
  412. // this.statementTypeSelect.options[0].selected = true;
  413. // this.json.type = this.statementTypeSelect.options[0].value;
  414. // }
  415. // },
  416. loadFieldSelect : function(){
  417. this.fieldSelect.empty();
  418. var d = this.data;
  419. var className = d.entityCategory === "dynamic" ? d.table : d.entityClassName;
  420. if( !className )return;
  421. var pre = ["sql", "sqlScript"].contains(d.format) ? "x" : "";
  422. o2.Actions.load("x_query_assemble_designer").QueryAction.getEntityProperties(
  423. className,
  424. d.entityCategory,
  425. function(json){
  426. json = Object.clone(json);
  427. var option = new Element("option", { "text": this.designer.lp.fileldSelectNote, "value": "" }).inject(this.fieldSelect);
  428. option.store("type", d.entityCategory);
  429. option.store("tableName", className );
  430. (json.data||[]).each( function ( field ) {
  431. if( pre )field.name = pre + field.name;
  432. var option = new Element("option", {
  433. "text": field.name + ( field.description ? ("-" + field.description) : "" ),
  434. "value": field.name
  435. }).inject(this.fieldSelect);
  436. option.store("field", field);
  437. option.store("type", d.entityCategory );
  438. option.store("tableName", className );
  439. }.bind(this));
  440. }.bind(this)
  441. )
  442. },
  443. loadVerticalResize: function(){
  444. this.verticalResize = new Drag(this.resizeNode, {
  445. "snap": 10,
  446. "onStart": function(el, e){
  447. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  448. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  449. el.store("position", {"x": x, "y": y});
  450. var size = this.designerArea.getSize(); //designerArea
  451. el.store("initialHeight", size.y);
  452. var allSize = this.areaNode.getSize();
  453. el.store("initialAllHeight", allSize.y);
  454. }.bind(this),
  455. "onDrag": function(el, e){
  456. var allHeight = el.retrieve("initialAllHeight").toFloat(); //this.areaNode.getSize();
  457. // var x = e.event.x;
  458. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  459. var position = el.retrieve("position");
  460. var dy = y.toFloat()-position.y.toFloat();
  461. var initialHeight = el.retrieve("initialHeight").toFloat();
  462. var height = initialHeight+dy;
  463. if (height < 180) height = 180;
  464. if (height > allHeight-180) height = allHeight-180;
  465. this.designerAreaPercent = height/allHeight;
  466. this.setVerticalResize();
  467. }.bind(this)
  468. });
  469. },
  470. setVerticalResize: function(){
  471. var size = this.areaNode.getSize();
  472. var height = size.y;
  473. var designAreaHeight = this.designerAreaPercent*height - 52;
  474. // var runAreaHeight = height-designAreaHeight;
  475. this.designerArea.setStyle("height", ""+designAreaHeight+"px");
  476. var editorHeight = designAreaHeight - 98;
  477. if(this.jpqlEditorNode)this.jpqlEditorNode.setStyle( "height", ""+editorHeight+"px" );
  478. if(this.jpqlCountEditorNode)this.jpqlCountEditorNode.setStyle( "height", ""+editorHeight+"px" );
  479. if(this.jpqlScriptArea)this.jpqlScriptArea.setStyle( "height", ""+editorHeight+"px" );
  480. if(this.jpqlCountScriptArea)this.jpqlCountScriptArea.setStyle( "height", ""+editorHeight+"px" );
  481. if(this.sqlEditorNode)this.sqlEditorNode.setStyle( "height", ""+editorHeight+"px" );
  482. if(this.sqlCountEditorNode)this.sqlCountEditorNode.setStyle( "height", ""+editorHeight+"px" );
  483. if(this.sqlScriptArea)this.sqlScriptArea.setStyle( "height", ""+editorHeight+"px" );
  484. if(this.sqlCountScriptArea)this.sqlCountScriptArea.setStyle( "height", ""+editorHeight+"px" );
  485. if( this.jpqlEditor )this.jpqlEditor.resize();
  486. if( this.jpqlCountEditor )this.jpqlCountEditor.resize();
  487. if( this.jpqlScriptEditor ){
  488. this.jpqlScriptEditor.container.setStyle("height", ""+editorHeight+"px");
  489. this.jpqlScriptEditor.resizeContentNodeSize();
  490. }
  491. if( this.jpqlCountScriptEditor ){
  492. this.jpqlCountScriptEditor.container.setStyle("height", ""+editorHeight+"px");
  493. this.jpqlCountScriptEditor.resizeContentNodeSize();
  494. }
  495. if( this.sqlEditor )this.sqlEditor.resize();
  496. if( this.sqlCountEditor )this.sqlCountEditor.resize();
  497. if( this.sqlScriptEditor ){
  498. this.sqlScriptEditor.container.setStyle("height", ""+editorHeight+"px");
  499. this.sqlScriptEditor.resizeContentNodeSize();
  500. }
  501. if( this.sqlCountScriptEditor ){
  502. this.sqlCountScriptEditor.container.setStyle("height", ""+editorHeight+"px");
  503. this.sqlCountScriptEditor.resizeContentNodeSize();
  504. }
  505. // this.tabNode.setStyle("height", ""+runAreaHeight+"px");
  506. this.setRunnerSize();
  507. if( this.view ){
  508. this.setViewSize();
  509. this.view.setContentHeight()
  510. }
  511. },
  512. getEditorHeight: function(){
  513. var size = this.areaNode.getSize();
  514. var height = size.y;
  515. var designAreaHeight = this.designerAreaPercent*height - 52;
  516. return designAreaHeight - 98;
  517. },
  518. setRunnerSize: function () {
  519. debugger;
  520. var size = this.areaNode.getSize();
  521. var designerSize = this.designerArea.getComputedSize();
  522. var reizeNodeSize = this.resizeNode.getComputedSize();
  523. var y = size.y - designerSize.totalHeight - reizeNodeSize.totalHeight;
  524. var mTop = this.runArea.getStyle("margin-top").toInt();
  525. var mBottom = this.runArea.getStyle("margin-bottom").toInt();
  526. var pTop = this.runArea.getStyle("padding-top").toInt();
  527. var pBottom = this.runArea.getStyle("padding-bottom").toInt();
  528. y = y - mTop - mBottom - pTop - pBottom - 5;
  529. var tabSize = this.tabNode.getComputedSize();
  530. y = y - tabSize.totalHeight;
  531. this.runArea.setStyle("height", "" + y + "px");
  532. // var titleSize = this.runTitleNode.getComputedSize();
  533. // y = y - titleSize.totalHeight;
  534. this.runContentNode.setStyle("height", "" + y + "px");
  535. },
  536. loadJpqlEditor: function () {
  537. if (!this.jpqlEditor) {
  538. var value;
  539. if( !this.json.data ){
  540. var table = "table";
  541. // switch (this.json.type) {
  542. // case "update":
  543. // value = "UPDATE " + table + " o SET ";
  544. // break;
  545. // case "delete":
  546. // value = "DELETE " + table + " o WHERE ";
  547. // break;
  548. // default:
  549. value = "SELECT o FROM " + table + " o";
  550. // }
  551. this.json.data = value;
  552. }
  553. if( this.jpqlEditorNode.offsetParent === null && o2.editorData.javascriptEditor.editor === "monaco" ){
  554. var postShowFun = function() {
  555. this._loadJpqlEditor();
  556. this.queryPage.removeEvent("postShow", postShowFun);
  557. }.bind(this);
  558. this.queryPage.addEvent("postShow", postShowFun);
  559. }else{
  560. this._loadJpqlEditor();
  561. }
  562. }else{
  563. this.jpqlEditor.resize();
  564. }
  565. },
  566. _loadJpqlEditor: function () {
  567. if (!this.jpqlEditor) {
  568. o2.require("o2.widget.JavascriptEditor", function () {
  569. this.jpqlEditor = new o2.widget.JavascriptEditor(this.jpqlEditorNode, {
  570. "title": "JPQL",
  571. "option": {"mode": "sql"}
  572. });
  573. this.jpqlEditor.load(function () {
  574. this.jpqlEditor.editor.setValue(this.json.data);
  575. this.jpqlEditor.addEditorEvent("change", function () {
  576. this.data.data = this.jpqlEditor.getValue();
  577. // this.checkStatementType();
  578. }.bind(this));
  579. }.bind(this));
  580. }.bind(this), false);
  581. }
  582. },
  583. loadJpqlCountEditor: function () {
  584. if (!this.jpqlCountEditor) {
  585. if( !this.json.countData )this.json.countData = "SELECT count(o.id) FROM table o";
  586. if( this.jpqlCountEditorNode.offsetParent === null && o2.editorData.javascriptEditor.editor === "monaco" ){
  587. var postShowFun = function() {
  588. this._loadJpqlCountEditor();
  589. this.countPage.removeEvent("postShow", postShowFun);
  590. }.bind(this);
  591. this.countPage.addEvent("postShow", postShowFun);
  592. }else{
  593. this._loadJpqlCountEditor();
  594. }
  595. }else{
  596. this.jpqlCountEditor.resize();
  597. }
  598. },
  599. _loadJpqlCountEditor : function(){
  600. o2.require("o2.widget.JavascriptEditor", function () {
  601. this.jpqlCountEditor = new o2.widget.JavascriptEditor(this.jpqlCountEditorNode, {
  602. "title": "JPQL",
  603. "option": {"mode": "sql"}
  604. });
  605. this.jpqlCountEditor.load(function () {
  606. this.jpqlCountEditor.editor.setValue(this.json.countData);
  607. this.jpqlCountEditor.addEditorEvent("change", function () {
  608. this.data.countData = this.jpqlCountEditor.getValue();
  609. }.bind(this));
  610. }.bind(this));
  611. }.bind(this), false);
  612. },
  613. loadSqlEditor: function () {
  614. if (!this.sqlEditor) {
  615. var value;
  616. if( !this.json.sql ){
  617. var table = "table";
  618. // switch (this.json.type) {
  619. // case "update":
  620. // value = "UPDATE " + table + " SET ";
  621. // break;
  622. // case "delete":
  623. // value = "DELETE FROM " + table + " WHERE ";
  624. // break;
  625. // default:
  626. value = "SELECT * FROM " + table + "";
  627. // }
  628. this.json.sql = value;
  629. }
  630. if( this.sqlEditorNode.offsetParent === null && o2.editorData.javascriptEditor.editor === "monaco" ){
  631. var postShowFun = function() {
  632. this._loadSqlEditor();
  633. this.queryPage.removeEvent("postShow", postShowFun);
  634. }.bind(this);
  635. this.queryPage.addEvent("postShow", postShowFun);
  636. }else{
  637. this._loadSqlEditor();
  638. }
  639. }else{
  640. this.sqlEditor.resize();
  641. }
  642. },
  643. _loadSqlEditor: function () {
  644. if (!this.sqlEditor) {
  645. o2.require("o2.widget.JavascriptEditor", function () {
  646. this.sqlEditor = new o2.widget.JavascriptEditor(this.sqlEditorNode, {
  647. "title": "SQL",
  648. "option": {"mode": "sql"}
  649. });
  650. this.sqlEditor.load(function () {
  651. this.sqlEditor.editor.setValue(this.json.sql);
  652. this.sqlEditor.addEditorEvent("change", function () {
  653. this.data.sql = this.sqlEditor.getValue();
  654. // this.checkStatementType();
  655. }.bind(this));
  656. }.bind(this));
  657. }.bind(this), false);
  658. }
  659. },
  660. loadSqlCountEditor: function () {
  661. if (!this.sqlCountEditor) {
  662. if( !this.json.sqlCount )this.json.sqlCount = "SELECT count(id) FROM table";
  663. if( this.sqlCountEditorNode.offsetParent === null && o2.editorData.javascriptEditor.editor === "monaco" ){
  664. var postShowFun = function() {
  665. this._loadSqlCountEditor();
  666. this.countPage.removeEvent("postShow", postShowFun);
  667. }.bind(this);
  668. this.countPage.addEvent("postShow", postShowFun);
  669. }else{
  670. this._loadSqlCountEditor();
  671. }
  672. }else{
  673. // this.sqlCountEditorNode.setStyle( "height", ""+editorHeight+"px" );
  674. this.sqlCountEditor.resize();
  675. }
  676. },
  677. _loadSqlCountEditor : function(){
  678. if (!this.sqlCountEditor) {
  679. o2.require("o2.widget.JavascriptEditor", function () {
  680. this.sqlCountEditor = new o2.widget.JavascriptEditor(this.sqlCountEditorNode, {
  681. "title": "SQL",
  682. "option": {"mode": "sql"}
  683. });
  684. this.sqlCountEditor.load(function () {
  685. this.sqlCountEditor.editor.setValue(this.json.sqlCount);
  686. this.sqlCountEditor.addEditorEvent("change", function () {
  687. this.data.sqlCount = this.sqlCountEditor.getValue();
  688. }.bind(this));
  689. }.bind(this));
  690. }.bind(this), false);
  691. }
  692. },
  693. loadJpqlScriptEditor: function () {
  694. if (!this.jpqlScriptEditor) {
  695. debugger;
  696. o2.require("o2.widget.ScriptArea", function () {
  697. this.jpqlScriptEditor = new o2.widget.ScriptArea(this.jpqlScriptArea, {
  698. "isbind": false,
  699. "api": "../api/server.service.module_parameters.html#server.service.module_parameters",
  700. "maxObj": this.designer.designNode,
  701. "title": this.designer.lp.scriptTitle,
  702. "type": "service",
  703. "onChange": function () {
  704. this.json.scriptText = this.jpqlScriptEditor.toJson().code;
  705. }.bind(this),
  706. "onSave": function () {
  707. this.designer.saveStatement();
  708. }.bind(this)
  709. });
  710. this.jpqlScriptEditor.load({"code": this.json.scriptText})
  711. }.bind(this), false);
  712. }
  713. },
  714. loadJpqlCountScriptEditor: function () {
  715. if (!this.jpqlCountScriptEditor) {
  716. debugger;
  717. o2.require("o2.widget.ScriptArea", function () {
  718. this.jpqlCountScriptEditor = new o2.widget.ScriptArea(this.jpqlCountScriptArea, {
  719. "isbind": false,
  720. "api": "../api/server.service.module_parameters.html#server.service.module_parameters",
  721. "maxObj": this.designer.designNode,
  722. "title": this.designer.lp.scriptTitle,
  723. "type": "service",
  724. "onChange": function () {
  725. this.json.countScriptText = this.jpqlCountScriptEditor.toJson().code;
  726. }.bind(this),
  727. "onSave": function () {
  728. this.designer.saveStatement();
  729. }.bind(this)
  730. });
  731. this.jpqlCountScriptEditor.load({"code": this.json.countScriptText})
  732. }.bind(this), false);
  733. }
  734. },
  735. loadSqlScriptEditor: function () {
  736. if (!this.sqlScriptEditor) {
  737. debugger;
  738. o2.require("o2.widget.ScriptArea", function () {
  739. this.sqlScriptEditor = new o2.widget.ScriptArea(this.sqlScriptArea, {
  740. "isbind": false,
  741. "api": "../api/server.service.module_parameters.html#server.service.module_parameters",
  742. "maxObj": this.designer.designNode,
  743. "title": this.designer.lp.sqlScriptTitle,
  744. "type": "service",
  745. "onChange": function () {
  746. this.json.sqlScriptText = this.sqlScriptEditor.toJson().code;
  747. }.bind(this),
  748. "onSave": function () {
  749. this.designer.saveStatement();
  750. }.bind(this)
  751. });
  752. this.sqlScriptEditor.load({"code": this.json.sqlScriptText})
  753. }.bind(this), false);
  754. }
  755. },
  756. loadSqlCountScriptEditor: function () {
  757. if (!this.sqlCountScriptEditor) {
  758. o2.require("o2.widget.ScriptArea", function () {
  759. this.sqlCountScriptEditor = new o2.widget.ScriptArea(this.sqlCountScriptArea, {
  760. "isbind": false,
  761. "api": "../api/server.service.module_parameters.html#server.service.module_parameters",
  762. "maxObj": this.designer.designNode,
  763. "title": this.designer.lp.sqlScriptTitle,
  764. "type": "service",
  765. "onChange": function () {
  766. this.json.sqlCountScriptText = this.sqlCountScriptEditor.toJson().code;
  767. }.bind(this),
  768. "onSave": function () {
  769. this.designer.saveStatement();
  770. }.bind(this)
  771. });
  772. this.sqlCountScriptEditor.load({"code": this.json.sqlCountScriptText})
  773. }.bind(this), false);
  774. }
  775. },
  776. // setSatementTable: function () {
  777. // if (!this.json.type) this.json.type = "select";
  778. // this.changeType(this.json.type, true);
  779. // },
  780. // checkStatementType: function () {
  781. // var str = this.json.data;
  782. // this.json.data = str;
  783. // var jpql_select = /^select/i;
  784. // var jpql_update = /^update/i;
  785. // var jpql_delete = /^delete/i;
  786. // if (jpql_select.test(str)) return this.changeType("select");
  787. // if (jpql_update.test(str)) return this.changeType("update");
  788. // if (jpql_delete.test(str)) return this.changeType("delete");
  789. // },
  790. // changeType: function (type, force) {
  791. // if (this.json.type != type) this.json.type = type;
  792. // if (type != this.statementTypeSelect.options[this.statementTypeSelect.selectedIndex].value || force) {
  793. // for (var i = 0; i < this.statementTypeSelect.options.length; i++) {
  794. // if (this.statementTypeSelect.options[i].value == type) {
  795. // this.statementTypeSelect.options[i].set("selected", true);
  796. // break;
  797. // }
  798. // }
  799. // }
  800. // },
  801. loadStatementHtml: function (callback) {
  802. this.areaNode.loadAll({
  803. "css": this.path + this.options.style + "/statement.css",
  804. "html": this.path + "statementDesigner.html"
  805. }, {
  806. "bind": {"lp": this.designer.lp, "data": this.data},
  807. "module": this
  808. }, function () {
  809. if (callback) callback();
  810. }.bind(this));
  811. },
  812. addFilterSample: function(){
  813. var filterList = this.filterListEditor.editor.getValue() || [];
  814. try{
  815. filterList = JSON.parse( filterList );
  816. }catch (e) {
  817. filterList = [];
  818. }
  819. filterList.push({
  820. "path": ["sql", "sqlScript"].contains(this.json.format) ? "xtitle" : "o.title",
  821. "comparison":"like",
  822. "value": ["sql", "sqlScript"].contains(this.json.format) ? "xtitle" : "o_title",
  823. "formatType":"textValue"
  824. });
  825. this.filterListEditor.editor.setValue( JSON.stringify(filterList, null, 4) );
  826. var parameter = this.jsonEditor.editor.getValue() || {};
  827. try{
  828. parameter = JSON.parse( parameter );
  829. }catch (e) {
  830. parameter = {};
  831. }
  832. parameter[ ["sql", "sqlScript"].contains(this.json.format) ? "xtitle" : "o_title" ] = "%关于%";
  833. this.jsonEditor.editor.setValue( JSON.stringify(parameter, null, 4) );
  834. },
  835. loadStatementRunner: function () {
  836. o2.require("o2.widget.JavascriptEditor", function () {
  837. this.jsonEditor = new o2.widget.JavascriptEditor(this.runJsonNode, {
  838. "title": "parameter",
  839. "option": {"mode": "json"}
  840. });
  841. this.jsonEditor.load(function () {
  842. debugger;
  843. var json = JSON.parse( this.data.testParameters || "{}" );
  844. if( json.parameter )json = json.parameter;
  845. this.jsonEditor.editor.setValue( JSON.stringify(json, null, 4) );
  846. }.bind(this));
  847. this.filterListEditor = new o2.widget.JavascriptEditor(this.runFilterNode, {
  848. "title": "filterList",
  849. "option": {"mode": "json"}
  850. });
  851. this.filterListEditor.load(function () {
  852. var json = JSON.parse( this.data.testParameters || "{}" );
  853. json = json.filterList || [];
  854. this.filterListEditor.editor.setValue( JSON.stringify(json, null, 4) );
  855. }.bind(this));
  856. }.bind(this), false);
  857. },
  858. getSQLTableByEntity: function(entityClassName){
  859. switch (entityClassName) {
  860. case "com.x.processplatform.core.entity.content.Task":
  861. return "PP_C_TASK";
  862. case "com.x.processplatform.core.entity.content.TaskCompleted":
  863. return "PP_C_TASKCOMPLETED";
  864. case "com.x.processplatform.core.entity.content.Read":
  865. return "PP_C_READ";
  866. case "com.x.processplatform.core.entity.content.ReadCompleted":
  867. return "PP_C_READCOMPLETED";
  868. case "com.x.processplatform.core.entity.content.Work":
  869. return "PP_C_WORK";
  870. case "com.x.processplatform.core.entity.content.WorkCompleted":
  871. return "PP_C_WORKCOMPLETED";
  872. case "com.x.processplatform.core.entity.content.Review":
  873. return "PP_C_REVIEW";
  874. case "com.x.cms.core.entity.Document":
  875. return "CMS_DOCUMENT";
  876. case "com.x.cms.core.entity.Review":
  877. return "CMS_REVIEW";
  878. case "com.x.cms.core.entity.DocumentViewRecord":
  879. return "CMS_DOCUMENT_VIEWRECORD";
  880. case "com.x.cms.core.entity.DocumentCommentInfo":
  881. return "CMS_DOCUMENT_COMMENTINFO";
  882. }
  883. },
  884. setDynamicTableName: function(){
  885. var name = this.json.tableObj && this.json.tableObj.name;
  886. if( name ){
  887. if( ["sql", "sqlScript"].contains(this.json.format) ){
  888. name = "QRY_DYN_" + name.toUpperCase();
  889. }
  890. this.dynamicTableContent.set("text", name);
  891. }else{
  892. this.dynamicTableContent.set("text", "");
  893. }
  894. },
  895. loadEditor: function(){
  896. switch (this.json.format) {
  897. case "sql":
  898. this.jpqlOfficalTable.hide();
  899. this.sqlOfficalTable.show();
  900. this.jpqlArea.hide();
  901. this.jpqlScriptArea.hide();
  902. this.sqlArea.show();
  903. this.sqlScriptArea.hide();
  904. this.loadSqlEditor();
  905. this.jpqlCountArea.hide();
  906. this.jpqlCountScriptArea.hide();
  907. this.sqlCountArea.show();
  908. this.sqlCountScriptArea.hide();
  909. this.loadSqlCountEditor();
  910. break;
  911. case "sqlScript":
  912. this.jpqlOfficalTable.hide();
  913. this.sqlOfficalTable.show();
  914. this.jpqlArea.hide();
  915. this.jpqlScriptArea.hide();
  916. this.sqlArea.hide();
  917. this.sqlScriptArea.show();
  918. this.loadSqlScriptEditor();
  919. this.jpqlCountArea.hide();
  920. this.jpqlCountScriptArea.hide();
  921. this.sqlCountArea.hide();
  922. this.sqlCountScriptArea.show();
  923. this.loadSqlCountScriptEditor();
  924. break;
  925. case "script":
  926. this.jpqlOfficalTable.show();
  927. this.sqlOfficalTable.hide();
  928. this.jpqlArea.hide();
  929. this.jpqlScriptArea.show();
  930. this.sqlArea.hide();
  931. this.sqlScriptArea.hide();
  932. this.loadJpqlScriptEditor();
  933. this.jpqlCountArea.hide();
  934. this.jpqlCountScriptArea.show();
  935. this.sqlCountArea.hide();
  936. this.sqlCountScriptArea.hide();
  937. this.loadJpqlCountScriptEditor();
  938. break;
  939. default:
  940. this.jpqlOfficalTable.show();
  941. this.sqlOfficalTable.hide();
  942. this.jpqlArea.show();
  943. this.jpqlScriptArea.hide();
  944. this.sqlArea.hide();
  945. this.sqlScriptArea.hide();
  946. this.loadJpqlEditor();
  947. this.jpqlCountArea.show();
  948. this.jpqlCountScriptArea.hide();
  949. this.sqlCountArea.hide();
  950. this.sqlCountScriptArea.hide();
  951. this.loadJpqlCountEditor();
  952. }
  953. },
  954. setEvent: function () {
  955. this.designerArea.addEvent("click", function (e) {
  956. this.selected();
  957. e.stopPropagation();
  958. }.bind(this));
  959. this.formatTypeArea.getElements("input").addEvent("click", function (e) {
  960. debugger;
  961. if (e.target.checked) {
  962. var v = e.target.get("value");
  963. this.json.format = v;
  964. this.loadEditor();
  965. this.setDynamicTableName();
  966. }
  967. this.loadFieldSelect();
  968. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.changeStatementType();
  969. this.checkViewFilter();
  970. }.bind(this));
  971. this.entityCategorySelect.addEvent("change", function (e) {
  972. var entityCategory = e.target.options[e.target.selectedIndex].value;
  973. switch (entityCategory) {
  974. case "dynamic":
  975. this.officialTableArea.hide();
  976. this.dynamicTableArea.show();
  977. this.customTableArea.hide();
  978. break;
  979. case "custom":
  980. this.officialTableArea.hide();
  981. this.dynamicTableArea.hide();
  982. this.customTableArea.show();
  983. break;
  984. default:
  985. this.officialTableArea.show();
  986. this.dynamicTableArea.hide();
  987. this.customTableArea.hide();
  988. break;
  989. }
  990. this.json.entityCategory = entityCategory;
  991. // this.loadStatementTypeSelect();
  992. this.loadFieldSelect();
  993. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  994. }.bind(this));
  995. //@todo change table
  996. this.officialTableSelectJPQL.addEvent("change", function (e) {
  997. debugger;
  998. var entityClassName = e.target.options[e.target.selectedIndex].value;
  999. this.json.entityClassName = entityClassName;
  1000. if( entityClassName ){
  1001. this.changeEditorEntityClassName( entityClassName.split(".").getLast() );
  1002. }
  1003. this.loadFieldSelect();
  1004. this.json.table = "";
  1005. this.json.tableObj = null;
  1006. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  1007. }.bind(this));
  1008. this.officialTableSelectSQL.addEvent("change", function (e) {
  1009. debugger;
  1010. var entityClassName = e.target.options[e.target.selectedIndex].value;
  1011. this.json.entityClassName = entityClassName;
  1012. if( entityClassName ){
  1013. this.changeEditorEntityClassName( this.getSQLTableByEntity(entityClassName) );
  1014. }
  1015. this.loadFieldSelect();
  1016. this.json.table = "";
  1017. this.json.tableObj = null;
  1018. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  1019. }.bind(this));
  1020. this.runActionNode.getFirst().addEvent("click", this.runStatement.bind(this));
  1021. this.dynamicTableSelect.addEvent("click", this.selectTable.bind(this));
  1022. // this.statementTypeSelect.addEvent("change", function () {
  1023. // var t = this.statementTypeSelect.options[this.statementTypeSelect.selectedIndex].value;
  1024. // if (t != this.json.type) {
  1025. // this.json.type = t;
  1026. // }
  1027. // if (t !== "select") {
  1028. // this.queryPage.showTabIm();
  1029. // this.countPage.disableTab();
  1030. //
  1031. // this.runPage.showTabIm();
  1032. // this.viewPage.disableTab();
  1033. // } else {
  1034. // if( this.json.countMethod === "assign" )this.countPage.enableTab(true);
  1035. // this.viewPage.enableTab(true);
  1036. // }
  1037. // }.bind(this));
  1038. this.countMethodSelect.addEvent("change", function () {
  1039. this.json.countMethod = this.countMethodSelect.options[this.countMethodSelect.selectedIndex].value;
  1040. switch (this.json.countMethod) {
  1041. case "auto":
  1042. case "ignore":
  1043. // if (this.json.type === "select") {
  1044. this.queryPage.showTabIm();
  1045. this.countPage.disableTab();
  1046. // }
  1047. break;
  1048. // case "assign":
  1049. // break;
  1050. default:
  1051. // if (this.json.type === "select") {
  1052. this.countPage.enableTab();
  1053. // }
  1054. break;
  1055. }
  1056. this.loadEditor();
  1057. }.bind(this));
  1058. this.fieldSelect.addEvent("change", function (ev) {
  1059. var option = ev.target.options[ev.target.selectedIndex];
  1060. var type = option.retrieve("type");
  1061. var field = option.retrieve("field");
  1062. if( !field )return;
  1063. var text = field.name;
  1064. if( this.countPage && this.countPage.isShow && !this.countPage.disabled ) {
  1065. if (this.data.format === "script" && this.jpqlCountScriptEditor.jsEditor) {
  1066. this.jpqlCountScriptEditor.jsEditor.insertValue(text);
  1067. } else if (this.data.format === "sqlScript" && this.sqlCountScriptEditor.jsEditor) {
  1068. this.sqlCountScriptEditor.jsEditor.insertValue(text);
  1069. } else if (this.data.format === "sql" && this.sqlCountEditor) {
  1070. this.sqlCountEditor.insertValue(text);
  1071. } else if (this.jpqlCountEditor) {
  1072. this.jpqlCountEditor.insertValue(text);
  1073. }
  1074. }else{
  1075. if( this.data.format === "script" && this.jpqlScriptEditor.jsEditor ){
  1076. this.jpqlScriptEditor.jsEditor.insertValue( text );
  1077. }else if( this.data.format === "sqlScript" && this.sqlScriptEditor.jsEditor ){
  1078. this.sqlScriptEditor.jsEditor.insertValue( text );
  1079. }else if( this.data.format === "sql" && this.sqlEditor ){
  1080. this.sqlEditor.insertValue( text );
  1081. }else if( this.jpqlEditor ) {
  1082. this.jpqlEditor.insertValue(text);
  1083. }
  1084. }
  1085. }.bind(this));
  1086. },
  1087. changeEditorEntityClassName : function( entityClassName ){
  1088. debugger;
  1089. var re, v, replaceClassName;
  1090. if (this.json.format === "jpql") {
  1091. replaceClassName = function (re, v) {
  1092. if( !re )re = /(.*from\s*)/ig;
  1093. //var re2 = /(\s+)/ig;
  1094. var arr = re.exec(v);
  1095. if (arr && arr[0]) {
  1096. var left = arr[0];
  1097. v = v.substring(left.length, v.length);
  1098. //var ar = re2.exec(v);
  1099. var right = v.substring(v.indexOf(" "), v.length);
  1100. return left + entityClassName + right;
  1101. }
  1102. return "";
  1103. };
  1104. if (this.jpqlEditor) {
  1105. // if (this.json.type === "update") re = /(.*update\s*)/ig;
  1106. v = replaceClassName( re, this.json.data);
  1107. if (v) {
  1108. this.json.data = v;
  1109. this.jpqlEditor.editor.setValue(this.json.data);
  1110. }
  1111. }
  1112. if( this.jpqlCountEditor ){
  1113. v = replaceClassName( re, this.json.countData);
  1114. if (v) {
  1115. this.json.countData = v;
  1116. this.jpqlCountEditor.editor.setValue(this.json.countData);
  1117. }
  1118. }
  1119. }else if (this.json.format === "sql") {
  1120. replaceClassName = function (re, v) {
  1121. if( !re )re = /(.*from\s*)/ig;
  1122. //var re2 = /(\s+)/ig;
  1123. var arr = re.exec(v);
  1124. if (arr && arr[0]) {
  1125. var left = arr[0];
  1126. v = v.substring(left.length, v.length);
  1127. //var ar = re2.exec(v);
  1128. var right;
  1129. if( v.indexOf(" ") > -1 ){
  1130. right = v.substring(v.indexOf(" "), v.length);
  1131. }else{
  1132. right = "";
  1133. }
  1134. return left + entityClassName + right;
  1135. }
  1136. return "";
  1137. };
  1138. if (this.sqlEditor) {
  1139. // if (this.json.type === "update") re = /(.*update\s*)/ig;
  1140. v = replaceClassName( re, this.json.sql);
  1141. if (v) {
  1142. this.json.sql = v;
  1143. this.sqlEditor.editor.setValue(this.json.sql);
  1144. }
  1145. }
  1146. if( this.sqlCountEditor ){
  1147. v = replaceClassName( re, this.json.sqlCount);
  1148. if (v) {
  1149. this.json.sqlCount = v;
  1150. this.sqlCountEditor.editor.setValue(this.json.sqlCount);
  1151. }
  1152. }
  1153. }
  1154. },
  1155. selectTable: function () {
  1156. new MWF.O2Selector(this.designer.content, {
  1157. "type": "queryTable",
  1158. "count": 1,
  1159. "values": (this.json.table) ? [this.json.table] : [],
  1160. "title": this.designer.lp.selectTable,
  1161. "onComplete": function (items) {
  1162. if (items.length) {
  1163. var id = items[0].data.id;
  1164. var name = items[0].data.name;
  1165. this.json.table = name;
  1166. this.json.tableObj = items[0].data;
  1167. if( name ){
  1168. this.json.tableObj.nativeTableName = "QRY_DYN_" + name.toUpperCase();
  1169. }
  1170. this.officialTableSelectJPQL.options[0].set("selected", true);
  1171. this.officialTableSelectSQL.options[0].set("selected", true);
  1172. this.json.entityClassName = "";
  1173. if( name && ["sql", "sqlScript"].contains(this.json.format) ){
  1174. name = "QRY_DYN_" + name.toUpperCase();
  1175. }
  1176. this.dynamicTableContent.set("text", name);
  1177. this.changeEditorEntityClassName( name );
  1178. this.loadFieldSelect();
  1179. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  1180. } else {
  1181. this.dynamicTableContent.set("text", "");
  1182. this.json.table = "";
  1183. this.loadFieldSelect();
  1184. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  1185. }
  1186. }.bind(this)
  1187. });
  1188. },
  1189. runStatement: function () {
  1190. // if (!this.json.data){
  1191. // this.designer.notice(this.designer.lp.inputStatementData, "error");
  1192. // return false;
  1193. // }
  1194. // o2.require("o2.widget.Mask", null, false);
  1195. // this.runMask = new o2.widget.Mask();
  1196. // this.runMask.loadNode(this.node);
  1197. this.saveSilence(function () {
  1198. this.execute(function (json) {
  1199. this.executeData = json;
  1200. o2.require("o2.widget.JsonParse", function () {
  1201. this.runResultNode.empty();
  1202. var jsonResult = new o2.widget.JsonParse(json, this.runResultNode);
  1203. jsonResult.load();
  1204. }.bind(this));
  1205. if (this.view) {
  1206. var flag = true;
  1207. // if (this.data.type !== "select") flag = false;
  1208. if( this.data.viewEnable === false )flag = false;
  1209. if (this.data.format === "script" && !this.data.scriptText) flag = false;
  1210. if (this.data.format === "jpql" && !this.data.data) flag = false;
  1211. if (this.data.format === "sql" && !this.data.sql) flag = false;
  1212. if (this.data.format === "sqlScript" && !this.data.sqlScriptText) flag = false;
  1213. if (flag) this.view.loadViewData();
  1214. }
  1215. this.setColumnDataPath(json);
  1216. // this.runMask.hide();
  1217. }.bind(this), function () {
  1218. // if (this.runMask) this.runMask.hide();
  1219. }.bind(this));
  1220. }.bind(this));
  1221. },
  1222. setColumnDataPath: function (json) {
  1223. // if (this.data.type !== "select") return;
  1224. if (this.data.format === "script" && !this.data.scriptText) return;
  1225. if (this.data.format === "jpql" && !this.data.data) return;
  1226. if (this.data.format === "sql" && !this.data.sql) return;
  1227. if (this.data.format === "sqlScript" && !this.data.sqlScriptText) return;
  1228. this.columnDataPathList = [];
  1229. debugger;
  1230. var addPath = function (value, key) {
  1231. if (typeOf(value) === "array") {
  1232. Array.each(value, function (v, idx) {
  1233. var path = (key || typeOf(key) === "number") ? (key + "." + idx) : idx.toString();
  1234. if (!this.columnDataPathList.contains(path)) this.columnDataPathList.push(path);
  1235. if (typeOf(v) === "array" || typeOf(v) === "object") addPath(v, path);
  1236. }.bind(this))
  1237. } else if (typeOf(value) === "object") {
  1238. Object.each(value, function (v, k) {
  1239. var path = (key || typeOf(key) === "number") ? (key + "." + k) : k;
  1240. if (!this.columnDataPathList.contains(path)) this.columnDataPathList.push(path);
  1241. if (typeOf(v) === "array" || typeOf(v) === "object") addPath(v, path);
  1242. addPath(v, path);
  1243. }.bind(this))
  1244. } else {
  1245. // if( key && !this.columnDataPathList.indexOf(key) )this.columnDataPathList.push(key);
  1246. }
  1247. }.bind(this);
  1248. for (var i = 0; i < json.data.length && i < 10; i++) {
  1249. var d = json.data[i];
  1250. addPath(d);
  1251. }
  1252. this.columnDataPathList.sort();
  1253. if (this.view && this.view.items) {
  1254. this.view.items.each(function (column) {
  1255. column.refreshColumnPathData()
  1256. })
  1257. }
  1258. },
  1259. getColumnDataPath: function () {
  1260. return this.columnDataPathList || [];
  1261. },
  1262. checkViewFilter: function(){
  1263. if( this.json.viewEnable === false )return true;
  1264. var noteFlag = false;
  1265. if (typeOf(this.viewJson) === "object" && this.viewJson.data && this.viewJson.data.customFilterList) {
  1266. this.viewJson.data.customFilterList.each(function (item) {
  1267. if (item.path) {
  1268. if (["sql", "sqlScript"].contains(this.data.format) && item.path.contains(".")) {
  1269. noteFlag = true;
  1270. }
  1271. if (!["sql", "sqlScript"].contains(this.data.format) && !item.path.contains(".")) {
  1272. noteFlag = true;
  1273. }
  1274. }
  1275. }.bind(this));
  1276. if (noteFlag) this.designer.notice(MWF.xApplication.query.StatementDesigner.LP.modifyViewFilterNote, "info");
  1277. }
  1278. return !noteFlag;
  1279. },
  1280. execute: function (success, failure) {
  1281. var json = this.jsonEditor.editor.getValue() || "{}";
  1282. var parameter = JSON.parse(json);
  1283. var filter = this.filterListEditor.editor.getValue() || "[]";
  1284. var filterList = JSON.parse(filter);
  1285. var pageNo = this.runPageNoInput.get("value").toInt();
  1286. var pageSize = this.runPageSizeInput.get("value").toInt();
  1287. var mode = "data";
  1288. // if (this.data.type === "select") {
  1289. var getMode = function (queryName, countName) {
  1290. switch (this.data.countMethod) {
  1291. case "ignore":
  1292. return this.data[queryName] ? "data" : false;
  1293. case "auto":
  1294. return this.data[queryName] ? "all" : false;
  1295. default:
  1296. if (this.data[queryName] && this.data[countName]) {
  1297. return "all";
  1298. } else if (this.data[queryName] && !this.data[countName]) {
  1299. return "data";
  1300. } else if (!this.data[queryName] && this.data[countName]) {
  1301. return "count";
  1302. } else {
  1303. return false;
  1304. }
  1305. }
  1306. }.bind(this);
  1307. switch (this.data.format) {
  1308. case "script":
  1309. mode = getMode("scriptText", "countScriptText");
  1310. break;
  1311. case "sqlScript":
  1312. mode = getMode("sqlScriptText", "sqlCountScriptText");
  1313. break;
  1314. case "sql":
  1315. mode = getMode("sql", "sqlCount");
  1316. break;
  1317. default:
  1318. mode = getMode("data", "countData");
  1319. break;
  1320. // }
  1321. if( !mode ){
  1322. this.designer.notice(this.designer.lp.inputStatementData, "error");
  1323. return false;
  1324. }
  1325. }
  1326. o2.Actions.load("x_query_assemble_designer").StatementAction.executeV2(this.json.id, mode, pageNo || 1, pageSize || 50, {
  1327. parameter: parameter,
  1328. filterList: filterList
  1329. }, function (json) {
  1330. if (success) success(json)
  1331. }.bind(this), function (xhr, text, error) {
  1332. if (failure) failure();
  1333. var errorText = error;
  1334. if (xhr) {
  1335. var json = JSON.decode(xhr.responseText);
  1336. if (json) {
  1337. errorText = json.message.trim() || "request json error";
  1338. } else {
  1339. errorText = "request json error: " + xhr.responseText;
  1340. }
  1341. }
  1342. errorText = errorText.replace(/\</g, "&lt;");
  1343. errorText = errorText.replace(/\</g, "&gt;");
  1344. MWF.xDesktop.notice("error", {x: "right", y: "top"}, errorText);
  1345. }.bind(this))
  1346. },
  1347. save: function (callback) {
  1348. if (!this.data.name) {
  1349. this.designer.notice(this.designer.lp.inputStatementName, "error");
  1350. return false;
  1351. }
  1352. if( !this.checkViewFilter() ){
  1353. return false;
  1354. }
  1355. if (typeOf(this.viewJson) === "object") {
  1356. if(this.viewJson.data && !this.viewJson.data.group)this.viewJson.data.group = {};
  1357. if(!this.viewJson.pageSize)this.viewJson.pageSize = "20";
  1358. this.data.view = JSON.stringify(this.viewJson);
  1359. }
  1360. // if (this.jpqlEditor) this.data.data = this.jpqlEditor.editor.getValue();
  1361. // if (this.jpqlScriptEditor) this.data.scriptText = this.jpqlScriptEditor.toJson().code;
  1362. var textJson = {};
  1363. if (this.jsonEditor) textJson.parameter = JSON.parse(this.jsonEditor.editor.getValue() || "{}");
  1364. if (this.filterListEditor) textJson.filterList = JSON.parse(this.filterListEditor.editor.getValue() || "[]");
  1365. this.data.testParameters = JSON.stringify(textJson);
  1366. this.designer.actions.saveStatement(this.data, function (json) {
  1367. this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  1368. this.data.id = json.data.id;
  1369. if (this.lisNode) {
  1370. this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
  1371. }
  1372. if (callback) callback();
  1373. }.bind(this));
  1374. },
  1375. _setEditStyle: function (name, input, oldValue) {
  1376. if( name === "viewEnable" && this.viewPage ){
  1377. if (this.data.viewEnable === false ) {
  1378. this.viewPage.disableTab();
  1379. } else {
  1380. this.viewPage.enableTab(true);
  1381. }
  1382. }
  1383. },
  1384. saveSilence: function (callback) {
  1385. if (!this.data.name) {
  1386. this.designer.notice(this.designer.lp.inputStatementName, "error");
  1387. return false;
  1388. }
  1389. if (typeOf(this.viewJson) === "object") {
  1390. if(this.viewJson.data && !this.viewJson.data.group)this.viewJson.data.group = {};
  1391. if( !this.viewJson.pageSize )this.viewJson.pageSize = "20";
  1392. this.data.view = JSON.stringify(this.viewJson);
  1393. }
  1394. // if (this.jpqlEditor) this.data.data = this.jpqlEditor.editor.getValue();
  1395. // if (this.jpqlScriptEditor) this.data.scriptText = this.jpqlScriptEditor.toJson().code;
  1396. // if (this.jsonEditor) this.data.testParameters = this.jsonEditor.editor.getValue();
  1397. var textJson = {};
  1398. if (this.jsonEditor) textJson.parameter = JSON.parse(this.jsonEditor.editor.getValue() || "{}");
  1399. if (this.filterListEditor) textJson.filterList = JSON.parse(this.filterListEditor.editor.getValue() || "[]");
  1400. this.data.testParameters = JSON.stringify(textJson);
  1401. this.designer.actions.saveStatement(this.data, function (json) {
  1402. //this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  1403. this.data.id = json.data.id;
  1404. if (this.lisNode) {
  1405. this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
  1406. }
  1407. if (callback) callback();
  1408. }.bind(this));
  1409. },
  1410. loadView: function (callback) {
  1411. this.setViewSize();
  1412. this.designer.addEvent("resize", this.setViewSize.bind(this));
  1413. if (!this.data.view) {
  1414. this.viewJson = {};
  1415. } else {
  1416. this.viewJson = JSON.parse(this.data.view)
  1417. }
  1418. this.view = new MWF.xApplication.query.StatementDesigner.View(this.designer, this, this.viewJson, {});
  1419. this.view.load(function () {
  1420. this.view.setContentHeight();
  1421. }.bind(this));
  1422. },
  1423. setViewSize: function () {
  1424. var size = this.areaNode.getSize();
  1425. var designerSize = this.designerArea.getComputedSize();
  1426. var reizeNodeSize = this.resizeNode.getComputedSize();
  1427. var y = size.y - designerSize.totalHeight - reizeNodeSize.totalHeight;
  1428. var mTop = this.viewArea.getStyle("margin-top").toInt();
  1429. var mBottom = this.viewArea.getStyle("margin-bottom").toInt();
  1430. var pTop = this.viewArea.getStyle("padding-top").toInt();
  1431. var pBottom = this.viewArea.getStyle("padding-bottom").toInt();
  1432. y = y - mTop - mBottom - pTop - pBottom - 1;
  1433. var tabSize = this.tabNode.getComputedSize();
  1434. y = y - tabSize.totalHeight;
  1435. this.viewArea.setStyle("height", "" + y + "px");
  1436. // var titleSize = this.runTitleNode.getComputedSize();
  1437. // y = y - titleSize.totalHeight;
  1438. // this.runContentNode.setStyle("height", ""+y+"px");
  1439. },
  1440. preview: function () {
  1441. if( this.json.viewEnable === false ){
  1442. this.designer.notice(this.designer.lp.cannotDisabledViewNotice, "error");
  1443. return;
  1444. }
  1445. if (this.isNewStatement) {
  1446. this.designer.notice(this.designer.lp.saveStatementNotice, "error");
  1447. return;
  1448. }
  1449. // if (this.data.type !== "select") {
  1450. // this.designer.notice(this.designer.lp.previewNotSelectStatementNotice, "error");
  1451. // return;
  1452. // }
  1453. if (!this.data.view) {
  1454. this.designer.notice(this.designer.lp.noViewNotice, "error");
  1455. }
  1456. this.saveSilence(function () {
  1457. var url = "../x_desktop/app.html?app=query.Query&status=";
  1458. url += JSON.stringify({
  1459. id: this.data.application,
  1460. statementId: this.data.id
  1461. });
  1462. window.open(o2.filterUrl(url), "_blank");
  1463. }.bind(this));
  1464. }
  1465. });
  1466. MWF.xApplication.query.StatementDesigner.View = new Class({
  1467. Extends: MWF.xApplication.query.ViewDesigner.View,
  1468. Implements: [Options, Events],
  1469. options: {
  1470. "style": "default",
  1471. "isView": false,
  1472. "showTab": true,
  1473. "propertyPath": "../x_component_query_StatementDesigner/$Statement/view.html"
  1474. },
  1475. initialize: function (designer, statement, data, options) {
  1476. this.setOptions(options);
  1477. this.path = "../x_component_query_ViewDesigner/$View/";
  1478. this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/css.wcss";
  1479. this._loadCss();
  1480. this.statement = statement;
  1481. this.designer = designer;
  1482. this.data = data;
  1483. this.data.id = this.statement.data.id + "_view";
  1484. // if (!this.data.data) this.data.data = {};
  1485. this.parseData();
  1486. this.node = this.statement.viewArea;
  1487. //this.tab = this.designer.tab;
  1488. this.areaNode = new Element("div", {"styles": {"height": "calc(100% - 2px)", "overflow": "auto"}});
  1489. this.areaNode.setStyles(this.css.areaNode);
  1490. //MWF.require("MWF.widget.ScrollBar", function(){
  1491. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  1492. //}.bind(this));
  1493. // this.propertyListNode = this.designer.propertyDomArea;
  1494. //this.propertyNode = this.designer.propertyContentArea;
  1495. // if(this.designer.application) this.data.applicationName = this.designer.application.name;
  1496. // if(this.designer.application) this.data.application = this.designer.application.id;
  1497. // this.isNewView = (this.data.name) ? false : true;
  1498. this.items = [];
  1499. this.view = this;
  1500. // this.autoSave();
  1501. // this.designer.addEvent("queryClose", function(){
  1502. // if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  1503. // }.bind(this));
  1504. },
  1505. load: function (callback) {
  1506. this.setAreaNodeSize();
  1507. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  1508. this.areaNode.inject(this.node);
  1509. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  1510. this.loadTemplateStyle(function () {
  1511. this.loadActionbar();
  1512. this.loadView();
  1513. this.loadPaging();
  1514. // this.selected();
  1515. this.setEvent();
  1516. //if (this.options.showTab) this.page.showTabIm();
  1517. this.setViewWidth();
  1518. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  1519. if (callback) callback();
  1520. }.bind(this))
  1521. },
  1522. parseData: function () {
  1523. this.json = this.data;
  1524. if (!this.json.id) {
  1525. this.json.id = (new o2.widget.UUID).id;
  1526. }
  1527. if (!this.json.data || !this.json.data.events) {
  1528. var url = "../x_component_query_StatementDesigner/$Statement/view.json";
  1529. MWF.getJSON(url, {
  1530. "onSuccess": function (obj) {
  1531. if (!this.json.data) this.json.data = obj.data;
  1532. if (!this.json.data.events) this.json.data.events = obj.data.events;
  1533. }.bind(this),
  1534. "onerror": function (text) {
  1535. this.notice(text, "error");
  1536. }.bind(this),
  1537. "onRequestFailure": function (xhr) {
  1538. this.notice(xhr.responseText, "error");
  1539. }.bind(this)
  1540. }, false);
  1541. }
  1542. },
  1543. loadViewNodes: function(){
  1544. this.viewAreaNode = new Element("div#viewAreaNode", {"styles": this.css.viewAreaNode}).inject(this.areaNode);
  1545. this.viewTitleNode = new Element("div#viewTitleNode", {"styles": this.css.viewTitleNode}).inject(this.viewAreaNode);
  1546. this.refreshNode = new Element("div", {"styles": this.css.refreshNode}).inject(this.viewTitleNode);
  1547. this.addColumnNode = new Element("div", {"styles": this.css.addColumnNode}).inject(this.viewTitleNode);
  1548. this.viewTitleContentNode = new Element("div", {"styles": this.css.viewTitleContentNode}).inject(this.viewTitleNode);
  1549. this.autoAddColumnsNode = new Element("div.autoAddColumnsNode", {
  1550. styles: this.css.autoAddColumnsNode,
  1551. title: this.designer.lp.autoAddColumns
  1552. }).inject(this.viewTitleContentNode);
  1553. if( this.json.data.selectList && this.json.data.selectList.length ){
  1554. this.autoAddColumnsNode.hide();
  1555. }
  1556. this.viewTitleTableNode = new Element("table", {
  1557. "styles": this.css.viewTitleTableNode,
  1558. "border": "0px",
  1559. "cellPadding": "0",
  1560. "cellSpacing": "0"
  1561. }).inject(this.viewTitleContentNode);
  1562. this.viewTitleTrNode = new Element("tr", {"styles": this.css.viewTitleTrNode}).inject(this.viewTitleTableNode);
  1563. this.viewContentScrollNode = new Element("div", {"styles": this.css.viewContentScrollNode}).inject(this.viewAreaNode);
  1564. this.viewContentNode = new Element("div", {"styles": this.css.viewContentNode}).inject(this.viewContentScrollNode);
  1565. MWF.require("MWF.widget.ScrollBar", function(){
  1566. new MWF.widget.ScrollBar(this.viewContentScrollNode, {"style": "view", "distance": 100, "indent": false});
  1567. }.bind(this));
  1568. this.contentLeftNode = new Element("div", {"styles": this.css.contentLeftNode}).inject(this.viewContentNode);
  1569. this.contentRightNode = new Element("div", {"styles": this.css.contentRightNode}).inject(this.viewContentNode);
  1570. this.viewContentBodyNode = new Element("div", {"styles": this.css.viewContentBodyNode}).inject(this.viewContentNode);
  1571. this.viewContentTableNode = new Element("table", {
  1572. "styles": this.css.viewContentTableNode,
  1573. "border": "0px",
  1574. "cellPadding": "0",
  1575. "cellSpacing": "0"
  1576. }).inject(this.viewContentBodyNode);
  1577. },
  1578. setEvent: function () {
  1579. this.areaNode.addEvents({
  1580. "click": function (e) {
  1581. this.selected();
  1582. e.stopPropagation();
  1583. }.bind(this),
  1584. "mouseover": function () {
  1585. if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode_over)
  1586. }.bind(this),
  1587. "mouseout": function () {
  1588. if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode)
  1589. }.bind(this)
  1590. });
  1591. this.refreshNode.addEvent("click", function (e) {
  1592. this.statement.runStatement();
  1593. e.stopPropagation();
  1594. }.bind(this));
  1595. this.addColumnNode.addEvent("click", function (e) {
  1596. this.addColumn();
  1597. e.stopPropagation();
  1598. }.bind(this));
  1599. this.autoAddColumnsNode.addEvent("click", function (e) {
  1600. this.autoAddColumns();
  1601. e.stopPropagation();
  1602. }.bind(this));
  1603. },
  1604. autoAddColumns: function(){
  1605. MWF.require("MWF.widget.UUID", null, false);
  1606. var d = this.statement.data;
  1607. var className = d.entityCategory === "dynamic" ? d.table : d.entityClassName;
  1608. if( !className )return;
  1609. var pre = ["sql", "sqlScript"].contains(d.format) ? "x" : "";
  1610. var p;
  1611. if( d.entityCategory === "dynamic" ){
  1612. p = o2.Actions.load("x_query_assemble_designer").TableAction.get(d.table, function(json){
  1613. if (json){
  1614. var dataJson = JSON.decode(json.data.data);
  1615. return dataJson.fieldList || [];
  1616. }
  1617. }.bind(this));
  1618. }else{
  1619. p = o2.Actions.load("x_query_assemble_designer").QueryAction.getEntityProperties(
  1620. className,
  1621. d.entityCategory,
  1622. function(json){
  1623. return json.data||[];
  1624. }.bind(this)
  1625. );
  1626. }
  1627. Promise.resolve(p).then(function (data){
  1628. this.json.data.selectList = data.map( function ( field ) {
  1629. return {
  1630. "id": (new MWF.widget.UUID).id,
  1631. "column": field.name,
  1632. "path": pre ? (pre + field.name) : field.name,
  1633. "displayName": field.description || field.name,
  1634. "orderType": "original"
  1635. }
  1636. }.bind(this));
  1637. this.json.data.selectList.each(function (d) {
  1638. this.items.push(new MWF.xApplication.query.StatementDesigner.View.Column(d, this));
  1639. }.bind(this));
  1640. }.bind(this))
  1641. },
  1642. selected: function () {
  1643. if (this.statement.currentSelectedModule) {
  1644. if (this.statement.currentSelectedModule == this) {
  1645. return true;
  1646. } else {
  1647. this.statement.currentSelectedModule.unSelected();
  1648. }
  1649. }
  1650. this.areaNode.setStyles(this.css.areaNode_selected);
  1651. this.statement.currentSelectedModule = this;
  1652. this.statement.selectMode = "view";
  1653. this.domListNode.show();
  1654. this.isSelected = true;
  1655. this.showProperty();
  1656. this.statement.designer.setDesignerStatementResize();
  1657. },
  1658. unSelected: function () {
  1659. this.statement.currentSelectedModule = null;
  1660. this.isSelected = false;
  1661. this.areaNode.setStyles(this.css.areaNode);
  1662. this.hideProperty();
  1663. },
  1664. showProperty: function () {
  1665. if (!this.property) {
  1666. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  1667. "path": this.options.propertyPath,
  1668. "onPostLoad": function () {
  1669. this.property.show();
  1670. }.bind(this)
  1671. });
  1672. this.property.load();
  1673. } else {
  1674. this.property.show();
  1675. }
  1676. },
  1677. hideProperty: function () {
  1678. if (this.property) this.property.hide();
  1679. },
  1680. loadViewData: function () {
  1681. if (this.data.id) {
  1682. // this.statement.saveSilence(function () {
  1683. this.viewContentBodyNode.empty();
  1684. this.viewContentTableNode = new Element("table", {
  1685. "styles": this.css.viewContentTableNode,
  1686. "border": "0px",
  1687. "cellPadding": "0",
  1688. "cellSpacing": "0"
  1689. }).inject(this.viewContentBodyNode);
  1690. // this.statement.execute( function (json) {
  1691. // this.statement.setColumnDataPath( json );
  1692. var entries = {};
  1693. this.json.data.selectList.each(function (entry) {
  1694. entries[entry.column] = entry;
  1695. }.bind(this));
  1696. if (this.statement.executeData && this.statement.executeData.data && this.statement.executeData.data.length) {
  1697. this.statement.executeData.data.each(function (line, idx) {
  1698. var tr = new Element("tr", {
  1699. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
  1700. }).inject(this.viewContentTableNode);
  1701. //this.createViewCheckboxTd( tr );
  1702. Object.each(entries, function (c, k) {
  1703. debugger;
  1704. var path = c.path, code = c.code, obj = line;
  1705. if( path ){
  1706. var pathList = path.split(".");
  1707. for( var i=0; i<pathList.length; i++ ){
  1708. var p = pathList[i];
  1709. if( (/(^[1-9]\d*$)/.test(p)) )p = p.toInt();
  1710. if( obj[ p ] ){
  1711. obj = obj[ p ];
  1712. }else if(obj[p] === undefined || obj[p] === null) {
  1713. obj = "";
  1714. break;
  1715. } else {
  1716. obj = obj[p];
  1717. break;
  1718. }
  1719. }
  1720. }
  1721. if( code && code.trim())obj = MWF.Macro.exec( code, { "target" : {"value": obj, "data": line, "entry": c} });
  1722. var toName = function (value) {
  1723. if(typeOf(value) === "array"){
  1724. Array.each( value, function (v, idx) {
  1725. value[idx] = toName(v)
  1726. })
  1727. }else if( typeOf(value) === "object" ){
  1728. Object.each( value, function (v, key) {
  1729. value[key] = toName(v);
  1730. })
  1731. }else if( typeOf( value ) === "string" ){
  1732. value = o2.name.cn( value )
  1733. }
  1734. return value;
  1735. };
  1736. var d;
  1737. if( obj!= undefined && obj!= null ){
  1738. if( typeOf(obj) === "array" ) {
  1739. d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
  1740. }else if( typeOf(obj) === "object" ){
  1741. d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
  1742. }else{
  1743. d = c.isName ? o2.name.cn( obj.toString() ) : obj;
  1744. }
  1745. }
  1746. if (d != undefined && d != null ) {
  1747. var td = new Element("td", {
  1748. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  1749. }).inject(tr);
  1750. if (c.isHtml) {
  1751. td.set("html", d);
  1752. } else {
  1753. td.set("text", d);
  1754. }
  1755. }
  1756. }.bind(this));
  1757. }.bind(this));
  1758. this.setContentColumnWidth();
  1759. this.setContentHeight();
  1760. } else if (this.json.data.noDataText) {
  1761. var noDataTextNodeStyle = this.css.noDataTextNode;
  1762. if (this.json.data.viewStyles) {
  1763. if (this.json.data.viewStyles["noDataTextNode"]) {
  1764. noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
  1765. } else {
  1766. this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
  1767. }
  1768. }
  1769. this.noDataTextNode = new Element("div", {
  1770. "styles": noDataTextNodeStyle,
  1771. "text": this.json.data.noDataText
  1772. }).inject(this.viewContentBodyNode);
  1773. }
  1774. // }.bind(this));
  1775. // }.bind(this));
  1776. }
  1777. },
  1778. addColumn: function () {
  1779. MWF.require("MWF.widget.UUID", function () {
  1780. var id = (new MWF.widget.UUID).id;
  1781. var json = {
  1782. "id": id,
  1783. "column": id,
  1784. "displayName": this.designer.lp.unnamed,
  1785. "orderType": "original"
  1786. };
  1787. if (!this.json.data.selectList) this.json.data.selectList = [];
  1788. this.json.data.selectList.push(json);
  1789. var column = new MWF.xApplication.query.StatementDesigner.View.Column(json, this);
  1790. this.items.push(column);
  1791. column.selected();
  1792. if (this.viewContentTableNode) {
  1793. var trs = this.viewContentTableNode.getElements("tr");
  1794. trs.each(function (tr) {
  1795. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  1796. }.bind(this));
  1797. //this.setContentColumnWidth();
  1798. }
  1799. this.setViewWidth();
  1800. this.addColumnNode.scrollIntoView(false);
  1801. }.bind(this));
  1802. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  1803. },
  1804. setContentHeight: function () {
  1805. var size = this.areaNode.getSize();
  1806. var titleSize = this.viewTitleNode.getSize();
  1807. var actionbarSize = this.actionbarNode ? this.actionbarNode.getSize() : {x: 0, y: 0};
  1808. var pagingSize = this.pagingNode ? this.pagingNode.getSize() : {x: 0, y: 0};
  1809. var height = size.y - titleSize.y - actionbarSize.y - pagingSize.y - 4;
  1810. this.viewContentScrollNode.setStyle("height", height);
  1811. var contentSize = this.viewContentBodyNode.getSize();
  1812. if (height < contentSize.y) height = contentSize.y + 10;
  1813. this.viewContentNode.setStyle("height", height);
  1814. this.contentLeftNode.setStyle("height", height);
  1815. this.contentRightNode.setStyle("height", height);
  1816. //this.viewContentBodyNode.setStyle("min-height", height);
  1817. },
  1818. loadViewColumns: function () {
  1819. // for (var i=0; i<10; i++){
  1820. if (this.json.data.selectList) {
  1821. this.json.data.selectList.each(function (json) {
  1822. this.items.push(new MWF.xApplication.query.StatementDesigner.View.Column(json, this));
  1823. }.bind(this));
  1824. }
  1825. // }
  1826. },
  1827. showActionbar: function (noSetHeight) {
  1828. this.actionbarNode.show();
  1829. if (!this.json.data.actionbarList) this.json.data.actionbarList = [];
  1830. if (!this.actionbarList || this.actionbarList.length == 0) {
  1831. if (this.json.data.actionbarList.length) {
  1832. this.json.data.actionbarList.each(function (json) {
  1833. this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(json, this.json.data.actionbarList, this))
  1834. }.bind(this));
  1835. } else {
  1836. this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(null, this.json.data.actionbarList, this))
  1837. }
  1838. }
  1839. if (!noSetHeight) this.setContentHeight();
  1840. },
  1841. showPagingbar: function (noSetHeight) {
  1842. this.pagingNode.show();
  1843. if (!this.json.data.pagingList) this.json.data.pagingList = [];
  1844. if (!this.pagingList || this.pagingList.length == 0) {
  1845. if (this.json.data.pagingList.length) {
  1846. this.json.data.pagingList.each(function (json) {
  1847. this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(json, this.json.data.pagingList, this))
  1848. }.bind(this));
  1849. } else {
  1850. this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(null, this.json.data.pagingList, this))
  1851. }
  1852. }
  1853. if( !noSetHeight )this.setContentHeight();
  1854. },
  1855. setViewWidth: function () {
  1856. if (!this.viewAreaNode) return;
  1857. this.viewAreaNode.setStyle("width", "auto");
  1858. this.viewTitleNode.setStyle("width", "auto");
  1859. var s1 = this.viewTitleTableNode.getSize();
  1860. var s2 = this.refreshNode.getSize();
  1861. var s3 = this.addColumnNode.getSize();
  1862. var width = s1.x + s2.x + s2.x;
  1863. var size = this.areaNode.getSize();
  1864. if (width > size.x) {
  1865. this.viewTitleNode.setStyle("width", "" + (width - 2) + "px");
  1866. this.viewAreaNode.setStyle("width", "" + (width - 2) + "px");
  1867. } else {
  1868. this.viewTitleNode.setStyle("width", "" + (size.x - 2) + "px");
  1869. this.viewAreaNode.setStyle("width", "" + (size.x - 2) + "px");
  1870. }
  1871. this.setContentColumnWidth();
  1872. this.setContentHeight();
  1873. },
  1874. _setEditStyle: function (name, input, oldValue) {
  1875. if (name == "data.actionbarHidden") {
  1876. if (this.json.data.actionbarHidden) {
  1877. this.hideActionbar()
  1878. } else {
  1879. this.showActionbar()
  1880. }
  1881. }
  1882. if (name == "data.pagingbarHidden") {
  1883. if (this.json.data.pagingbarHidden) {
  1884. this.hidePagingbar()
  1885. } else {
  1886. this.showPagingbar()
  1887. }
  1888. }
  1889. if (name == "data.selectAllEnable") {
  1890. if (this.json.data.selectAllEnable) {
  1891. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display", "table-cell");
  1892. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display", "table-cell");
  1893. } else {
  1894. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display", "none");
  1895. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display", "none");
  1896. }
  1897. }
  1898. if (name == "data.viewStyleType") {
  1899. var file = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].file : null;
  1900. var extendFile = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].extendFile : null;
  1901. this.loadTemplateStyles(file, extendFile, function (templateStyles) {
  1902. this.templateStyles = templateStyles;
  1903. var oldFile, oldExtendFile;
  1904. if (oldValue && this.stylesList[oldValue]) {
  1905. oldFile = this.stylesList[oldValue].file;
  1906. oldExtendFile = this.stylesList[oldValue].extendFile;
  1907. }
  1908. this.loadTemplateStyles(oldFile, oldExtendFile, function (oldTemplateStyles) {
  1909. this.json.data.styleConfig = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType] : null;
  1910. if (oldTemplateStyles["view"]) this.clearTemplateStyles(oldTemplateStyles["view"]);
  1911. if (this.templateStyles["view"]) this.setTemplateStyles(this.templateStyles["view"]);
  1912. this.setAllStyles();
  1913. this.actionbarList.each(function (module) {
  1914. if (oldTemplateStyles["actionbar"]) {
  1915. module.clearTemplateStyles(oldTemplateStyles["actionbar"]);
  1916. }
  1917. module.setStyleTemplate();
  1918. module.setAllStyles();
  1919. })
  1920. this.pagingList.each(function (module) {
  1921. if (oldTemplateStyles["paging"]) {
  1922. module.clearTemplateStyles(oldTemplateStyles["paging"]);
  1923. }
  1924. module.setStyleTemplate();
  1925. module.setAllStyles();
  1926. });
  1927. // this.moduleList.each(function(module){
  1928. // if (oldTemplateStyles[module.moduleName]){
  1929. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  1930. // }
  1931. // module.setStyleTemplate();
  1932. // module.setAllStyles();
  1933. // }.bind(this));
  1934. }.bind(this))
  1935. }.bind(this))
  1936. }
  1937. if (name == "data.viewStyles") {
  1938. this.setCustomStyles();
  1939. }
  1940. },
  1941. loadTemplateStyle: function (callback) {
  1942. this.loadStylesList(function () {
  1943. var oldStyleValue = "";
  1944. if ((!this.json.data.viewStyleType) || !this.stylesList[this.json.data.viewStyleType]) this.json.data.viewStyleType = "default";
  1945. this.loadTemplateStyles(this.stylesList[this.json.data.viewStyleType].file, this.stylesList[this.json.data.viewStyleType].extendFile,
  1946. function (templateStyles) {
  1947. this.templateStyles = templateStyles;
  1948. if (!this.json.data.viewStyleType) this.json.data.viewStyleType = "default";
  1949. if (this.templateStyles && this.templateStyles["view"]) {
  1950. var viewStyles = Object.clone(this.templateStyles["view"]);
  1951. if (viewStyles.contentGroupTd) delete viewStyles.contentGroupTd;
  1952. if (viewStyles.groupCollapseNode) delete viewStyles.groupCollapseNode;
  1953. if (viewStyles.groupExpandNode) delete viewStyles.groupExpandNode;
  1954. if (!this.json.data.viewStyles) {
  1955. this.json.data.viewStyles = viewStyles;
  1956. } else {
  1957. this.setTemplateStyles(viewStyles);
  1958. }
  1959. }
  1960. this.setCustomStyles();
  1961. if (callback) callback();
  1962. }.bind(this)
  1963. );
  1964. }.bind(this));
  1965. },
  1966. clearTemplateStyles: function (styles) {
  1967. if (styles) {
  1968. if (styles.container) this.removeStyles(styles.container, "container");
  1969. if (styles.table) this.removeStyles(styles.table, "table");
  1970. if (styles.titleTr) this.removeStyles(styles.titleTr, "titleTr");
  1971. if (styles.titleTd) this.removeStyles(styles.titleTd, "titleTd");
  1972. if (styles.contentTr) this.removeStyles(styles.contentTr, "contentTr");
  1973. if (styles.contentSelectedTr) this.removeStyles(styles.contentSelectedTr, "contentSelectedTr");
  1974. if (styles.contentTd) this.removeStyles(styles.contentTd, "contentTd");
  1975. if (styles.zebraContentTd) this.removeStyles(styles.zebraContentTd, "zebraContentTd");
  1976. // if (styles.contentGroupTd) this.removeStyles(styles.contentGroupTd, "contentGroupTd");
  1977. // if (styles.groupCollapseNode) this.removeStyles(styles.groupCollapseNode, "groupCollapseNode");
  1978. // if (styles.groupExpandNode) this.removeStyles(styles.groupExpandNode, "groupExpandNode");
  1979. if (styles.checkboxNode) this.removeStyles(styles.checkboxNode, "checkboxNode");
  1980. if (styles.checkedCheckboxNode) this.removeStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1981. if (styles.radioNode) this.removeStyles(styles.radioNode, "radioNode");
  1982. if (styles.checkedRadioNode) this.removeStyles(styles.checkedRadioNode, "checkedRadioNode");
  1983. if (styles.tableProperties) this.removeStyles(styles.tableProperties, "tableProperties");
  1984. }
  1985. },
  1986. setTemplateStyles: function (styles) {
  1987. if (styles.container) this.copyStyles(styles.container, "container");
  1988. if (styles.table) this.copyStyles(styles.table, "table");
  1989. if (styles.titleTr) this.copyStyles(styles.titleTr, "titleTr");
  1990. if (styles.titleTd) this.copyStyles(styles.titleTd, "titleTd");
  1991. if (styles.contentTr) this.copyStyles(styles.contentTr, "contentTr");
  1992. if (styles.contentSelectedTr) this.copyStyles(styles.contentSelectedTr, "contentSelectedTr");
  1993. if (styles.contentTd) this.copyStyles(styles.contentTd, "contentTd");
  1994. if (styles.zebraContentTd) this.copyStyles(styles.zebraContentTd, "zebraContentTd");
  1995. // if (styles.contentGroupTd) this.copyStyles(styles.contentGroupTd, "contentGroupTd");
  1996. // if (styles.groupCollapseNode) this.copyStyles(styles.groupCollapseNode, "groupCollapseNode");
  1997. // if (styles.groupExpandNode) this.copyStyles(styles.groupExpandNode, "groupExpandNode");
  1998. if (styles.checkboxNode) this.copyStyles(styles.checkboxNode, "checkboxNode");
  1999. if (styles.checkedCheckboxNode) this.copyStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  2000. if (styles.radioNode) this.copyStyles(styles.radioNode, "radioNode");
  2001. if (styles.checkedRadioNode) this.copyStyles(styles.checkedRadioNode, "checkedRadioNode");
  2002. if (styles.tableProperties) this.copyStyles(styles.tableProperties, "tableProperties");
  2003. },
  2004. removeStyles: function (from, to) {
  2005. if( this.isForceClearCustomStyle() ){
  2006. this.json.data.viewStyles[to] = {};
  2007. }else{
  2008. if (this.json.data.viewStyles[to]) {
  2009. Object.each(from, function (style, key) {
  2010. if (this.json.data.viewStyles[to][key] && this.json.data.viewStyles[to][key] == style) {
  2011. delete this.json.data.viewStyles[to][key];
  2012. }
  2013. }.bind(this));
  2014. }
  2015. }
  2016. },
  2017. copyStyles: function (from, to) {
  2018. if( this.isForceClearCustomStyle() ){
  2019. this.json.data.viewStyles[to] = {};
  2020. Object.each(from, function (style, key) {
  2021. this.json.data.viewStyles[to][key] = style;
  2022. }.bind(this));
  2023. }else{
  2024. if (!this.json.data.viewStyles[to]) this.json.data.viewStyles[to] = {};
  2025. Object.each(from, function (style, key) {
  2026. if (!this.json.data.viewStyles[to][key]) this.json.data.viewStyles[to][key] = style;
  2027. }.bind(this));
  2028. }
  2029. }
  2030. // preview: function(){
  2031. // if( this.isNewView ){
  2032. // this.designer.notice( this.designer.lp.saveViewNotice, "error" );
  2033. // return;
  2034. // }
  2035. // this.saveSilence( function () {
  2036. // var url = "../x_desktop/app.html?app=query.Query&status=";
  2037. // url += JSON.stringify({
  2038. // id : this.data.application,
  2039. // viewId : this.data.id
  2040. // });
  2041. // window.open(o2.filterUrl(url),"_blank");
  2042. // }.bind(this));
  2043. // },
  2044. // saveSilence: function(callback){
  2045. // if (!this.data.name){
  2046. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  2047. // return false;
  2048. // }
  2049. //
  2050. // this.designer.actions.saveView(this.data, function(json){
  2051. // this.data.id = json.data.id;
  2052. // this.isNewView = false;
  2053. // //this.page.textNode.set("text", this.data.name);
  2054. // if (this.lisNode) {
  2055. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  2056. // }
  2057. // if (callback) callback();
  2058. // }.bind(this));
  2059. // },
  2060. // save: function(callback){
  2061. // //if (this.designer.tab.showPage==this.page){
  2062. // if (!this.data.name){
  2063. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  2064. // return false;
  2065. // }
  2066. // //}
  2067. // this.designer.actions.saveView(this.data, function(json){
  2068. // this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  2069. // this.isNewView = false;
  2070. // this.data.id = json.data.id;
  2071. // //this.page.textNode.set("text", this.data.name);
  2072. // if (this.lisNode) {
  2073. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  2074. // }
  2075. // if (callback) callback();
  2076. // }.bind(this));
  2077. // },
  2078. // saveAs: function(){
  2079. // var form = new MWF.xApplication.query.StatementDesigner.View.NewNameForm(this, {
  2080. // name : this.data.name + "_" + MWF.xApplication.query.StatementDesigner.LP.copy,
  2081. // query : this.data.query || this.data.application,
  2082. // queryName : this.data.queryName || this.data.applicationName
  2083. // }, {
  2084. // onSave : function( data, callback ){
  2085. // this._saveAs( data, callback );
  2086. // }.bind(this)
  2087. // }, {
  2088. // app: this.designer
  2089. // });
  2090. // form.edit()
  2091. // },
  2092. // _saveAs : function( data , callback){
  2093. // var _self = this;
  2094. //
  2095. // var d = this.cloneObject( this.data );
  2096. //
  2097. // d.isNewView = true;
  2098. // d.id = this.designer.actions.getUUID();
  2099. // d.name = data.name;
  2100. // d.alias = "";
  2101. // d.query = data.query;
  2102. // d.queryName = data.queryName;
  2103. // d.application = data.query;
  2104. // d.applicationName = data.queryName;
  2105. // d.pid = d.id + d.id;
  2106. //
  2107. // delete d[this.data.id+"viewFilterType"];
  2108. // d[d.id+"viewFilterType"]="custom";
  2109. //
  2110. // d.data.selectList.each( function( entry ){
  2111. // entry.id = (new MWF.widget.UUID).id;
  2112. // }.bind(this));
  2113. //
  2114. // this.designer.actions.saveView(d, function(json){
  2115. // this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  2116. // if (callback) callback();
  2117. // }.bind(this));
  2118. // }
  2119. });
  2120. MWF.xApplication.query.StatementDesigner.View.Column = new Class({
  2121. Extends: MWF.xApplication.query.ViewDesigner.View.Column,
  2122. initialize: function (json, view, next) {
  2123. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/column.html";
  2124. this.view = view;
  2125. this.json = json;
  2126. this.next = next;
  2127. this.css = this.view.css;
  2128. this.content = this.view.viewTitleTrNode;
  2129. this.domListNode = this.view.domListNode;
  2130. this.view.autoAddColumnsNode.hide();
  2131. this.load();
  2132. },
  2133. refreshColumnPathData: function () {
  2134. if (this.property) {
  2135. this.property.loadDataPathSelect();
  2136. }
  2137. },
  2138. getColumnDataPath: function () {
  2139. return this.view.statement.getColumnDataPath();
  2140. },
  2141. showProperty: function () {
  2142. if (!this.property) {
  2143. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  2144. "path": this.propertyPath,
  2145. "onPostLoad": function () {
  2146. this.property.show();
  2147. var processDiv = this.property.propertyContent.getElements("#" + this.json.id + "dataPathSelectedProcessArea");
  2148. var cmsDiv = this.property.propertyContent.getElements("#" + this.json.id + "dataPathSelectedCMSArea");
  2149. if (this.view.json.type == "cms") {
  2150. processDiv.setStyle("display", "none");
  2151. cmsDiv.setStyle("display", "block");
  2152. } else {
  2153. processDiv.setStyle("display", "block");
  2154. cmsDiv.setStyle("display", "none");
  2155. }
  2156. }.bind(this)
  2157. });
  2158. this.property.load();
  2159. } else {
  2160. this.property.show();
  2161. }
  2162. },
  2163. selected: function () {
  2164. if (this.view.statement.currentSelectedModule) {
  2165. if (this.view.statement.currentSelectedModule == this) {
  2166. return true;
  2167. } else {
  2168. this.view.statement.currentSelectedModule.unSelected();
  2169. }
  2170. }
  2171. this.view.domListNode.show();
  2172. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  2173. this.listNode.setStyles(this.css.cloumnListNode_selected);
  2174. // new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  2175. // new Fx.Scroll(this.view.designer.propertyDomArea, {
  2176. // "wheelStops": false,
  2177. // "duration": 100
  2178. // }).toElement(this.listNode);
  2179. try{
  2180. this.node.scrollIntoView(false);
  2181. this.listNode.scrollIntoView(false);
  2182. }catch (e) {
  2183. }
  2184. this.view.statement.selectMode = "viewColumn";
  2185. this.view.statement.currentSelectedModule = this;
  2186. this.isSelected = true;
  2187. this._showActions();
  2188. this.showProperty();
  2189. this.view.statement.designer.setDesignerStatementResize();
  2190. },
  2191. unSelected: function () {
  2192. this.view.statement.currentSelectedModule = null;
  2193. //this.node.setStyles(this.css.viewTitleColumnNode);
  2194. if (this.isError) {
  2195. this.node.setStyles(this.css.viewTitleColumnNode_error)
  2196. } else {
  2197. this.node.setStyles(this.css.viewTitleColumnNode)
  2198. }
  2199. this.listNode.setStyles(this.css.cloumnListNode);
  2200. this.isSelected = false;
  2201. this._hideActions();
  2202. this.hideProperty();
  2203. },
  2204. _destroy: function (){
  2205. if( !this.view.json.data.selectList || !this.view.json.data.selectList.length ){
  2206. this.view.autoAddColumnsNode.show();
  2207. }
  2208. },
  2209. addColumn: function(e, data){
  2210. MWF.require("MWF.widget.UUID", function(){
  2211. var json;
  2212. if (data){
  2213. json = Object.clone(data);
  2214. json.id = (new MWF.widget.UUID).id;
  2215. json.column = (new MWF.widget.UUID).id;
  2216. }else{
  2217. var id = (new MWF.widget.UUID).id;
  2218. json = {
  2219. "id": id,
  2220. "column": id,
  2221. "displayName": this.view.designer.lp.unnamed,
  2222. "orderType": "original"
  2223. };
  2224. }
  2225. var idx = this.view.json.data.selectList.indexOf(this.json);
  2226. this.view.json.data.selectList.splice(idx, 0, json);
  2227. var column = new MWF.xApplication.query.StatementDesigner.View.Column(json, this.view, this);
  2228. this.view.items.splice(idx, 0, column);
  2229. column.selected();
  2230. if (this.view.viewContentTableNode){
  2231. var trs = this.view.viewContentTableNode.getElements("tr");
  2232. trs.each(function(tr){
  2233. var td = tr.insertCell(idx);
  2234. td.setStyles(this.css.viewContentTdNode);
  2235. }.bind(this));
  2236. }
  2237. this.view.setViewWidth();
  2238. }.bind(this));
  2239. }
  2240. });
  2241. MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({
  2242. Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar,
  2243. initialize: function (json, jsonList, view, options) {
  2244. this.setOptions(options);
  2245. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/actionbar.html";
  2246. this.path = "../x_component_query_ViewDesigner/$View/";
  2247. this.imagePath_default = "../x_component_query_ViewDesigner/$View/";
  2248. this.imagePath_custom = "../x_component_process_FormDesigner/Module/Actionbar/";
  2249. this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/actionbar.wcss";
  2250. this.view = view;
  2251. this.json = json;
  2252. this.jsonList = jsonList;
  2253. this.css = this.view.css;
  2254. this.container = this.view.actionbarNode;
  2255. this.moduleName = "actionbar";
  2256. this.load();
  2257. },
  2258. getJsonPath: function () {
  2259. return "../x_component_query_StatementDesigner/$Statement/toolbars.json";
  2260. },
  2261. selected: function () {
  2262. if (this.view.statement.currentSelectedModule) {
  2263. if (this.view.statement.currentSelectedModule == this) {
  2264. return true;
  2265. } else {
  2266. this.view.statement.currentSelectedModule.unSelected();
  2267. }
  2268. }
  2269. this.view.domListNode.show();
  2270. this.node.setStyles(this.css.toolbarWarpNode_selected);
  2271. // new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  2272. try {
  2273. this.node.scrollIntoView(false);
  2274. }catch (e) {
  2275. }
  2276. this.view.statement.selectMode = "viewActionbar";
  2277. this.view.statement.currentSelectedModule = this;
  2278. this.isSelected = true;
  2279. //this._showActions();
  2280. this.showProperty();
  2281. this.view.statement.designer.setDesignerStatementResize();
  2282. },
  2283. unSelected: function () {
  2284. this.view.statement.currentSelectedModule = null;
  2285. this.node.setStyles(this.css.toolbarWarpNode);
  2286. //this.listNode.setStyles(this.css.cloumnListNode);
  2287. this.isSelected = false;
  2288. //this._hideActions();
  2289. this.hideProperty();
  2290. },
  2291. showProperty: function(){
  2292. if (!this.property){
  2293. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  2294. "path": this.propertyPath,
  2295. "onPostLoad": function(){
  2296. this.property.show();
  2297. }.bind(this)
  2298. });
  2299. this.property.load();
  2300. }else{
  2301. this.property.show();
  2302. }
  2303. }
  2304. });
  2305. MWF.xApplication.query.StatementDesigner.View.Paging = new Class({
  2306. Extends: MWF.xApplication.query.ViewDesigner.View.Paging,
  2307. selected: function () {
  2308. if (this.view.statement.currentSelectedModule) {
  2309. if (this.view.statement.currentSelectedModule == this) {
  2310. return true;
  2311. } else {
  2312. this.view.statement.currentSelectedModule.unSelected();
  2313. }
  2314. }
  2315. this.view.domListNode.show();
  2316. this.node.setStyles(this.css.pagingWarpNode_selected);
  2317. // new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  2318. try {
  2319. this.node.scrollIntoView(false);
  2320. }catch (e) {
  2321. }
  2322. this.view.statement.selectMode = "viewPaging";
  2323. this.view.statement.currentSelectedModule = this;
  2324. this.isSelected = true;
  2325. this.showProperty();
  2326. this.view.statement.designer.setDesignerStatementResize();
  2327. },
  2328. unSelected: function () {
  2329. this.view.statement.currentSelectedModule = null;
  2330. this.node.setStyles(this.css.pagingWarpNode);
  2331. this.isSelected = false;
  2332. this.hideProperty();
  2333. }
  2334. });