Statement.js 32.7 KB
Newer Older
U
unknown 已提交
1 2 3 4 5
MWF.xApplication.query = MWF.xApplication.query || {};
MWF.xApplication.query.Query = MWF.xApplication.query.Query || {};
MWF.xDesktop.requireApp("query.Query", "Viewer", null, false);
MWF.xApplication.query.Query.Statement = MWF.QStatement = new Class({
    Extends: MWF.QViewer,
6 7
    options: {},
    initialize: function (container, json, options, app, parentMacro) {
U
unknown 已提交
8 9 10 11 12 13 14 15
        //本类有三种事件,
        //一种是通过 options 传进来的事件,包括 loadView、openDocument、select
        //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
        //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件

        this.setOptions(options);

        this.path = "../x_component_query_Query/$Viewer/";
16
        this.cssPath = "../x_component_query_Query/$Viewer/" + this.options.style + "/css.wcss";
U
unknown 已提交
17 18 19 20 21 22
        this._loadCss();
        this.lp = MWF.xApplication.query.Query.LP;

        this.app = app;

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

        debugger;
U
unknown 已提交
25
        this.json = json || {};
U
unknown 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39

        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 已提交
40
        this.parameter = {};
U
unknown 已提交
41 42 43

        this.gridJson = null;

44 45
        if (this.options.isload) {
            this.init(function () {
U
unknown 已提交
46 47 48 49 50
                this.load();
            }.bind(this));
        }

    },
51 52
    init: function (callback) {
        if (this.json.view) {
U
unknown 已提交
53
            this.viewJson = JSON.decode(this.json.view);
U
unknown 已提交
54
            this.statementJson = this.json;
U
unknown 已提交
55
            this.statementJson.viewJson = this.viewJson;
U
unknown 已提交
56
            if (callback) callback();
57
        } else {
U
unknown 已提交
58 59 60 61 62 63 64 65 66
            this.getView(callback);
        }
    },
    loadMacro: function (callback) {
        MWF.require("MWF.xScript.Macro", function () {
            this.Macro = new MWF.Macro.ViewContext(this);
            if (callback) callback();
        }.bind(this));
    },
67
    createActionbarNode: function () {
U
unknown 已提交
68
        this.actionbarAreaNode.empty();
69 70 71
        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 已提交
72 73 74 75
            this.actionbar = new MWF.xApplication.query.Query.Statement.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
            this.actionbar.load();
        }
    },
76
    _loadPageNode: function () {
U
unknown 已提交
77
        this.viewPageAreaNode.empty();
78
        if (!this.paging) {
U
unknown 已提交
79
            var json;
80
            if (!this.viewJson.pagingList || !this.viewJson.pagingList.length) {
U
unknown 已提交
81 82 83 84
                json = {
                    "firstPageText": this.lp.firstPage,
                    "lastPageText": this.lp.lastPage
                };
85
            } else {
U
unknown 已提交
86 87 88 89
                json = this.viewJson.pagingList[0];
            }
            this.paging = new MWF.xApplication.query.Query.Statement.Paging(this.viewPageAreaNode, json, this, {});
            this.paging.load();
90
        } else {
U
unknown 已提交
91 92 93
            this.paging.reload();
        }
    },
U
unknown 已提交
94 95 96 97 98 99
    // _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;
    // },
100 101
    lookup: function (data, callback) {
        if (this.lookuping) return;
U
unknown 已提交
102
        this.lookuping = true;
U
unknown 已提交
103 104
        // this.getLookupAction(function(){
        //     if (this.json.application){
U
unknown 已提交
105

U
unknown 已提交
106 107 108 109
        var d = data || {};
        // d.count = this.json.count;
        // this.lookupAction.bundleView(this.json.id, d, function(json){
        //     this.bundleItems = json.data.valueList;
U
unknown 已提交
110

U
unknown 已提交
111
        // this._initPage();
U
unknown 已提交
112

U
unknown 已提交
113
        debugger;
114 115
        this.loadParameter(d);
        this.loadFilter(d);
U
unknown 已提交
116 117 118 119

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

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


148
        }.bind(this), true, "all");
U
unknown 已提交
149 150

        // }.bind(this));
U
unknown 已提交
151 152 153
        // }
        // }.bind(this));
    },
154
    loadFilter: function (data) {
U
unknown 已提交
155
        debugger;
U
unknown 已提交
156
        this.filterList = [];
157
        (data.filterList || []).each(function (d) {
U
unknown 已提交
158
            var parameterName = d.path.replace(/\./g, "_");
U
unknown 已提交
159
            var value = d.value;
U
unknown 已提交
160 161 162
            // if( d.code && d.code.code ){
            //     value = this.Macro.exec( d.code.code, this);
            // }
163 164 165 166 167 168 169 170 171 172 173
            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 已提交
174
                }
175
                this.parameter[parameterName] = value;
U
unknown 已提交
176 177 178
            }
            d.value = parameterName;

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

U
unknown 已提交
267 268
        debugger;

269
        if (this.pageloading) return;
U
unknown 已提交
270 271 272 273 274
        this.pageloading = true;

        this.items = [];

        var p = this.currentPage;
U
unknown 已提交
275
        var d = {
276 277
            "filterList": this.filterList,
            "parameter": this.parameter
U
unknown 已提交
278
        };
U
unknown 已提交
279

280
        while (this.viewTable.rows.length > 1) {
U
unknown 已提交
281 282 283 284
            this.viewTable.deleteRow(-1);
        }
        //this.createLoadding();

U
unknown 已提交
285
        this.loadViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
U
unknown 已提交
286
            this.options.statementId || this.options.statementName || this.json.statementId || this.json.statementName,
287
            type || "data", p, this.json.pageSize, d, function (json) {
U
unknown 已提交
288

289 290
                if (type === "all" || type === "count") {
                    if (typeOf(json.count) === "number") {
U
unknown 已提交
291
                        this.count = json.count;
292 293
                        var i = this.count / this.json.pageSize;
                        this.pages = (i.toInt() < i) ? i.toInt() + 1 : i;
U
unknown 已提交
294 295 296 297
                    }
                }

                this.gridJson = json.data;
U
unknown 已提交
298
                this.setSelectedableFlag();
U
unknown 已提交
299

U
unknown 已提交
300
                this.fireEvent("postLoadPageData");
U
unknown 已提交
301

U
unknown 已提交
302 303 304 305
                // if (this.viewJson.group.column){
                //     this.gridJson = json.data.groupGrid;
                // }else{
                //     this.gridJson = json.data.grid;
U
unknown 已提交
306
                this.loadData();
U
unknown 已提交
307 308
                // }
                if (this.gridJson.length) this._loadPageNode();
309
                if (this.loadingAreaNode) {
U
unknown 已提交
310 311 312
                    this.loadingAreaNode.destroy();
                    this.loadingAreaNode = null;
                }
U
unknown 已提交
313

U
unknown 已提交
314
                this.pageloading = false;
U
unknown 已提交
315

U
unknown 已提交
316 317
                this.fireEvent("loadView"); //options 传入的事件
                this.fireEvent("postLoadPage");
U
unknown 已提交
318

319 320
                if (callback) callback(json);
            }.bind(this), null, async === false ? false : true);
U
unknown 已提交
321
    },
322 323
    getView: function (callback) {
        this.getViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.get(this.json.statementId || this.json.statementName, function (json) {
U
unknown 已提交
324
            debugger;
U
unknown 已提交
325
            var viewData = JSON.decode(json.data.view);
326
            if (!this.json.pageSize) this.json.pageSize = viewData.pageSize || "20";
U
unknown 已提交
327
            this.viewJson = viewData.data;
U
unknown 已提交
328 329 330
            this.json.application = json.data.query;
            //this.json = Object.merge(this.json, json.data);
            this.statementJson = json.data;
U
unknown 已提交
331
            this.statementJson.viewJson = this.viewJson;
U
unknown 已提交
332 333 334
            if (callback) callback();
        }.bind(this));
    },
U
unknown 已提交
335

336 337 338
    loadData: function () {
        if (this.getSelectFlag() === "multi" && this.viewJson.allowSelectAll) {
            if (this.selectTitleCell && this.selectTitleCell.retrieve("selectAllLoaded")) {
U
unknown 已提交
339
                this.setUnSelectAllStyle();
340
            } else {
U
unknown 已提交
341 342
                this.createSelectAllNode();
            }
343
        } else if (this.selectAllNode) {
U
unknown 已提交
344 345 346
            this.clearSelectAllStyle();
        }

347
        if (this.gridJson.length) {
U
unknown 已提交
348
            // if( !this.options.paging ){
349
            this.gridJson.each(function (line, i) {
U
unknown 已提交
350 351 352 353 354
                this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, line, null, i));
            }.bind(this));
            // }else{
            //     this.loadPaging();
            // }
355
        } else {
U
unknown 已提交
356 357 358
            if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
        }
    },
359 360 361 362 363
    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 已提交
364
            this.isItemsLoading = true;
365
            for (var i = from; i < to; i++) {
U
unknown 已提交
366 367 368
                this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, this.gridJson[i], null, i));
            }
            this.isItemsLoading = false;
369 370
            this.pageNumber++;
            if (to == this.gridJson.length) this.isItemsLoaded = true;
U
unknown 已提交
371 372
        }
    },
373
    getFilter: function () {
U
unknown 已提交
374
        var filterData = [];
375 376 377
        if (this.searchStatus === "custom") {
            if (this.filterItems.length) {
                this.filterItems.each(function (filter) {
U
unknown 已提交
378 379 380 381
                    filterData.push(filter.data);
                }.bind(this));
            }
        }
382
        if (this.searchStatus === "default") {
U
unknown 已提交
383
            var key = this.viewSearchInputNode.get("value");
384 385 386
            if (key && key !== this.lp.searchKeywork) {
                this.viewJson.customFilterList.each(function (entry) {
                    if (entry.formatType === "textValue") {
U
unknown 已提交
387 388 389 390
                        var d = {
                            "path": entry.path,
                            "value": key,
                            "formatType": entry.formatType,
U
unknown 已提交
391
                            "logic": "or",
U
unknown 已提交
392 393 394 395
                            "comparison": "like"
                        };
                        filterData.push(d);
                    }
396
                    if (entry.formatType === "numberValue") {
U
unknown 已提交
397
                        var v = key.toFloat();
398
                        if (!isNaN(v)) {
U
unknown 已提交
399 400 401 402
                            var d = {
                                "path": entry.path,
                                "value": v,
                                "formatType": entry.formatType,
U
unknown 已提交
403
                                "logic": "or",
U
unknown 已提交
404 405 406 407 408 409 410 411 412 413
                                "comparison": "like"
                            };
                            filterData.push(d);
                        }
                    }
                }.bind(this));
            }
        }
        return (filterData.length) ? filterData : null;
    },
414
    viewSearchCustomAddToFilter: function () {
U
unknown 已提交
415 416
        var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
        var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
417 418 419 420 421
        if (pathIdx === -1) {
            MWF.xDesktop.notice("error", {
                "x": "left",
                "y": "top"
            }, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
U
unknown 已提交
422 423
            return false;
        }
424 425 426 427 428
        if (comparisonIdx === -1) {
            MWF.xDesktop.notice("error", {
                "x": "left",
                "y": "top"
            }, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
U
unknown 已提交
429 430 431 432
            return false;
        }
        var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
        var entry = pathOption.retrieve("entry");
433
        if (entry) {
U
unknown 已提交
434 435 436 437 438 439
            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 = "";

440
            if (entry.valueType === "script" && entry.valueScript && entry.valueScript.code) {
U
unknown 已提交
441
                var idx = this.viewSearchCustomValueNode.selectedIndex;
442
                if (idx !== -1) {
U
unknown 已提交
443
                    var v = this.viewSearchCustomValueNode.options[idx].get("value");
444
                    value = entry.formatType === "booleanValue" ? (v === "true") : v;
U
unknown 已提交
445
                }
446 447
            } else {
                switch (entry.formatType) {
U
unknown 已提交
448 449 450 451 452 453 454 455
                    case "numberValue":
                        value = this.viewSearchCustomValueNode.get("value");
                        break;
                    case "dateTimeValue":
                        value = this.viewSearchCustomValueNode.get("value");
                        break;
                    case "booleanValue":
                        var idx = this.viewSearchCustomValueNode.selectedIndex;
456
                        if (idx !== -1) {
U
unknown 已提交
457
                            var v = this.viewSearchCustomValueNode.options[idx].get("value");
458
                            value = (v === "true");
U
unknown 已提交
459 460 461 462 463 464 465
                        }
                        break;
                    default:
                        value = this.viewSearchCustomValueNode.get("value");
                }
            }

466 467 468 469 470
            if (value === "") {
                MWF.xDesktop.notice("error", {
                    "x": "left",
                    "y": "top"
                }, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
U
unknown 已提交
471 472 473 474 475 476 477 478 479 480
                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,
481
                "formatType": (entry.formatType == "datetimeValue") ? "dateTimeValue" : entry.formatType
U
unknown 已提交
482 483 484 485
            }, this.viewSearchCustomFilterContentNode));

            this.searchCustomView();
        }
U
unknown 已提交
486
    },
U
unknown 已提交
487
    //搜索相关结束
488
    getStatementInfor: function () {
U
unknown 已提交
489 490 491
        debugger;
        return this.statementJson;
    },
492
    getPageInfor: function () {
U
unknown 已提交
493
        return {
494 495 496
            pages: this.pages,
            perPageCount: this.json.pageSize,
            currentPageNumber: this.currentPage
U
unknown 已提交
497
        };
U
unknown 已提交
498
    },
499
    switchStatement: function (json) {
U
unknown 已提交
500
        this.switchView(json);
U
unknown 已提交
501
    },
502 503 504 505
    setFilter: function (filter, parameter, callback) {
        if (this.lookuping || this.pageloading) return;
        if (!filter) filter = [];
        if (!parameter) parameter = {};
U
unknown 已提交
506 507
        this.json.filter = filter;
        this.json.parameter = parameter;
508 509
        if (this.viewAreaNode) {
            this.createViewNode({"filterList": this.json.filter.clone()}, callback);
U
unknown 已提交
510
        }
U
unknown 已提交
511
    }
U
unknown 已提交
512 513 514
});

MWF.xApplication.query.Query.Statement.Item = new Class({
515 516
    Extends: MWF.xApplication.query.Query.Viewer.Item,
    initialize: function (view, data, prev, i, category) {
U
unknown 已提交
517 518
        this.view = view;
        this.data = data;
519
        this.dataString = JSON.stringify(data);
U
unknown 已提交
520 521
        this.css = this.view.css;
        this.isSelected = false;
U
unknown 已提交
522
        this.category = category;
U
unknown 已提交
523 524 525 526 527 528
        this.prev = prev;
        this.idx = i;
        this.clazzType = "item";

        this.load();
    },
529
    load: function () {
U
unknown 已提交
530 531 532
        this.view.fireEvent("queryLoadItemRow", [null, this]);

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

        this.node = new Element("tr", {
536
            "styles": (viewStyles && viewStyles["contentTr"]) ? viewStyles["contentTr"] : this.css.viewContentTrNode
U
unknown 已提交
537
        });
538
        if (this.prev) {
U
unknown 已提交
539
            this.node.inject(this.prev.node, "after");
540
        } else {
U
unknown 已提交
541 542 543 544
            this.node.inject(this.view.viewTable);
        }

        //if (this.view.json.select==="single" || this.view.json.select==="multi"){
545
        this.selectTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
U
unknown 已提交
546 547
        this.selectTd.setStyles({"cursor": "pointer"});
        if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
U
unknown 已提交
548 549 550

        //var selectFlag = this.view.json.select || this.view.viewJson.select ||  "none";
        var selectFlag = this.view.getSelectFlag();
551
        if (this.data.$selectedEnable && ["multi", "single"].contains(selectFlag) && this.view.viewJson.selectBoxShow === "always") {
U
unknown 已提交
552 553 554 555 556 557 558 559 560 561 562 563 564 565
            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"});
            }
        }

566
        if (this.view.isSelectTdHidden()) {
U
unknown 已提交
567 568 569 570 571
            this.selectTd.hide();
        }
        //}

        //序号
572
        if (this.view.viewJson.isSequence === "yes") {
U
unknown 已提交
573 574
            this.sequenceTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
            this.sequenceTd.setStyle("width", "10px");
575
            var s = 1 + this.view.json.pageSize * (this.view.currentPage - 1) + this.idx;
U
unknown 已提交
576 577 578 579 580
            this.sequenceTd.set("text", s);
        }

        debugger;

581
        Object.each(this.view.entries, function (c, k) {
U
unknown 已提交
582
            //if (cell){
583
            if (this.view.hideColumns.indexOf(k) === -1) {
U
unknown 已提交
584
                var td = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
U
unknown 已提交
585

586
                var cell = this.getText(c, k, td); //this.data[k];
U
unknown 已提交
587 588 589 590
                if (cell === undefined || cell === null) cell = "";

                // if (k!== this.view.viewJson.group.column){
                var v = cell;
591
                if (c.isHtml) {
U
unknown 已提交
592
                    td.set("html", v);
593
                } else {
U
unknown 已提交
594
                    td.set("text", v);
U
unknown 已提交
595 596
                }

597
                if (typeOf(c.contentProperties) === "object") td.setProperties(c.contentProperties);
U
unknown 已提交
598
                if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
599
                if (typeOf(c.contentStyles) === "object") td.setStyles(c.contentStyles);
U
unknown 已提交
600 601 602 603
                // }else{
                //     if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
                // }

604
                if (this.view.openColumns.indexOf(k) !== -1) {
U
unknown 已提交
605 606 607
                    this.setOpenWork(td, c)
                }

U
unknown 已提交
608
                // if (k!== this.view.viewJson.group.column){
609 610 611 612 613 614 615
                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 已提交
616 617
                                return this.view.Macro.fire(
                                    e.code,
618
                                    {"node": td, "json": c, "data": v, "view": this.view, "row": this},
U
unknown 已提交
619 620 621
                                    event
                                );
                            }.bind(this));
U
unknown 已提交
622
                        }
U
unknown 已提交
623 624 625
                    }
                }.bind(this));
                // }
U
unknown 已提交
626 627 628 629 630
            }
            //}
        }.bind(this));

        //默认选中
631 632
        var selectedFlag;

U
unknown 已提交
633
        var defaultSelectedScript = this.view.json.defaultSelectedScript || this.view.viewJson.defaultSelectedScript;
634
        if (!this.isSelected && defaultSelectedScript) {
U
unknown 已提交
635 636 637 638
            // var flag = this.view.json.select || this.view.viewJson.select ||  "none";
            // if ( flag ==="single" || flag==="multi"){
            //
            // }
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
            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 已提交
660 661 662 663 664 665 666 667
                }
            }
        }

        this.setEvent();

        this.view.fireEvent("postLoadItemRow", [null, this]);
    },
668 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 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
    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 已提交
723 724 725 726 727 728 729 730 731 732 733 734 735
        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
    },
736
    getText: function (c, k, td) {
U
unknown 已提交
737
        var path = c.path, code = c.code, obj = this.data;
738
        if (!path) {
U
unknown 已提交
739
            return ""
740 741
        } else if (path === "$all") {
        } else {
U
unknown 已提交
742
            obj = this.getDataByPath(obj, path);
U
unknown 已提交
743 744
        }

745 746 747 748 749 750 751 752
        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 已提交
753 754

        var toName = function (value) {
755 756
            if (typeOf(value) === "array") {
                Array.each(value, function (v, idx) {
U
unknown 已提交
757 758
                    value[idx] = toName(v)
                })
759 760
            } else if (typeOf(value) === "object") {
                Object.each(value, function (v, key) {
U
unknown 已提交
761 762
                    value[key] = toName(v);
                })
763 764
            } else if (typeOf(value) === "string") {
                value = o2.name.cn(value)
U
unknown 已提交
765 766 767 768 769
            }
            return value;
        };

        var d;
770 771
        if (obj != undefined && obj != null) {
            if (typeOf(obj) === "array") {
U
unknown 已提交
772
                d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
773
            } else if (typeOf(obj) === "object") {
U
unknown 已提交
774
                d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
775 776
            } else {
                d = c.isName ? o2.name.cn(obj.toString()) : obj;
U
unknown 已提交
777 778 779 780 781
            }
        }

        return d;
    },
782
    setOpenWork: function (td, column) {
U
unknown 已提交
783
        td.setStyle("cursor", "pointer");
784 785
        if (column.clickCode) {
            if (!this.view.Macro) {
U
unknown 已提交
786 787
                MWF.require("MWF.xScript.Macro", function () {
                    this.view.businessData = {};
788
                    this.view.Macro = new MWF.Macro.ViewContext(this.view);
U
unknown 已提交
789 790
                }.bind(this), false);
            }
791
            td.addEvent("click", function (ev) {
U
unknown 已提交
792 793 794 795
                var result = this.view.Macro.fire(column.clickCode, this, ev);
                ev.stopPropagation();
                return result;
            }.bind(this));
796 797 798 799 800
        } 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 已提交
801 802 803
                        this.openCms(ev, id);
                        ev.stopPropagation();
                    }.bind(this));
804 805
                } else {
                    td.addEvent("click", function (ev) {
U
unknown 已提交
806 807 808 809 810
                        this.openWork(ev, id);
                        ev.stopPropagation();
                    }.bind(this));
                }
            }
U
unknown 已提交
811
        }
U
unknown 已提交
812
    },
813
    openCms: function (e, id) {
U
unknown 已提交
814 815 816 817
        var options = {"documentId": id};
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
        layout.desktop.openApplication(e, "cms.Document", options);
    },
818
    openWork: function (e, id) {
U
unknown 已提交
819 820 821
        var options = {"workId": id};
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
        layout.desktop.openApplication(e, "process.Work", options);
U
unknown 已提交
822 823 824 825
    }
});

MWF.xApplication.query.Query.Statement.Filter = new Class({
826
    Extends: MWF.xApplication.query.Query.Viewer.Filter
U
unknown 已提交
827 828 829
});

MWF.xApplication.query.Query.Statement.Actionbar = new Class({
830
    Extends: MWF.xApplication.query.Query.Viewer.Actionbar
U
unknown 已提交
831 832 833
});

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