Fix look and feel of row selection

Always refresh all tables on render and click events, to display or remove active rows without any delay.

refs #9054
refs #9346
This commit is contained in:
Matthias Jentsch 2015-06-30 11:53:38 +02:00
parent 96677fb6c7
commit e0d588cda3

View File

@ -93,28 +93,6 @@
return tuple; return tuple;
}, },
/**
* If this table is currently used to control the selection
*
* @returns {Boolean}
*/
active: function() {
var loc = this.icinga.utils.parseUrl(window.location.href);
if (!loc.hash) {
return false;
}
if (this.getMultiselectionUrl()) {
var multiUrl = this.getMultiselectionUrl();
return multiUrl === loc.hash.split('?')[0].substr(1);
} else {
return this.rowActions().filter('[href="' + loc.hash.substr(1) + '"]').length > 1;
}
},
loading: function() {
},
clear: function() { clear: function() {
this.selections().removeClass('active'); this.selections().removeClass('active');
}, },
@ -210,6 +188,25 @@
} else { } else {
return ''; return '';
} }
},
refresh: function() {
this.clear();
var hash = this.icinga.utils.parseUrl(window.location.href).hash;
if (this.hasMultiselection()) {
var query = parseSelectionQuery(hash);
if (query.length > 1 && this.getMultiselectionUrl() === this.icinga.utils.parseUrl(hash.substr(1)).path) {
// select all rows with matching filters
var self = this;
$.each(query, function(i, selection) {
self.select(selection);
});
}
if (query.length > 1) {
return;
}
}
this.selectUrl(hash.substr(1));
} }
}; };
@ -237,16 +234,6 @@
}; };
Selection.prototype = new Icinga.EventListener(); Selection.prototype = new Icinga.EventListener();
Selection.prototype.toogleTableRowSelection = function ($tr) {
// multi selection
if ($tr.hasClass('active')) {
$tr.removeClass('active');
} else {
$tr.addClass('active');
}
return true;
};
Selection.prototype.tables = function(context) { Selection.prototype.tables = function(context) {
if (context) { if (context) {
return $(context).find('table.action'); return $(context).find('table.action');
@ -275,6 +262,7 @@
// range selection // range selection
table.range($tr); table.range($tr);
} else { } else {
// single selection
table.clear(); table.clear();
table.select($tr); table.select($tr);
} }
@ -285,25 +273,24 @@
// update history // update history
var url = self.icinga.utils.parseUrl(window.location.href.split('#')[0]); var url = self.icinga.utils.parseUrl(window.location.href.split('#')[0]);
if (table.selections().length > 0) { var count = table.selections().length;
var state = url.path + url.query;
if (count > 0) {
var query = table.toQuery(); var query = table.toQuery();
self.icinga.loader.loadUrl(query, self.icinga.events.getLinkTargetFor($tr)); self.icinga.loader.loadUrl(query, self.icinga.events.getLinkTargetFor($tr));
self.icinga.history.pushUrl(url.path + url.query + '#!' + query); state += '#!' + query;
} else { } else {
if (self.icinga.events.getLinkTargetFor($tr).attr('id') === 'col2') { if (self.icinga.events.getLinkTargetFor($tr).attr('id') === 'col2') {
icinga.ui.layout1col(); self.icinga.ui.layout1col();
} }
self.icinga.history.pushUrl(url.path + url.query);
} }
self.icinga.history.pushUrl(state);
// clear all inactive tables // re draw all table selections
this.tables().each(function () { self.tables().each(function () {
var t = new Table(this, self.icinga) new Table(this, self.icinga).refresh();
if (! t.active()) {
t.clear();
}
}); });
// update selection info // update selection info
$('.selection-info-count').text(table.selections().size()); $('.selection-info-count').text(table.selections().size());
return false; return false;
@ -312,28 +299,15 @@
Selection.prototype.onRendered = function(evt) { Selection.prototype.onRendered = function(evt) {
var container = evt.target; var container = evt.target;
var self = evt.data.self; var self = evt.data.self;
if (self.tables(container).length < 1) {
return;
}
// draw all selections // draw all selections
self.tables().each(function(i, el) { self.tables().each(function(i, el) {
var table = new Table(el, self.icinga); new Table(el, self.icinga).refresh();
table.clear();
if (! table.active()) {
return;
}
var hash = self.icinga.utils.parseUrl(window.location.href).hash;
if (table.hasMultiselection()) {
$.each(parseSelectionQuery(hash), function(i, selection) {
table.select(selection);
});
} else {
table.selectUrl(hash.substr(1));
}
$('.selection-info-count').text(table.selections().size());
}); });
// update displayed selection count
var table = new Table(self.tables(container).first());
$(container).find('.selection-info-count').text(table.selections().size());
}; };
Icinga.Behaviors.Selection = Selection; Icinga.Behaviors.Selection = Selection;