Statement.js 62.6 KB
Newer Older
NoSubject's avatar
NoSubject 已提交
1 2 3 4 5 6
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);
U
unknown 已提交
7 8
MWF.xDesktop.requireApp("query.StatementDesigner", "Property", null, false);
MWF.xDesktop.requireApp("query.ViewDesigner", "View", null, false);
NoSubject's avatar
NoSubject 已提交
9
o2.require("o2.widget.JavascriptEditor", null, false);
NoSubject's avatar
NoSubject 已提交
10 11 12 13 14 15 16 17

MWF.xApplication.query.StatementDesigner.Statement = new Class({
    Extends: MWF.widget.Common,
    Implements: [Options, Events],
    options: {
        "style": "default",
        "isView": false,
        "showTab": true,
18
        "propertyPath": "../x_component_query_StatementDesigner/$Statement/statement.html"
NoSubject's avatar
NoSubject 已提交
19 20 21 22 23
    },

    initialize: function(designer, data, options){
        this.setOptions(options);

24 25
        this.path = "../x_component_query_StatementDesigner/$Statement/";
        this.cssPath = "../x_component_query_StatementDesigner/$Statement/"+this.options.style+"/css.wcss";
NoSubject's avatar
NoSubject 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

        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;
R
roo00 已提交
52 53 54 55
        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";
NoSubject's avatar
NoSubject 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68
    },
    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(){
R
roo00 已提交
69 70


NoSubject's avatar
NoSubject 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
        // 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();
U
unknown 已提交
88 89 90 91 92 93 94 95 96 97 98
        // this.showProperty();
        this.selected();
    },
    selected: function(){
        if (this.currentSelectedModule){
            if (this.currentSelectedModule==this){
                return true;
            }else{
                this.currentSelectedModule.unSelected();
            }
        }
U
unknown 已提交
99 100 101
        if( this.view && this.view.domListNode ){
            this.view.domListNode.hide();
        }
U
unknown 已提交
102 103 104

        this.currentSelectedModule = this;
        this.isSelected = true;
NoSubject's avatar
NoSubject 已提交
105 106
        this.showProperty();
    },
U
unknown 已提交
107 108 109 110 111
    unSelected: function(){
        this.currentSelectedModule = null;
        this.isSelected = false;
        this.hideProperty();
    },
NoSubject's avatar
NoSubject 已提交
112 113
    showProperty: function(){
        if (!this.property){
U
unknown 已提交
114
            this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.designerContentArea, this.designer, {
NoSubject's avatar
NoSubject 已提交
115 116 117 118 119 120 121 122 123 124
                "path": this.options.propertyPath,
                "onPostLoad": function(){
                    this.property.show();
                }.bind(this)
            });
            this.property.load();
        }else{
            this.property.show();
        }
    },
U
unknown 已提交
125 126 127
    hideProperty: function(){
        if (this.property) this.property.hide();
    },
U
unknown 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
    loadJpqlTab: function(callback){
        var _self = this;
        MWF.require("MWF.widget.Tab", null, false);

        this.jpqlTab = new MWF.widget.Tab(this.jpqlTabNode, {"style": "script"});
        this.jpqlTab.load();

        this.tabJpqlNode = Element("div");
        this.jpqlTabPageNode.inject( this.tabJpqlNode );

        this.tabCountJpqlNode = Element("div");
        this.countJpqlTabPageNode.inject( this.tabCountJpqlNode );

        this.jpqlPage = this.jpqlTab.addTab(this.tabJpqlNode, this.designer.lp.queryStatement);
        this.countJpqlPage = this.jpqlTab.addTab(this.tabCountJpqlNode, this.designer.lp.countStatement );

        this.jpqlPage.showTabIm();

        // this.jpqlPage.addEvent("postShow", function(){
        //     if( this.view ){
        //         this.view.setContentHeight();
        //         this.view.selected();
        //     }
        // }.bind(this));
        // this.countJpqlPage.addEvent("postShow", function(){
        //     this.selected();
        // }.bind(this));
    },
    loadTab: function(callback){
        var _self = this;
        MWF.require("MWF.widget.Tab", null, false);

        this.tab = new MWF.widget.Tab(this.tabNode, {"style": "script"});
        this.tab.load();

        this.tabRunNode = Element("div");
        this.pageRunNode = new Element("div", {"styles": {"overflow": "auto","background-color":"#fff"}}).inject(this.tabRunNode);
        this.runArea.inject( this.pageRunNode );

        this.tabViewNode = Element("div", {"styles": { "height": "100%" }});
        this.pageViewNode = new Element("div.pageViewNode").inject(this.tabViewNode);
        this.viewArea.inject( this.pageViewNode );

        this.runPage = this.tab.addTab(this.tabRunNode, this.designer.lp.runTest);
        this.viewPage = this.tab.addTab(this.tabViewNode, this.designer.lp.view );

        this.runPage.showTabIm();

        this.viewPage.addEvent("postShow", function(){
            if( this.view ){
                this.view.setContentHeight();
                this.view.selected();
            }
        }.bind(this));
        this.runPage.addEvent("postShow", function(){
            this.selected();
        }.bind(this));
    },
NoSubject's avatar
NoSubject 已提交
186 187 188 189
    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");
U
unknown 已提交
190 191 192

            this.jpqlTabPageNode = this.areaNode.getElement(".o2_statement_statementJpqlTabPageNode");

R
roo00 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
            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");

U
unknown 已提交
208
            this.jpqlTabNode = this.areaNode.getElement(".o2_statement_statementJpqlTabNode");
R
roo00 已提交
209 210 211 212 213 214 215 216 217 218 219 220 221

            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");

NoSubject's avatar
NoSubject 已提交
222
            this.jpqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerJpqlLine");
R
roo00 已提交
223 224


U
unknown 已提交
225 226 227 228 229
            this.countJpqlTabPageNode = this.areaNode.getElement(".o2_statement_statementCountJpqlTabPageNode");
            this.countJpqlArea = this.areaNode.getElement(".o2_statement_statementDesignerCountJpql");
            this.countScriptArea = this.areaNode.getElement(".o2_statement_statementDesignerCountScript");
            this.countJpqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerCountJpqlLine");
            this.loadJpqlTab();
NoSubject's avatar
NoSubject 已提交
230

U
unknown 已提交
231
            this.tabNode = this.areaNode.getElement(".o2_statement_tabNode");
R
roo00 已提交
232

U
unknown 已提交
233 234 235 236 237 238 239 240
            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));
R
roo00 已提交
241 242
            if (this.json.format=="script"){
                this.loadStatementScriptEditor();
U
unknown 已提交
243
                this.loadStatementCountScriptEditor();
R
roo00 已提交
244 245
            }else{
                this.loadStatementEditor();
U
unknown 已提交
246
                this.loadStatementCountEditor();
R
roo00 已提交
247
            }
U
unknown 已提交
248 249 250
            this.loadStatementRunner();

            this.viewArea = this.areaNode.getElement(".o2_statement_viewNode");
U
unknown 已提交
251
            this.loadView();
U
unknown 已提交
252 253 254

            this.loadTab();

NoSubject's avatar
NoSubject 已提交
255 256 257
            this.setEvent();
        }.bind(this));
    },
R
roo00 已提交
258 259
    loadStatementScriptEditor: function(){
        if (! this.scriptEditor){
NoSubject's avatar
NoSubject 已提交
260
            debugger;
R
roo00 已提交
261 262 263
            o2.require("o2.widget.ScriptArea", function(){
                this.scriptEditor = new o2.widget.ScriptArea(this.scriptArea, {
                    "isbind": false,
NoSubject's avatar
NoSubject 已提交
264
                    "maxObj": this.designer.designNode,
R
roo00 已提交
265 266 267 268 269 270 271 272 273
                    "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);
        }
    },
U
unknown 已提交
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
    loadStatementCountScriptEditor: function(){
        if (! this.countScriptEditor){
            debugger;
            o2.require("o2.widget.ScriptArea", function(){
                this.countScriptEditor = new o2.widget.ScriptArea(this.countScriptArea, {
                    "isbind": false,
                    "maxObj": this.designer.designNode,
                    "title": this.designer.lp.scriptTitle,
                    "onChange": function(){
                        this.json.countScriptText = this.countScriptEditor.toJson().code;
                    }.bind(this)
                });
                this.countScriptEditor.load({"code": this.json.countScriptText})
            }.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;

        var tabSize = this.tabNode.getComputedSize();
        y = y - tabSize.totalHeight;

        this.runArea.setStyle("height", ""+y+"px");

        // var titleSize = this.runTitleNode.getComputedSize();
        // y = y - titleSize.totalHeight;

        this.runContentNode.setStyle("height", ""+y+"px");
    },
NoSubject's avatar
NoSubject 已提交
311
    loadStatementEditor: function(){
R
roo00 已提交
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
        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();
NoSubject's avatar
NoSubject 已提交
332

NoSubject's avatar
NoSubject 已提交
333
                    this.editor.addEditorEvent("change", function(){
NoSubject's avatar
NoSubject 已提交
334
                        debugger;
NoSubject's avatar
NoSubject 已提交
335
                        this.data.data = this.editor.getValue();
R
roo00 已提交
336 337
                        this.checkJpqlType();
                    }.bind(this));
NoSubject's avatar
NoSubject 已提交
338 339 340 341 342

                    // this.editor.editor.on("change", function(){
                    //     this.data.data = this.editor.getValue();
                    //     this.checkJpqlType();
                    // }.bind(this));
NoSubject's avatar
NoSubject 已提交
343
                }.bind(this));
R
roo00 已提交
344 345 346
            }.bind(this), false);
        }

U
unknown 已提交
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
    },
    loadStatementCountEditor: function(){
        if (!this.countEditor){
            o2.require("o2.widget.JavascriptEditor", function(){
                this.countEditor = new o2.widget.JavascriptEditor(this.countJpqlEditorNode, {"title": "JPQL", "option": {"mode": "sql"}});
                this.countEditor.load(function(){
                    if (this.json.countData){
                        this.countEditor.editor.setValue(this.json.countData);
                    }else{
                        var table = "table";
                        this.countEditor.editor.setValue("SELECT count(o.id) FROM "+table+" o");
                    }
                    this.json.countData = this.countEditor.editor.getValue();

                    this.countEditor.addEditorEvent("change", function(){
                        debugger;
                        this.data.countData = this.countEditor.getValue();
                    }.bind(this));

                    // this.editor.editor.on("change", function(){
                    //     this.data.data = this.editor.getValue();
                    //     this.checkJpqlType();
                    // }.bind(this));
                }.bind(this));
            }.bind(this), false);
        }

NoSubject's avatar
NoSubject 已提交
374 375 376 377 378 379 380 381 382 383
    },
    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":
R
roo00 已提交
384
                    this.editor.editor.setValue("UPDATE "+table+" o SET ");
NoSubject's avatar
NoSubject 已提交
385 386
                    break;
                case "delete":
R
roo00 已提交
387
                    this.editor.editor.setValue("DELETE "+table+" o WHERE ");
NoSubject's avatar
NoSubject 已提交
388 389
                    break;
                default:
R
roo00 已提交
390
                    this.editor.editor.setValue("SELECT * FROM "+table+" o");
NoSubject's avatar
NoSubject 已提交
391 392 393 394 395
            }
        }
    },

    checkJpqlType: function(){
R
roo00 已提交
396
        var str = this.json.data;
NoSubject's avatar
NoSubject 已提交
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
        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"
        }, {
R
roo00 已提交
421
            "bind": {"lp": this.designer.lp, "data": this.data}
NoSubject's avatar
NoSubject 已提交
422 423 424 425
        },function(){
            if (callback) callback();
        }.bind(this));
    },
U
unknown 已提交
426 427 428 429 430 431 432 433
     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);
    },
NoSubject's avatar
NoSubject 已提交
434
    setEvent: function(){
U
unknown 已提交
435 436 437 438
        this.designerArea.addEvent("click", function (e) {
            this.selected();
            e.stopPropagation();
        }.bind(this));
R
roo00 已提交
439 440 441 442 443 444 445
        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();
U
unknown 已提交
446 447 448 449

                    this.countScriptArea.show();
                    this.countJpqlArea.hide();
                    this.loadStatementCountScriptEditor();
R
roo00 已提交
450 451 452 453
                }else{
                    this.scriptArea.hide();
                    this.jpqlArea.show();
                    this.loadStatementEditor();
U
unknown 已提交
454 455 456 457

                    this.countScriptArea.hide();
                    this.countJpqlArea.show();
                    this.loadStatementCountEditor();
R
roo00 已提交
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
                }
                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));

U
unknown 已提交
541
        this.runActionNode.getFirst().addEvent("click", this.runStatement.bind(this));
U
unknown 已提交
542

R
roo00 已提交
543
        this.dynamicTableSelect.addEvent("click", this.selectTable.bind(this));
NoSubject's avatar
NoSubject 已提交
544 545
        this.jpqlTypeSelect.addEvent("change", function(){
            var t = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value;
U
unknown 已提交
546 547 548 549 550 551 552 553 554 555 556 557 558
            if (t!=this.json.type){
                this.json.type = t;
            }
            if( t!="select"){
                this.jpqlPage.showTabIm();
                this.countJpqlPage.disableTab();

                this.runPage.showTabIm();
                this.viewPage.disableTab();
            }else{
                this.countJpqlPage.enableTab( true );
                this.viewPage.enableTab( true );
            }
NoSubject's avatar
NoSubject 已提交
559 560
        }.bind(this));
    },
R
roo00 已提交
561

NoSubject's avatar
NoSubject 已提交
562 563 564 565 566 567 568 569 570 571
    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;
R
roo00 已提交
572
                    this.dynamicTableContent.set("text", name);
NoSubject's avatar
NoSubject 已提交
573 574 575
                    this.json.table = name;
                    this.json.tableObj = items[0].data;
                }else{
R
roo00 已提交
576
                    this.dynamicTableContent.set("text", "");
NoSubject's avatar
NoSubject 已提交
577 578 579 580 581 582 583 584
                    this.json.table = "";
                }
            }.bind(this)
        });
    },

    runStatement:function(){
        debugger;
R
roo00 已提交
585 586 587 588
        // if (!this.json.data){
        //     this.designer.notice(this.designer.lp.inputStatementData, "error");
        //     return false;
        // }
NoSubject's avatar
NoSubject 已提交
589 590 591 592 593 594 595
        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);
R
roo00 已提交
596
            o2.Actions.get("x_query_assemble_designer").executeStatement(this.json.id, 1, 50 , o, function(json){
NoSubject's avatar
NoSubject 已提交
597
                o2.require("o2.widget.JsonParse", function(){
U
unknown 已提交
598 599 600
                    this.runResultNode.empty();
                    var jsonResult = new o2.widget.JsonParse(json.data, this.runResultNode);
                    jsonResult.load();
NoSubject's avatar
NoSubject 已提交
601 602
                }.bind(this));
                this.runMask.hide();
R
roo00 已提交
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
            }.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, "&lt;");
                errorText = errorText.replace(/\</g, "&gt;");
                MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
            }.bind(this))
NoSubject's avatar
NoSubject 已提交
619 620 621 622
        }.bind(this));
    },

    save: function(callback){
R
roo00 已提交
623
        debugger;
NoSubject's avatar
NoSubject 已提交
624 625 626 627
        if (!this.data.name){
            this.designer.notice(this.designer.lp.inputStatementName, "error");
            return false;
        }
R
roo00 已提交
628 629 630
        //if( !this.data.tableType ){
        //    this.data.tableType = "dynamic";
        //}
R
roo00 已提交
631 632
        if (this.editor) this.data.data = this.editor.editor.getValue();
        if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
NoSubject's avatar
NoSubject 已提交
633

NoSubject's avatar
NoSubject 已提交
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
        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;
        }
R
roo00 已提交
651 652 653
        if (this.editor) this.data.data = this.editor.editor.getValue();
        if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;

NoSubject's avatar
NoSubject 已提交
654 655 656 657 658 659 660 661 662
        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));
U
unknown 已提交
663 664
    },

U
unknown 已提交
665 666 667 668
    loadView : function( callback ){
        this.setViewSize();
        this.designer.addEvent("resize", this.setViewSize.bind(this));

U
unknown 已提交
669 670
        if( !this.data.view )this.data.view = {};
        this.view = new MWF.xApplication.query.StatementDesigner.View(this.designer, this, this.data.view, {});
U
unknown 已提交
671 672 673
        this.view.load( function () {
            this.view.setContentHeight();
        }.bind(this));
U
unknown 已提交
674 675 676 677 678 679 680 681 682 683 684 685
    },
    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;

U
unknown 已提交
686 687 688
        var tabSize = this.tabNode.getComputedSize();
        y = y - tabSize.totalHeight;

U
unknown 已提交
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
        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;

U
unknown 已提交
725
        this.areaNode = new Element("div", {"styles": {"height": "calc(100% - 2px)", "overflow": "auto" }});
U
unknown 已提交
726
        this.areaNode.setStyles(this.css.areaNode);
U
unknown 已提交
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748

        //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));
    },
U
unknown 已提交
749
    load : function( callback ){
U
unknown 已提交
750 751 752 753 754 755 756 757 758 759 760 761 762 763
        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();

U
unknown 已提交
764
            // this.selected();
U
unknown 已提交
765 766 767 768 769 770
            this.setEvent();

            //if (this.options.showTab) this.page.showTabIm();
            this.setViewWidth();

            this.designer.addEvent("resize", this.setViewWidth.bind(this));
U
unknown 已提交
771 772

            if(callback)callback();
U
unknown 已提交
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
        }.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);
        }
    },
U
unknown 已提交
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
    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;
U
unknown 已提交
819
        this.domListNode.show();
U
unknown 已提交
820 821 822 823 824 825 826 827 828
        this.isSelected = true;
        this.showProperty();
    },
    unSelected: function(){
        this.statement.currentSelectedModule = null;
        this.isSelected = false;
        this.areaNode.setStyles(this.css.areaNode);
        this.hideProperty();
    },
U
unknown 已提交
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070

    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();
    },
U
unknown 已提交
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
    setContentHeight: function(){
        var size = this.areaNode.getSize();
        var titleSize = this.viewTitleNode.getSize();
        var actionbarSize = this.actionbarNode ? this.actionbarNode.getSize() : {x:0, y:0};
        var pagingSize = this.pagingNode ? this.pagingNode.getSize() : {x:0, y:0};
        var height = size.y-titleSize.y-actionbarSize.y-pagingSize.y-4;

        this.viewContentScrollNode.setStyle("height", height);

        var contentSize = this.viewContentBodyNode.getSize();
        if (height<contentSize.y) height = contentSize.y+10;

        this.viewContentNode.setStyle("height", height);
        this.contentLeftNode.setStyle("height", height);
        this.contentRightNode.setStyle("height", height);
        //this.viewContentBodyNode.setStyle("min-height", height);
    },
U
unknown 已提交
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
    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){
U
unknown 已提交
1139 1140
            this.viewTitleNode.setStyle("width", ""+(width-2)+"px");
            this.viewAreaNode.setStyle("width", ""+(width-2)+"px");
U
unknown 已提交
1141
        }else{
U
unknown 已提交
1142 1143
            this.viewTitleNode.setStyle("width", ""+(size.x-2)+"px");
            this.viewAreaNode.setStyle("width", ""+(size.x-2)+"px");
U
unknown 已提交
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
        }
        this.setContentColumnWidth();
        this.setContentHeight();
    },

    _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));
NoSubject's avatar
NoSubject 已提交
1231
    }
U
unknown 已提交
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320
// 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));
    // },
    // 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));
    // }
U
unknown 已提交
1321 1322 1323 1324

});

MWF.xApplication.query.StatementDesigner.View.Column = new Class({
U
unknown 已提交
1325
    Extends: MWF.xApplication.query.ViewDesigner.View.Column,
U
unknown 已提交
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
    initialize: function(json, view, next){
        this.propertyPath = "../x_component_query_StatementDesigner/$Statement/column.html";
        this.view = view;
        this.json = json;
        this.next = next;
        this.css = this.view.css;
        this.content = this.view.viewTitleTrNode;
        this.domListNode = this.view.domListNode;
        this.load();
    },
U
unknown 已提交
1336 1337 1338 1339 1340 1341 1342 1343
    selected: function(){
        if (this.view.statement.currentSelectedModule){
            if (this.view.statement.currentSelectedModule==this){
                return true;
            }else{
                this.view.statement.currentSelectedModule.unSelected();
            }
        }
U
unknown 已提交
1344
        this.view.domListNode.show();
U
unknown 已提交
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368
        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();
    }
U
unknown 已提交
1369 1370 1371
});

MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({
U
unknown 已提交
1372
    Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar,
U
unknown 已提交
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
    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();
    },
U
unknown 已提交
1389
    getJsonPath : function(){
U
unknown 已提交
1390
        return "../x_component_query_StatementDesigner/$Statement/toolbars.json";
U
unknown 已提交
1391 1392 1393 1394 1395 1396 1397 1398 1399
    },
    selected: function(){
        if (this.view.statement.currentSelectedModule){
            if (this.view.statement.currentSelectedModule==this){
                return true;
            }else{
                this.view.statement.currentSelectedModule.unSelected();
            }
        }
U
unknown 已提交
1400
        this.view.domListNode.show();
U
unknown 已提交
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412
        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;
U
unknown 已提交
1413
        this.node.setStyles(this.css.toolbarWarpNode);
U
unknown 已提交
1414 1415 1416 1417 1418 1419

        //this.listNode.setStyles(this.css.cloumnListNode);
        this.isSelected = false;
        //this._hideActions();
        this.hideProperty();
    },
U
unknown 已提交
1420 1421 1422
});

MWF.xApplication.query.StatementDesigner.View.Paging = new Class({
U
unknown 已提交
1423 1424 1425 1426 1427 1428 1429 1430 1431
    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();
            }
        }
U
unknown 已提交
1432
        this.view.domListNode.show();
U
unknown 已提交
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
        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();
    }
NoSubject's avatar
NoSubject 已提交
1447
});