pandora/static/js/errorlogsDialog.js

254 lines
8.4 KiB
JavaScript
Raw Permalink Normal View History

2011-11-05 17:04:10 +00:00
'use strict';
pandora.ui.errorlogsDialog = function() {
2011-11-01 16:08:09 +00:00
var height = Math.round((window.innerHeight - 48) * 0.9),
width = Math.round(window.innerWidth * 0.9),
$reloadButton = Ox.Button({
disabled: true,
title: 'redo',
tooltip: Ox._('Reload'),
type: 'image'
})
.css({float: 'left', margin: '4px'})
.bindEvent({
click: function() {
$reloadButton.options({disabled: true});
2014-12-16 13:44:42 +00:00
Ox.Request.clearCache('findErrorLogs');
$list.reloadList(true);
}
}),
2011-11-01 16:08:09 +00:00
findFields = [
{id: 'all', title: Ox._('Find: All')},
{id: 'user', title: Ox._('Find: User')},
{id: 'url', title: Ox._('Find: URL')},
{id: 'text', title: Ox._('Find: Text')}
],
findFieldKeys = findFields.slice(1).map(function(f) { return f.id; }),
2011-11-01 16:08:09 +00:00
$findSelect = Ox.Select({
items: findFields,
2011-11-01 16:08:09 +00:00
overlap: 'right',
2011-12-22 18:30:03 +00:00
type: 'image',
value: 'all'
2011-11-01 16:08:09 +00:00
})
.bindEvent({
change: function(data) {
2011-12-21 15:34:28 +00:00
var key = data.value,
2011-11-01 16:08:09 +00:00
value = $findInput.value();
value && updateList(key, value);
$findInput.options({
2011-12-21 15:34:28 +00:00
placeholder: data.title
2011-11-01 16:08:09 +00:00
});
}
}),
$findInput = Ox.Input({
changeOnKeypress: true,
clear: true,
2013-05-10 14:54:30 +00:00
placeholder: Ox._('Find: All'),
2011-11-01 16:08:09 +00:00
width: 192
})
.bindEvent({
change: function(data) {
var key = $findSelect.value(),
value = data.value;
updateList(key, value);
}
}),
$findElement = Ox.FormElementGroup({
elements: [
$findSelect,
$findInput
]
})
.css({float: 'right', margin: '4px'}),
2012-06-27 07:41:39 +00:00
$list = Ox.TableList({
2011-11-01 16:08:09 +00:00
columns: [
{
id: 'id',
2013-05-09 10:13:58 +00:00
title: Ox._('ID'),
2012-05-26 15:46:24 +00:00
visible: false
2011-11-01 16:08:09 +00:00
},
{
format: function(value) {
2014-12-17 12:19:27 +00:00
return Ox.formatDate(value, "%Y-%m-%d %H:%M:%S");
},
2014-12-17 12:19:27 +00:00
id: 'created',
operator: '-',
title: Ox._('Date'),
2011-11-01 16:08:09 +00:00
visible: true,
2014-12-17 12:19:27 +00:00
width: 160
2011-11-01 16:08:09 +00:00
},
{
format: function(value) {
2014-12-17 12:19:27 +00:00
return Ox.encodeHTMLEntities(value);
2011-11-01 16:08:09 +00:00
},
2014-12-17 12:19:27 +00:00
id: 'user',
operator: '+',
title: Ox._('User'),
2011-11-01 16:08:09 +00:00
visible: true,
2014-12-17 12:19:27 +00:00
width: 160
2011-11-01 16:08:09 +00:00
},
{
format: function(value, data) {
2011-11-03 01:52:15 +00:00
return formatURL(value, data.line);
2011-11-02 17:58:16 +00:00
},
id: 'url',
2011-11-02 17:58:16 +00:00
operator: '+',
2013-05-09 10:13:58 +00:00
title: Ox._('URL'),
2011-11-02 17:58:16 +00:00
visible: true,
width: 320
2011-11-01 16:08:09 +00:00
},
{
format: function(value) {
return Ox.encodeHTMLEntities(value);
},
2011-11-01 16:08:09 +00:00
id: 'text',
operator: '+',
2013-05-09 10:13:58 +00:00
title: Ox._('Text'),
2011-11-02 17:58:16 +00:00
visible: true,
width: 640
2011-11-01 16:08:09 +00:00
},
],
2011-11-02 17:58:16 +00:00
columnsMovable: true,
columnsResizable: true,
2011-11-01 16:08:09 +00:00
columnsVisible: true,
2014-12-16 13:44:42 +00:00
items: pandora.api.findErrorLogs,
2011-11-02 17:58:16 +00:00
keys: ['line'],
2011-11-01 16:08:09 +00:00
scrollbarVisible: true,
sort: [{key: 'created', operator: '-'}],
unique: 'id'
2011-11-01 16:08:09 +00:00
})
.bindEvent({
init: function(data) {
$status.html(Ox.toTitleCase(
Ox.formatCount(data.items, 'entry', 'entries')
));
2011-11-01 16:08:09 +00:00
},
'delete': function(data) {
2014-12-16 13:44:42 +00:00
pandora.api.removeErrorLogs({ids: data.ids}, function(result) {
Ox.Request.clearCache('findErrorLogs');
2012-03-18 17:52:59 +00:00
$list.reloadList();
2011-11-01 16:08:09 +00:00
});
2011-11-03 01:52:15 +00:00
},
load: function() {
$reloadButton.options({disabled: false});
},
2011-11-03 01:52:15 +00:00
open: function(data) {
var value = $list.value(Ox.last(data.ids)),
$dialog;
$dialog = Ox.Dialog({
buttons: [
Ox.Button({
id: 'close',
title: Ox._('Close')
})
.bindEvent({
click: function() {
$dialog.close();
}
})
],
closeButton: true,
content: $('<code>').append(
$('<pre>')
.addClass('OxSelectable')
.css({margin: '16px'})
.text(value.text)
),
height: height - 48,
keys: {enter: 'close', escape: 'close'},
maximizeButton: true,
removeOnClose: true,
title: formatURL(value.url, value.line),
width: width - 48
})
.open();
2011-11-01 16:08:09 +00:00
}
}),
that = Ox.Dialog({
buttons: [
Ox.Button({
id: 'done',
2013-05-09 10:13:58 +00:00
title: Ox._('Done'),
2011-11-01 16:08:09 +00:00
width: 48
}).bindEvent({
click: function() {
that.close();
}
})
],
closeButton: true,
content: Ox.SplitPanel({
elements: [
{
2011-11-02 17:58:16 +00:00
element: Ox.Bar({size: 24})
.append($reloadButton)
.append($findElement),
2011-11-02 17:58:16 +00:00
size: 24
2011-11-01 16:08:09 +00:00
},
{
2011-11-02 17:58:16 +00:00
element: $list
2011-11-01 16:08:09 +00:00
}
],
2011-11-02 17:58:16 +00:00
orientation: 'vertical'
2011-11-01 16:08:09 +00:00
}),
height: height,
maximizeButton: true,
minHeight: 256,
minWidth: 512,
padding: 0,
2012-03-18 17:52:59 +00:00
removeOnClose: true,
2013-05-09 10:13:58 +00:00
title: Ox._('Error Logs'),
2011-11-01 16:08:09 +00:00
width: width
}),
$status = $('<div>')
.css({
position: 'absolute',
top: '4px',
2011-11-03 12:58:22 +00:00
left: '128px',
right: '128px',
2011-11-01 16:08:09 +00:00
bottom: '4px',
paddingTop: '2px',
fontSize: '9px',
2012-05-26 15:46:24 +00:00
textAlign: 'center'
2011-11-01 16:08:09 +00:00
})
2012-05-22 13:15:16 +00:00
.appendTo(that.find('.OxButtonsbar'));
2011-11-01 16:08:09 +00:00
that.superClose = that.close;
that.close = function() {
2014-12-16 13:44:42 +00:00
Ox.Request.clearCache('findErrorLogs');
that.superClose();
};
2011-11-03 01:52:15 +00:00
function formatURL(url, line) {
return Ox.encodeHTMLEntities(url.split('?')[0]) + ':' + line;
2011-11-03 01:52:15 +00:00
}
2011-11-01 16:08:09 +00:00
function updateList(key, value) {
var keys = key == 'all' ? findFieldKeys : [key];
2011-11-01 16:08:09 +00:00
var query = {
conditions: keys.map(function(k) {
return {key: k, value: value, operator: '='};
}),
operator: '|'
2011-11-01 16:08:09 +00:00
};
$list.options({
items: function(data, callback) {
2014-12-16 13:44:42 +00:00
return pandora.api.findErrorLogs(Ox.extend(data, {
2011-11-01 16:08:09 +00:00
query: query
}), callback);
}
});
}
return that;
};