ui.js indentation

This commit is contained in:
Thomas Gelf 2014-03-08 15:04:09 +01:00
parent 415193f9de
commit 7e2d6cd5c2

View File

@ -21,332 +21,332 @@
Icinga.UI.prototype = { Icinga.UI.prototype = {
initialize: function () { initialize: function () {
$('html').removeClass('no-js').addClass('js'); $('html').removeClass('no-js').addClass('js');
this.icinga.timer.register(this.refreshTimeSince, this, 1000); this.icinga.timer.register(this.refreshTimeSince, this, 1000);
this.triggerWindowResize(); this.triggerWindowResize();
this.fadeNotificationsAway(); this.fadeNotificationsAway();
}, },
fadeNotificationsAway: function() fadeNotificationsAway: function()
{ {
var icinga = this.icinga; var icinga = this.icinga;
$('#notifications li') $('#notifications li')
.not('.fading-out') .not('.fading-out')
.not('.persist') .not('.persist')
.addClass('fading-out') .addClass('fading-out')
.delay(7000) .delay(7000)
.fadeOut('slow', .fadeOut('slow',
function() { function() {
icinga.ui.fixControls(); icinga.ui.fixControls();
this.remove(); this.remove();
}); });
}, },
enableDebug: function () { enableDebug: function () {
this.debug = true; this.debug = true;
this.debugTimer = this.icinga.timer.register( this.debugTimer = this.icinga.timer.register(
this.refreshDebug, this.refreshDebug,
this, this,
1000 1000
); );
this.fixDebugVisibility(); this.fixDebugVisibility();
return this; return this;
}, },
fixDebugVisibility: function () { fixDebugVisibility: function () {
if (this.debug) { if (this.debug) {
$('#responsive-debug').css({display: 'block'}); $('#responsive-debug').css({display: 'block'});
} else { } else {
$('#responsive-debug').css({display: 'none'}); $('#responsive-debug').css({display: 'none'});
} }
return this; return this;
}, },
disableDebug: function () { disableDebug: function () {
if (this.debug === false) { return; } if (this.debug === false) { return; }
this.debug = false; this.debug = false;
this.icinga.timer.unregister(this.debugTimer); this.icinga.timer.unregister(this.debugTimer);
this.debugTimer = null; this.debugTimer = null;
this.fixDebugVisibility(); this.fixDebugVisibility();
return this; return this;
}, },
flipContent: function () { flipContent: function () {
var col1 = $('#col1 > div').detach(); var col1 = $('#col1 > div').detach();
var col2 = $('#col2 > div').detach(); var col2 = $('#col2 > div').detach();
$('#col2').html(''); $('#col2').html('');
$('#col1').html(''); $('#col1').html('');
col1.appendTo('#col2'); col1.appendTo('#col2');
col2.appendTo('#col1'); col2.appendTo('#col1');
this.fixControls(); this.fixControls();
}, },
triggerWindowResize: function () { triggerWindowResize: function () {
this.onWindowResize({data: {self: this}}); this.onWindowResize({data: {self: this}});
}, },
/** /**
* Our window got resized, let's fix our UI * Our window got resized, let's fix our UI
*/ */
onWindowResize: function (event) { onWindowResize: function (event) {
var self = event.data.self; var self = event.data.self;
self.fixControls(); self.fixControls();
if (self.layoutHasBeenChanged()) { if (self.layoutHasBeenChanged()) {
self.icinga.logger.info( self.icinga.logger.info(
'Layout change detected, switching to', 'Layout change detected, switching to',
self.currentLayout self.currentLayout
); );
} }
self.refreshDebug(); self.refreshDebug();
}, },
layoutHasBeenChanged: function () { layoutHasBeenChanged: function () {
var layout = $('html').css('fontFamily').replace(/['",]/g, ''); var layout = $('html').css('fontFamily').replace(/['",]/g, '');
var matched; var matched;
if (null !== (matched = layout.match(/^([a-z]+)-layout$/))) { if (null !== (matched = layout.match(/^([a-z]+)-layout$/))) {
if (matched[1] === this.currentLayout && if (matched[1] === this.currentLayout &&
$('#layout').hasClass(layout) $('#layout').hasClass(layout)
) { ) {
return false; return false;
} else { } else {
$('#layout').removeClass(this.currentLayout + '-layout').addClass(layout); $('#layout').removeClass(this.currentLayout + '-layout').addClass(layout);
this.currentLayout = matched[1]; this.currentLayout = matched[1];
if (this.currentLayout === 'poor' || this.currentLayout === 'minimal') { if (this.currentLayout === 'poor' || this.currentLayout === 'minimal') {
this.icinga.events.layout1col(); this.icinga.events.layout1col();
} }
return true; return true;
} }
} }
this.icinga.logger.error( this.icinga.logger.error(
'Someone messed up our responsiveness hacks, html font-family is', 'Someone messed up our responsiveness hacks, html font-family is',
layout layout
); );
return false; return false;
}, },
getAvailableColumnSpace: function () { getAvailableColumnSpace: function () {
return $('#main').width() / this.getDefaultFontSize(); return $('#main').width() / this.getDefaultFontSize();
}, },
setColumnCount: function (count) { setColumnCount: function (count) {
if (count === 3) { if (count === 3) {
$('#main > .container').css({ $('#main > .container').css({
width: '33.33333%' width: '33.33333%'
}); });
} else if (count === 2) { } else if (count === 2) {
$('#main > .container').css({ $('#main > .container').css({
width: '50%' width: '50%'
}); });
} else { } else {
$('#main > .container').css({ $('#main > .container').css({
width: '100%' width: '100%'
}); });
} }
}, },
setTitle: function (title) { setTitle: function (title) {
document.title = title; document.title = title;
return this; return this;
}, },
getColumnCount: function () { getColumnCount: function () {
return $('#main > .container').length; return $('#main > .container').length;
}, },
prepareContainers: function () { prepareContainers: function () {
var icinga = this.icinga; var icinga = this.icinga;
$('.container').each(function(idx, el) { $('.container').each(function(idx, el) {
icinga.events.applyHandlers($(el)); icinga.events.applyHandlers($(el));
icinga.ui.initializeControls($(el)); icinga.ui.initializeControls($(el));
}); });
/* /*
$('#icinga-main').attr( $('#icinga-main').attr(
'icingaurl', 'icingaurl',
window.location.pathname + window.location.search window.location.pathname + window.location.search
); );
*/ */
}, },
refreshDebug: function () { refreshDebug: function () {
var size = this.getDefaultFontSize().toString(); var size = this.getDefaultFontSize().toString();
var winWidth = $( window ).width(); var winWidth = $( window ).width();
var winHeight = $( window ).height(); var winHeight = $( window ).height();
var loading = ''; var loading = '';
$.each(this.icinga.loader.requests, function (el, req) { $.each(this.icinga.loader.requests, function (el, req) {
if (loading === '') { if (loading === '') {
loading = '<br />Loading:<br />'; loading = '<br />Loading:<br />';
} }
loading += el + ' => ' + req.url; loading += el + ' => ' + req.url;
}); });
$('#responsive-debug').html( $('#responsive-debug').html(
' Time: ' + ' Time: ' +
this.icinga.utils.formatHHiiss(new Date()) + this.icinga.utils.formatHHiiss(new Date()) +
'<br /> 1em: ' + '<br /> 1em: ' +
size + size +
'px<br /> Win: ' + 'px<br /> Win: ' +
winWidth + winWidth +
'x'+ 'x'+
winHeight + winHeight +
'px<br />' + 'px<br />' +
' Layout: ' + ' Layout: ' +
this.currentLayout + this.currentLayout +
loading loading
); );
}, },
refreshTimeSince: function () { refreshTimeSince: function () {
$('.timesince').each(function (idx, el) { $('.timesince').each(function (idx, el) {
var m = el.innerHTML.match(/^(-?\d+)m\s(-?\d+)s/); var m = el.innerHTML.match(/^(-?\d+)m\s(-?\d+)s/);
if (m !== null) { if (m !== null) {
var nm = parseInt(m[1]); var nm = parseInt(m[1]);
var ns = parseInt(m[2]); var ns = parseInt(m[2]);
if (ns < 59) { if (ns < 59) {
ns++; ns++;
} else { } else {
ns = 0; ns = 0;
nm++; nm++;
} }
$(el).html(nm + 'm ' + ns + 's'); $(el).html(nm + 'm ' + ns + 's');
} }
}); });
$('.timeunless').each(function (idx, el) { $('.timeunless').each(function (idx, el) {
var m = el.innerHTML.match(/^(-?\d+)m\s(-?\d+)s/); var m = el.innerHTML.match(/^(-?\d+)m\s(-?\d+)s/);
if (m !== null) { if (m !== null) {
var nm = parseInt(m[1]); var nm = parseInt(m[1]);
var ns = parseInt(m[2]); var ns = parseInt(m[2]);
if (nm >= 0) { if (nm >= 0) {
if (ns > 0) { if (ns > 0) {
ns--; ns--;
} else { } else {
ns = 59; ns = 59;
nm--; nm--;
} }
} else { } else {
if (ns < 59) { if (ns < 59) {
ns++; ns++;
} else { } else {
ns = 0; ns = 0;
nm--; nm--;
} }
} }
$(el).html(nm + 'm ' + ns + 's'); $(el).html(nm + 'm ' + ns + 's');
} }
}); });
}, },
createFontSizeCalculator: function () { createFontSizeCalculator: function () {
var $el = $('<div id="fontsize-calc">&nbsp;</div>'); var $el = $('<div id="fontsize-calc">&nbsp;</div>');
$('#layout').append($el); $('#layout').append($el);
return $el; return $el;
}, },
getDefaultFontSize: function () { getDefaultFontSize: function () {
var $calc = $('#fontsize-calc'); var $calc = $('#fontsize-calc');
if (! $calc.length) { if (! $calc.length) {
$calc = this.createFontSizeCalculator(); $calc = this.createFontSizeCalculator();
} }
return $calc.width() / 1000; return $calc.width() / 1000;
}, },
initializeControls: function (parent) { initializeControls: function (parent) {
var self = this; var self = this;
$('.controls', parent).each(function (idx, el) { $('.controls', parent).each(function (idx, el) {
var $el = $(el); var $el = $(el);
if (! $el.next('.fake-controls').length) { if (! $el.next('.fake-controls').length) {
var newdiv = $('<div class="fake-controls"></div>'); var newdiv = $('<div class="fake-controls"></div>');
newdiv.css({ newdiv.css({
height: $el.css('height') height: $el.css('height')
}); });
$el.after(newdiv); $el.after(newdiv);
} }
}); });
this.fixControls(parent); this.fixControls(parent);
}, },
fixControls: function ($parent) { fixControls: function ($parent) {
var self = this; var self = this;
if ('undefined' === typeof $parent) { if ('undefined' === typeof $parent) {
$('#header').css({height: 'auto'}); $('#header').css({height: 'auto'});
$('#main').css({top: $('#header').css('height')}); $('#main').css({top: $('#header').css('height')});
$('#sidebar').css({top: $('#header').height() + 'px'}); $('#sidebar').css({top: $('#header').height() + 'px'});
$('#header').css({height: $('#header').height() + 'px'}); $('#header').css({height: $('#header').height() + 'px'});
$('#inner-layout').css({top: $('#header').css('height')}); $('#inner-layout').css({top: $('#header').css('height')});
$('.container').each(function (idx, container) { $('.container').each(function (idx, container) {
self.fixControls($(container)); self.fixControls($(container));
}); });
return; return;
} }
self.icinga.logger.debug('Fixing controls for ', $parent); self.icinga.logger.debug('Fixing controls for ', $parent);
$('.controls', $parent).each(function (idx, el) { $('.controls', $parent).each(function (idx, el) {
var $el = $(el); var $el = $(el);
var $fake = $el.next('.fake-controls'); var $fake = $el.next('.fake-controls');
var y = $parent.scrollTop(); var y = $parent.scrollTop();
$el.css({ $el.css({
position : 'fixed', position : 'fixed',
top : $parent.offset().top, top : $parent.offset().top,
width : $fake.css('width') width : $fake.css('width')
}); });
$fake.css({ $fake.css({
height : $el.css('height'), height : $el.css('height'),
display : 'block' display : 'block'
}); });
}); });
}, },
toggleFullscreen: function () { toggleFullscreen: function () {
$('#layout').toggleClass('fullscreen-layout'); $('#layout').toggleClass('fullscreen-layout');
this.fixControls(); this.fixControls();
}, },
getWindowId: function () { getWindowId: function () {
var res = window.name.match(/^Icinga_([a-zA-Z0-9])$/); var res = window.name.match(/^Icinga_([a-zA-Z0-9])$/);
if (res) { if (res) {
return res[1]; return res[1];
} }
return null; return null;
}, },
hasWindowId: function () { hasWindowId: function () {
var res = window.name.match(/^Icinga_([a-zA-Z0-9])$/); var res = window.name.match(/^Icinga_([a-zA-Z0-9])$/);
return typeof res === 'object'; return typeof res === 'object';
}, },
setWindowId: function (id) { setWindowId: function (id) {
window.name = 'Icinga_' + id; window.name = 'Icinga_' + id;
}, },
destroy: function () { destroy: function () {
// This is gonna be hard, clean up the mess // This is gonna be hard, clean up the mess
this.icinga = null; this.icinga = null;
} }
}; };