SearchResultLayoutView.js 61.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**
 * 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',
21
    'table-dragger',
22
    'hbs!tmpl/search/SearchResultLayoutView_tmpl',
23 24 25 26
    'modules/Modal',
    'models/VEntity',
    'utils/Utils',
    'utils/Globals',
27
    'collection/VSearchList',
28
    'models/VCommon',
29
    'utils/CommonViewFunction',
30 31
    'utils/Messages',
    'utils/Enums',
32 33 34
    'utils/UrlLinks',
    'platform'
], function(require, Backbone, tableDragger, SearchResultLayoutViewTmpl, Modal, VEntity, Utils, Globals, VSearchList, VCommon, CommonViewFunction, Messages, Enums, UrlLinks, platform) {
35 36
    'use strict';

37 38
    var SearchResultLayoutView = Backbone.Marionette.LayoutView.extend(
        /** @lends SearchResultLayoutView */
39
        {
40
            _viewName: 'SearchResultLayoutView',
41

42
            template: SearchResultLayoutViewTmpl,
43 44 45 46 47

            /** Layout sub regions */
            regions: {
                RTagLayoutView: "#r_tagLayoutView",
                RSearchLayoutView: "#r_searchLayoutView",
48
                REntityTableLayoutView: "#r_searchResultTableLayoutView",
49
                RSearchQuery: '#r_searchQuery'
50 51 52 53 54
            },

            /** ui selector cache */
            ui: {
                tagClick: '[data-id="tagClick"]',
55
                termClick: '[data-id="termClick"]',
56
                addTag: '[data-id="addTag"]',
57
                addTerm: '[data-id="addTerm"]',
58 59
                paginationDiv: '[data-id="paginationDiv"]',
                previousData: "[data-id='previousData']",
60
                nextData: "[data-id='nextData']",
61
                pageRecordText: "[data-id='pageRecordText']",
62
                addAssignTag: "[data-id='addAssignTag']",
63
                addAssignTerm: "[data-id='addAssignTerm']",
64
                createEntity: "[data-id='createEntity']",
65
                checkDeletedEntity: "[data-id='checkDeletedEntity']",
66 67
                checkSubClassification: "[data-id='checkSubClassification']",
                checkSubType: "[data-id='checkSubType']",
68
                colManager: "[data-id='colManager']",
69
                containerCheckBox: "[data-id='containerCheckBox']",
70 71 72 73
                columnEmptyInfo: "[data-id='columnEmptyInfo']",
                showPage: "[data-id='showPage']",
                gotoPage: "[data-id='gotoPage']",
                gotoPagebtn: "[data-id='gotoPagebtn']",
74
                activePage: "[data-id='activePage']"
75 76 77
            },
            templateHelpers: function() {
                return {
78
                    entityCreate: Globals.entityCreate,
79
                    searchType: this.searchType,
80
                    fromView: this.fromView,
81
                    isGlossaryView: this.fromView == "glossary",
82
                    isSearchTab: Utils.getUrlState.isSearchTab()
83
                };
84 85 86
            },
            /** ui events hash */
            events: function() {
87 88
                var events = {},
                    that = this;
89
                events["click " + this.ui.tagClick] = function(e) {
90
                    var scope = $(e.currentTarget);
91 92 93
                    if (e.target.nodeName.toLocaleLowerCase() == "i") {
                        this.onClickTagCross(e);
                    } else {
94 95 96 97 98 99 100
                        this.triggerUrl({
                            url: '#!/tag/tagAttribute/' + scope.text(),
                            urlParams: null,
                            mergeBrowserUrl: false,
                            trigger: true,
                            updateTabState: null
                        });
101 102
                    }
                };
103 104 105 106 107 108 109
                events["click " + this.ui.termClick] = function(e) {
                    var scope = $(e.currentTarget);
                    if (e.target.nodeName.toLocaleLowerCase() == "i") {
                        this.onClickTermCross(e);
                    } else {
                        this.triggerUrl({
                            url: '#!/glossary/' + scope.find('i').data('termguid'),
110
                            urlParams: { gType: "term", viewType: "term", fromView: "entity" },
111 112 113 114 115 116
                            mergeBrowserUrl: false,
                            trigger: true,
                            updateTabState: null
                        });
                    }
                };
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
                events["keyup " + this.ui.gotoPage] = function(e) {
                    var code = e.which,
                        goToPage = parseInt(e.currentTarget.value);
                    if (e.currentTarget.value) {
                        that.ui.gotoPagebtn.attr('disabled', false);
                    } else {
                        that.ui.gotoPagebtn.attr('disabled', true);
                    }
                    if (code == 13) {
                        if (e.currentTarget.value) {
                            that.gotoPagebtn();
                        }
                    }
                };
                events["change " + this.ui.showPage] = 'changePageLimit';
                events["click " + this.ui.gotoPagebtn] = 'gotoPagebtn';
133
                events["click " + this.ui.addTag] = 'onClickAddTag';
134
                events["click " + this.ui.addTerm] = 'onClickAddTermBtn';
135 136
                events["click " + this.ui.addAssignTag] = 'onClickAddTag';
                events["click " + this.ui.addAssignTerm] = 'onClickAddTermBtn';
137 138
                events["click " + this.ui.nextData] = "onClicknextData";
                events["click " + this.ui.previousData] = "onClickpreviousData";
139
                events["click " + this.ui.createEntity] = 'onClickCreateEntity';
140 141 142
                events["click " + this.ui.checkDeletedEntity] = 'onCheckExcludeIncludeResult';
                events["click " + this.ui.checkSubClassification] = 'onCheckExcludeIncludeResult';
                events["click " + this.ui.checkSubType] = 'onCheckExcludeIncludeResult';
143 144 145
                return events;
            },
            /**
146
             * intialize a new SearchResultLayoutView Layout
147 148 149
             * @constructs
             */
            initialize: function(options) {
150
                _.extend(this, _.pick(options, 'value', 'guid', 'initialView', 'isTypeTagNotExists', 'classificationDefCollection', 'entityDefCollection', 'typeHeaders', 'searchVent', 'enumDefCollection', 'tagCollection', 'searchTableColumns', 'isTableDropDisable', 'fromView', 'glossaryCollection', 'termName'));
151
                this.entityModel = new VEntity();
152
                this.searchCollection = new VSearchList();
153
                this.limit = 25;
154
                this.asyncFetchCounter = 0;
155
                this.offset = 0;
156
                this.bindEvents();
157
                this.multiSelectEntity = [];
158
                this.searchType = 'Basic Search';
159
                this.columnOrder = null;
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
                if (this.value) {
                    if (this.value.searchType && this.value.searchType == 'dsl') {
                        this.searchType = 'Advanced Search';
                    }
                    if (this.value.pageLimit) {
                        var pageLimit = parseInt(this.value.pageLimit, 10);
                        if (_.isNaN(pageLimit) || pageLimit == 0 || pageLimit <= -1) {
                            this.value.pageLimit = this.limit;
                            this.triggerUrl();
                        } else {
                            this.limit = pageLimit;
                        }
                    }
                    if (this.value.pageOffset) {
                        var pageOffset = parseInt(this.value.pageOffset, 10);
                        if (_.isNaN(pageOffset) || pageLimit <= -1) {
                            this.value.pageOffset = this.offset;
                            this.triggerUrl();
                        } else {
                            this.offset = pageOffset;
                        }
                    }
182 183 184
                };
                if (platform.name === "IE") {
                    this.isTableDropDisable = true;
185
                }
186 187
            },
            bindEvents: function() {
188
                var that = this;
189
                this.onClickLoadMore();
190
                this.listenTo(this.searchCollection, 'backgrid:selected', function(model, checked) {
191
                    this.multiSelectEntity = [];
192 193 194 195 196 197 198
                    if (checked === true) {
                        model.set("isEnable", true);
                    } else {
                        model.set("isEnable", false);
                    }
                    this.searchCollection.find(function(item) {
                        if (item.get('isEnable')) {
199
                            var obj = item.toJSON();
200
                            that.multiSelectEntity.push({
201 202
                                id: obj.guid,
                                model: obj
203 204 205
                            });
                        }
                    });
206

207 208
                    if (this.multiSelectEntity.length > 0) {
                        this.$('.multiSelectTag,.multiSelectTerm').show();
209
                    } else {
210
                        this.$('.multiSelectTag,.multiSelectTerm').hide();
211
                    }
212
                });
213
                this.listenTo(this.searchCollection, "error", function(model, response) {
214 215
                    this.hideLoader({ type: 'error' });
                    var responseJSON = response && response.responseJSON ? response.responseJSON : null,
216
                        errorText = (responseJSON && (responseJSON.errorMessage || responseJSON.message || responseJSON.error)) || 'Invalid Expression';
217
                    if (errorText) {
218
                        Utils.notifyError({
219
                            content: errorText
220
                        });
221
                        this.$('.searchTable > .well').html('<center>' + errorText + '</center>')
222
                    }
223
                }, this);
224 225 226
                this.listenTo(this.searchCollection, "state-changed", function(state) {
                    if (Utils.getUrlState.isSearchTab()) {
                        this.updateColumnList(state);
227 228
                        var excludeDefaultColumn = [];
                        if (this.value && this.value.type) {
229
                            excludeDefaultColumn = _.without(this.searchTableColumns[this.value.type], "selected", "name", "description", "typeName", "owner", "tag", "term");
230 231 232 233 234
                            if (this.searchTableColumns[this.value.type] === null) {
                                this.ui.columnEmptyInfo.show();
                            } else {
                                this.ui.columnEmptyInfo.hide();
                            }
235
                        }
236
                        this.columnOrder = this.getColumnOrder(this.REntityTableLayoutView.$el.find('.colSort th.renderable'));
237
                        this.triggerUrl();
238
                        var attributes = this.searchCollection.filterObj.attributes;
239
                        if ((excludeDefaultColumn && attributes) && (excludeDefaultColumn.length > attributes.length || _.difference(excludeDefaultColumn, attributes).length)) {
240 241
                            this.fetchCollection(this.value);
                        }
242 243
                    }
                }, this);
244 245 246
                this.listenTo(this.searchVent, "search:refresh", function(model, response) {
                    this.fetchCollection();
                }, this);
247 248 249
                this.listenTo(this.searchCollection, "backgrid:sorted", function(model, response) {
                    this.checkTableFetch();
                }, this)
250 251
            },
            onRender: function() {
252 253 254 255 256 257 258 259 260
                var that = this;
                this.commonTableOptions = {
                    collection: this.searchCollection,
                    includePagination: false,
                    includeFooterRecords: false,
                    includeColumnManager: (Utils.getUrlState.isSearchTab() && this.value && this.value.searchType === "basic" && !this.value.profileDBView ? true : false),
                    includeOrderAbleColumns: false,
                    includeSizeAbleColumns: false,
                    includeTableLoader: false,
261
                    includeAtlasTableSorting: true,
262 263 264 265 266 267
                    columnOpts: {
                        opts: {
                            initialColumnsVisible: null,
                            saveState: false
                        },
                        visibilityControlOpts: {
268
                            buttonTemplate: _.template("<button class='btn btn-action btn-sm pull-right'>Columns&nbsp<i class='fa fa-caret-down'></i></button>")
269 270 271 272
                        },
                        el: this.ui.colManager
                    },
                    gridOpts: {
273
                        emptyText: 'No Records found!',
274
                        className: 'table table-hover backgrid table-quickMenu colSort'
275 276 277 278
                    },
                    filterOpts: {},
                    paginatorOpts: {}
                };
279 280 281 282 283
                if (!this.initialView) {
                    var value = {},
                        that = this;
                    if (this.value) {
                        value = this.value;
284 285 286
                        if (value && value.includeDE) {
                            this.ui.checkDeletedEntity.prop('checked', true);
                        }
287 288 289 290 291 292 293
                        if (value && value.excludeSC) {
                            this.ui.checkSubClassification.prop('checked', true);
                        }
                        if (value && value.excludeST) {
                            this.ui.checkSubType.prop('checked', true);
                        }

294 295
                    } else {
                        value = {
296
                            'query': null,
297
                            'searchType': 'basic'
298 299
                        };
                    }
300
                    this.updateColumnList();
301 302 303 304 305
                    if (this.value && this.searchTableColumns && this.searchTableColumns[this.value.type] === null) {
                        this.ui.columnEmptyInfo.show();
                    } else {
                        this.ui.columnEmptyInfo.hide();
                    }
306
                    this.fetchCollection(value, _.extend({ 'fromUrl': true }, (this.value && this.value.pageOffset ? { 'next': true } : null)));
307 308 309 310 311 312 313 314 315
                    this.ui.showPage.select2({
                        data: _.sortBy(_.union([25, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500], [this.limit])),
                        tags: true,
                        dropdownCssClass: "number-input",
                        multiple: false
                    });
                    if (this.value && this.value.pageLimit) {
                        this.ui.showPage.val(this.limit).trigger('change', { "skipViewChange": true });
                    }
316 317 318
                } else {
                    if (Globals.entityTypeConfList) {
                        this.$(".entityLink").show();
319
                    }
320 321 322 323 324
                    if (this.isTypeTagNotExists) {
                        Utils.notifyError({
                            content: Messages.search.notExists
                        });
                    }
325 326
                }
            },
327 328 329 330 331 332
            getColumnOrderWithPosition: function() {
                var that = this;
                return _.map(that.columnOrder, function(value, key) {
                    return key + "::" + value;
                }).join(",");
            },
333 334 335
            triggerUrl: function(options) {
                Utils.setUrl(_.extend({
                    url: Utils.getUrlState.getQueryUrl().queyParams[0],
336
                    urlParams: this.columnOrder ? _.extend(this.value, { 'uiParameters': this.getColumnOrderWithPosition() }) : this.value,
337 338 339 340
                    mergeBrowserUrl: false,
                    trigger: false,
                    updateTabState: true
                }, options));
341
            },
342 343
            updateColumnList: function(updatedList) {
                if (updatedList) {
344
                    var listOfColumns = [];
345 346 347 348 349 350
                    _.map(updatedList, function(obj) {
                        var key = obj.name;
                        if (obj.renderable) {
                            listOfColumns.push(obj.name);
                        }
                    });
351
                    listOfColumns = _.sortBy(listOfColumns);
352
                    this.value.attributes = listOfColumns.length ? listOfColumns.join(",") : null;
353
                    if (this.value && this.value.type && this.searchTableColumns) {
354 355 356 357
                        this.searchTableColumns[this.value.type] = listOfColumns.length ? listOfColumns : null;
                    }
                } else if (this.value && this.value.type && this.searchTableColumns && this.value.attributes) {
                    this.searchTableColumns[this.value.type] = this.value.attributes.split(",");
358 359
                }
            },
360
            fetchCollection: function(value, options) {
361
                var that = this,
362 363 364 365 366 367
                    isPostMethod = (this.value && this.value.searchType === "basic"),
                    isSearchTab = Utils.getUrlState.isSearchTab(),
                    tagFilters = null,
                    entityFilters = null;
                if (isSearchTab) {
                    tagFilters = CommonViewFunction.attributeFilter.generateAPIObj(this.value.tagFilters);
368
                    entityFilters = CommonViewFunction.attributeFilter.generateAPIObj(this.value.entityFilters);
369 370 371
                }

                if (isPostMethod && isSearchTab) {
372
                    var excludeDefaultColumn = this.value.type && this.searchTableColumns ? _.without(this.searchTableColumns[this.value.type], "selected", "name", "description", "typeName", "owner", "tag") : null,
373 374 375 376 377 378 379
                        filterObj = {
                            'entityFilters': entityFilters,
                            'tagFilters': tagFilters,
                            'attributes': excludeDefaultColumn ? excludeDefaultColumn : null
                        };
                }

380
                this.showLoader();
381
                if (Globals.searchApiCallRef && Globals.searchApiCallRef.readyState === 1) {
382 383
                    Globals.searchApiCallRef.abort();
                }
384
                var apiObj = {
385
                    skipDefaultError: true,
386
                    sort: false,
387
                    success: function(dataOrCollection, response) {
388 389 390
                        if (that.isDestroyed) {
                            return;
                        }
391 392 393
                        that.ui.gotoPage.val('');
                        that.ui.gotoPage.parent().removeClass('has-error');
                        that.ui.gotoPagebtn.prop("disabled", true);
394
                        Globals.searchApiCallRef = undefined;
395 396 397
                        var isFirstPage = that.offset === 0,
                            dataLength = 0,
                            goToPage = that.ui.gotoPage.val();
398 399 400
                        if (!(that.ui.pageRecordText instanceof jQuery)) {
                            return;
                        }
401 402 403 404 405 406 407
                        if (isPostMethod && dataOrCollection && dataOrCollection.entities) {
                            dataLength = dataOrCollection.entities.length;
                        } else {
                            dataLength = dataOrCollection.length;
                        }

                        if (!dataLength && that.offset >= that.limit && ((options && options.next) || goToPage) && (options && !options.fromUrl)) {
408
                            /* User clicks on next button and server returns
409 410
                            empty response then disabled the next button without rendering table*/

411
                            that.hideLoader();
412 413 414
                            var pageNumber = that.activePage + 1;
                            if (goToPage) {
                                pageNumber = goToPage;
415
                                that.offset = (that.activePage - 1) * that.limit;
416 417 418 419 420 421 422 423 424 425 426 427
                            } else {
                                that.ui.nextData.attr('disabled', true);
                                that.offset = that.offset - that.limit;
                            }
                            if (that.value) {
                                that.value.pageOffset = that.offset;
                                that.triggerUrl();
                            }
                            Utils.notifyInfo({
                                html: true,
                                content: Messages.search.noRecordForPage + '<b>' + Utils.getNumberSuffix({ number: pageNumber, sup: true }) + '</b> page'
                            });
428 429
                            return;
                        }
430
                        if (isPostMethod) {
431 432 433 434
                            Utils.findAndMergeRefEntity({
                                attributeObject: dataOrCollection.entities,
                                referredEntities: dataOrCollection.referredEntities
                            });
435 436 437
                            that.searchCollection.referredEntities = dataOrCollection.referredEntities;
                            that.searchCollection.entities = dataOrCollection.entities;
                            that.searchCollection.reset(dataOrCollection.entities, { silent: true });
438
                        }
439

440

441
                        /*Next button check.
442
                        It's outside of Previous button else condition
443 444
                        because when user comes from 2 page to 1 page than we need to check next button.*/
                        if (dataLength < that.limit) {
445 446 447 448
                            that.ui.nextData.attr('disabled', true);
                        } else {
                            that.ui.nextData.attr('disabled', false);
                        }
449 450 451 452 453 454 455 456 457 458

                        if (isFirstPage && (!dataLength || dataLength < that.limit)) {
                            that.ui.paginationDiv.hide();
                        } else {
                            that.ui.paginationDiv.show();
                        }

                        // Previous button check.
                        if (isFirstPage) {
                            that.ui.previousData.attr('disabled', true);
459 460
                            that.pageFrom = 1;
                            that.pageTo = that.limit;
461 462 463 464 465
                        } else {
                            that.ui.previousData.attr('disabled', false);
                        }

                        if (options && options.next) {
466 467 468
                            //on next click, adding "1" for showing the another records.
                            that.pageTo = that.offset + that.limit;
                            that.pageFrom = that.offset + 1;
469
                        } else if (!isFirstPage && options && options.previous) {
470 471 472
                            that.pageTo = that.pageTo - that.limit;
                            that.pageFrom = (that.pageTo - that.limit) + 1;
                        }
473
                        that.ui.pageRecordText.html("Showing  <u>" + that.searchCollection.models.length + " records</u> From " + that.pageFrom + " - " + that.pageTo);
474 475 476
                        that.activePage = Math.round(that.pageTo / that.limit);
                        that.ui.activePage.attr('title', "Page " + that.activePage);
                        that.ui.activePage.text(that.activePage);
477
                        that.renderTableLayoutView();
478
                        if (dataLength > 0) {
479 480
                            that.$('.searchTable').removeClass('noData')
                        }
481
                        if (Utils.getUrlState.isSearchTab() && value && !value.profileDBView) {
482
                            var searchString = 'Results for: <span class="filterQuery">' + CommonViewFunction.generateQueryOfFilter(that.value) + "</span>";
483 484 485 486
                            if (Globals.entityCreate && Globals.entityTypeConfList && Utils.getUrlState.isSearchTab()) {
                                searchString += "<p>If you do not find the entity in search result below then you can" + '<a href="javascript:void(0)" data-id="createEntity"> create new entity</a></p>';
                            }
                            that.$('.searchResult').html(searchString);
487
                        }
488
                    },
489 490
                    silent: true,
                    reset: true
491
                }
492 493 494 495
                if (this.value) {
                    var checkBoxValue = {
                        'excludeDeletedEntities': (this.value.includeDE ? false : true),
                        'includeSubClassifications': (this.value.excludeSC ? false : true),
496
                        'includeSubTypes': (this.value.excludeST ? false : true),
497
                        'includeClassificationAttributes': true // server will return classication details with guid
498 499
                    }
                }
500 501 502 503
                if (value) {
                    if (value.searchType) {
                        this.searchCollection.url = UrlLinks.searchApiUrl(value.searchType);
                    }
504
                    _.extend(this.searchCollection.queryParams, { 'limit': this.limit, 'offset': this.offset, 'query': _.trim(value.query), 'typeName': value.type || null, 'classification': value.tag || null, 'termName': value.term || null });
505
                    if (value.profileDBView && value.typeName && value.guid) {
506 507
                        var profileParam = {};
                        profileParam['guid'] = value.guid;
508
                        profileParam['relation'] = value.typeName === 'hive_db' ? '__hive_table.db' : '__hbase_table.namespace';
509 510
                        profileParam['sortBy'] = 'name';
                        profileParam['sortOrder'] = 'ASCENDING';
511
                        _.extend(this.searchCollection.queryParams, profileParam);
512
                    }
513
                    if (isPostMethod) {
514
                        this.searchCollection.filterObj = _.extend({}, filterObj);
515
                        apiObj['data'] = _.extend(checkBoxValue, filterObj, _.pick(this.searchCollection.queryParams, 'query', 'excludeDeletedEntities', 'limit', 'offset', 'typeName', 'classification', 'termName'))
516 517 518
                        Globals.searchApiCallRef = this.searchCollection.getBasicRearchResult(apiObj);
                    } else {
                        apiObj.data = null;
519
                        this.searchCollection.filterObj = null;
520
                        if (this.value.profileDBView) {
521
                            _.extend(this.searchCollection.queryParams, checkBoxValue);
522
                        }
523 524 525 526
                        Globals.searchApiCallRef = this.searchCollection.fetch(apiObj);
                    }
                } else {
                    if (isPostMethod) {
527
                        apiObj['data'] = _.extend(checkBoxValue, filterObj, _.pick(this.searchCollection.queryParams, 'query', 'excludeDeletedEntities', 'limit', 'offset', 'typeName', 'classification', 'termName'));
528 529 530
                        Globals.searchApiCallRef = this.searchCollection.getBasicRearchResult(apiObj);
                    } else {
                        apiObj.data = null;
531
                        if (this.value.profileDBView) {
532
                            _.extend(this.searchCollection.queryParams, checkBoxValue);
533
                        }
534 535 536
                        Globals.searchApiCallRef = this.searchCollection.fetch(apiObj);
                    }
                }
537

538 539 540 541 542 543 544 545
            },
            renderSearchQueryView: function() {
                var that = this;
                require(['views/search/SearchQueryView'], function(SearchQueryView) {
                    that.RSearchQuery.show(new SearchQueryView({
                        value: that.value,
                        searchVent: that.searchVent
                    }));
546
                });
547
            },
548 549 550 551 552
            tableRender: function(options) {
                var that = this,
                    savedColumnOrder = options.order,
                    TableLayout = options.table,
                    columnCollection = Backgrid.Columns.extend({
553
                        sortKey: "displayOrder",
554
                        className: "my-awesome-css-animated-grid",
555 556 557 558 559
                        comparator: function(item) {
                            return item.get(this.sortKey) || 999;
                        },
                        setPositions: function() {
                            _.each(this.models, function(model, index) {
560
                                model.set("displayOrder", (savedColumnOrder == null ? index : parseInt(savedColumnOrder[model.get('label')])) + 1, { silent: true });
561 562 563 564
                            });
                            return this;
                        }
                    });
565 566 567 568 569
                var columns = new columnCollection((that.searchCollection.dynamicTable ? that.getDaynamicColumns(that.searchCollection.toJSON()) : that.getFixedDslColumn()));
                columns.setPositions().sort();
                var table = new TableLayout(_.extend({}, that.commonTableOptions, {
                    columns: columns
                }));
570
                if (table.collection.length === 0) {
571
                    that.$(".searchTable").addClass('noData');
572
                }
573 574 575 576 577 578 579 580 581
                if (!that.REntityTableLayoutView) {
                    return;
                }
                that.REntityTableLayoutView.show(table);
                if (that.value.searchType !== "dsl") {
                    that.ui.containerCheckBox.show();
                } else {
                    that.ui.containerCheckBox.hide();
                }
582
                that.$(".ellipsis-with-margin .inputAssignTag").hide();
583 584 585 586 587 588 589 590 591
                table.trigger("grid:refresh"); /*Event fire when table rendered*/
                // that.REntityTableLayoutView.$el.find('.colSort thead tr th:not(:first)').addClass('dragHandler');
                if (that.isTableDropDisable !== true) {
                    var tableDropFunction = function(from, to, el) {
                        tableDragger(document.querySelector(".colSort")).destroy();
                        that.columnOrder = that.getColumnOrder(el.querySelectorAll('th.renderable'));
                        that.triggerUrl();
                        that.tableRender({ "order": that.columnOrder, "table": TableLayout });
                        that.checkTableFetch();
592
                    }
593
                    that.REntityTableLayoutView.$el.find('.colSort thead tr th:not(.select-all-header-cell)').addClass('dragHandler');
594 595 596 597 598 599 600 601 602 603 604
                    tableDragger(document.querySelector(".colSort"), { dragHandler: ".dragHandler" }).on('drop', tableDropFunction);
                }
            },
            renderTableLayoutView: function(col) {
                var that = this;
                require(['utils/TableLayout'], function(TableLayout) {
                    // displayOrder added for column manager
                    if (that.value.uiParameters) {
                        var savedColumnOrder = _.object(that.value.uiParameters.split(',').map(function(a) {
                            return a.split('::');
                        })); // get Column position from string to object
605
                    }
606 607

                    that.tableRender({ "order": savedColumnOrder, "table": TableLayout });
608
                    that.checkTableFetch();
609 610
                });
            },
611 612 613
            getColumnOrder: function(arr) {
                var obj = {};
                for (var i = 0; i < arr.length; ++i) {
614 615
                    var innerText = arr[i].innerText.trim();
                    obj[(innerText == "" ? 'Select' : innerText)] = i;
616 617 618
                }
                return obj;
            },
619
            checkTableFetch: function() {
620
                if (this.asyncFetchCounter <= 0) {
621
                    this.hideLoader();
622 623
                    Utils.generatePopover({
                        el: this.$('[data-id="showMoreLess"]'),
624
                        contentClass: 'popover-tag-term',
625
                        viewFixedPopover: true,
626
                        popoverOptions: {
627
                            container: null,
628
                            content: function() {
629
                                return $(this).find('.popup-tag-term').children().clone();
630 631 632
                            }
                        }
                    });
633 634
                }
            },
635 636
            getFixedDslColumn: function() {
                var that = this,
637
                    nameCheck = 0,
638
                    columnToShow = null,
639
                    col = {};
640
                if (this.value && this.value.searchType === "basic" && this.searchTableColumns && (this.searchTableColumns[this.value.type] !== undefined)) {
641 642
                    columnToShow = this.searchTableColumns[this.value.type] == null ? [] : this.searchTableColumns[this.value.type];
                }
643

644 645
                col['Check'] = {
                    name: "selected",
646
                    label: "Select",
647
                    cell: "select-row",
648 649
                    resizeable: false,
                    orderable: false,
650
                    renderable: (columnToShow ? _.contains(columnToShow, 'selected') : true),
651 652
                    headerCell: "select-all"
                };
653

654

655
                col['name'] = {
656
                    label: this.value && this.value.profileDBView ? "Table Name" : "Name",
657 658
                    cell: "html",
                    editable: false,
659
                    resizeable: true,
660
                    orderable: false,
661
                    renderable: true,
662 663 664
                    className: "searchTableName",
                    formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
                        fromRaw: function(rawValue, model) {
665 666 667
                            var obj = model.toJSON(),
                                nameHtml = "",
                                name = Utils.getName(obj);
668
                            if (obj.guid) {
669 670 671 672 673
                                if (obj.guid == "-1") {
                                    nameHtml = '<span title="' + name + '">' + name + '</span>';
                                } else {
                                    nameHtml = '<a title="' + name + '" href="#!/detailPage/' + obj.guid + (that.fromView ? "?from=" + that.fromView : "") + '">' + name + '</a>';
                                }
674
                            } else {
675
                                nameHtml = '<span title="' + name + '">' + name + '</span>';
676 677
                            }
                            if (obj.status && Enums.entityStateReadOnly[obj.status]) {
678
                                nameHtml += '<button type="button" title="Deleted" class="btn btn-action btn-md deleteBtn"><i class="fa fa-trash"></i></button>';
679
                                nameHtml = '<div class="readOnly readOnlyLink">' + nameHtml + '</div>';
680
                            }
681 682 683 684 685
                            var getImageData = function(options) {
                                var imagePath = options.imagePath,
                                    returnImgUrl = null;
                                $.ajax({
                                        "url": imagePath,
686 687
                                        "method": "get",
                                        "cache": true
688 689 690 691 692 693 694 695
                                    })
                                    .always(function(data, status, xhr) {
                                        if (data.status == 404) {
                                            returnImgUrl = getImageData({
                                                "imagePath": Utils.getEntityIconPath({ entityData: obj, errorUrl: imagePath })
                                            });
                                        } else if (data) {
                                            returnImgUrl = imagePath;
696
                                            that.$("img[data-imgGuid='" + obj.guid + "']").removeClass("searchTableLogoLoader").attr("src", imagePath);
697 698 699
                                        }
                                    });
                            }
700
                            var img = "",
701 702 703 704
                                isIncompleteClass = "isIncomplete search-result-page";
                            if (obj.isIncomplete === true) {
                                isIncompleteClass += " show";
                            }
705 706
                            img = "<div class='" + isIncompleteClass + "'><img data-imgGuid='" + obj.guid + "' class='searchTableLogoLoader'><i class='fa fa-hourglass-half'></i></div>";
                            getImageData({ imagePath: Utils.getEntityIconPath({ entityData: obj }) });
707
                            return (img + nameHtml);
708 709 710
                        }
                    })
                };
711

712 713
                col['owner'] = {
                    label: "Owner",
714 715
                    cell: "String",
                    editable: false,
716 717 718
                    resizeable: true,
                    orderable: true,
                    renderable: true,
719 720
                    formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
                        fromRaw: function(rawValue, model) {
721
                            var obj = model.toJSON();
722 723
                            if (obj && obj.attributes && obj.attributes.owner) {
                                return obj.attributes.owner;
724 725 726
                            }
                        }
                    })
727
                };
728 729


730 731 732 733 734 735 736 737 738 739 740 741 742
                if (this.value && this.value.profileDBView) {
                    col['createTime'] = {
                        label: "Date Created",
                        cell: "Html",
                        editable: false,
                        formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
                            fromRaw: function(rawValue, model) {
                                var obj = model.toJSON();
                                if (obj && obj.attributes && obj.attributes.createTime) {
                                    return new Date(obj.attributes.createTime);
                                } else {
                                    return '-'
                                }
743
                            }
744 745 746 747
                        })
                    }
                }
                if (this.value && !this.value.profileDBView) {
748

749 750 751 752 753 754 755 756 757 758 759 760 761
                    col['description'] = {
                        label: "Description",
                        cell: "String",
                        editable: false,
                        resizeable: true,
                        orderable: true,
                        renderable: true,
                        formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
                            fromRaw: function(rawValue, model) {
                                var obj = model.toJSON();
                                if (obj && obj.attributes && obj.attributes.description) {
                                    return obj.attributes.description;
                                }
762
                            }
763 764
                        })
                    };
765 766


767 768 769 770 771 772 773 774 775 776 777 778 779
                    col['typeName'] = {
                        label: "Type",
                        cell: "Html",
                        editable: false,
                        resizeable: true,
                        orderable: true,
                        renderable: (columnToShow ? _.contains(columnToShow, 'typeName') : true),
                        formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
                            fromRaw: function(rawValue, model) {
                                var obj = model.toJSON();
                                if (obj && obj.typeName) {
                                    return '<a title="Search ' + obj.typeName + '" href="#!/search/searchResult?query=' + obj.typeName + ' &searchType=dsl&dslChecked=true">' + obj.typeName + '</a>';
                                }
780
                            }
781 782
                        })
                    };
783
                    this.getTagCol({ 'col': col, 'columnToShow': columnToShow });
784
                    if ((!_.contains(["glossary"], this.fromView))) {
785 786
                        this.getTermCol({ 'col': col, 'columnToShow': columnToShow });
                    }
787

788 789 790 791 792 793
                    if (this.value && this.value.searchType === "basic") {
                        var def = this.entityDefCollection.fullCollection.find({ name: this.value.type });
                        if (def) {
                            var attrObj = Utils.getNestedSuperTypeObj({ data: def.toJSON(), collection: this.entityDefCollection, attrMerge: true });
                            _.each(attrObj, function(obj, key) {
                                var key = obj.name,
794 795
                                    isRenderable = _.contains(columnToShow, key),
                                    isSortable = obj.typeName.search(/(array|map)/i) == -1;
796 797 798 799 800 801 802
                                if (key == "name" || key == "description" || key == "owner") {
                                    if (columnToShow) {
                                        col[key].renderable = isRenderable;
                                    }
                                    return;
                                }
                                col[obj.name] = {
803
                                    label: _.escape(obj.name).capitalize(),
804
                                    cell: "Html",
805
                                    headerCell: Backgrid.HeaderHTMLDecodeCell,
806 807 808
                                    editable: false,
                                    resizeable: true,
                                    orderable: true,
809
                                    sortable: isSortable,
810 811 812 813 814 815 816 817 818 819
                                    renderable: isRenderable,
                                    formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
                                        fromRaw: function(rawValue, model) {
                                            var modelObj = model.toJSON();
                                            if (modelObj && modelObj.attributes && !_.isUndefined(modelObj.attributes[key])) {
                                                var tempObj = {
                                                    'scope': that,
                                                    'attributeDefs': [obj],
                                                    'valueObject': {},
                                                    'isTable': false
820 821
                                                };
                                                tempObj.valueObject[key] = modelObj.attributes[key];
822 823 824 825 826 827 828 829 830
                                                var tablecolumn = CommonViewFunction.propertyTable(tempObj);
                                                if (_.isArray(modelObj.attributes[key])) {
                                                    var column = $("<div>" + tablecolumn + "</div>")
                                                    if (tempObj.valueObject[key].length > 2) {
                                                        column.addClass("toggleList semi-collapsed").append("<span><a data-id='load-more-columns'>Show More</a></span>");
                                                    }
                                                    return column;
                                                }
                                                return tablecolumn;
831 832 833 834 835 836 837 838 839 840
                                            }
                                        }
                                    })
                                };
                            });
                        }
                    }
                }
                return this.searchCollection.constructor.getTableCols(col, this.searchCollection);
            },
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
            onClickLoadMore: function() {
                var that = this;
                this.$el.on('click', "[data-id='load-more-columns']", function(event) {
                    event.stopPropagation();
                    event.stopImmediatePropagation();
                    var $this = $(this),
                        $toggleList = $(this).parents('.toggleList');
                    if ($toggleList.length) {
                        if ($toggleList.hasClass('semi-collapsed')) {
                            $toggleList.removeClass('semi-collapsed');
                            $this.text("Show Less");
                        } else {
                            $toggleList.addClass('semi-collapsed');
                            $this.text("Show More");
                        }
                    }
                });
            },
859 860 861 862 863 864
            getDaynamicColumns: function(valueObj) {
                var that = this,
                    col = {};
                if (valueObj && valueObj.length) {
                    var firstObj = _.first(valueObj);
                    _.each(_.keys(firstObj), function(key) {
865 866 867 868 869 870 871 872 873 874 875 876 877
                        col[key] = {
                            label: key.capitalize(),
                            cell: "Html",
                            editable: false,
                            resizeable: true,
                            orderable: true,
                            formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
                                fromRaw: function(rawValue, model) {
                                    var modelObj = model.toJSON();
                                    if (key == "name") {
                                        var nameHtml = "",
                                            name = modelObj[key];
                                        if (modelObj.guid) {
878
                                            nameHtml = '<a title="' + name + '" href="#!/detailPage/' + modelObj.guid + (that.fromView ? "?from=" + that.fromView : "") + '">' + name + '</a>';
879 880 881 882 883 884
                                        } else {
                                            nameHtml = '<span title="' + name + '">' + name + '</span>';
                                        }
                                        if (modelObj.status && Enums.entityStateReadOnly[modelObj.status]) {
                                            nameHtml += '<button type="button" title="Deleted" class="btn btn-action btn-md deleteBtn"><i class="fa fa-trash"></i></button>';
                                            return '<div class="readOnly readOnlyLink">' + nameHtml + '</div>';
885
                                        }
886 887 888 889 890 891 892 893 894 895
                                        return nameHtml;
                                    } else if (modelObj && !_.isUndefined(modelObj[key])) {
                                        var tempObj = {
                                            'scope': that,
                                            // 'attributeDefs':
                                            'valueObject': {},
                                            'isTable': false
                                        };
                                        tempObj.valueObject[key] = modelObj[key];
                                        return CommonViewFunction.propertyTable(tempObj);
896
                                    }
897 898 899
                                }
                            })
                        };
900 901 902 903
                    });
                }
                return this.searchCollection.constructor.getTableCols(col, this.searchCollection);
            },
904
            getTagCol: function(options) {
905 906 907 908
                var that = this,
                    columnToShow = options.columnToShow,
                    col = options.col;
                if (col) {
909
                    col['tag'] = {
910
                        label: "Classifications",
911 912 913
                        cell: "Html",
                        editable: false,
                        sortable: false,
914
                        resizeable: true,
915
                        orderable: true,
916 917
                        renderable: (columnToShow ? _.contains(columnToShow, 'tag') : true),
                        className: 'searchTag',
918 919
                        formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
                            fromRaw: function(rawValue, model) {
920
                                var obj = model.toJSON();
921 922 923
                                if (obj.guid == "-1") {
                                    return
                                }
924
                                if (obj.status && Enums.entityStateReadOnly[obj.status]) {
925
                                    return '<div class="readOnly">' + CommonViewFunction.tagForTable(obj); + '</div>';
926
                                } else {
927
                                    return CommonViewFunction.tagForTable(obj);
928
                                }
929

930 931 932
                            }
                        })
                    };
933
                }
934
            },
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
            getTermCol: function(options) {
                var that = this,
                    columnToShow = options.columnToShow,
                    col = options.col;
                if (col) {
                    col['term'] = {
                        label: "Term",
                        cell: "Html",
                        editable: false,
                        sortable: false,
                        resizeable: true,
                        orderable: true,
                        renderable: (columnToShow ? _.contains(columnToShow, 'term') : true),
                        className: 'searchTag',
                        formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
                            fromRaw: function(rawValue, model) {
                                var obj = model.toJSON();
952 953 954
                                if (obj.guid == "-1") {
                                    return
                                }
955
                                if (obj.typeName && !(_.startsWith(obj.typeName, "AtlasGlossary"))) {
956 957 958 959 960
                                    if (obj.status && Enums.entityStateReadOnly[obj.status]) {
                                        return '<div class="readOnly">' + CommonViewFunction.termForTable(obj); + '</div>';
                                    } else {
                                        return CommonViewFunction.termForTable(obj);
                                    }
961 962 963 964 965 966
                                }
                            }
                        })
                    };
                }
            },
967
            addTagModalView: function(guid, multiple) {
968
                var that = this;
969
                require(['views/tag/AddTagModalView'], function(AddTagModalView) {
970
                    var view = new AddTagModalView({
971 972
                        guid: guid,
                        multiple: multiple,
973
                        callback: function() {
974 975
                            that.multiSelectEntity = [];
                            that.$('.multiSelectTag,.multiSelectTerm').hide();
976
                            that.fetchCollection();
977
                        },
978
                        tagList: that.getTagList(guid, multiple),
979
                        showLoader: that.showLoader.bind(that),
980
                        hideLoader: that.hideLoader.bind(that),
981
                        collection: that.classificationDefCollection,
982
                        enumDefCollection: that.enumDefCollection
983 984 985
                    });
                });
            },
986 987 988
            getTagList: function(guid, multiple) {
                var that = this;
                if (!multiple || multiple.length === 0) {
989 990
                    var model = this.searchCollection.find(function(item) {
                        var obj = item.toJSON();
991 992 993 994
                        if (obj.guid === guid) {
                            return true;
                        }
                    });
995
                    if (model) {
996
                        var obj = model.toJSON();
997 998 999
                    } else {
                        return [];
                    }
1000 1001 1002 1003 1004
                    return _.compact(_.map(obj.classifications, function(val) {
                        if (val.entityGuid == guid) {
                            return val.typeName
                        }
                    }));
1005 1006 1007 1008
                } else {
                    return [];
                }
            },
1009
            showLoader: function() {
1010 1011
                this.$('.fontLoader:not(.for-ignore)').addClass('show');
                this.$('.tableOverlay').addClass('show');
1012
            },
1013
            hideLoader: function(options) {
1014
                this.$('.fontLoader:not(.for-ignore)').removeClass('show');
1015
                options && options.type === 'error' ? this.$('.ellipsis-with-margin,.pagination-box').hide() : this.$('.ellipsis-with-margin,.pagination-box').show(); // only show for first time and hide when type is error
1016
                this.$('.tableOverlay').removeClass('show');
1017
            },
1018
            onClickAddTag: function(e) {
1019
                var guid = "",
1020
                    that = this,
1021
                    isTagMultiSelect = $(e.currentTarget).hasClass('multiSelectTag');
1022 1023
                if (isTagMultiSelect && this.multiSelectEntity && this.multiSelectEntity.length) {
                    that.addTagModalView(guid, this.multiSelectEntity);
1024
                } else {
1025 1026
                    guid = that.$(e.currentTarget).data("guid");
                    that.addTagModalView(guid);
1027 1028
                }
            },
1029 1030
            onClickAddTermBtn: function(e) {
                var that = this,
1031
                    guid = "",
1032
                    entityGuid = $(e.currentTarget).data("guid"),
1033 1034 1035 1036 1037 1038
                    associatedTerms = undefined,
                    multiple = undefined,
                    isTermMultiSelect = $(e.currentTarget).hasClass('multiSelectTerm');
                if (isTermMultiSelect && this.multiSelectEntity && this.multiSelectEntity.length) {
                    multiple = this.multiSelectEntity;
                } else if (entityGuid) {
1039
                    associatedTerms = this.searchCollection.find({ guid: entityGuid }).get('meanings');
1040
                }
1041 1042 1043
                require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
                    var view = new AssignTermLayoutView({
                        guid: entityGuid,
1044
                        multiple: multiple,
1045
                        associatedTerms: associatedTerms,
1046
                        callback: function() {
1047 1048
                            that.multiSelectEntity = [];
                            that.$('.multiSelectTag,.multiSelectTerm').hide();
1049
                            that.fetchCollection();
1050

1051 1052 1053 1054 1055
                        },
                        glossaryCollection: that.glossaryCollection,
                    });
                });
            },
1056
            onClickTagCross: function(e) {
1057 1058
                var that = this,
                    tagName = $(e.target).data("name"),
1059
                    guid = $(e.target).data("guid"),
1060
                    entityGuid = $(e.target).data("entityguid"),
1061 1062 1063 1064
                    assetName = $(e.target).data("assetname");
                CommonViewFunction.deleteTag({
                    tagName: tagName,
                    guid: guid,
1065
                    associatedGuid: guid != entityGuid ? entityGuid : null,
1066
                    msg: "<div class='ellipsis-with-margin'>Remove: " + "<b>" + _.escape(tagName) + "</b> assignment from" + " " + "<b>" + assetName + " ?</b></div>",
1067 1068 1069 1070 1071 1072 1073 1074 1075
                    titleMessage: Messages.removeTag,
                    okText: "Remove",
                    showLoader: that.showLoader.bind(that),
                    hideLoader: that.hideLoader.bind(that),
                    callback: function() {
                        that.fetchCollection();
                    }
                });

1076
            },
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
            onClickTermCross: function(e) {
                var $el = $(e.target),
                    termGuid = $el.data('termguid'),
                    guid = $el.data('guid'),
                    termName = $(e.currentTarget).text(),
                    assetname = $el.data('assetname'),
                    meanings = this.searchCollection.find({ "guid": guid }).get("meanings"),
                    that = this,
                    termObj = _.find(meanings, { termGuid: termGuid });
                CommonViewFunction.removeCategoryTermAssociation({
                    termGuid: termGuid,
                    model: {
                        guid: guid,
                        relationshipGuid: termObj.relationGuid
                    },
                    collection: that.glossaryCollection,
1093
                    msg: "<div class='ellipsis-with-margin'>Remove: " + "<b>" + _.escape(termName) + "</b> assignment from" + " " + "<b>" + assetname + "?</b></div>",
1094 1095 1096 1097 1098 1099 1100 1101
                    titleMessage: Messages.glossary.removeTermfromEntity,
                    isEntityView: true,
                    buttonText: "Remove",
                    callback: function() {
                        that.fetchCollection();
                    }
                });
            },
1102
            onClicknextData: function() {
1103 1104 1105
                this.offset = this.offset + this.limit;
                _.extend(this.searchCollection.queryParams, {
                    offset: this.offset
1106
                });
1107 1108 1109 1110
                if (this.value) {
                    this.value.pageOffset = this.offset;
                    this.triggerUrl();
                }
1111 1112 1113
                this.fetchCollection(null, {
                    next: true
                });
1114 1115
            },
            onClickpreviousData: function() {
1116 1117 1118 1119 1120 1121
                this.offset = this.offset - this.limit;
                if (this.offset <= -1) {
                    this.offset = 0;
                }
                _.extend(this.searchCollection.queryParams, {
                    offset: this.offset
1122
                });
1123 1124 1125 1126
                if (this.value) {
                    this.value.pageOffset = this.offset;
                    this.triggerUrl();
                }
1127 1128 1129
                this.fetchCollection(null, {
                    previous: true
                });
1130
            },
1131 1132 1133 1134 1135 1136 1137
            onClickCreateEntity: function(e) {
                var that = this;
                $(e.currentTarget).blur();
                require([
                    'views/entity/CreateEntityLayoutView'
                ], function(CreateEntityLayoutView) {
                    var view = new CreateEntityLayoutView({
1138
                        entityDefCollection: that.entityDefCollection,
1139
                        typeHeaders: that.typeHeaders,
1140 1141 1142 1143 1144
                        callback: function() {
                            that.fetchCollection();
                        }
                    });
                });
1145
            },
1146 1147 1148
            onCheckExcludeIncludeResult: function(e) {
                var flag = false,
                    val = $(e.currentTarget).attr('data-value');
1149
                if (e.target.checked) {
1150
                    flag = true;
1151
                }
1152
                if (this.value) {
1153
                    this.value[val] = flag;
1154
                    this.triggerUrl();
1155
                }
1156
                _.extend(this.searchCollection.queryParams, { limit: this.limit, offset: this.offset });
1157
                this.fetchCollection();
1158

1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201
            },
            changePageLimit: function(e, obj) {
                if (!obj || (obj && !obj.skipViewChange)) {
                    var limit = parseInt(this.ui.showPage.val());
                    if (limit == 0) {
                        this.ui.showPage.data('select2').$container.addClass('has-error');
                        return;
                    } else {
                        this.ui.showPage.data('select2').$container.removeClass('has-error');
                    }
                    this.limit = limit;
                    this.offset = 0;
                    if (this.value) {
                        this.value.pageLimit = this.limit;
                        this.value.pageOffset = this.offset;
                        this.triggerUrl();
                    }
                    _.extend(this.searchCollection.queryParams, { limit: this.limit, offset: this.offset });
                    this.fetchCollection();
                }
            },
            gotoPagebtn: function(e) {
                var that = this;
                var goToPage = parseInt(this.ui.gotoPage.val());
                if (!(_.isNaN(goToPage) || goToPage <= -1)) {
                    this.offset = (goToPage - 1) * this.limit;
                    if (this.offset <= -1) {
                        this.offset = 0;
                    }
                    _.extend(this.searchCollection.queryParams, { limit: this.limit, offset: this.offset });
                    if (this.offset == (this.pageFrom - 1)) {
                        Utils.notifyInfo({
                            content: Messages.search.onSamePage
                        });
                    } else {
                        if (this.value) {
                            this.value.pageOffset = this.offset;
                            this.triggerUrl();
                        }
                        // this.offset is updated in gotoPagebtn function so use next button calculation.
                        this.fetchCollection(null, { 'next': true });
                    }
                }
1202
            }
1203
        });
1204
    return SearchResultLayoutView;
1205
});