Statement.js 41.0 KB
Newer Older
U
unknown 已提交
1 2 3
MWF.xApplication.query = MWF.xApplication.query || {};
MWF.xApplication.query.Query = MWF.xApplication.query.Query || {};
MWF.xDesktop.requireApp("query.Query", "Viewer", null, false);
U
unknown 已提交
4

U
unknown 已提交
5 6
MWF.xApplication.query.Query.Statement = MWF.QStatement = new Class({
    Extends: MWF.QViewer,
U
unknown 已提交
7
    options: {
U
unknown 已提交
8
        "lazy": false,
U
unknown 已提交
9 10 11
        "moduleEvents": ["queryLoad", "postLoad", "postLoadPageData", "postLoadPage", "selectRow", "unselectRow",
            "queryLoadItemRow", "postLoadItemRow", "queryLoadCategoryRow", "postLoadCategoryRow", "export", "exportRow"]
    },
12
    initialize: function (container, json, options, app, parentMacro) {
U
unknown 已提交
13 14 15 16 17 18 19 20
        //本类有三种事件,
        //一种是通过 options 传进来的事件,包括 loadView、openDocument、select
        //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
        //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件

        this.setOptions(options);

        this.path = "../x_component_query_Query/$Viewer/";
21
        this.cssPath = "../x_component_query_Query/$Viewer/" + this.options.style + "/css.wcss";
U
unknown 已提交
22 23 24 25 26 27
        this._loadCss();
        this.lp = MWF.xApplication.query.Query.LP;

        this.app = app;

        this.container = $(container);
U
unknown 已提交
28

U
unknown 已提交
29
        this.json = json || {};
U
unknown 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43

        this.parentMacro = parentMacro;

        this.originalJson = Object.clone(json);

        this.viewJson = null;
        this.filterItems = [];
        this.searchStatus = "none"; //none, custom, default


        this.items = [];
        this.selectedItems = [];
        this.hideColumns = [];
        this.openColumns = [];
U
unknown 已提交
44
        this.parameter = {};
U
unknown 已提交
45 46 47

        this.gridJson = null;

48 49
        if (this.options.isload) {
            this.init(function () {
U
unknown 已提交
50 51 52 53 54
                this.load();
            }.bind(this));
        }

    },
55 56
    init: function (callback) {
        if (this.json.view) {
U
unknown 已提交
57
            this.viewJson = JSON.decode(this.json.view);
U
unknown 已提交
58
            this.statementJson = this.json;
U
unknown 已提交
59
            this.statementJson.viewJson = this.viewJson;
U
unknown 已提交
60
            if (callback) callback();
61
        } else {
U
unknown 已提交
62 63 64 65 66 67 68 69 70
            this.getView(callback);
        }
    },
    loadMacro: function (callback) {
        MWF.require("MWF.xScript.Macro", function () {
            this.Macro = new MWF.Macro.ViewContext(this);
            if (callback) callback();
        }.bind(this));
    },
71
    createActionbarNode: function () {
U
unknown 已提交
72
        this.actionbarAreaNode.empty();
73 74 75
        if (typeOf(this.json.showActionbar) === "boolean" && this.json.showActionbar !== true) return;
        if (typeOf(this.viewJson.actionbarHidden) === "boolean") {
            if (this.viewJson.actionbarHidden === true || !this.viewJson.actionbarList || !this.viewJson.actionbarList.length) return;
U
unknown 已提交
76 77 78 79
            this.actionbar = new MWF.xApplication.query.Query.Statement.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
            this.actionbar.load();
        }
    },
80
    _loadPageNode: function () {
U
unknown 已提交
81
        this.viewPageAreaNode.empty();
82
        if (!this.paging) {
U
unknown 已提交
83
            var json;
84
            if (!this.viewJson.pagingList || !this.viewJson.pagingList.length) {
U
unknown 已提交
85 86 87 88
                json = {
                    "firstPageText": this.lp.firstPage,
                    "lastPageText": this.lp.lastPage
                };
89
            } else {
U
unknown 已提交
90 91 92 93
                json = this.viewJson.pagingList[0];
            }
            this.paging = new MWF.xApplication.query.Query.Statement.Paging(this.viewPageAreaNode, json, this, {});
            this.paging.load();
94
        } else {
U
unknown 已提交
95 96 97
            this.paging.reload();
        }
    },
U
unknown 已提交
98 99 100 101 102 103
    // _initPage: function(){
    //     var i = this.count/this.json.pageSize;
    //     this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
    //     this.currentPage = this.options.defaultPage || 1;
    //     this.options.defaultPage = null;
    // },
104 105
    lookup: function (data, callback) {
        if (this.lookuping) return;
U
unknown 已提交
106
        this.lookuping = true;
U
unknown 已提交
107 108
        // this.getLookupAction(function(){
        //     if (this.json.application){
U
unknown 已提交
109

U
unknown 已提交
110
        var d = Object.clone( data || {} );
U
unknown 已提交
111 112 113
        // d.count = this.json.count;
        // this.lookupAction.bundleView(this.json.id, d, function(json){
        //     this.bundleItems = json.data.valueList;
U
unknown 已提交
114

U
unknown 已提交
115
        // this._initPage();
U
unknown 已提交
116

U
unknown 已提交
117
        debugger;
118 119
        this.loadParameter(d);
        this.loadFilter(d);
U
unknown 已提交
120 121 122 123

        this.currentPage = this.options.defaultPage || 1;
        this.options.defaultPage = null;

124 125
        if (this.noDataTextNode) this.noDataTextNode.destroy();
        this.loadCurrentPageData(function (json) {
U
unknown 已提交
126
            if (this.count || (json.data && json.data.length )) {
U
unknown 已提交
127 128
                this.fireEvent("postLoad"); //用户配置的事件
                this.lookuping = false;
129 130
                if (callback) callback(this);
            } else {
U
unknown 已提交
131
                this.viewPageAreaNode.empty();
132
                if (this.viewJson.noDataText) {
U
unknown 已提交
133
                    var noDataTextNodeStyle = this.css.noDataTextNode;
134
                    if (this.viewJson.viewStyles && this.viewJson.viewStyles["noDataTextNode"]) {
U
unknown 已提交
135 136
                        noDataTextNodeStyle = this.viewJson.viewStyles["noDataTextNode"];
                    }
137
                    this.noDataTextNode = new Element("div", {
U
unknown 已提交
138
                        "styles": noDataTextNodeStyle,
139 140
                        "text": this.viewJson.noDataText
                    }).inject(this.contentAreaNode);
U
unknown 已提交
141 142 143 144 145 146 147
                }
                // if (this.loadingAreaNode){
                //     this.loadingAreaNode.destroy();
                //     this.loadingAreaNode = null;
                // }
                this.fireEvent("postLoad"); //用户配置的事件
                this.lookuping = false;
148
                if (callback) callback(this);
U
unknown 已提交
149 150 151
            }


152
        }.bind(this), true, "all");
U
unknown 已提交
153 154

        // }.bind(this));
U
unknown 已提交
155 156 157
        // }
        // }.bind(this));
    },
158
    loadFilter: function (data) {
U
unknown 已提交
159
        debugger;
U
unknown 已提交
160
        this.filterList = [];
161
        (data.filterList || []).each(function (d) {
162 163 164 165 166 167 168
            var pName = d.path.replace(/\./g, "_");

            var parameterName = pName;
            var suffix = 1;
            while( this.parameter[parameterName] ){
                parameterName = pName + "_" + suffix;
                suffix++;
169
            }
170

U
unknown 已提交
171
            var value = d.value;
U
unknown 已提交
172 173 174
            // if( d.code && d.code.code ){
            //     value = this.Macro.exec( d.code.code, this);
            // }
175 176 177 178 179 180 181 182 183 184 185
            if (d.comparison === "like" || d.comparison === "notLike") {
                if (value.substr(0, 1) !== "%") value = "%" + value;
                if (value.substr(value.length - 1, 1) !== "%") value = value + "%";
                this.parameter[parameterName] = value; //"%"+value+"%";
            } else {
                if (d.formatType === "dateTimeValue" || d.formatType === "datetimeValue") {
                    value = "{ts '" + value + "'}"
                } else if (d.formatType === "dateValue") {
                    value = "{d '" + value + "'}"
                } else if (d.formatType === "timeValue") {
                    value = "{t '" + value + "'}"
U
unknown 已提交
186 187
                } else if (d.formatType === "numberValue"){
                    value = parseFloat(value);
U
unknown 已提交
188
                }
189
                this.parameter[parameterName] = value;
U
unknown 已提交
190 191 192
            }
            d.value = parameterName;

193 194
            if( !d.logic )d.logic = "and";

195
            this.filterList.push(d);
U
unknown 已提交
196 197
        }.bind(this))
    },
198
    loadParameter: function () {
U
unknown 已提交
199
        this.parameter = {};
U
unknown 已提交
200
        debugger;
U
unknown 已提交
201
        var parameter = this.json.parameter ? Object.clone(this.json.parameter) : {};
U
unknown 已提交
202
        //系统默认的参数
203
        (this.viewJson.parameterList || []).each(function (f) {
U
unknown 已提交
204
            var value = f.value;
205 206 207
            if (parameter && parameter[f.parameter]) {
                value = parameter[f.parameter];
                delete parameter[f.parameter];
U
unknown 已提交
208
            }
209
            if (typeOf(value) === "date") {
U
unknown 已提交
210 211
                value = value.format("db");
            }
212 213 214
            if (f.valueType === "script") {
                value = this.Macro.exec(f.valueScript ? f.valueScript.code : "", this);
            } else {
U
unknown 已提交
215
                var user = layout.user;
216
                switch (f.value) {
U
unknown 已提交
217
                    case "@person":
U
unknown 已提交
218
                        value = user.distinguishedName;
U
unknown 已提交
219 220
                        break;
                    case "@identityList":
221 222
                        value = user.identityList.map(function (d) {
                            return d.distinguishedName;
U
unknown 已提交
223
                        });
U
unknown 已提交
224 225
                        break;
                    case "@unitList":
226 227
                        o2.Actions.load("x_organization_assemble_express").UnitAction.listWithPerson({"personList": [user.distinguishedName]}, function (json) {
                            value = json.unitList;
U
unknown 已提交
228
                        }, null, false);
U
unknown 已提交
229 230
                        break;
                    case "@unitAllList":
231 232
                        o2.Actions.load("x_organization_assemble_express").UnitAction.listWithIdentitySupNested({"personList": [user.distinguishedName]}, function (json) {
                            value = json.unitList;
U
unknown 已提交
233
                        }, null, false);
U
unknown 已提交
234 235 236 237 238
                        break;
                    case "@year":
                        value = (new Date().getFullYear()).toString();
                        break;
                    case "@season":
U
unknown 已提交
239
                        var m = new Date().format("%m");
240
                        if (["01", "02", "03"].contains(m)) {
U
unknown 已提交
241
                            value = "1"
242
                        } else if (["04", "05", "06"].contains(m)) {
U
unknown 已提交
243
                            value = "2"
244
                        } else if (["07", "08", "09"].contains(m)) {
U
unknown 已提交
245
                            value = "3"
246
                        } else {
U
unknown 已提交
247 248
                            value = "4"
                        }
U
unknown 已提交
249 250 251 252 253 254 255 256
                        break;
                    case "@month":
                        value = new Date().format("%Y-%m");
                        break;
                    case "@time":
                        value = new Date().format("db");
                        break;
                    case "@date":
U
unknown 已提交
257
                        value = new Date().format("%Y-%m-%d");
U
unknown 已提交
258 259 260 261
                        break;
                    default:
                }
            }
262 263 264 265 266 267
            if (f.formatType === "dateTimeValue" || f.formatType === "datetimeValue") {
                value = "{ts '" + value + "'}"
            } else if (f.formatType === "dateValue") {
                value = "{d '" + value + "'}"
            } else if (f.formatType === "timeValue") {
                value = "{t '" + value + "'}"
U
unknown 已提交
268
            }
269
            this.parameter[f.parameter] = value;
U
unknown 已提交
270 271
        }.bind(this));
        //传入的参数
272
        for (var p in parameter) {
U
unknown 已提交
273
            var value = parameter[p];
274 275
            if (typeOf(value) === "date") {
                value = "{ts '" + value.format("db") + "'}"
U
unknown 已提交
276
            }
277
            this.parameter[p] = value;
U
unknown 已提交
278
        }
U
unknown 已提交
279
    },
280
    loadCurrentPageData: function (callback, async, type) {
U
unknown 已提交
281 282
        //是否需要在翻页的时候清空之前的items ?

U
unknown 已提交
283 284
        debugger;

285
        if (this.pageloading) return;
U
unknown 已提交
286 287
        this.pageloading = true;

U
unknown 已提交
288 289 290 291 292 293
        if( this.io ){
            this.items.each(function(item){
                this.io.unobserve(item.node);
            }.bind(this))
        }

U
unknown 已提交
294 295 296
        this.items = [];

        var p = this.currentPage;
U
unknown 已提交
297
        var d = {
298 299
            "filterList": this.filterList,
            "parameter": this.parameter
U
unknown 已提交
300
        };
U
unknown 已提交
301

302
        while (this.viewTable.rows.length > 1) {
U
unknown 已提交
303 304
            this.viewTable.deleteRow(-1);
        }
U
unknown 已提交
305 306 307 308 309 310
        if( this.viewTable.rows.length>0 && !this.viewTable.rows[0].hasClass("viewTitleLine") ){
            this.viewTable.deleteRow(0);
        }

        this.contentAreaNode.scrollTo(0, 0);

U
unknown 已提交
311 312
        //this.createLoadding();

U
unknown 已提交
313
        this.loadViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
U
unknown 已提交
314
            this.options.statementId || this.options.statementName || this.json.statementId || this.json.statementName,
315
            type || "data", p, this.json.pageSize, d, function (json) {
U
unknown 已提交
316

317 318
                if (type === "all" || type === "count") {
                    if (typeOf(json.count) === "number") {
U
unknown 已提交
319
                        this.count = json.count;
320 321
                        var i = this.count / this.json.pageSize;
                        this.pages = (i.toInt() < i) ? i.toInt() + 1 : i;
U
unknown 已提交
322 323 324 325
                    }
                }

                this.gridJson = json.data;
U
unknown 已提交
326
                this.setSelectedableFlag();
U
unknown 已提交
327

U
unknown 已提交
328
                this.fireEvent("postLoadPageData");
U
unknown 已提交
329

U
unknown 已提交
330 331 332 333
                // if (this.viewJson.group.column){
                //     this.gridJson = json.data.groupGrid;
                // }else{
                //     this.gridJson = json.data.grid;
U
unknown 已提交
334
                this.loadData();
U
unknown 已提交
335 336
                // }
                if (this.gridJson.length) this._loadPageNode();
337
                if (this.loadingAreaNode) {
U
unknown 已提交
338 339 340
                    this.loadingAreaNode.destroy();
                    this.loadingAreaNode = null;
                }
U
unknown 已提交
341

U
unknown 已提交
342
                this.pageloading = false;
U
unknown 已提交
343

U
unknown 已提交
344 345
                this.fireEvent("loadView"); //options 传入的事件
                this.fireEvent("postLoadPage");
U
unknown 已提交
346

347 348
                if (callback) callback(json);
            }.bind(this), null, async === false ? false : true);
U
unknown 已提交
349
    },
350 351
    getView: function (callback) {
        this.getViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.get(this.json.statementId || this.json.statementName, function (json) {
U
unknown 已提交
352
            debugger;
U
unknown 已提交
353
            var viewData = JSON.decode(json.data.view);
354
            if (!this.json.pageSize) this.json.pageSize = viewData.pageSize || "20";
U
unknown 已提交
355
            this.viewJson = viewData.data;
U
unknown 已提交
356 357 358
            this.json.application = json.data.query;
            //this.json = Object.merge(this.json, json.data);
            this.statementJson = json.data;
U
unknown 已提交
359
            this.statementJson.viewJson = this.viewJson;
U
unknown 已提交
360 361 362
            if (callback) callback();
        }.bind(this));
    },
U
unknown 已提交
363

364 365 366
    loadData: function () {
        if (this.getSelectFlag() === "multi" && this.viewJson.allowSelectAll) {
            if (this.selectTitleCell && this.selectTitleCell.retrieve("selectAllLoaded")) {
U
unknown 已提交
367
                this.setUnSelectAllStyle();
368
            } else {
U
unknown 已提交
369 370
                this.createSelectAllNode();
            }
371
        } else if (this.selectAllNode) {
U
unknown 已提交
372 373 374
            this.clearSelectAllStyle();
        }

375
        if (this.gridJson.length) {
U
unknown 已提交
376
            // if( !this.options.paging ){
377
            this.gridJson.each(function (line, i) {
U
unknown 已提交
378
                this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, line, null, i, null, this.options.lazy));
U
unknown 已提交
379 380 381 382
            }.bind(this));
            // }else{
            //     this.loadPaging();
            // }
383
        } else {
U
unknown 已提交
384 385 386
            if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
        }
    },
387 388 389 390 391
    loadDataByPaging: function () {
        if (this.isItemsLoading) return;
        if (!this.isItemsLoaded) {
            var from = Math.min(this.pageNumber * this.options.perPageCount, this.gridJson.length);
            var to = Math.min((this.pageNumber + 1) * this.options.perPageCount + 1, this.gridJson.length);
U
unknown 已提交
392
            this.isItemsLoading = true;
393
            for (var i = from; i < to; i++) {
U
unknown 已提交
394
                this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, this.gridJson[i], null, i, null, this.options.lazy));
U
unknown 已提交
395 396
            }
            this.isItemsLoading = false;
397 398
            this.pageNumber++;
            if (to == this.gridJson.length) this.isItemsLoaded = true;
U
unknown 已提交
399 400
        }
    },
401
    getFilter: function () {
U
unknown 已提交
402
        var filterData = [];
403 404 405
        if (this.searchStatus === "custom") {
            if (this.filterItems.length) {
                this.filterItems.each(function (filter) {
406
                    if( !filter.data.logic )filter.data.logic = "and";
U
unknown 已提交
407 408 409 410
                    filterData.push(filter.data);
                }.bind(this));
            }
        }
411
        if (this.searchStatus === "default") {
U
unknown 已提交
412
            var key = this.viewSearchInputNode.get("value");
413 414 415
            if (key && key !== this.lp.searchKeywork) {
                this.viewJson.customFilterList.each(function (entry) {
                    if (entry.formatType === "textValue") {
U
unknown 已提交
416 417 418 419
                        var d = {
                            "path": entry.path,
                            "value": key,
                            "formatType": entry.formatType,
U
unknown 已提交
420
                            "logic": "or",
U
unknown 已提交
421 422 423 424
                            "comparison": "like"
                        };
                        filterData.push(d);
                    }
425
                    if (entry.formatType === "numberValue") {
U
unknown 已提交
426
                        var v = key.toFloat();
427
                        if (!isNaN(v)) {
U
unknown 已提交
428 429 430 431
                            var d = {
                                "path": entry.path,
                                "value": v,
                                "formatType": entry.formatType,
U
unknown 已提交
432
                                "logic": "or",
U
unknown 已提交
433 434 435 436 437 438 439 440 441 442
                                "comparison": "like"
                            };
                            filterData.push(d);
                        }
                    }
                }.bind(this));
            }
        }
        return (filterData.length) ? filterData : null;
    },
443
    viewSearchCustomAddToFilter: function () {
U
unknown 已提交
444 445
        var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
        var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
446 447 448 449 450
        if (pathIdx === -1) {
            MWF.xDesktop.notice("error", {
                "x": "left",
                "y": "top"
            }, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
U
unknown 已提交
451 452
            return false;
        }
453 454 455 456 457
        if (comparisonIdx === -1) {
            MWF.xDesktop.notice("error", {
                "x": "left",
                "y": "top"
            }, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
U
unknown 已提交
458 459 460 461
            return false;
        }
        var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
        var entry = pathOption.retrieve("entry");
462
        if (entry) {
U
unknown 已提交
463 464 465 466 467 468
            var pathTitle = entry.title;
            var path = entry.path;
            var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
            var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
            var value = "";

469
            if (entry.valueType === "script" && entry.valueScript && entry.valueScript.code) {
U
unknown 已提交
470
                var idx = this.viewSearchCustomValueNode.selectedIndex;
471
                if (idx !== -1) {
U
unknown 已提交
472
                    var v = this.viewSearchCustomValueNode.options[idx].get("value");
473
                    value = entry.formatType === "booleanValue" ? (v === "true") : v;
U
unknown 已提交
474
                }
475 476
            } else {
                switch (entry.formatType) {
U
unknown 已提交
477 478 479 480 481 482 483 484
                    case "numberValue":
                        value = this.viewSearchCustomValueNode.get("value");
                        break;
                    case "dateTimeValue":
                        value = this.viewSearchCustomValueNode.get("value");
                        break;
                    case "booleanValue":
                        var idx = this.viewSearchCustomValueNode.selectedIndex;
485
                        if (idx !== -1) {
U
unknown 已提交
486
                            var v = this.viewSearchCustomValueNode.options[idx].get("value");
487
                            value = (v === "true");
U
unknown 已提交
488 489 490 491 492 493 494
                        }
                        break;
                    default:
                        value = this.viewSearchCustomValueNode.get("value");
                }
            }

495 496 497 498 499
            if (value === "") {
                MWF.xDesktop.notice("error", {
                    "x": "left",
                    "y": "top"
                }, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
U
unknown 已提交
500 501 502 503 504 505 506 507 508 509
                return false;
            }

            this.filterItems.push(new MWF.xApplication.query.Query.Statement.Filter(this, {
                "logic": "and",
                "path": path,
                "title": pathTitle,
                "comparison": comparison,
                "comparisonTitle": comparisonTitle,
                "value": value,
510
                "formatType": (entry.formatType == "datetimeValue") ? "dateTimeValue" : entry.formatType
U
unknown 已提交
511 512 513 514
            }, this.viewSearchCustomFilterContentNode));

            this.searchCustomView();
        }
U
unknown 已提交
515
    },
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
    searchView: function(){
        debugger;
        if (this.viewJson.customFilterList) {
            var key = this.viewSearchInputNode.get("value");
            if (key && key !== this.lp.searchKeywork) {
                var filterData = [];
                this.filterItems = [];
                this.viewJson.customFilterList.each(function (entry) {
                    if (entry.formatType === "textValue") {
                        var d = {
                            "path": entry.path,
                            "value": key,
                            "formatType": entry.formatType,
                            "logic": "or",
                            "comparison": "like"
                        };
                        filterData.push(d);
                        this.filterItems.push({"data":d});
                    }
                    if (entry.formatType === "numberValue") {
                        var v = key.toFloat();
                        if (!isNaN(v)) {
                            var d = {
                                "path": entry.path,
                                "value": v,
                                "formatType": entry.formatType,
                                "logic": "or",
                                "comparison": "equals"
                            };
                            filterData.push(d);
                            this.filterItems.push({"data":d});
                        }
                    }
                }.bind(this));

                if( this.json.filter ){
                    this.json.filter.clone().each(function(f){
                        filterData.push(f);
                    })
                }

                this.createViewNode({"filterList": filterData});
            }else{
                this.filterItems = [];
                var filterData = this.json.filter ? this.json.filter.clone() : [];
                this.createViewNode( {"filterList": filterData} );
            }
        }
    },
U
unknown 已提交
565
    //搜索相关结束
566
    getStatementInfor: function () {
U
unknown 已提交
567 568 569
        debugger;
        return this.statementJson;
    },
570
    getPageInfor: function () {
U
unknown 已提交
571
        return {
572 573 574
            pages: this.pages,
            perPageCount: this.json.pageSize,
            currentPageNumber: this.currentPage
U
unknown 已提交
575
        };
U
unknown 已提交
576
    },
577
    switchStatement: function (json) {
U
unknown 已提交
578
        this.switchView(json);
U
unknown 已提交
579
    },
580 581 582 583
    setFilter: function (filter, parameter, callback) {
        if (this.lookuping || this.pageloading) return;
        if (!filter) filter = [];
        if (!parameter) parameter = {};
U
unknown 已提交
584 585
        this.json.filter = filter;
        this.json.parameter = parameter;
586 587
        if (this.viewAreaNode) {
            this.createViewNode({"filterList": this.json.filter.clone()}, callback);
U
unknown 已提交
588
        }
U
unknown 已提交
589 590 591 592 593 594 595 596 597 598 599 600 601
    },


    // getExportTotalCount: function(){
    //     return this.count || 0;
    // },
    // getExportMaxCount: function(){
    //     return 2000;
    // },
    exportView: function(){

        // var excelName = this.statementJson.name + "(" + start + "-" + end + ").xlsx";

602
        var excelName = this.statementJson.name;
U
unknown 已提交
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618

        var p = this.currentPage;
        var d = {
            "filterList": this.filterList,
            "parameter": this.parameter
        };

        this.createLoadding();

        debugger;

        var exportArray = [];

        var titleArray = [];
        var colWidthArr = [];
        var dateIndexArray = [];
619
        var numberIndexArray = [];
U
unknown 已提交
620 621
        var idx = 0;
        Object.each(this.entries, function (c, k) {
U
unknown 已提交
622
            if (this.hideColumns.indexOf(k) === -1 && c.exportEnable !== false) {
U
unknown 已提交
623 624 625
                titleArray.push(c.displayName);
                colWidthArr.push(c.exportWidth || 200);
                if( c.isTime )dateIndexArray.push(idx);
626
                if( c.isNumber )numberIndexArray.push(idx);
U
unknown 已提交
627 628 629 630 631 632 633 634 635 636 637 638
                idx++;
            }
        }.bind(this));
        exportArray.push(titleArray);

        o2.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
            this.options.statementId || this.options.statementName || this.json.statementId || this.json.statementName,
            "data", 1, 100000, d, function (json) {

                json.data.each(function (d, i) {
                    var dataArray = [];
                    Object.each(this.entries, function (c, k) {
U
unknown 已提交
639
                        if (this.hideColumns.indexOf(k) === -1 && c.exportEnable !== false) {
U
unknown 已提交
640
                            var text = this.getExportText(c, k, d);
641 642 643
                            // if( c.isNumber && typeOf(text) === "string" && (parseFloat(text).toString() !== "NaN") ){
                            //     text = parseFloat(text);
                            // }
U
unknown 已提交
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
                            dataArray.push( text );
                        }
                    }.bind(this));
                    //exportRow事件
                    var argu = {"index":i, "source": d, "data":dataArray};
                    this.fireEvent("exportRow", [argu]);
                    exportArray.push( argu.data || dataArray );
                }.bind(this));

                //export事件
                var arg = {
                    data : exportArray,
                    colWidthArray : colWidthArr,
                    title : excelName
                };
                this.fireEvent("export", [arg]);

                if (this.loadingAreaNode) {
                    this.loadingAreaNode.destroy();
                    this.loadingAreaNode = null;
                }

                new MWF.xApplication.query.Query.Statement.ExcelUtils().exportToExcel(
                    arg.data || exportArray,
                    arg.title || excelName,
                    arg.colWidthArray || colWidthArr,
670 671
                    dateIndexArray,  //日期格式列下标
                    numberIndexArray  //数字格式列下标
U
unknown 已提交
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 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
                );

            }.bind(this));
    },
    getDataByPath: function (obj, 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;
            }
        }
        return obj
    },
    getExportText: function (c, k, data) {
        var path = c.path, code = c.code, obj = data;
        if (!path) {
            return ""
        } else if (path === "$all") {
        } else {
            obj = this.getDataByPath(obj, path);
        }

        try{
            if (code && code.trim()) obj = this.view.Macro.exec(code, {
                "value": obj,
                "data": data,
                "entry": c,
                "json": c
            });
        }catch (e) {}

        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;
            }
        }
        return d;
U
unknown 已提交
734
    }
U
unknown 已提交
735 736 737
});

MWF.xApplication.query.Query.Statement.Item = new Class({
738
    Extends: MWF.xApplication.query.Query.Viewer.Item,
U
unknown 已提交
739
    initialize: function (view, data, prev, i, category, lazy) {
U
unknown 已提交
740 741
        this.view = view;
        this.data = data;
742
        this.dataString = JSON.stringify(data);
U
unknown 已提交
743 744
        this.css = this.view.css;
        this.isSelected = false;
U
unknown 已提交
745
        this.category = category;
U
unknown 已提交
746 747 748
        this.prev = prev;
        this.idx = i;
        this.clazzType = "item";
U
unknown 已提交
749
        this.lazy = lazy;
U
unknown 已提交
750 751
        this.load();
    },
U
unknown 已提交
752 753 754 755
    _load: function () {
        this.loading = true;

        if(!this.node)this.view.fireEvent("queryLoadItemRow", [null, this]);
U
unknown 已提交
756 757

        var viewStyles = this.view.viewJson.viewStyles;
758
        var viewContentTdNode = (viewStyles && viewStyles["contentTd"]) ? viewStyles["contentTd"] : this.css.viewContentTdNode;
U
unknown 已提交
759

U
unknown 已提交
760
        if(!this.node)this.loadNode();
U
unknown 已提交
761 762

        //if (this.view.json.select==="single" || this.view.json.select==="multi"){
763
        this.selectTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
U
unknown 已提交
764 765
        this.selectTd.setStyles({"cursor": "pointer"});
        if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
U
unknown 已提交
766 767 768

        //var selectFlag = this.view.json.select || this.view.viewJson.select ||  "none";
        var selectFlag = this.view.getSelectFlag();
769
        if (this.data.$selectedEnable && ["multi", "single"].contains(selectFlag) && this.view.viewJson.selectBoxShow === "always") {
U
unknown 已提交
770 771 772 773 774 775 776 777 778 779 780 781 782 783
            var viewStyles = this.view.viewJson.viewStyles;
            if (viewStyles) {
                if (selectFlag === "single") {
                    this.selectTd.setStyles(viewStyles["radioNode"]);
                } else {
                    this.selectTd.setStyles(viewStyles["checkboxNode"]);
                }
            } else {
                var iconName = "checkbox";
                if (selectFlag === "single") iconName = "radiobox";
                this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/" + iconName + ".png) center center no-repeat"});
            }
        }

784
        if (this.view.isSelectTdHidden()) {
U
unknown 已提交
785 786 787 788 789
            this.selectTd.hide();
        }
        //}

        //序号
790 791
        var sequence = 1 + this.view.json.pageSize * (this.view.currentPage - 1) + this.idx;
        this.data["$sequence"] = sequence;
792
        if (this.view.viewJson.isSequence === "yes") {
U
unknown 已提交
793 794
            this.sequenceTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
            this.sequenceTd.setStyle("width", "10px");
795
            this.sequenceTd.set("text", sequence);
U
unknown 已提交
796 797
        }

798
        Object.each(this.view.entries, function (c, k) {
U
unknown 已提交
799
            //if (cell){
800
            if (this.view.hideColumns.indexOf(k) === -1) {
U
unknown 已提交
801
                var td = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
U
unknown 已提交
802

803
                var cell = this.getText(c, k, td); //this.data[k];
U
unknown 已提交
804 805 806 807
                if (cell === undefined || cell === null) cell = "";

                // if (k!== this.view.viewJson.group.column){
                var v = cell;
808
                if (c.isHtml) {
U
unknown 已提交
809
                    td.set("html", v);
810
                } else {
U
unknown 已提交
811
                    td.set("text", v);
U
unknown 已提交
812 813
                }

814
                if (typeOf(c.contentProperties) === "object") td.setProperties(c.contentProperties);
U
unknown 已提交
815
                if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
816
                if (typeOf(c.contentStyles) === "object") td.setStyles(c.contentStyles);
U
unknown 已提交
817 818 819 820
                // }else{
                //     if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
                // }

821
                if (this.view.openColumns.indexOf(k) !== -1) {
U
unknown 已提交
822 823 824
                    this.setOpenWork(td, c)
                }

U
unknown 已提交
825
                // if (k!== this.view.viewJson.group.column){
826 827 828 829 830 831 832
                Object.each(c.events || {}, function (e, key) {
                    if (e.code) {
                        if (key === "loadContent") {
                            this.view.Macro.fire(e.code,
                                {"node": td, "json": c, "data": v, "view": this.view, "row": this});
                        } else if (key !== "loadTitle") {
                            td.addEvent(key, function (event) {
U
unknown 已提交
833 834
                                return this.view.Macro.fire(
                                    e.code,
835
                                    {"node": td, "json": c, "data": v, "view": this.view, "row": this},
U
unknown 已提交
836 837 838
                                    event
                                );
                            }.bind(this));
U
unknown 已提交
839
                        }
U
unknown 已提交
840 841 842
                    }
                }.bind(this));
                // }
U
unknown 已提交
843 844 845 846
            }
            //}
        }.bind(this));

U
unknown 已提交
847 848 849 850 851
        if(this.placeholderTd){
            this.placeholderTd.destroy();
            this.placeholderTd = null;
        }

U
unknown 已提交
852
        //默认选中
853 854
        var selectedFlag;

U
unknown 已提交
855
        var defaultSelectedScript = this.view.json.defaultSelectedScript || this.view.viewJson.defaultSelectedScript;
856
        if (!this.isSelected && defaultSelectedScript) {
U
unknown 已提交
857 858 859 860
            // var flag = this.view.json.select || this.view.viewJson.select ||  "none";
            // if ( flag ==="single" || flag==="multi"){
            //
            // }
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881
            selectedFlag = this.view.Macro.exec(defaultSelectedScript,
                {"node": this.node, "data": this.data, "view": this.view, "row": this});
        }

        //判断是不是在selectedItems中,用户手工选择
        if (!this.isSelected && this.view.selectedItems.length) {
            for (var i = 0; i < this.view.selectedItems.length; i++) {
                if (this.view.selectedItems[i].dataString === this.dataString) {
                    selectedFlag = "true";
                    break;
                }
            }
        }

        if (selectedFlag) {
            if (selectedFlag === "multi" || selectedFlag === "single") {
                this.select(selectedFlag);
            } else if (selectedFlag.toString() === "true") {
                var f = this.view.json.select || this.view.viewJson.select || "none";
                if (f === "single" || f === "multi") {
                    this.select();
U
unknown 已提交
882 883 884 885 886 887 888
                }
            }
        }

        this.setEvent();

        this.view.fireEvent("postLoadItemRow", [null, this]);
U
unknown 已提交
889 890 891

        this.loading = false;
        this.loaded = true;
U
unknown 已提交
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
    selected: function( from ){
        for(var i=0; i<this.view.selectedItems.length; i++){
            var item = this.view.selectedItems[i];
            if( item.dataString === this.dataString ){
                this.view.selectedItems.erase(item);
                break;
            }
        }
        this.view.selectedItems.push(this);
        var viewStyles = this.view.viewJson.viewStyles;
        if( viewStyles ){
            this.selectTd.setStyles( viewStyles["checkedCheckboxNode"] );
            this.node.setStyles( viewStyles["contentSelectedTr"] );
        }else{
            this.selectTd.setStyles({"background": "url("+"../x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
            this.node.setStyles(this.css.viewContentTrNode_selected);
        }
        this.isSelected = true;
        if( from !== "view" && from !=="category" && this.view.viewJson.allowSelectAll ){
            this.view.checkSelectAllStatus();
            if( this.category )this.category.checkSelectAllStatus();
        }
        this.view.fireEvent("selectRow", [this]);
    },
    unSelected: function( from ){
        for(var i=0; i<this.view.selectedItems.length; i++){
            var item = this.view.selectedItems[i];
            if( item.dataString === this.dataString ){
                this.view.selectedItems.erase(item);
                break;
            }
        }
        var viewStyles = this.view.viewJson.viewStyles;
        if( this.view.viewJson.selectBoxShow !=="always" ){
            this.selectTd.setStyles({"background": "transparent"});
        }else{
            if (viewStyles) {
                this.selectTd.setStyles(viewStyles["checkboxNode"]);
            }else{
                this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/checkbox.png) center center no-repeat"});
            }
        }
        if( viewStyles ){
            this.node.setStyles( viewStyles["contentTr"] );
        }else{
            this.node.setStyles(this.css.viewContentTrNode);
        }
        this.isSelected = false;
        if( from !== "view" && from !=="category" && this.view.viewJson.allowSelectAll ){
            this.view.checkSelectAllStatus();
            if( this.category )this.category.checkSelectAllStatus();
        }
        this.view.fireEvent("unselectRow", [this]);
    },
    getDataByPath: function (obj, path) {
U
unknown 已提交
948 949 950 951 952 953
        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];
954
            } else if(obj[p] === undefined || obj[p] === null) {
U
unknown 已提交
955 956
                obj = "";
                break;
957 958 959
            } else {
                obj = obj[p];
                break;
U
unknown 已提交
960 961 962 963
            }
        }
        return obj
    },
964
    getText: function (c, k, td) {
U
unknown 已提交
965
        var path = c.path, code = c.code, obj = this.data;
966
        if (!path) {
967 968 969
           var co = code && code.trim();
           if( !co )return "";
           obj = "";
970 971
        } else if (path === "$all") {
        } else {
U
unknown 已提交
972
            obj = this.getDataByPath(obj, path);
U
unknown 已提交
973 974
        }

975 976 977 978 979 980 981 982
        if (code && code.trim()) obj = this.view.Macro.exec(code, {
            "value": obj,
            "data": this.data,
            "entry": c,
            "node": td,
            "json": c,
            "row": this
        });
U
unknown 已提交
983 984

        var toName = function (value) {
985 986
            if (typeOf(value) === "array") {
                Array.each(value, function (v, idx) {
U
unknown 已提交
987 988
                    value[idx] = toName(v)
                })
989 990
            } else if (typeOf(value) === "object") {
                Object.each(value, function (v, key) {
U
unknown 已提交
991 992
                    value[key] = toName(v);
                })
993 994
            } else if (typeOf(value) === "string") {
                value = o2.name.cn(value)
U
unknown 已提交
995 996 997 998 999
            }
            return value;
        };

        var d;
1000 1001
        if (obj != undefined && obj != null) {
            if (typeOf(obj) === "array") {
U
unknown 已提交
1002
                d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
1003
            } else if (typeOf(obj) === "object") {
U
unknown 已提交
1004
                d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
1005 1006
            } else {
                d = c.isName ? o2.name.cn(obj.toString()) : obj;
U
unknown 已提交
1007 1008 1009 1010 1011
            }
        }

        return d;
    },
1012
    setOpenWork: function (td, column) {
U
unknown 已提交
1013
        td.setStyle("cursor", "pointer");
1014 1015
        if (column.clickCode) {
            if (!this.view.Macro) {
U
unknown 已提交
1016 1017
                MWF.require("MWF.xScript.Macro", function () {
                    this.view.businessData = {};
1018
                    this.view.Macro = new MWF.Macro.ViewContext(this.view);
U
unknown 已提交
1019 1020
                }.bind(this), false);
            }
1021
            td.addEvent("click", function (ev) {
U
unknown 已提交
1022 1023 1024 1025
                var result = this.view.Macro.fire(column.clickCode, this, ev);
                ev.stopPropagation();
                return result;
            }.bind(this));
1026 1027 1028 1029 1030
        } else if (this.view.statementJson.entityCategory === "official" && column.idPath) {
            var id = this.getDataByPath(this.data, column.idPath);
            if (id) {
                if (this.view.statementJson.entityClassName === "com.x.cms.core.entity.Document") {
                    td.addEvent("click", function (ev) {
U
unknown 已提交
1031 1032 1033
                        this.openCms(ev, id);
                        ev.stopPropagation();
                    }.bind(this));
1034 1035
                } else {
                    td.addEvent("click", function (ev) {
U
unknown 已提交
1036 1037 1038 1039 1040
                        this.openWork(ev, id);
                        ev.stopPropagation();
                    }.bind(this));
                }
            }
U
unknown 已提交
1041
        }
U
unknown 已提交
1042
    },
1043
    openCms: function (e, id) {
U
unknown 已提交
1044 1045 1046 1047
        var options = {"documentId": id};
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
        layout.desktop.openApplication(e, "cms.Document", options);
    },
1048
    openWork: function (e, id) {
U
unknown 已提交
1049 1050 1051
        var options = {"workId": id};
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
        layout.desktop.openApplication(e, "process.Work", options);
U
unknown 已提交
1052 1053 1054 1055
    }
});

MWF.xApplication.query.Query.Statement.Filter = new Class({
1056
    Extends: MWF.xApplication.query.Query.Viewer.Filter
U
unknown 已提交
1057 1058 1059
});

MWF.xApplication.query.Query.Statement.Actionbar = new Class({
1060
    Extends: MWF.xApplication.query.Query.Viewer.Actionbar
U
unknown 已提交
1061 1062 1063
});

MWF.xApplication.query.Query.Statement.Paging = new Class({
1064
    Extends: MWF.xApplication.query.Query.Viewer.Paging
U
unknown 已提交
1065 1066
});

U
unknown 已提交
1067
MWF.xDesktop.requireApp("Template", "utils.ExcelUtils", null, false);
U
unknown 已提交
1068
MWF.xApplication.query.Query.Statement.ExcelUtils = new Class({
U
unknown 已提交
1069
    Extends: MWF.xApplication.Template.utils.ExcelUtils
U
unknown 已提交
1070
});