Viewer.js 100.7 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
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",
U
unknown 已提交
12
        "skin" : null,
13
        "skin" : null,
R
roo00 已提交
14 15 16 17
        "resizeNode": true,
        "paging" : "scroll",
        "perPageCount" : 50,
        "isload": "true",
U
unknown 已提交
18
        "export": false,
19 20
        "moduleEvents": ["queryLoad", "postLoad", "postLoadPageData", "postLoadPage", "selectRow", "unselectRow",
            "queryLoadItemRow", "postLoadItemRow", "queryLoadCategoryRow", "postLoadCategoryRow"]
U
unknown 已提交
21

R
roo00 已提交
22 23 24 25 26 27 28
        // "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 已提交
29
    initialize: function(container, json, options, app, parentMacro){
U
unknown 已提交
30 31 32 33 34
        //本类有三种事件,
        //一种是通过 options 传进来的事件,包括 loadView、openDocument、select
        //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
        //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件

R
roo00 已提交
35 36
        this.setOptions(options);

37 38
        this.path = "../x_component_query_Query/$Viewer/";
        this.cssPath = "../x_component_query_Query/$Viewer/"+this.options.style+"/css.wcss";
R
roo00 已提交
39 40 41
        this._loadCss();
        this.lp = MWF.xApplication.query.Query.LP;

U
unknown 已提交
42 43
        this.app = app;

R
roo00 已提交
44 45 46
        this.container = $(container);
        this.json = json;

U
unknown 已提交
47 48
        this.parentMacro = parentMacro;

49 50
        this.originalJson = Object.clone(json);

R
roo00 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
        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 已提交
68

R
roo00 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    },
    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 已提交
88 89 90 91 92 93 94
        this.loadMacro( function () {
            this._loadModuleEvents();
            if (this.fireEvent("queryLoad")){
                this._loadUserInterface();
                //this._loadStyles();
                this._loadDomEvents();
            }
95
        }.bind(this))
U
unknown 已提交
96 97
    },
    _loadUserInterface : function(){
R
roo00 已提交
98
        this.loadLayout();
U
unknown 已提交
99
        this.createActionbarNode();
R
roo00 已提交
100 101 102 103 104 105 106 107 108 109 110
        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);
111
        this.actionbarAreaNode =  new Element("div.actionbarAreaNode", {"styles": this.css.actionbarAreaNode}).inject(this.node);
U
unknown 已提交
112
        //if (this.options.export) this.exportAreaNode = new Element("div", {"styles": this.css.exportAreaNode}).inject(this.node);
R
roo00 已提交
113 114
        this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.node);
        this.viewAreaNode = new Element("div", {"styles": this.css.viewAreaNode}).inject(this.node);
115 116
        // this.viewPageNode = new Element("div", {"styles": this.css.viewPageNode}).inject(this.node);
        this.viewPageAreaNode = new Element("div", {"styles": this.css.viewPageAreaNode}).inject(this.node);
R
roo00 已提交
117
    },
U
unknown 已提交
118
    loadMacro: function (callback) {
U
unknown 已提交
119 120
        MWF.require("MWF.xScript.Macro", function () {
            this.Macro = new MWF.Macro.ViewContext(this);
U
unknown 已提交
121
            if (callback) callback();
U
unknown 已提交
122
        }.bind(this));
U
unknown 已提交
123
    },
R
roo00 已提交
124 125 126
    createExportNode: function(){
        if (this.options.export){
            MWF.require("MWF.widget.Toolbar", function(){
U
unknown 已提交
127
                this.toolbar = new MWF.widget.Toolbar(this.actionbarAreaNode, {"style": "simple"}, this); //this.exportAreaNode
R
roo00 已提交
128 129 130 131 132 133 134
                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 已提交
135
                }).inject(this.actionbarAreaNode); //this.exportAreaNode
R
roo00 已提交
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159

                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 已提交
160 161 162 163 164 165 166 167 168 169 170
    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 已提交
171
        }
172
        var pageSize = this.viewPageAreaNode.getComputedSize();
U
unknown 已提交
173 174
        h = h-pageSize.totalHeight;
        this.viewAreaNode.setStyle("height", ""+h+"px");
R
roo00 已提交
175
    },
U
unknown 已提交
176 177 178 179 180 181 182
    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 已提交
183
    },
U
unknown 已提交
184 185
    createActionbarNode : function(){
        this.actionbarAreaNode.empty();
U
unknown 已提交
186
        if( typeOf(this.json.showActionbar) === "boolean" && this.json.showActionbar !== true )return;
U
unknown 已提交
187 188 189 190 191 192
        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 已提交
193 194
        }
    },
U
unknown 已提交
195 196
    createViewNode: function(data){
        this.viewAreaNode.empty();
U
unknown 已提交
197

198 199
        this.selectedItems = [];

U
unknown 已提交
200 201 202 203 204
        var viewStyles = this.viewJson.viewStyles;

        this.contentAreaNode = new Element("div", {"styles":
                (viewStyles && viewStyles["container"]) ? viewStyles["container"] : this.css.contentAreaNode
        }).inject(this.viewAreaNode);
R
roo00 已提交
205

U
unknown 已提交
206 207 208 209 210 211
        this.viewTable = new Element("table", {
            "styles": this.css.viewTitleTableNode,
            "border": "0px",
            "cellPadding": "0",
            "cellSpacing": "0"
        }).inject(this.contentAreaNode);
U
unknown 已提交
212 213 214 215 216
        if( viewStyles ){
            if( viewStyles["tableProperties"] )this.viewTable.set(viewStyles["tableProperties"]);
            if( viewStyles["table"] )this.viewTable.setStyles(viewStyles["table"]);
        }

U
unknown 已提交
217
        this.createLoadding();
R
roo00 已提交
218

U
unknown 已提交
219
        var viewTitleCellNode = (viewStyles && viewStyles["titleTd"]) ? viewStyles["titleTd"] : this.css.viewTitleCellNode;
U
unknown 已提交
220
        if (this.json.isTitle!=="no"){
U
unknown 已提交
221 222 223
            this.viewTitleLine = new Element("tr", {
                "styles": (viewStyles && viewStyles["titleTr"]) ? viewStyles["titleTr"] : this.css.viewTitleLineNode
            }).inject(this.viewTable);
R
roo00 已提交
224

U
unknown 已提交
225
            //if (this.json.select==="single" || this.json.select==="multi") {
226
            this.selectTitleCell = new Element("td.selectTitleCell", {
U
unknown 已提交
227
                "styles": viewTitleCellNode
U
unknown 已提交
228 229 230 231
            }).inject(this.viewTitleLine);
            this.selectTitleCell.setStyle("width", "10px");
            if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
            //}
232 233 234 235
            if( this.isSelectTdHidden() ){
                this.selectTitleCell.hide();
            }

R
roo00 已提交
236

U
unknown 已提交
237 238 239
            //序号
            if (this.viewJson.isSequence==="yes"){
                this.sequenceTitleCell = new Element("td", {
U
unknown 已提交
240
                    "styles": viewTitleCellNode
U
unknown 已提交
241 242 243
                }).inject(this.viewTitleLine);
                this.sequenceTitleCell.setStyle("width", "10px");
                if (this.json.titleStyles) this.sequenceTitleCell.setStyles(this.json.titleStyles);
R
roo00 已提交
244 245
            }

U
unknown 已提交
246 247 248
            this.entries = {};
            this.viewJson.selectList.each(function(column){
                this.entries[column.column] = column;
R
roo00 已提交
249

U
unknown 已提交
250 251
                if (!column.hideColumn){
                    var viewCell = new Element("td", {
U
unknown 已提交
252
                        "styles": viewTitleCellNode,
U
unknown 已提交
253 254
                        "text": column.displayName
                    }).inject(this.viewTitleLine);
U
unknown 已提交
255
                    var size = MWF.getTextSize(column.displayName, viewTitleCellNode);
U
unknown 已提交
256 257
                    viewCell.setStyle("min-width", ""+size.x+"px");
                    if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
258 259 260

                    if( typeOf(column.titleStyles) === "object" )viewCell.setStyles(column.titleStyles);
                    if( typeOf(column.titleProperties) === "object" )viewCell.setProperties(column.titleProperties);
261 262 263 264 265

                    if( column.events && column.events.loadTitle && column.events.loadTitle.code ){
                        var code = column.events.loadTitle.code;
                        this.Macro.fire( code, {"node" : viewCell, "json" : column, "data" : column.displayName, "view" : this});
                    }
U
unknown 已提交
266 267 268
                }else{
                    this.hideColumns.push(column.column);
                }
269

U
unknown 已提交
270 271 272 273 274 275 276 277 278 279
                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 已提交
280
    },
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
    isSelectTdHidden(){
        if( !this.viewJson.firstTdHidden ){
            return false;
        }
        if( this.json.select === "single" || this.json.select === "multi"  ){
            return false;
        }
        if( this.viewJson.select === "single" || this.viewJson.select === "multi"  ){
            return false;
        }
        if( this.options.select === "single" || this.options.select === "multi"  ){
            return false;
        }
        if( this.viewJson.group && this.viewJson.group.column ){
            return false;
        }
        return true;
    },
U
unknown 已提交
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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
    // _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(){
        this.viewPageAreaNode.empty();
U
unknown 已提交
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
        if( !this.paging ){
            var json;
            if( !this.viewJson.pagingList || !this.viewJson.pagingList.length ){
                json = {
                    "firstPageText": this.lp.firstPage,
                    "lastPageText": this.lp.lastPage
                };
            }else{
                json = this.viewJson.pagingList[0];
            }
            this.paging = new MWF.xApplication.query.Query.Viewer.Paging(this.viewPageAreaNode, json, this, {});
            this.paging.load();
        }else{
            this.paging.reload();
        }
R
roo00 已提交
386
    },
U
unknown 已提交
387 388 389 390 391 392
    _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;
U
unknown 已提交
393 394
        this.currentPage = this.options.defaultPage || 1;
        this.options.defaultPage = null;
R
roo00 已提交
395
    },
U
unknown 已提交
396 397 398 399 400 401 402 403 404 405 406
    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){
407
                        if( this.noDataTextNode )this.noDataTextNode.destroy();
U
unknown 已提交
408 409 410 411 412 413
                        this.loadCurrentPageData( function () {
                            this.fireEvent("postLoad"); //用户配置的事件
                        }.bind(this));
                    }else{
                        //this._loadPageNode();
                        this.viewPageAreaNode.empty();
414 415 416 417 418 419 420 421 422 423
                        if( this.viewJson.noDataText ){
                            var noDataTextNodeStyle = this.css.noDataTextNode;
                            if( this.viewJson.viewStyles && this.viewJson.viewStyles["noDataTextNode"] ){
                                noDataTextNodeStyle = this.viewJson.viewStyles["noDataTextNode"];
                            }
                            this.noDataTextNode = new Element( "div", {
                                "styles": noDataTextNodeStyle,
                                "text" : this.viewJson.noDataText
                            }).inject( this.contentAreaNode );
                        }
U
unknown 已提交
424 425 426 427 428 429 430 431
                        if (this.loadingAreaNode){
                            this.loadingAreaNode.destroy();
                            this.loadingAreaNode = null;
                        }
                        this.fireEvent("postLoad"); //用户配置的事件
                    }
                }.bind(this));
            }
R
roo00 已提交
432 433
        }.bind(this));
    },
434
    loadCurrentPageData: function( callback, async ){
U
unknown 已提交
435 436
        //是否需要在翻页的时候清空之前的items ?
        this.items = [];
R
roo00 已提交
437

U
unknown 已提交
438 439 440 441
        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 已提交
442

U
unknown 已提交
443 444 445 446
        while (this.viewTable.rows.length>1){
            this.viewTable.deleteRow(-1);
        }
        //this.createLoadding();
R
roo00 已提交
447

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

U
unknown 已提交
451
            this.fireEvent("postLoadPageData");
R
roo00 已提交
452

U
unknown 已提交
453 454 455 456 457 458
            if (this.viewJson.group.column){
                this.gridJson = json.data.groupGrid;
                this.loadGroupData();
            }else{
                this.gridJson = json.data.grid;
                this.loadData();
R
roo00 已提交
459
            }
U
unknown 已提交
460 461 462 463
            if (this.gridJson.length) this._loadPageNode();
            if (this.loadingAreaNode){
                this.loadingAreaNode.destroy();
                this.loadingAreaNode = null;
R
roo00 已提交
464 465
            }

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

U
unknown 已提交
468 469 470
            this.fireEvent("postLoadPage");

            if(callback)callback();
471
        }.bind(this), null, async === false ? false : true );
U
unknown 已提交
472 473 474 475 476 477 478 479 480 481 482 483 484 485
    },


    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 已提交
486 487
        }
    },
U
unknown 已提交
488 489 490 491 492 493 494
    loadPaging : function(){
        this.isItemsLoading = false;
        this.pageNumber = 0;
        this.isItemsLoaded = false;
        this.isSetedScroll = false;
        this.setScroll();
        this.loadDataByPaging()
R
roo00 已提交
495
    },
U
unknown 已提交
496 497 498 499 500 501 502 503 504 505 506 507 508 509
    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 已提交
510
        }
R
roo00 已提交
511
    },
U
unknown 已提交
512 513 514 515 516 517 518 519 520 521 522 523 524
    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 已提交
525
    },
U
unknown 已提交
526
    loadGroupData: function(){
U
unknown 已提交
527 528 529 530 531 532 533
        if (this.selectTitleCell && !this.selectTitleCell.retrieve("expandLoaded") ){
            if( this.viewJson.viewStyles && this.viewJson.viewStyles["groupCollapseNode"] ){
                this.expandAllNode = new Element("span", {
                    styles : this.viewJson.viewStyles["groupCollapseNode"]
                }).inject( this.selectTitleCell );
                this.selectTitleCell.setStyle("cursor", "pointer");
            }else{
534
                this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
U
unknown 已提交
535
            }
U
unknown 已提交
536 537
            this.selectTitleCell.setStyle("cursor", "pointer");
            this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
U
unknown 已提交
538
            this.selectTitleCell.store("expandLoaded", true);
U
unknown 已提交
539
        }
U
unknown 已提交
540
        this.expandAll = false;
U
unknown 已提交
541 542 543 544 545 546 547 548 549 550 551

        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 已提交
552 553
        }
    },
U
unknown 已提交
554
    expandOrCollapseAll: function(){
U
unknown 已提交
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
        if( this.viewJson.viewStyles && this.viewJson.viewStyles["groupCollapseNode"] ){
            var span = this.selectTitleCell.getElement("span");
            if( this.expandAll ){
                this.items.each(function(item){
                    item.collapse();
                    span.setStyles( this.viewJson.viewStyles["groupCollapseNode"] );
                }.bind(this));
                this.expandAll = false;
            }else{
                this.items.each(function(item, i){
                    window.setTimeout(function(){
                        item.expand();
                    }.bind(this), 10*i+5);

                    span.setStyles( this.viewJson.viewStyles["groupExpandNode"] );
                    this.expandAll = true;
                }.bind(this));
            }
U
unknown 已提交
573
        }else{
U
unknown 已提交
574 575 576 577
            var icon = this.selectTitleCell.getElement("span");
            if (icon.get("html").indexOf("expand.png")===-1){
                this.items.each(function(item){
                    item.collapse();
578
                    icon.set("html", "<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>");
U
unknown 已提交
579 580 581 582 583 584 585
                }.bind(this));
                this.expandAll = false;
            }else{
                this.items.each(function(item, i){
                    window.setTimeout(function(){
                        item.expand();
                    }.bind(this), 10*i+5);
R
roo00 已提交
586

587
                    icon.set("html", "<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/down.png'/>");
U
unknown 已提交
588 589 590
                }.bind(this));
                this.expandAll = true;
            }
U
unknown 已提交
591 592 593 594 595 596 597 598 599 600
        }
    },
    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 已提交
601

U
unknown 已提交
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
                // 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 已提交
641

U
unknown 已提交
642 643 644 645 646
        this.filterItems.each(function(filter){
            filter.destroy();
        }.bind(this));
        this.filterItems = [];
        if (this.viewSearchInputNode) this.viewSearchInputNode.set("text", this.lp.searchKeywork);
R
roo00 已提交
647

U
unknown 已提交
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 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
        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 已提交
690
            }
U
unknown 已提交
691 692 693 694 695 696 697 698 699 700
        }
        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 已提交
701
        }else{
U
unknown 已提交
702
            return [];
R
roo00 已提交
703 704
        }
    },
U
unknown 已提交
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
    _loadModuleEvents : function(){
        Object.each(this.viewJson.events, function(e, key){
            if (e.code){
                if (this.options.moduleEvents.indexOf(key)!==-1){
                    this.addEvent(key, function(event, target){
                        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 已提交
748
            }.bind(this),
U
unknown 已提交
749 750 751
            "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();
752 753
            }.bind(this)
        });
NoSubject's avatar
NoSubject 已提交
754
    },
U
unknown 已提交
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
    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 已提交
774
    },
U
unknown 已提交
775 776 777
    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 已提交
778

U
unknown 已提交
779 780 781
        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 已提交
782

U
unknown 已提交
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
        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 已提交
829 830
                        }
                    }
R
roo00 已提交
831
                }.bind(this));
U
unknown 已提交
832 833 834

                this.createViewNode({"filterList": filterData});
            }else{
835
                this.filterItems = [];
U
unknown 已提交
836
                this.createViewNode();
R
roo00 已提交
837
            }
U
unknown 已提交
838
        }
R
roo00 已提交
839
    },
U
unknown 已提交
840 841 842 843 844 845
    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 已提交
846

U
unknown 已提交
847 848 849
            this.createViewNode({"filterList": filterData});
        }else{
            this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
NoSubject's avatar
NoSubject 已提交
850
        }
U
unknown 已提交
851 852
    },
    loadCustomSearch: function(){
853 854 855 856 857
        if( this.lastFilterItems ){
            this.filterItems = this.lastFilterItems;
        }else{
            this.filterItems = [];
        }
U
unknown 已提交
858
        debugger;
U
unknown 已提交
859 860 861
        this.viewSearchIconNode.setStyle("display", "none");
        this.viewSearchInputBoxNode.setStyle("display", "none");
        this.viewSearchCustomActionNode.setStyle("display", "none");
NoSubject's avatar
NoSubject 已提交
862

U
unknown 已提交
863 864 865
        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 已提交
866

U
unknown 已提交
867 868 869 870 871 872
        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 已提交
873

U
unknown 已提交
874 875 876
            if (this.viewSearchCustomContentNode){
                this.viewSearchCustomCloseActionNode.setStyle("display", "block");
                this.viewSearchCustomContentNode.setStyle("display", "block");
NoSubject's avatar
NoSubject 已提交
877
            }else{
U
unknown 已提交
878
                this.loadCustomSearchContent();
NoSubject's avatar
NoSubject 已提交
879
            }
880

U
unknown 已提交
881
            if(this.setContentHeightFun)this.setContentHeightFun();
NoSubject's avatar
NoSubject 已提交
882
        }.bind(this));
U
unknown 已提交
883
        this.searchCustomView();
NoSubject's avatar
NoSubject 已提交
884
    },
U
unknown 已提交
885 886 887
    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 已提交
888

U
unknown 已提交
889 890 891 892 893 894
        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 已提交
895

U
unknown 已提交
896
        this.loadViewSearchCustomList();
R
roo00 已提交
897

U
unknown 已提交
898 899 900 901 902 903
        this.viewSearchCustomCloseActionNode.addEvents({
            "click": function(){this.closeCustomSearch();}.bind(this)
        });
        this.viewSearchCustomAddIconNode.addEvents({
            "click": function(){this.viewSearchCustomAddToFilter();}.bind(this)
        });
R
roo00 已提交
904
    },
U
unknown 已提交
905 906 907 908 909 910 911 912 913
    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 已提交
914

U
unknown 已提交
915 916 917 918 919 920 921 922
        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 已提交
923

U
unknown 已提交
924 925 926 927 928 929 930 931 932
        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){
933
            var selectableList = this.getCustomSelectScriptResult(entry);
U
unknown 已提交
934 935 936
            switch (entry.formatType){
                case "numberValue":
                    this.loadComparisonSelect(this.lp.numberFilter);
937 938 939 940 941
                    if( selectableList.length > 0 ){
                        this.loadViewSerchCustomSelectByScript(selectableList)
                    }else{
                        this.loadViewSearchCustomValueNumberInput();
                    }
U
unknown 已提交
942 943 944
                    break;
                case "dateTimeValue":
                    this.loadComparisonSelect(this.lp.dateFilter);
945 946 947 948 949
                    if( selectableList.length > 0 ){
                        this.loadViewSerchCustomSelectByScript(selectableList)
                    }else {
                        this.loadViewSearchCustomValueDateTimeInput();
                    }
U
unknown 已提交
950 951 952
                    break;
                case "dateValue":
                    this.loadComparisonSelect(this.lp.dateFilter);
953 954 955 956 957
                    if( selectableList.length > 0 ){
                        this.loadViewSerchCustomSelectByScript(selectableList)
                    }else {
                        this.loadViewSearchCustomValueDateInput();
                    }
U
unknown 已提交
958 959 960
                    break;
                case "timeValue":
                    this.loadComparisonSelect(this.lp.dateFilter);
961 962 963 964 965
                    if( selectableList.length > 0 ){
                        this.loadViewSerchCustomSelectByScript(selectableList)
                    }else {
                        this.loadViewSearchCustomValueTimeInput();
                    }
U
unknown 已提交
966 967 968
                    break;
                case "booleanValue":
                    this.loadComparisonSelect(this.lp.booleanFilter);
969 970 971 972 973
                    if( selectableList.length > 0 ){
                        this.loadViewSerchCustomSelectByScript(selectableList)
                    }else {
                        this.loadViewSearchCustomValueBooleanInput();
                    }
U
unknown 已提交
974 975 976
                    break;
                default:
                    this.loadComparisonSelect(this.lp.textFilter);
977 978 979 980 981
                    if( selectableList.length > 0 ){
                        this.loadViewSerchCustomSelectByScript(selectableList)
                    }else {
                        this.loadViewSearchCustomValueTextInput();
                    }
R
roo00 已提交
982
            }
U
unknown 已提交
983 984
        }
    },
985 986 987 988 989 990 991 992 993 994 995 996 997 998
    getCustomSelectScriptResult : function( entry ){
        var scriptResult = [];
        if( entry.valueType === "script" ){
            if( entry.valueScript && entry.valueScript.code ){
                var result = this.Macro.exec(entry.valueScript.code, this);
                var array = typeOf( result ) === "array" ? result : [result];
                for( var i=0; i<array.length; i++ ){
                    if( array[i].indexOf( "|" ) > -1 ){
                        var arr = array[i].split("|");
                        scriptResult.push({ "text" : arr[0], "value" : arr[1] })
                    }else{
                        scriptResult.push({ "text" : array[i], "value" : array[i] })
                    }
                }
R
roo00 已提交
999
            }
U
unknown 已提交
1000
        }
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
        return scriptResult;
    },
    loadViewSerchCustomSelectByScript: function( array ){
        this.viewSearchCustomValueContentNode.empty();
        this.viewSearchCustomValueNode = new Element("select", {
            "styles": this.css.viewFilterSearchCustomComparisonListNode,
            "multiple": true
        }).inject(this.viewSearchCustomValueContentNode);
        array.each(function( v ){
            var option = new Element("option", {
                "style": this.css.viewFilterSearchOptionNode,
                "value": v.value,
                "text": v.text,
                "selected" : array.length === 1
            }).inject(this.viewSearchCustomValueNode);
        }.bind(this));
U
unknown 已提交
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
    },
    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,
1036
                "secondEnable" : true,
U
unknown 已提交
1037 1038 1039
                "target": this.container,
                "format": "db"
            });
R
roo00 已提交
1040 1041
        }.bind(this));
    },
U
unknown 已提交
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
    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 已提交
1057
    },
U
unknown 已提交
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
    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 已提交
1073
    },
U
unknown 已提交
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
    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 已提交
1093
        }.bind(this));
U
unknown 已提交
1094 1095 1096 1097 1098
    },
    closeCustomSearch: function(){
        if (this.viewSearchCustomContentNode && this.viewSearchCustomContentNode.getStyle("display")==="block"){
            this.viewSearchCustomCloseActionNode.setStyle("display", "none");
            this.viewSearchCustomContentNode.setStyle("display", "none");
R
roo00 已提交
1099

U
unknown 已提交
1100 1101 1102
            var x = this.viewSearchInputAreaNode.getParent().getSize().x;
            x1 = x-2-10-90;
            this.css.viewFilterSearchInputAreaNode.width = ""+x1+"px";
R
roo00 已提交
1103

U
unknown 已提交
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
            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");

U
unknown 已提交
1117
                if(this.setContentHeightFun)this.setContentHeightFun();
U
unknown 已提交
1118
            }.bind(this));
1119
            this.lastFilterItems = this.filterItems;
U
unknown 已提交
1120 1121
            this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
        }
R
roo00 已提交
1122
    },
U
unknown 已提交
1123 1124 1125 1126 1127 1128
    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 已提交
1129
        }
U
unknown 已提交
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
        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 = "";

1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
            if( entry.valueType === "script" && entry.valueScript && entry.valueScript.code  ){
                var idx = this.viewSearchCustomValueNode.selectedIndex;
                if (idx!==-1){
                    var v = this.viewSearchCustomValueNode.options[idx].get("value");
                    value = entry.formatType === "booleanValue" ? (v==="true") : v;
                }
            }else{
                switch (entry.formatType){
                    case "numberValue":
                        value = this.viewSearchCustomValueNode.get("value");
                        break;
                    case "dateTimeValue":
                        value = this.viewSearchCustomValueNode.get("value");
                        break;
                    case "booleanValue":
                        var idx = this.viewSearchCustomValueNode.selectedIndex;
                        if (idx!==-1){
                            var v = this.viewSearchCustomValueNode.options[idx].get("value");
                            value = (v==="true");
                        }
                        break;
                    default:
                        value = this.viewSearchCustomValueNode.get("value");
                }
R
roo00 已提交
1167
            }
1168

U
unknown 已提交
1169 1170 1171
            if (value===""){
                MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
                return false;
U
unknown 已提交
1172
            }
U
unknown 已提交
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185

            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 已提交
1186
    },
U
unknown 已提交
1187 1188 1189 1190
    searchViewRemoveFilter: function(filter){
        this.filterItems.erase(filter);
        filter.destroy();
        this.searchCustomView()
1191
    },
U
unknown 已提交
1192
    //搜索相关结束
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214

    //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 已提交
1215 1216 1217
    getSelectedData : function(){
        return this.getData();
    },
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
    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;
1255 1256 1257
        if( this.viewAreaNode ){
            this.createViewNode({"filterList": this.json.filter  ? this.json.filter.clone() : null});
        }
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
    },
    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 已提交
1289
    }
1290
    //api 使用 结束
R
roo00 已提交
1291 1292 1293 1294 1295 1296 1297 1298 1299
});

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 已提交
1300
        this.idx = i;
1301
        this.clazzType = "item";
1302

R
roo00 已提交
1303 1304 1305
        this.load();
    },
    load: function(){
1306
        this.view.fireEvent("queryLoadItemRow", [null, this]);
U
unknown 已提交
1307

U
unknown 已提交
1308 1309 1310 1311 1312 1313
        var viewStyles = this.view.viewJson.viewStyles;
        var viewContentTdNode = ( viewStyles && viewStyles["contentTd"] ) ? viewStyles["contentTd"] : this.css.viewContentTdNode;

        this.node = new Element("tr", {
            "styles": ( viewStyles && viewStyles["contentTr"] ) ? viewStyles["contentTr"] : this.css.viewContentTrNode
        });
R
roo00 已提交
1314 1315 1316 1317 1318 1319 1320
        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 已提交
1321
        this.selectTd = new Element("td", { "styles": viewContentTdNode }).inject(this.node);
U
unknown 已提交
1322 1323
        this.selectTd.setStyles({"cursor": "pointer"});
        if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
1324 1325 1326
        if( this.view.isSelectTdHidden() ){
            this.selectTd.hide();
        }
R
roo00 已提交
1327 1328
        //}

R
roo00 已提交
1329 1330
        //序号
        if (this.view.viewJson.isSequence==="yes"){
U
unknown 已提交
1331
            this.sequenceTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
R
roo00 已提交
1332 1333 1334 1335 1336
            this.sequenceTd.setStyle("width", "10px");
            var s= 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
            this.sequenceTd.set("text", s);
        }

1337 1338
        debugger;

R
roo00 已提交
1339 1340 1341 1342
        Object.each(this.view.entries, function(c, k){
            var cell = this.data.data[k];
            if (cell === undefined) cell = "";
            //if (cell){
U
unknown 已提交
1343
            if (this.view.hideColumns.indexOf(k)===-1){
U
unknown 已提交
1344
                var td = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
U
unknown 已提交
1345 1346 1347 1348 1349 1350 1351
                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 已提交
1352
                    }
1353
                    if( typeOf(c.contentProperties) === "object" )td.setProperties(c.contentProperties);
1354 1355 1356 1357 1358 1359 1360 1361 1362
                    if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
                    if( typeOf(c.contentStyles) === "object" )td.setStyles(c.contentStyles);
                }else{
                    if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
                }

                if (this.view.openColumns.indexOf(k)!==-1){
                    this.setOpenWork(td, c)
                }
1363

1364
                if (k!== this.view.viewJson.group.column){
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379
                    Object.each( c.events || {}, function (e , key) {
                        if(e.code){
                            if( key === "loadContent" ){
                                this.view.Macro.fire( e.code,
                                    {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this});
                            }else if( key !== "loadTitle" ){
                                td.addEvent(key, function(event){
                                    return this.view.Macro.fire(
                                        e.code,
                                        {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this},
                                        event
                                    );
                                }.bind(this));
                            }
                        }
1380
                    }.bind(this));
U
unknown 已提交
1381 1382
                }
            }
R
roo00 已提交
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400
            //}
        }.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 已提交
1401

1402
        this.view.fireEvent("postLoadItemRow", [null, this]);
R
roo00 已提交
1403
    },
R
roo00 已提交
1404
    setOpenWork: function(td, column){
R
roo00 已提交
1405
        td.setStyle("cursor", "pointer");
R
roo00 已提交
1406
        if( column.clickCode ){
U
unknown 已提交
1407 1408 1409 1410 1411 1412
            // 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 已提交
1413
            td.addEvent("click", function( ev ){
U
unknown 已提交
1414 1415 1416
                var result = this.view.Macro.fire(column.clickCode, this, ev);
                ev.stopPropagation();
                return result;
R
roo00 已提交
1417
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
1418
        }else{
R
roo00 已提交
1419
            if (this.view.json.type==="cms"){
U
unknown 已提交
1420 1421 1422 1423
                td.addEvent("click", function(ev){
                    this.openCms(ev)
                    ev.stopPropagation();
                }.bind(this));
R
roo00 已提交
1424
            }else{
U
unknown 已提交
1425 1426 1427 1428
                td.addEvent("click", function(ev){
                    this.openWorkAndCompleted(ev)
                    ev.stopPropagation();
                }.bind(this));
R
roo00 已提交
1429
            }
NoSubject's avatar
NoSubject 已提交
1430 1431 1432 1433 1434
        }

    },
    openCms: function(e){
        var options = {"documentId": this.data.bundle};
U
unknown 已提交
1435
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
NoSubject's avatar
NoSubject 已提交
1436
        layout.desktop.openApplication(e, "cms.Document", options);
R
roo00 已提交
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
    },
    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 已提交
1484
            json.data.each(function(task){
R
roo00 已提交
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499
                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 已提交
1500
            var id = e.target.retrieve("workId");
R
roo00 已提交
1501
            worksAreaNode.destroy();
NoSubject's avatar
NoSubject 已提交
1502
            this.openWorkCompleted(id, e);
R
roo00 已提交
1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525
        }.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 已提交
1526
        MWF.require("MWF.widget.Mask", null, false);
R
roo00 已提交
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
        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 已提交
1555
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
R
roo00 已提交
1556 1557 1558 1559
        layout.desktop.openApplication(e, "process.Work", options);
    },
    openWorkCompleted: function(id, e){
        var options = {"workCompletedId": id};
U
unknown 已提交
1560
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
R
roo00 已提交
1561 1562 1563 1564
        layout.desktop.openApplication(e, "process.Work", options);
    },

    setEvent: function(){
U
unknown 已提交
1565 1566
        var flag = this.view.json.select || this.view.viewJson.select ||  "none";
        if ( flag ==="single" || flag==="multi"){
R
roo00 已提交
1567 1568 1569
            this.node.addEvents({
                "mouseover": function(){
                    if (!this.isSelected){
U
unknown 已提交
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
                        var viewStyles = this.view.viewJson.viewStyles;
                        if( viewStyles ){
                            if( flag === "single" ){
                                this.selectTd.setStyles( viewStyles["radioNode"] );
                            }else{
                                this.selectTd.setStyles( viewStyles["checkboxNode"] );
                            }
                        }else{
                            var iconName = "checkbox";
                            if (flag==="single") iconName = "radiobox";
1580
                            this.selectTd.setStyles({"background": "url("+"../x_component_query_Query/$Viewer/default/icon/"+iconName+".png) center center no-repeat"});
U
unknown 已提交
1581
                        }
R
roo00 已提交
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592
                    }
                }.bind(this),
                "mouseout": function(){
                    if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
                }.bind(this),
                "click": function(){this.select();}.bind(this)
            });
        }
    },

    select: function(){
U
unknown 已提交
1593
        var flag = this.view.json.select || this.view.viewJson.select ||  "none";
R
roo00 已提交
1594
        if (this.isSelected){
U
unknown 已提交
1595
            if (flag==="single"){
R
roo00 已提交
1596 1597 1598 1599 1600
                this.unSelectedSingle();
            }else{
                this.unSelected();
            }
        }else{
U
unknown 已提交
1601
            if (flag==="single"){
R
roo00 已提交
1602 1603 1604 1605 1606
                this.selectedSingle();
            }else{
                this.selected();
            }
        }
U
unknown 已提交
1607
        this.view.fireEvent("select"); //options 传入的事件
R
roo00 已提交
1608 1609 1610 1611
    },

    selected: function(){
        this.view.selectedItems.push(this);
U
unknown 已提交
1612 1613 1614 1615 1616
        var viewStyles = this.view.viewJson.viewStyles;
        if( viewStyles ){
            this.selectTd.setStyles( viewStyles["checkedCheckboxNode"] );
            this.node.setStyles( viewStyles["contentSelectedTr"] );
        }else{
1617
            this.selectTd.setStyles({"background": "url("+"../x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
U
unknown 已提交
1618 1619
            this.node.setStyles(this.css.viewContentTrNode_selected);
        }
R
roo00 已提交
1620
        this.isSelected = true;
U
unknown 已提交
1621
        this.view.fireEvent("selectRow", [this]);
R
roo00 已提交
1622 1623 1624 1625
    },
    unSelected: function(){
        this.view.selectedItems.erase(this);
        this.selectTd.setStyles({"background": "transparent"});
U
unknown 已提交
1626 1627 1628 1629 1630 1631
        var viewStyles = this.view.viewJson.viewStyles;
        if( viewStyles ){
            this.node.setStyles( viewStyles["contentTr"] );
        }else{
            this.node.setStyles(this.css.viewContentTrNode);
        }
R
roo00 已提交
1632
        this.isSelected = false;
U
unknown 已提交
1633
        this.view.fireEvent("unselectRow", [this]);
R
roo00 已提交
1634 1635 1636 1637 1638
    },
    selectedSingle: function(){
        if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
        this.view.selectedItems = [this];
        this.view.currentSelectedItem = this;
U
unknown 已提交
1639 1640 1641 1642 1643
        var viewStyles = this.view.viewJson.viewStyles;
        if( viewStyles ){
            this.selectTd.setStyles( viewStyles["checkedRadioNode"] );
            this.node.setStyles( viewStyles["contentSelectedTr"] );
        }else {
1644
            this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/radiobox_checked.png) center center no-repeat"});
U
unknown 已提交
1645 1646
            this.node.setStyles(this.css.viewContentTrNode_selected);
        }
R
roo00 已提交
1647
        this.isSelected = true;
U
unknown 已提交
1648
        this.view.fireEvent("selectRow", [this]);
R
roo00 已提交
1649 1650 1651 1652 1653
    },
    unSelectedSingle: function(){
        this.view.selectedItems = [];
        this.view.currentSelectedItem = null;
        this.selectTd.setStyles({"background": "transparent"});
U
unknown 已提交
1654 1655 1656 1657 1658 1659
        var viewStyles = this.view.viewJson.viewStyles;
        if( viewStyles ){
            this.node.setStyles( viewStyles["contentTr"] );
        }else{
            this.node.setStyles(this.css.viewContentTrNode);
        }
R
roo00 已提交
1660
        this.isSelected = false;
U
unknown 已提交
1661
        this.view.fireEvent("unselectRow", [this]);
R
roo00 已提交
1662 1663 1664 1665
    }
});

MWF.xApplication.query.Query.Viewer.ItemCategory = new Class({
R
roo00 已提交
1666
    initialize: function(view, data, i){
R
roo00 已提交
1667 1668 1669 1670 1671
        this.view = view;
        this.data = data;
        this.css = this.view.css;
        this.items = [];
        this.loadChild = false;
R
roo00 已提交
1672
        this.idx = i;
1673
        this.clazzType = "category";
R
roo00 已提交
1674 1675 1676
        this.load();
    },
    load: function(){
1677
        this.view.fireEvent("queryLoadCategoryRow", [null, this]);
U
unknown 已提交
1678

U
unknown 已提交
1679 1680 1681 1682 1683 1684 1685
        var viewStyles = this.view.viewJson.viewStyles;

        var viewContentCategoryTdNode = ( viewStyles && viewStyles["contentGroupTd"] ) ? viewStyles["contentGroupTd"] : this.css.viewContentCategoryTdNode;

        this.node = new Element("tr", {
            "styles": (viewStyles && viewStyles["contentTr"]) ? viewStyles["contentTr"] : this.css.viewContentTrNode
        }).inject(this.view.viewTable);
R
roo00 已提交
1686
        //if (this.view.json.select==="single" || this.view.json.select==="multi"){
U
unknown 已提交
1687
        this.selectTd = new Element("td", {"styles": viewContentCategoryTdNode}).inject(this.node);
U
unknown 已提交
1688
        if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
1689 1690 1691 1692
        // if( this.view.isSelectTdHidden() ){
        //     this.selectTd.hide();
        // }

R
roo00 已提交
1693 1694
        //}
        this.categoryTd = new Element("td", {
U
unknown 已提交
1695
            "styles": viewContentCategoryTdNode,
R
roo00 已提交
1696
            "colspan": this.view.viewJson.selectList.length+1
R
roo00 已提交
1697 1698 1699 1700 1701 1702 1703 1704 1705
        }).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;
            }
        }
1706

R
roo00 已提交
1707 1708 1709 1710 1711 1712 1713
        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;
        }

U
unknown 已提交
1714 1715 1716 1717 1718 1719 1720
        if( viewStyles && viewStyles["groupCollapseNode"] ){
            this.expandNode = new Element("span", {
                styles : viewStyles["groupCollapseNode"]
            }).inject( this.categoryTd );
            new Element("span", { text : text }).inject( this.categoryTd );
            // this.categoryTd.set("text", text );
        }else{
1721
            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);
U
unknown 已提交
1722 1723
        }
        this.expanded = false;
R
roo00 已提交
1724 1725
        if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);

1726 1727 1728 1729 1730 1731
        debugger;
        if( this.groupColumn ){
            if( typeOf(this.groupColumn.contentStyles) === "object" )this.categoryTd.setStyles(this.groupColumn.contentStyles);
            if( typeOf(this.groupColumn.contentProperties) === "object" )this.categoryTd.setProperties(this.groupColumn.contentProperties);
        }

R
roo00 已提交
1732
        this.setEvent();
U
unknown 已提交
1733

1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750
        var column = this.groupColumn;
        var td = this.categoryTd;
        Object.each( column.events || {}, function (e , key) {
            if(e.code){
                if( key === "loadContent" ){
                    this.view.Macro.fire( e.code,
                        {"node" : td, "json" : column, "data" : this.data.group, "view": this.view, "row" : this});
                }else if( key !== "loadTitle" ){
                    td.addEvent(key, function(event){
                        return this.view.Macro.fire(
                            e.code,
                            {"node" : td, "json" : column, "data" : this.data.group, "view": this.view, "row" : this},
                            event
                        );
                    }.bind(this));
                }
            }
1751
        }.bind(this));
1752

1753
        this.view.fireEvent("postLoadCategoryRow", [null, this]);
R
roo00 已提交
1754 1755 1756
    },
    setEvent: function(){
        //if (this.selectTd){
U
unknown 已提交
1757 1758 1759
        this.node.addEvents({
            "click": function(){this.expandOrCollapse();}.bind(this)
        });
R
roo00 已提交
1760 1761 1762
        //}
    },
    expandOrCollapse: function(){
U
unknown 已提交
1763 1764 1765 1766 1767 1768 1769
        // var t = this.node.getElement("span").get("html");
        // if (t.indexOf("expand.png")===-1){
        //     this.collapse();
        // }else{
        //     this.expand();
        // }
        if( this.expanded ){
R
roo00 已提交
1770 1771 1772 1773 1774 1775 1776 1777 1778
            this.collapse();
        }else{
            this.expand();
        }
    },
    collapse: function(){
        this.items.each(function(item){
            item.node.setStyle("display", "none");
        }.bind(this));
U
unknown 已提交
1779 1780 1781
        if( this.expandNode ){
            this.expandNode.setStyles( this.view.viewJson.viewStyles["groupCollapseNode"] )
        }else{
1782
            this.node.getElement("span").set("html", "<img src='../x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/>");
U
unknown 已提交
1783 1784
        }
        this.expanded = false;
R
roo00 已提交
1785 1786 1787 1788 1789
    },
    expand: function(){
        this.items.each(function(item){
            item.node.setStyle("display", "table-row");
        }.bind(this));
U
unknown 已提交
1790 1791 1792
        if( this.expandNode ){
            this.expandNode.setStyles( this.view.viewJson.viewStyles["groupExpandNode"] )
        }else{
1793
            this.node.getElement("span").set("html", "<img src='../x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
U
unknown 已提交
1794 1795
        }
        this.expanded = true;
R
roo00 已提交
1796 1797
        if (!this.loadChild){
            //window.setTimeout(function(){
R
roo00 已提交
1798 1799 1800 1801
            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 已提交
1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 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 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874
            }.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 已提交
1875
});
U
unknown 已提交
1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038

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){
2039
        var path = "../x_component_process_FormDesigner/Module/Actionbar/";
U
unknown 已提交
2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052
        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 已提交
2053 2054 2055
                // if (tool.control){
                //     flag = this.form.businessData.control[tool.control]
                // }
U
unknown 已提交
2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087
                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){
2088 2089
        //var path = "../x_component_process_FormDesigner/Module/Actionbar/";
        var path = "../x_component_query_ViewDesigner/$View/";
U
unknown 已提交
2090
        var flag = true;
U
unknown 已提交
2091 2092 2093
        // if (tool.control){
        //     flag = this.form.businessData.control[tool.control]
        // }
U
unknown 已提交
2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104
        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,
U
unknown 已提交
2105
                "MWFButtonImage": path+this.options.style+"/actionbar/"+ ( this.json.iconStyle || "default" ) +"/"+tool.img,
U
unknown 已提交
2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137
                "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();
    }
U
unknown 已提交
2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267
});

MWF.xApplication.query.Query.Viewer.Paging = new Class({
    Implements: [Events],
    options: {
        "style" : "default",
        "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad","jump"]
    },
    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");
        }
    },

    _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.loadPaging( true )
    },
    reload : function(){
        this.loadPaging( false )
    },
    loadPaging : function( firstLoading ){
2268 2269 2270 2271 2272 2273 2274
        // this.pagingNode = this.node.getFirst("div");
        // if( !this.pagingNode ){
        //     this.pagingNode = new Element("div").inject( this.node );
        // }
        // this.pagingNode.empty();
        this.node.empty();
        this.paging = new o2.widget.Paging(this.node, {
U
unknown 已提交
2275 2276
            //style : this.options.skin && this.options.skin.pagingBar ? this.options.skin.pagingBar : "default",
            countPerPage: this.view.json.pageSize || this.view.options.perPageCount,
2277
            visiblePages: layout.mobile?5:(this.json.visiblePages ? this.json.visiblePages.toInt() : 9),
U
unknown 已提交
2278 2279 2280 2281 2282 2283 2284
            currentPage: this.view.currentPage,
            itemSize: this.view.count,
            pageSize: this.view.pages,
            hasNextPage: typeOf( this.json.hasPreNextPage ) === "boolean" ? this.json.hasPreNextPage : true,
            hasPrevPage: typeOf( this.json.hasPreNextPage ) === "boolean" ? this.json.hasPreNextPage : true,
            hasTruningBar: typeOf( this.json.hasTruningBar ) === "boolean" ? this.json.hasTruningBar : true,
            hasBatchTuring: typeOf( this.json.hasBatchTuring ) === "boolean" ? this.json.hasBatchTuring : true,
2285 2286 2287
            hasFirstPage: typeOf( this.json.hasFirstLastPage ) === "boolean" ? this.json.hasFirstLastPage : (layout.mobile?false:true),
            hasLastPage: typeOf( this.json.hasFirstLastPage ) === "boolean" ? this.json.hasFirstLastPage : (layout.mobile?false:true),
            hasJumper: typeOf( this.json.hasPageJumper ) === "boolean" ? this.json.hasPageJumper : (layout.mobile?false:true),
U
unknown 已提交
2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298
            hiddenWithDisable: false,
            hiddenWithNoItem: true,
            text: {
                prePage: this.json.prePageText,
                nextPage: this.json.nextPageText,
                firstPage: this.json.firstPageText,
                lastPage: this.json.lastPageText
            },
            onJumpingPage : function( pageNum, itemNum ){
                this.view.currentPage = pageNum;
                this.fireEvent("jump");
2299
                this.view.loadCurrentPageData( null, false );
U
unknown 已提交
2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310
            }.bind(this),
            onPostLoad : function () {
                if( firstLoading ){
                    if(this.view.setContentHeightFun)this.view.setContentHeightFun();
                    this.fireEvent("load");
                }
                this.fireEvent("afterLoad");
            }.bind(this)
        }, this.json.pagingStyles || {});
        this.paging.load();
    }
U
unknown 已提交
2311
});