2014-03-06 13:01:52 +01:00
|
|
|
/**
|
|
|
|
* Icinga.Events
|
|
|
|
*
|
|
|
|
* Event handlers
|
|
|
|
*/
|
|
|
|
(function (Icinga, $) {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Icinga.Events = function (icinga) {
|
|
|
|
this.icinga = icinga;
|
|
|
|
};
|
|
|
|
|
|
|
|
Icinga.Events.prototype = {
|
|
|
|
|
2014-04-02 18:23:01 +02:00
|
|
|
keyboard: {
|
|
|
|
ctrlKey: false,
|
|
|
|
altKey: false,
|
|
|
|
shiftKey: false
|
|
|
|
},
|
|
|
|
|
2014-03-06 13:01:52 +01:00
|
|
|
/**
|
|
|
|
* Icinga will call our initialize() function once it's ready
|
|
|
|
*/
|
|
|
|
initialize: function () {
|
|
|
|
this.applyGlobalDefaults();
|
|
|
|
this.applyHandlers($('#layout'));
|
|
|
|
this.icinga.ui.prepareContainers();
|
2014-04-09 19:13:46 +02:00
|
|
|
this.icinga.ui.prepareMultiselectTables($(document));
|
2014-03-06 13:01:52 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// TODO: What's this?
|
|
|
|
applyHandlers: function (el) {
|
|
|
|
|
|
|
|
var icinga = this.icinga;
|
|
|
|
|
|
|
|
$('.dashboard > div', el).each(function(idx, el) {
|
2014-03-17 17:10:03 +01:00
|
|
|
var url = $(el).data('icingaUrl');
|
2014-03-06 13:01:52 +01:00
|
|
|
if (typeof url === 'undefined') return;
|
|
|
|
icinga.loader.loadUrl(url, $(el)).autorefresh = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Set first links href in a action table tr as row href:
|
|
|
|
$('table.action tr', el).each(function(idx, el) {
|
|
|
|
var $a = $('a[href]', el).first();
|
|
|
|
if ($a.length) {
|
2014-03-17 17:10:03 +01:00
|
|
|
// TODO: Find out whether we leak memory on IE with this:
|
2014-03-06 13:01:52 +01:00
|
|
|
$(el).attr('href', $a.attr('href'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-27 20:39:04 +01:00
|
|
|
var moduleName;
|
2014-03-20 10:58:28 +01:00
|
|
|
if (moduleName = el.data('icingaModule')) {
|
|
|
|
if (icinga.hasModule(moduleName)) {
|
|
|
|
var module = icinga.module(moduleName);
|
|
|
|
// NOT YET, the applyOnloadDings: module.applyEventHandlers(mod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-06 13:01:52 +01:00
|
|
|
$('.icinga-module', el).each(function(idx, mod) {
|
|
|
|
var $mod = $(mod);
|
2014-03-20 10:58:28 +01:00
|
|
|
moduleName = $mod.data('icingaModule');
|
2014-03-06 13:01:52 +01:00
|
|
|
if (icinga.hasModule(moduleName)) {
|
|
|
|
var module = icinga.module(moduleName);
|
|
|
|
// NOT YET, the applyOnloadDings: module.applyEventHandlers(mod);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('input.autofocus', el).focus();
|
|
|
|
|
2014-05-07 17:03:27 +02:00
|
|
|
$('img.inlinepie', el).each(function() {
|
|
|
|
icinga.ui.initializeSparklines($(this));
|
2014-03-06 13:01:52 +01:00
|
|
|
});
|
2014-05-07 17:03:27 +02:00
|
|
|
|
|
|
|
// replace all sparklines
|
|
|
|
$('span.sparkline', el).sparkline('html', { enableTagOptions: true });
|
2014-03-06 13:01:52 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Global default event handlers
|
|
|
|
*/
|
|
|
|
applyGlobalDefaults: function () {
|
|
|
|
// We catch resize events
|
|
|
|
$(window).on('resize', { self: this.icinga.ui }, this.icinga.ui.onWindowResize);
|
|
|
|
|
2014-04-01 10:40:38 +02:00
|
|
|
// Trigger 'rendered' event also on page loads
|
|
|
|
$(window).on('load', { self: this }, this.onLoad);
|
|
|
|
|
2014-03-06 13:01:52 +01:00
|
|
|
// Destroy Icinga, clean up and interrupt pending requests on unload
|
|
|
|
$( window ).on('unload', { self: this }, this.onUnload);
|
|
|
|
$( window ).on('beforeunload', { self: this }, this.onUnload);
|
|
|
|
|
|
|
|
// We catch scroll events in our containers
|
2014-03-26 10:25:57 +01:00
|
|
|
$('.container').on('scroll', this.icinga.events.onContainerScroll);
|
2014-03-06 13:01:52 +01:00
|
|
|
|
|
|
|
// We want to catch each link click
|
|
|
|
$(document).on('click', 'a', { self: this }, this.linkClicked);
|
|
|
|
|
2014-04-09 19:11:56 +02:00
|
|
|
// Select a table row
|
2014-04-23 19:41:07 +02:00
|
|
|
$(document).on('click', 'table.action tr[href]', { self: this }, this.rowSelected);
|
|
|
|
$(document).on('click', 'table.action tr a', { self: this }, this.rowSelected);
|
2014-03-06 13:01:52 +01:00
|
|
|
|
2014-03-07 18:12:44 +01:00
|
|
|
$(document).on('click', 'button', { self: this }, this.submitForm);
|
|
|
|
|
2014-03-06 13:01:52 +01:00
|
|
|
// We catch all form submit events
|
|
|
|
$(document).on('submit', 'form', { self: this }, this.submitForm);
|
|
|
|
|
|
|
|
// We support an 'autosubmit' class on dropdown form elements
|
2014-03-09 23:38:55 +01:00
|
|
|
$(document).on('change', 'form select.autosubmit', { self: this }, this.autoSubmitForm);
|
2014-03-06 13:01:52 +01:00
|
|
|
|
2014-03-25 13:13:42 +01:00
|
|
|
$(document).on('keyup', '#menu input.search', {self: this}, this.autoSubmitForm);
|
2014-03-06 13:01:52 +01:00
|
|
|
|
|
|
|
$(document).on('mouseenter', '.historycolorgrid td', this.historycolorgridHover);
|
|
|
|
$(document).on('mouseleave', '.historycolorgrid td', this.historycolorgidUnhover);
|
2014-03-24 10:22:20 +01:00
|
|
|
$(document).on('mouseenter', 'li.dropdown', this.dropdownHover);
|
|
|
|
$(document).on('mouseleave', 'li.dropdown', this.dropdownLeave);
|
2014-03-27 20:39:04 +01:00
|
|
|
$(document).on('mouseenter', '#menu > ul > li', this.menuTitleHovered);
|
|
|
|
$(document).on('mouseleave', '#sidebar', this.leaveSidebar);
|
2014-03-17 17:17:10 +01:00
|
|
|
$(document).on('click', '.tree .handle', { self: this }, this.treeNodeToggle);
|
|
|
|
|
2014-04-16 19:43:56 +02:00
|
|
|
// Toggle all triStateButtons
|
2014-04-23 11:35:16 +02:00
|
|
|
$(document).on('click', 'div.tristate .tristate-dummy', { self: this }, this.clickTriState);
|
2014-03-24 10:22:20 +01:00
|
|
|
|
2014-03-06 13:01:52 +01:00
|
|
|
// TBD: a global autocompletion handler
|
|
|
|
// $(document).on('keyup', 'form.auto input', this.formChangeDelayed);
|
|
|
|
// $(document).on('change', 'form.auto input', this.formChanged);
|
|
|
|
// $(document).on('change', 'form.auto select', this.submitForm);
|
|
|
|
},
|
|
|
|
|
2014-03-27 20:39:04 +01:00
|
|
|
menuTitleHovered: function () {
|
|
|
|
var $li = $(this),
|
|
|
|
delay = 800;
|
|
|
|
|
|
|
|
if ($li.hasClass('active')) {
|
2014-03-28 16:34:08 +01:00
|
|
|
$li.siblings().removeClass('hover');
|
2014-03-27 20:39:04 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($li.children('ul').children('li').length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($('#layout').hasClass('hoveredmenu')) {
|
|
|
|
delay = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
if (! $li.is('li:hover')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($li.hasClass('active')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$li.siblings().each(function () {
|
|
|
|
var $sibling = $(this);
|
|
|
|
if ($sibling.is('li:hover')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($sibling.hasClass('hover')) {
|
|
|
|
$sibling.removeClass('hover');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#layout').addClass('hoveredmenu');
|
|
|
|
$li.addClass('hover');
|
|
|
|
}, delay);
|
|
|
|
},
|
|
|
|
|
|
|
|
leaveSidebar: function () {
|
|
|
|
var $sidebar = $(this);
|
|
|
|
var $li = $sidebar.find('li.hover');
|
|
|
|
if (! $li.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
if ($li.is('li:hover') || $sidebar.is('sidebar:hover') ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$li.removeClass('hover');
|
|
|
|
$('#layout').removeClass('hoveredmenu');
|
2014-03-28 20:57:04 +01:00
|
|
|
}, 500);
|
2014-03-27 20:39:04 +01:00
|
|
|
},
|
|
|
|
|
2014-03-24 10:22:20 +01:00
|
|
|
dropdownHover: function () {
|
|
|
|
$(this).addClass('hover');
|
|
|
|
},
|
|
|
|
|
|
|
|
dropdownLeave: function () {
|
|
|
|
var $li = $(this);
|
|
|
|
setTimeout(function () {
|
|
|
|
if (! $li.is('li:hover')) {
|
|
|
|
$li.removeClass('hover');
|
|
|
|
}
|
|
|
|
}, 300);
|
|
|
|
},
|
|
|
|
|
|
|
|
treeNodeToggle: function () {
|
2014-03-20 10:58:28 +01:00
|
|
|
var $parent = $(this).closest('li');
|
|
|
|
if ($parent.hasClass('collapsed')) {
|
|
|
|
$('li', $parent).addClass('collapsed');
|
|
|
|
$parent.removeClass('collapsed');
|
|
|
|
} else {
|
|
|
|
$parent.addClass('collapsed');
|
|
|
|
}
|
2014-03-17 17:17:10 +01:00
|
|
|
},
|
|
|
|
|
2014-04-01 10:40:38 +02:00
|
|
|
onLoad: function (event) {
|
|
|
|
$('.container').trigger('rendered');
|
|
|
|
},
|
|
|
|
|
2014-03-06 13:01:52 +01:00
|
|
|
onUnload: function (event) {
|
|
|
|
var icinga = event.data.self.icinga;
|
|
|
|
icinga.logger.info('Unloading Icinga');
|
|
|
|
icinga.destroy();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A scroll event happened in one of our containers
|
|
|
|
*/
|
|
|
|
onContainerScroll: function (event) {
|
|
|
|
// Ugly. And PLEASE, not so often
|
|
|
|
icinga.ui.fixControls();
|
|
|
|
},
|
|
|
|
|
|
|
|
historycolorgridHover: function () {
|
|
|
|
$(this).addClass('hover');
|
|
|
|
},
|
|
|
|
|
|
|
|
historycolorgidUnhover: function() {
|
|
|
|
$(this).removeClass('hover');
|
|
|
|
},
|
|
|
|
|
2014-03-09 23:38:55 +01:00
|
|
|
autoSubmitForm: function (event) {
|
|
|
|
return event.data.self.submitForm(event, true);
|
|
|
|
},
|
|
|
|
|
2014-04-16 19:43:56 +02:00
|
|
|
clickTriState: function (event) {
|
|
|
|
var $tristate = $(this);
|
|
|
|
var triState = parseInt($tristate.data('icinga-tristate'), 10);
|
|
|
|
|
2014-04-23 11:35:16 +02:00
|
|
|
// load current values
|
2014-04-23 19:41:07 +02:00
|
|
|
var old = $tristate.data('icinga-old').toString();
|
2014-04-23 11:35:16 +02:00
|
|
|
var value = $tristate.parent().find('input:radio:checked').first().prop('checked', false).val();
|
|
|
|
|
|
|
|
// calculate the new value
|
2014-04-16 19:43:56 +02:00
|
|
|
if (triState) {
|
|
|
|
// 1 => 0
|
|
|
|
// 0 => unchanged
|
|
|
|
// unchanged => 1
|
|
|
|
value = value === '1' ? '0' : (value === '0' ? 'unchanged' : '1');
|
|
|
|
} else {
|
|
|
|
// 1 => 0
|
|
|
|
// 0 => 1
|
|
|
|
value = value === '1' ? '0' : '1';
|
|
|
|
}
|
2014-04-23 19:41:07 +02:00
|
|
|
|
2014-04-23 11:35:16 +02:00
|
|
|
// update form value
|
|
|
|
$tristate.parent().find('input:radio[value="' + value + '"]').prop('checked', true);
|
|
|
|
// update dummy
|
2014-04-16 19:43:56 +02:00
|
|
|
|
2014-04-23 11:35:16 +02:00
|
|
|
if (value !== old) {
|
|
|
|
$tristate.parent().find('b.tristate-changed').css('visibility', 'visible');
|
2014-04-16 19:43:56 +02:00
|
|
|
} else {
|
2014-04-23 19:41:07 +02:00
|
|
|
$tristate.parent().find('b.tristate-changed').css('visibility', 'hidden');
|
2014-04-16 19:43:56 +02:00
|
|
|
}
|
2014-04-23 11:35:16 +02:00
|
|
|
self.icinga.ui.setTriState(value.toString(), $tristate);
|
2014-04-16 19:43:56 +02:00
|
|
|
},
|
|
|
|
|
2014-03-06 13:01:52 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-03-09 23:38:55 +01:00
|
|
|
submitForm: function (event, autosubmit) {
|
2014-03-08 15:25:10 +01:00
|
|
|
var self = event.data.self;
|
|
|
|
var icinga = self.icinga;
|
2014-03-06 13:01:52 +01:00
|
|
|
|
|
|
|
// .closest is not required unless subelements to trigger this
|
|
|
|
var $form = $(event.currentTarget).closest('form');
|
2014-03-25 08:44:24 +01:00
|
|
|
var regex = new RegExp('&', 'g');
|
|
|
|
var url = $form.attr('action').replace(regex, '&'); // WHY??
|
2014-03-06 13:01:52 +01:00
|
|
|
var method = $form.attr('method');
|
2014-03-28 15:53:37 +01:00
|
|
|
var $button = $('input[type=submit]:focus', $form);
|
2014-03-08 15:25:10 +01:00
|
|
|
var $target;
|
2014-03-26 08:48:22 +01:00
|
|
|
var data;
|
2014-03-08 15:25:10 +01:00
|
|
|
|
2014-03-25 13:13:42 +01:00
|
|
|
if (typeof method === 'undefined') {
|
|
|
|
method = 'POST';
|
|
|
|
} else {
|
|
|
|
method = method.toUpperCase();
|
|
|
|
}
|
|
|
|
|
2014-03-28 15:53:37 +01:00
|
|
|
if ($button.length === 0) {
|
|
|
|
$button = $('input[type=submit]', $form).first();
|
|
|
|
}
|
|
|
|
|
2014-03-08 15:25:10 +01:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
2014-03-25 13:13:42 +01:00
|
|
|
icinga.logger.debug('Submitting form: ' + method + ' ' + url, method);
|
2014-03-06 13:01:52 +01:00
|
|
|
|
2014-03-08 15:25:10 +01:00
|
|
|
$target = self.getLinkTargetFor($form);
|
2014-03-25 13:13:42 +01:00
|
|
|
|
|
|
|
if (method === 'GET') {
|
2014-03-26 08:48:22 +01:00
|
|
|
url = icinga.utils.addUrlParams(url, $form.serializeObject());
|
2014-03-25 13:13:42 +01:00
|
|
|
} else {
|
2014-03-26 08:48:22 +01:00
|
|
|
data = $form.serializeArray();
|
|
|
|
|
|
|
|
if (typeof autosubmit === 'undefined' || ! autosubmit) {
|
2014-03-28 15:53:37 +01:00
|
|
|
if ($button.length) {
|
|
|
|
data.push({
|
|
|
|
name: $button.attr('name'),
|
|
|
|
value: $button.attr('value')
|
|
|
|
});
|
|
|
|
}
|
2014-03-26 08:48:22 +01:00
|
|
|
}
|
2014-03-25 13:13:42 +01:00
|
|
|
}
|
2014-03-26 08:48:22 +01:00
|
|
|
icinga.loader.loadUrl(url, $target, data, method);
|
2014-03-08 15:25:10 +01:00
|
|
|
|
2014-03-06 13:01:52 +01:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2014-04-02 18:23:01 +02:00
|
|
|
handleExternalTarget: function($node) {
|
|
|
|
var linkTarget = $node.attr('target');
|
|
|
|
|
|
|
|
// TODO: Let remote links pass through. Right now they only work
|
|
|
|
// combined with target="_blank" or target="_self"
|
|
|
|
// window.open is used as return true; didn't work reliable
|
|
|
|
if (linkTarget === '_blank' || linkTarget === '_self') {
|
|
|
|
window.open(href, linkTarget);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle table selection.
|
|
|
|
*/
|
|
|
|
rowSelected: function(event) {
|
|
|
|
var self = event.data.self;
|
|
|
|
var icinga = self.icinga;
|
|
|
|
var $tr = $(this);
|
|
|
|
var $table = $tr.closest('table.multiselect');
|
2014-04-23 19:41:07 +02:00
|
|
|
var data = self.icinga.ui.getSelectionKeys($table);
|
2014-04-02 18:23:01 +02:00
|
|
|
var multisel = $table.hasClass('multiselect');
|
|
|
|
var url = $table.data('icinga-multiselect-url');
|
2014-04-09 19:11:56 +02:00
|
|
|
|
|
|
|
// When the selection points to a link, select the closest row
|
|
|
|
if ($tr.prop('tagName').toLowerCase() === 'a') {
|
|
|
|
$tr = $tr.closest('tr').first();
|
|
|
|
}
|
|
|
|
|
2014-04-02 18:23:01 +02:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2014-04-09 19:11:56 +02:00
|
|
|
|
2014-04-02 18:23:01 +02:00
|
|
|
if (icinga.events.handleExternalTarget($tr)) {
|
|
|
|
// link handled externally
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-09 19:13:46 +02:00
|
|
|
if (multisel && !data) {
|
2014-04-02 18:23:01 +02:00
|
|
|
icinga.logger.error('A table with multiselection must define the attribute "data-icinga-multiselect-data"');
|
|
|
|
return;
|
|
|
|
}
|
2014-04-09 19:13:46 +02:00
|
|
|
if (multisel && !url) {
|
2014-04-02 18:23:01 +02:00
|
|
|
icinga.logger.error('A table with multiselection must define the attribute "data-icinga-multiselect-url"');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-23 19:41:07 +02:00
|
|
|
// update selection
|
2014-04-28 09:46:35 +02:00
|
|
|
if ((event.ctrlKey || event.metaKey) && multisel) {
|
2014-04-07 13:36:25 +02:00
|
|
|
icinga.ui.toogleTableRowSelection($tr);
|
2014-04-02 18:23:01 +02:00
|
|
|
// multi selection
|
|
|
|
} else if (event.shiftKey && multisel) {
|
|
|
|
// range selection
|
2014-04-07 13:36:25 +02:00
|
|
|
icinga.ui.addTableRowRangeSelection($tr);
|
2014-04-02 18:23:01 +02:00
|
|
|
} else {
|
|
|
|
// single selection
|
2014-04-07 13:36:25 +02:00
|
|
|
icinga.ui.setTableRowSelection($tr);
|
2014-04-02 18:23:01 +02:00
|
|
|
}
|
2014-04-23 19:41:07 +02:00
|
|
|
// focus only the current table.
|
2014-04-09 19:11:56 +02:00
|
|
|
icinga.ui.focusTable($table[0]);
|
2014-04-02 18:23:01 +02:00
|
|
|
|
2014-04-23 19:41:07 +02:00
|
|
|
// update url
|
2014-04-09 19:13:46 +02:00
|
|
|
var $target = self.getLinkTargetFor($tr);
|
|
|
|
if (multisel) {
|
|
|
|
var $trs = $table.find('tr[href].active');
|
|
|
|
if ($trs.length > 1) {
|
2014-04-23 19:41:07 +02:00
|
|
|
var queries = [];
|
|
|
|
var selectionData = icinga.ui.getSelectionSetData($trs, data);
|
|
|
|
var query = icinga.ui.selectionDataToQuery(selectionData, data, icinga);
|
2014-04-09 19:13:46 +02:00
|
|
|
icinga.loader.loadUrl(url + '?' + query, $target);
|
2014-04-23 19:41:07 +02:00
|
|
|
icinga.ui.storeSelectionData(selectionData);
|
2014-04-09 19:13:46 +02:00
|
|
|
} else if ($trs.length === 1) {
|
|
|
|
// display a single row
|
|
|
|
icinga.loader.loadUrl($tr.attr('href'), $target);
|
2014-04-23 19:41:07 +02:00
|
|
|
icinga.ui.storeSelectionData($tr.attr('href'));
|
2014-04-09 19:13:46 +02:00
|
|
|
} else {
|
|
|
|
// display nothing
|
|
|
|
icinga.loader.loadUrl('#');
|
2014-04-23 19:41:07 +02:00
|
|
|
icinga.ui.storeSelectionData(null);
|
2014-04-09 19:13:46 +02:00
|
|
|
}
|
2014-04-02 18:23:01 +02:00
|
|
|
} else {
|
2014-04-09 19:13:46 +02:00
|
|
|
icinga.loader.loadUrl($tr.attr('href'), $target);
|
2014-04-02 18:23:01 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2014-03-06 13:01:52 +01:00
|
|
|
/**
|
|
|
|
* Someone clicked a link or tr[href]
|
|
|
|
*/
|
|
|
|
linkClicked: function (event) {
|
2014-03-08 15:25:10 +01:00
|
|
|
var self = event.data.self;
|
|
|
|
var icinga = self.icinga;
|
2014-03-06 13:01:52 +01:00
|
|
|
var $a = $(this);
|
|
|
|
var href = $a.attr('href');
|
2014-03-09 00:58:49 +01:00
|
|
|
var linkTarget = $a.attr('target');
|
2014-03-06 13:01:52 +01:00
|
|
|
var $li;
|
2014-03-08 15:25:10 +01:00
|
|
|
var $target;
|
2014-03-08 14:53:17 +01:00
|
|
|
var isMenuLink = $a.closest('#menu').length > 0;
|
2014-03-20 12:24:15 +01:00
|
|
|
var formerUrl;
|
2014-03-08 14:53:17 +01:00
|
|
|
|
|
|
|
// TODO: Let remote links pass through. Right now they only work
|
2014-03-08 15:25:10 +01:00
|
|
|
// combined with target="_blank" or target="_self"
|
2014-03-09 00:58:49 +01:00
|
|
|
// window.open is used as return true; didn't work reliable
|
|
|
|
if (linkTarget === '_blank' || linkTarget === '_self') {
|
|
|
|
window.open(href, linkTarget);
|
|
|
|
return false;
|
2014-03-06 13:01:52 +01:00
|
|
|
}
|
2014-03-08 15:25:10 +01:00
|
|
|
|
2014-04-09 19:11:56 +02:00
|
|
|
// ignore links inside of tables.
|
|
|
|
if ($a.closest('table tr').length > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-09 00:58:49 +01:00
|
|
|
// Handle all other links as XHR requests
|
2014-03-06 13:01:52 +01:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
2014-03-20 12:24:15 +01:00
|
|
|
// If link has hash tag...
|
|
|
|
if (href.match(/#/)) {
|
2014-03-08 15:01:57 +01:00
|
|
|
// ...it may be a menu section without a dedicated link.
|
|
|
|
// Switch the active menu item:
|
2014-03-08 14:53:17 +01:00
|
|
|
if (isMenuLink) {
|
2014-03-06 13:01:52 +01:00
|
|
|
$li = $a.closest('li');
|
|
|
|
$('#menu .active').removeClass('active');
|
|
|
|
$li.addClass('active');
|
2014-03-27 20:55:19 +01:00
|
|
|
if ($li.hasClass('hover')) {
|
|
|
|
$li.removeClass('hover');
|
|
|
|
}
|
2014-03-06 13:01:52 +01:00
|
|
|
}
|
2014-03-20 12:24:15 +01:00
|
|
|
if (href === '#') {
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-08 14:53:17 +01:00
|
|
|
|
2014-03-20 12:24:15 +01:00
|
|
|
$target = self.getLinkTargetFor($a);
|
2014-03-08 14:53:17 +01:00
|
|
|
|
2014-03-20 12:24:15 +01:00
|
|
|
formerUrl = $target.data('icingaUrl');
|
|
|
|
if (typeof formerUrl !== 'undefined' && formerUrl.split(/#/)[0] === href.split(/#/)[0]) {
|
|
|
|
icinga.ui.scrollContainerToAnchor($target, href.split(/#/)[1]);
|
|
|
|
$target.data('icingaUrl', href);
|
|
|
|
if (formerUrl !== href) {
|
|
|
|
icinga.history.pushCurrentState();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$target = self.getLinkTargetFor($a);
|
|
|
|
}
|
2014-03-08 14:53:17 +01:00
|
|
|
|
|
|
|
// Load link URL
|
2014-03-06 13:01:52 +01:00
|
|
|
icinga.loader.loadUrl(href, $target);
|
2014-03-06 13:08:11 +01:00
|
|
|
|
2014-03-08 14:53:17 +01:00
|
|
|
// Menu links should remove all but the first layout column
|
|
|
|
if (isMenuLink) {
|
2014-03-08 15:08:03 +01:00
|
|
|
icinga.ui.layout1col();
|
2014-03-06 13:01:52 +01:00
|
|
|
}
|
2014-03-06 13:08:11 +01:00
|
|
|
|
2014-03-08 15:25:10 +01:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detect the link/form target for a given element (link, form, whatever)
|
|
|
|
*/
|
|
|
|
getLinkTargetFor: function($el)
|
|
|
|
{
|
|
|
|
var targetId;
|
|
|
|
|
|
|
|
// If everything else fails, our target is the first column...
|
|
|
|
var $target = $('#col1');
|
|
|
|
|
|
|
|
// ...but usually we will use our own container...
|
|
|
|
var $container = $el.closest('.container');
|
|
|
|
if ($container.length) {
|
|
|
|
$target = $container;
|
|
|
|
}
|
|
|
|
|
2014-03-21 11:27:46 +01:00
|
|
|
// You can of course override the default behaviour:
|
2014-03-08 15:25:10 +01:00
|
|
|
if ($el.closest('[data-base-target]').length) {
|
|
|
|
targetId = $el.closest('[data-base-target]').data('baseTarget');
|
|
|
|
|
|
|
|
// Simulate _next to prepare migration to dynamic column layout
|
2014-03-20 16:41:36 +01:00
|
|
|
// YES, there are duplicate lines right now.
|
2014-03-08 15:25:10 +01:00
|
|
|
if (targetId === '_next') {
|
2014-03-17 17:10:03 +01:00
|
|
|
if ($el.closest('#col2').length) {
|
|
|
|
this.icinga.ui.moveToLeft();
|
|
|
|
}
|
2014-03-08 15:25:10 +01:00
|
|
|
targetId = 'col2';
|
2014-03-20 16:41:36 +01:00
|
|
|
$target = $('#' + targetId);
|
|
|
|
} else if (targetId === '_self') {
|
|
|
|
$target = $el.closest('.container');
|
|
|
|
targetId = $target.attr('id');
|
|
|
|
} else if (targetId === '_main') {
|
2014-03-09 23:30:37 +01:00
|
|
|
targetId = 'col1';
|
2014-03-20 16:41:36 +01:00
|
|
|
$target = $('#' + targetId);
|
2014-03-09 23:30:37 +01:00
|
|
|
icinga.ui.layout1col();
|
2014-03-20 16:41:36 +01:00
|
|
|
} else {
|
|
|
|
$target = $('#' + targetId);
|
2014-03-09 23:30:37 +01:00
|
|
|
}
|
|
|
|
|
2014-03-08 15:25:10 +01:00
|
|
|
}
|
|
|
|
|
2014-03-08 14:53:17 +01:00
|
|
|
// Hardcoded layout switch unless columns are dynamic
|
|
|
|
if ($target.attr('id') === 'col2') {
|
2014-03-08 15:08:03 +01:00
|
|
|
icinga.ui.layout2col();
|
2014-03-06 13:01:52 +01:00
|
|
|
}
|
2014-03-08 15:25:10 +01:00
|
|
|
|
|
|
|
return $target;
|
2014-03-06 13:01:52 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
hrefIsHashtag: function(href) {
|
|
|
|
// WARNING: IE gives full URL :(
|
|
|
|
// Also it doesn't support negativ indexes in substr
|
|
|
|
return href.substr(href.length - 1, 1) == '#';
|
|
|
|
},
|
|
|
|
*/
|
|
|
|
|
|
|
|
unbindGlobalHandlers: function () {
|
|
|
|
$(window).off('resize', this.onWindowResize);
|
2014-04-01 10:40:38 +02:00
|
|
|
$(window).off('load', this.onLoad);
|
2014-03-06 13:01:52 +01:00
|
|
|
$(window).off('unload', this.onUnload);
|
|
|
|
$(window).off('beforeunload', this.onUnload);
|
|
|
|
$(document).off('scroll', '.container', this.onContainerScroll);
|
|
|
|
$(document).off('click', 'a', this.linkClicked);
|
2014-04-23 19:41:07 +02:00
|
|
|
$(document).off('click', 'table.action tr[href]', this.rowSelected);
|
|
|
|
$(document).off('click', 'table.action tr a', this.rowSelected);
|
2014-03-06 13:01:52 +01:00
|
|
|
$(document).off('submit', 'form', this.submitForm);
|
2014-03-08 00:39:06 +01:00
|
|
|
$(document).off('click', 'button', this.submitForm);
|
2014-03-06 13:01:52 +01:00
|
|
|
$(document).off('change', 'form select.autosubmit', this.submitForm);
|
|
|
|
$(document).off('mouseenter', '.historycolorgrid td', this.historycolorgridHover);
|
2014-03-24 10:22:20 +01:00
|
|
|
$(document).off('mouseleave', '.historycolorgrid td', this.historycolorgidUnhover);
|
|
|
|
$(document).off('mouseenter', 'li.dropdown', this.dropdownHover);
|
|
|
|
$(document).off('mouseleave', 'li.dropdown', this.dropdownLeave);
|
2014-04-23 11:35:16 +02:00
|
|
|
$(document).off('click', 'div.tristate .tristate-dummy', this.clickTriState);
|
2014-03-06 13:01:52 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
// This is gonna be hard, clean up the mess
|
|
|
|
this.unbindGlobalHandlers();
|
|
|
|
this.icinga = null;
|
2014-03-05 13:38:38 +01:00
|
|
|
}
|
2014-03-06 13:01:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}(Icinga, jQuery));
|