2016-02-08 15:41:00 +01:00
|
|
|
/*! Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
2014-07-15 13:39:22 +02:00
|
|
|
|
2014-02-18 19:34:39 +01:00
|
|
|
/**
|
|
|
|
* Icinga starts here.
|
|
|
|
*
|
|
|
|
* Usage example:
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* var icinga = new Icinga({
|
|
|
|
* baseUrl: '/icinga',
|
|
|
|
* });
|
|
|
|
* </code>
|
|
|
|
*/
|
2014-03-04 14:08:29 +01:00
|
|
|
(function(window, $) {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var Icinga = function (config) {
|
|
|
|
|
2014-03-26 11:30:45 +01:00
|
|
|
this.initialized = false;
|
|
|
|
|
2014-03-04 14:08:29 +01:00
|
|
|
/**
|
|
|
|
* Our config object
|
|
|
|
*/
|
|
|
|
this.config = config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Icinga.Logger
|
|
|
|
*/
|
|
|
|
this.logger = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Icinga.UI
|
|
|
|
*/
|
|
|
|
this.ui = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Icinga.Loader
|
|
|
|
*/
|
|
|
|
this.loader = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Icinga.Events
|
|
|
|
*/
|
|
|
|
this.events = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Icinga.Timer
|
|
|
|
*/
|
|
|
|
this.timer = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Icinga.History
|
|
|
|
*/
|
|
|
|
this.history = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Icinga.Utils
|
|
|
|
*/
|
|
|
|
this.utils = null;
|
|
|
|
|
2014-09-09 18:45:16 +02:00
|
|
|
/**
|
|
|
|
* Additional site behavior
|
|
|
|
*/
|
|
|
|
this.behaviors = {};
|
|
|
|
|
2014-03-04 14:08:29 +01:00
|
|
|
/**
|
|
|
|
* Loaded modules
|
|
|
|
*/
|
|
|
|
this.modules = {};
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
$(document).ready(function () {
|
|
|
|
self.initialize();
|
|
|
|
self = null;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Icinga.prototype = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Icinga startup, will be triggerd once the document is ready
|
|
|
|
*/
|
|
|
|
initialize: function () {
|
2014-03-26 11:30:45 +01:00
|
|
|
if (this.initialized) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 14:08:29 +01:00
|
|
|
|
2014-09-05 13:17:40 +02:00
|
|
|
this.timezone = new Icinga.Timezone();
|
|
|
|
this.utils = new Icinga.Utils(this);
|
|
|
|
this.logger = new Icinga.Logger(this);
|
|
|
|
this.timer = new Icinga.Timer(this);
|
|
|
|
this.ui = new Icinga.UI(this);
|
|
|
|
this.loader = new Icinga.Loader(this);
|
|
|
|
this.events = new Icinga.Events(this);
|
|
|
|
this.history = new Icinga.History(this);
|
2014-09-09 18:45:16 +02:00
|
|
|
var self = this;
|
|
|
|
$.each(Icinga.Behaviors, function(name, Behavior) {
|
2014-09-10 10:44:22 +02:00
|
|
|
self.behaviors[name.toLowerCase()] = new Behavior(self);
|
2014-09-09 18:45:16 +02:00
|
|
|
});
|
2014-09-05 13:17:40 +02:00
|
|
|
|
|
|
|
this.timezone.initialize();
|
2014-03-04 14:08:29 +01:00
|
|
|
this.timer.initialize();
|
|
|
|
this.events.initialize();
|
|
|
|
this.history.initialize();
|
|
|
|
this.ui.initialize();
|
|
|
|
this.loader.initialize();
|
2014-09-09 18:45:16 +02:00
|
|
|
|
2014-03-26 11:30:45 +01:00
|
|
|
this.logger.info('Icinga is ready, running on jQuery ', $().jquery);
|
|
|
|
this.initialized = true;
|
2014-03-04 14:08:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a given module by name
|
2015-08-10 14:46:58 +02:00
|
|
|
*
|
|
|
|
* @param {string} name
|
|
|
|
*
|
|
|
|
* @return {boolean}
|
2014-03-04 14:08:29 +01:00
|
|
|
*/
|
|
|
|
loadModule: function (name) {
|
|
|
|
|
2015-08-10 14:46:58 +02:00
|
|
|
if (this.isLoadedModule(name)) {
|
2014-03-04 14:08:29 +01:00
|
|
|
this.logger.error('Cannot load module ' + name + ' twice');
|
2015-08-10 14:46:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! this.hasModule(name)) {
|
|
|
|
this.logger.error('Cannot find module ' + name);
|
|
|
|
return false;
|
2014-03-04 14:08:29 +01:00
|
|
|
}
|
|
|
|
|
2015-08-10 14:46:58 +02:00
|
|
|
this.modules[name] = new Icinga.Module(
|
|
|
|
this,
|
|
|
|
name,
|
|
|
|
Icinga.availableModules[name]
|
|
|
|
);
|
|
|
|
return true;
|
2014-03-04 14:08:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-08-10 14:46:58 +02:00
|
|
|
* Whether a module matching the given name exists or is loaded
|
|
|
|
*
|
|
|
|
* @param {string} name
|
|
|
|
*
|
|
|
|
* @return {boolean}
|
2014-03-04 14:08:29 +01:00
|
|
|
*/
|
|
|
|
hasModule: function (name) {
|
2015-08-10 14:46:58 +02:00
|
|
|
return this.isLoadedModule(name) ||
|
2014-03-04 14:08:29 +01:00
|
|
|
'undefined' !== typeof Icinga.availableModules[name];
|
|
|
|
},
|
|
|
|
|
2015-08-10 14:46:58 +02:00
|
|
|
/**
|
|
|
|
* Return whether the given module is loaded
|
|
|
|
*
|
|
|
|
* @param {string} name The name of the module
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
isLoadedModule: function (name) {
|
|
|
|
return 'undefined' !== typeof this.modules[name];
|
|
|
|
},
|
|
|
|
|
2014-03-04 14:08:29 +01:00
|
|
|
/**
|
|
|
|
* Get a module by name
|
2015-08-10 14:46:58 +02:00
|
|
|
*
|
|
|
|
* @param {string} name
|
|
|
|
*
|
|
|
|
* @return {object}
|
2014-03-04 14:08:29 +01:00
|
|
|
*/
|
|
|
|
module: function (name) {
|
|
|
|
|
2015-08-10 14:46:58 +02:00
|
|
|
if (this.hasModule(name) && !this.isLoadedModule(name)) {
|
|
|
|
this.modules[name] = new Icinga.Module(
|
|
|
|
this,
|
|
|
|
name,
|
|
|
|
Icinga.availableModules[name]
|
|
|
|
);
|
2014-03-04 14:08:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.modules[name];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up and unload all Icinga components
|
|
|
|
*/
|
|
|
|
destroy: function () {
|
|
|
|
|
|
|
|
$.each(this.modules, function (name, module) {
|
|
|
|
module.destroy();
|
|
|
|
});
|
|
|
|
|
2014-09-05 13:17:40 +02:00
|
|
|
this.timezone.destroy();
|
2014-03-04 14:08:29 +01:00
|
|
|
this.timer.destroy();
|
|
|
|
this.events.destroy();
|
|
|
|
this.loader.destroy();
|
|
|
|
this.ui.destroy();
|
|
|
|
this.logger.debug('Icinga has been destroyed');
|
|
|
|
this.logger.destroy();
|
|
|
|
this.utils.destroy();
|
|
|
|
|
|
|
|
this.modules = [];
|
|
|
|
this.timer = this.events = this.loader = this.ui = this.logger =
|
|
|
|
this.utils = null;
|
2014-03-26 11:30:45 +01:00
|
|
|
this.initialized = false;
|
2014-03-26 10:28:03 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
reload: function () {
|
|
|
|
setTimeout(function () {
|
|
|
|
var oldjQuery = window.jQuery;
|
|
|
|
var oldConfig = window.icinga.config;
|
|
|
|
var oldIcinga = window.Icinga;
|
|
|
|
window.icinga.destroy();
|
|
|
|
window.Icinga = undefined;
|
|
|
|
window.$ = undefined;
|
|
|
|
window.jQuery = undefined;
|
2014-03-26 11:30:45 +01:00
|
|
|
jQuery = undefined;
|
|
|
|
$ = undefined;
|
2014-03-26 10:28:03 +01:00
|
|
|
|
|
|
|
oldjQuery.getScript(
|
2016-02-29 21:40:48 +01:00
|
|
|
oldConfig.baseUrl.replace(/\/$/, '') + '/js/icinga.min.js'
|
2014-03-26 10:28:03 +01:00
|
|
|
).done(function () {
|
2014-03-26 11:30:45 +01:00
|
|
|
var jQuery = window.jQuery;
|
|
|
|
window.icinga = new window.Icinga(oldConfig);
|
|
|
|
window.icinga.initialize();
|
2014-03-26 10:28:03 +01:00
|
|
|
window.icinga.ui.reloadCss();
|
|
|
|
oldjQuery = undefined;
|
|
|
|
oldConfig = undefined;
|
|
|
|
oldIcinga = undefined;
|
|
|
|
}).fail(function () {
|
2014-03-26 11:30:45 +01:00
|
|
|
window.jQuery = oldjQuery;
|
|
|
|
window.$ = window.jQuery;
|
|
|
|
window.Icinga = oldIcinga;
|
2014-03-26 10:28:03 +01:00
|
|
|
window.icinga = new Icinga(oldConfig);
|
|
|
|
window.icinga.ui.reloadCss();
|
|
|
|
});
|
|
|
|
}, 0);
|
2014-02-18 19:34:39 +01:00
|
|
|
}
|
2014-03-26 10:28:03 +01:00
|
|
|
|
2014-03-04 14:08:29 +01:00
|
|
|
};
|
2014-02-18 19:34:39 +01:00
|
|
|
|
2014-03-04 14:08:29 +01:00
|
|
|
window.Icinga = Icinga;
|
|
|
|
|
|
|
|
Icinga.availableModules = {};
|
|
|
|
|
2014-03-26 11:30:45 +01:00
|
|
|
})(window, jQuery);
|