VSearchList.js 3.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**
 * 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',
    'utils/Globals',
    'collection/BaseCollection',
22 23 24
    'models/VSearch',
    'utils/UrlLinks'
], function(require, Globals, BaseCollection, VSearch, UrlLinks) {
25 26 27 28
    'use strict';
    var VSearchList = BaseCollection.extend(
        //Prototypal attributes
        {
29
            url: UrlLinks.searchApiUrl(),
30 31 32

            model: VSearch,

33 34
            initialize: function(options) {
                _.extend(this, options);
35
                this.modelName = 'VSearchList';
36
                this.modelAttrName = '';
37 38
            },
            parseRecords: function(resp, options) {
39 40
                this.queryType = resp.queryType;
                this.queryText = resp.queryText;
41
                this.referredEntities = resp.referredEntities;
42
                if (resp.attributes) {
43
                    this.dynamicTable = true;
44 45
                    var entities = [];
                    _.each(resp.attributes.values, function(obj) {
46 47 48 49 50 51 52
                        var temp = {};
                        _.each(obj, function(val, index) {
                            var key = resp.attributes.name[index];
                            if (key == "__guid") {
                                key = "guid"
                            }
                            temp[key] = val;
53 54 55 56
                        });
                        entities.push(temp);
                    });
                    return entities;
57
                } else if (resp.entities) {
58
                    this.dynamicTable = false;
59
                    return resp.entities ? resp.entities : [];
60
                } else {
61
                    return [];
62
                }
63
            },
64 65 66 67 68 69 70 71 72 73
            getExpimpAudit: function(params, options) {
                var url = UrlLinks.expimpAudit(params);

                options = _.extend({
                    contentType: 'application/json',
                    dataType: 'json',
                }, options);

                return this.constructor.nonCrudOperation.call(this, url, 'GET', options);
            },
74 75 76 77 78 79 80 81 82 83 84
            getBasicRearchResult: function(options) {
                var url = UrlLinks.searchApiUrl('basic');

                options = _.extend({
                    contentType: 'application/json',
                    dataType: 'json',
                }, options);
                options.data = JSON.stringify(options.data);

                return this.constructor.nonCrudOperation.call(this, url, 'POST', options);
            }
85 86 87 88 89 90 91 92 93 94 95 96
        },
        //Static Class Members
        {
            /**
             * Table Cols to be passed to Backgrid
             * UI has to use this as base and extend this.
             *
             */
            tableCols: {}
        }
    );
    return VSearchList;
97
});