main.js 11.4 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
        'moment-timezone': {
            'deps': ['moment']
119
        },
120 121
        'moment': {
            'exports': ['moment']
122
        },
123 124 125 126 127 128
        'nvd3': {
            'deps': ['d3']
        },
        'sparkline': {
            'deps': ['jquery'],
            'exports': ['sparkline']
129 130 131
        },
        'jstree': {
            'deps': ['jquery']
132 133 134
        },
        'jquery-steps': {
            'deps': ['jquery']
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
        }
    },

    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',
152
        'backgrid-columnmanager': 'external_lib/backgrid-columnmanager/js/Backgrid.ColumnManager',
153 154 155 156 157
        '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',
158 159 160
        'handlebars': 'external_lib/require-handlebars-plugin/js/handlebars',
        'hbs': 'external_lib/require-handlebars-plugin/js/hbs',
        'i18nprecompile': 'external_lib/require-handlebars-plugin/js/i18nprecompile',
161
        'dagreD3': 'libs/dagre-d3/dagre-d3.min',
162
        'select2': 'libs/select2/select2.full.min',
163
        'backgrid-select-all': 'libs/backgrid-select-all/backgrid-select-all.min',
164
        'moment': 'libs/moment/js/moment.min',
165
        'moment-timezone': 'libs/moment-timezone/moment-timezone-with-data.min',
166
        'jquery-ui': 'external_lib/jquery-ui/jquery-ui.min',
167 168 169
        'pnotify': 'external_lib/pnotify/pnotify.custom.min',
        'pnotify.buttons': 'external_lib/pnotify/pnotify.custom.min',
        'pnotify.confirm': 'external_lib/pnotify/pnotify.custom.min',
170
        'jquery-placeholder': 'libs/jquery-placeholder/js/jquery.placeholder',
171 172
        'platform': 'libs/platform/platform',
        'query-builder': 'libs/jQueryQueryBuilder/js/query-builder.standalone.min',
173 174
        'daterangepicker': 'libs/bootstrap-daterangepicker/js/daterangepicker',
        'nvd3': 'libs/nvd3/nv.d3.min',
175
        'sparkline': 'libs/sparkline/jquery.sparkline.min',
176
        'table-dragger': 'libs/table-dragger/table-dragger',
177 178
        'jstree': 'libs/jstree/jstree.min',
        'jquery-steps': 'libs/jquery-steps/jquery.steps.min',
179 180 181 182 183 184 185 186
    },

    /**
     * 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}
     */
187
    'enforceDefine': false
188 189 190 191
});

require(['App',
    'router/Router',
192
    'utils/Helper',
193 194
    'utils/CommonViewFunction',
    'utils/Globals',
195
    'utils/UrlLinks',
196
    'collection/VEntityList',
197
    'collection/VTagList',
198 199
    'utils/Overrides',
    'bootstrap',
200
    'd3',
201
    'select2'
202
], function(App, Router, Helper, CommonViewFunction, Globals, UrlLinks, VEntityList, VTagList) {
203
    var that = this;
204
    this.asyncFetchCounter = 6;
205
    this.entityDefCollection = new VEntityList();
206 207 208
    this.entityDefCollection.url = UrlLinks.entitiesDefApiUrl();
    this.typeHeaders = new VTagList();
    this.typeHeaders.url = UrlLinks.typesApiUrl();
209 210 211
    this.enumDefCollection = new VTagList();
    this.enumDefCollection.url = UrlLinks.enumDefApiUrl();
    this.enumDefCollection.modelAttrName = "enumDefs";
212
    this.classificationDefCollection = new VTagList();
213 214 215
    this.entityCountCollection = new VTagList();
    this.entityCountCollection.url = UrlLinks.entityCountApi();
    this.entityCountCollection.modelAttrName = "data";
216 217

    App.appRouter = new Router({
218
        entityDefCollection: this.entityDefCollection,
219
        typeHeaders: this.typeHeaders,
220
        enumDefCollection: this.enumDefCollection,
221 222
        classificationDefCollection: this.classificationDefCollection,
        entityCountCollection: this.entityCountCollection
223 224 225 226 227 228 229
    });

    var startApp = function() {
        if (that.asyncFetchCounter === 0) {
            App.start();
        }
    };
230
    CommonViewFunction.userDataFetch({
231
        url: UrlLinks.sessionApiUrl(),
232
        callback: function(response) {
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
            if (response) {
                if (response.userName) {
                    Globals.userLogedIn.status = true;
                    Globals.userLogedIn.response = response;
                }
                if (response['atlas.entity.create.allowed'] !== undefined) {
                    Globals.entityCreate = response['atlas.entity.create.allowed'];
                }
                if (response['atlas.entity.update.allowed'] !== undefined) {
                    Globals.entityUpdate = response['atlas.entity.update.allowed'];
                }
                if (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;
                        }
252 253 254
                    }
                }
            }
255 256 257 258
            --that.asyncFetchCounter;
            startApp();
        }
    });
259 260 261
    this.entityDefCollection.fetch({
        skipDefaultError: true,
        complete: function() {
262 263 264 265
            that.entityDefCollection.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            };
            that.entityDefCollection.fullCollection.sort({ silent: true });
266 267 268 269 270 271
            --that.asyncFetchCounter;
            startApp();
        }
    });
    this.typeHeaders.fetch({
        skipDefaultError: true,
272
        complete: function() {
273 274 275 276
            that.typeHeaders.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            }
            that.typeHeaders.fullCollection.sort({ silent: true });
277 278
            --that.asyncFetchCounter;
            startApp();
279 280
        }
    });
281 282 283
    this.enumDefCollection.fetch({
        skipDefaultError: true,
        complete: function() {
284 285 286 287
            that.enumDefCollection.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            };
            that.enumDefCollection.fullCollection.sort({ silent: true });
288 289 290 291
            --that.asyncFetchCounter;
            startApp();
        }
    });
292 293 294
    this.classificationDefCollection.fetch({
        skipDefaultError: true,
        complete: function() {
295 296 297 298
            that.classificationDefCollection.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            };
            that.classificationDefCollection.fullCollection.sort({ silent: true });
299 300 301 302
            --that.asyncFetchCounter;
            startApp();
        }
    });
303 304 305 306 307 308 309 310

    this.entityCountCollection.fetch({
        skipDefaultError: true,
        complete: function() {
            --that.asyncFetchCounter;
            startApp();
        }
    });
311
});