FTSearchView.js 17.4 KB
Newer Older
U
unknown 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
MWF.require("o2.widget.Paging", null, false);
MWF.xApplication.ftsearch.FTSearchView = new Class({
    Extends: MWF.widget.Common,
    Implements: [Options, Events],

    options: {
        "style": "default",
        "query": ""
    },
    initialize: function(node, app, options){
        this.setOptions(options);

        this.path = "../x_component_ftsearch/$FTSearchView/";

        this.app = app;
        this.container = $(node);
        this.facetOrderList = ["category","applicationName", "processName","appName","categoryName"];
        this.load();
    },
    load: function(){
        this.pageSize = 10;
        this.currentKey = "";

        this.docPageNum = 1;
        this.docTotal = 0;
        this.docList = [];
        this.selectedConditionList = [];

        var url = this.path+this.options.style+"/view.html";
        this.container.loadHtml(url, {
            "bind": {"lp": this.app.lp, "data": {"query":this.options.query}},
            "module": this
         }, function(){
            this.loadSelectedCondition();
            this.search(null, this.options.query);
        }.bind(this));

        this.resizeFun = this.checkAllSwitchButton.bind(this);
        this.app.addEvent("resize", this.resizeFun);
    },
    recordStatus: function(){
        return {
            // view: "ftsearch",
            query: this.getQuery()
        }
    },
    reload: function(){
        this.container.empty();
        if(this.resizeFun){
            this.app.removeEvent("resize", this.resizeFun);
        }
        this.load();
    },
    destroy : function(){
        // this.app.removeEvent("resize", this.resetNodeSizeFun );
        this.container.empty();
        if(this.resizeFun){
            this.app.removeEvent("resize", this.resizeFun);
        }
    },
    getQuery: function(){
        return this.searchInput.get("value") || "";
    },
    gotoMainPage: function(){
        this.app.gotoMainPage();
    },
    selectTab: function(){
        this.app.selectTab();
    },
    searchKeydown: function(e){
        if( e.keyCode === 13 ){
            this.search();
        }
    },
U
unknown 已提交
75
     search: function(pageNum, query){
U
unknown 已提交
76 77
        this.selectedConditionList = [];
        this.loadSelectedCondition();
U
unknown 已提交
78 79 80 81 82 83 84 85 86

        if( typeOf(this.collapseCondition) === "boolean" ){
            this._search(pageNum, query);
        }else{
            MWF.UD.getDataJson("ftsearchCollapseCondition", function (json) {
                this.collapseCondition = json === "true";
                this._search(pageNum, query);
            }.bind(this), true);
        }
U
unknown 已提交
87 88 89 90 91
    },
    _search: function( pageNum, query ){
        pageNum = o2.typeOf(pageNum) === "number" ? pageNum : null;
        this.docPageNum = pageNum || 1;
        this.currentKey = query || this.searchInput.get("value") || "";
92
        if( this.currentKey ){
U
unknown 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

            var startDate = new Date();

            var filterList = this.selectedConditionList.map(function(cond){
                return {
                    field: cond.field,
                    valueList: cond.valueList
                };
                // {
                //     field: cond.field,
                //     value: cond.value,
                //     start: xxx
                //     end: xxx
                // }
            });
U
unknown 已提交
108
            o2.Actions.load("x_query_assemble_surface").SearchAction.post({
U
unknown 已提交
109
                query: this.currentKey || "",
U
unknown 已提交
110 111 112 113
                page:  this.docPageNum,
                size: this.pageSize,
                filterList: filterList
            }).then(function(json){
U
unknown 已提交
114 115 116 117 118 119 120
                var sequence = (this.docPageNum - 1) * this.pageSize;
                this.docList = json.data.documentList.map(function (d) {
                    sequence++;
                    d.sequence = sequence;
                    return d;
                });

U
unknown 已提交
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
                this.docTotal =  json.data.count;

                this.loadDocList(this.docList);
                var facetList = this.orderFacet(json.data.facetList);
                this.loadCondition( facetList);

                if(!pageNum){
                    var endDate = new Date();
                    var t = endDate.getTime()-startDate.getTime();
                    t = ((t/1000)*100).toInt()/100;
                    var text = this.app.lp.docTotalInfor.replace("{count}", this.docTotal||0).replace("{time}", t);
                    this.docTotalNode.set("html", text);

                    this.loadDocPagination();
                }
            }.bind(this));
137 138 139 140 141 142 143 144 145
        }else{
            this.docList = [];
            this.docTotal = 0;
            this.docTotalNode.set("text", "");
            this.loadSelectedCondition();
            this.loadCondition( []);
            this.loadDocList();
            this.loadDocPagination();
        }
U
unknown 已提交
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
    },
    orderFacet: function(facetList){
        facetList.sort(function (a, b) {
           var indexA =  this.facetOrderList.indexOf(a.field);
           var indexB =  this.facetOrderList.indexOf(b.field);
           if( indexA === -1 )indexA = 999999;
           if( indexB === -1 )indexB = 999999;
           return indexA - indexB;
        }.bind(this));
        return facetList
    },

    setBody: function(ev, d){
        // var body;
        // var regex = /(<([^>]+)>)/ig;
        // if(d.highlighting ){
        //     body = o2.typeOf( d.highlighting ) === "array" ? d.highlighting[0] : d.highlighting;
        // }
        // if( !body && d._summary_){
        //     body = o2.typeOf( d._summary_ ) === "array" ? d._summary_.join("") : d._summary_;
        // }
U
unknown 已提交
167
        ev.target.set("html", d.highlighting || d.summary || "")
U
unknown 已提交
168 169 170 171 172 173 174 175 176 177 178 179
    },
    setSummary: function(ev, d){
        var body;
        if( !body && d._summary_){
            body = o2.typeOf( d._summary_ ) === "array" ? d._summary_.join("") : d._summary_;
        }
        if( body ){
            ev.target.set("text", body)
        }else{
            ev.target.getParent().hide();
        }
    },
U
unknown 已提交
180 181 182
    // openWork: function(id, event, row){
    //     o2.api.page.openWork(id);
    // },
U
unknown 已提交
183
    openWork: function(id, event, row){
U
unknown 已提交
184 185 186 187 188 189
        var appId = "process.Work"+id;
        var op = {
            "jobId": id,
            "appId": appId
        };
        return layout.desktop.openApplication(this.event, "process.Work", op);
U
unknown 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
    },
    openDoc: function(id, event, row){
        debugger;
        o2.api.page.openDocument(id);
    },
    loadDocList: function(data){
        this.docListNode.empty();
        this.docListNode.loadHtml(this.path+this.options.style+"/docList.html",
            {
                "bind": {"lp": this.app.lp, "data": data},
                "module": this,
                "reload": true
            },
            function(){

            }.bind(this)
        );
    },
    loadDocPagination: function(){
        this.docPaginationNode.empty();
        this.docPaging = new o2.widget.Paging(this.docPaginationNode, {
            style: "blue_round",
            countPerPage: this.pageSize,
            visiblePages: 9,
            currentPage: 1,
            itemSize: this.docTotal,
            useMainColor: true,
            text: {
                firstPage: this.app.lp.firstPage,
                lastPage: this.app.lp.lastPage
            },
            // pageSize: pageSize,
            onJumpingPage: function (pageNum) {
                this._search(pageNum);
            }.bind(this)
        });
        this.docPaging.load();
    },
    loadCondition: function( json ){
        var lp = this.app.lp;
        json.each(function(d){
U
unknown 已提交
231
            d.label = lp[d.field.toString()] || d.field;
U
unknown 已提交
232 233 234
            d.valueCountPairList.each(function (v) {
                v.field = d.field;
                v.parentLabel = d.label;
U
unknown 已提交
235 236
                if( ["category","completed"].contains(d.field)){
                    v.label = lp[v.value.toString()] || v.value;
U
unknown 已提交
237 238 239 240 241 242 243 244 245
                }else{
                    v.label = v.value;
                }
            });
        });
        this.conditionArea.empty();
        json = json.filter(function(d){
            return d.valueCountPairList && d.valueCountPairList.length;
        });
U
unknown 已提交
246 247 248
        json.each(function(d, i){
            d.index = i;
        });
U
unknown 已提交
249 250
        this.conditionArea.loadHtml(this.path+this.options.style+"/condition.html",
            {
U
unknown 已提交
251 252 253 254
                "bind": {"lp": this.app.lp, "data": json, status: {
                        collapseCondition: this.collapseCondition,
                        showSwitch: json.length > 1
                    }},
U
unknown 已提交
255 256 257 258 259 260 261 262 263
                "module": this,
                "reload": true
            },
            function(){

            }.bind(this)
        );
        // }.bind(this));
    },
U
unknown 已提交
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
    switchCondition: function(){
        this.collapseCondition = !this.collapseCondition;
        if( this.collapseCondition ){
            this.switchNode.getElement("i").addClass( 'o2icon-chevron-thin-down' ).removeClass('o2icon-chevron-thin-up');
            this.switchNode.getElement("span").set("text", this.app.lp.expandCondition);
            this.conditionNode.getElements(".item").each(function (item, index) {
                item.setStyle("display", index ? "none": "")
            })
        }else{
            this.switchNode.getElement("i").removeClass( 'o2icon-chevron-thin-down' ).addClass('o2icon-chevron-thin-up');
            this.switchNode.getElement("span").set("text", this.app.lp.collapseCondition);
            this.conditionNode.getElements(".item").each(function (item, index) {
                item.setStyle("display", "");
            })
        }
        MWF.UD.putData("ftsearchCollapseCondition", this.collapseCondition.toString(), null,);
    },
U
unknown 已提交
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
    loadSelectedCondition: function(){
        this.conditionSelectedArea.empty();
        this.conditionSelectedArea.loadHtml(this.path+this.options.style+"/conditionSelected.html",
            {
                "bind": {"lp": this.app.lp, "data": this.selectedConditionList},
                "module": this,
                "reload": true
            },
            function(){

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

    iconOver: function(e){
        e.target.addClass('mainColor_color');
    },
    iconOut: function(e){
        e.target.removeClass('mainColor_color');
    },

    inputOver: function(e){
        this.app.getEventTarget(e, "view_inputArea").addClass('mainColor_border');
    },
    inputOut: function(e){
        this.app.getEventTarget(e, "view_inputArea").removeClass('mainColor_border');
    },

    loadMultiSelectConditionItem: function(e, row){
        if( this.curMultiSelectNode ){
            this.curMultiSelectNode.empty();
            this.curMultiSelectNode.hide();
            this.curMultiSelectItemNode.show();
        }
        this.curMultiSelectConditionList = [];
        this.curMultiSelectItemNode = e.target.getParent(".item");
        this.curMultiSelectItemNode.hide();
        this.curMultiSelectNode = this.curMultiSelectItemNode.getParent().getElement(".item-multiselect").show();
        this.curMultiSelectNode.loadHtml(this.path+this.options.style+"/conditionItem_multiselect.html",
            {
                "bind": {"lp": this.app.lp, "data": row},
                "module": this,
                "reload": true
            },
            function(){}.bind(this)
        );
    },
    multiSelect: function(e, item){
        var target = this.app.getEventTarget(e, "subItem-content");
        var index = -1;
        this.curMultiSelectConditionList.each(function (cond, idx) {
            if( cond.field === item.field && cond.value === item.value )index = idx;
        });
        if( index > -1 ){ //已经选择了
            target.getElement("i.checkbox").removeClass("o2icon-check_box").addClass("o2icon-check_box_outline_blank").removeClass("mainColor_color");
            this.curMultiSelectConditionList.splice(index, 1);
        }else{ //还没有选择
            target.getElement("i.checkbox").removeClass("o2icon-check_box_outline_blank").addClass("o2icon-check_box").addClass("mainColor_color");
            this.curMultiSelectConditionList.push(item);
        }
    },
    okMultiSelect: function(e, item){
        if(!this.curMultiSelectConditionList.length){
            this.app.notice(this.app.lp.selectConditionNote, "info");
            return;
        }
        var object = {
            field: this.curMultiSelectConditionList[0].field,
            parentLabel: this.curMultiSelectConditionList[0].parentLabel,
            valueList: [],
            labelList: []
        };
        this.curMultiSelectConditionList.each(function(cond){
            object.valueList.push(cond.value);
            object.labelList.push(cond.label);
        })

        this.changeCondition(e, object)
    },
    cancelMultiSelect: function(e, item){
        if( this.curMultiSelectNode ){
            this.curMultiSelectItemNode.show();
            this.curMultiSelectNode.empty();
            this.curMultiSelectNode.hide();
        }
    },

    checkAllSwitchButton: function(e){
        if(this.conditionNode)this.conditionNode.getElements(".item").each(function(itemNode){
            var more = itemNode.getElement(".switch-button");
            var ul = itemNode.getElement(".subitem-wrap");
            if( 41 < ul.scrollHeight ){
                more.show();
            }else{
                more.hide();
            }
        });
    },
    checkSwitchButton: function(e){
        var p = e.target.getParent();
        var more = p.getElement(".switch-button");
        var ul = p.getElement(".subitem-wrap");
        if( 41 < ul.scrollHeight ){
            more.show();
        }else{
            more.hide();
        }
    },
    switchConditionItem: function(e){
        var more = this.app.getEventTarget(e, "switch-button");
        var ul = more.getParent().getElement(".subitem-wrap");
        if( ul.retrieve("expand") ){
            ul.removeClass("subitem-wrap_expand");
            more.getElement("i").addClass("o2icon-triangle_down").removeClass("o2icon-triangle_up");
            more.getElement("span").innerText = this.app.lp.more;
            ul.store("expand", false);
        }else{
            ul.addClass("subitem-wrap_expand");
            more.getElement("i").addClass("o2icon-triangle_up").removeClass("o2icon-triangle_down");
            more.getElement("span").innerText = this.app.lp.collapse;
            ul.store("expand", true);
        }
    },
    changeCondition: function(e, item){
        var index = -1;
        this.selectedConditionList.each(function (cond, idx) {
            if( cond.field === item.field )index = idx;
        });
        if( index > -1 ) { //已经选择了
            this.selectedConditionList.splice(index, 1);
        }else{
            this.selectedConditionList.push(item);
        }
        this.loadSelectedCondition();
        this._search();
    },
    changeSingleCondition: function(e, item){
        var itemIndex = -1, valueIndex = -1;
        this.selectedConditionList.each(function (cond, idx) {
            if( cond.field === item.field ){
                itemIndex = idx;
                valueIndex = cond.valueList.indexOf(item.value);
            }
        });
        if( valueIndex > -1 ){ //已经选择了
            e.target.removeClass('mainColor_bg');
            e.target.store("selected", false);
            this.selectedConditionList[itemIndex].valueList.splice(valueIndex, 1);
            this.selectedConditionList[itemIndex].labelList.splice(valueIndex, 1);
            if( !this.selectedConditionList[itemIndex].valueList.length ){
                this.selectedConditionList.splice(itemIndex, 1);
            }
            this.loadSelectedCondition();
        }else{ //还没有选择
            e.target.removeClass('mainColor_bg_opacity');
            e.target.addClass('mainColor_bg');
            e.target.store("selected", true);
            if( itemIndex > -1 ){
                this.selectedConditionList[itemIndex].valueList.push(item.value);
                this.selectedConditionList[itemIndex].labelList.push(item.label);
            }else{
                this.selectedConditionList.push({
                    field: item.field,
                    parentLabel: item.parentLabel,
                    valueList: [item.value],
                    labelList: [item.label]
                });
            }
            this.loadSelectedCondition();
        }
        this._search();
    },
    subConditionOver: function(e){
        if(!e.target.retrieve("selected"))e.target.addClass('mainColor_bg_opacity');
    },
    subConditionOut: function(e){
        if(!e.target.retrieve("selected"))e.target.removeClass('mainColor_bg_opacity');
    },
    subConditionOver_multi: function(e){
        var target = this.app.getEventTarget(e, "subItem-content");
        if(!target.retrieve("selected"))target.addClass('mainColor_bg_opacity');
    },
    subConditionOut_multi: function(e){
        var target = this.app.getEventTarget(e, "subItem-content");
        if(!target.retrieve("selected"))target.removeClass('mainColor_bg_opacity');
    },
    removeSelectedConditionItem: function(e, item){
        this.changeCondition(e, item);
    },
    conditionSelectedOver: function(e){
        this.app.getEventTarget(e, "item").getElement("i").addClass("icon_over");
    },
    conditionSelectedOut: function(e){
        this.app.getEventTarget(e, "item").getElement("i").removeClass("icon_over");
    },
    mainColorOver: function (className, e) {
        var target = this.app.getEventTarget(e, className);
        if(target)target.addClass('mainColor_color');
    },
    mainColorOut: function (className, e) {
        var target = this.app.getEventTarget(e, className);
        if(target)target.removeClass('mainColor_color');
    }

});