Statement.js 29.3 KB
Newer Older
U
unknown 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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,
    options: {
    },
    initialize: function(container, json, options, app, parentMacro){
        //本类有三种事件,
        //一种是通过 options 传进来的事件,包括 loadView、openDocument、select
        //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
        //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件

        this.setOptions(options);

        this.path = "../x_component_query_Query/$Viewer/";
        this.cssPath = "../x_component_query_Query/$Viewer/"+this.options.style+"/css.wcss";
        this._loadCss();
        this.lp = MWF.xApplication.query.Query.LP;

        this.app = app;

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

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

        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 已提交
41
        this.parameter = {};
U
unknown 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54

        this.gridJson = null;

        if (this.options.isload){
            this.init(function(){
                this.load();
            }.bind(this));
        }

    },
    init: function(callback){
        if (this.json.view){
            this.viewJson = JSON.decode(this.json.view);
U
unknown 已提交
55
            this.statementJson = this.json;
U
unknown 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
            if (callback) callback();
        }else{
            this.getView(callback);
        }
    },
    loadMacro: function (callback) {
        MWF.require("MWF.xScript.Macro", function () {
            this.Macro = new MWF.Macro.ViewContext(this);
            if (callback) callback();
        }.bind(this));
    },
    createActionbarNode : function(){
        this.actionbarAreaNode.empty();
        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;
            this.actionbar = new MWF.xApplication.query.Query.Statement.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
            this.actionbar.load();
        }
    },
    _loadPageNode : function(){
        this.viewPageAreaNode.empty();
        if( !this.paging ){
            var json;
            if( !this.viewJson.pagingList || !this.viewJson.pagingList.length ){
                json = {
                    "firstPageText": this.lp.firstPage,
                    "lastPageText": this.lp.lastPage
                };
            }else{
                json = this.viewJson.pagingList[0];
            }
            this.paging = new MWF.xApplication.query.Query.Statement.Paging(this.viewPageAreaNode, json, this, {});
            this.paging.load();
        }else{
            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;
    // },
U
unknown 已提交
100 101 102
    lookup: function(data, callback){
        if( this.lookuping )return;
        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;
U
unknown 已提交
114
        this.loadParameter( d );
U
unknown 已提交
115
        this.loadFilter( d );
U
unknown 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

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

        if( this.noDataTextNode )this.noDataTextNode.destroy();
        this.loadCurrentPageData( function (json) {
            if(this.count){
                this.fireEvent("postLoad"); //用户配置的事件
                this.lookuping = false;
                if(callback)callback(this);
            }else{
                this.viewPageAreaNode.empty();
                if( this.viewJson.noDataText ){
                    var noDataTextNodeStyle = this.css.noDataTextNode;
                    if( this.viewJson.viewStyles && this.viewJson.viewStyles["noDataTextNode"] ){
                        noDataTextNodeStyle = this.viewJson.viewStyles["noDataTextNode"];
                    }
                    this.noDataTextNode = new Element( "div", {
                        "styles": noDataTextNodeStyle,
                        "text" : this.viewJson.noDataText
                    }).inject( this.contentAreaNode );
                }
                // if (this.loadingAreaNode){
                //     this.loadingAreaNode.destroy();
                //     this.loadingAreaNode = null;
                // }
                this.fireEvent("postLoad"); //用户配置的事件
                this.lookuping = false;
                if(callback)callback(this);
            }


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

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

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

U
unknown 已提交
270 271
        debugger;

U
unknown 已提交
272 273 274 275 276 277
        if( this.pageloading )return;
        this.pageloading = true;

        this.items = [];

        var p = this.currentPage;
U
unknown 已提交
278
        var d = {
U
unknown 已提交
279 280
            "filterList" : this.filterList,
            "parameter" : this.parameter
U
unknown 已提交
281
        };
U
unknown 已提交
282 283 284 285 286 287

        while (this.viewTable.rows.length>1){
            this.viewTable.deleteRow(-1);
        }
        //this.createLoadding();

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

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

                this.gridJson = json.data;
U
unknown 已提交
301
                this.setSelectedableFlag();
U
unknown 已提交
302

U
unknown 已提交
303
                this.fireEvent("postLoadPageData");
U
unknown 已提交
304

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

U
unknown 已提交
317
                this.pageloading = false;
U
unknown 已提交
318

U
unknown 已提交
319 320
                this.fireEvent("loadView"); //options 传入的事件
                this.fireEvent("postLoadPage");
U
unknown 已提交
321

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

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

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

            if( entry.valueType === "script" && entry.valueScript && entry.valueScript.code  ){
                var idx = this.viewSearchCustomValueNode.selectedIndex;
                if (idx!==-1){
                    var v = this.viewSearchCustomValueNode.options[idx].get("value");
                    value = entry.formatType === "booleanValue" ? (v==="true") : v;
                }
            }else{
                switch (entry.formatType){
                    case "numberValue":
                        value = this.viewSearchCustomValueNode.get("value");
                        break;
                    case "dateTimeValue":
                        value = this.viewSearchCustomValueNode.get("value");
                        break;
                    case "booleanValue":
                        var idx = this.viewSearchCustomValueNode.selectedIndex;
                        if (idx!==-1){
                            var v = this.viewSearchCustomValueNode.options[idx].get("value");
                            value = (v==="true");
                        }
                        break;
                    default:
                        value = this.viewSearchCustomValueNode.get("value");
                }
            }

            if (value===""){
                MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
                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,
                "formatType": (entry.formatType=="datetimeValue") ? "dateTimeValue": entry.formatType
            }, this.viewSearchCustomFilterContentNode));

            this.searchCustomView();
        }
U
unknown 已提交
479
    },
U
unknown 已提交
480
    //搜索相关结束
U
unknown 已提交
481 482 483 484 485
    getStatementInfor : function () {
        return this.json;
    },
    switchStatement : function (json) {
        this.switchView(json);
U
unknown 已提交
486 487 488 489 490 491 492 493 494 495
    },
    setFilter : function( filter, callback ){
        if( this.lookuping || this.pageloading )return;
        if( !filter )filter = {"filterList": [], "paramter" : {} };
        if( typeOf( filter ) === "object" )return;
        this.json.filter = filter.filterList || [];
        this.json.paramter = filter.paramter || {};
        if( this.viewAreaNode ){
            this.createViewNode({"filterList": this.json.filter.clone(), "paramter" : Object.clone(this.json.paramter) }, callback);
        }
U
unknown 已提交
496
    }
U
unknown 已提交
497 498 499 500
});

MWF.xApplication.query.Query.Statement.Item = new Class({
    Extends : MWF.xApplication.query.Query.Viewer.Item,
U
unknown 已提交
501
    initialize: function(view, data, prev, i, category){
U
unknown 已提交
502 503 504 505
        this.view = view;
        this.data = data;
        this.css = this.view.css;
        this.isSelected = false;
U
unknown 已提交
506
        this.category = category;
U
unknown 已提交
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
        this.prev = prev;
        this.idx = i;
        this.clazzType = "item";

        this.load();
    },
    load: function(){
        this.view.fireEvent("queryLoadItemRow", [null, this]);

        var viewStyles = this.view.viewJson.viewStyles;
        var viewContentTdNode = ( viewStyles && viewStyles["contentTd"] ) ? viewStyles["contentTd"] : this.css.viewContentTdNode;

        this.node = new Element("tr", {
            "styles": ( viewStyles && viewStyles["contentTr"] ) ? viewStyles["contentTr"] : this.css.viewContentTrNode
        });
        if (this.prev){
            this.node.inject(this.prev.node, "after");
        }else{
            this.node.inject(this.view.viewTable);
        }

        //if (this.view.json.select==="single" || this.view.json.select==="multi"){
        this.selectTd = new Element("td", { "styles": viewContentTdNode }).inject(this.node);
        this.selectTd.setStyles({"cursor": "pointer"});
        if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
U
unknown 已提交
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549

        //var selectFlag = this.view.json.select || this.view.viewJson.select ||  "none";
        var selectFlag = this.view.getSelectFlag();
        if ( this.data.$selectedEnable && ["multi","single"].contains(selectFlag) && this.view.viewJson.selectBoxShow==="always") {
            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"});
            }
        }

U
unknown 已提交
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
        if( this.view.isSelectTdHidden() ){
            this.selectTd.hide();
        }
        //}

        //序号
        if (this.view.viewJson.isSequence==="yes"){
            this.sequenceTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
            this.sequenceTd.setStyle("width", "10px");
            var s= 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
            this.sequenceTd.set("text", s);
        }

        debugger;

        Object.each(this.view.entries, function(c, k){
            //if (cell){
            if (this.view.hideColumns.indexOf(k)===-1){
                var td = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
U
unknown 已提交
569 570 571 572 573 574 575 576

                var cell =  this.getText( c, k, td ); //this.data[k];
                if (cell === undefined || cell === null) cell = "";

                // if (k!== this.view.viewJson.group.column){
                var v = cell;
                if (c.isHtml){
                    td.set("html", v);
U
unknown 已提交
577
                }else{
U
unknown 已提交
578
                    td.set("text", v);
U
unknown 已提交
579 580
                }

U
unknown 已提交
581 582 583 584 585 586 587
                if( typeOf(c.contentProperties) === "object" )td.setProperties(c.contentProperties);
                if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
                if( typeOf(c.contentStyles) === "object" )td.setStyles(c.contentStyles);
                // }else{
                //     if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
                // }

U
unknown 已提交
588 589 590 591
                if (this.view.openColumns.indexOf(k)!==-1){
                    this.setOpenWork(td, c)
                }

U
unknown 已提交
592 593 594 595 596 597 598 599 600 601 602 603 604 605
                // if (k!== this.view.viewJson.group.column){
                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){
                                return this.view.Macro.fire(
                                    e.code,
                                    {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this},
                                    event
                                );
                            }.bind(this));
U
unknown 已提交
606
                        }
U
unknown 已提交
607 608 609
                    }
                }.bind(this));
                // }
U
unknown 已提交
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
            }
            //}
        }.bind(this));

        //默认选中
        var defaultSelectedScript = this.view.json.defaultSelectedScript || this.view.viewJson.defaultSelectedScript;
        if( !this.isSelected && defaultSelectedScript ){
            // var flag = this.view.json.select || this.view.viewJson.select ||  "none";
            // if ( flag ==="single" || flag==="multi"){
            //
            // }
            var flag = this.view.Macro.exec( defaultSelectedScript,
                {"node" : this.node, "data" : this.data, "view": this.view, "row" : this});
            if( flag ){
                if( flag === "multi" || flag === "single" ){
                    this.select( flag );
                }else if( flag.toString() === "true" ){
                    var f = this.view.json.select || this.view.viewJson.select ||  "none";
                    if ( f ==="single" || f==="multi"){
                        this.select();
                    }
                }
            }
        }

        this.setEvent();

        this.view.fireEvent("postLoadItemRow", [null, this]);
    },
U
unknown 已提交
639 640 641 642 643 644 645 646 647 648 649 650 651 652
    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
    },
U
unknown 已提交
653 654
    getText : function(c, k, td){
        var path = c.path, code = c.code, obj = this.data;
U
unknown 已提交
655 656 657 658
        if( !path ){
            return ""
        }else if( path === "$all" ){
        }else{
U
unknown 已提交
659
            obj = this.getDataByPath(obj, path);
U
unknown 已提交
660 661
        }

U
unknown 已提交
662
        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 已提交
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691

        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 已提交
692 693 694
    setOpenWork: function(td, column){
        td.setStyle("cursor", "pointer");
        if( column.clickCode ){
U
unknown 已提交
695 696 697 698 699 700
            if( !this.view.Macro ){
                MWF.require("MWF.xScript.Macro", function () {
                    this.view.businessData = {};
                    this.view.Macro = new MWF.Macro.PageContext(this.view);
                }.bind(this), false);
            }
U
unknown 已提交
701 702 703 704 705
            td.addEvent("click", function( ev ){
                var result = this.view.Macro.fire(column.clickCode, this, ev);
                ev.stopPropagation();
                return result;
            }.bind(this));
U
unknown 已提交
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
        }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){
                        this.openCms(ev, id);
                        ev.stopPropagation();
                    }.bind(this));
                }else{
                    td.addEvent("click", function(ev){
                        this.openWork(ev, id);
                        ev.stopPropagation();
                    }.bind(this));
                }
            }
U
unknown 已提交
721
        }
U
unknown 已提交
722 723 724 725 726 727 728 729 730 731
    },
    openCms: function(e, id){
        var options = {"documentId": id};
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
        layout.desktop.openApplication(e, "cms.Document", options);
    },
    openWork: function(e, id){
        var options = {"workId": id};
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
        layout.desktop.openApplication(e, "process.Work", options);
U
unknown 已提交
732 733 734 735 736 737 738 739 740 741 742 743 744 745
    }
});

MWF.xApplication.query.Query.Statement.Filter = new Class({
    Extends : MWF.xApplication.query.Query.Viewer.Filter
});

MWF.xApplication.query.Query.Statement.Actionbar = new Class({
    Extends : MWF.xApplication.query.Query.Viewer.Actionbar
});

MWF.xApplication.query.Query.Statement.Paging = new Class({
    Extends : MWF.xApplication.query.Query.Viewer.Paging
});