| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269 |
- 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();
- this.selected();
- },
- selected: function(){
- if (this.currentSelectedModule){
- if (this.currentSelectedModule==this){
- return true;
- }else{
- this.currentSelectedModule.unSelected();
- }
- }
- this.currentSelectedModule = this;
- this.isSelected = true;
- this.showProperty();
- },
- unSelected: function(){
- this.currentSelectedModule = null;
- this.isSelected = false;
- this.hideProperty();
- },
- 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();
- }
- },
- hideProperty: function(){
- if (this.property) this.property.hide();
- },
- 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; i<this.jpqlTypeSelect.options.length; i++){
- if (this.jpqlTypeSelect.options[i].value==type){
- this.jpqlTypeSelect.options[i].set("selected", true);
- break;
- }
- }
- }
- },
- loadStatementHtml: function(callback){
- this.areaNode.loadAll({
- "css": this.path+this.options.style+"/statement.css",
- "html": this.path+"statementDesigner.html"
- }, {
- "bind": {"lp": this.designer.lp, "data": this.data}
- },function(){
- if (callback) callback();
- }.bind(this));
- },
- // loadStatementRunner: function(){
- // o2.require("o2.widget.JavascriptEditor", function(){
- // this.jsonEditor = new o2.widget.JavascriptEditor(this.runJsonNode, {"title": "JPQL", "option": {"mode": "json"}});
- // this.jsonEditor.load(function(){
- // this.jsonEditor.editor.setValue("{}");
- // }.bind(this));
- // }.bind(this), false);
- // },
- setEvent: function(){
- this.designerArea.addEvent("click", function (e) {
- this.selected();
- e.stopPropagation();
- }.bind(this));
- this.formatTypeArea.getElements("input").addEvent("click", function(e){
- if (e.target.checked){
- var v = e.target.get("value");
- if (v==="script"){
- this.scriptArea.show();
- this.jpqlArea.hide();
- this.loadStatementScriptEditor();
- }else{
- this.scriptArea.hide();
- this.jpqlArea.show();
- this.loadStatementEditor();
- }
- this.json.format = v;
- }
- }.bind(this));
- this.entityCategorySelect.addEvent("change", function(e){
- var entityCategory = e.target.options[e.target.selectedIndex].value;
- switch (entityCategory) {
- case "dynamic":
- this.officialTableArea.hide();
- this.dynamicTableArea.show();
- this.customTableArea.hide();
- break;
- case "custom":
- this.officialTableArea.hide();
- this.dynamicTableArea.hide();
- this.customTableArea.show();
- break;
- default:
- this.officialTableArea.show();
- this.dynamicTableArea.hide();
- this.customTableArea.hide();
- break;
- }
- this.json.entityCategory = entityCategory
- }.bind(this));
- //@todo change table
- this.officialTableSelect.addEvent("change", function(e){
- debugger;
- var entityClassName = e.target.options[e.target.selectedIndex].value;
- this.json.entityClassName = entityClassName;
- if (this.json.format=="jpql"){
- if (this.editor){
- var re = /(.*from\s*)/ig;
- if (this.json.type=="update") re = /(.*update\s*)/ig;
- //if (this.json.type=="select" && this.editor){
- var v = this.json.data;
- var re2 = /(\s+)/ig;
- var arr = re.exec(v);
- if (arr && arr[0]){
- var left = arr[0]
- v = v.substring(left.length, v.length);
- //var ar = re2.exec(v);
- var right = v.substring(v.indexOf(" "),v.length);
- this.json.data = left+entityClassName+right;
- this.editor.editor.setValue(this.json.data);
- }
- //}
- }
- }
- // var className = e.target.options[e.target.selectedIndex].value;
- // if (this.json.type=="select"){
- // this.json.data
- // /(select)*(where|)/g
- // }
- // }.bind(this));
- // this.jpqlTypeSelect.addEvent("change", function(){
- // var type = e.target.options[e.target.selectedIndex].value;
- // switch (entityCategory) {
- // case "update":
- // this.jpqlSelectEditor.hide();
- // this.jpqlUpdateEditor.show();
- // this.jpqlDeleteEditor.hide();
- // this.loadJpqlUpdateEditor();
- // break;
- // case "delete":
- // this.jpqlSelectEditor.hide();
- // this.jpqlUpdateEditor.hide();
- // this.jpqlDeleteEditor.show();
- // break;
- // default:
- // this.jpqlSelectEditor.show();
- // this.jpqlUpdateEditor.hide();
- // this.jpqlDeleteEditor.hide();
- // break;
- // }
- }.bind(this));
- // this.runActionNode.getFirst().addEvent("click", this.runStatement.bind(this));
- this.dynamicTableSelect.addEvent("click", this.selectTable.bind(this));
- this.jpqlTypeSelect.addEvent("change", function(){
- var t = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value;
- if (t!=this.json.type) this.json.type=t;
- }.bind(this));
- },
- selectTable: function(){
- new MWF.O2Selector(this.designer.content, {
- "type": "queryTable",
- "count": 1,
- "values": (this.json.table) ? [this.json.table] : [],
- "title": this.designer.lp.selectTable,
- "onComplete": function(items){
- if (items.length){
- var id = items[0].data.id;
- var name = items[0].data.name;
- this.dynamicTableContent.set("text", name);
- this.json.table = name;
- this.json.tableObj = items[0].data;
- }else{
- this.dynamicTableContent.set("text", "");
- this.json.table = "";
- }
- }.bind(this)
- });
- },
- runStatement:function(){
- debugger;
- // if (!this.json.data){
- // this.designer.notice(this.designer.lp.inputStatementData, "error");
- // return false;
- // }
- o2.require("o2.widget.Mask", null, false);
- this.runMask = new o2.widget.Mask();
- this.runMask.loadNode(this.node);
- this.saveSilence(function(){
- var json = this.jsonEditor.editor.getValue();
- var o = JSON.parse(json);
- o2.Actions.get("x_query_assemble_designer").executeStatement(this.json.id, 1, 50 , o, function(json){
- o2.require("o2.widget.JsonParse", function(){
- // this.runResultNode.empty();
- // var jsonResult = new o2.widget.JsonParse(json.data, this.runResultNode);
- // jsonResult.load();
- }.bind(this));
- this.runMask.hide();
- }.bind(this), function(xhr, text, error){
- debugger;
- if (this.runMask) this.runMask.hide();
- var errorText = error;
- if (xhr){
- var json = JSON.decode(xhr.responseText);
- if (json){
- errorText = json.message.trim() || "request json error";
- }else{
- errorText = "request json error: "+xhr.responseText;
- }
- }
- errorText = errorText.replace(/\</g, "<");
- errorText = errorText.replace(/\</g, ">");
- MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
- }.bind(this))
- }.bind(this));
- },
- save: function(callback){
- debugger;
- if (!this.data.name){
- this.designer.notice(this.designer.lp.inputStatementName, "error");
- return false;
- }
- //if( !this.data.tableType ){
- // this.data.tableType = "dynamic";
- //}
- if (this.editor) this.data.data = this.editor.editor.getValue();
- if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
- this.designer.actions.saveStatement(this.data, function(json){
- this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
- this.data.id = json.data.id;
- if (this.lisNode) {
- this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
- }
- if (callback) callback();
- }.bind(this));
- },
- _setEditStyle: function(){},
- saveSilence: function(callback){
- if (!this.data.name){
- this.designer.notice(this.designer.lp.inputStatementName, "error");
- return false;
- }
- if (this.editor) this.data.data = this.editor.editor.getValue();
- if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
- this.designer.actions.saveStatement(this.data, function(json){
- //this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
- this.data.id = json.data.id;
- if (this.lisNode) {
- this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
- }
- if (callback) callback();
- }.bind(this));
- },
- loadView : function(){
- if( !this.data.view )this.data.view = {};
- this.view = new MWF.xApplication.query.StatementDesigner.View(this.designer, this, this.data.view, {});
- this.view.load();
- },
- setViewSize: function(){
- debugger;
- var size = this.areaNode.getSize();
- var designerSize = this.designerArea.getComputedSize();
- var y = size.y-designerSize.totalHeight;
- var mTop = this.viewArea.getStyle("margin-top").toInt();
- var mBottom = this.viewArea.getStyle("margin-bottom").toInt();
- var pTop = this.viewArea.getStyle("padding-top").toInt();
- var pBottom = this.viewArea.getStyle("padding-bottom").toInt();
- y = y-mTop-mBottom-pTop-pBottom-1;
- this.viewArea.setStyle("height", ""+y+"px");
- // var titleSize = this.runTitleNode.getComputedSize();
- // y = y - titleSize.totalHeight;
- // this.runContentNode.setStyle("height", ""+y+"px");
- }
- });
- MWF.xApplication.query.StatementDesigner.View = new Class({
- Extends: MWF.xApplication.query.ViewDesigner.View,
- Implements: [Options, Events],
- options: {
- "style": "default",
- "isView": false,
- "showTab": true,
- "propertyPath": "../x_component_query_StatementDesigner/$Statement/view.html"
- },
- initialize: function(designer, statement, data, options){
- this.setOptions(options);
- this.path = "../x_component_query_ViewDesigner/$View/";
- this.cssPath = "../x_component_query_ViewDesigner/$View/"+this.options.style+"/css.wcss";
- this._loadCss();
- this.statement = statement;
- this.designer = designer;
- this.data = data;
- // if (!this.data.data) this.data.data = {};
- this.parseData();
- this.node = this.statement.viewArea;
- //this.tab = this.designer.tab;
- this.areaNode = new Element("div", {"styles": {"height": "calc(100% - 2px)", "overflow": "auto" }});
- this.areaNode.setStyles(this.css.areaNode);
- //MWF.require("MWF.widget.ScrollBar", function(){
- // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
- //}.bind(this));
- // this.propertyListNode = this.designer.propertyDomArea;
- //this.propertyNode = this.designer.propertyContentArea;
- // if(this.designer.application) this.data.applicationName = this.designer.application.name;
- // if(this.designer.application) this.data.application = this.designer.application.id;
- // this.isNewView = (this.data.name) ? false : true;
- this.items = [];
- this.view = this;
- // this.autoSave();
- // this.designer.addEvent("queryClose", function(){
- // if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
- // }.bind(this));
- },
- load : function(){
- this.setAreaNodeSize();
- this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
- this.areaNode.inject(this.node);
- this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
- this.loadTemplateStyle( function () {
- this.loadActionbar();
- this.loadView();
- this.loadPaging();
- // this.selected();
- this.setEvent();
- //if (this.options.showTab) this.page.showTabIm();
- this.setViewWidth();
- this.designer.addEvent("resize", this.setViewWidth.bind(this));
- }.bind(this))
- },
- parseData: function(){
- this.json = this.data;
- if( !this.json.data || !this.json.data.events ){
- var url = "../x_component_query_StatementDesigner/$Statement/view.json";
- MWF.getJSON(url, {
- "onSuccess": function(obj){
- if(!this.json.data)this.json.data = obj.data;
- if(!this.json.data.events)this.json.data.events = obj.data.events;
- }.bind(this),
- "onerror": function(text){
- this.notice(text, "error");
- }.bind(this),
- "onRequestFailure": function(xhr){
- this.notice(xhr.responseText, "error");
- }.bind(this)
- },false);
- }
- },
- setEvent: function(){
- this.areaNode.addEvents({
- "click": function(e){ this.selected(); e.stopPropagation(); }.bind(this),
- "mouseover": function(){ if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode_over)}.bind(this),
- "mouseout": function(){if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode)}.bind(this)
- });
- this.refreshNode.addEvent("click", function(e){
- this.loadViewData();
- e.stopPropagation();
- }.bind(this));
- this.addColumnNode.addEvent("click", function(e){
- this.addColumn();
- e.stopPropagation();
- }.bind(this));
- },
- selected: function(){
- debugger;
- if (this.statement.currentSelectedModule){
- if (this.statement.currentSelectedModule==this){
- return true;
- }else{
- this.statement.currentSelectedModule.unSelected();
- }
- }
- this.areaNode.setStyles(this.css.areaNode_selected);
- this.statement.currentSelectedModule = this;
- this.isSelected = true;
- this.showProperty();
- },
- unSelected: function(){
- this.statement.currentSelectedModule = null;
- this.isSelected = false;
- this.areaNode.setStyles(this.css.areaNode);
- this.hideProperty();
- },
- showProperty: function(){
- if (!this.property){
- this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
- "path": this.options.propertyPath,
- "onPostLoad": function(){
- this.property.show();
- }.bind(this)
- });
- this.property.load();
- }else{
- this.property.show();
- }
- },
- hideProperty: function(){
- if (this.property) this.property.hide();
- },
- loadViewData: function(){
- if (this.data.id){
- this.saveSilence(function(){
- this.viewContentBodyNode.empty();
- this.viewContentTableNode = new Element("table", {
- "styles": this.css.viewContentTableNode,
- "border": "0px",
- "cellPadding": "0",
- "cellSpacing": "0"
- }).inject(this.viewContentBodyNode);
- this.designer.actions.loadView(this.data.id, null,function(json){
- var entries = {};
- json.data.selectList.each(function(entry){entries[entry.column] = entry;}.bind(this));
- if (this.json.data.group.column){
- if (json.data.groupGrid.length){
- var groupColumn = null;
- for (var c = 0; c<json.data.selectList.length; c++){
- if (json.data.selectList[c].column === json.data.group.column){
- groupColumn = json.data.selectList[c];
- break;
- }
- }
- json.data.groupGrid.each(function(line, idx){
- var groupTr = new Element("tr", {
- "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode,
- "data-is-group" : "yes"
- }).inject(this.viewContentTableNode);
- var colSpan = this.items.length ;
- var td = new Element("td", {
- "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentGroupTd"] : this.css.viewContentGroupTdNode,
- "colSpan": colSpan
- }).inject(groupTr);
- var groupAreaNode;
- if( this.json.data.viewStyles ){
- groupAreaNode = new Element("div", {"styles": this.json.data.viewStyles["groupCollapseNode"]}).inject(td);
- groupAreaNode.set("text", line.group);
- }else{
- groupAreaNode = new Element("div", {"styles": this.css.viewContentTdGroupNode}).inject(td);
- var groupIconNode = new Element("div", {"styles": this.css.viewContentTdGroupIconNode}).inject(groupAreaNode);
- var groupTextNode = new Element("div", {"styles": this.css.viewContentTdGroupTextNode}).inject(groupAreaNode);
- if (groupColumn){
- //groupTextNode.set("text", (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": line.group, "gridData": json.data.groupGrid, "data": json.data, "entry": line}) : line.group);
- groupTextNode.set("text", line.group);
- }else{
- groupTextNode.set("text", line.group);
- }
- }
- var subtrs = [];
- line.list.each(function(entry){
- var tr = new Element("tr", {
- "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
- }).inject(this.viewContentTableNode);
- tr.setStyle("display", "none");
- //this.createViewCheckboxTd( tr );
- var td = new Element("td", {
- "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
- }).inject(tr);
- Object.each(entries, function(c, k){
- var d = entry.data[k];
- if (d!=undefined){
- if (k!=this.json.data.group.column){
- var td = new Element("td", {
- "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
- }).inject(tr);
- //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
- if (c.isHtml){
- td.set("html", d);
- }else{
- td.set("text", d);
- }
- }
- }
- }.bind(this));
- // Object.each(entry.data, function(d, k){
- // if (k!=this.json.data.group.column){
- // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
- // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
- // }
- // }.bind(this));
- subtrs.push(tr)
- }.bind(this));
- groupAreaNode.store("subtrs", subtrs);
- var _self = this;
- groupAreaNode.addEvent("click", function(){
- var subtrs = this.retrieve("subtrs");
- var iconNode = groupAreaNode.getFirst("div");
- if (subtrs[0]){
- if (subtrs[0].getStyle("display")=="none"){
- subtrs.each(function(subtr){ subtr.setStyle("display", "table-row"); });
- if( iconNode ) {
- iconNode.setStyle("background", "url(" + "../x_component_process_StatementDesigner/$View/default/icon/down.png) center center no-repeat");
- }else{
- this.setStyles( _self.json.data.viewStyles["groupExpandNode"] )
- }
- }else{
- subtrs.each(function(subtr){ subtr.setStyle("display", "none"); });
- if( iconNode ) {
- iconNode.setStyle("background", "url(" + "../x_component_process_StatementDesigner/$View/default/icon/right.png) center center no-repeat");
- }else{
- this.setStyles( _self.json.data.viewStyles["groupCollapseNode"] )
- }
- }
- }
- _self.setContentHeight();
- });
- }.bind(this));
- this.setContentColumnWidth();
- this.setContentHeight();
- }else if(this.json.data.noDataText){
- var noDataTextNodeStyle = this.css.noDataTextNode;
- if( this.json.data.viewStyles ){
- if( this.json.data.viewStyles["noDataTextNode"] ){
- noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
- }else{
- this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
- }
- }
- this.noDataTextNode = new Element( "div", {
- "styles": noDataTextNodeStyle,
- "text" : this.json.data.noDataText
- }).inject( this.viewContentBodyNode );
- }
- }else{
- if (json.data.grid.length){
- json.data.grid.each(function(line, idx){
- var tr = new Element("tr", {
- "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
- }).inject(this.viewContentTableNode);
- //this.createViewCheckboxTd( tr );
- Object.each(entries, function(c, k){
- var d = line.data[k];
- if (d!=undefined){
- var td = new Element("td", {
- "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
- }).inject(tr);
- //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
- if (c.isHtml){
- td.set("html", d);
- }else{
- td.set("text", d);
- }
- //td.set("text", d);
- }
- }.bind(this));
- // Object.each(line.data, function(d, k){
- // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
- // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
- // }.bind(this));
- }.bind(this));
- this.setContentColumnWidth();
- this.setContentHeight();
- }else if(this.json.data.noDataText){
- var noDataTextNodeStyle = this.css.noDataTextNode;
- if( this.json.data.viewStyles ){
- if( this.json.data.viewStyles["noDataTextNode"] ){
- noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
- }else{
- this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
- }
- }
- this.noDataTextNode = new Element( "div", {
- "styles": noDataTextNodeStyle,
- "text" : this.json.data.noDataText
- }).inject( this.viewContentBodyNode );
- }
- }
- }.bind(this));
- }.bind(this));
- }
- },
- addColumn: function(){
- debugger;
- MWF.require("MWF.widget.UUID", function(){
- var id = (new MWF.widget.UUID).id;
- var json = {
- "id": id,
- "column": id,
- "displayName": this.designer.lp.unnamed,
- "orderType": "original"
- };
- if (!this.json.data.selectList) this.json.data.selectList = [];
- this.json.data.selectList.push(json);
- var column = new MWF.xApplication.query.StatementDesigner.View.Column(json, this);
- this.items.push(column);
- column.selected();
- if (this.viewContentTableNode){
- var trs = this.viewContentTableNode.getElements("tr");
- trs.each(function(tr){
- new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
- }.bind(this));
- //this.setContentColumnWidth();
- }
- this.setViewWidth();
- this.addColumnNode.scrollIntoView(true);
- }.bind(this));
- //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
- },
- loadViewColumns: function(){
- // for (var i=0; i<10; i++){
- if (this.json.data.selectList) {
- this.json.data.selectList.each(function (json) {
- this.items.push(new MWF.xApplication.query.StatementDesigner.View.Column(json, this));
- }.bind(this));
- }
- // }
- },
- showActionbar : function( noSetHeight ){
- this.actionbarNode.show();
- if( !this.json.data.actionbarList )this.json.data.actionbarList = [];
- if( !this.actionbarList || this.actionbarList.length == 0 ){
- if( this.json.data.actionbarList.length ){
- this.json.data.actionbarList.each( function(json){
- this.actionbarList.push( new MWF.xApplication.query.StatementDesigner.View.Actionbar( json, this.json.data.actionbarList, this) )
- }.bind(this));
- }else{
- this.actionbarList.push( new MWF.xApplication.query.StatementDesigner.View.Actionbar( null, this.json.data.actionbarList, this) )
- }
- }
- if( !noSetHeight )this.setContentHeight();
- },
- loadPaging: function( noSetHeight ){
- this.pagingNode = new Element("div#pagingNode", {"styles": this.css.pagingNode}).inject(this.areaNode);
- this.pagingList = [];
- if( !this.json.data.pagingList )this.json.data.pagingList = [];
- if( !this.pagingList || this.pagingList.length == 0 ){
- if( this.json.data.pagingList.length ){
- this.json.data.pagingList.each( function(json){
- this.pagingList.push( new MWF.xApplication.query.StatementDesigner.View.Paging( json, this.json.data.pagingList, this) )
- }.bind(this));
- }else{
- this.pagingList.push( new MWF.xApplication.query.StatementDesigner.View.Paging( null, this.json.data.pagingList, this) )
- }
- }
- // if( !noSetHeight )this.setContentHeight();
- },
- setViewWidth: function(){
- if( !this.viewAreaNode )return;
- this.viewAreaNode.setStyle("width", "auto");
- this.viewTitleNode.setStyle("width", "auto");
- var s1 = this.viewTitleTableNode.getSize();
- var s2 = this.refreshNode.getSize();
- var s3 = this.addColumnNode.getSize();
- var width = s1.x+s2.x+s2.x;
- var size = this.areaNode.getSize();
- if (width>size.x){
- this.viewTitleNode.setStyle("width", ""+(width-2)+"px");
- this.viewAreaNode.setStyle("width", ""+(width-2)+"px");
- }else{
- this.viewTitleNode.setStyle("width", ""+(size.x-2)+"px");
- this.viewAreaNode.setStyle("width", ""+(size.x-2)+"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,
- selected: function(){
- if (this.view.statement.currentSelectedModule){
- if (this.view.statement.currentSelectedModule==this){
- return true;
- }else{
- this.view.statement.currentSelectedModule.unSelected();
- }
- }
- this.node.setStyles(this.css.viewTitleColumnNode_selected);
- this.listNode.setStyles(this.css.cloumnListNode_selected);
- new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
- new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
- this.view.statement.currentSelectedModule = this;
- this.isSelected = true;
- this._showActions();
- this.showProperty();
- },
- unSelected: function(){
- this.view.statement.currentSelectedModule = null;
- //this.node.setStyles(this.css.viewTitleColumnNode);
- if (this.isError){
- this.node.setStyles(this.css.viewTitleColumnNode_error)
- }else{
- this.node.setStyles(this.css.viewTitleColumnNode)
- }
- this.listNode.setStyles(this.css.cloumnListNode);
- this.isSelected = false;
- this._hideActions();
- this.hideProperty();
- }
- });
- MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({
- Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar,
- initialize: function(json, jsonList, view, options){
- this.setOptions( options );
- this.propertyPath = "../x_component_query_StatementDesigner/$Statement/actionbar.html";
- this.path = "../x_component_query_ViewDesigner/$View/";
- this.imagePath_default = "../x_component_query_ViewDesigner/$View/";
- this.imagePath_custom = "../x_component_process_FormDesigner/Module/Actionbar/";
- this.cssPath = "../x_component_query_ViewDesigner/$View/"+this.options.style+"/actionbar.wcss";
- this.view = view;
- this.json = json;
- this.jsonList = jsonList;
- this.css = this.view.css;
- this.container = this.view.actionbarNode;
- this.moduleName = "actionbar";
- this.load();
- },
- getJsonPath : function(){
- return "../x_component_query_StatementDesigner/$Statement/toolbars.json";
- },
- selected: function(){
- if (this.view.statement.currentSelectedModule){
- if (this.view.statement.currentSelectedModule==this){
- return true;
- }else{
- this.view.statement.currentSelectedModule.unSelected();
- }
- }
- this.node.setStyles(this.css.toolbarWarpNode_selected);
- //this.listNode.setStyles(this.css.cloumnListNode_selected);
- new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
- //new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
- this.view.statement.currentSelectedModule = this;
- this.isSelected = true;
- //this._showActions();
- this.showProperty();
- },
- unSelected: function(){
- this.view.statement.currentSelectedModule = null;
- this.node.setStyles(this.css.toolbarWarpNode)
- //this.listNode.setStyles(this.css.cloumnListNode);
- this.isSelected = false;
- //this._hideActions();
- this.hideProperty();
- },
- });
- MWF.xApplication.query.StatementDesigner.View.Paging = new Class({
- Extends: MWF.xApplication.query.ViewDesigner.View.Paging,
- selected: function(){
- if (this.view.statement.currentSelectedModule){
- if (this.view.statement.currentSelectedModule==this){
- return true;
- }else{
- this.view.statement.currentSelectedModule.unSelected();
- }
- }
- this.node.setStyles(this.css.pagingWarpNode_selected);
- new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
- this.view.statement.currentSelectedModule = this;
- this.isSelected = true;
- this.showProperty();
- },
- unSelected: function(){
- this.view.statement.currentSelectedModule = null;
- this.node.setStyles(this.css.pagingWarpNode);
- this.isSelected = false;
- this.hideProperty();
- }
- });
|