Viewer.js 81.2 KB
Newer Older
R
roo00 已提交
1 2 3
MWF.xApplication.query = MWF.xApplication.query || {};
MWF.xApplication.query.Query = MWF.xApplication.query.Query || {};
MWF.require("MWF.widget.Common", null, false);
4
MWF.require("o2.widget.Paging", null, false);
R
roo00 已提交
5 6 7 8 9 10 11 12 13 14 15
MWF.require("MWF.xScript.Macro", null, false);
MWF.xDesktop.requireApp("query.Query", "lp.zh-cn", null, false);
MWF.xApplication.query.Query.Viewer = MWF.QViewer = new Class({
    Implements: [Options, Events],
    Extends: MWF.widget.Common,
    options: {
        "style": "default",
        "resizeNode": true,
        "paging" : "scroll",
        "perPageCount" : 50,
        "isload": "true",
U
unknown 已提交
16
        "export": false,
17 18
        "moduleEvents": ["queryLoad", "postLoad", "postLoadPageData", "postLoadPage", "selectRow", "unselectRow",
            "queryLoadItemRow", "postLoadItemRow", "queryLoadCategoryRow", "postLoadCategoryRow"]
U
unknown 已提交
19

R
roo00 已提交
20 21 22 23 24 25 26
        // "actions": {
        //     "lookup": {"uri": "/jaxrs/view/flag/{view}/query/{application}/execute", "method":"PUT"},
        //     "getView": {"uri": "/jaxrs/view/flag/{view}/query/{application}"}
        //
        // },
        // "actionRoot": "x_query_assemble_surface"
    },
U
unknown 已提交
27
    initialize: function(container, json, options, app, parentMacro){
U
unknown 已提交
28 29 30 31 32
        //本类有三种事件,
        //一种是通过 options 传进来的事件,包括 loadView、openDocument、select
        //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
        //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件

R
roo00 已提交
33 34 35 36 37 38 39
        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;

U
unknown 已提交
40 41
        this.app = app;

R
roo00 已提交
42 43 44
        this.container = $(container);
        this.json = json;

U
unknown 已提交
45 46
        this.parentMacro = parentMacro;

47 48 49
        debugger;
        this.originalJson = Object.clone(json);

R
roo00 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
        this.viewJson = null;
        this.filterItems = [];
        this.searchStatus = "none"; //none, custom, default


        this.items = [];
        this.selectedItems = [];
        this.hideColumns = [];
        this.openColumns = [];

        this.gridJson = null;

        if (this.options.isload){
            this.init(function(){
                this.load();
            }.bind(this));
        }
U
unknown 已提交
67

R
roo00 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    },
    loadView: function(){
        if (this.viewJson){
            this.reload();
        }else{
            this.init(function(){
                this.load();
            }.bind(this));
        }
    },
    init: function(callback){
        if (this.json.data){
            this.viewJson = JSON.decode(this.json.data);
            if (callback) callback();
        }else{
            this.getView(callback);
        }
    },
    load: function(){
U
unknown 已提交
87 88 89 90 91 92 93
        this.loadMacro( function () {
            this._loadModuleEvents();
            if (this.fireEvent("queryLoad")){
                this._loadUserInterface();
                //this._loadStyles();
                this._loadDomEvents();
            }
94
        }.bind(this))
U
unknown 已提交
95 96
    },
    _loadUserInterface : function(){
R
roo00 已提交
97
        this.loadLayout();
U
unknown 已提交
98
        this.createActionbarNode();
R
roo00 已提交
99 100 101 102 103 104 105 106 107 108 109
        this.createSearchNode();
        this.createViewNode({"filterList": this.json.filter  ? this.json.filter.clone() : null});

        if (this.options.resizeNode){
            this.setContentHeightFun = this.setContentHeight.bind(this);
            this.container.addEvent("resize", this.setContentHeightFun);
            this.setContentHeightFun();
        }
    },
    loadLayout: function(){
        this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
U
unknown 已提交
110 111
        this.actionbarAreaNode =  new Element("div", {"styles": this.css.actionbarAreaNode}).inject(this.node);
        //if (this.options.export) this.exportAreaNode = new Element("div", {"styles": this.css.exportAreaNode}).inject(this.node);
R
roo00 已提交
112 113
        this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.node);
        this.viewAreaNode = new Element("div", {"styles": this.css.viewAreaNode}).inject(this.node);
NoSubject's avatar
NoSubject 已提交
114 115
        this.viewPageNode = new Element("div", {"styles": this.css.viewPageNode}).inject(this.node);
        this.viewPageAreaNode = new Element("div", {"styles": this.css.viewPageAreaNode}).inject(this.viewPageNode);
R
roo00 已提交
116
    },
U
unknown 已提交
117
    loadMacro: function (callback) {
U
unknown 已提交
118 119
        MWF.require("MWF.xScript.Macro", function () {
            this.Macro = new MWF.Macro.ViewContext(this);
U
unknown 已提交
120
            if (callback) callback();
U
unknown 已提交
121
        }.bind(this));
U
unknown 已提交
122
    },
R
roo00 已提交
123 124 125
    createExportNode: function(){
        if (this.options.export){
            MWF.require("MWF.widget.Toolbar", function(){
U
unknown 已提交
126
                this.toolbar = new MWF.widget.Toolbar(this.actionbarAreaNode, {"style": "simple"}, this); //this.exportAreaNode
R
roo00 已提交
127 128 129 130 131 132 133
                var actionNode = new Element("div", {
                    "id": "",
                    "MWFnodetype": "MWFToolBarButton",
                    "MWFButtonImage": this.path+""+this.options.style+"/icon/export.png",
                    "title": this.lp.exportExcel,
                    "MWFButtonAction": "exportView",
                    "MWFButtonText": this.lp.exportExcel
U
unknown 已提交
134
                }).inject(this.actionbarAreaNode); //this.exportAreaNode
R
roo00 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158

                this.toolbar.load();
            }.bind(this));
            //this.exportNode = new Element("button", {"text": this.lp.exportExcel}).inject(this.exportAreaNode);
        }
    },
    exportView: function(){
        var action = MWF.Actions.get("x_query_assemble_surface");

        var filterData = this.json.filter ? this.json.filter.clone() : [];
        if (this.filterItems.length){
            this.filterItems.each(function(filter){
                filterData.push(filter.data);
            }.bind(this));
        }
        action.exportViewWithQuery(this.json.viewName, this.json.application, {"filterList": filterData}, function(json){
            var uri = action.action.actions.getViewExcel.uri;
            uri = uri.replace("{flag}", json.data.id);
            uri = action.action.address+uri;
            var a = new Element("a", {"href": uri, "target":"_blank"});
            a.click();
            a.destroy();
        }.bind(this));
    },
U
unknown 已提交
159 160 161 162 163 164 165 166 167 168 169
    setContentHeight: function(){
        var size = this.node.getSize();
        var searchSize = this.searchAreaNode.getComputedSize();
        var h = size.y-searchSize.totalHeight;
        //if (this.exportAreaNode){
        //    var exportSize = this.exportAreaNode.getComputedSize();
        //    h = h-exportSize.totalHeight;
        //}
        if( this.actionbarAreaNode ){
            var exportSize = this.actionbarAreaNode.getComputedSize();
            h = h-exportSize.totalHeight;
R
roo00 已提交
170
        }
U
unknown 已提交
171 172 173
        var pageSize = this.viewPageNode.getComputedSize();
        h = h-pageSize.totalHeight;
        this.viewAreaNode.setStyle("height", ""+h+"px");
R
roo00 已提交
174
    },
U
unknown 已提交
175 176 177 178 179 180 181
    createLoadding: function(){
        this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.contentAreaNode);
        new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
        var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
        new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
        var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
        loadingTextNode.set("text", "loading...");
R
roo00 已提交
182
    },
U
unknown 已提交
183 184 185 186 187 188 189 190
    createActionbarNode : function(){
        this.actionbarAreaNode.empty();
        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.Viewer.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
            this.actionbar.load();
        }else{ //兼容以前的ExportNode
            this.createExportNode();
R
roo00 已提交
191 192
        }
    },
U
unknown 已提交
193 194 195
    createViewNode: function(data){
        this.viewAreaNode.empty();
        this.contentAreaNode = new Element("div", {"styles": this.css.contentAreaNode}).inject(this.viewAreaNode);
R
roo00 已提交
196

U
unknown 已提交
197 198 199 200 201 202 203
        this.viewTable = new Element("table", {
            "styles": this.css.viewTitleTableNode,
            "border": "0px",
            "cellPadding": "0",
            "cellSpacing": "0"
        }).inject(this.contentAreaNode);
        this.createLoadding();
R
roo00 已提交
204

U
unknown 已提交
205 206
        if (this.json.isTitle!=="no"){
            this.viewTitleLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
R
roo00 已提交
207

U
unknown 已提交
208 209 210 211 212 213 214
            //if (this.json.select==="single" || this.json.select==="multi") {
            this.selectTitleCell = new Element("td", {
                "styles": this.css.viewTitleCellNode
            }).inject(this.viewTitleLine);
            this.selectTitleCell.setStyle("width", "10px");
            if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
            //}
R
roo00 已提交
215

U
unknown 已提交
216 217 218 219 220 221 222
            //序号
            if (this.viewJson.isSequence==="yes"){
                this.sequenceTitleCell = new Element("td", {
                    "styles": this.css.viewTitleCellNode
                }).inject(this.viewTitleLine);
                this.sequenceTitleCell.setStyle("width", "10px");
                if (this.json.titleStyles) this.sequenceTitleCell.setStyles(this.json.titleStyles);
R
roo00 已提交
223 224
            }

U
unknown 已提交
225 226 227
            this.entries = {};
            this.viewJson.selectList.each(function(column){
                this.entries[column.column] = column;
R
roo00 已提交
228

U
unknown 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
                if (!column.hideColumn){
                    var viewCell = new Element("td", {
                        "styles": this.css.viewTitleCellNode,
                        "text": column.displayName
                    }).inject(this.viewTitleLine);
                    var size = MWF.getTextSize(column.displayName, this.css.viewTitleCellNode);
                    viewCell.setStyle("min-width", ""+size.x+"px");
                    if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
                }else{
                    this.hideColumns.push(column.column);
                }
                if (column.allowOpen) this.openColumns.push(column.column);
            }.bind(this));
            this.lookup(data);
        }else{
            this.viewJson.selectList.each(function(column){
                if (column.hideColumn) this.hideColumns.push(column.column);
                if (!column.allowOpen) this.openColumns.push(column.column);
            }.bind(this));
            this.lookup(data);
        }
R
roo00 已提交
250
    },
U
unknown 已提交
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
    // _loadPageCountNode: function(){
    //     this.viewPageContentNode.empty();
    //
    //     var size = this.viewPageAreaNode.getSize();
    //     var w1 = this.viewPageFirstNode.getSize().x*2;
    //     var w2 = this.viewPageContentNode.getStyle("margin-left").toInt();
    //     var w = size.x-w1-w2;
    //
    //     var bw = this.css.viewPageButtonNode.width.toInt()+this.css.viewPageButtonNode["margin-right"].toInt();
    //     var count = (w/bw).toInt()-2;
    //     if (count>10) count = 10;
    //     this.showPageCount = Math.min(count, this.pages);
    //
    //     var tmp = this.showPageCount/2;
    //     var n = tmp.toInt();
    //     var left = this.currentPage-n;
    //     if (left<=0) left = 1;
    //     var right = this.showPageCount + left-1;
    //     if (right>this.pages) right = this.pages;
    //     left = right-this.showPageCount+1;
    //     if (left<=1) left = 1;
    //
    //     this.viewPagePrevNode = new Element("div", {"styles": this.css.viewPagePrevButtonNode}).inject(this.viewPageContentNode);
    //     this.loadPageButtonEvent(this.viewPagePrevNode, "viewPagePrevButtonNode_over", "viewPagePrevButtonNode_up", "viewPagePrevButtonNode_down", function(){
    //         if (this.currentPage>1) this.currentPage--;
    //         this.loadCurrentPageData();
    //     }.bind(this));
    //
    //     for (i=left; i<=right; i++){
    //         var node = new Element("div", {"styles": this.css.viewPageButtonNode, "text": i}).inject(this.viewPageContentNode);
    //         if (i==this.currentPage){
    //             node.setStyles(this.css.viewPageButtonNode_current);
    //         }else{
    //             this.loadPageButtonEvent(node, "viewPageButtonNode_over", "viewPageButtonNode_up", "viewPageButtonNode_down", function(e){
    //                 this.currentPage = e.target.get("text").toInt();
    //                 this.loadCurrentPageData();
    //             }.bind(this));
    //         }
    //     }
    //     this.viewPageNextNode = new Element("div", {"styles": this.css.viewPageNextButtonNode}).inject(this.viewPageContentNode);
    //     this.loadPageButtonEvent(this.viewPageNextNode, "viewPageNextButtonNode_over", "viewPageNextButtonNode_up", "viewPageNextButtonNode_down", function(){
    //         if (this.currentPage<=this.pages-1) this.currentPage++;
    //         this.loadCurrentPageData();
    //     }.bind(this));
    // },
    // loadPageButtonEvent: function(node, over, out, down, click){
    //     node.addEvents({
    //         "mouseover": function(){node.setStyles(this.css[over])}.bind(this),
    //         "mouseout": function(){node.setStyles(this.css[out])}.bind(this),
    //         "mousedown": function(){node.setStyles(this.css[down])}.bind(this),
    //         "mouseup": function(){node.setStyles(this.css[out])}.bind(this),
    //         "click": click
    //     });
    // },
    // _loadPageNode: function(){
    //     this.viewPageAreaNode.empty();
    //     this.viewPageFirstNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.firstPage}).inject(this.viewPageAreaNode);
    //     this.viewPageContentNode = new Element("div", {"styles": this.css.viewPageContentNode}).inject(this.viewPageAreaNode);
    //     this.viewPageLastNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.lastPage}).inject(this.viewPageAreaNode);
    //     this._loadPageCountNode();
    //
    //     this.loadPageButtonEvent(this.viewPageFirstNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
    //         this.currentPage = 1;
    //         this.loadCurrentPageData();
    //     }.bind(this));
    //     this.loadPageButtonEvent(this.viewPageLastNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
    //         this.currentPage = this.pages;
    //         this.loadCurrentPageData();
    //     }.bind(this));
    // },
    _loadPageNode : function(){
        debugger;
        this.viewPageAreaNode.empty();
        this.paging = new o2.widget.Paging(this.viewPageAreaNode, {
            countPerPage: this.json.pageSize || this.options.perPageCount,
            visiblePages: this.viewJson.visiblePages ? this.viewJson.visiblePages.toInt() : 9,
            currentPage: this.currentPage,
            itemSize: this.count,
            pageSize: this.pages,
            hasNextPage: typeOf( this.viewJson.hasPreNextPage ) === "boolean" ? this.viewJson.hasPreNextPage : true,
            hasPrevPage: typeOf( this.viewJson.hasPreNextPage ) === "boolean" ? this.viewJson.hasPreNextPage : true,
            hasTruningBar: typeOf( this.viewJson.hasTruningBar ) === "boolean" ? this.viewJson.hasTruningBar : true,
            hasBatchTuring: typeOf( this.viewJson.hasBatchTuring ) === "boolean" ? this.viewJson.hasBatchTuring : true,
            hasFirstPage: typeOf( this.viewJson.hasFirstLastPage ) === "boolean" ? this.viewJson.hasFirstLastPage : true,
            hasLastPage: typeOf( this.viewJson.hasFirstLastPage ) === "boolean" ? this.viewJson.hasFirstLastPage : true,
            hasJumper: typeOf( this.viewJson.hasPageJumper ) === "boolean" ? this.viewJson.hasPageJumper : true,
            hiddenWithDisable: false,
            hiddenWithNoItem: true,
            text: {
                prePage: "",
                nextPage: "",
                firstPage: this.lp.firstPage,
                lastPage: this.lp.lastPage
            },
            onJumpingPage : function( pageNum, itemNum ){
                this.currentPage = pageNum;
                this.loadCurrentPageData();
            }.bind(this),
            onPostLoad : function () {
                this.setContentHeightFun();
            }.bind(this)
        });
        this.paging.load();
R
roo00 已提交
354
    },
U
unknown 已提交
355 356 357 358 359 360
    _initPage: function(){
        this.count = this.bundleItems.length;

        var i = this.count/this.json.pageSize;
        this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
        this.currentPage = 1;
R
roo00 已提交
361
    },
U
unknown 已提交
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
    lookup: function(data){
        this.getLookupAction(function(){
            if (this.json.application){

                var d = data || {};
                d.count = this.json.count;
                this.lookupAction.bundleView(this.json.id, d, function(json){
                    this.bundleItems = json.data.valueList;

                    this._initPage();
                    if (this.bundleItems.length){
                        this.loadCurrentPageData( function () {
                            this.fireEvent("postLoad"); //用户配置的事件
                        }.bind(this));
                    }else{
                        //this._loadPageNode();
                        this.viewPageAreaNode.empty();
                        if (this.loadingAreaNode){
                            this.loadingAreaNode.destroy();
                            this.loadingAreaNode = null;
                        }
                        this.fireEvent("postLoad"); //用户配置的事件
                    }
                }.bind(this));
            }
R
roo00 已提交
387 388
        }.bind(this));
    },
U
unknown 已提交
389 390 391 392
    loadCurrentPageData: function( callback ){
        debugger;
        //是否需要在翻页的时候清空之前的items ?
        this.items = [];
R
roo00 已提交
393

U
unknown 已提交
394 395 396 397
        var p = this.currentPage;
        var d = {};
        var valueList = this.bundleItems.slice((p-1)*this.json.pageSize,this.json.pageSize*p);
        d.bundleList = valueList;
R
roo00 已提交
398

U
unknown 已提交
399 400 401 402
        while (this.viewTable.rows.length>1){
            this.viewTable.deleteRow(-1);
        }
        //this.createLoadding();
R
roo00 已提交
403

U
unknown 已提交
404 405
        this.loadViewRes = this.lookupAction.loadView(this.json.name, this.json.application, d, function(json){
            this.viewData = json.data;
R
roo00 已提交
406

U
unknown 已提交
407
            this.fireEvent("postLoadPageData");
R
roo00 已提交
408

U
unknown 已提交
409 410 411 412 413 414
            if (this.viewJson.group.column){
                this.gridJson = json.data.groupGrid;
                this.loadGroupData();
            }else{
                this.gridJson = json.data.grid;
                this.loadData();
R
roo00 已提交
415
            }
U
unknown 已提交
416 417 418 419
            if (this.gridJson.length) this._loadPageNode();
            if (this.loadingAreaNode){
                this.loadingAreaNode.destroy();
                this.loadingAreaNode = null;
R
roo00 已提交
420 421
            }

U
unknown 已提交
422
            this.fireEvent("loadView"); //options 传入的事件
R
roo00 已提交
423

U
unknown 已提交
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
            this.fireEvent("postLoadPage");

            if(callback)callback();
        }.bind(this));
    },


    loadData: function(){
        if (this.gridJson.length){
            // if( !this.options.paging ){
            this.gridJson.each(function(line, i){
                this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, line, null, i));
            }.bind(this));
            // }else{
            //     this.loadPaging();
            // }
        }else{
            if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
R
roo00 已提交
442 443
        }
    },
U
unknown 已提交
444 445 446 447 448 449 450
    loadPaging : function(){
        this.isItemsLoading = false;
        this.pageNumber = 0;
        this.isItemsLoaded = false;
        this.isSetedScroll = false;
        this.setScroll();
        this.loadDataByPaging()
R
roo00 已提交
451
    },
U
unknown 已提交
452 453 454 455 456 457 458 459 460 461 462 463 464 465
    setScroll : function(){
        if( this.options.paging && !this.isSetedScroll ){
            this.contentAreaNode.setStyle("overflow","auto");
            this.scrollContainerFun = function(){
                var scrollSize = this.contentAreaNode.getScrollSize();
                var clientSize = this.contentAreaNode.getSize();
                var scrollHeight = scrollSize.y - clientSize.y;
                //alert( "clientSize.y=" + clientSize.y + " scrollSize.y="+scrollSize.y + " this.contentAreaNode.scrollTop="+this.contentAreaNode.scrollTop);
                if (this.contentAreaNode.scrollTop + 150 > scrollHeight ) {
                    if (!this.isItemsLoaded) this.loadDataByPaging();
                }
            }.bind(this);
            this.isSetedScroll = true;
            this.contentAreaNode.addEvent("scroll", this.scrollContainerFun )
NoSubject's avatar
NoSubject 已提交
466
        }
R
roo00 已提交
467
    },
U
unknown 已提交
468 469 470 471 472 473 474 475 476 477 478 479 480
    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.Viewer.Item(this, this.gridJson[i], null, i));
            }
            this.isItemsLoading = false;
            this.pageNumber ++;
            if( to == this.gridJson.length )this.isItemsLoaded = true;
        }
R
roo00 已提交
481
    },
U
unknown 已提交
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
    loadGroupData: function(){
        if (this.selectTitleCell){
            this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
            this.selectTitleCell.setStyle("cursor", "pointer");
            this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
        }

        if (this.gridJson.length){
            var i = 0;
            this.gridJson.each(function(data){
                this.items.push(new MWF.xApplication.query.Query.Viewer.ItemCategory(this, data, i));
                i += data.list.length;
            }.bind(this));

            if (this.json.isExpand=="yes") this.expandOrCollapseAll();
        }else{
            if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
U
unknown 已提交
499 500
        }
    },
U
unknown 已提交
501 502 503 504 505 506 507 508 509 510 511 512
    expandOrCollapseAll: function(){
        var icon = this.selectTitleCell.getElement("span");
        if (icon.get("html").indexOf("expand.png")===-1){
            this.items.each(function(item){
                item.collapse();
                icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>");
            }.bind(this));
        }else{
            this.items.each(function(item, i){
                window.setTimeout(function(){
                    item.expand();
                }.bind(this), 10*i+5);
R
roo00 已提交
513

U
unknown 已提交
514 515 516 517 518 519 520 521 522 523 524 525
                icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/down.png'/>");
            }.bind(this));
        }
    },
    getView: function(callback){
        this.getLookupAction(function(){
            if (this.json.application){
                this.getViewRes = this.lookupAction.getView(this.json.viewName, this.json.application, function(json){
                    this.viewJson = JSON.decode(json.data.data);
                    this.json = Object.merge(this.json, json.data);
                    if (callback) callback();
                }.bind(this));
R
roo00 已提交
526

U
unknown 已提交
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 565
                // this.lookupAction.invoke({"name": "getView","async": true, "parameter": {"view": this.json.viewName, "application": this.json.application},"success": function(json){
                //     this.viewJson = JSON.decode(json.data.data);
                //     this.json = Object.merge(this.json, json.data);
                //     //var viewData = JSON.decode(json.data.data);
                //     if (callback) callback();
                // }.bind(this)});
            }else{
                this.getViewRes = this.lookupAction.getViewById(this.json.viewId, function(json){
                    this.viewJson = JSON.decode(json.data.data);
                    this.json.application = json.data.query;
                    this.json = Object.merge(this.json, json.data);
                    if (callback) callback();
                }.bind(this));
            }
        }.bind(this));
    },
    getLookupAction: function(callback){
        if (!this.lookupAction){
            this.lookupAction = MWF.Actions.get("x_query_assemble_surface");
            if (callback) callback();
            // var _self = this;
            // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
            //     this.lookupAction = new MWF.xDesktop.Actions.RestActions("", this.options.actionRoot, "");
            //     this.lookupAction.getActions = function(actionCallback){
            //         this.actions = _self.options.actions;
            //         if (actionCallback) actionCallback();
            //     };
            //     if (callback) callback();
            // }.bind(this));
        }else{
            if (callback) callback();
        }
    },
    hide: function(){
        this.node.setStyle("display", "none");
    },
    reload: function(){
        this.node.setStyle("display", "block");
        if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
R
roo00 已提交
566

U
unknown 已提交
567 568 569 570 571
        this.filterItems.each(function(filter){
            filter.destroy();
        }.bind(this));
        this.filterItems = [];
        if (this.viewSearchInputNode) this.viewSearchInputNode.set("text", this.lp.searchKeywork);
R
roo00 已提交
572

U
unknown 已提交
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
        this.closeCustomSearch();

        this.viewAreaNode.empty();
        this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
    },
    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,
                            "logic": "or",
                            "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,
                                "logic": "or",
                                "comparison": "like"
                            };
                            filterData.push(d);
                        }
                    }
                }.bind(this));
R
roo00 已提交
615
            }
U
unknown 已提交
616 617 618 619 620 621 622 623 624 625
        }
        return (filterData.length) ? filterData : null;
    },
    getData: function(){
        if (this.selectedItems.length){
            var arr = [];
            this.selectedItems.each(function(item){
                arr.push(item.data);
            });
            return arr;
R
roo00 已提交
626
        }else{
U
unknown 已提交
627
            return [];
R
roo00 已提交
628 629
        }
    },
U
unknown 已提交
630
    _loadModuleEvents : function(){
631
        debugger;
U
unknown 已提交
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
        Object.each(this.viewJson.events, function(e, key){
            if (e.code){
                if (this.options.moduleEvents.indexOf(key)!==-1){
                    this.addEvent(key, function(event, target){
                        debugger;
                        return this.Macro.fire(e.code, target || this, event);
                    }.bind(this));
                }
            }
        }.bind(this));
    },
    _loadDomEvents: function(){
        Object.each(this.viewJson.events, function(e, key){
            if (e.code){
                if (this.options.moduleEvents.indexOf(key)===-1){
                    this.node.addEvent(key, function(event){
                        return this.Macro.fire(e.code, this, event);
                    }.bind(this));
                }
            }
        }.bind(this));
    },

    //搜索相关开始
    createSearchNode: function(){
        if (this.viewJson.customFilterList && this.viewJson.customFilterList.length){
            this.searchStatus = "default";
            this.loadFilterSearch();
        }else{
            this.loadSimpleSearch();
        }
    },
    loadSimpleSearch: function(){
        return false;
        this.searchSimpleNode = new Element("div", {"styles": this.css.searchSimpleNode}).inject(this.searchAreaNode);
        this.searchSimpleButtonNode = new Element("div", {"styles": this.css.searchSimpleButtonNode}).inject(this.searchSimpleNode);
        this.searchSimpleInputNode = new Element("input", {"type":"text", "styles": this.css.searchSimpleInputNode, "value": this.lp.searchKeywork}).inject(this.searchSimpleNode);
        this.searchSimpleButtonNode.addEvent("click", function(){
            this.search();
        }.bind(this));
        this.searchSimpleInputNode.addEvents({
            "focus": function(){
                if (this.searchSimpleInputNode.get("value")===this.lp.searchKeywork) this.searchSimpleInputNode.set("value", "");
U
unknown 已提交
675
            }.bind(this),
U
unknown 已提交
676 677 678
            "blur": function(){if (!this.searchSimpleInputNode.get("value")) this.searchSimpleInputNode.set("value", this.lp.searchKeywork);}.bind(this),
            "keydown": function(e){
                if (e.code===13) this.search();
679 680
            }.bind(this)
        });
NoSubject's avatar
NoSubject 已提交
681
    },
U
unknown 已提交
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
    search: function(){
        if (this.gridJson){
            var key = this.searchSimpleInputNode.get("value");
            var rows = this.viewTable.rows;
            var first = (this.json.isTitle!=="no") ? 1 : 0;
            for (var i = first; i<rows.length; i++){
                var tr = rows[i];
                if (!key || key==this.lp.searchKeywork){
                    if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
                }else{
                    if (tr.get("text").indexOf(key)!==-1){
                        if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
                    }else{
                        if (tr.getStyle("display")!=="none") tr.setStyle("display", "none");
                    }
                }
            }
            //if (this.viewPageAreaNode) this.viewPageAreaNode.hide();
        }
NoSubject's avatar
NoSubject 已提交
701
    },
U
unknown 已提交
702 703 704
    loadFilterSearch: function(){
        this.viewSearchCustomActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomActionNode, "text": this.lp.customSearch}).inject(this.searchAreaNode);
        this.viewSearchInputAreaNode = new Element("div", {"styles": this.css.viewFilterSearchInputAreaNode}).inject(this.searchAreaNode);
NoSubject's avatar
NoSubject 已提交
705

U
unknown 已提交
706 707 708
        this.viewSearchIconNode = new Element("div", {"styles": this.css.viewFilterSearchIconNode}).inject(this.viewSearchInputAreaNode);
        this.viewSearchInputBoxNode = new Element("div", {"styles": this.css.viewFilterSearchInputBoxNode}).inject(this.viewSearchInputAreaNode);
        this.viewSearchInputNode = new Element("input", {"styles": this.css.viewFilterSearchInputNode, "value": this.lp.searchKeywork}).inject(this.viewSearchInputBoxNode);
NoSubject's avatar
NoSubject 已提交
709

U
unknown 已提交
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755
        this.viewSearchInputNode.addEvents({
            "focus": function(){
                if (this.viewSearchInputNode.get("value")===this.lp.searchKeywork) this.viewSearchInputNode.set("value", "");
            }.bind(this),
            "blur": function(){if (!this.viewSearchInputNode.get("value")) this.viewSearchInputNode.set("value", this.lp.searchKeywork);}.bind(this),
            "keydown": function(e){
                if (e.code===13) this.searchView();
            }.bind(this)
        });
        this.viewSearchIconNode.addEvents({
            "click": function(){this.searchView();}.bind(this)
        });
        this.viewSearchCustomActionNode.addEvents({
            "click": function(){this.loadCustomSearch();}.bind(this)
        });
    },
    searchView: function(){
        if (this.viewJson.customFilterList) {
            var key = this.viewSearchInputNode.get("value");
            if (key && key !== this.lp.searchKeywork) {
                var filterData = this.json.filter ? this.json.filter : [];
                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": "like"
                            };
                            filterData.push(d);
                            this.filterItems.push({"data":d});
NoSubject's avatar
NoSubject 已提交
756 757
                        }
                    }
R
roo00 已提交
758
                }.bind(this));
U
unknown 已提交
759 760 761 762

                this.createViewNode({"filterList": filterData});
            }else{
                this.createViewNode();
R
roo00 已提交
763
            }
U
unknown 已提交
764
        }
R
roo00 已提交
765
    },
U
unknown 已提交
766 767 768 769 770 771
    searchCustomView: function(){
        if (this.filterItems.length){
            var filterData = this.json.filter ? this.json.filter.clone() : [];
            this.filterItems.each(function(filter){
                filterData.push(filter.data);
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
772

U
unknown 已提交
773 774 775
            this.createViewNode({"filterList": filterData});
        }else{
            this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
NoSubject's avatar
NoSubject 已提交
776
        }
U
unknown 已提交
777 778 779 780 781
    },
    loadCustomSearch: function(){
        this.viewSearchIconNode.setStyle("display", "none");
        this.viewSearchInputBoxNode.setStyle("display", "none");
        this.viewSearchCustomActionNode.setStyle("display", "none");
NoSubject's avatar
NoSubject 已提交
782

U
unknown 已提交
783 784 785
        if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
        var x = this.viewSearchInputAreaNode.getParent().getSize().x-2-20;
        this.css.viewFilterSearchInputAreaNode_custom.width = ""+x+"px";
U
unknown 已提交
786

U
unknown 已提交
787 788 789 790 791 792
        var x1 = this.viewSearchInputAreaNode.getSize().x-2;
        this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
        this.searchMorph.start(this.css.viewFilterSearchInputAreaNode_custom).chain(function(){
            this.searchStatus = "custom";
            this.css.viewFilterSearchInputAreaNode_custom.width = "auto";
            this.viewSearchInputAreaNode.setStyle("width", "auto");
U
unknown 已提交
793

U
unknown 已提交
794 795 796
            if (this.viewSearchCustomContentNode){
                this.viewSearchCustomCloseActionNode.setStyle("display", "block");
                this.viewSearchCustomContentNode.setStyle("display", "block");
NoSubject's avatar
NoSubject 已提交
797
            }else{
U
unknown 已提交
798
                this.loadCustomSearchContent();
NoSubject's avatar
NoSubject 已提交
799
            }
800

U
unknown 已提交
801
            this.setContentHeightFun();
NoSubject's avatar
NoSubject 已提交
802
        }.bind(this));
U
unknown 已提交
803
        this.searchCustomView();
NoSubject's avatar
NoSubject 已提交
804
    },
U
unknown 已提交
805 806 807
    loadCustomSearchContent: function(){
        this.viewSearchCustomCloseActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomCloseActionNode}).inject(this.viewSearchInputAreaNode);
        this.viewSearchCustomContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomContentNode}).inject(this.viewSearchInputAreaNode);
NoSubject's avatar
NoSubject 已提交
808

U
unknown 已提交
809 810 811 812 813 814
        this.viewSearchCustomPathContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomPathContentNode}).inject(this.viewSearchCustomContentNode);
        this.viewSearchCustomComparisonContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomComparisonContentNode}).inject(this.viewSearchCustomContentNode);
        this.viewSearchCustomValueContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomValueContentNode}).inject(this.viewSearchCustomContentNode);
        this.viewSearchCustomAddContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddContentNode}).inject(this.viewSearchCustomContentNode);
        this.viewSearchCustomAddIconNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddIconNode}).inject(this.viewSearchCustomAddContentNode);
        this.viewSearchCustomFilterContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomFilterContentNode}).inject(this.viewSearchCustomContentNode);
NoSubject's avatar
NoSubject 已提交
815

U
unknown 已提交
816
        this.loadViewSearchCustomList();
R
roo00 已提交
817

U
unknown 已提交
818 819 820 821 822 823
        this.viewSearchCustomCloseActionNode.addEvents({
            "click": function(){this.closeCustomSearch();}.bind(this)
        });
        this.viewSearchCustomAddIconNode.addEvents({
            "click": function(){this.viewSearchCustomAddToFilter();}.bind(this)
        });
R
roo00 已提交
824
    },
U
unknown 已提交
825 826 827 828 829 830 831 832 833
    loadViewSearchCustomList: function(){
        this.viewSearchCustomPathListNode = new Element("select", {
            "styles": this.css.viewFilterSearchCustomPathListNode,
            "multiple": true
        }).inject(this.viewSearchCustomPathContentNode);
        this.viewSearchCustomComparisonListNode = new Element("select", {
            "styles": this.css.viewFilterSearchCustomComparisonListNode,
            "multiple": true
        }).inject(this.viewSearchCustomComparisonContentNode);
R
roo00 已提交
834

U
unknown 已提交
835 836 837 838 839 840 841 842
        this.viewJson.customFilterList.each(function(entry){
            var option = new Element("option", {
                "style": this.css.viewFilterSearchOptionNode,
                "value": entry.path,
                "text": entry.title
            }).inject(this.viewSearchCustomPathListNode);
            option.store("entry", entry);
        }.bind(this));
R
roo00 已提交
843

U
unknown 已提交
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
        this.viewSearchCustomPathListNode.addEvent("change", function(){
            this.loadViewSearchCustomComparisonList();
        }.bind(this));
    },
    loadViewSearchCustomComparisonList: function(){
        var idx = this.viewSearchCustomPathListNode.selectedIndex;
        var option = this.viewSearchCustomPathListNode.options[idx];
        var entry = option.retrieve("entry");
        if (entry){
            switch (entry.formatType){
                case "numberValue":
                    this.loadComparisonSelect(this.lp.numberFilter);
                    this.loadViewSearchCustomValueNumberInput();
                    break;
                case "dateTimeValue":
                    this.loadComparisonSelect(this.lp.dateFilter);
                    this.loadViewSearchCustomValueDateTimeInput();
                    break;
                case "dateValue":
                    this.loadComparisonSelect(this.lp.dateFilter);
                    this.loadViewSearchCustomValueDateInput();
                    break;
                case "timeValue":
                    this.loadComparisonSelect(this.lp.dateFilter);
                    this.loadViewSearchCustomValueTimeInput();
                    break;
                case "booleanValue":
                    this.loadComparisonSelect(this.lp.booleanFilter);
                    this.loadViewSearchCustomValueBooleanInput();
                    break;
                default:
                    this.loadComparisonSelect(this.lp.textFilter);
                    this.loadViewSearchCustomValueTextInput();
R
roo00 已提交
877
            }
U
unknown 已提交
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
        }
    },
    loadViewSearchCustomValueNumberInput: function(){
        this.viewSearchCustomValueContentNode.empty();
        this.viewSearchCustomValueNode = new Element("input", {
            "styles": this.css.viewFilterSearchCustomValueNode,
            "type": "number"
        }).inject(this.viewSearchCustomValueContentNode);
    },
    loadViewSearchCustomValueDateTimeInput: function(){
        this.viewSearchCustomValueContentNode.empty();
        this.viewSearchCustomValueNode = new Element("input", {
            "styles": this.css.viewFilterSearchCustomValueNode,
            "type": "text",
            "readonly": true
        }).inject(this.viewSearchCustomValueContentNode);
        MWF.require("MWF.widget.Calendar", function(){
            this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
                "style": "xform",
                "isTime": true,
898
                "secondEnable" : true,
U
unknown 已提交
899 900 901
                "target": this.container,
                "format": "db"
            });
R
roo00 已提交
902 903
        }.bind(this));
    },
U
unknown 已提交
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
    loadViewSearchCustomValueDateInput: function(){
        this.viewSearchCustomValueContentNode.empty();
        this.viewSearchCustomValueNode = new Element("input", {
            "styles": this.css.viewFilterSearchCustomValueNode,
            "type": "text",
            "readonly": true
        }).inject(this.viewSearchCustomValueContentNode);
        MWF.require("MWF.widget.Calendar", function(){
            this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
                "style": "xform",
                "isTime": false,
                "target": this.container,
                "format": "%Y-%m-%d"
            });
        }.bind(this));
R
roo00 已提交
919
    },
U
unknown 已提交
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
    loadViewSearchCustomValueTimeInput: function(){
        this.viewSearchCustomValueContentNode.empty();
        this.viewSearchCustomValueNode = new Element("input", {
            "styles": this.css.viewFilterSearchCustomValueNode,
            "type": "text",
            "readonly": true
        }).inject(this.viewSearchCustomValueContentNode);
        MWF.require("MWF.widget.Calendar", function(){
            this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
                "style": "xform",
                "timeOnly": true,
                "target": this.container,
                "format": "%H:%M:%S"
            });
        }.bind(this));
R
roo00 已提交
935
    },
U
unknown 已提交
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
    loadViewSearchCustomValueBooleanInput: function(){
        this.viewSearchCustomValueContentNode.empty();
        this.viewSearchCustomValueNode = new Element("select", {
            "styles": this.css.viewFilterSearchCustomValueSelectNode,
            "multiple": true
        }).inject(this.viewSearchCustomValueContentNode);
        new Element("option", {"value": "true","text": this.lp.yes}).inject(this.viewSearchCustomValueNode);
        new Element("option", {"value": "false","text": this.lp.no}).inject(this.viewSearchCustomValueNode);
    },
    loadViewSearchCustomValueTextInput: function(){
        this.viewSearchCustomValueContentNode.empty();
        this.viewSearchCustomValueNode = new Element("textarea", {
            "styles": this.css.viewFilterSearchCustomValueNode
        }).inject(this.viewSearchCustomValueContentNode);
    },
    loadComparisonSelect:function(obj){
        this.viewSearchCustomComparisonListNode.empty();
        Object.each(obj, function(v, k){
            var option = new Element("option", {"value": k,"text": v}).inject(this.viewSearchCustomComparisonListNode);
R
roo00 已提交
955
        }.bind(this));
U
unknown 已提交
956 957 958 959 960
    },
    closeCustomSearch: function(){
        if (this.viewSearchCustomContentNode && this.viewSearchCustomContentNode.getStyle("display")==="block"){
            this.viewSearchCustomCloseActionNode.setStyle("display", "none");
            this.viewSearchCustomContentNode.setStyle("display", "none");
R
roo00 已提交
961

U
unknown 已提交
962 963 964
            var x = this.viewSearchInputAreaNode.getParent().getSize().x;
            x1 = x-2-10-90;
            this.css.viewFilterSearchInputAreaNode.width = ""+x1+"px";
R
roo00 已提交
965

U
unknown 已提交
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
            var x1 = this.viewSearchInputAreaNode.getSize().x-2;
            this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");

            if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
            this.searchMorph.start(this.css.viewFilterSearchInputAreaNode).chain(function(){
                this.searchStatus = "default";
                this.css.viewFilterSearchInputAreaNode.width = "auto";
                this.viewSearchInputAreaNode.setStyle("margin-right", "90px");

                this.viewSearchIconNode.setStyle("display", "block");
                this.viewSearchInputBoxNode.setStyle("display", "block");
                this.viewSearchCustomActionNode.setStyle("display", "block");

                this.setContentHeightFun();
            }.bind(this));
            this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
        }
R
roo00 已提交
983
    },
U
unknown 已提交
984 985 986 987 988 989
    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;
R
roo00 已提交
990
        }
U
unknown 已提交
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
        if (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 = "";

            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");
R
roo00 已提交
1016
                    }
U
unknown 已提交
1017 1018 1019
                    break;
                default:
                    value = this.viewSearchCustomValueNode.get("value");
R
roo00 已提交
1020
            }
U
unknown 已提交
1021 1022 1023
            if (value===""){
                MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
                return false;
U
unknown 已提交
1024
            }
U
unknown 已提交
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037

            this.filterItems.push(new MWF.xApplication.query.Query.Viewer.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 已提交
1038
    },
U
unknown 已提交
1039 1040 1041 1042
    searchViewRemoveFilter: function(filter){
        this.filterItems.erase(filter);
        filter.destroy();
        this.searchCustomView()
1043
    },
U
unknown 已提交
1044
    //搜索相关结束
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066

    //api 使用 开始
    getParentEnvironment : function(){
        return this.parentMacro ? this.parentMacro.environment : null;
    },
    getViewInfor : function(){
        return this.json;
    },
    getPageInfor : function(){
        return {
            pages : this.pages,
            perPageCount : this.options.perPageCount,
            currentPageNumber : this.currentPage
        };
    },
    getPageData : function () {
        return this.gridJson;
    },
    toPage : function( pageNumber, callback ){
        this.currentPage = pageNumber;
        this.loadCurrentPageData( callback );
    },
U
unknown 已提交
1067 1068 1069
    getSelectedData : function(){
        return this.getData();
    },
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
    selectAll : function(){
        var flag = this.json.select || this.viewJson.select ||  "none";
        if ( flag==="multi"){
            this.items.each( function (item) {
                if( item.clazzType === "item" ){
                    item.selected();
                }else{
                    item.expand();
                    if( item.items ){
                        item.items.each( function (it) {
                            it.selected();
                        })
                    }
                }
            })
        }
    },
    unSelectAll : function(){
        var flag = this.json.select || this.viewJson.select ||  "none";
        if ( flag==="multi"){
            this.items.each( function (item) {
                if( item.clazzType === "item" ){
                    item.unSelected();
                }else{
                    if(item.items){
                        item.items.each( function (it) {
                            it.unSelected();
                        })
                    }
                }
            })
        }
    },
    setFilter : function( filter ){
        if( !filter )filter = [];
        if( typeOf( filter ) === "object" )filter = [ filter ];
        this.json.filter = filter;
        this.createViewNode({"filterList": this.json.filter  ? this.json.filter.clone() : null});
    },
    switchView : function( json ){
        debugger;
        // json = {
        //     "application": application,
        //     "viewName": viewName,
        //     "isTitle": "yes",
        //     "select": "none",
        //     "titleStyles": titleStyles,
        //     "itemStyles": itemStyles,
        //     "isExpand": "no",
        //     "filter": filter
        // }
        this.node.setStyle("display", "block");
        if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");

        this.searchMorph = null;
        this.viewSearchCustomContentNode = null;

        var newJson = Object.merge( Object.clone(this.originalJson), json );
        this.container.empty();
        this.initialize( this.container, newJson, Object.clone(this.options), this.app, this.parentMacro);
    },
    confirm: function (type, e, title, text, width, height, ok, cancel, callback, mask, style) {
        this.app.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style)
    },
    alert: function (type, title, text, width, height) {
        this.app.alert(type, "center", title, text, width, height);
    },
    notice: function (content, type, target, where, offset, option) {
        this.app.notice(content, type, target, where, offset, option)
R
roo00 已提交
1139
    }
1140
    //api 使用 结束
R
roo00 已提交
1141 1142 1143 1144 1145 1146 1147 1148 1149
});

MWF.xApplication.query.Query.Viewer.Item = new Class({
    initialize: function(view, data, prev, i){
        this.view = view;
        this.data = data;
        this.css = this.view.css;
        this.isSelected = false;
        this.prev = prev;
R
roo00 已提交
1150
        this.idx = i;
1151
        this.clazzType = "item";
R
roo00 已提交
1152 1153 1154
        this.load();
    },
    load: function(){
1155
        this.view.fireEvent("queryLoadItemRow", [null, this]);
U
unknown 已提交
1156

R
roo00 已提交
1157 1158 1159 1160 1161 1162 1163 1164
        this.node = new Element("tr", {"styles": 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"){
U
unknown 已提交
1165 1166 1167
        this.selectTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
        this.selectTd.setStyles({"cursor": "pointer"});
        if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
R
roo00 已提交
1168 1169
        //}

R
roo00 已提交
1170 1171 1172 1173 1174 1175 1176 1177
        //序号
        if (this.view.viewJson.isSequence==="yes"){
            this.sequenceTd = new Element("td", {"styles": this.css.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);
        }

R
roo00 已提交
1178 1179 1180 1181
        Object.each(this.view.entries, function(c, k){
            var cell = this.data.data[k];
            if (cell === undefined) cell = "";
            //if (cell){
U
unknown 已提交
1182 1183 1184 1185 1186 1187 1188 1189 1190
            if (this.view.hideColumns.indexOf(k)===-1){
                var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
                if (k!== this.view.viewJson.group.column){
                    //var v = (this.view.entries[k].code) ? MWF.Macro.exec(this.view.entries[k].code, {"value": cell, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : cell;
                    var v = cell;
                    if (c.isHtml){
                        td.set("html", v);
                    }else{
                        td.set("text", v);
U
unknown 已提交
1191
                    }
R
roo00 已提交
1192
                }
U
unknown 已提交
1193 1194 1195 1196 1197
                if (this.view.openColumns.indexOf(k)!==-1){
                    this.setOpenWork(td, c)
                }
                if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
            }
R
roo00 已提交
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
            //}
        }.bind(this));

        // Object.each(this.data.data, function(cell, k){
        //     if (this.view.hideColumns.indexOf(k)===-1){
        //         var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
        //         if (k!== this.view.viewJson.group.column){
        //             var v = (this.view.entries[k].code) ? MWF.Macro.exec(this.view.entries[k].code, {"value": cell, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : cell;
        //             td.set("text", v);
        //         }
        //         if (this.view.openColumns.indexOf(k)!==-1){
        //             this.setOpenWork(td)
        //         }
        //         if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
        //     }
        // }.bind(this));

        this.setEvent();
U
unknown 已提交
1216

1217
        this.view.fireEvent("postLoadItemRow", [null, this]);
R
roo00 已提交
1218
    },
R
roo00 已提交
1219
    setOpenWork: function(td, column){
R
roo00 已提交
1220
        td.setStyle("cursor", "pointer");
R
roo00 已提交
1221
        if( column.clickCode ){
U
unknown 已提交
1222 1223 1224 1225 1226 1227
            // 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);
            // }
R
roo00 已提交
1228
            td.addEvent("click", function( ev ){
U
unknown 已提交
1229 1230 1231
                var result = this.view.Macro.fire(column.clickCode, this, ev);
                ev.stopPropagation();
                return result;
R
roo00 已提交
1232
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
1233
        }else{
R
roo00 已提交
1234
            if (this.view.json.type==="cms"){
U
unknown 已提交
1235 1236 1237 1238
                td.addEvent("click", function(ev){
                    this.openCms(ev)
                    ev.stopPropagation();
                }.bind(this));
R
roo00 已提交
1239
            }else{
U
unknown 已提交
1240 1241 1242 1243
                td.addEvent("click", function(ev){
                    this.openWorkAndCompleted(ev)
                    ev.stopPropagation();
                }.bind(this));
R
roo00 已提交
1244
            }
NoSubject's avatar
NoSubject 已提交
1245 1246 1247 1248 1249
        }

    },
    openCms: function(e){
        var options = {"documentId": this.data.bundle};
U
unknown 已提交
1250
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
NoSubject's avatar
NoSubject 已提交
1251
        layout.desktop.openApplication(e, "cms.Document", options);
R
roo00 已提交
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
    },
    openWorkAndCompleted: function(e){
        MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(this.data.bundle, function(json){
            var workCompletedCount = json.data.workCompletedList.length;
            var workCount = json.data.workList.length;
            var count = workCount+workCompletedCount;
            if (count===1){
                if (workCompletedCount) {
                    this.openWorkCompleted(json.data.workCompletedList[0].id, e);
                }else{
                    this.openWork(json.data.workList[0].id, e);
                }
            }else if (count>1){
                var worksAreaNode = this.createWorksArea();
                json.data.workCompletedList.each(function(work){
                    this.createWorkCompletedNode(work, worksAreaNode);
                }.bind(this));
                json.data.workList.each(function(work){
                    this.createWorkNode(work, worksAreaNode);
                }.bind(this));
                this.showWorksArea(worksAreaNode, e);
            }else{

            }
        }.bind(this));
    },
    createWorkNode: function(work, worksAreaNode){
        var worksAreaContentNode = worksAreaNode.getLast();
        var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
        var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);

        actionNode.store("workId", work.id);
        actionNode.addEvent("click", function(e){
            this.openWork(e.target.retrieve("workId"), e);
            this.mask.hide();
            worksAreaNode.destroy();
        }.bind(this));

        var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);

        var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
        var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
        new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
        new Element("div", {"styles": this.css.workAreaContentTextNode, "text": work.activityName}).inject(contentNode);

        var taskUsers = [];
        MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
NoSubject's avatar
NoSubject 已提交
1299
            json.data.each(function(task){
R
roo00 已提交
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
                taskUsers.push(MWF.name.cn(task.person));
            }.bind(this));
            new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.taskPeople+": "}).inject(contentNode);
            new Element("div", {"styles": this.css.workAreaContentTextNode, "text": taskUsers.join(", ")}).inject(contentNode);
        }.bind(this));
    },
    createWorkCompletedNode: function(work, worksAreaNode){
        var worksAreaContentNode = worksAreaNode.getLast();

        var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
        var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);

        actionNode.store("workId", work.id);
        actionNode.addEvent("click", function(e){
            this.mask.hide();
NoSubject's avatar
NoSubject 已提交
1315
            var id = e.target.retrieve("workId");
R
roo00 已提交
1316
            worksAreaNode.destroy();
NoSubject's avatar
NoSubject 已提交
1317
            this.openWorkCompleted(id, e);
R
roo00 已提交
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
        }.bind(this));

        var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);

        var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
        var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);

        new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
        new Element("div", {"styles": this.css.workAreaContentTextNode, "text": this.view.lp.processCompleted}).inject(contentNode);
    },
    createWorksArea: function(){
        var worksAreaNode = new Element("div", {"styles": this.css.worksAreaNode});
        var worksAreaTitleNode = new Element("div", {"styles": this.css.worksAreaTitleNode}).inject(worksAreaNode);
        var worksAreaTitleCloseNode = new Element("div", {"styles": this.css.worksAreaTitleCloseNode}).inject(worksAreaTitleNode);
        worksAreaTitleCloseNode.addEvent("click", function(e){
            this.mask.hide();
            e.target.getParent().getParent().destroy();
        }.bind(this));
        var worksAreaContentNode = new Element("div", {"styles": this.css.worksAreaContentNode}).inject(worksAreaNode);

        return worksAreaNode;
    },
    showWorksArea: function(node, e){
R
roo00 已提交
1341
        MWF.require("MWF.widget.Mask", null, false);
R
roo00 已提交
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
        this.mask = new MWF.widget.Mask({"style": "desktop", "loading": false});
        this.mask.loadNode(this.view.container);

        node.inject(this.view.node);
        this.setWorksAreaPosition(node, e.target);
    },
    setWorksAreaPosition: function(node, td){
        var p = td.getPosition(this.view.container);
        var containerS = this.view.container.getSize();
        var containerP = this.view.container.getPosition(this.view.container.getOffsetParent());
        var s = node.getSize();
        var offX = p.x+s.x-containerS.x;
        offX = (offX>0) ? offX+20 : 0;
        var offY = p.y+s.y-containerS.y;
        offY = (offY>0) ? offY+5 : 0;

        node.position({
            "relativeTo": td,
            "position": "lefttop",
            "edge": "lefttop",
            "offset": {
                "x": 0-offX,
                "y": 0-offY
            }
        });
    },
    openWork: function(id, e){
        var options = {"workId": id};
U
unknown 已提交
1370
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
R
roo00 已提交
1371 1372 1373 1374
        layout.desktop.openApplication(e, "process.Work", options);
    },
    openWorkCompleted: function(id, e){
        var options = {"workCompletedId": id};
U
unknown 已提交
1375
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
R
roo00 已提交
1376 1377 1378 1379
        layout.desktop.openApplication(e, "process.Work", options);
    },

    setEvent: function(){
U
unknown 已提交
1380 1381
        var flag = this.view.json.select || this.view.viewJson.select ||  "none";
        if ( flag ==="single" || flag==="multi"){
R
roo00 已提交
1382 1383 1384 1385
            this.node.addEvents({
                "mouseover": function(){
                    if (!this.isSelected){
                        var iconName = "checkbox";
U
unknown 已提交
1386
                        if (flag==="single") iconName = "radiobox";
R
roo00 已提交
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
                        this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/"+iconName+".png) center center no-repeat"});
                    }
                }.bind(this),
                "mouseout": function(){
                    if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
                }.bind(this),
                "click": function(){this.select();}.bind(this)
            });
        }
    },

    select: function(){
U
unknown 已提交
1399
        var flag = this.view.json.select || this.view.viewJson.select ||  "none";
R
roo00 已提交
1400
        if (this.isSelected){
U
unknown 已提交
1401
            if (flag==="single"){
R
roo00 已提交
1402 1403 1404 1405 1406
                this.unSelectedSingle();
            }else{
                this.unSelected();
            }
        }else{
U
unknown 已提交
1407
            if (flag==="single"){
R
roo00 已提交
1408 1409 1410 1411 1412
                this.selectedSingle();
            }else{
                this.selected();
            }
        }
U
unknown 已提交
1413
        this.view.fireEvent("select"); //options 传入的事件
R
roo00 已提交
1414 1415 1416 1417 1418 1419 1420
    },

    selected: function(){
        this.view.selectedItems.push(this);
        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;
U
unknown 已提交
1421
        this.view.fireEvent("selectRow", [this]);
R
roo00 已提交
1422 1423 1424 1425 1426 1427
    },
    unSelected: function(){
        this.view.selectedItems.erase(this);
        this.selectTd.setStyles({"background": "transparent"});
        this.node.setStyles(this.css.viewContentTrNode);
        this.isSelected = false;
U
unknown 已提交
1428
        this.view.fireEvent("unselectRow", [this]);
R
roo00 已提交
1429 1430 1431 1432 1433 1434 1435 1436
    },
    selectedSingle: function(){
        if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
        this.view.selectedItems = [this];
        this.view.currentSelectedItem = this;
        this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/radiobox_checked.png) center center no-repeat"});
        this.node.setStyles(this.css.viewContentTrNode_selected);
        this.isSelected = true;
U
unknown 已提交
1437
        this.view.fireEvent("selectRow", [this]);
R
roo00 已提交
1438 1439 1440 1441 1442 1443 1444
    },
    unSelectedSingle: function(){
        this.view.selectedItems = [];
        this.view.currentSelectedItem = null;
        this.selectTd.setStyles({"background": "transparent"});
        this.node.setStyles(this.css.viewContentTrNode);
        this.isSelected = false;
U
unknown 已提交
1445
        this.view.fireEvent("unselectRow", [this]);
R
roo00 已提交
1446 1447 1448 1449
    }
});

MWF.xApplication.query.Query.Viewer.ItemCategory = new Class({
R
roo00 已提交
1450
    initialize: function(view, data, i){
R
roo00 已提交
1451 1452 1453 1454 1455
        this.view = view;
        this.data = data;
        this.css = this.view.css;
        this.items = [];
        this.loadChild = false;
R
roo00 已提交
1456
        this.idx = i;
1457
        this.clazzType = "category";
R
roo00 已提交
1458 1459 1460
        this.load();
    },
    load: function(){
1461
        this.view.fireEvent("queryLoadCategoryRow", [null, this]);
U
unknown 已提交
1462

R
roo00 已提交
1463 1464
        this.node = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.view.viewTable);
        //if (this.view.json.select==="single" || this.view.json.select==="multi"){
U
unknown 已提交
1465 1466
        this.selectTd = new Element("td", {"styles": this.css.viewContentCategoryTdNode}).inject(this.node);
        if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
R
roo00 已提交
1467 1468 1469
        //}
        this.categoryTd = new Element("td", {
            "styles": this.css.viewContentCategoryTdNode,
R
roo00 已提交
1470
            "colspan": this.view.viewJson.selectList.length+1
R
roo00 已提交
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
        }).inject(this.node);

        this.groupColumn = null;
        for (var c = 0; c<this.view.viewJson.selectList.length; c++){
            if (this.view.viewJson.selectList[c].column === this.view.viewJson.group.column){
                this.groupColumn = this.view.viewJson.selectList[c];
                break;
            }
        }
        if (this.groupColumn){
            //var text = (this.groupColumn.code) ? MWF.Macro.exec(this.groupColumn.code, {"value": this.data.group, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : this.data.group;
            var text = this.data.group;
        }else{
            var text = this.data.group;
        }

        this.categoryTd.set("html", "<span style='font-family: Webdings'><img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/></span> "+text);
        if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);

        this.setEvent();
U
unknown 已提交
1491

1492
        this.view.fireEvent("postLoadCategoryRow", [null, this]);
R
roo00 已提交
1493 1494 1495
    },
    setEvent: function(){
        //if (this.selectTd){
U
unknown 已提交
1496 1497 1498
        this.node.addEvents({
            "click": function(){this.expandOrCollapse();}.bind(this)
        });
R
roo00 已提交
1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521
        //}
    },
    expandOrCollapse: function(){
        var t = this.node.getElement("span").get("html");
        if (t.indexOf("expand.png")===-1){
            this.collapse();
        }else{
            this.expand();
        }
    },
    collapse: function(){
        this.items.each(function(item){
            item.node.setStyle("display", "none");
        }.bind(this));
        this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/>");
    },
    expand: function(){
        this.items.each(function(item){
            item.node.setStyle("display", "table-row");
        }.bind(this));
        this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
        if (!this.loadChild){
            //window.setTimeout(function(){
R
roo00 已提交
1522 1523 1524 1525
            this.data.list.each(function(line, i){
                var s = this.idx+i;
                this.lastItem = new MWF.xApplication.query.Query.Viewer.Item(this.view, line, (this.lastItem || this), s);
                this.items.push(this.lastItem);
R
roo00 已提交
1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598
            }.bind(this));
            this.loadChild = true;
            //}.bind(this), 10);
        }
    }
});

MWF.xApplication.query.Query.Viewer.Filter = new Class({
    initialize: function(viewer, data, node){
        this.viewer = viewer;
        this.data = data;
        this.css = this.viewer.css;
        this.content = node;
        this.load();
    },
    load: function(){
        this.node = new Element("div", {"styles": this.css.viewSearchFilterNode}).inject(this.content);
        if (this.viewer.filterItems.length){
            this.logicNode = new Element("div", {"styles": this.css.viewSearchFilterSelectAreaNode}).inject(this.node);
            this.logicSelectNode = new Element("div", {
                "styles": this.css.viewSearchFilterSelectNode,
                "text": this.viewer.lp.and,
                "value": "and"
            }).inject(this.logicNode);

            this.logicSelectButtonNode = new Element("div", {"styles": this.css.viewSearchFilterSelectButtonNode}).inject(this.logicNode);
            this.logicNode.addEvents({
                "click": function(){
                    var v = this.logicSelectNode.get("value");
                    if (v==="and"){
                        this.logicSelectButtonNode.setStyle("float", "left");
                        this.logicSelectNode.setStyle("float", "right");
                        this.logicSelectNode.set({
                            "text": this.viewer.lp.or,
                            "value": "or"
                        });
                        this.data.logic = "or";
                    }else{
                        this.logicSelectButtonNode.setStyle("float", "right");
                        this.logicSelectNode.setStyle("float", "left");
                        this.logicSelectNode.set({
                            "text": this.viewer.lp.and,
                            "value": "and"
                        });
                        this.data.logic = "and";
                    }
                    this.viewer.searchCustomView();
                }.bind(this)
            });
        }
        this.titleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.title}).inject(this.node);
        this.comparisonTitleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.comparisonTitle}).inject(this.node);
        this.valueNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": "\""+this.data.value+"\""}).inject(this.node);
        this.deleteNode = new Element("div", {"styles": this.css.viewSearchFilterDeleteNode}).inject(this.node);

        this.node.addEvents({
            "mouseover": function(){
                this.node.setStyles(this.css.viewSearchFilterNode_over);
                this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode_over);
            }.bind(this),
            "mouseout": function(){
                this.node.setStyles(this.css.viewSearchFilterNode);
                this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode);
            }.bind(this)
        });
        this.deleteNode.addEvent("click", function(){
            this.viewer.searchViewRemoveFilter(this);
        }.bind(this));
    },
    destroy: function(){
        this.node.destroy();
        MWF.release(this);
    }
NoSubject's avatar
NoSubject 已提交
1599
});
U
unknown 已提交
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776

MWF.xApplication.query.Query.Viewer.Actionbar = new Class({
    Implements: [Events],
    options: {
        "style" : "default",
        "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad"]
    },
    initialize: function(node, json, form, options){

        this.node = $(node);
        this.node.store("module", this);
        this.json = json;
        this.form = form;
        this.view = form;
    },
    hide: function(){
        var dsp = this.node.getStyle("display");
        if (dsp!=="none") this.node.store("mwf_display", dsp);
        this.node.setStyle("display", "none");
    },
    show: function(){
        var dsp = this.node.retrieve("mwf_display", dsp);
        this.node.setStyle("display", dsp);
    },
    load: function(){

        this._loadModuleEvents();
        if (this.fireEvent("queryLoad")){
            //this._queryLoaded();
            this._loadUserInterface();
            this._loadStyles();
            this._loadDomEvents();
            //this._loadEvents();

            //this._afterLoaded();
            this.fireEvent("postLoad");
            this.fireEvent("load");
        }
    },

    _loadStyles: function(){
        if (this.json.styles) Object.each(this.json.styles, function(value, key){
            if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
                var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
                var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
                var host3 = MWF.Actions.getHost("x_cms_assemble_control");
                if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
                    value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
                }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
                    value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
                }
                if (value.indexOf("/x_portal_assemble_surface")!==-1){
                    value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
                }else if (value.indexOf("x_portal_assemble_surface")!==-1){
                    value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
                }
                if (value.indexOf("/x_cms_assemble_control")!==-1){
                    value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
                }else if (value.indexOf("x_cms_assemble_control")!==-1){
                    value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
                }
            }
            this.node.setStyle(key, value);
        }.bind(this));

        // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
        //     var host = MWF.Actions.getHost(root);
        //     return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
        // }
        //if (this.json.styles) this.node.setStyles(this.json.styles);
    },
    _loadModuleEvents : function(){
        Object.each(this.json.events, function(e, key){
            if (e.code){
                if (this.options.moduleEvents.indexOf(key)!==-1){
                    this.addEvent(key, function(event){
                        return this.form.Macro.fire(e.code, this, event);
                    }.bind(this));
                }
            }
        }.bind(this));
    },
    _loadDomEvents: function(){
        Object.each(this.json.events, function(e, key){
            if (e.code){
                if (this.options.moduleEvents.indexOf(key)===-1){
                    this.node.addEvent(key, function(event){
                        return this.form.Macro.fire(e.code, this, event);
                    }.bind(this));
                }
            }
        }.bind(this));
    },
    _loadEvents: function(){
        Object.each(this.json.events, function(e, key){
            if (e.code){
                if (this.options.moduleEvents.indexOf(key)!==-1){
                    this.addEvent(key, function(event){
                        return this.form.Macro.fire(e.code, this, event);
                    }.bind(this));
                }else{
                    this.node.addEvent(key, function(event){
                        return this.form.Macro.fire(e.code, this, event);
                    }.bind(this));
                }
            }
        }.bind(this));
    },
    addModuleEvent: function(key, fun){
        if (this.options.moduleEvents.indexOf(key)!==-1){
            this.addEvent(key, function(event){
                return (fun) ? fun(this, event) : null;
            }.bind(this));
        }else{
            this.node.addEvent(key, function(event){
                return (fun) ? fun(this, event) : null;
            }.bind(this));
        }
    },
    _loadUserInterface: function(){
        // if (this.form.json.mode == "Mobile"){
        //     this.node.empty();
        // }else if (COMMON.Browser.Platform.isMobile){
        //     this.node.empty();
        // }else{
        this.toolbarNode = this.node.getFirst("div");
        if( !this.toolbarNode ){
            this.toolbarNode = new Element("div").inject( this.node );
        }
        this.toolbarNode.empty();

        MWF.require("MWF.widget.Toolbar", function(){
            this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
                "style": this.json.style,
                "onPostLoad" : function(){
                    this.fireEvent("afterLoad");
                }.bind(this)
            }, this);
            if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
            //alert(this.readonly)

            if (this.json.hideSystemTools){
                this.setCustomToolbars(this.json.tools, this.toolbarNode);
                this.toolbarWidget.load();
            }else{
                if (this.json.defaultTools){
                    this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
                    this.setCustomToolbars(this.json.tools, this.toolbarNode);
                    this.toolbarWidget.load();
                }else{
                    MWF.getJSON(this.form.path+"toolbars.json", function(json){
                        this.setToolbars(json, this.toolbarNode, this.readonly, true);
                        this.setCustomToolbars(this.json.tools, this.toolbarNode);
                        this.toolbarWidget.load();
                    }.bind(this), null);
                }
            }

        }.bind(this));
        // }
    },

    setCustomToolbars: function(tools, node){
        var path = "/x_component_process_FormDesigner/Module/Actionbar/";
        var iconPath = "";
        if( this.json.customIconStyle ){
            iconPath = this.json.customIconStyle+"/";
        }
        tools.each(function(tool){
            var flag = true;
            if (this.readonly){
                flag = tool.readShow;
            }else{
                flag = tool.editShow;
            }
            if (flag){
                flag = true;
U
unknown 已提交
1777 1778 1779
                // if (tool.control){
                //     flag = this.form.businessData.control[tool.control]
                // }
U
unknown 已提交
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814
                if (tool.condition){
                    var hideFlag = this.form.Macro.exec(tool.condition, this);
                    flag = !hideFlag;
                }
                if (flag){
                    var actionNode = new Element("div", {
                        "id": tool.id,
                        "MWFnodetype": tool.type,
                        "MWFButtonImage": path+""+this.form.options.style+"/custom/"+iconPath+tool.img,
                        "title": tool.title,
                        "MWFButtonAction": "runCustomAction",
                        "MWFButtonText": tool.text
                    }).inject(node);
                    if( this.json.customIconOverStyle ){
                        actionNode.set("MWFButtonImageOver" , path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
                    }
                    if( tool.properties ){
                        actionNode.set(tool.properties);
                    }
                    if (tool.actionScript){
                        actionNode.store("script", tool.actionScript);
                    }
                    if (tool.sub){
                        var subNode = node.getLast();
                        this.setCustomToolbars(tool.sub, subNode);
                    }
                }
            }
        }.bind(this));
    },

    setToolbarItem: function(tool, node, readonly, noCondition){
        //var path = "/x_component_process_FormDesigner/Module/Actionbar/";
        var path = "/x_component_query_ViewDesigner/$View/";
        var flag = true;
U
unknown 已提交
1815 1816 1817
        // if (tool.control){
        //     flag = this.form.businessData.control[tool.control]
        // }
U
unknown 已提交
1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
        if (!noCondition) if (tool.condition){
            var hideFlag = this.form.Macro.exec(tool.condition, this);
            flag = flag && (!hideFlag);
        }
        if (readonly) if (!tool.read) flag = false;
        if (flag){
            var actionNode = new Element("div", {
                "id": tool.id,
                "MWFnodetype": tool.type,
                //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
                //"MWFButtonImage": path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
                "MWFButtonImage": path+this.options.style+"/actionbar/"+tool.img,
                "title": tool.title,
                "MWFButtonAction": tool.action,
                "MWFButtonText": tool.text
            }).inject(node);
            if( this.json.iconOverStyle ){
                actionNode.set("MWFButtonImageOver" , path+""+this.options.style+"/actionbar/"+this.json.iconOverStyle+"/"+tool.img );
                //actionNode.set("MWFButtonImageOver" , path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+tool.img );
            }
            if( tool.properties ){
                actionNode.set(tool.properties);
            }
            if (tool.sub){
                var subNode = node.getLast();
                this.setToolbars(tool.sub, subNode, readonly, noCondition);
            }
        }
    },
    setToolbars: function(tools, node, readonly, noCondition){
        tools.each(function(tool){
            this.setToolbarItem(tool, node, readonly, noCondition);
        }.bind(this));
    },
    runCustomAction: function(bt){
        var script = bt.node.retrieve("script");
        this.form.Macro.exec(script, this);
    },
    exportView : function(){
        this.form.exportView();
    },
    deleteWork: function(){
        this.form.deleteWork();
    }
});