MWF.xApplication = MWF.xApplication || {}; MWF.xApplication.query = MWF.xApplication.query || {}; MWF.xApplication.query.StatementDesigner = MWF.xApplication.query.StatementDesigner || {}; MWF.APPDSMD = MWF.xApplication.query.StatementDesigner; MWF.xDesktop.requireApp("query.StatementDesigner", "lp."+MWF.language, null, false); MWF.xDesktop.requireApp("query.StatementDesigner", "Property", null, false); MWF.xDesktop.requireApp("query.ViewDesigner", "View", null, false); o2.require("o2.widget.JavascriptEditor", null, false); MWF.xApplication.query.StatementDesigner.Statement = new Class({ Extends: MWF.widget.Common, Implements: [Options, Events], options: { "style": "default", "isView": false, "showTab": true, "propertyPath": "../x_component_query_StatementDesigner/$Statement/statement.html" }, initialize: function(designer, data, options){ this.setOptions(options); this.path = "../x_component_query_StatementDesigner/$Statement/"; this.cssPath = "../x_component_query_StatementDesigner/$Statement/"+this.options.style+"/css.wcss"; this._loadCss(); this.designer = designer; this.data = data; this.parseData(); this.node = this.designer.designNode; this.areaNode = new Element("div", {"styles": {"height": "100%", "overflow": "auto"}}); //this.statementRunNode = this.designer.designerStatementArea; if(this.designer.application) this.data.applicationName = this.designer.application.name; if(this.designer.application) this.data.application = this.designer.application.id; this.isNewStatement = (this.data.id) ? false : true; this.view = this; this.autoSave(); this.designer.addEvent("queryClose", function(){ if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID); }.bind(this)); }, parseData: function(){ this.json = this.data; if (!this.json.type) this.json.type = "select"; if (!this.json.format) this.json.format = "jpql"; if (!this.json.entityCategory) this.json.entityCategory = "official"; if (!this.json.entityClassName) this.json.entityClassName = "com.x.processplatform.core.entity.content.Task"; }, autoSave: function(){ this.autoSaveTimerID = window.setInterval(function(){ if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFAutoSaveCheck"); if (this.autoSaveCheckNode){ if (this.autoSaveCheckNode.get("checked")){ this.save(); } } }.bind(this), 60000); }, load : function(){ // this.setAreaNodeSize(); // this.designer.addEvent("resize", this.setAreaNodeSize.bind(this)); this.areaNode.inject(this.node); this.designer.statementListAreaNode.getChildren().each(function(node){ var statement = node.retrieve("statement"); if (statement.id==this.data.id){ if (this.designer.currentListStatementItem){ this.designer.currentListStatementItem.setStyles(this.designer.css.listStatementItem); } node.setStyles(this.designer.css.listStatementItem_current); this.designer.currentListStatementItem = node; this.lisNode = node; } }.bind(this)); this.loadStatement(); this.showProperty(); }, showProperty: function(){ if (!this.property){ this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.designerContentArea, this.designer, { "path": this.options.propertyPath, "onPostLoad": function(){ this.property.show(); }.bind(this) }); this.property.load(); }else{ this.property.show(); } }, loadStatement: function(){ //this.statementDesignerNode = new Element("div", {"styles": this.css.statementDesignerNode}).inject(this.areaNode); this.loadStatementHtml(function(){ this.designerArea = this.areaNode.getElement(".o2_statement_statementDesignerNode"); this.jpqlArea = this.areaNode.getElement(".o2_statement_statementDesignerJpql"); this.scriptArea = this.areaNode.getElement(".o2_statement_statementDesignerScript"); this.formatTypeArea = this.areaNode.getElement(".o2_statement_statementDesignerFormatContent"); this.entityCategorySelect = this.areaNode.getElement(".o2_statement_statementDesignerCategoryContent").getElement("select"); this.dynamicTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_dynamic"); this.officialTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_official"); this.customTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_custom"); this.dynamicTableSelect = this.areaNode.getElement(".o2_statement_statementDesignerSelectTable"); this.officialTableSelect = this.officialTableArea.getElement("select"); this.dynamicTableContent = this.areaNode.getElement(".o2_statement_statementDesignerTableContent"); this.jpqlTypeSelect = this.areaNode.getElement(".o2_statement_statementDesignerTypeContent").getElement("select"); // this.jpqlSelectEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_select"); // this.jpqlUpdateEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_update"); // this.jpqlDeleteEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_sdelete"); // this.jpqlSelectEditor_selectContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_selectContent"); // this.jpqlSelectEditor_fromContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_fromContent"); // this.jpqlSelectEditor_whereContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_whereContent"); this.jpqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerJpqlLine"); // this.runArea = this.areaNode.getElement(".o2_statement_statementRunNode"); // this.runTitleNode = this.areaNode.getElement(".o2_statement_statementRunTitleNode"); // this.runContentNode = this.areaNode.getElement(".o2_statement_statementRunContentNode"); // this.runJsonNode = this.runContentNode.getFirst(); // this.runActionNode = this.runJsonNode.getNext(); // this.runResultNode = this.runContentNode.getLast(); // // this.setRunnerSize(); // this.designer.addEvent("resize", this.setRunnerSize.bind(this)); this.viewArea = this.areaNode.getElement(".o2_statement_viewNode"); this.setViewSize(); this.designer.addEvent("resize", this.setViewSize.bind(this)); if (this.json.format=="script"){ this.loadStatementScriptEditor(); }else{ this.loadStatementEditor(); } // this.loadStatementRunner(); this.loadView(); this.setEvent(); }.bind(this)); }, loadStatementScriptEditor: function(){ if (! this.scriptEditor){ debugger; o2.require("o2.widget.ScriptArea", function(){ this.scriptEditor = new o2.widget.ScriptArea(this.scriptArea, { "isbind": false, "maxObj": this.designer.designNode, "title": this.designer.lp.scriptTitle, "onChange": function(){ this.json.scriptText = this.scriptEditor.toJson().code; }.bind(this) }); this.scriptEditor.load({"code": this.json.scriptText}) }.bind(this), false); } }, // setRunnerSize: function(){ // debugger; // var size = this.areaNode.getSize(); // var designerSize = this.designerArea.getComputedSize(); // var y = size.y-designerSize.totalHeight; // var mTop = this.runArea.getStyle("margin-top").toInt(); // var mBottom = this.runArea.getStyle("margin-bottom").toInt(); // var pTop = this.runArea.getStyle("padding-top").toInt(); // var pBottom = this.runArea.getStyle("padding-bottom").toInt(); // y = y-mTop-mBottom-pTop-pBottom-1; // // this.runArea.setStyle("height", ""+y+"px"); // // var titleSize = this.runTitleNode.getComputedSize(); // y = y - titleSize.totalHeight; // this.runContentNode.setStyle("height", ""+y+"px"); // }, loadStatementEditor: function(){ if (!this.editor){ o2.require("o2.widget.JavascriptEditor", function(){ this.editor = new o2.widget.JavascriptEditor(this.jpqlEditorNode, {"title": "JPQL", "option": {"mode": "sql"}}); this.editor.load(function(){ if (this.json.data){ this.editor.editor.setValue(this.json.data); }else{ var table = "table"; switch (this.json.type) { case "update": this.editor.editor.setValue("UPDATE "+table+" o SET "); break; case "delete": this.editor.editor.setValue("DELETE "+table+" o WHERE "); break; default: this.editor.editor.setValue("SELECT * FROM "+table+" o"); } } this.json.data = this.editor.editor.getValue(); this.editor.addEditorEvent("change", function(){ debugger; this.data.data = this.editor.getValue(); this.checkJpqlType(); }.bind(this)); // this.editor.editor.on("change", function(){ // this.data.data = this.editor.getValue(); // this.checkJpqlType(); // }.bind(this)); }.bind(this)); }.bind(this), false); } }, setSatementTable: function(){ if (!this.json.type) this.json.type = "select"; this.changeType(this.json.type, true); if (this.json.data){ this.editor.editor.setValue(this.json.data); }else{ var table = (this.json.tableObj) ? this.json.tableObj.name : "table"; switch (this.json.type) { case "update": this.editor.editor.setValue("UPDATE "+table+" o SET "); break; case "delete": this.editor.editor.setValue("DELETE "+table+" o WHERE "); break; default: this.editor.editor.setValue("SELECT * FROM "+table+" o"); } } }, checkJpqlType: function(){ var str = this.json.data; this.json.data = str; var jpql_select = /^select/i; var jpql_update = /^update/i; var jpql_delete = /^delete/i; if (jpql_select.test(str)) return this.changeType("select"); if (jpql_update.test(str)) return this.changeType("update"); if (jpql_delete.test(str)) return this.changeType("delete"); }, changeType: function(type, force){ if (this.json.type!=type) this.json.type=type; if (type != this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value || force){ for (var i=0; isize.x){ this.viewTitleNode.setStyle("width", ""+width+"px"); this.viewAreaNode.setStyle("width", ""+width+"px"); }else{ this.viewTitleNode.setStyle("width", ""+size.x+"px"); this.viewAreaNode.setStyle("width", ""+size.x+"px"); } this.setContentColumnWidth(); this.setContentHeight(); }, preview: function(){ if( this.isNewView ){ this.designer.notice( this.designer.lp.saveViewNotice, "error" ); return; } this.saveSilence( function () { var url = "../x_desktop/app.html?app=query.Query&status="; url += JSON.stringify({ id : this.data.application, viewId : this.data.id }); window.open(o2.filterUrl(url),"_blank"); }.bind(this)); }, saveSilence: function(callback){ if (!this.data.name){ this.designer.notice(this.designer.lp.notice.inputName, "error"); return false; } this.designer.actions.saveView(this.data, function(json){ this.data.id = json.data.id; this.isNewView = false; //this.page.textNode.set("text", this.data.name); if (this.lisNode) { this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")"); } if (callback) callback(); }.bind(this)); }, save: function(callback){ //if (this.designer.tab.showPage==this.page){ if (!this.data.name){ this.designer.notice(this.designer.lp.notice.inputName, "error"); return false; } //} this.designer.actions.saveView(this.data, function(json){ this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"}); this.isNewView = false; this.data.id = json.data.id; //this.page.textNode.set("text", this.data.name); if (this.lisNode) { this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")"); } if (callback) callback(); }.bind(this)); }, _setEditStyle: function(name, input, oldValue){ if( name=="data.actionbarHidden" ){ if( this.json.data.actionbarHidden ){ this.hideActionbar() }else{ this.showActionbar() } } if( name=="data.selectAllEnable" ){ if( this.json.data.selectAllEnable ){ this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display","table-cell"); this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display","table-cell"); }else{ this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display","none"); this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display","none"); } } if (name=="data.viewStyleType"){ var file = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].file : null; var extendFile = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].extendFile : null; this.loadTemplateStyles( file, extendFile, function( templateStyles ){ this.templateStyles = templateStyles; var oldFile, oldExtendFile; if( oldValue && this.stylesList[oldValue] ){ oldFile = this.stylesList[oldValue].file; oldExtendFile = this.stylesList[oldValue].extendFile; } this.loadTemplateStyles( oldFile, oldExtendFile, function( oldTemplateStyles ){ this.json.data.styleConfig = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType] : null; if (oldTemplateStyles["view"]) this.clearTemplateStyles(oldTemplateStyles["view"]); if (this.templateStyles["view"]) this.setTemplateStyles(this.templateStyles["view"]); this.setAllStyles(); this.actionbarList.each( function (module) { if (oldTemplateStyles["actionbar"]){ module.clearTemplateStyles(oldTemplateStyles["actionbar"]); } module.setStyleTemplate(); module.setAllStyles(); }) this.pagingList.each( function (module) { if (oldTemplateStyles["paging"]){ module.clearTemplateStyles(oldTemplateStyles["paging"]); } module.setStyleTemplate(); module.setAllStyles(); }); // this.moduleList.each(function(module){ // if (oldTemplateStyles[module.moduleName]){ // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]); // } // module.setStyleTemplate(); // module.setAllStyles(); // }.bind(this)); }.bind(this)) }.bind(this)) } if (name=="data.viewStyles"){ this.setCustomStyles(); } }, removeStyles: function(from, to){ if (this.json.data.viewStyles[to]){ Object.each(from, function(style, key){ if (this.json.data.viewStyles[to][key] && this.json.data.viewStyles[to][key]==style){ delete this.json.data.viewStyles[to][key]; } }.bind(this)); } }, copyStyles: function(from, to){ if (!this.json.data.viewStyles[to]) this.json.data.viewStyles[to] = {}; Object.each(from, function(style, key){ if (!this.json.data.viewStyles[to][key]) this.json.data.viewStyles[to][key] = style; }.bind(this)); }, saveAs: function(){ var form = new MWF.xApplication.query.StatementDesigner.View.NewNameForm(this, { name : this.data.name + "_" + MWF.xApplication.query.StatementDesigner.LP.copy, query : this.data.query || this.data.application, queryName : this.data.queryName || this.data.applicationName }, { onSave : function( data, callback ){ this._saveAs( data, callback ); }.bind(this) }, { app: this.designer }); form.edit() }, _saveAs : function( data , callback){ var _self = this; var d = this.cloneObject( this.data ); d.isNewView = true; d.id = this.designer.actions.getUUID(); d.name = data.name; d.alias = ""; d.query = data.query; d.queryName = data.queryName; d.application = data.query; d.applicationName = data.queryName; d.pid = d.id + d.id; delete d[this.data.id+"viewFilterType"]; d[d.id+"viewFilterType"]="custom"; d.data.selectList.each( function( entry ){ entry.id = (new MWF.widget.UUID).id; }.bind(this)); this.designer.actions.saveView(d, function(json){ this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"}); if (callback) callback(); }.bind(this)); } }); MWF.xApplication.query.StatementDesigner.View.Column = new Class({ Extends: MWF.xApplication.query.ViewDesigner.View.Column }); MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({ Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar }); MWF.xApplication.query.StatementDesigner.View.Paging = new Class({ Extends: MWF.xApplication.query.ViewDesigner.View.Paging });