Statement.js 73.9 KB
Newer Older
NoSubject's avatar
NoSubject 已提交
1 2 3 4 5
MWF.xApplication = MWF.xApplication || {};
MWF.xApplication.query = MWF.xApplication.query || {};
MWF.xApplication.query.StatementDesigner = MWF.xApplication.query.StatementDesigner || {};
MWF.APPDSMD = MWF.xApplication.query.StatementDesigner;

U
unknown 已提交
6
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);
U
unknown 已提交
10
o2.require("o2.widget.UUID", null, false);
NoSubject's avatar
NoSubject 已提交
11 12 13 14 15 16 17 18

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

U
unknown 已提交
22
    initialize: function (designer, data, options) {
NoSubject's avatar
NoSubject 已提交
23 24
        this.setOptions(options);

25
        this.path = "../x_component_query_StatementDesigner/$Statement/";
U
unknown 已提交
26
        this.cssPath = "../x_component_query_StatementDesigner/$Statement/" + this.options.style + "/css.wcss";
NoSubject's avatar
NoSubject 已提交
27 28 29 30 31 32 33 34 35 36 37 38

        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;

U
unknown 已提交
39 40
        if (this.designer.application) this.data.applicationName = this.designer.application.name;
        if (this.designer.application) this.data.application = this.designer.application.id;
NoSubject's avatar
NoSubject 已提交
41 42 43 44 45 46

        this.isNewStatement = (this.data.id) ? false : true;

        this.view = this;

        this.autoSave();
U
unknown 已提交
47
        this.designer.addEvent("queryClose", function () {
NoSubject's avatar
NoSubject 已提交
48 49 50
            if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
        }.bind(this));
    },
U
unknown 已提交
51
    parseData: function () {
NoSubject's avatar
NoSubject 已提交
52
        this.json = this.data;
R
roo00 已提交
53 54 55 56
        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 已提交
57
    },
U
unknown 已提交
58 59
    autoSave: function () {
        this.autoSaveTimerID = window.setInterval(function () {
NoSubject's avatar
NoSubject 已提交
60
            if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFAutoSaveCheck");
U
unknown 已提交
61 62
            if (this.autoSaveCheckNode) {
                if (this.autoSaveCheckNode.get("checked")) {
NoSubject's avatar
NoSubject 已提交
63 64 65 66 67 68
                    this.save();
                }
            }
        }.bind(this), 60000);
    },

U
unknown 已提交
69
    load: function () {
R
roo00 已提交
70 71


NoSubject's avatar
NoSubject 已提交
72 73 74 75
        // this.setAreaNodeSize();
        // this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
        this.areaNode.inject(this.node);

U
unknown 已提交
76
        this.designer.statementListAreaNode.getChildren().each(function (node) {
NoSubject's avatar
NoSubject 已提交
77
            var statement = node.retrieve("statement");
U
unknown 已提交
78 79
            if (statement.id == this.data.id) {
                if (this.designer.currentListStatementItem) {
NoSubject's avatar
NoSubject 已提交
80 81 82 83 84 85 86 87 88
                    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 已提交
89 90 91
        // this.showProperty();
        this.selected();
    },
U
unknown 已提交
92 93 94
    selected: function () {
        if (this.currentSelectedModule) {
            if (this.currentSelectedModule == this) {
U
unknown 已提交
95
                return true;
U
unknown 已提交
96
            } else {
U
unknown 已提交
97 98 99
                this.currentSelectedModule.unSelected();
            }
        }
U
unknown 已提交
100
        if (this.view && this.view.domListNode) {
U
unknown 已提交
101 102
            this.view.domListNode.hide();
        }
U
unknown 已提交
103 104 105

        this.currentSelectedModule = this;
        this.isSelected = true;
NoSubject's avatar
NoSubject 已提交
106 107
        this.showProperty();
    },
U
unknown 已提交
108
    unSelected: function () {
U
unknown 已提交
109 110 111 112
        this.currentSelectedModule = null;
        this.isSelected = false;
        this.hideProperty();
    },
U
unknown 已提交
113 114
    showProperty: function () {
        if (!this.property) {
U
unknown 已提交
115
            this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.designerContentArea, this.designer, {
NoSubject's avatar
NoSubject 已提交
116
                "path": this.options.propertyPath,
U
unknown 已提交
117
                "onPostLoad": function () {
NoSubject's avatar
NoSubject 已提交
118 119 120 121
                    this.property.show();
                }.bind(this)
            });
            this.property.load();
U
unknown 已提交
122
        } else {
NoSubject's avatar
NoSubject 已提交
123 124 125
            this.property.show();
        }
    },
U
unknown 已提交
126
    hideProperty: function () {
U
unknown 已提交
127 128
        if (this.property) this.property.hide();
    },
U
unknown 已提交
129
    loadJpqlTab: function (callback) {
U
unknown 已提交
130 131 132 133 134 135 136
        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");
U
unknown 已提交
137
        this.jpqlTabPageNode.inject(this.tabJpqlNode);
U
unknown 已提交
138 139

        this.tabCountJpqlNode = Element("div");
U
unknown 已提交
140
        this.countJpqlTabPageNode.inject(this.tabCountJpqlNode);
U
unknown 已提交
141 142

        this.jpqlPage = this.jpqlTab.addTab(this.tabJpqlNode, this.designer.lp.queryStatement);
U
unknown 已提交
143
        this.countJpqlPage = this.jpqlTab.addTab(this.tabCountJpqlNode, this.designer.lp.countStatement);
U
unknown 已提交
144 145 146 147 148 149 150 151 152 153 154 155 156

        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));
    },
U
unknown 已提交
157
    loadTab: function (callback) {
U
unknown 已提交
158 159 160 161 162 163 164
        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");
U
unknown 已提交
165 166 167 168 169 170 171
        this.pageRunNode = new Element("div", {
            "styles": {
                "overflow": "auto",
                "background-color": "#fff"
            }
        }).inject(this.tabRunNode);
        this.runArea.inject(this.pageRunNode);
U
unknown 已提交
172

U
unknown 已提交
173
        this.tabViewNode = Element("div", {"styles": {"height": "100%"}});
U
unknown 已提交
174
        this.pageViewNode = new Element("div.pageViewNode").inject(this.tabViewNode);
U
unknown 已提交
175
        this.viewArea.inject(this.pageViewNode);
U
unknown 已提交
176 177

        this.runPage = this.tab.addTab(this.tabRunNode, this.designer.lp.runTest);
U
unknown 已提交
178
        this.viewPage = this.tab.addTab(this.tabViewNode, this.designer.lp.view);
U
unknown 已提交
179 180 181

        this.runPage.showTabIm();

U
unknown 已提交
182 183
        this.viewPage.addEvent("postShow", function () {
            if (this.view) {
U
unknown 已提交
184 185 186 187
                this.view.setContentHeight();
                this.view.selected();
            }
        }.bind(this));
U
unknown 已提交
188
        this.runPage.addEvent("postShow", function () {
U
unknown 已提交
189 190 191
            this.selected();
        }.bind(this));
    },
U
unknown 已提交
192
    loadStatement: function () {
NoSubject's avatar
NoSubject 已提交
193
        //this.statementDesignerNode = new Element("div", {"styles": this.css.statementDesignerNode}).inject(this.areaNode);
U
unknown 已提交
194
        this.loadStatementHtml(function () {
NoSubject's avatar
NoSubject 已提交
195
            this.designerArea = this.areaNode.getElement(".o2_statement_statementDesignerNode");
U
unknown 已提交
196 197 198

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

R
roo00 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
            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 已提交
214
            this.jpqlTabNode = this.areaNode.getElement(".o2_statement_statementJpqlTabNode");
R
roo00 已提交
215 216 217 218 219 220 221 222 223 224 225 226

            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 已提交
227
            this.jpqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerJpqlLine");
R
roo00 已提交
228 229


U
unknown 已提交
230 231 232 233 234
            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 已提交
235

236 237
            this.resizeNode = this.areaNode.getElement(".o2_statement_resizeNode");

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

U
unknown 已提交
240 241 242 243 244 245 246 247
            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));
U
unknown 已提交
248
            if (this.json.format == "script") {
R
roo00 已提交
249
                this.loadStatementScriptEditor();
U
unknown 已提交
250
                this.loadStatementCountScriptEditor();
U
unknown 已提交
251
            } else {
R
roo00 已提交
252
                this.loadStatementEditor();
U
unknown 已提交
253
                this.loadStatementCountEditor();
R
roo00 已提交
254
            }
U
unknown 已提交
255 256 257
            this.loadStatementRunner();

            this.viewArea = this.areaNode.getElement(".o2_statement_viewNode");
U
unknown 已提交
258
            this.loadView();
U
unknown 已提交
259 260 261

            this.loadTab();

NoSubject's avatar
NoSubject 已提交
262
            this.setEvent();
263
            this.loadVerticalResize();
NoSubject's avatar
NoSubject 已提交
264 265
        }.bind(this));
    },
266 267 268 269 270 271 272 273 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
    loadVerticalResize: function(){
        this.verticalResize = new Drag(this.resizeNode, {
            "snap": 10,
            "onStart": function(el, e){
                var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
                var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
                el.store("position", {"x": x, "y": y});

                var size = this.designerArea.getSize(); //designerArea
                el.store("initialHeight", size.y);

                var allSize = this.areaNode.getSize();
                el.store("initialAllHeight", allSize.y);
            }.bind(this),
            "onDrag": function(el, e){

                var allHeight = el.retrieve("initialAllHeight").toFloat(); //this.areaNode.getSize();

                //			var x = e.event.x;
                var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
                var position = el.retrieve("position");
                var dy = y.toFloat()-position.y.toFloat();

                var initialHeight = el.retrieve("initialHeight").toFloat();
                var height = initialHeight+dy;
                if (height < 180) height = 180;
                if (height > allHeight-180) height = allHeight-180;

                this.designerAreaPercent = height/allHeight;

                this.setVerticalResize();

            }.bind(this)
        });
    },
    setVerticalResize: function(){
        var size = this.areaNode.getSize();

        var height = size.y;

U
unknown 已提交
306
        var designAreaHeight = this.designerAreaPercent*height - 52;
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
        // var runAreaHeight = height-designAreaHeight;

        this.designerArea.setStyle("height", ""+designAreaHeight+"px");

        debugger;

        var editorHeight = designAreaHeight - 98;

        if(this.jpqlEditorNode)this.jpqlEditorNode.setStyle( "height", ""+editorHeight+"px" );
        if(this.countJpqlEditorNode)this.countJpqlEditorNode.setStyle( "height", ""+editorHeight+"px" );
        if(this.scriptArea)this.scriptArea.setStyle( "height", ""+editorHeight+"px" );
        if(this.countScriptArea)this.countScriptArea.setStyle( "height", ""+editorHeight+"px" );

        if( this.editor )this.editor.resize();
        if( this.countEditor )this.countEditor.resize();
        if( this.scriptEditor ){
            this.scriptEditor.container.setStyle("height", ""+editorHeight+"px");
            this.scriptEditor.resizeContentNodeSize();
        }
        if( this.countScriptEditor ){
            this.countScriptEditor.container.setStyle("height", ""+editorHeight+"px");
            this.countScriptEditor.resizeContentNodeSize();
        }

        // this.tabNode.setStyle("height", ""+runAreaHeight+"px");
        this.setRunnerSize();
        if( this.view ){
            this.setViewSize();
            this.view.setContentHeight()
        }
    },
U
unknown 已提交
338 339
    loadStatementScriptEditor: function () {
        if (!this.scriptEditor) {
NoSubject's avatar
NoSubject 已提交
340
            debugger;
U
unknown 已提交
341
            o2.require("o2.widget.ScriptArea", function () {
R
roo00 已提交
342 343
                this.scriptEditor = new o2.widget.ScriptArea(this.scriptArea, {
                    "isbind": false,
NoSubject's avatar
NoSubject 已提交
344
                    "maxObj": this.designer.designNode,
R
roo00 已提交
345
                    "title": this.designer.lp.scriptTitle,
U
unknown 已提交
346
                    "onChange": function () {
R
roo00 已提交
347 348 349 350 351 352 353
                        this.json.scriptText = this.scriptEditor.toJson().code;
                    }.bind(this)
                });
                this.scriptEditor.load({"code": this.json.scriptText})
            }.bind(this), false);
        }
    },
U
unknown 已提交
354 355
    loadStatementCountScriptEditor: function () {
        if (!this.countScriptEditor) {
U
unknown 已提交
356
            debugger;
U
unknown 已提交
357
            o2.require("o2.widget.ScriptArea", function () {
U
unknown 已提交
358 359 360 361
                this.countScriptEditor = new o2.widget.ScriptArea(this.countScriptArea, {
                    "isbind": false,
                    "maxObj": this.designer.designNode,
                    "title": this.designer.lp.scriptTitle,
U
unknown 已提交
362
                    "onChange": function () {
U
unknown 已提交
363 364 365 366 367 368 369
                        this.json.countScriptText = this.countScriptEditor.toJson().code;
                    }.bind(this)
                });
                this.countScriptEditor.load({"code": this.json.countScriptText})
            }.bind(this), false);
        }
    },
U
unknown 已提交
370
    setRunnerSize: function () {
U
unknown 已提交
371 372 373
        debugger;
        var size = this.areaNode.getSize();
        var designerSize = this.designerArea.getComputedSize();
374 375 376
        var reizeNodeSize = this.resizeNode.getComputedSize();

        var y = size.y - designerSize.totalHeight - reizeNodeSize.totalHeight;
U
unknown 已提交
377 378 379 380
        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();
381
        y = y - mTop - mBottom - pTop - pBottom - 5;
U
unknown 已提交
382 383 384 385

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

U
unknown 已提交
386
        this.runArea.setStyle("height", "" + y + "px");
U
unknown 已提交
387 388 389 390

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

U
unknown 已提交
391
        this.runContentNode.setStyle("height", "" + y + "px");
U
unknown 已提交
392
    },
U
unknown 已提交
393 394 395 396 397 398 399 400 401
    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) {
R
roo00 已提交
402
                        this.editor.editor.setValue(this.json.data);
U
unknown 已提交
403
                    } else {
R
roo00 已提交
404 405 406
                        var table = "table";
                        switch (this.json.type) {
                            case "update":
U
unknown 已提交
407
                                this.editor.editor.setValue("UPDATE " + table + " o SET ");
R
roo00 已提交
408 409
                                break;
                            case "delete":
U
unknown 已提交
410
                                this.editor.editor.setValue("DELETE " + table + " o WHERE ");
R
roo00 已提交
411 412
                                break;
                            default:
U
unknown 已提交
413
                                this.editor.editor.setValue("SELECT o FROM " + table + " o");
R
roo00 已提交
414 415 416
                        }
                    }
                    this.json.data = this.editor.editor.getValue();
NoSubject's avatar
NoSubject 已提交
417

U
unknown 已提交
418
                    this.editor.addEditorEvent("change", function () {
NoSubject's avatar
NoSubject 已提交
419
                        debugger;
NoSubject's avatar
NoSubject 已提交
420
                        this.data.data = this.editor.getValue();
R
roo00 已提交
421 422
                        this.checkJpqlType();
                    }.bind(this));
NoSubject's avatar
NoSubject 已提交
423 424 425 426 427

                    // this.editor.editor.on("change", function(){
                    //     this.data.data = this.editor.getValue();
                    //     this.checkJpqlType();
                    // }.bind(this));
NoSubject's avatar
NoSubject 已提交
428
                }.bind(this));
R
roo00 已提交
429 430 431
            }.bind(this), false);
        }

U
unknown 已提交
432
    },
U
unknown 已提交
433 434 435 436 437 438 439 440 441
    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) {
U
unknown 已提交
442
                        this.countEditor.editor.setValue(this.json.countData);
U
unknown 已提交
443
                    } else {
U
unknown 已提交
444
                        var table = "table";
U
unknown 已提交
445
                        this.countEditor.editor.setValue("SELECT count(o.id) FROM " + table + " o");
U
unknown 已提交
446 447 448
                    }
                    this.json.countData = this.countEditor.editor.getValue();

U
unknown 已提交
449
                    this.countEditor.addEditorEvent("change", function () {
U
unknown 已提交
450 451 452 453 454 455 456 457 458 459 460 461
                        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 已提交
462
    },
U
unknown 已提交
463
    setSatementTable: function () {
NoSubject's avatar
NoSubject 已提交
464 465
        if (!this.json.type) this.json.type = "select";
        this.changeType(this.json.type, true);
U
unknown 已提交
466
        if (this.json.data) {
NoSubject's avatar
NoSubject 已提交
467
            this.editor.editor.setValue(this.json.data);
U
unknown 已提交
468
        } else {
NoSubject's avatar
NoSubject 已提交
469 470 471
            var table = (this.json.tableObj) ? this.json.tableObj.name : "table";
            switch (this.json.type) {
                case "update":
U
unknown 已提交
472
                    this.editor.editor.setValue("UPDATE " + table + " o SET ");
NoSubject's avatar
NoSubject 已提交
473 474
                    break;
                case "delete":
U
unknown 已提交
475
                    this.editor.editor.setValue("DELETE " + table + " o WHERE ");
NoSubject's avatar
NoSubject 已提交
476 477
                    break;
                default:
U
unknown 已提交
478
                    this.editor.editor.setValue("SELECT o FROM " + table + " o");
NoSubject's avatar
NoSubject 已提交
479 480 481 482
            }
        }
    },

U
unknown 已提交
483
    checkJpqlType: function () {
R
roo00 已提交
484
        var str = this.json.data;
NoSubject's avatar
NoSubject 已提交
485 486 487 488 489 490 491 492
        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");
    },
U
unknown 已提交
493 494 495 496 497
    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) {
NoSubject's avatar
NoSubject 已提交
498 499 500 501 502 503
                    this.jpqlTypeSelect.options[i].set("selected", true);
                    break;
                }
            }
        }
    },
U
unknown 已提交
504
    loadStatementHtml: function (callback) {
NoSubject's avatar
NoSubject 已提交
505
        this.areaNode.loadAll({
U
unknown 已提交
506 507
            "css": this.path + this.options.style + "/statement.css",
            "html": this.path + "statementDesigner.html"
NoSubject's avatar
NoSubject 已提交
508
        }, {
R
roo00 已提交
509
            "bind": {"lp": this.designer.lp, "data": this.data}
U
unknown 已提交
510
        }, function () {
NoSubject's avatar
NoSubject 已提交
511 512 513
            if (callback) callback();
        }.bind(this));
    },
U
unknown 已提交
514 515 516 517 518 519 520
    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 () {
U
unknown 已提交
521
                this.jsonEditor.editor.setValue(this.data.testParameters || "{}");
U
unknown 已提交
522 523 524
            }.bind(this));
        }.bind(this), false);
    },
U
unknown 已提交
525
    setEvent: function () {
U
unknown 已提交
526 527 528 529
        this.designerArea.addEvent("click", function (e) {
            this.selected();
            e.stopPropagation();
        }.bind(this));
U
unknown 已提交
530 531
        this.formatTypeArea.getElements("input").addEvent("click", function (e) {
            if (e.target.checked) {
R
roo00 已提交
532
                var v = e.target.get("value");
U
unknown 已提交
533
                if (v === "script") {
R
roo00 已提交
534 535 536
                    this.scriptArea.show();
                    this.jpqlArea.hide();
                    this.loadStatementScriptEditor();
U
unknown 已提交
537 538 539 540

                    this.countScriptArea.show();
                    this.countJpqlArea.hide();
                    this.loadStatementCountScriptEditor();
U
unknown 已提交
541
                } else {
R
roo00 已提交
542 543 544
                    this.scriptArea.hide();
                    this.jpqlArea.show();
                    this.loadStatementEditor();
U
unknown 已提交
545 546 547 548

                    this.countScriptArea.hide();
                    this.countJpqlArea.show();
                    this.loadStatementCountEditor();
R
roo00 已提交
549 550 551 552
                }
                this.json.format = v;
            }
        }.bind(this));
U
unknown 已提交
553
        this.entityCategorySelect.addEvent("change", function (e) {
R
roo00 已提交
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
            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
U
unknown 已提交
575
        this.officialTableSelect.addEvent("change", function (e) {
R
roo00 已提交
576 577 578
            debugger;
            var entityClassName = e.target.options[e.target.selectedIndex].value;
            this.json.entityClassName = entityClassName;
U
unknown 已提交
579 580 581
            if( entityClassName ){
                this.changeEditorEntityClassName( entityClassName.split(".").getLast() );
            }
R
roo00 已提交
582 583


U
unknown 已提交
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
            //     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;
            //     }
R
roo00 已提交
611 612
        }.bind(this));

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

R
roo00 已提交
615
        this.dynamicTableSelect.addEvent("click", this.selectTable.bind(this));
U
unknown 已提交
616
        this.jpqlTypeSelect.addEvent("change", function () {
NoSubject's avatar
NoSubject 已提交
617
            var t = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value;
U
unknown 已提交
618
            if (t != this.json.type) {
U
unknown 已提交
619 620
                this.json.type = t;
            }
U
unknown 已提交
621
            if (t != "select") {
U
unknown 已提交
622 623 624 625 626
                this.jpqlPage.showTabIm();
                this.countJpqlPage.disableTab();

                this.runPage.showTabIm();
                this.viewPage.disableTab();
U
unknown 已提交
627 628 629
            } else {
                this.countJpqlPage.enableTab(true);
                this.viewPage.enableTab(true);
U
unknown 已提交
630
            }
NoSubject's avatar
NoSubject 已提交
631 632
        }.bind(this));
    },
U
unknown 已提交
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
    changeEditorEntityClassName : function( 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);
                }

                //}
            }

            if( this.countEditor ){
                var re = /(.*from\s*)/ig;
                var v = this.json.countData;

                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.countData = left + entityClassName + right;
                    this.countEditor.editor.setValue(this.json.countData);
                }
            }

        }
    },
R
roo00 已提交
674

U
unknown 已提交
675
    selectTable: function () {
NoSubject's avatar
NoSubject 已提交
676 677 678 679 680
        new MWF.O2Selector(this.designer.content, {
            "type": "queryTable",
            "count": 1,
            "values": (this.json.table) ? [this.json.table] : [],
            "title": this.designer.lp.selectTable,
U
unknown 已提交
681 682
            "onComplete": function (items) {
                if (items.length) {
NoSubject's avatar
NoSubject 已提交
683 684
                    var id = items[0].data.id;
                    var name = items[0].data.name;
R
roo00 已提交
685
                    this.dynamicTableContent.set("text", name);
NoSubject's avatar
NoSubject 已提交
686 687
                    this.json.table = name;
                    this.json.tableObj = items[0].data;
U
unknown 已提交
688 689
                    this.changeEditorEntityClassName( name );
                    if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
U
unknown 已提交
690
                } else {
R
roo00 已提交
691
                    this.dynamicTableContent.set("text", "");
NoSubject's avatar
NoSubject 已提交
692
                    this.json.table = "";
U
unknown 已提交
693
                    if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
NoSubject's avatar
NoSubject 已提交
694 695 696 697 698
                }
            }.bind(this)
        });
    },

U
unknown 已提交
699
    runStatement: function () {
NoSubject's avatar
NoSubject 已提交
700
        debugger;
R
roo00 已提交
701 702 703 704
        // if (!this.json.data){
        //     this.designer.notice(this.designer.lp.inputStatementData, "error");
        //     return false;
        // }
NoSubject's avatar
NoSubject 已提交
705 706 707 708
        o2.require("o2.widget.Mask", null, false);
        this.runMask = new o2.widget.Mask();
        this.runMask.loadNode(this.node);

U
unknown 已提交
709
        this.saveSilence(function () {
710
            debugger;
U
unknown 已提交
711
            this.execute(function (json) {
U
unknown 已提交
712
                this.executeData = json;
U
unknown 已提交
713
                o2.require("o2.widget.JsonParse", function () {
U
unknown 已提交
714
                    this.runResultNode.empty();
715
                    var jsonResult = new o2.widget.JsonParse(json, this.runResultNode);
U
unknown 已提交
716
                    jsonResult.load();
NoSubject's avatar
NoSubject 已提交
717
                }.bind(this));
U
unknown 已提交
718 719 720 721 722 723 724 725
                if (this.view) {
                    var flag = true;
                    if (this.data.type !== "select") flag = false;
                    if (this.data.format === "script" && !this.data.scriptText) flag = false;
                    if (this.data.format !== "script" && !this.data.data) flag = false;
                    if (flag) this.view.loadViewData();
                }
                this.setColumnDataPath(json);
NoSubject's avatar
NoSubject 已提交
726
                this.runMask.hide();
U
unknown 已提交
727
            }.bind(this), function () {
R
roo00 已提交
728 729
                if (this.runMask) this.runMask.hide();
            }.bind(this))
U
unknown 已提交
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782

            // var json = this.jsonEditor.editor.getValue();
            // var o = JSON.parse(json);
            //
            // var mode = "data";
            // if( this.data.type === "select" ){
            //     if( this.data.format === "script" ){
            //         if( this.data.scriptText && this.data.countScriptText ){
            //             mode = "all"
            //         }else if( this.data.scriptText && !this.data.countScriptText ){
            //             mode = "data"
            //         }else if( !this.data.scriptText && this.data.countScriptText ){
            //             mode = "count"
            //         }else{
            //             this.designer.notice(this.designer.lp.inputStatementData, "error");
            //             return false;
            //         }
            //     }else{
            //         if( this.data.data && this.data.countData ){
            //             mode = "all"
            //         }else if( this.data.data && !this.data.countData ){
            //             mode = "data"
            //         }else if( !this.data.data && this.data.countData ){
            //             mode = "count"
            //         }else{
            //             this.designer.notice(this.designer.lp.inputStatementData, "error");
            //             return false;
            //         }
            //     }
            // }
            // o2.Actions.load("x_query_assemble_designer").StatementAction.executeV2(this.json.id, mode, 1, 50 , o, function(json){
            //     o2.require("o2.widget.JsonParse", function(){
            //         this.runResultNode.empty();
            //         var jsonResult = new o2.widget.JsonParse(json, 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, "&lt;");
            //     errorText = errorText.replace(/\</g, "&gt;");
            //     MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
            // }.bind(this))
NoSubject's avatar
NoSubject 已提交
783 784
        }.bind(this));
    },
U
unknown 已提交
785 786 787 788 789 790 791 792 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 819 820 821 822
    setColumnDataPath: function (json) {
        if (this.data.type !== "select") return;
        if (this.data.format === "script" && !this.data.scriptText) return;
        if (this.data.format !== "script" && !this.data.data) return;
        this.columnDataPathList = [];
        debugger;
        var addPath = function (value, key) {
            if (typeOf(value) === "array") {
                Array.each(value, function (v, idx) {
                    var path = (key || typeOf(key) === "number") ? (key + "." + idx) : idx.toString();
                    if (!this.columnDataPathList.contains(path)) this.columnDataPathList.push(path);
                    if (typeOf(v) === "array" || typeOf(v) === "object") addPath(v, path);
                }.bind(this))
            } else if (typeOf(value) === "object") {
                Object.each(value, function (v, k) {
                    var path = (key || typeOf(key) === "number") ? (key + "." + k) : k;
                    if (!this.columnDataPathList.contains(path)) this.columnDataPathList.push(path);
                    if (typeOf(v) === "array" || typeOf(v) === "object") addPath(v, path);
                    addPath(v, path);
                }.bind(this))
            } else {
                // if( key && !this.columnDataPathList.indexOf(key) )this.columnDataPathList.push(key);
            }
        }.bind(this);
        for (var i = 0; i < json.data.length && i < 10; i++) {
            var d = json.data[i];
            addPath(d);
        }
        this.columnDataPathList.sort();
        if (this.view && this.view.items) {
            this.view.items.each(function (column) {
                column.refreshColumnPathData()
            })
        }
    },
    getColumnDataPath: function () {
        return this.columnDataPathList || [];
    },
U
unknown 已提交
823 824 825 826 827 828 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
    execute: function (success, failure) {
        var json = this.jsonEditor.editor.getValue();
        var o = JSON.parse(json);

        var mode = "data";
        if (this.data.type === "select") {
            if (this.data.format === "script") {
                if (this.data.scriptText && this.data.countScriptText) {
                    mode = "all"
                } else if (this.data.scriptText && !this.data.countScriptText) {
                    mode = "data"
                } else if (!this.data.scriptText && this.data.countScriptText) {
                    mode = "count"
                } else {
                    this.designer.notice(this.designer.lp.inputStatementData, "error");
                    return false;
                }
            } else {
                if (this.data.data && this.data.countData) {
                    mode = "all"
                } else if (this.data.data && !this.data.countData) {
                    mode = "data"
                } else if (!this.data.data && this.data.countData) {
                    mode = "count"
                } else {
                    this.designer.notice(this.designer.lp.inputStatementData, "error");
                    return false;
                }
            }
        }
        o2.Actions.load("x_query_assemble_designer").StatementAction.executeV2(this.json.id, mode, 1, 50, o, function (json) {
            if (success) success(json)
        }.bind(this), function (xhr, text, error) {
            debugger;
            if (failure) failure();
            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 已提交
872

U
unknown 已提交
873
    save: function (callback) {
R
roo00 已提交
874
        debugger;
U
unknown 已提交
875
        if (!this.data.name) {
NoSubject's avatar
NoSubject 已提交
876 877 878
            this.designer.notice(this.designer.lp.inputStatementName, "error");
            return false;
        }
U
unknown 已提交
879

U
unknown 已提交
880
        if (typeOf(this.viewJson) === "object") {
U
unknown 已提交
881
            this.data.view = JSON.stringify(this.viewJson);
U
unknown 已提交
882
            if(!this.data.view.group)this.data.view.group = {};
U
unknown 已提交
883
        }
R
roo00 已提交
884 885 886
        //if( !this.data.tableType ){
        //    this.data.tableType = "dynamic";
        //}
R
roo00 已提交
887 888
        if (this.editor) this.data.data = this.editor.editor.getValue();
        if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
U
unknown 已提交
889
        if (this.jsonEditor) this.data.testParameters = this.jsonEditor.editor.getValue();
NoSubject's avatar
NoSubject 已提交
890

U
unknown 已提交
891
        this.designer.actions.saveStatement(this.data, function (json) {
NoSubject's avatar
NoSubject 已提交
892 893 894 895
            this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});

            this.data.id = json.data.id;
            if (this.lisNode) {
U
unknown 已提交
896
                this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
NoSubject's avatar
NoSubject 已提交
897 898 899 900
            }
            if (callback) callback();
        }.bind(this));
    },
U
unknown 已提交
901 902
    _setEditStyle: function () {
    },
NoSubject's avatar
NoSubject 已提交
903

U
unknown 已提交
904 905
    saveSilence: function (callback) {
        if (!this.data.name) {
NoSubject's avatar
NoSubject 已提交
906 907 908
            this.designer.notice(this.designer.lp.inputStatementName, "error");
            return false;
        }
U
unknown 已提交
909

U
unknown 已提交
910
        if (typeOf(this.viewJson) === "object") {
U
unknown 已提交
911 912 913
            this.data.view = JSON.stringify(this.viewJson);
        }

R
roo00 已提交
914 915
        if (this.editor) this.data.data = this.editor.editor.getValue();
        if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
U
unknown 已提交
916
        if (this.jsonEditor) this.data.testParameters = this.jsonEditor.editor.getValue();
R
roo00 已提交
917

U
unknown 已提交
918
        this.designer.actions.saveStatement(this.data, function (json) {
NoSubject's avatar
NoSubject 已提交
919 920 921 922
            //this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});

            this.data.id = json.data.id;
            if (this.lisNode) {
U
unknown 已提交
923
                this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
NoSubject's avatar
NoSubject 已提交
924 925 926
            }
            if (callback) callback();
        }.bind(this));
U
unknown 已提交
927 928
    },

U
unknown 已提交
929
    loadView: function (callback) {
U
unknown 已提交
930 931 932
        this.setViewSize();
        this.designer.addEvent("resize", this.setViewSize.bind(this));

U
unknown 已提交
933
        if (!this.data.view) {
U
unknown 已提交
934
            this.viewJson = {};
U
unknown 已提交
935
        } else {
U
unknown 已提交
936 937 938
            this.viewJson = JSON.parse(this.data.view)
        }
        this.view = new MWF.xApplication.query.StatementDesigner.View(this.designer, this, this.viewJson, {});
U
unknown 已提交
939
        this.view.load(function () {
U
unknown 已提交
940 941
            this.view.setContentHeight();
        }.bind(this));
U
unknown 已提交
942
    },
U
unknown 已提交
943
    setViewSize: function () {
U
unknown 已提交
944 945 946
        debugger;
        var size = this.areaNode.getSize();
        var designerSize = this.designerArea.getComputedSize();
947 948 949
        var reizeNodeSize = this.resizeNode.getComputedSize();

        var y = size.y - designerSize.totalHeight - reizeNodeSize.totalHeight;
U
unknown 已提交
950 951 952 953
        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();
U
unknown 已提交
954
        y = y - mTop - mBottom - pTop - pBottom - 1;
U
unknown 已提交
955

U
unknown 已提交
956 957 958
        var tabSize = this.tabNode.getComputedSize();
        y = y - tabSize.totalHeight;

U
unknown 已提交
959
        this.viewArea.setStyle("height", "" + y + "px");
U
unknown 已提交
960 961 962 963

        // var titleSize = this.runTitleNode.getComputedSize();
        // y = y - titleSize.totalHeight;
        // this.runContentNode.setStyle("height", ""+y+"px");
U
unknown 已提交
964
    },
U
unknown 已提交
965 966 967
    preview: function () {
        if (this.isNewStatement) {
            this.designer.notice(this.designer.lp.saveStatementNotice, "error");
U
unknown 已提交
968 969
            return;
        }
U
unknown 已提交
970 971
        if (this.data.type !== "select") {
            this.designer.notice(this.designer.lp.previewNotSelectStatementNotice, "error");
U
unknown 已提交
972 973
            return;
        }
U
unknown 已提交
974 975
        if (!this.data.view) {
            this.designer.notice(this.designer.lp.noViewNotice, "error");
U
unknown 已提交
976 977

        }
U
unknown 已提交
978
        this.saveSilence(function () {
U
unknown 已提交
979 980
            var url = "../x_desktop/app.html?app=query.Query&status=";
            url += JSON.stringify({
U
unknown 已提交
981 982
                id: this.data.application,
                statementId: this.data.id
U
unknown 已提交
983
            });
U
unknown 已提交
984
            window.open(o2.filterUrl(url), "_blank");
U
unknown 已提交
985
        }.bind(this));
U
unknown 已提交
986 987 988 989 990 991 992 993 994 995 996 997 998
    }
});

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"
    },

U
unknown 已提交
999
    initialize: function (designer, statement, data, options) {
U
unknown 已提交
1000 1001 1002
        this.setOptions(options);

        this.path = "../x_component_query_ViewDesigner/$View/";
U
unknown 已提交
1003
        this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/css.wcss";
U
unknown 已提交
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016

        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 已提交
1017
        this.areaNode = new Element("div", {"styles": {"height": "calc(100% - 2px)", "overflow": "auto"}});
U
unknown 已提交
1018
        this.areaNode.setStyles(this.css.areaNode);
U
unknown 已提交
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040

        //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 已提交
1041
    load: function (callback) {
U
unknown 已提交
1042 1043 1044 1045 1046 1047
        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);

U
unknown 已提交
1048
        this.loadTemplateStyle(function () {
U
unknown 已提交
1049 1050 1051 1052 1053 1054 1055

            this.loadActionbar();

            this.loadView();

            this.loadPaging();

U
unknown 已提交
1056
            // this.selected();
U
unknown 已提交
1057 1058 1059 1060 1061 1062
            this.setEvent();

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

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

U
unknown 已提交
1064
            if (callback) callback();
U
unknown 已提交
1065 1066
        }.bind(this))
    },
U
unknown 已提交
1067
    parseData: function () {
U
unknown 已提交
1068
        this.json = this.data;
U
unknown 已提交
1069
        if (!this.json.id) {
U
unknown 已提交
1070 1071
            this.json.id = (new o2.widget.UUID).id;
        }
U
unknown 已提交
1072
        if (!this.json.data || !this.json.data.events) {
U
unknown 已提交
1073 1074
            var url = "../x_component_query_StatementDesigner/$Statement/view.json";
            MWF.getJSON(url, {
U
unknown 已提交
1075 1076 1077
                "onSuccess": function (obj) {
                    if (!this.json.data) this.json.data = obj.data;
                    if (!this.json.data.events) this.json.data.events = obj.data.events;
U
unknown 已提交
1078
                }.bind(this),
U
unknown 已提交
1079
                "onerror": function (text) {
U
unknown 已提交
1080 1081
                    this.notice(text, "error");
                }.bind(this),
U
unknown 已提交
1082
                "onRequestFailure": function (xhr) {
U
unknown 已提交
1083 1084
                    this.notice(xhr.responseText, "error");
                }.bind(this)
U
unknown 已提交
1085
            }, false);
U
unknown 已提交
1086 1087
        }
    },
U
unknown 已提交
1088
    setEvent: function () {
U
unknown 已提交
1089
        this.areaNode.addEvents({
U
unknown 已提交
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
            "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)
U
unknown 已提交
1100
        });
U
unknown 已提交
1101
        this.refreshNode.addEvent("click", function (e) {
U
unknown 已提交
1102
            this.statement.runStatement();
U
unknown 已提交
1103 1104
            e.stopPropagation();
        }.bind(this));
U
unknown 已提交
1105
        this.addColumnNode.addEvent("click", function (e) {
U
unknown 已提交
1106 1107 1108 1109
            this.addColumn();
            e.stopPropagation();
        }.bind(this));
    },
U
unknown 已提交
1110
    selected: function () {
U
unknown 已提交
1111
        debugger;
U
unknown 已提交
1112 1113
        if (this.statement.currentSelectedModule) {
            if (this.statement.currentSelectedModule == this) {
U
unknown 已提交
1114
                return true;
U
unknown 已提交
1115
            } else {
U
unknown 已提交
1116 1117 1118 1119 1120
                this.statement.currentSelectedModule.unSelected();
            }
        }
        this.areaNode.setStyles(this.css.areaNode_selected);
        this.statement.currentSelectedModule = this;
U
unknown 已提交
1121
        this.domListNode.show();
U
unknown 已提交
1122 1123 1124
        this.isSelected = true;
        this.showProperty();
    },
U
unknown 已提交
1125
    unSelected: function () {
U
unknown 已提交
1126 1127 1128 1129 1130
        this.statement.currentSelectedModule = null;
        this.isSelected = false;
        this.areaNode.setStyles(this.css.areaNode);
        this.hideProperty();
    },
U
unknown 已提交
1131

U
unknown 已提交
1132 1133
    showProperty: function () {
        if (!this.property) {
U
unknown 已提交
1134 1135
            this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
                "path": this.options.propertyPath,
U
unknown 已提交
1136
                "onPostLoad": function () {
U
unknown 已提交
1137 1138 1139 1140
                    this.property.show();
                }.bind(this)
            });
            this.property.load();
U
unknown 已提交
1141
        } else {
U
unknown 已提交
1142 1143 1144
            this.property.show();
        }
    },
U
unknown 已提交
1145
    hideProperty: function () {
U
unknown 已提交
1146 1147 1148
        if (this.property) this.property.hide();
    },

U
unknown 已提交
1149
    loadViewData: function () {
U
unknown 已提交
1150
        debugger;
U
unknown 已提交
1151
        if (this.data.id) {
U
unknown 已提交
1152 1153 1154 1155 1156 1157 1158 1159
            // this.statement.saveSilence(function () {
            this.viewContentBodyNode.empty();
            this.viewContentTableNode = new Element("table", {
                "styles": this.css.viewContentTableNode,
                "border": "0px",
                "cellPadding": "0",
                "cellSpacing": "0"
            }).inject(this.viewContentBodyNode);
U
unknown 已提交
1160

U
unknown 已提交
1161
            // this.statement.execute( function (json) {
U
unknown 已提交
1162

U
unknown 已提交
1163 1164 1165
            // this.statement.setColumnDataPath( json );

            var entries = {};
U
unknown 已提交
1166

U
unknown 已提交
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
            this.json.data.selectList.each(function (entry) {
                entries[entry.column] = entry;
            }.bind(this));

            if (this.statement.executeData && this.statement.executeData.data && this.statement.executeData.data.length) {
                this.statement.executeData.data.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) {
                        debugger;

                        var path = c.path, code = c.code, obj = line;
                        if( path ){
                            var pathList = path.split(".");
                            for( var i=0; i<pathList.length; i++ ){
                                var p = pathList[i];
                                if( (/(^[1-9]\d*$)/.test(p)) )p = p.toInt();
                                if( obj[ p ] ){
                                    obj = obj[ p ];
                                }else{
                                    obj = "";
                                    break;
U
unknown 已提交
1193
                                }
U
unknown 已提交
1194 1195 1196
                            }
                        }

U
unknown 已提交
1197
                        if( code && code.trim())obj = MWF.Macro.exec( code, { "target" : {"value": obj,  "data": line, "entry": c} });
U
unknown 已提交
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 1231

                        var toName = function (value) {
                            if(typeOf(value) === "array"){
                                Array.each( value, function (v, idx) {
                                    value[idx] = toName(v)
                                })
                            }else if( typeOf(value) === "object" ){
                                Object.each( value, function (v, key) {
                                    value[key] = toName(v);
                                })
                            }else if( typeOf( value ) === "string" ){
                                value = o2.name.cn( value )
                            }
                            return value;
                        };

                        var d;
                        if( obj!= undefined && obj!= null ){
                            if( typeOf(obj) === "array" ) {
                                d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
                            }else if( typeOf(obj) === "object" ){
                                d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
                            }else{
                                d = c.isName ? o2.name.cn( obj.toString() ) : obj;
                            }
                        }


                        if (d != undefined && d != null ) {
                            var td = new Element("td", {
                                "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
                            }).inject(tr);
                            if (c.isHtml) {
                                td.set("html", d);
U
unknown 已提交
1232
                            } else {
U
unknown 已提交
1233
                                td.set("text", d);
U
unknown 已提交
1234 1235
                            }
                        }
U
unknown 已提交
1236
                    }.bind(this));
U
unknown 已提交
1237
                }.bind(this));
U
unknown 已提交
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
                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));
U
unknown 已提交
1256 1257
        }
    },
U
unknown 已提交
1258
    addColumn: function () {
U
unknown 已提交
1259 1260 1261

        debugger;

U
unknown 已提交
1262
        MWF.require("MWF.widget.UUID", function () {
U
unknown 已提交
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275
            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();

U
unknown 已提交
1276
            if (this.viewContentTableNode) {
U
unknown 已提交
1277
                var trs = this.viewContentTableNode.getElements("tr");
U
unknown 已提交
1278
                trs.each(function (tr) {
U
unknown 已提交
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
                    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 已提交
1289
    setContentHeight: function () {
U
unknown 已提交
1290 1291
        var size = this.areaNode.getSize();
        var titleSize = this.viewTitleNode.getSize();
U
unknown 已提交
1292 1293 1294
        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;
U
unknown 已提交
1295 1296 1297 1298

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

        var contentSize = this.viewContentBodyNode.getSize();
U
unknown 已提交
1299
        if (height < contentSize.y) height = contentSize.y + 10;
U
unknown 已提交
1300 1301 1302 1303 1304 1305

        this.viewContentNode.setStyle("height", height);
        this.contentLeftNode.setStyle("height", height);
        this.contentRightNode.setStyle("height", height);
        //this.viewContentBodyNode.setStyle("min-height", height);
    },
U
unknown 已提交
1306
    loadViewColumns: function () {
U
unknown 已提交
1307 1308 1309 1310 1311 1312 1313 1314 1315
        //    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));
        }
        //    }
    },
U
unknown 已提交
1316
    showActionbar: function (noSetHeight) {
U
unknown 已提交
1317
        this.actionbarNode.show();
U
unknown 已提交
1318 1319 1320 1321 1322
        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))
U
unknown 已提交
1323
                }.bind(this));
U
unknown 已提交
1324 1325
            } else {
                this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(null, this.json.data.actionbarList, this))
U
unknown 已提交
1326 1327
            }
        }
U
unknown 已提交
1328
        if (!noSetHeight) this.setContentHeight();
U
unknown 已提交
1329
    },
U
unknown 已提交
1330
    loadPaging: function (noSetHeight) {
U
unknown 已提交
1331 1332
        this.pagingNode = new Element("div#pagingNode", {"styles": this.css.pagingNode}).inject(this.areaNode);
        this.pagingList = [];
U
unknown 已提交
1333 1334 1335 1336 1337
        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))
U
unknown 已提交
1338
                }.bind(this));
U
unknown 已提交
1339 1340
            } else {
                this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(null, this.json.data.pagingList, this))
U
unknown 已提交
1341 1342 1343 1344
            }
        }
        // if( !noSetHeight )this.setContentHeight();
    },
U
unknown 已提交
1345 1346
    setViewWidth: function () {
        if (!this.viewAreaNode) return;
U
unknown 已提交
1347 1348 1349 1350 1351 1352
        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();
U
unknown 已提交
1353
        var width = s1.x + s2.x + s2.x;
U
unknown 已提交
1354 1355
        var size = this.areaNode.getSize();

U
unknown 已提交
1356 1357 1358 1359 1360 1361
        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");
U
unknown 已提交
1362 1363 1364 1365 1366
        }
        this.setContentColumnWidth();
        this.setContentHeight();
    },

U
unknown 已提交
1367 1368 1369
    _setEditStyle: function (name, input, oldValue) {
        if (name == "data.actionbarHidden") {
            if (this.json.data.actionbarHidden) {
U
unknown 已提交
1370
                this.hideActionbar()
U
unknown 已提交
1371
            } else {
U
unknown 已提交
1372 1373 1374
                this.showActionbar()
            }
        }
U
unknown 已提交
1375 1376 1377 1378 1379 1380 1381
        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");
U
unknown 已提交
1382 1383
            }
        }
U
unknown 已提交
1384
        if (name == "data.viewStyleType") {
U
unknown 已提交
1385 1386 1387

            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;
U
unknown 已提交
1388
            this.loadTemplateStyles(file, extendFile, function (templateStyles) {
U
unknown 已提交
1389 1390 1391
                this.templateStyles = templateStyles;

                var oldFile, oldExtendFile;
U
unknown 已提交
1392
                if (oldValue && this.stylesList[oldValue]) {
U
unknown 已提交
1393 1394 1395
                    oldFile = this.stylesList[oldValue].file;
                    oldExtendFile = this.stylesList[oldValue].extendFile;
                }
U
unknown 已提交
1396
                this.loadTemplateStyles(oldFile, oldExtendFile, function (oldTemplateStyles) {
U
unknown 已提交
1397 1398 1399 1400 1401 1402 1403

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

U
unknown 已提交
1404 1405
                    this.actionbarList.each(function (module) {
                        if (oldTemplateStyles["actionbar"]) {
U
unknown 已提交
1406 1407 1408 1409 1410 1411
                            module.clearTemplateStyles(oldTemplateStyles["actionbar"]);
                        }
                        module.setStyleTemplate();
                        module.setAllStyles();
                    })

U
unknown 已提交
1412 1413
                    this.pagingList.each(function (module) {
                        if (oldTemplateStyles["paging"]) {
U
unknown 已提交
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430
                            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))
        }
U
unknown 已提交
1431
        if (name == "data.viewStyles") {
U
unknown 已提交
1432 1433 1434
            this.setCustomStyles();
        }
    },
U
unknown 已提交
1435

U
unknown 已提交
1436 1437
    loadTemplateStyle: function (callback) {
        this.loadStylesList(function () {
U
unknown 已提交
1438
            var oldStyleValue = "";
U
unknown 已提交
1439 1440 1441
            if ((!this.json.data.viewStyleType) || !this.stylesList[this.json.data.viewStyleType]) this.json.data.viewStyleType = "default";
            this.loadTemplateStyles(this.stylesList[this.json.data.viewStyleType].file, this.stylesList[this.json.data.viewStyleType].extendFile,
                function (templateStyles) {
U
unknown 已提交
1442
                    this.templateStyles = templateStyles;
U
unknown 已提交
1443
                    if (!this.json.data.viewStyleType) this.json.data.viewStyleType = "default";
U
unknown 已提交
1444

U
unknown 已提交
1445
                    if (this.templateStyles && this.templateStyles["view"]) {
U
unknown 已提交
1446
                        var viewStyles = Object.clone(this.templateStyles["view"]);
U
unknown 已提交
1447 1448 1449 1450
                        if (viewStyles.contentGroupTd) delete viewStyles.contentGroupTd;
                        if (viewStyles.groupCollapseNode) delete viewStyles.groupCollapseNode;
                        if (viewStyles.groupExpandNode) delete viewStyles.groupExpandNode;
                        if (!this.json.data.viewStyles) {
U
unknown 已提交
1451
                            this.json.data.viewStyles = viewStyles;
U
unknown 已提交
1452 1453
                        } else {
                            this.setTemplateStyles(viewStyles);
U
unknown 已提交
1454 1455 1456 1457 1458
                        }
                    }

                    this.setCustomStyles();

U
unknown 已提交
1459
                    if (callback) callback();
U
unknown 已提交
1460 1461 1462 1463
                }.bind(this)
            );
        }.bind(this));
    },
U
unknown 已提交
1464 1465
    clearTemplateStyles: function (styles) {
        if (styles) {
U
unknown 已提交
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
            if (styles.container) this.removeStyles(styles.container, "container");
            if (styles.table) this.removeStyles(styles.table, "table");
            if (styles.titleTr) this.removeStyles(styles.titleTr, "titleTr");
            if (styles.titleTd) this.removeStyles(styles.titleTd, "titleTd");
            if (styles.contentTr) this.removeStyles(styles.contentTr, "contentTr");
            if (styles.contentSelectedTr) this.removeStyles(styles.contentSelectedTr, "contentSelectedTr");
            if (styles.contentTd) this.removeStyles(styles.contentTd, "contentTd");
            // if (styles.contentGroupTd) this.removeStyles(styles.contentGroupTd, "contentGroupTd");
            // if (styles.groupCollapseNode) this.removeStyles(styles.groupCollapseNode, "groupCollapseNode");
            // if (styles.groupExpandNode) this.removeStyles(styles.groupExpandNode, "groupExpandNode");
            if (styles.checkboxNode) this.removeStyles(styles.checkboxNode, "checkboxNode");
            if (styles.checkedCheckboxNode) this.removeStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
            if (styles.radioNode) this.removeStyles(styles.radioNode, "radioNode");
            if (styles.checkedRadioNode) this.removeStyles(styles.checkedRadioNode, "checkedRadioNode");
            if (styles.tableProperties) this.removeStyles(styles.tableProperties, "tableProperties");
        }
    },

U
unknown 已提交
1484
    setTemplateStyles: function (styles) {
U
unknown 已提交
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500
        if (styles.container) this.copyStyles(styles.container, "container");
        if (styles.table) this.copyStyles(styles.table, "table");
        if (styles.titleTr) this.copyStyles(styles.titleTr, "titleTr");
        if (styles.titleTd) this.copyStyles(styles.titleTd, "titleTd");
        if (styles.contentTr) this.copyStyles(styles.contentTr, "contentTr");
        if (styles.contentSelectedTr) this.copyStyles(styles.contentSelectedTr, "contentSelectedTr");
        if (styles.contentTd) this.copyStyles(styles.contentTd, "contentTd");
        // if (styles.contentGroupTd) this.copyStyles(styles.contentGroupTd, "contentGroupTd");
        // if (styles.groupCollapseNode) this.copyStyles(styles.groupCollapseNode, "groupCollapseNode");
        // if (styles.groupExpandNode) this.copyStyles(styles.groupExpandNode, "groupExpandNode");
        if (styles.checkboxNode) this.copyStyles(styles.checkboxNode, "checkboxNode");
        if (styles.checkedCheckboxNode) this.copyStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
        if (styles.radioNode) this.copyStyles(styles.radioNode, "radioNode");
        if (styles.checkedRadioNode) this.copyStyles(styles.checkedRadioNode, "checkedRadioNode");
        if (styles.tableProperties) this.copyStyles(styles.tableProperties, "tableProperties");
    },
U
unknown 已提交
1501 1502 1503 1504
    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) {
U
unknown 已提交
1505 1506 1507 1508 1509
                    delete this.json.data.viewStyles[to][key];
                }
            }.bind(this));
        }
    },
U
unknown 已提交
1510
    copyStyles: function (from, to) {
U
unknown 已提交
1511
        if (!this.json.data.viewStyles[to]) this.json.data.viewStyles[to] = {};
U
unknown 已提交
1512
        Object.each(from, function (style, key) {
U
unknown 已提交
1513 1514
            if (!this.json.data.viewStyles[to][key]) this.json.data.viewStyles[to][key] = style;
        }.bind(this));
NoSubject's avatar
NoSubject 已提交
1515
    }
U
unknown 已提交
1516
    // preview: function(){
U
unknown 已提交
1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604
    //     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 已提交
1605 1606 1607 1608

});

MWF.xApplication.query.StatementDesigner.View.Column = new Class({
U
unknown 已提交
1609
    Extends: MWF.xApplication.query.ViewDesigner.View.Column,
U
unknown 已提交
1610
    initialize: function (json, view, next) {
U
unknown 已提交
1611 1612 1613 1614 1615 1616 1617 1618 1619
        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 已提交
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
    refreshColumnPathData: function () {
        if (this.property) {
            this.property.loadDataPathSelect();
        }
    },
    getColumnDataPath: function () {
        return this.view.statement.getColumnDataPath();
    },
    showProperty: function () {
        if (!this.property) {
            this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
                "path": this.propertyPath,
                "onPostLoad": function () {
                    this.property.show();

                    var processDiv = this.property.propertyContent.getElements("#" + this.json.id + "dataPathSelectedProcessArea");
                    var cmsDiv = this.property.propertyContent.getElements("#" + this.json.id + "dataPathSelectedCMSArea");

                    if (this.view.json.type == "cms") {
                        processDiv.setStyle("display", "none");
                        cmsDiv.setStyle("display", "block");
                    } else {
                        processDiv.setStyle("display", "block");
                        cmsDiv.setStyle("display", "none");
                    }
                }.bind(this)
            });
            this.property.load();
        } else {
            this.property.show();
        }
    },
U
unknown 已提交
1652 1653 1654
    selected: function () {
        if (this.view.statement.currentSelectedModule) {
            if (this.view.statement.currentSelectedModule == this) {
U
unknown 已提交
1655
                return true;
U
unknown 已提交
1656
            } else {
U
unknown 已提交
1657 1658 1659
                this.view.statement.currentSelectedModule.unSelected();
            }
        }
U
unknown 已提交
1660
        this.view.domListNode.show();
U
unknown 已提交
1661 1662 1663
        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);
U
unknown 已提交
1664 1665 1666 1667
        new Fx.Scroll(this.view.designer.propertyDomArea, {
            "wheelStops": false,
            "duration": 100
        }).toElement(this.listNode);
U
unknown 已提交
1668 1669 1670 1671 1672 1673

        this.view.statement.currentSelectedModule = this;
        this.isSelected = true;
        this._showActions();
        this.showProperty();
    },
U
unknown 已提交
1674
    unSelected: function () {
U
unknown 已提交
1675 1676
        this.view.statement.currentSelectedModule = null;
        //this.node.setStyles(this.css.viewTitleColumnNode);
U
unknown 已提交
1677
        if (this.isError) {
U
unknown 已提交
1678
            this.node.setStyles(this.css.viewTitleColumnNode_error)
U
unknown 已提交
1679
        } else {
U
unknown 已提交
1680 1681 1682 1683 1684 1685 1686 1687
            this.node.setStyles(this.css.viewTitleColumnNode)
        }

        this.listNode.setStyles(this.css.cloumnListNode);
        this.isSelected = false;
        this._hideActions();
        this.hideProperty();
    }
U
unknown 已提交
1688 1689 1690
});

MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({
U
unknown 已提交
1691
    Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar,
U
unknown 已提交
1692 1693
    initialize: function (json, jsonList, view, options) {
        this.setOptions(options);
U
unknown 已提交
1694 1695 1696 1697
        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/";
U
unknown 已提交
1698
        this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/actionbar.wcss";
U
unknown 已提交
1699 1700 1701 1702 1703 1704 1705 1706 1707

        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 已提交
1708
    getJsonPath: function () {
U
unknown 已提交
1709
        return "../x_component_query_StatementDesigner/$Statement/toolbars.json";
U
unknown 已提交
1710
    },
U
unknown 已提交
1711 1712 1713
    selected: function () {
        if (this.view.statement.currentSelectedModule) {
            if (this.view.statement.currentSelectedModule == this) {
U
unknown 已提交
1714
                return true;
U
unknown 已提交
1715
            } else {
U
unknown 已提交
1716 1717 1718
                this.view.statement.currentSelectedModule.unSelected();
            }
        }
U
unknown 已提交
1719
        this.view.domListNode.show();
U
unknown 已提交
1720 1721 1722 1723 1724 1725 1726 1727 1728 1729
        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();
    },
U
unknown 已提交
1730
    unSelected: function () {
U
unknown 已提交
1731
        this.view.statement.currentSelectedModule = null;
U
unknown 已提交
1732
        this.node.setStyles(this.css.toolbarWarpNode);
U
unknown 已提交
1733 1734 1735 1736 1737 1738

        //this.listNode.setStyles(this.css.cloumnListNode);
        this.isSelected = false;
        //this._hideActions();
        this.hideProperty();
    },
U
unknown 已提交
1739 1740 1741
});

MWF.xApplication.query.StatementDesigner.View.Paging = new Class({
U
unknown 已提交
1742
    Extends: MWF.xApplication.query.ViewDesigner.View.Paging,
U
unknown 已提交
1743 1744 1745
    selected: function () {
        if (this.view.statement.currentSelectedModule) {
            if (this.view.statement.currentSelectedModule == this) {
U
unknown 已提交
1746
                return true;
U
unknown 已提交
1747
            } else {
U
unknown 已提交
1748 1749 1750
                this.view.statement.currentSelectedModule.unSelected();
            }
        }
U
unknown 已提交
1751
        this.view.domListNode.show();
U
unknown 已提交
1752 1753 1754 1755 1756 1757 1758
        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();
    },
U
unknown 已提交
1759
    unSelected: function () {
U
unknown 已提交
1760 1761 1762 1763 1764 1765
        this.view.statement.currentSelectedModule = null;
        this.node.setStyles(this.css.pagingWarpNode);

        this.isSelected = false;
        this.hideProperty();
    }
NoSubject's avatar
NoSubject 已提交
1766
});