Table.js 60.5 KB
Newer Older
NoSubject's avatar
NoSubject 已提交
1 2
MWF.xApplication = MWF.xApplication || {};
MWF.xApplication.query = MWF.xApplication.query || {};
NoSubject's avatar
NoSubject 已提交
3 4
MWF.xApplication.query.TableDesigner = MWF.xApplication.query.TableDesigner || {};
MWF.APPDTBD = MWF.xApplication.query.TableDesigner;
NoSubject's avatar
NoSubject 已提交
5

NoSubject's avatar
NoSubject 已提交
6
MWF.xDesktop.requireApp("query.TableDesigner", "lp."+MWF.language, null, false);
7
MWF.xDesktop.requireApp("query.ViewDesigner", "ViewBase", null, false);
NoSubject's avatar
NoSubject 已提交
8
MWF.xDesktop.requireApp("query.TableDesigner", "Property", null, false);
NoSubject's avatar
NoSubject 已提交
9

NoSubject's avatar
NoSubject 已提交
10
MWF.xApplication.query.TableDesigner.Table = new Class({
11
    Extends: MWF.xApplication.query.ViewDesigner.ViewBase,
NoSubject's avatar
NoSubject 已提交
12 13 14 15 16
    Implements: [Options, Events],
    options: {
        "style": "default",
        "isView": false,
        "showTab": true,
17
        "propertyPath": "../x_component_query_TableDesigner/$Table/table.html"
NoSubject's avatar
NoSubject 已提交
18 19 20 21 22
    },

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

23 24
        this.path = "../x_component_query_TableDesigner/$Table/";
        this.cssPath = "../x_component_query_TableDesigner/$Table/"+this.options.style+"/css.wcss";
NoSubject's avatar
NoSubject 已提交
25 26 27 28 29

        this._loadCss();

        this.designer = designer;
        this.data = data;
NoSubject's avatar
NoSubject 已提交
30
        if (!this.data.draftData) this.data.draftData = {};
NoSubject's avatar
NoSubject 已提交
31 32 33 34 35 36 37 38 39 40
        this.parseData();

        this.node = this.designer.designNode;
        this.areaNode = new Element("div", {"styles": {"height": "100%", "overflow": "auto"}});

        this.propertyListNode = this.designer.propertyDomArea;

        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
        this.isNewTable = (this.data.id) ? false : true;
NoSubject's avatar
NoSubject 已提交
42 43 44 45 46 47 48 49 50 51

        this.items = [];
        this.view = this;
        this.queryView = null;

        this.autoSave();
        this.designer.addEvent("queryClose", function(){
            if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
        }.bind(this));
    },
NoSubject's avatar
NoSubject 已提交
52 53 54
    parseData: function(){
        this.json = this.data;
    },
NoSubject's avatar
NoSubject 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    load : function(){
        this.setAreaNodeSize();
        this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
        this.areaNode.inject(this.node);

        this.designer.viewListAreaNode.getChildren().each(function(node){
            var table = node.retrieve("table");
            if (table.id==this.data.id){
                if (this.designer.currentListViewItem){
                    this.designer.currentListViewItem.setStyles(this.designer.css.listViewItem);
                }
                node.setStyles(this.designer.css.listViewItem_current);
                this.designer.currentListViewItem = node;
                this.lisNode = node;
            }
        }.bind(this));

        this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
NoSubject's avatar
NoSubject 已提交
73 74 75 76
        this.designer.propertyTitleNode.set("text", this.designer.lp.clumn);
        this.designer.propertyDomPercent = 0.5;
        this.designer.loadPropertyContentResize();
        this.createColumnEditTable();
NoSubject's avatar
NoSubject 已提交
77 78

        this.loadView();
NoSubject's avatar
NoSubject 已提交
79 80 81 82 83
        this.refreshNode.setStyles(this.css.tableRunNode);
        if (!this.data.buildSuccess){
            this.refreshNode.hide();
            this.addColumnNode.hide();
        }
NoSubject's avatar
NoSubject 已提交
84 85 86 87 88 89 90

        this.selected();
        this.setEvent();

        this.setViewWidth();
        this.designer.addEvent("resize", this.setViewWidth.bind(this));

NoSubject's avatar
NoSubject 已提交
91
        this.checkToolbars();
NoSubject's avatar
NoSubject 已提交
92
    },
NoSubject's avatar
NoSubject 已提交
93 94 95 96 97 98 99 100 101 102 103
    setEvent: function(){
        this.areaNode.addEvent("click", this.selected.bind(this));
        this.refreshNode.addEvent("click", function(e){
            this.loadViewData();
            e.stopPropagation();
        }.bind(this));
        this.addColumnNode.addEvent("click", function(e){
            debugger;
            this.addLine();
            e.stopPropagation();
        }.bind(this));
NoSubject's avatar
NoSubject 已提交
104
    },
NoSubject's avatar
NoSubject 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    addLine: function(){
        var data = this.getNewData();
        this.createNewLineDlg(data);
    },
    createNewLineDlg: function(data){
        var div = new Element("div", {"styles": {"margin": "10px 10px 0px 10px", "padding": "5px", "height": "400px", "width": "440px", "overflow": "hidden"}});
        var options ={
            "content": div,
            "title": this.designer.lp.addLine,
            "container": this.designer.content,
            "width": 500,
            "mask": false,
            "height": 530,
            "buttonList": [
                {
                    "text": this.designer.lp.ok,
                    "action": function(){
                        this.saveNewLine(dlg);
                    }.bind(this)
                },
                {
                    "text": this.designer.lp.cancel,
                    "action": function(){dlg.close();}.bind(this),
                    "styles": {
                        "border": "1px solid #999",
                        "background-color": "#f3f3f3",
                        "color": "#666666",
                        "height": "30px",
                        "border-radius": "5px",
                        "min-width": "80px",
                        "margin": "10px 5px"
NoSubject's avatar
NoSubject 已提交
136 137
                    }
                }
NoSubject's avatar
NoSubject 已提交
138 139 140 141 142 143 144 145 146
            ],
            "onResize": function(){
                var size = dlg.content.getSize();
                var width = size.x-60;
                var height = size.y - 30;
                div.setStyles({
                    "width": ""+width+"px",
                    "height": ""+height+"px",
                });
NoSubject's avatar
NoSubject 已提交
147 148
            }
        }
NoSubject's avatar
NoSubject 已提交
149 150 151 152 153 154 155 156 157 158 159
        var dlg = o2.DL.open(options);

        o2.require("o2.widget.JavascriptEditor", function(){
            dlg.editor = new o2.widget.JavascriptEditor(div, {"option": {"mode": "json"}});
            dlg.editor.load(function(){
                debugger;
                dlg.editor.editor.setValue(JSON.stringify(data, null, "\t"));
            }.bind(this));
        }.bind(this), false);

        return dlg;
NoSubject's avatar
NoSubject 已提交
160
    },
NoSubject's avatar
NoSubject 已提交
161 162 163 164 165 166 167 168
    saveNewLine: function(dlg){
        var str = dlg.editor.editor.getValue();
        try{
            var data = JSON.parse(str);
            this.designer.actions.insertRow(this.data.id, data, function(){
                if (this.lastSelectJPQL) this.runJpql(this.lastSelectJPQL);
                this.designer.notice(this.designer.lp.newLineSuccess, "success");
                dlg.close();
NoSubject's avatar
NoSubject 已提交
169
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
170 171
        }catch(e){
            this.designer.notice(this.designer.lp.newLineSuccess, "error");
NoSubject's avatar
NoSubject 已提交
172
        }
NoSubject's avatar
NoSubject 已提交
173

NoSubject's avatar
NoSubject 已提交
174
    },
NoSubject's avatar
NoSubject 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
    getNewData: function(){
        var data = JSON.parse(this.data.data);
        var newLineData = {};
        data.fieldList.each(function(field){
            switch (field.type) {
                case "string":
                    newLineData[field.name] = "";
                    break;
                case "integer":
                case "long":
                case "double":
                    newLineData[field.name] = 0;
                    break;
                case "date":
                    var str = new Date().format("%Y-%m-%d");
                    newLineData[field.name] = str;
                    break;
                case "time":
                    var str = new Date().format("%H:%M:%S");
                    newLineData[field.name] = str;
                    break;
                case "dateTime":
                    var str = new Date().format("db");
                    newLineData[field.name] = str;
                    break;
                case "boolean":
                    newLineData[field.name] = true;
                    break;
                case "stringList":
                case "integerList":
                case "longList":
                case "doubleList":
                    newLineData[field.name] = [];
                    break;
                case "stringLob":
                    newLineData[field.name] = "";
                    break;
                case "stringMap":
                    newLineData[field.name] = {};
                    break;
            }
        }.bind(this));
        return newLineData;
    },
    checkToolbars: function(){
        if (this.designer.toolbar){
            var buildBtn = this.designer.toolbar.childrenButton[1];
            var draftBtn = this.designer.toolbar.childrenButton[2];

            buildBtn.setDisable(true);
            draftBtn.setDisable(true);
NoSubject's avatar
NoSubject 已提交
226

NoSubject's avatar
NoSubject 已提交
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
            if (!this.data.isNewTable) buildBtn.setDisable(false);
            if (this.data.status=="build") draftBtn.setDisable(false);
        }
    },
    createColumnEditTable: function(){
        this.columnListTable = new Element("table", {"styles": this.css.columnListTable}).inject(this.domListNode);
        this.columnListHeaderTr = this.columnListTable.insertRow(-1).setStyles(this.css.columnListTr);
        this.columnListHeaderTr.insertCell().setStyles(this.css.columnListHeaderTd).set("text", this.designer.lp.name);
        this.columnListHeaderTr.insertCell().setStyles(this.css.columnListHeaderTd).set("text", this.designer.lp.description);
        this.columnListHeaderTr.insertCell().setStyles(this.css.columnListHeaderTd).set("text", this.designer.lp.type);

        this.columnListEditTr = this.columnListTable.insertRow(-1).setStyles(this.css.columnListEditTr);
        var td = this.columnListEditTr.insertCell().setStyles(this.css.columnListTd);
        this.columnListEditNameInput = new Element("input", {"styles": this.css.columnListEditInput}).inject(td);

        td = this.columnListEditTr.insertCell().setStyles(this.css.columnListTd);
        this.columnListEditDescriptionInput = new Element("input", {"styles": this.css.columnListEditInput}).inject(td);

        td = this.columnListEditTr.insertCell().setStyles(this.css.columnListTd);
        this.columnListEditTypeSelect = new Element("select", {"styles": this.css.columnListEditSelect}).inject(td);
        //var options = '<option value=""></option>';
        var options = '<option value="string">string</option>';
        options += '<option value="integer">integer</option>';
        options += '<option value="long">long</option>';
        options += '<option value="double">double</option>';
        options += '<option value="boolean">boolean</option>';
        options += '<option value="date">date</option>';
        options += '<option value="time">time</option>';
        options += '<option value="dateTime">dateTime</option>';
        options += '<option value="stringList">stringList</option>';
        options += '<option value="integerList">integerList</option>';
        options += '<option value="longList">longList</option>';
        options += '<option value="doubleList">doubleList</option>';
        options += '<option value="booleanList">booleanList</option>';
        options += '<option value="stringLob">stringLob</option>';
        options += '<option value="stringMap">stringMap</option>';
        this.columnListEditTypeSelect.set("html", options);

        this.columnListEditTypeSelect.addEvents({
            "change": function(e){
                this.checkAddColumn();
            }.bind(this)
        });
        this.columnListEditNameInput.addEvents({
            "keydown": function(e){
                if (e.code==13) this.checkAddColumn();
            }.bind(this)
        });
        this.columnListEditDescriptionInput.addEvents({
            "keydown": function(e){
                if (e.code==13) this.checkAddColumn();
            }.bind(this)
        });
    },
    checkColumnName: function(name){
        var rex = /^\d+|\.|\#|\s|\@|\&|\*|\(|\)|\=|\+|\!|\^|\$|\%|\;|\"|\{|\}|\[|\]|\||\\|\,|\.|\?|\/|\:|\;|\'|\"|\<|\>/g;
        if (rex.test(name)){
            this.designer.notice(this.designer.lp.errorName, "error");
            return false;
        }
287 288 289 290 291
        var keywords = ["string","int","integer","long","float","double","boolean"];
        if( keywords.contains((name||"").toLowerCase()) ){
            this.designer.notice(this.designer.lp.nameUseKeywork.replace("{key}", keywords.join(",")), "error");
            return false;
        }
NoSubject's avatar
NoSubject 已提交
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
        return true;
    },
    checkAddColumn: function(){
        var name = this.columnListEditNameInput.get("value");
        var description = this.columnListEditDescriptionInput.get("value");
        var type = this.columnListEditTypeSelect.options[this.columnListEditTypeSelect.selectedIndex].value;
        if (name && this.checkColumnName(name)){
            if (!this.json.draftData.fieldList) this.json.draftData.fieldList = [];
            var columnNames = this.json.draftData.fieldList.map(function(item){ return item.name; });
            if ((columnNames.indexOf(name)!=-1)){
                this.designer.notice(this.designer.lp.duplicateName, "error");
                this.columnListEditNameInput.focus();
            }else{
                var o = {
                    "name": name,
                    "description": description,
                    "type": type
                }
                this.addColumn(o);
                this.columnListEditNameInput.set("value", "");
                this.columnListEditDescriptionInput.set("value", "");
                this.columnListEditNameInput.focus();
            }
        }
    },
NoSubject's avatar
NoSubject 已提交
317 318
    showProperty: function(){
        if (!this.property){
NoSubject's avatar
NoSubject 已提交
319
            this.property = new MWF.xApplication.query.TableDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
NoSubject's avatar
NoSubject 已提交
320 321 322 323 324 325 326 327 328 329
                "path": this.options.propertyPath,
                "onPostLoad": function(){
                    this.property.show();
                }.bind(this)
            });
            this.property.load();
        }else{
            this.property.show();
        }
    },
NoSubject's avatar
NoSubject 已提交
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
    addColumn: function(data){
        var json;
        if (!data){
            if (!this.json.draftData.fieldList) this.json.draftData.fieldList = [];
            var columnNames = this.json.draftData.fieldList.map(function(item){ return item.name; });
            var name = "column";
            var i=1;
            while(columnNames.indexOf(name)!=-1){
                name = "column"+i;
                i++;
            }
            json = {
                "name": name,
                "type":"string",
                "description": this.designer.lp.newColumn
            };
        }else{
            json = data;
NoSubject's avatar
NoSubject 已提交
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
        }

        this.json.draftData.fieldList.push(json);
        var column = new MWF.xApplication.query.TableDesigner.Table.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);

NoSubject's avatar
NoSubject 已提交
365 366 367

        //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
    },
U
unknown 已提交
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
    setViewWidth: function(){
        debugger;
        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 || 30) + ( s2.x || 30 );
        var size = this.areaNode.getSize();

        if (width>size.x){
            this.viewTitleNode.setStyle("width", ""+width+"px");
            this.viewAreaNode.setStyle("width", ""+width+"px");
        }else{
            this.viewTitleNode.setStyle("width", ""+size.x+"px");
            this.viewAreaNode.setStyle("width", ""+size.x+"px");
        }
        this.setContentColumnWidth();
        this.setContentHeight();
    },
NoSubject's avatar
NoSubject 已提交
389 390

    loadViewColumns: function(){
NoSubject's avatar
NoSubject 已提交
391 392 393
        if (this.json.draftData.fieldList) {
            this.json.draftData.fieldList.each(function (json) {
                this.items.push(new MWF.xApplication.query.TableDesigner.Table.Column(json, this));
NoSubject's avatar
NoSubject 已提交
394 395 396 397
            }.bind(this));
        }
    },
    saveSilence: function(callback){
U
unknown 已提交
398
        debugger;
NoSubject's avatar
NoSubject 已提交
399
        if (!this.data.name){
NoSubject's avatar
NoSubject 已提交
400
            this.designer.notice(this.designer.lp.inputTableName, "error");
NoSubject's avatar
NoSubject 已提交
401 402
            return false;
        }
U
unknown 已提交
403 404 405 406 407 408 409 410 411 412 413 414 415
        if( this.data.status !== "build" ){
            var reg = /^[A-Za-z]/;
            if( !reg.test(this.data.name) ){
                this.designer.notice(this.designer.lp.tableNameNotStartWithLetter, "error");
                return false;
            }

            var reg2 = /^[A-Za-z0-9]+$/;
            if( !reg2.test(this.data.name) ){
                this.designer.notice(this.designer.lp.tableNameNotBeLetterAndNumber, "error");
                return false;
            }
        }
NoSubject's avatar
NoSubject 已提交
416 417
        if (!this.json.draftData.fieldList.length){
            this.designer.notice(this.designer.lp.errorFieldList, "error");
NoSubject's avatar
NoSubject 已提交
418 419
            return false;
        }
NoSubject's avatar
NoSubject 已提交
420
        this.designer.actions.saveTable(this.data, function(json){
NoSubject's avatar
NoSubject 已提交
421 422 423 424
            this.data.id = json.data.id;
            if (this.lisNode) {
                this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
            }
NoSubject's avatar
NoSubject 已提交
425
            this.checkToolbars();
NoSubject's avatar
NoSubject 已提交
426 427 428 429
            if (callback) callback();
        }.bind(this));
    },
    save: function(callback){
U
unknown 已提交
430
        debugger;
NoSubject's avatar
NoSubject 已提交
431
        if (!this.data.name){
NoSubject's avatar
NoSubject 已提交
432
            this.designer.notice(this.designer.lp.inputTableName, "error");
NoSubject's avatar
NoSubject 已提交
433 434
            return false;
        }
U
unknown 已提交
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
        if( this.data.status !== "build" ){
            var reg = /^[A-Za-z]/;
            if( !reg.test(this.data.name) ){
                this.designer.notice(this.designer.lp.tableNameNotStartWithLetter, "error");
                return false;
            }
            if( this.data.alias && !reg.test(this.data.alias) ){
                this.designer.notice(this.designer.lp.tableAliasNotStartWithLetter, "error");
                return false;
            }


            var reg2 = /^[A-Za-z0-9]+$/;
            if( !reg2.test(this.data.name) ){
                this.designer.notice(this.designer.lp.tableNameNotBeLetterAndNumber, "error");
                return false;
            }
            if( this.data.alias && !reg2.test(this.data.alias) ){
                this.designer.notice(this.designer.lp.tableAliasNotBeLetterAndNumber, "error");
                return false;
            }
        }
NoSubject's avatar
NoSubject 已提交
457 458
        if (!this.json.draftData.fieldList.length){
            this.designer.notice(this.designer.lp.errorFieldList, "error");
NoSubject's avatar
NoSubject 已提交
459 460
            return false;
        }
NoSubject's avatar
NoSubject 已提交
461 462
        this.designer.actions.saveTable(this.data, function(json){
            this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
NoSubject's avatar
NoSubject 已提交
463 464 465 466 467

            this.data.id = json.data.id;
            if (this.lisNode) {
                this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
            }
NoSubject's avatar
NoSubject 已提交
468
            this.checkToolbars();
NoSubject's avatar
NoSubject 已提交
469 470 471
            if (callback) callback();
        }.bind(this));
    },
472 473 474 475
    unSelected: function(){
        this.currentSelectedModule = null;
        return true;
    },
NoSubject's avatar
NoSubject 已提交
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
    statusBuild: function(e){
        var _self = this;
        if (!e) e = this.node;
        this.designer.confirm("warn", e, MWF.APPDTBD.LP.statusBuildTitle, MWF.APPDTBD.LP.statusBuildInfor, 420, 120, function(){
            _self.designer.actions.statusBuild(_self.data.id, function(json){
                debugger;
                this.designer.notice(this.designer.lp.statusBuild_success, "success", this.node, {"x": "left", "y": "bottom"});
                this.designer.actions.getTable(json.data.id, function(tjson){
                    this.data.status = tjson.data.status;
                    this.checkToolbars();
                }.bind(this));
            }.bind(_self));
            this.close();
        }, function(){
            this.close();
        }, null);
NoSubject's avatar
NoSubject 已提交
492
    },
NoSubject's avatar
NoSubject 已提交
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
    statusDraft: function(e){
        var _self = this;
        if (!e) e = this.node;
        this.designer.confirm("warn", e, MWF.APPDTBD.LP.statusDraftTitle, {"html": MWF.APPDTBD.LP.statusDraftInfor}, 450, 120, function(){
            this.close();
            _self.designer.confirm("warn", e, MWF.APPDTBD.LP.statusDraftTitle, {"html": MWF.APPDTBD.LP.statusDraftInforAgain}, 480, 120, function(){
                _self.designer.actions.statusDraft(_self.data.id, function(json){
                    this.designer.notice(this.designer.lp.statusDraft_success, "success", this.node, {"x": "left", "y": "bottom"});
                    this.designer.actions.getTable(json.data.id, function(tjson){
                        this.data.status = tjson.data.status;
                        this.checkToolbars();
                    }.bind(this));
                }.bind(_self));
                this.close();
            }, function(){
                this.close();
            }, null);

        }, function(){
            this.close();
        }, null);
NoSubject's avatar
NoSubject 已提交
514
    },
515 516 517
    buildAllView: function(e){
        var _self = this;
        if (!e) e = this.node;
U
unknown 已提交
518 519 520
        this.designer.confirm("warn", e, MWF.APPDTBD.LP.buildAllViewTitle, {
            "html": MWF.APPDTBD.LP.buildAllViewInfor
        }, 480, 120, function(){
521 522 523 524 525 526 527
            _self.designer.actions.buildAllTable(function(json){
                this.designer.notice(this.designer.lp.buildAllView_success, "success", this.node, {"x": "left", "y": "bottom"});
            }.bind(_self));
            this.close();
        }, function(){
            this.close();
        }, null);
528 529
    },
    bulidCurrentApp: function(e){
530
        MWF.require("MWF.widget.Mask", null, false);
531 532
        var _self = this;
        if (!e) e = this.node;
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
         var html = MWF.APPDTBD.LP.buildCurrentAppInfor;

        this.designer.actions.listTable(this.designer.application.id, function (json) {
            var listStr = "";
            json.data.each(function(table){
                listStr += "<div style='line-height: 24px;padding-left: 10px;'>" + table.name + "</div>"; //+ (table.alias ? ("  (" + table.alias + ")") : "")
            }.bind(this));
            var h = "<div style='min-height: 70px; max-height: 200px; width: 400px; overflow:auto; font-size: 12px;'>"+listStr+"</div>";
            html = html.replace("{tablelist}", h);
            this.designer.confirm("warn", e, MWF.APPDTBD.LP.buildCurrentAppTitle, {
                "html": html
            }, 480, 120, function(){

                _self.mask = new MWF.widget.Mask({"style": "desktop", "html": MWF.APPDTBD.LP.building});
                _self.mask.loadNode(_self.designer.content);

                this.close();

                o2.Actions.load("x_query_assemble_designer").TableAction.buildDispatch( _self.data.application , function(json){

                    _self.designer.notice(MWF.APPDTBD.LP.buildCurrentApp_success, "success", _self.node, {"x": "left", "y": "bottom"});
                    _self.mask.hide();

                    _self.designer.refresh();
                });
            }, function(){
                this.close();
            }, null);
        }.bind(this));
562
    },
563 564 565 566 567 568 569 570 571 572 573 574
    tableClear: function(e){
        var _self = this;
        if (!e) e = this.node;
        this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableClearTitle, MWF.APPDTBD.LP.tableClearInfo, 480, 120, function(){
            _self.designer.actions.deleteAllRow(_self.data.id,function(json){
                this.designer.notice(this.designer.lp.tableClear_success, "success", this.node, {"x": "left", "y": "bottom"});
            }.bind(_self));
            this.close();
        }, function(){
            this.close();
        }, null);
    },
R
roo00 已提交
575 576 577 578 579 580 581 582 583 584
    tableImplode: function(e){
        var _self = this;
        if (!e) e = this.node;
        this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableImplodeTitle, MWF.APPDTBD.LP.tableImplodeInfo, 480, 120, function(){
            _self.implodeLocal();
            this.close();
        }, function(){
            this.close();
        }, null);
    },
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 611 612 613 614 615 616 617 618 619
    tableExcelImplode: function(e){
        var _self = this;
        if (!e) e = this.node;
        this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableExcelImplodeTitle, MWF.APPDTBD.LP.tableExcelImplodeInfo, 480, 120, function(){
            _self.implodeExcelLocal();
            this.close();
        }, function(){
            this.close();
        }, null);
    },
    implodeExcelLocal : function (){
        var ExcelUtils = new MWF.xApplication.query.TableDesigner.Table.ExcelUtils();
        var uploadFileAreaNode = new Element("div");
        var html = "<input name=\"file\" type=\"file\" accept=\"*\" />";
        uploadFileAreaNode.set("html", html);

        var fileUploadNode = uploadFileAreaNode.getFirst();
        fileUploadNode.addEvent("change", function () {
            var files = fileNode.files;
            if (files.length) {
                var file = files.item(0);
                //第三个参数是日期的列
                ExcelUtils.import( file, function(json){
                    console.log(JSON.stringify(json));

                    this.designer.actions.rowSave(this.data.id,json[0],function(json){
                        this.designer.notice(this.designer.lp.tableImplode_success, "success", this.node, {"x": "left", "y": "bottom"});
                    }.bind(this));
                }.bind(this) );

            }
        }.bind(this));
        var fileNode = uploadFileAreaNode.getFirst();
        fileNode.click();
    },
R
roo00 已提交
620 621 622 623 624 625 626 627 628 629 630 631 632 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
    implodeLocal: function(){
        if (!this.uploadFileAreaNode){
            this.uploadFileAreaNode = new Element("div");
            var html = "<input name=\"file\" type=\"file\" accept=\".json\"/>";
            this.uploadFileAreaNode.set("html", html);
            this.fileUploadNode = this.uploadFileAreaNode.getFirst();
            this.fileUploadNode.addEvent("change", this.implodeLocalFile.bind(this));
        }else{
            if (this.fileUploadNode) this.fileUploadNode.destroy();
            this.uploadFileAreaNode.empty();
            var html = "<input name=\"file\" type=\"file\" accept=\".json\"/>";
            this.uploadFileAreaNode.set("html", html);
            this.fileUploadNode = this.uploadFileAreaNode.getFirst();
            this.fileUploadNode.addEvent("change", this.implodeLocalFile.bind(this));
        }
        this.fileUploadNode.click();
    },
    implodeLocalFile: function(){
        var files = this.fileUploadNode.files;
        if (files.length){
            var file = files[0];
            var reader = new FileReader();
            reader.readAsText(file);
            var _self = this;
            reader.onload = function(){
                var data = JSON.parse(this.result);

                _self.designer.actions.rowSave(_self.data.id,data,function(json){
                    this.designer.notice(this.designer.lp.tableImplode_success, "success", this.node, {"x": "left", "y": "bottom"});
                }.bind(_self));

            };
        }
    },
    tableExplode: function(e){
        var _self = this;
        if (!e) e = this.node;
        this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableExplodeTitle, MWF.APPDTBD.LP.tableExplodeInfo, 480, 120, function(){

            var url =  _self.designer.actions.action.address + _self.designer.actions.action.actions.exportRow.uri

            url = url.replace("{tableFlag}",_self.data.id);
            url = url.replace("{count}",1000);
663
            window.open(o2.filterUrl(url))
R
roo00 已提交
664 665 666 667 668
            this.close();
        }, function(){
            this.close();
        }, null);
    },
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
    tableExcelExplode: function(e){
        var ExcelUtils = new MWF.xApplication.query.TableDesigner.Table.ExcelUtils();
        var _self = this;
        if (!e) e = this.node;
        this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableExcelExplodeTitle, MWF.APPDTBD.LP.tableExplodeInfo, 480, 120, function(){
            var fieldList = JSON.parse(_self.view.data.data).fieldList;
            var fieldArr = [];
            var resultArr = [];
            fieldList.each(function (field){
                fieldArr.push(field.name);
                resultArr.push("o." + field.name);
            })
            var array = [fieldArr];
            var jpql = {
                "data": "select " + resultArr.join() + " from " + _self.data.name + " o",
                "type": "select",
                "firstResult": 0,
                "maxResults": 1000
            }
            _self.designer.actions.executeJpql(_self.data.id, jpql, function(json){
                json.data.each(function (d){
                    var f = [];
                    if(o2.typeOf(json.data[0])==="string"){
                        f = [d];
                    }else {
                        d.each(function (dd){
                            if(!dd){
                                f.push("");
                            }else {
                                f.push(dd);
                            }
                        })
                    }
                    array.push(f);
                })
U
unknown 已提交
704
                ExcelUtils.export(array,  MWF.APPDTBD.LP.exportExcelFileName +(new Date).format("db"));
705 706 707 708 709 710
            }.bind(this));
            this.close();
        }, function(){
            this.close();
        }, null);
    },
NoSubject's avatar
NoSubject 已提交
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
    setContentHeight: function(){
        var size = this.areaNode.getSize();
        var titleSize = this.viewTitleNode.getSize()
        debugger;
        var height = size.y-titleSize.y-2;
        // if (this.jpqlAreaNode){
        //     var jpqlSize = this.jpqlAreaNode.getComputedSize();
        //     height = height - jpqlSize.totalHeight;
        // }

        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);
    },
    createJpqlAreaNode: function(callback){
        if (!this.jpqlAreaNode){
            this.viewTitleNode.setStyles(this.css.viewTitleNode_run);
            this.refreshNode.setStyles(this.css.tableRunNode_run);
            this.addColumnNode.setStyles(this.css.addColumnNode_run);

            this.jpqlAreaNode = new Element("div", {
                "styles": this.css.jpqlAreaNode
            }).inject(this.viewTitleContentNode, "top");

            this.jpqlEditor = new MWF.xApplication.query.TableDesigner.Table.JPQLRunner(this.jpqlAreaNode, this.refreshNode, this);
            this.jpqlEditor.load(function(){
                this.jpqlEditor.setJpql("slect", "select o from "+this.data.name+" o", 0, 50);
                if (callback) callback();
            }.bind(this));
            this.setContentHeight();
NoSubject's avatar
NoSubject 已提交
747
        }else{
NoSubject's avatar
NoSubject 已提交
748
            if (callback) callback();
NoSubject's avatar
NoSubject 已提交
749 750
        }
    },
NoSubject's avatar
NoSubject 已提交
751 752 753
    runJpql: function(jpql){
        this.designer.actions.executeJpql(this.data.id, jpql, function(json){
            this.loadViewMask.hide();
NoSubject's avatar
NoSubject 已提交
754

NoSubject's avatar
NoSubject 已提交
755 756 757 758 759 760 761 762 763 764 765 766
            if (jpql.type!="select"){
                this.designer.notice(this.designer.lp.jpqlRunSuccess, "success");
                if (this.lastSelectJPQL) this.runJpql(this.lastSelectJPQL);
            }else{
                this.lastSelectJPQL = jpql;
                this.viewContentBodyNode.empty();
                this.viewContentTableNode = new Element("table", {
                    "styles": this.css.viewContentTableNode,
                    "border": "0px",
                    "cellPadding": "0",
                    "cellSpacing": "0"
                }).inject(this.viewContentBodyNode);
NoSubject's avatar
NoSubject 已提交
767

NoSubject's avatar
NoSubject 已提交
768 769 770 771 772 773 774 775
                if (json.data.length){
                    json.data.each(function(line, idx){
                        new MWF.xApplication.query.TableDesigner.Table.DataLine(line, this);
                    }.bind(this));
                    this.setContentColumnWidth();
                    this.setContentHeight();
                }
            }
NoSubject's avatar
NoSubject 已提交
776

NoSubject's avatar
NoSubject 已提交
777 778 779 780 781 782 783 784 785 786 787 788 789 790
        }.bind(this), function(xhr, text, error){
            this.loadViewMask.hide();
            if (xhr.status!=0){
                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;
                    }
                }
                MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
            }
NoSubject's avatar
NoSubject 已提交
791
        }.bind(this));
NoSubject's avatar
NoSubject 已提交
792 793 794 795 796 797 798 799 800 801 802 803 804 805
    },
    loadViewData: function(){
        if (this.data.buildSuccess){
            if (this.data.id){
                o2.require("o2.widget.Mask", null, false);
                this.loadViewMask = new o2.widget.Mask();
                this.loadViewMask.loadNode(this.viewAreaNode);

                this.createJpqlAreaNode(function(){
                    var jpql = this.jpqlEditor.getJpql();
                    this.runJpql(jpql);
                }.bind(this));
            }
        }
NoSubject's avatar
NoSubject 已提交
806 807 808
    }
});

NoSubject's avatar
NoSubject 已提交
809
MWF.xApplication.query.TableDesigner.Table.Column = new Class({
810
    Extends:MWF.xApplication.query.ViewDesigner.ViewBase.Column,
R
roo00 已提交
811
    initialize: function(json, view, next){
812
        this.propertyPath = "../x_component_query_TableDesigner/$Table/column.html";
R
roo00 已提交
813
        this.view = view;
NoSubject's avatar
NoSubject 已提交
814 815 816 817 818 819
        this.json = json;
        this.next = next;
        this.css = this.view.css;
        this.content = this.view.viewTitleTrNode;
        this.domListNode = this.view.domListNode;
        this.load();
R
roo00 已提交
820
    },
NoSubject's avatar
NoSubject 已提交
821
    createDomListItem: function(){
R
roo00 已提交
822
        //this.view.columnListEditTr;
NoSubject's avatar
NoSubject 已提交
823 824 825 826 827
        var idx = this.view.columnListTable.rows.length;
        this.listNode = this.view.columnListTable.insertRow(idx-1).setStyles(this.css.cloumnListNode);
        this.listNode.insertCell().setStyles(this.css.columnListTd).set("text", this.json.name);
        this.listNode.insertCell().setStyles(this.css.columnListTd).set("text", this.json.description);
        this.listNode.insertCell().setStyles(this.css.columnListTd).set("text", this.json.type);
NoSubject's avatar
NoSubject 已提交
828 829
        this.resetTextNode();
    },
NoSubject's avatar
NoSubject 已提交
830 831 832 833 834 835 836 837 838 839 840
    selected: function(){
        debugger;
        if (this.view.currentSelectedModule){
            if (this.view.currentSelectedModule==this){
                return true;
            }else{
                if (!this.view.currentSelectedModule.unSelected()) return true;
            }
        }
        this.node.setStyles(this.css.viewTitleColumnNode_selected);
        this.listNode.setStyles(this.css.cloumnListNode_selected);
NoSubject's avatar
NoSubject 已提交
841

NoSubject's avatar
NoSubject 已提交
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865
        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.currentSelectedModule = this;
        this.isSelected = true;
        this._showActions();
        this.showProperty();
    },
    unSelected: function(){
        if (this.checkColumn()){
            this.resetTextNode();
            this.view.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();
            return true;
NoSubject's avatar
NoSubject 已提交
866
        }
NoSubject's avatar
NoSubject 已提交
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
        return false;
    },
    checkColumn: function(){
        debugger;
        var tds = this.listNode.getElements("td");
        var nameInput = tds[0].getFirst();
        var descriptionInput = tds[1].getFirst();
        var select = tds[2].getFirst();

        if (nameInput && nameInput.tagName.toString().toLowerCase()=="input"){
            var name = tds[0].getFirst().get("value");
            var description = tds[1].getFirst().get("value");
            var type = tds[2].getFirst().options[tds[2].getFirst().selectedIndex].value;

            if (name && name!==this.json.name && this.view.checkColumnName(name)){
                if (!this.view.json.draftData.fieldList) this.view.json.draftData.fieldList = [];
                var columnNames = this.view.json.draftData.fieldList.map(function(item){ return item.name; });
                if ((columnNames.indexOf(name)!=-1)){
                    this.view.designer.notice(this.view.designer.lp.duplicateName, "error");
                    tds[0].getFirst().focus();
                    return false;
                }else{
                    this.json.name = name;
                    this.json.description = description;
                    this.json.type = type;
                    return true;
                }
            }else if (name==this.json.name){
                this.json.name = name;
                this.json.description = description;
                this.json.type = type;
                return true;
            }else{
                this.view.designer.notice(this.view.designer.lp.inputName, "error");
                tds[0].getFirst().focus();
                return false;
            }
        }
        return true;
    },

    showProperty: function(){
        var tds = this.listNode.getElements("td");
        tds[0].empty();
        tds[1].empty();
        tds[2].empty();
        var nameInput = new Element("input", {"styles": this.css.columnListEditModifyInput, "value": this.json.name}).inject(tds[0]);
        var descriptionInput = new Element("input", {"styles": this.css.columnListEditModifyInput, "value": this.json.description}).inject(tds[1]);

        var select = new Element("select", {"styles": this.css.columnListEditModifySelect}).inject(tds[2]);
        //var options = '<option value=""></option>';
        var options = '<option '+((this.json.type=='string') ? 'selected' : '')+' value="string">string</option>';
        options += '<option '+((this.json.type=='integer') ? 'selected' : '')+' value="integer">integer</option>';
        options += '<option '+((this.json.type=='long') ? 'selected' : '')+' value="long">long</option>';
        options += '<option '+((this.json.type=='double') ? 'selected' : '')+' value="double">double</option>';
        options += '<option '+((this.json.type=='boolean') ? 'selected' : '')+' value="boolean">boolean</option>';
        options += '<option '+((this.json.type=='date') ? 'selected' : '')+' value="date">date</option>';
        options += '<option '+((this.json.type=='time') ? 'selected' : '')+' value="time">time</option>';
        options += '<option '+((this.json.type=='dateTime') ? 'selected' : '')+' value="dateTime">dateTime</option>';
        options += '<option '+((this.json.type=='stringList') ? 'selected' : '')+' value="stringList">stringList</option>';
        options += '<option '+((this.json.type=='integerList') ? 'selected' : '')+' value="integerList">integerList</option>';
        options += '<option '+((this.json.type=='longList') ? 'selected' : '')+' value="longList">longList</option>';
        options += '<option '+((this.json.type=='doubleList') ? 'selected' : '')+' value="doubleList">doubleList</option>';
        options += '<option '+((this.json.type=='booleanList') ? 'selected' : '')+' value="booleanList">booleanList</option>';
        options += '<option '+((this.json.type=='stringLob') ? 'selected' : '')+' value="stringLob">stringLob</option>';
        options += '<option '+((this.json.type=='stringMap') ? 'selected' : '')+' value="stringMap">stringMap</option>';
        select.set("html", options);

        nameInput.focus();

        select.addEvents({
            "change": function(e){
                if (this.checkColumn()) this.resetColumnTextNode();
            }.bind(this),
            "click": function(e){e.stopPropagation()}
        });
        nameInput.addEvents({
            "keydown": function(e){ if (e.code==13) if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
            "change": function(e){ if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
            "click": function(e){e.stopPropagation()}
        });
        descriptionInput.addEvents({
            "keydown": function(e){ if (e.code==13) if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
            "change": function(e){ if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
            "click": function(e){e.stopPropagation()}
        });
    },
    hideProperty: function(){
        var tds = this.listNode.getElements("td");
        tds[0].empty().set("text", this.json.name);
        tds[1].empty().set("text", this.json.description);
        tds[2].empty().set("text", this.json.type);
    },
    resetColumnTextNode: function(){
        var text = (this.json.description) ? this.json.name+"("+this.json.description+")" : this.json.name;
        this.textNode.set("text", text);
    },
    resetTextNode: function(){
        var text = (this.json.description) ? this.json.name+"("+this.json.description+")" : this.json.name;

        this.textNode.set("text", text);
        this.listNode.getFirst().set("text", this.json.name);
        this.listNode.getFirst().getNext().set("text", this.json.description);
        this.listNode.getLast().set("text", this.json.type);
    },
    "delete": function(e){
        var _self = this;
        if (!e) e = this.node;
        this.view.designer.confirm("warn", e, MWF.APPDTBD.LP.deleteColumnTitle, MWF.APPDTBD.LP.deleteColumn, 300, 120, function(){
            _self.destroy();

            this.close();
        }, function(){
            this.close();
        }, null);
NoSubject's avatar
NoSubject 已提交
982
    },
NoSubject's avatar
NoSubject 已提交
983 984 985 986 987
    destroy: function(){
        if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
        if (this.actionArea) this.actionArea.destroy();
        if (this.listNode) this.listNode.destroy();
        if (this.property) this.property.propertyContent.destroy();
NoSubject's avatar
NoSubject 已提交
988

NoSubject's avatar
NoSubject 已提交
989
        var idx = this.view.items.indexOf(this);
NoSubject's avatar
NoSubject 已提交
990

NoSubject's avatar
NoSubject 已提交
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
        if (this.view.viewContentTableNode){
            var trs = this.view.viewContentTableNode.getElements("tr");
            trs.each(function(tr){
                tr.deleteCell(idx);
            }.bind(this));
        }

        if (this.view.json.draftData.fieldList) this.view.json.draftData.fieldList.erase(this.json);
        this.view.items.erase(this);
        this.areaNode.destroy();
        this.view.selected();
        this.view.setViewWidth();
        MWF.release(this);
        delete this;
    },
    addColumn: function(e, data){
        var json;
        if (!data){
            if (!this.view.json.draftData.fieldList) this.view.json.draftData.fieldList = [];
            var columnNames = this.view.json.draftData.fieldList.map(function(item){ return item.name; });
            var name = "column";
            var i=1;
            while(columnNames.indexOf(name)!=-1){
                name = "column"+i;
                i++;
NoSubject's avatar
NoSubject 已提交
1016
            }
NoSubject's avatar
NoSubject 已提交
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
            json = {
                "name": name,
                "type":"string",
                "description": this.view.designer.lp.newColumn
            };
        }else{
            json = data;
        }

        this.view.json.draftData.fieldList.push(json);
        var column = new MWF.xApplication.query.TableDesigner.Table.Column(json, this.view, this);
        this.view.items.push(column);
        column.selected();

        if (this.view.viewContentTableNode){
            var trs = this.view.viewContentTableNode.getElements("tr");
            trs.each(function(tr){
                new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
            }.bind(this));
            //this.setContentColumnWidth();
NoSubject's avatar
NoSubject 已提交
1037
        }
NoSubject's avatar
NoSubject 已提交
1038 1039
        this.view.setViewWidth();
        this.view.addColumnNode.scrollIntoView(true);
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
    },

    _createIconAction: function(){
        if (!this.actionArea){
            this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.view.areaNode, "after");
            this._createAction({
                "name": "add",
                "icon": "add.png",
                "event": "click",
                "action": "addColumn",
                "title": MWF.APPDVD.LP.action.add
            });
            this._createAction({
                "name": "delete",
                "icon": "delete1.png",
                "event": "click",
                "action": "delete",
                "title": MWF.APPDVD.LP.action["delete"]
            });
        }
NoSubject's avatar
NoSubject 已提交
1060 1061
    }
});
NoSubject's avatar
NoSubject 已提交
1062

NoSubject's avatar
NoSubject 已提交
1063 1064 1065 1066 1067 1068 1069 1070
MWF.xApplication.query.TableDesigner.Table.DataLine = new Class({
    initialize: function(data, table){
        this.table = table;
        this.lineData = data;
        this.tableData = this.table.data;
        this.tableContentTableNode = this.table.viewContentTableNode;
        this.css = this.table.css;
        this.load();
NoSubject's avatar
NoSubject 已提交
1071 1072
    },

NoSubject's avatar
NoSubject 已提交
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
    load: function(){
        this.tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.tableContentTableNode);

        this.tableData.draftData.fieldList.each(function(c, i){
            var d = this.lineData[c.name];
            var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.tr);
            td.store("field", c);

            if (d!=undefined){

                var t = o2.typeOf(d);
                switch (t){
                    case "array":
                        td.store("data", d);
                        td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>[...]</div>");
                        break;
                    case "object":
                        td.store("data", d);
                        td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>{...}</div>");
                        break;
                    default:
                        td.set("text", d);
                }
NoSubject's avatar
NoSubject 已提交
1096
            }else{
NoSubject's avatar
NoSubject 已提交
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
                switch (c.type){
                    case "stringList":
                    case "integerList":
                    case "longList":
                    case "doubleList":
                    case "booleanList":
                        td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>[...]</div>");
                        break;
                    case "stringLob":
                        td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>...</div>");
                        break;
                    case "stringMap":
                        td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>{...}</div>");
                        break;
                    default:
                        td.set("text", "");
                }
NoSubject's avatar
NoSubject 已提交
1114 1115
            }

NoSubject's avatar
NoSubject 已提交
1116 1117 1118
            if (td.getFirst()){
                td.getFirst().addEvent("click", function(e){
                    this.getFieldValue(e.target.getParent());
NoSubject's avatar
NoSubject 已提交
1119 1120 1121 1122
                }.bind(this));
            }
        }.bind(this));
    },
NoSubject's avatar
NoSubject 已提交
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
    createObjectValueDlg: function(target){
        var div = new Element("div", {"styles": {"margin": "10px 10px 0px 10px", "padding": "5px", "overflow": "hidden"}});
        //var node = new Element("div", {"styles": {"margin": "10px 10px 0px 10px", "padding": "5px", "overflow": "hidden"}}).inject(div);
        var p = target.getPosition(this.table.designer.content);
        var s = target.getSize();
        var size = this.table.designer.content.getSize();
        var top = p.y;
        var left = (p.x+s.x/2)-180;
        if (top+400+10>size.y) top = size.y-400-10;
        if (left+360+10>size.x) left = size.x-360-10;
        if (top<10) top = 10;
        if (left<10) left = 10;
        var fromTop = p.y+s.y/2;
        var fromLeft = p.x+s.x/2;

        var options ={
            "content": div,
            "isTitle": false,
            "container": this.table.designer.content,
            "width": 360,
            "height": 400,
            "top": top,
            "left": left,
            "fromTop": fromTop,
            "fromLeft": fromLeft,
            "buttonList": [
                {
                    "text": this.table.designer.lp.close,
                    "action": function(){dlg.close();}.bind(this)
NoSubject's avatar
NoSubject 已提交
1152
                }
NoSubject's avatar
NoSubject 已提交
1153 1154 1155 1156
            ]
        }
        var dlg = o2.DL.open(options);
        return dlg;
NoSubject's avatar
NoSubject 已提交
1157
    },
NoSubject's avatar
NoSubject 已提交
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
    getFieldValue: function(node){
        var field = node.retrieve("field")
        this.loadFieldValue(field.name, function(){
            var value = this.lineData[field.name];
            var dlg = this.createObjectValueDlg(node);
            var listNode = dlg.content.getFirst();

            switch (field.type){
                case "stringList":
                case "integerList":
                case "longList":
                case "doubleList":
                case "booleanList":
                    o2.require("o2.widget.Arraylist", function(){
                        var list = new o2.widget.Arraylist(listNode, {
                            "style": "table",
                            "title": field.name,
                            "isAdd": false,
                            "isDelete": false,
                            "isModify": false
                        });
                        list.load(value);
NoSubject's avatar
NoSubject 已提交
1180
                    }.bind(this));
NoSubject's avatar
NoSubject 已提交
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
                    break;
                case "stringLob":
                    td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>...</div>");
                    break;
                case "stringMap":
                    o2.require("o2.widget.Maplist", function(){
                        var list = new o2.widget.Maplist(listNode, {
                            "style": "table",
                            "title": field.name,
                            "isAdd": false,
                            "isDelete": false,
                            "isModify": false
                        });
                        list.load(value);
                    }.bind(this));
                    break;
            }
        }.bind(this));
    },
    loadFieldValue: function(name, callback){
        if (name){
            if (this.lineData[name]){
                if (callback) callback();
NoSubject's avatar
NoSubject 已提交
1204
            }else{
NoSubject's avatar
NoSubject 已提交
1205 1206 1207 1208
                this.table.designer.actions.getRow(this.tableData.id, this.lineData.id, function(json){
                    this.lineData = json.data;
                    if (callback) callback();
                }.bind(this));
NoSubject's avatar
NoSubject 已提交
1209 1210
            }
        }
NoSubject's avatar
NoSubject 已提交
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
    }
});

MWF.xApplication.query.TableDesigner.Table.JPQLRunner = new Class({
    initialize: function(node, runNode, table){
        this.table = table;
        this.node = node;
        this.runNode = runNode;
        this.css = this.table.css;
        this.lp = this.table.designer.lp;
        //this.select = select;
NoSubject's avatar
NoSubject 已提交
1222
    },
NoSubject's avatar
NoSubject 已提交
1223 1224 1225 1226 1227 1228 1229 1230 1231 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
    load: function(callback){
        this.optionArea = new Element("div", {"styles": this.css.jpqlOptionArea}).inject(this.node);
        //this.contentArea = new Element("div", {"styles": this.css.jpqlContentArea}).inject(this.node);
        this.contentWhereArea = new Element("div", {"styles": this.css.jpqlContentWhereArea}).inject(this.node);
        this.loadOptions();
        //this.loadSelectEditor(callback);
        this.loadEditor(callback);
    },
    loadOptions: function(){
        var html = "<table cellpadding='0' cellspacing='0' style='height:30px'><tr>";
        html += "<td style='padding: 0 5px'>"+this.lp.jpqlType+"</td>";
        html += "<td style='padding: 0 5px'><select><option value='select'>select</option><option value='update'>update</option><option value='delete'>delete</option></select></td>";
        html += "<td style='padding: 0 5px'>"+this.lp.jpqlFromResult+"</td>";
        html += "<td style='padding: 0 5px'><input type='number' value='1'/></td>";
        html += "<td style='padding: 0 5px'>"+this.lp.jpqlMaxResult+"</td>";
        html += "<td style='padding: 0 5px'><input type='number' value='50'/></td>";
        // html += "<td style='padding: 0 5px'>"+this.lp.jpqlSelectTitle+"</td>";
        // html += "<td style='padding: 0 5px'><input readonly type='text' value='"+this.select+"'/></td>";
        // html += "<td style='padding: 0 5px'>"+this.lp.inputWhere+"</td>";
        html += "</tr></table>";
        this.optionArea.set("html", html);
        this.jpqlTypeSelect = this.optionArea.getElement("select");
        var inputs = this.optionArea.getElements("input");
        this.fromResultInput = inputs[0];
        this.maxResultsInput = inputs[1];
        this.jpqlTypeSelect.setStyles(this.css.jpqlTypeSelect);
        this.fromResultInput.setStyles(this.css.jpqlOptionInput);
        this.maxResultsInput.setStyles(this.css.jpqlOptionInput);

        this.jpqlTypeSelect.addEvent("change", function(){
            var type = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value;
            this.changeType(type, true);
        }.bind(this));
        // inputs[2].setStyles(this.css.jpqlOptionInput);
        // inputs[2].setStyle("width", "200px")
    },
    // loadSelectEditor: function(){
    //     this.contentArea.set("text", this.select);
    //     o2.require("o2.widget.ace", function(){
    //         o2.widget.ace.load(function(){
1263
    //             o2.load("../o2_lib/ace/src-min-noconflict/ext-static_highlight.js", function(){
NoSubject's avatar
NoSubject 已提交
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
    //                 var highlight = ace.require("ace/ext/static_highlight");
    //                 highlight(this.contentArea, {mode: "ace/mode/jql", theme: "ace/theme/tomorrow", "fontSize": 16});
    //             }.bind(this));
    //         }.bind(this));
    //     }.bind(this));
    // },
    loadEditor: function(callback){
        o2.require("o2.widget.JavascriptEditor", function(){
            this.editor = new o2.widget.JavascriptEditor(this.contentWhereArea, {"title": "JPQL", "option": {"mode": "sql"}});
            this.editor.load(function(){
NoSubject's avatar
NoSubject 已提交
1274
                this.editor.addEditorEvent("change", function(){
NoSubject's avatar
NoSubject 已提交
1275 1276
                    this.checkJpqlType();
                }.bind(this));
NoSubject's avatar
NoSubject 已提交
1277 1278 1279 1280

                // this.editor.editor.on("change", function(){
                //     this.checkJpqlType();
                // }.bind(this));
NoSubject's avatar
NoSubject 已提交
1281
                if (callback) callback();
NoSubject's avatar
NoSubject 已提交
1282
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
1283
        }.bind(this), false);
NoSubject's avatar
NoSubject 已提交
1284
    },
NoSubject's avatar
NoSubject 已提交
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
    checkJpqlType: function(){
        var str = this.editor.editor.getValue();
        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 (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;
                }
            }
            if (type!="select"){
                var tds = this.optionArea.getElements("td");
                tds[2].hide();
                tds[3].hide();
                tds[4].hide();
                tds[5].hide();
NoSubject's avatar
NoSubject 已提交
1308
            }else{
NoSubject's avatar
NoSubject 已提交
1309 1310 1311 1312 1313
                var tds = this.optionArea.getElements("td");
                tds[2].show();
                tds[3].show();
                tds[4].show();
                tds[5].show();
NoSubject's avatar
NoSubject 已提交
1314 1315
            }
        }
NoSubject's avatar
NoSubject 已提交
1316 1317 1318 1319
    },
    setJpql: function(type, jpql, firstResult, maxResults){
        if (this.editor){
            if (this.editor.editor) this.editor.editor.setValue(jpql);
NoSubject's avatar
NoSubject 已提交
1320
        }
NoSubject's avatar
NoSubject 已提交
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330
        if (this.jpqlTypeSelect){
            for (var i=0; i<this.jpqlTypeSelect.options.length; i++){
                if (this.jpqlTypeSelect.options[i].value==type.toString().toLowerCase()){
                    this.jpqlTypeSelect.options[i].set("selected", true);
                    break;
                }
            }
        }
        if (this.fromResultInput) this.fromResultInput.set("value", firstResult);
        if (this.maxResultsInput) this.maxResultsInput.set("value", maxResults);
NoSubject's avatar
NoSubject 已提交
1331
    },
NoSubject's avatar
NoSubject 已提交
1332 1333 1334 1335 1336 1337 1338 1339 1340 1341
    getJpql: function(){
        var jpql = this.editor.editor.getValue();
        var type = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].get("value");
        var fromResult = this.fromResultInput.get("value");
        var maxResults = this.maxResultsInput.get("value");
        return {
            "data": jpql,
            "type": type,
            "firstResult": fromResult.toInt(),
            "maxResults": maxResults.toInt()
NoSubject's avatar
NoSubject 已提交
1342 1343
        }
    }
1344
});
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380

MWF.xApplication.query.TableDesigner.Table.ExcelUtils = new Class({
    _loadResource : function( callback ){
        var uri = "/x_component_Template/framework/xlsx/xlsx.full.js";
        var uri2 = "/x_component_Template/framework/xlsx/xlsxUtils.js";
        COMMON.AjaxModule.load(uri, function(){
            COMMON.AjaxModule.load(uri2, function(){
                callback();
            }.bind(this))
        }.bind(this))
    },
    _openDownloadDialog: function(url, saveName){
        /**
         * 通用的打开下载对话框方法,没有测试过具体兼容性
         * @param url 下载地址,也可以是一个blob对象,必选
         * @param saveName 保存文件名,可选
         */
        if( Browser.name !== 'ie' ){
            if(typeof url == 'object' && url instanceof Blob){
                url = URL.createObjectURL(url); // 创建blob地址
            }
            var aLink = document.createElement('a');
            aLink.href = url;
            aLink.download = saveName || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
            var event;
            if(window.MouseEvent && typeOf( window.MouseEvent ) == "function" ) event = new MouseEvent('click');
            else
            {
                event = document.createEvent('MouseEvents');
                event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
            }
            aLink.dispatchEvent(event);
        }else{
            window.navigator.msSaveBlob( url, saveName);
        }
    },
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394
    index2ColName : function( index ){
        if (index < 0) {
            return null;
        }
        var num = 65;// A的Unicode码
        var colName = "";
        do {
            if (colName.length > 0)index--;
            var remainder = index % 26;
            colName =  String.fromCharCode(remainder + num) + colName;
            index = (index - remainder) / 26;
        } while (index > 0);
        return colName;
    },
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406
    export : function(array, fileName){
        this._loadResource( function(){
            data = xlsxUtils.format2Sheet(array, 0, 0, null);//偏移3行按keyMap顺序转换
            var wb = xlsxUtils.format2WB(data, "sheet1", undefined);
            var wopts = { bookType: 'xlsx', bookSST: false, type: 'binary' };
            var dataInfo = wb.Sheets[wb.SheetNames[0]];

            var widthArray = [];
            array[0].each( function( v, i ){

                widthArray.push( {wpx: 100} );

1407 1408
                // var at = String.fromCharCode(97 + i).toUpperCase();
                var at = this.index2ColName(i);
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463
                var di = dataInfo[at+"1"];
                // di.v = v;
                // di.t = "s";
                di.s = {  //设置副标题样式
                    font: {
                        //name: '宋体',
                        sz: 12,
                        color: {rgb: "#FFFF0000"},
                        bold: true,
                        italic: false,
                        underline: false
                    },
                    alignment: {
                        horizontal: "center" ,
                        vertical: "center"
                    }
                };
            }.bind(this));
            dataInfo['!cols'] = widthArray,

                this._openDownloadDialog(xlsxUtils.format2Blob(wb), fileName +".xlsx");
        }.bind(this))
    },
    import : function( file, callback, dateColArray ){
        this._loadResource( function(){
            var reader = new FileReader();
            var workbook, data;
            reader.onload = function (e) {
                //var data = data.content;
                if (!e) {
                    data = reader.content;
                }else {
                    data = e.target.result;
                }
                workbook = XLSX.read(data, { type: 'binary' });
                //wb.SheetNames[0]是获取Sheets中第一个Sheet的名字
                //wb.Sheets[Sheet名]获取第一个Sheet的数据
                var sheet = workbook.SheetNames[0];
                var jsonList = [];
                for (var sheet in workbook.Sheets) {
                    if (workbook.Sheets.hasOwnProperty(sheet)) {
                        fromTo = workbook.Sheets[sheet]['!ref'];
                        console.log(fromTo);
                        var json = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
                        console.log(JSON.stringify(json));
                        jsonList.push(json);
                        // break; // 如果只取第一张表,就取消注释这行
                    }
                }
                if(callback)callback(jsonList);
            };
            reader.readAsBinaryString(file);
        })
    }
});