SearchLayoutView.js 33.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

define(['require',
    'backbone',
    'hbs!tmpl/search/SearchLayoutView_tmpl',
    'utils/Utils',
23 24
    'utils/UrlLinks',
    'utils/Globals',
25
    'utils/Enums',
26
    'collection/VSearchList',
27
    'utils/CommonViewFunction'
28
], function(require, Backbone, SearchLayoutViewTmpl, Utils, UrlLinks, Globals, Enums, VSearchList, CommonViewFunction) {
29 30 31 32 33 34 35 36 37 38
    'use strict';

    var SearchLayoutView = Backbone.Marionette.LayoutView.extend(
        /** @lends SearchLayoutView */
        {
            _viewName: 'SearchLayoutView',

            template: SearchLayoutViewTmpl,

            /** Layout sub regions */
39 40 41 42
            regions: {
                RSaveSearchBasic: "[data-id='r_saveSearchBasic']",
                RSaveSearchAdvance: "[data-id='r_saveSearchAdvance']"
            },
43 44 45 46

            /** ui selector cache */
            ui: {
                searchInput: '[data-id="searchInput"]',
47 48
                searchType: 'input[name="queryType"]',
                searchBtn: '[data-id="searchBtn"]',
49
                clearSearch: '[data-id="clearSearch"]',
50
                typeLov: '[data-id="typeLOV"]',
51
                tagLov: '[data-id="tagLOV"]',
52
                termLov: '[data-id="termLOV"]',
53
                refreshBtn: '[data-id="refreshBtn"]',
54 55 56
                advancedInfoBtn: '[data-id="advancedInfo"]',
                typeAttrFilter: '[data-id="typeAttrFilter"]',
                tagAttrFilter: '[data-id="tagAttrFilter"]'
57 58
            },

59 60 61 62 63 64
            /** ui events hash */
            events: function() {
                var events = {},
                    that = this;
                events["keyup " + this.ui.searchInput] = function(e) {
                    var code = e.which;
65
                    this.value.query = e.currentTarget.value;
66
                    if (code == 13) {
67
                        that.findSearchResult();
68
                    }
69
                    this.checkForButtonVisiblity();
70
                };
71 72 73
                events["change " + this.ui.searchType] = 'dslFulltextToggle';
                events["click " + this.ui.searchBtn] = 'findSearchResult';
                events["click " + this.ui.clearSearch] = 'clearSearchData';
74 75
                events["change " + this.ui.typeLov] = 'checkForButtonVisiblity';
                events["change " + this.ui.tagLov] = 'checkForButtonVisiblity';
76
                events["change " + this.ui.termLov] = 'checkForButtonVisiblity';
77
                events["click " + this.ui.refreshBtn] = 'onRefreshButton';
78
                events["click " + this.ui.advancedInfoBtn] = 'advancedInfo';
79 80 81 82 83 84
                events["click " + this.ui.typeAttrFilter] = function() {
                    this.openAttrFilter('type');
                };
                events["click " + this.ui.tagAttrFilter] = function() {
                    this.openAttrFilter('tag');
                };
85 86 87 88 89 90 91
                return events;
            },
            /**
             * intialize a new SearchLayoutView Layout
             * @constructs
             */
            initialize: function(options) {
92
                _.extend(this, _.pick(options, 'value', 'typeHeaders', 'searchVent', 'entityDefCollection', 'enumDefCollection', 'classificationDefCollection', 'searchTableColumns', 'searchTableFilters'));
93
                this.type = "basic";
94 95 96
                var param = Utils.getUrlState.getQueryParams();
                this.query = {
                    dsl: {
97
                        query: null,
98 99 100
                        type: null,
                        pageOffset: null,
                        pageLimit: null
101
                    },
102
                    basic: {
103 104
                        query: null,
                        type: null,
105
                        tag: null,
106
                        term: null,
107
                        attributes: null,
108
                        tagFilters: null,
109 110
                        pageOffset: null,
                        pageLimit: null,
111
                        entityFilters: null,
112
                        includeDE: null,
113 114
                        excludeST: null,
                        excludeSC: null
115 116
                    }
                };
117 118 119
                if (!this.value) {
                    this.value = {};
                }
120
                this.dsl = false;
121
                if (param && param.searchType) {
122 123
                    this.type = param.searchType;
                    this.updateQueryObject(param);
124
                }
125
                this.bindEvents();
126
            },
127 128
            renderSaveSearch: function() {
                var that = this;
129
                require(['views/search/save/SaveSearchView'], function(SaveSearchView) {
130 131 132 133
                    var saveSearchBaiscCollection = new VSearchList(),
                        saveSearchAdvanceCollection = new VSearchList(),
                        saveSearchCollection = new VSearchList();
                    saveSearchCollection.url = UrlLinks.saveSearchApiUrl();
134 135 136 137 138 139
                    saveSearchBaiscCollection.fullCollection.comparator = function(model) {
                        return model.get('name').toLowerCase();
                    }
                    saveSearchAdvanceCollection.fullCollection.comparator = function(model) {
                        return model.get('name').toLowerCase();
                    }
140 141 142 143 144 145 146 147 148 149 150 151 152
                    var obj = {
                        value: that.value,
                        searchVent: that.searchVent,
                        typeHeaders: that.typeHeaders,
                        fetchCollection: fetchSaveSearchCollection,
                        classificationDefCollection: that.classificationDefCollection,
                        entityDefCollection: that.entityDefCollection,
                        getValue: function() {
                            var queryObj = that.query[that.type],
                                entityObj = that.searchTableFilters['entityFilters'],
                                tagObj = that.searchTableFilters['tagFilters'],
                                urlObj = Utils.getUrlState.getQueryParams();
                            if (urlObj) {
153
                                // includeDE value in because we need to send "true","false" to the server.
154 155 156
                                urlObj.includeDE = urlObj.includeDE == "true" ? true : false;
                                urlObj.excludeSC = urlObj.excludeSC == "true" ? true : false;
                                urlObj.excludeST = urlObj.excludeST == "true" ? true : false;
157 158 159 160 161 162
                            }
                            return _.extend({}, queryObj, urlObj, {
                                'entityFilters': entityObj ? entityObj[queryObj.type] : null,
                                'tagFilters': tagObj ? tagObj[queryObj.tag] : null,
                                'type': queryObj.type,
                                'query': queryObj.query,
163
                                'term': queryObj.term,
164 165 166 167 168
                                'tag': queryObj.tag
                            })
                        },
                        applyValue: function(model, searchType) {
                            that.manualRender(_.extend(searchType, CommonViewFunction.generateUrlFromSaveSearchObject({
169
                                value: { "searchParameters": model.get('searchParameters'), 'uiParameters': model.get('uiParameters') },
170 171 172 173 174 175 176
                                classificationDefCollection: that.classificationDefCollection,
                                entityDefCollection: that.entityDefCollection
                            })));
                        }
                    }
                    that.RSaveSearchBasic.show(new SaveSearchView(_.extend(obj, {
                        isBasic: true,
177
                        collection: saveSearchBaiscCollection.fullCollection
178 179 180
                    })));
                    that.RSaveSearchAdvance.show(new SaveSearchView(_.extend(obj, {
                        isBasic: false,
181
                        collection: saveSearchAdvanceCollection.fullCollection
182 183 184 185 186
                    })));

                    function fetchSaveSearchCollection() {
                        saveSearchCollection.fetch({
                            success: function(collection, data) {
187 188
                                saveSearchAdvanceCollection.fullCollection.reset(_.where(data, { "searchType": "ADVANCED" }));
                                saveSearchBaiscCollection.fullCollection.reset(_.where(data, { "searchType": "BASIC" }));
189 190 191 192 193 194 195
                            },
                            silent: true
                        });
                    }
                    fetchSaveSearchCollection();
                });
            },
196
            bindEvents: function(param) {
197
                this.listenTo(this.typeHeaders, "reset", function(value) {
198
                    this.initializeValues();
199 200
                }, this);
            },
201 202
            initializeValues: function() {
                this.renderTypeTagList();
203
                this.renderTermList();
204 205 206 207
                this.setValues();
                this.checkForButtonVisiblity();
                this.renderSaveSearch();
            },
208 209 210 211 212 213 214 215 216 217
            makeFilterButtonActive: function(filtertypeParam) {
                var filtertype = ['entityFilters', 'tagFilters'],
                    that = this;
                if (filtertypeParam) {
                    if (_.isArray(filtertypeParam)) {
                        filtertype = filtertypeParam;
                    } else if (_.isString(filtertypeParam)) {
                        filtertype = [filtertypeParam];
                    }
                }
218
                var typeCheck = function(filterObj, type) {
219 220 221
                    if (that.value.type) {
                        if (filterObj && filterObj.length) {
                            that.ui.typeAttrFilter.addClass('active');
222
                        } else {
223
                            that.ui.typeAttrFilter.removeClass('active');
224
                        }
225 226 227 228
                        that.ui.typeAttrFilter.prop('disabled', false);
                    } else {
                        that.ui.typeAttrFilter.removeClass('active');
                        that.ui.typeAttrFilter.prop('disabled', true);
229
                    }
230
                }
231
                var tagCheck = function(filterObj, type) {
232
                    if (that.value.tag && !_.contains(Enums.addOnClassification, that.value.tag)) {
233 234 235
                        that.ui.tagAttrFilter.prop('disabled', false);
                        if (filterObj && filterObj.length) {
                            that.ui.tagAttrFilter.addClass('active');
236
                        } else {
237
                            that.ui.tagAttrFilter.removeClass('active');
238
                        }
239 240 241
                    } else {
                        that.ui.tagAttrFilter.removeClass('active');
                        that.ui.tagAttrFilter.prop('disabled', true);
242 243
                    }
                }
244
                _.each(filtertype, function(type) {
245
                    var filterObj = that.searchTableFilters[type];
246
                    if (type == "entityFilters") {
247
                        typeCheck(filterObj[that.value.type], type);
248 249
                    }
                    if (type == "tagFilters") {
250
                        tagCheck(filterObj[that.value.tag], type);
251 252
                    }
                });
253
            },
254
            checkForButtonVisiblity: function(e, options) {
255 256
                if (this.type == "basic" && e && e.currentTarget) {
                    var $el = $(e.currentTarget),
257 258 259
                        isTagEl = $el.data('id') == "tagLOV",
                        isTermEl = $el.data('id') == "termLOV",
                        isTypeEl = $el.data('id') == "typeLOV";
260 261
                    if (e.type == "change" && $el.select2('data')) {
                        var value = $el.val(),
262 263 264 265 266 267 268
                            key = "tag",
                            filterType = 'tagFilters',
                            value = value && value.length ? value : null;
                        if (!isTagEl) {
                            key = (isTermEl ? "term" : "type");
                            filterType = (isTypeEl ? "entityFilters" : null);
                        }
269
                        if (this.value) {
270 271
                            //On Change handle
                            if (this.value[key] !== value || (!value && !this.value[key])) {
272 273 274
                                var temp = {};
                                temp[key] = value;
                                _.extend(this.value, temp);
275
                                // on change of type/tag change the offset.
276 277 278
                                if (_.isUndefined(options)) {
                                    this.value.pageOffset = 0;
                                }
279
                                _.extend(this.query[this.type], temp);
280 281
                            } else {
                                // Initial loading handle.
282 283 284 285 286
                                if (filterType) {
                                    var filterObj = this.searchTableFilters[filterType];
                                    if (filterObj && this.value[key]) {
                                        this.searchTableFilters[filterType][this.value[key]] = this.value[filterType] ? this.value[filterType] : null;
                                    }
287
                                }
288

289 290 291 292 293 294 295 296 297 298 299 300 301
                                if (this.value.type) {
                                    if (this.value.attributes) {
                                        var attributes = _.sortBy(this.value.attributes.split(',')),
                                            tableColumn = this.searchTableColumns[this.value.type];
                                        if (_.isEmpty(this.searchTableColumns) || !tableColumn) {
                                            this.searchTableColumns[this.value.type] = attributes
                                        } else if (tableColumn.join(",") !== attributes.join(",")) {
                                            this.searchTableColumns[this.value.type] = attributes;
                                        }
                                    } else if (this.searchTableColumns[this.value.type]) {
                                        this.searchTableColumns[this.value.type] = undefined;
                                    }
                                }
302
                            }
303 304 305
                            if (filterType) {
                                this.makeFilterButtonActive(filterType);
                            }
306 307 308 309 310 311
                        } else {
                            this.ui.tagAttrFilter.prop('disabled', true);
                            this.ui.typeAttrFilter.prop('disabled', true);
                        }
                    }
                }
312 313
                var that = this,
                    value = this.ui.searchInput.val() || this.ui.typeLov.val();
314
                if (!this.dsl && !value) {
315
                    value = this.ui.tagLov.val() || this.ui.termLov.val();
316 317 318 319 320 321 322 323 324 325
                }
                if (value && value.length) {
                    this.ui.searchBtn.removeAttr("disabled");
                    setTimeout(function() {
                        that.ui.searchInput.focus();
                    }, 0);
                } else {
                    this.ui.searchBtn.attr("disabled", "true");
                }
            },
326 327
            onRender: function() {
                // array of tags which is coming from url
328
                this.initializeValues();
329
            },
330 331 332 333
            updateQueryObject: function(param) {
                if (param && param.searchType) {
                    this.type = param.searchType;
                }
334 335 336
                _.extend(this.query[this.type],
                    (this.type == "dsl" ? {
                        query: null,
337 338 339
                        type: null,
                        pageOffset: null,
                        pageLimit: null
340
                    } : {
341 342
                        query: null,
                        type: null,
343
                        tag: null,
344
                        term: null,
345
                        attributes: null,
346
                        tagFilters: null,
347 348
                        pageOffset: null,
                        pageLimit: null,
349
                        entityFilters: null,
350
                        includeDE: null
351
                    }), param);
352
            },
353
            fetchCollection: function(value) {
354
                this.typeHeaders.fetch({ reset: true });
355
            },
356 357
            onRefreshButton: function() {
                this.fetchCollection();
358
                //to check url query param contain type or not
359 360
                var checkURLValue = Utils.getUrlState.getQueryParams(this.url);
                if (this.searchVent && (_.has(checkURLValue, "tag") || _.has(checkURLValue, "type") || _.has(checkURLValue, "query"))) {
361 362
                    this.searchVent.trigger('search:refresh');
                }
363
            },
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
            advancedInfo: function(e) {
                require([
                    'views/search/AdvancedSearchInfoView',
                    'modules/Modal'
                ], function(AdvancedSearchInfoView, Modal) {
                    var view = new AdvancedSearchInfoView();
                    var modal = new Modal({
                        title: 'Advanced Search Queries',
                        content: view,
                        okCloses: true,
                        showFooter: true,
                        allowCancel: false
                    }).open();
                    view.on('closeModal', function() {
                        modal.trigger('cancel');
                    });
                });
            },
382 383 384 385 386 387 388 389 390 391 392
            openAttrFilter: function(filterType) {
                var that = this;
                require(['views/search/SearchQueryView'], function(SearchQueryView) {
                    that.attrModal = new SearchQueryView({
                        value: that.value,
                        tag: (filterType === "tag" ? true : false),
                        type: (filterType === "type" ? true : false),
                        searchVent: that.searchVent,
                        typeHeaders: that.typeHeaders,
                        entityDefCollection: that.entityDefCollection,
                        enumDefCollection: that.enumDefCollection,
393 394
                        classificationDefCollection: that.classificationDefCollection,
                        searchTableFilters: that.searchTableFilters
395
                    });
396 397
                    that.attrModal.on('ok', function(scope, e) {
                        that.okAttrFilterButton(e);
398 399 400
                    });
                });
            },
401
            okAttrFilterButton: function(e) {
402 403
                var isTag = this.attrModal.tag ? true : false,
                    filtertype = isTag ? 'tagFilters' : 'entityFilters',
404 405
                    queryBuilderRef = this.attrModal.RQueryBuilder.currentView.ui.builder,
                    col = [];
406 407 408
                if (queryBuilderRef.data('queryBuilder')) {
                    var rule = queryBuilderRef.queryBuilder('getRules');
                }
409
                if (rule) {
410
                    var ruleUrl = CommonViewFunction.attributeFilter.generateUrl({ "value": rule, "formatedDateToLong": true });
411
                    this.searchTableFilters[filtertype][(isTag ? this.value.tag : this.value.type)] = ruleUrl;
412
                    this.makeFilterButtonActive(filtertype);
413
                    if (!isTag && this.value && this.value.type && this.searchTableColumns) {
414 415 416
                        if (!this.searchTableColumns[this.value.type]) {
                            this.searchTableColumns[this.value.type] = ["selected", "name", "owner", "description", "tag", "typeName"]
                        }
417
                        this.searchTableColumns[this.value.type] = _.sortBy(_.union(this.searchTableColumns[this.value.type], getIdFromRuleObject(rule)));
418
                    }
419
                    this.attrModal.modal.close();
420 421
                    if ($(e.currentTarget).hasClass('search')) {
                        this.findSearchResult();
422
                    }
423 424 425 426 427 428 429 430 431 432 433

                    function getIdFromRuleObject(rule) {
                        _.map(rule.rules, function(obj, key) {
                            if (_.has(obj, 'condition')) {
                                return getIdFromRuleObject(obj);
                            } else {
                                return col.push(obj.id)
                            }
                        });
                        return col;
                    }
434 435
                }
            },
436
            manualRender: function(paramObj) {
437
                this.updateQueryObject(paramObj);
438
                this.setValues(paramObj);
439
            },
440
            renderTypeTagList: function() {
441 442
                var that = this;
                this.ui.typeLov.empty();
443 444
                var typeStr = '<option></option>',
                    tagStr = typeStr;
445
                this.typeHeaders.fullCollection.each(function(model) {
446
                    var name = Utils.getName(model.toJSON(), 'name');
447
                    if (model.get('category') == 'ENTITY') {
448
                        typeStr += '<option>' + (name) + '</option>';
449 450
                    }
                    if (model.get('category') == 'CLASSIFICATION') {
451
                        tagStr += '<option>' + (name) + '</option>';
452
                    }
453
                });
454 455 456 457
                //to insert extra classification list
                _.each(Enums.addOnClassification, function(classificationName) {
                    tagStr += '<option>' + classificationName + '</option>';
                });
458 459
                that.ui.typeLov.html(typeStr);
                that.ui.tagLov.html(tagStr);
460
                this.ui.typeLov.select2({
461
                    placeholder: "Select Type",
462 463 464
                    allowClear: true
                });
                this.ui.tagLov.select2({
465
                    placeholder: "Select Classification",
466 467
                    allowClear: true
                });
468
            },
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
            renderTermList: function() {
                var getTypeAheadData = function(data, params) {
                    var dataList = data.entities,
                        foundOptions = [];
                    _.each(dataList, function(obj) {
                        if (obj) {
                            if (obj.guid) {
                                obj['id'] = Utils.getName(obj, 'qualifiedName');
                            }
                            foundOptions.push(obj);
                        }
                    });
                    return foundOptions;
                }
                this.ui.termLov.select2({
                    placeholder: "Search Term",
                    allowClear: true,
                    ajax: {
                        url: UrlLinks.searchApiUrl('attribute'),
                        dataType: 'json',
                        delay: 250,
                        data: function(params) {
                            return {
                                attrValuePrefix: params.term, // search term
493
                                typeName: "AtlasGlossaryTerm",
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
                                limit: 10,
                                offset: 0
                            };
                        },
                        processResults: function(data, params) {
                            return {
                                results: getTypeAheadData(data, params)
                            };
                        },
                        cache: true
                    },
                    templateResult: function(option) {
                        var name = Utils.getName(option, 'qualifiedName');
                        return name === "-" ? option.text : name;
                    },
                    templateSelection: function(option) {
                        var name = Utils.getName(option, 'qualifiedName');
                        return name === "-" ? option.text : name;
                    },
                    escapeMarkup: function(markup) {
                        return markup;
                    },
                    minimumInputLength: 1
                });
            },
519
            setValues: function(paramObj) {
520 521
                var arr = [],
                    that = this;
522 523 524 525
                if (paramObj) {
                    this.value = paramObj;
                }
                if (this.value) {
526
                    this.ui.searchInput.val(this.value.query || "");
527
                    if (this.value.dslChecked == "true") {
528 529 530
                        if (!this.ui.searchType.prop("checked")) {
                            this.ui.searchType.prop("checked", true).trigger("change");
                        }
531
                    } else {
532 533 534
                        if (this.ui.searchType.prop("checked")) {
                            this.ui.searchType.prop("checked", false).trigger("change");
                        }
535
                    }
536
                    this.ui.typeLov.val(this.value.type);
537
                    if (this.ui.typeLov.data('select2')) {
538 539
                        if (this.ui.typeLov.val() !== this.value.type) {
                            this.value.type = null;
540
                            this.ui.typeLov.val("").trigger("change", { 'manual': true });
541
                        } else {
542
                            this.ui.typeLov.trigger("change", { 'manual': true });
543
                        }
544
                    }
545

546
                    if (!this.dsl) {
547
                        this.ui.tagLov.val(this.value.tag);
548
                        if (this.ui.tagLov.data('select2')) {
549 550 551
                            // To handle delete scenario.
                            if (this.ui.tagLov.val() !== this.value.tag) {
                                this.value.tag = null;
552
                                this.ui.tagLov.val("").trigger("change", { 'manual': true });
553
                            } else {
554
                                this.ui.tagLov.trigger("change", { 'manual': true });
555
                            }
556
                        }
557 558 559
                        if (this.value.term) {
                            this.ui.termLov.append('<option value="' + this.value.term + '" selected="selected">' + this.value.term + '</option>');
                        }
560 561 562 563 564 565 566 567
                        if (this.ui.termLov.data('select2')) {
                            if (this.ui.termLov.val() !== this.value.term) {
                                this.value.term = null;
                                this.ui.termLov.val("").trigger("change", { 'manual': true });
                            } else {
                                this.ui.termLov.trigger("change", { 'manual': true });
                            }
                        }
568
                    }
569 570 571
                    setTimeout(function() {
                        that.ui.searchInput.focus();
                    }, 0);
572 573 574
                }
            },
            findSearchResult: function() {
575 576 577
                this.triggerSearch(this.ui.searchInput.val());
            },
            triggerSearch: function(value) {
578 579
                var params = {
                    searchType: this.type,
580 581 582
                    dslChecked: this.ui.searchType.is(':checked'),
                    tagFilters: null,
                    entityFilters: null
583
                }
584
                params['type'] = this.ui.typeLov.select2('val') || null;
585
                if (!this.dsl) {
586
                    params['tag'] = this.ui.tagLov.select2('val') || null;
587
                    params['term'] = this.ui.termLov.select2('val') || null;
588 589 590 591 592 593 594 595
                    var entityFilterObj = this.searchTableFilters['entityFilters'],
                        tagFilterObj = this.searchTableFilters['tagFilters'];
                    if (this.value.tag) {
                        params['tagFilters'] = tagFilterObj[this.value.tag]
                    }
                    if (this.value.type) {
                        params['entityFilters'] = entityFilterObj[this.value.type]
                    }
596
                    var columnList = this.value && this.value.type && this.searchTableColumns ? this.searchTableColumns[this.value.type] : null;
597
                    if (columnList) {
598
                        params['attributes'] = columnList.join(',');
599
                    }
600 601 602
                    params['includeDE'] = _.isUndefinedNull(this.value.includeDE) ? false : this.value.includeDE;
                    params['excludeST'] = _.isUndefinedNull(this.value.excludeST) ? false : this.value.excludeST;
                    params['excludeSC'] = _.isUndefinedNull(this.value.excludeSC) ? false : this.value.excludeSC;
603
                }
604
                if (!_.isUndefinedNull(this.value.pageLimit)) {
605
                    params['pageLimit'] = this.value.pageLimit;
606
                }
607 608
                if (!_.isUndefinedNull(this.value.pageOffset)) {
                    if (!_.isUndefinedNull(this.query[this.type]) && this.query[this.type].query != value) {
609
                        params['pageOffset'] = 0;
610
                    } else {
611
                        params['pageOffset'] = this.value.pageOffset;
612 613
                    }
                }
614 615
                params['query'] = value || null;
                _.extend(this.query[this.type], params);
616 617
                Utils.setUrl({
                    url: '#!/search/searchResult',
618
                    urlParams: _.extend({}, this.query[this.type]),
619
                    mergeBrowserUrl: false,
620 621
                    trigger: true,
                    updateTabState: true
622 623 624
                });
            },
            dslFulltextToggle: function(e) {
625
                var paramObj = Utils.getUrlState.getQueryParams();
626 627 628
                if (paramObj && this.type == paramObj.searchType) {
                    this.updateQueryObject(paramObj);
                }
629 630
                if (e.currentTarget.checked) {
                    this.type = "dsl";
631
                    this.dsl = true;
632 633 634
                    this.$('.typeFilterBtn,.tagBox,.termBox,.basicSaveSearch').hide();
                    this.$('.typeFilter').addClass('col-sm-12');
                    this.$('.typeFilter').removeClass('col-sm-10');
635
                    this.$('.advanceSaveSearch').show();
636 637
                    this.$('.searchText').text('Search By Query');
                    this.ui.searchInput.attr("placeholder", 'Search By Query eg. where name="sales_fact"');
638
                } else {
639 640 641
                    this.$('.typeFilter').addClass('col-sm-10');
                    this.$('.typeFilter').removeClass('col-sm-12');
                    this.$('.typeFilterBtn,.tagBox,.termBox,.basicSaveSearch').show();
642
                    this.$('.advanceSaveSearch').hide();
643
                    this.dsl = false;
644
                    this.type = "basic";
645 646
                    this.$('.searchText').text('Search By Text');
                    this.ui.searchInput.attr("placeholder", "Search By Text");
647
                }
648 649 650 651 652
                if (Utils.getUrlState.isSearchTab()) {
                    Utils.setUrl({
                        url: '#!/search/searchResult',
                        urlParams: _.extend(this.query[this.type], {
                            searchType: this.type,
653
                            dslChecked: this.ui.searchType.is(':checked')
654 655
                        }),
                        mergeBrowserUrl: false,
656 657
                        trigger: true,
                        updateTabState: true
658
                    });
659
                }
660 661
            },
            clearSearchData: function() {
662
                this.updateQueryObject();
663
                this.ui.typeLov.val("").trigger("change");
664
                this.ui.tagLov.val("").trigger("change");
665
                this.ui.searchInput.val("");
666 667 668 669 670 671
                var type = "basicSaveSearch";
                if (this.type == "dsl") {
                    type = "advanceSaveSearch";
                }
                this.$('.' + type + ' .saveSearchList').find('li.active').removeClass('active');
                this.$('.' + type + ' [data-id="saveBtn"]').attr('disabled', true);
672
                if (!this.dsl) {
673 674 675
                    this.searchTableFilters.tagFilters = {};
                    this.searchTableFilters.entityFilters = {};
                }
676
                this.checkForButtonVisiblity();
677
                Utils.setUrl({
678 679 680 681 682
                    url: '#!/search/searchResult',
                    urlParams: {
                        searchType: this.type,
                        dslChecked: this.ui.searchType.is(':checked')
                    },
683 684 685
                    mergeBrowserUrl: false,
                    trigger: true
                });
686
            }
687 688
        });
    return SearchLayoutView;
689
});