main.js 10.5 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.
 */

require.config({
    /* starting point for application */
21 22 23
    'hbs': {
        'disableI18n': true, // This disables the i18n helper and doesn't require the json i18n files (e.g. en_us.json)
        'helperPathCallback': // Callback to determine the path to look for helpers
24
            function(name) { // ('/template/helpers/'+name by default)
25 26
                return 'modules/Helpers';
            },
27 28
        'templateExtension': 'html', // Set the extension automatically appended to templates
        'compileOptions': {} // options object which is passed to Handlebars compiler
29
    },
30
    'urlArgs': "bust=" + getBustValue(),
31 32 33 34 35 36 37
    /**
     * Requested as soon as the loader has processed the configuration. It does
     * not block any other require() calls from starting their requests for
     * modules, it is just a way to specify some modules to load asynchronously
     * as part of a config block.
     * @type {Array} An array of dependencies to load.
     */
38
    'deps': ['marionette'],
39 40 41 42 43 44

    /**
     * The number of seconds to wait before giving up on loading a script.
     * @default 7 seconds
     * @type {Number}
     */
45
    'waitSeconds': 30,
46

47 48 49 50
    'shim': {
        'backbone': {
            'deps': ['underscore', 'jquery'],
            'exports': 'Backbone'
51
        },
52
        'jquery-ui': {
53
            'deps': ['jquery']
54
        },
55 56 57
        'asBreadcrumbs': {
            'deps': ['jquery'],
            'exports': 'asBreadcrumbs'
58
        },
59 60 61
        'bootstrap': {
            'deps': ['jquery'],
            'exports': 'jquery'
62
        },
63 64
        'underscore': {
            'exports': '_'
65
        },
66 67
        'marionette': {
            'deps': ['backbone']
68
        },
69 70 71
        'backgrid': {
            'deps': ['backbone'],
            'exports': 'Backgrid'
72 73
        },
        'backgrid-paginator': {
74
            'deps': ['backbone', 'backgrid']
75 76
        },
        'backgrid-filter': {
77
            'deps': ['backbone', 'backgrid']
78 79
        },
        'backgrid-orderable': {
80
            'deps': ['backbone', 'backgrid'],
81 82
        },
        'backgrid-sizeable': {
83
            'deps': ['backbone', 'backgrid'],
84
        },
85
        'backgrid-select-all': {
86
            'deps': ['backbone', 'backgrid']
87
        },
88 89 90
        'backgrid-columnmanager': {
            'deps': ['backbone', 'backgrid'],
        },
91 92
        'hbs': {
            'deps': ['underscore', 'handlebars']
93
        },
94 95
        'd3': {
            'exports': ['d3']
96 97
        },
        'd3-tip': {
98 99
            'deps': ['d3'],
            'exports': ['d3-tip']
100
        },
101 102 103
        'dagreD3': {
            'deps': ['d3'],
            'exports': ['dagreD3']
104
        },
105 106 107 108 109
        'pnotify': {
            'exports': ['pnotify']
        },
        'jquery-placeholder': {
            'deps': ['jquery']
110 111 112 113 114 115
        },
        'query-builder': {
            'deps': ['jquery']
        },
        'daterangepicker': {
            'deps': ['jquery', 'moment']
116 117 118 119 120 121 122
        },
        'nvd3': {
            'deps': ['d3']
        },
        'sparkline': {
            'deps': ['jquery'],
            'exports': ['sparkline']
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
        }
    },

    paths: {
        'jquery': 'libs/jquery/js/jquery.min',
        'underscore': 'libs/underscore/underscore-min',
        'bootstrap': 'libs/bootstrap/js/bootstrap.min',
        'backbone': 'libs/backbone/backbone-min',
        'backbone.babysitter': 'libs/backbone.babysitter/lib/backbone.babysitter.min',
        'marionette': 'libs/backbone-marionette/backbone.marionette.min',
        'backbone.paginator': 'libs/backbone-paginator/backbone.paginator.min',
        'backbone.wreqr': 'libs/backbone-wreqr/backbone.wreqr.min',
        'backgrid': 'libs/backgrid/js/backgrid',
        'backgrid-filter': 'libs/backgrid-filter/js/backgrid-filter.min',
        'backgrid-orderable': 'libs/backgrid-orderable-columns/js/backgrid-orderable-columns',
        'backgrid-paginator': 'libs/backgrid-paginator/js/backgrid-paginator.min',
        'backgrid-sizeable': 'libs/backgrid-sizeable-columns/js/backgrid-sizeable-columns',
140
        'backgrid-columnmanager': 'external_lib/backgrid-columnmanager/js/Backgrid.ColumnManager',
141 142 143 144 145
        'asBreadcrumbs': 'libs/jquery-asBreadcrumbs/js/jquery-asBreadcrumbs.min',
        'd3': 'libs/d3/d3.min',
        'd3-tip': 'libs/d3/index',
        'tmpl': 'templates',
        'requirejs.text': 'libs/requirejs-text/text',
146 147 148
        'handlebars': 'external_lib/require-handlebars-plugin/js/handlebars',
        'hbs': 'external_lib/require-handlebars-plugin/js/hbs',
        'i18nprecompile': 'external_lib/require-handlebars-plugin/js/i18nprecompile',
149
        'dagreD3': 'libs/dagre-d3/dagre-d3.min',
150
        'select2': 'libs/select2/select2.full.min',
151
        'backgrid-select-all': 'libs/backgrid-select-all/backgrid-select-all.min',
152
        'moment': 'libs/moment/js/moment.min',
153
        'jquery-ui': 'external_lib/jquery-ui/jquery-ui.min',
154 155 156
        'pnotify': 'external_lib/pnotify/pnotify.custom.min',
        'pnotify.buttons': 'external_lib/pnotify/pnotify.custom.min',
        'pnotify.confirm': 'external_lib/pnotify/pnotify.custom.min',
157
        'jquery-placeholder': 'libs/jquery-placeholder/js/jquery.placeholder',
158 159
        'platform': 'libs/platform/platform',
        'query-builder': 'libs/jQueryQueryBuilder/js/query-builder.standalone.min',
160 161
        'daterangepicker': 'libs/bootstrap-daterangepicker/js/daterangepicker',
        'nvd3': 'libs/nvd3/nv.d3.min',
162
        'sparkline': 'libs/sparkline/jquery.sparkline.min',
163
        'table-dragger': 'libs/table-dragger/table-dragger'
164 165 166 167 168 169 170 171
    },

    /**
     * If set to true, an error will be thrown if a script loads that does not
     * call define() or have a shim exports string value that can be checked.
     * To get timely, correct error triggers in IE, force a define/shim export.
     * @type {Boolean}
     */
172
    'enforceDefine': false
173 174 175 176
});

require(['App',
    'router/Router',
177 178
    'utils/CommonViewFunction',
    'utils/Globals',
179
    'utils/UrlLinks',
180
    'collection/VEntityList',
181
    'collection/VTagList',
182 183
    'utils/Overrides',
    'bootstrap',
184
    'd3',
185
    'select2'
186
], function(App, Router, CommonViewFunction, Globals, UrlLinks, VEntityList, VTagList) {
187
    var that = this;
188
    this.asyncFetchCounter = 5;
189
    this.entityDefCollection = new VEntityList();
190 191 192
    this.entityDefCollection.url = UrlLinks.entitiesDefApiUrl();
    this.typeHeaders = new VTagList();
    this.typeHeaders.url = UrlLinks.typesApiUrl();
193 194 195
    this.enumDefCollection = new VTagList();
    this.enumDefCollection.url = UrlLinks.enumDefApiUrl();
    this.enumDefCollection.modelAttrName = "enumDefs";
196
    this.classificationDefCollection = new VTagList();
197 198

    App.appRouter = new Router({
199
        entityDefCollection: this.entityDefCollection,
200
        typeHeaders: this.typeHeaders,
201 202
        enumDefCollection: this.enumDefCollection,
        classificationDefCollection: this.classificationDefCollection
203 204 205 206 207 208 209
    });

    var startApp = function() {
        if (that.asyncFetchCounter === 0) {
            App.start();
        }
    };
210
    CommonViewFunction.userDataFetch({
211
        url: UrlLinks.sessionApiUrl(),
212 213 214 215 216
        callback: function(response) {
            if (response && response.userName) {
                Globals.userLogedIn.status = true;
                Globals.userLogedIn.response = response;
            }
217 218 219 220 221 222
            if (response && response['atlas.entity.create.allowed'] !== undefined) {
                Globals.entityCreate = response['atlas.entity.create.allowed'];
            }
            if (response && response['atlas.entity.update.allowed'] !== undefined) {
                Globals.entityUpdate = response['atlas.entity.update.allowed'];
            }
223 224 225 226 227 228 229 230 231 232
            if (response && response['atlas.ui.editable.entity.types'] !== undefined) {
                var entityTypeList = response['atlas.ui.editable.entity.types'].trim().split(",");
                if (entityTypeList.length) {
                    if (entityTypeList[0] === "*") {
                        Globals.entityTypeConfList = [];
                    } else if (entityTypeList.length > 0) {
                        Globals.entityTypeConfList = entityTypeList;
                    }
                }
            }
233 234 235 236
            --that.asyncFetchCounter;
            startApp();
        }
    });
237 238 239
    this.entityDefCollection.fetch({
        skipDefaultError: true,
        complete: function() {
240 241 242 243
            that.entityDefCollection.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            };
            that.entityDefCollection.fullCollection.sort({ silent: true });
244 245 246 247 248 249
            --that.asyncFetchCounter;
            startApp();
        }
    });
    this.typeHeaders.fetch({
        skipDefaultError: true,
250
        complete: function() {
251 252 253 254
            that.typeHeaders.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            }
            that.typeHeaders.fullCollection.sort({ silent: true });
255 256
            --that.asyncFetchCounter;
            startApp();
257 258
        }
    });
259 260 261
    this.enumDefCollection.fetch({
        skipDefaultError: true,
        complete: function() {
262 263 264 265
            that.enumDefCollection.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            };
            that.enumDefCollection.fullCollection.sort({ silent: true });
266 267 268 269
            --that.asyncFetchCounter;
            startApp();
        }
    });
270 271 272
    this.classificationDefCollection.fetch({
        skipDefaultError: true,
        complete: function() {
273 274 275 276
            that.classificationDefCollection.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            };
            that.classificationDefCollection.fullCollection.sort({ silent: true });
277 278 279 280
            --that.asyncFetchCounter;
            startApp();
        }
    });
281
});