You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.5 KiB

Page.Log = new Class({
Extends: PageBase,
order: 60,
name: 'log',
title: 'Show recent logs.',
has_tab: false,
indexAction: function(){
var self = this;
14 years ago
self.getLogs(0);
},
getLogs: function(nr){
var self = this;
if(self.log) self.log.destroy();
self.log = new Element('div.container.loading', {
'text': 'loading...'
14 years ago
}).inject(self.el);
Api.request('logging.get', {
'data': {
14 years ago
'nr': nr
},
'onComplete': function(json){
self.log.set('text', '');
self.log.adopt(self.createLogElements(json.log));
self.log.removeClass('loading');
14 years ago
var nav = new Element('ul.nav', {
'events': {
'click:relay(li.select)': function(e, el){
self.getLogs(parseInt(el.get('text'))-1);
}
}
});
14 years ago
// Type selection
new Element('li.filter').grab(
new Element('select', {
14 years ago
'events': {
'change': function(){
var type_filter = this.getSelected()[0].get('value');
self.log.set('data-filter', type_filter);
self.scrollToBottom();
}
14 years ago
}
}).adopt(
new Element('option', {'value': 'ALL', 'text': 'Show all logs'}),
new Element('option', {'value': 'INFO', 'text': 'Show only INFO'}),
new Element('option', {'value': 'DEBUG', 'text': 'Show only DEBUG'}),
new Element('option', {'value': 'ERROR', 'text': 'Show only ERROR'})
)
).inject(nav);
// Selections
for (var i = 0; i <= json.total; i++) {
new Element('li', {
'text': i+1,
'class': 'select ' + (nr == i ? 'active': '')
}).inject(nav);
11 years ago
}
14 years ago
// Clear button
new Element('li.clear', {
14 years ago
'text': 'clear',
'events': {
'click': function(){
Api.request('logging.clear', {
'onComplete': function(){
self.getLogs(0);
}
});
}
}
}).inject(nav);
// Add to page
nav.inject(self.log, 'top');
self.scrollToBottom();
}
14 years ago
});
14 years ago
},
createLogElements: function(logs){
14 years ago
var elements = [];
14 years ago
logs.each(function(log){
elements.include(new Element('div', {
'class': 'time ' + log.type.toLowerCase(),
'text': log.time
}).adopt(
new Element('span.type', {
'text': log.type
}),
new Element('span.message', {
'text': log.message
})
))
});
return elements;
},
scrollToBottom: function(){
new Fx.Scroll(window, {'duration': 0}).toBottom();
}
11 years ago
});