Re-design configuration interface

Conflicts:
	public/js/icinga/events.js
This commit is contained in:
Alexander Klimov 2014-03-05 13:38:38 +01:00
parent 63c73a8215
commit d2ec3c9509
6 changed files with 327 additions and 347 deletions

View File

@ -134,6 +134,8 @@ class DbBackendForm extends BaseBackendForm
*/ */
public function isValidAuthenticationBackend() public function isValidAuthenticationBackend()
{ {
// @TODO fix validation of authentication backends (AK #5712)
//return true;
try { try {
$name = $this->getBackendName(); $name = $this->getBackendName();
$dbBackend = new DbUserBackend( $dbBackend = new DbUserBackend(

View File

@ -114,10 +114,9 @@ class ReorderForm extends Form
array( array(
'type' => 'submit', 'type' => 'submit',
'escape' => false, 'escape' => false,
'class' => 'btn btn-cta btn-wide',
'value' => 'btn_' . $this->getBackendName() . '_reorder_up', 'value' => 'btn_' . $this->getBackendName() . '_reorder_up',
'name' => 'btn_' . $this->getBackendName() . '_reorder_up', 'name' => 'btn_' . $this->getBackendName() . '_reorder_up',
'label' => '<i class="icinga-icon-up"></i> Move up in authentication order', 'label' => '<img src="/icingaweb/img/icons/up.png" title="Move up in authentication order" />',
) )
); );
} }
@ -137,10 +136,9 @@ class ReorderForm extends Form
array( array(
'type' => 'submit', 'type' => 'submit',
'escape' => false, 'escape' => false,
'class' => 'btn btn-cta btn-wide',
'value' => 'btn_' . $this->getBackendName() . '_reorder_down', 'value' => 'btn_' . $this->getBackendName() . '_reorder_down',
'name' => 'btn_' . $this->getBackendName() . '_reorder_down', 'name' => 'btn_' . $this->getBackendName() . '_reorder_down',
'label' => '<i class="icinga-icon-down"></i> Move down in authentication order', 'label' => '<img src="/icingaweb/img/icons/down.png" title="Move down in authentication order" />',
) )
); );

View File

@ -12,35 +12,33 @@ $createDbBackend = $this->href('/config/createAuthenticationBackend', array('typ
<?= $this->messageBox->render() ?> <?= $this->messageBox->render() ?>
<?php endif ?> <?php endif ?>
<div> <h1>Create Authentication Provider</h1>
<div> <p>
Create Authentication Provider <a href="<?= $createLdapBackend ?>"><?= $this->img('img/icons/create.png', array('title' => 'Create A New LDAP Authentication Backend'));
</div> ?> Create A New LDAP Authentication Backend</a>
<div> <br />
<a href="<?= $createLdapBackend ?>"><i class="icinga-icon-create"></i> Create A New LDAP Authentication Backend</a><br/> <a href="<?= $createDbBackend ?>"><?= $this->img('img/icons/create.png', array('title' => 'Create A New DB Authentication Backend'));
<a href="<?= $createDbBackend ?>"><i class="icinga-icon-create"></i> Create A New DB Authentication Backend</a> ?> Create A New DB Authentication Backend</a>
</div> </p>
</div>
<table class="configTable">
<?php foreach ($this->backends as $backend): ?> <?php foreach ($this->backends as $backend): ?>
<tr>
<td class="configTable">
<div> <div>
<div> <b>Backend:</b>&ensp;<?= $this->escape($backend->name); ?>
Backend <?= $this->escape($backend->name); ?>
<br/>
<?= $backend->reorderForm; ?>
</div> </div>
<div> <div>
<?= $backend->reorderForm; ?>
<a href="<?= $this->href('config/editAuthenticationBackend', array('auth_backend' => $backend->name));?>"> <a href="<?= $this->href('config/editAuthenticationBackend', array('auth_backend' => $backend->name));?>">
<i class="icinga-icon-edit"></i> Edit This Authentication Provider <?= $this->img('img/icons/edit.png', array('title' => 'Edit')); ?> Edit</a>&emsp;
</a>
<br/>
<?php if (count($this->backends) > 1): ?> <?php if (count($this->backends) > 1): ?>
<a href="<?= $this->href('config/removeAuthenticationBackend', array('auth_backend' => $backend->name));?>"> <a href="<?= $this->href('config/removeAuthenticationBackend', array('auth_backend' => $backend->name));?>">
<i class="icinga-icon-remove"></i> Remove This Authentication Provider <?= $this->img('img/icons/remove.png', array('title' => 'Remove')); ?> Remove</a>&emsp;
</a>
<br/>
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </td>
</tr>
<?php endforeach; ?> <?php endforeach; ?>
</table>
</div> </div>

View File

@ -11,39 +11,28 @@ $createResource = $this->href('/config/createresource');
<?= $this->messageBox->render() ?> <?= $this->messageBox->render() ?>
<?php endif ?> <?php endif ?>
<div> <h1>Create Resource</h1>
<div> <p><a href="<?= $createResource ?>"><?= $this->img('img/icons/create.png', array('title' => 'Create A New Resource'));
Create Resource ?> Create A New Resource</a></p>
</div>
<div>
<a href="<?= $createResource ?>"><i class="icinga-icon-create"></i> Create A New Resource</a><br/>
</div>
</div>
<table class="configTable">
<?php foreach ($this->resources as $name => $resource): ?> <?php foreach ($this->resources as $name => $resource): ?>
<tr>
<td class="configTable">
<div> <div>
<b>Resource:</b>&ensp;<?= $this->escape($name); ?>
<div>
<b>Resource: </b> <?= $this->escape($name); ?>
<br/>
</div> </div>
<div> <div>
<a href="<?= $this->href('config/editresource', array('resource' => $name));?>"> <a href="<?= $this->href('config/editresource', array('resource' => $name));?>">
<i class="icinga-icon-edit"></i> Edit This Resource <?= $this->img('img/icons/edit.png', array('title' => 'Edit')); ?> Edit</a>&emsp;
</a>
<br/>
<?php if (count($this->resources) > 1): ?> <?php if (count($this->resources) > 1): ?>
<a href="<?= $this->href('config/removeresource', array('resource' => $name));?>"> <a href="<?= $this->href('config/removeresource', array('resource' => $name));?>">
<i class="icinga-icon-remove"></i> Remove This Resource <?= $this->img('img/icons/remove.png', array('title' => 'Remove')); ?> Remove</a>&emsp;
</a>
<br/>
<?php endif; ?> <?php endif; ?>
</div>
</div> </div>
</td>
</tr>
<?php endforeach; ?> <?php endforeach; ?>
</table>
</div> </div>

View File

@ -1,4 +1,19 @@
table.configTable {
border-spacing: 10px;
border-collapse: separate;
}
td.configTable {
border: solid;
border-width: thin;
padding: 10px;
}
div.form-group {
float: right;
}
.form-group { .form-group {
margin-bottom: 1em; margin-bottom: 1em;
} }

View File

@ -1,11 +1,4 @@
/** (function(Icinga) {
* Icinga.Events
*
* Event handlers
*/
(function (Icinga, $) {
'use strict';
Icinga.Events = function(icinga) { Icinga.Events = function(icinga) {
this.icinga = icinga; this.icinga = icinga;
@ -16,23 +9,21 @@
/** /**
* Icinga will call our initialize() function once it's ready * Icinga will call our initialize() function once it's ready
*/ */
initialize: function () { initialize: function()
{
this.applyGlobalDefaults(); this.applyGlobalDefaults();
this.applyHandlers($('#layout'));
this.icinga.ui.prepareContainers(); this.icinga.ui.prepareContainers();
}, },
// TODO: What's this? // TODO: What's this?
applyHandlers: function (el) { applyHandlers: function(el)
{
var icinga = this.icinga; var icinga = this.icinga;
$('.dashboard > div', el).each(function(idx, el) { $('.dashboard > div', el).each(function(idx, el) {
var url = $(el).attr('data-icinga-url'); var url = $(el).attr('data-icinga-url');
if (typeof url === 'undefined') return; if (typeof url === 'undefined') return;
icinga.loader.loadUrl(url, $(el)).autorefresh = true; icinga.loader.loadUrl(url, $(el)).autorefresh = true;
}); });
// Set first links href in a action table tr as row href: // Set first links href in a action table tr as row href:
$('table.action tr', el).each(function(idx, el) { $('table.action tr', el).each(function(idx, el) {
var $a = $('a[href]', el).first(); var $a = $('a[href]', el).first();
@ -40,9 +31,8 @@
$(el).attr('href', $a.attr('href')); $(el).attr('href', $a.attr('href'));
} }
}); });
$('.icinga-module', el).each(function(idx, mod) { $('.icinga-module', el).each(function(idx, mod) {
var $mod = $(mod); $mod = $(mod);
var moduleName = $mod.data('icinga-module'); var moduleName = $mod.data('icinga-module');
if (icinga.hasModule(moduleName)) { if (icinga.hasModule(moduleName)) {
var module = icinga.module(moduleName); var module = icinga.module(moduleName);
@ -50,22 +40,21 @@
} }
}); });
$('input.autofocus', el).focus();
$('.inlinepie', el).sparkline('html', { $('.inlinepie', el).sparkline('html', {
type: 'pie', type: 'pie',
sliceColors: ['#44bb77', '#ffaa44', '#ff5566', '#dcd'], sliceColors: ['#44bb77', '#ffaa44', '#ff5566', '#dcd'],
width: '2em', width: '2em',
height: '2em', height: '2em',
}); });
},
},
/** /**
* Global default event handlers * Global default event handlers
*/ */
applyGlobalDefaults: function () { applyGlobalDefaults: function()
{
// We catch resize events // We catch resize events
$(window).on('resize', { self: this.icinga.ui }, this.icinga.ui.onWindowResize); $(window).on('resize', { self: this }, this.onWindowResize);
// Destroy Icinga, clean up and interrupt pending requests on unload // Destroy Icinga, clean up and interrupt pending requests on unload
$( window ).on('unload', { self: this }, this.onUnload); $( window ).on('unload', { self: this }, this.onUnload);
@ -86,10 +75,7 @@
// We support an 'autosubmit' class on dropdown form elements // We support an 'autosubmit' class on dropdown form elements
$(document).on('change', 'form select.autosubmit', { self: this }, this.submitForm); $(document).on('change', 'form select.autosubmit', { self: this }, this.submitForm);
$(document).on('keyup', '#menu input.search', {self: this}, this.submitForm); $(window).on('popstate', { self: this }, this.historyChanged);
$(document).on('mouseenter', '.historycolorgrid td', this.historycolorgridHover);
$(document).on('mouseleave', '.historycolorgrid td', this.historycolorgidUnhover);
// TBD: a global autocompletion handler // TBD: a global autocompletion handler
// $(document).on('keyup', 'form.auto input', this.formChangeDelayed); // $(document).on('keyup', 'form.auto input', this.formChangeDelayed);
@ -97,32 +83,50 @@
// $(document).on('change', 'form.auto select', this.submitForm); // $(document).on('change', 'form.auto select', this.submitForm);
}, },
onUnload: function (event) { onUnload: function(event)
{
var icinga = event.data.self.icinga; var icinga = event.data.self.icinga;
icinga.logger.info('Unloading Icinga'); icinga.logger.info('Unloading Icinga');
icinga.destroy(); icinga.destroy();
}, },
historyChanged: function(event)
{
var icinga = event.data.self.icinga;
if (event.originalEvent.state === null) {
icinga.logger.debug('No more history steps available');
} else {
icinga.logger.debug(event.originalEvent.state);
}
icinga.loader.loadUrl(
document.location.pathname + document.location.search,
$('#col1')
).historyTriggered = true;
},
/** /**
* A scroll event happened in one of our containers * Our window got resized, let's fix our UI
*/ */
onContainerScroll: function (event) { onWindowResize: function(event)
// Ugly. And PLEASE, not so often {
var icinga = event.data.self.icinga;
icinga.ui.fixControls(); icinga.ui.fixControls();
}, },
historycolorgridHover: function () { /**
$(this).addClass('hover'); * A scroll event happened in one of our containers
}, */
onContainerScroll: function(event)
historycolorgidUnhover: function() { {
$(this).removeClass('hover'); // Yet ugly. And PLEASE, not so often
icinga.ui.fixControls();
}, },
/** /**
* *
*/ */
submitForm: function (event) { submitForm: function (event)
{
var icinga = event.data.self.icinga; var icinga = event.data.self.icinga;
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
@ -138,66 +142,38 @@
icinga.logger.debug('Submitting form: ' + method + ' ' + url); icinga.logger.debug('Submitting form: ' + method + ' ' + url);
// We should move this to a generic target-finder: // We should move this to a generic target-finder:
var $target = null; var $target = $form.closest('.container');
if ($form.closest('[data-base-target]').length) { if ($target.length == 0) {
$target = $( $target = $('#body');
'#' + $form.closest('[data-base-target]').data('baseTarget')
);
} else if ($form.closest('.container').length) {
$target = $form.closest('.container');
} else {
icinga.logger.error('No form target found, stopping here');
return false;
} }
icinga.loader.loadUrl(url, $target, data, method); icinga.loader.loadUrl(url, $target, data, method);
// TODO: Do we really need to return false with stop/preventDefault? // TODO: Do we really need to return false with stop/preventDefault?
return false; return false;
}, },
layout1col: function () {
if (! $('#layout').hasClass('twocols')) { return; }
var $col2 = $('#col2');
icinga.logger.debug('Switching to single col');
$('#layout').removeClass('twocols');
$col2.removeAttr('data-icinga-url');
$col2.removeAttr('data-icinga-refresh');
$col2.removeData('icingaUrl');
$col2.removeData('icingaRefresh');
this.icinga.loader.stopPendingRequestsFor($col2);
$col2.html('');
this.icinga.ui.fixControls();
},
layout2col: function () {
if ($('#layout').hasClass('twocols')) { return; }
icinga.logger.debug('Switching to double col');
$('#layout').addClass('twocols');
this.icinga.ui.fixControls();
},
/** /**
* Someone clicked a link or tr[href] * Someone clicked a link or tr[href]
*/ */
linkClicked: function (event) { linkClicked: function(event)
{
var icinga = event.data.self.icinga; var icinga = event.data.self.icinga;
var $a = $(this); var $a = $(this);
var href = $a.attr('href'); var href = $a.attr('href');
var $li;
var targetId;
if ($a.attr('target') === '_blank') { if ($a.attr('target') === '_blank') {
return true; return true;
} }
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
// If link is hash tag...
if (href === '#') { if (href === '#') {
if ($a.closest('#menu')) { if ($a.closest('#menu')) {
$li = $a.closest('li'); var $li = $a.closest('li');
$('#menu .active').removeClass('active'); $li.siblings('li.active').removeClass('active');
$li.addClass('active'); $li.addClass('active');
} }
return; return;
@ -207,20 +183,19 @@
if ($container.length) { if ($container.length) {
$target = $container; $target = $container;
} }
// If link is hash tag...
if ($a.closest('table.action').length) { if ($a.closest('table.action').length) {
$target = $('#col2'); $target = $('#col2');
icinga.events.layout2col(); $('#layout').addClass('twocols');
icinga.ui.fixControls();
} }
if ($a.closest('[data-base-target]').length) { if ($a.closest('[data-base-target]').length) {
targetId = $a.closest('[data-base-target]').data('baseTarget'); $target = $('#' + $a.closest('[data-base-target]').data('baseTarget'));
$target = $('#' + targetId); $('#layout').addClass('twocols');
if (targetId === 'col2') { icinga.ui.fixControls();
icinga.events.layout2col();
}
} }
if ($a.closest('.tree').length) { if ($a.closest('.tree').length) {
$li = $a.closest('li'); var $li = $a.closest('li');
if ($li.find('li').length) { if ($li.find('li').length) {
if ($li.hasClass('collapsed')) { if ($li.hasClass('collapsed')) {
$li.removeClass('collapsed'); $li.removeClass('collapsed');
@ -231,41 +206,46 @@
return false; return false;
} else { } else {
$target = $('#col2'); $target = $('#col2');
icinga.events.layout2col(); $('#layout').addClass('twocols');
icinga.ui.fixControls();
} }
} }
icinga.loader.loadUrl(href, $target); icinga.loader.loadUrl(href, $target);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if ($a.closest('#menu').length) { if ($a.closest('#menu').length) {
icinga.events.layout1col(); $('#layout').removeClass('twocols');
$('#col2').html('<ul class="tabs"></ul>');
icinga.ui.fixControls();
return false; return false;
} }
if ($a.closest('table').length) {
if ($a.closest('table.action').length) {
if ($('#layout').hasClass('twocols')) { if ($('#layout').hasClass('twocols')) {
if ($target.attr('id') === 'col2') { if ($target.attr('id') === 'col2') return;
return; icinga.logger.debug('Switching to single col');
} $('#layout').removeClass('twocols');
icinga.events.layout1col(); icinga.ui.fixControls();
} else { } else {
icinga.events.layout2col(); icinga.logger.debug('Switching to double col');
$('#layout').addClass('twocols');
icinga.ui.fixControls();
} }
return false; return false;
} }
}, },
/* /*
hrefIsHashtag: function(href) { hrefIsHashtag: function(href)
{
// WARNING: IE gives full URL :( // WARNING: IE gives full URL :(
// Also it doesn't support negativ indexes in substr // Also it doesn't support negativ indexes in substr
return href.substr(href.length - 1, 1) == '#'; return href.substr(href.length - 1, 1) == '#';
}, },
*/ */
unbindGlobalHandlers: function () { unbindGlobalHandlers: function()
{
$(window).off('popstate', this.historyChanged);
$(window).off('resize', this.onWindowResize); $(window).off('resize', this.onWindowResize);
$(window).off('unload', this.onUnload); $(window).off('unload', this.onUnload);
$(window).off('beforeunload', this.onUnload); $(window).off('beforeunload', this.onUnload);
@ -274,8 +254,6 @@
$(document).off('click', 'tr[href]', this.linkClicked); $(document).off('click', 'tr[href]', this.linkClicked);
$(document).off('submit', 'form', this.submitForm); $(document).off('submit', 'form', this.submitForm);
$(document).off('change', 'form select.autosubmit', this.submitForm); $(document).off('change', 'form select.autosubmit', this.submitForm);
$(document).off('mouseenter', '.historycolorgrid td', this.historycolorgridHover);
$(document).off('mouseenter', '.historycolorgrid td', this.historycolorgidUnhover);
}, },
destroy: function() { destroy: function() {
@ -285,4 +263,4 @@
} }
}; };
}(Icinga, jQuery)); }(Icinga));