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.

83 lines
1.7 KiB

Page.Log = new Class({
Extends: PageBase,
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){
14 years ago
self.log.set('html', self.addColors(json.log));
self.log.removeClass('loading');
14 years ago
14 years ago
new Fx.Scroll(window, {'duration': 0}).toBottom();
14 years ago
var nav = new Element('ul.nav').inject(self.log, 'top');
for (var i = 0; i <= json.total; i++) {
14 years ago
new Element('li', {
'text': i+1,
'class': nr == i ? 'active': '',
14 years ago
'events': {
'click': function(e){
self.getLogs(e.target.get('text')-1);
}
14 years ago
}
}).inject(nav);
14 years ago
};
14 years ago
new Element('li', {
'text': 'clear',
'events': {
'click': function(){
Api.request('logging.clear', {
'onComplete': function(){
self.getLogs(0);
}
});
}
}
}).inject(nav)
}
14 years ago
});
14 years ago
},
addColors: function(text){
var self = this;
text = text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/\u001b\[31m/gi, '</span><span class="error">')
.replace(/\u001b\[36m/gi, '</span><span class="debug">')
.replace(/\u001b\[33m/gi, '</span><span class="debug">')
.replace(/\u001b\[0m\n/gi, '</div><div class="time">')
.replace(/\u001b\[0m/gi, '</span><span>')
14 years ago
return '<div class="time">' + text + '</div>';
}
})