pandora/static/js/changelogDialog.js

252 lines
8.5 KiB
JavaScript
Raw Permalink Normal View History

2011-11-05 17:04:10 +00:00
'use strict';
pandora.ui.changelogDialog = 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 14:04:42 +00:00
Ox.Request.clearCache('findChangeLogs');
$list.reloadList(true);
}
}),
2011-11-01 16:08:09 +00:00
$findSelect = Ox.Select({
items: [
2013-05-09 10:13:58 +00:00
{id: 'all', title: Ox._('Find: All')},
{id: 'user', title: Ox._('Find: User')},
2014-12-17 12:54:04 +00:00
{id: 'action', title: Ox._('Find: Action')},
{id: 'changeid', title: Ox._('Find: ID')}
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
},
2014-12-17 12:19:42 +00:00
{
format: function(value) {
2016-08-13 11:56:29 +00:00
return Ox.formatDate(value, '%Y-%m-%d %H:%M:%S');
2014-12-17 12:19:42 +00:00
},
id: 'created',
operator: '-',
title: Ox._('Date'),
visible: true,
width: 160
},
2011-11-01 16:08:09 +00:00
{
format: function(value) {
return Ox.encodeHTMLEntities(value);
},
2011-11-02 17:58:16 +00:00
id: 'user',
operator: '+',
2013-05-09 10:13:58 +00:00
title: Ox._('User'),
2011-11-01 16:08:09 +00:00
visible: true,
2014-12-17 12:19:42 +00:00
width: 160
2011-11-01 16:08:09 +00:00
},
{
2014-12-17 12:19:42 +00:00
id: 'action',
operator: '+',
title: Ox._('Action'),
2011-11-01 16:08:09 +00:00
visible: true,
2014-12-17 12:19:42 +00:00
width: 160
2011-11-01 16:08:09 +00:00
},
{
format: function(value, data) {
2014-12-17 12:19:42 +00:00
return value; // FIXME: TODO
2011-11-02 17:58:16 +00:00
},
id: 'changeid',
2011-11-02 17:58:16 +00:00
operator: '+',
title: Ox._('ID'),
2011-11-02 17:58:16 +00:00
visible: true,
2014-12-17 13:47:25 +00:00
width: 160
2011-11-01 16:08:09 +00:00
},
{
format: function(value) {
2014-12-17 12:19:42 +00:00
return Ox.encodeHTMLEntities(JSON.stringify(value));
},
2014-12-17 12:19:42 +00:00
id: 'data',
operator: '+',
title: Ox._('Data'),
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 14:04:42 +00:00
items: pandora.api.findChangeLogs,
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
},
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)),
2014-12-17 17:11:04 +00:00
FIXME = Ox.print(value),
2011-11-03 01:52:15 +00:00
$dialog = Ox.Dialog({
buttons: [
Ox.Button({
id: 'close',
2013-05-09 10:13:58 +00:00
title: Ox._('Close')
2011-11-03 01:52:15 +00:00
})
.bindEvent({
click: function() {
$dialog.close();
}
})
],
closeButton: true,
2014-12-17 17:05:47 +00:00
content: $('<code>').append(
$('<pre>')
.addClass('OxSelectable')
.css({margin: '16px'})
2014-12-17 17:14:09 +00:00
.text(JSON.stringify(value.data, null, ' '))
2014-12-17 17:05:47 +00:00
),
2011-11-03 01:52:15 +00:00
height: height - 48,
keys: {enter: 'close', escape: 'close'},
maximizeButton: true,
2012-03-18 17:52:59 +00:00
removeOnClose: true,
2014-12-17 17:06:54 +00:00
title: [value.user, value.action, value.changeid].join(' &mdash; '),
2011-11-03 01:52:15 +00:00
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,
2014-12-16 14:04:42 +00:00
title: Ox._('Changelog'),
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 14:04:42 +00:00
Ox.Request.clearCache('findChangeLogs');
that.superClose();
};
2011-11-01 16:08:09 +00:00
function updateList(key, value) {
var query = {
2014-12-17 12:54:04 +00:00
conditions: key == 'all' ? [
{key: 'user', value: value, operator: '='},
{key: 'action', value: value, operator: '='},
{key: 'changeid', value: value, operator: '='}
] : [
{key: key, value: value, operator: '='}
],
2011-11-01 16:08:09 +00:00
operator: key == 'all' ? '|' : '&'
};
$list.options({
items: function(data, callback) {
2014-12-16 14:04:42 +00:00
return pandora.api.findChangeLogs(Ox.extend(data, {
2011-11-01 16:08:09 +00:00
query: query
}), callback);
}
});
}
return that;
};