mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-20 20:34:25 +02:00
Extend module event handler capabilities, allow for easier use
* introduce 'rendered' event for modules * use this.module.on() instead of registerEventHandlers() * no CSS filter creates event handlers on module containers
This commit is contained in:
parent
f67b83fb75
commit
d0fd25d4ef
@ -435,6 +435,7 @@
|
|||||||
if (active) {
|
if (active) {
|
||||||
$('[href="' + active + '"]', req.$target).addClass('active');
|
$('[href="' + active + '"]', req.$target).addClass('active');
|
||||||
}
|
}
|
||||||
|
req.$target.trigger('rendered');
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,10 +10,11 @@
|
|||||||
// The Icinga instance
|
// The Icinga instance
|
||||||
this.icinga = icinga;
|
this.icinga = icinga;
|
||||||
|
|
||||||
// Event handlers registered by this module
|
// Applied event handlers
|
||||||
this.handlers = [];
|
this.handlers = [];
|
||||||
|
|
||||||
this.registeredHandlers = {};
|
// Event handlers registered by this module
|
||||||
|
this.registeredHandlers = [];
|
||||||
|
|
||||||
// The module name
|
// The module name
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -44,7 +45,7 @@
|
|||||||
// The constructor of the modules prototype must be prepared to get an
|
// The constructor of the modules prototype must be prepared to get an
|
||||||
// instance of Icinga.Module
|
// instance of Icinga.Module
|
||||||
this.object = new this.prototyp(this);
|
this.object = new this.prototyp(this);
|
||||||
this.applyRegisteredEventHandlers();
|
this.applyHandlers();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
this.icinga.logger.error(
|
this.icinga.logger.error(
|
||||||
'Failed to load module ' + this.name + ': ',
|
'Failed to load module ' + this.name + ': ',
|
||||||
@ -63,29 +64,29 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Globally register this modules event handlers
|
* Register this modules event handlers
|
||||||
*/
|
*/
|
||||||
registerEventHandlers: function (handlers) {
|
on: function (event, filter, handler) {
|
||||||
this.registeredHandlers = handlers;
|
if (typeof handler === 'undefined') {
|
||||||
return this;
|
handler = filter;
|
||||||
|
filter = '.module-' + this.name;
|
||||||
|
} else {
|
||||||
|
filter = '.module-' + this.name + ' ' + filter;
|
||||||
|
}
|
||||||
|
this.registeredHandlers.push({event: event, filter: filter, handler: handler});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
applyRegisteredEventHandlers: function () {
|
applyHandlers: function () {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
$.each(this.registeredHandlers, function (filter, events) {
|
$.each(this.registeredHandlers, function (key, on) {
|
||||||
|
|
||||||
$.each(events, function (event, handler) {
|
|
||||||
// TODO: if (event[1] === 'each') {
|
|
||||||
// $(event[0], $(el)).each(event[2]);
|
|
||||||
self.bindEventHandler(
|
self.bindEventHandler(
|
||||||
event,
|
on.event,
|
||||||
'.module-' + self.name + ' ' + filter,
|
on.filter,
|
||||||
handler
|
on.handler
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
self = null;
|
self = null;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user