pandora/static/js/namesDialog.js

201 lines
6.7 KiB
JavaScript
Raw Permalink Normal View History

2011-11-05 17:04:10 +00:00
'use strict';
2018-06-19 06:33:26 +00:00
2011-10-11 11:29:05 +00:00
pandora.ui.namesDialog = function() {
// FIXME: add cache invalidation
2011-10-11 11:29:05 +00:00
var height = Math.round((window.innerHeight - 48) * 0.9),
2014-09-26 12:12:25 +00:00
width = 576 + Ox.UI.SCROLLBAR_SIZE,
2011-10-11 11:29:05 +00:00
$findInput = Ox.Input({
changeOnKeypress: true,
clear: true,
2014-02-13 16:24:52 +00:00
placeholder: Ox._('Find'),
2011-10-11 11:29:05 +00:00
width: 192
})
.css({float: 'right', margin: '4px'})
2011-10-11 11:29:05 +00:00
.bindEvent({
change: function(data) {
var query = {
conditions: [
2015-04-20 08:13:56 +00:00
{
key: 'name',
operator: '=',
value: data.value
},
{
key: 'sortname',
operator: '=',
value: data.value
}
],
operator: '|'
};
$list.options({
2012-06-20 10:47:15 +00:00
query: query,
2011-10-29 17:46:46 +00:00
});
2011-10-11 11:29:05 +00:00
}
}),
2012-06-27 07:41:39 +00:00
$list = Ox.TableList({
2011-10-11 11:29:05 +00:00
columns: [
{
id: 'id',
2013-05-09 10:13:58 +00:00
title: Ox._('ID'),
2011-10-11 11:29:05 +00:00
visible: false,
2011-10-11 16:01:33 +00:00
width: 0
2011-10-11 11:29:05 +00:00
},
{
id: 'name',
operator: '+',
removable: false,
2013-05-09 10:13:58 +00:00
title: Ox._('Name'),
2011-10-11 11:29:05 +00:00
visible: true,
2011-10-11 16:01:33 +00:00
width: 256
2011-10-11 11:29:05 +00:00
},
{
2011-10-11 16:01:33 +00:00
editable: true,
id: 'sortname',
2011-10-11 11:29:05 +00:00
operator: '+',
2013-05-09 10:13:58 +00:00
title: Ox._('Sort Name'),
tooltip: Ox._('Edit Sort Name'),
2011-10-11 11:29:05 +00:00
visible: true,
2011-10-11 16:01:33 +00:00
width: 256
2011-10-11 11:29:05 +00:00
},
{
id: 'numberofnames',
align: 'right',
operator: '-',
2013-05-09 10:13:58 +00:00
title: Ox._('Names'),
2011-10-11 11:29:05 +00:00
visible: true,
2011-10-11 16:01:33 +00:00
width: 64
2011-10-11 11:29:05 +00:00
},
],
columnsVisible: true,
items: pandora.api.findNames,
max: 1,
scrollbarVisible: true,
sort: [{key: 'sortname', operator: '+'}],
unique: 'id'
2011-10-11 11:29:05 +00:00
})
.bindEvent({
init: function(data) {
$status.html(
Ox.toTitleCase(Ox.formatCount(data.items, 'name'))
);
2011-10-11 11:29:05 +00:00
},
open: function(data) {
2012-05-22 13:15:16 +00:00
$list.find('.OxItem.OxSelected > .OxCell.OxColumnSortname')
.trigger('mousedown')
.trigger('mouseup');
},
select: function(data) {
$findButton.options({disabled: !data.ids.length});
},
2011-10-11 16:01:33 +00:00
submit: function(data) {
Ox.Request.clearCache('findNames');
2011-10-11 16:01:33 +00:00
pandora.api.editName({
id: data.id,
2011-10-11 16:58:12 +00:00
sortname: data.value
2011-10-11 16:01:33 +00:00
});
2011-10-11 11:29:05 +00:00
}
}),
$findButton = Ox.Button({
disabled: true,
2013-05-09 10:13:58 +00:00
title: Ox._('Find'),
2012-05-26 15:46:24 +00:00
width: 48
}).bindEvent({
click: function() {
that.close();
2013-07-14 15:36:49 +00:00
pandora.UI.set({find: {
conditions: [{
key: 'name',
2015-04-20 08:13:56 +00:00
value: $list.value(
$list.options('selected'), 'name'
),
operator: '='
}],
operator: '&'
2013-07-14 15:36:49 +00:00
}});
2012-06-11 08:50:03 +00:00
pandora.$ui.findElement.updateElement();
}
}),
2011-10-29 17:46:46 +00:00
2011-10-11 11:29:05 +00:00
that = Ox.Dialog({
buttons: [
Ox.Button({
2013-05-09 10:13:58 +00:00
title: Ox._('Manage Titles...')
}).bindEvent({
click: function() {
that.close();
(pandora.$ui.titlesDialog || (
pandora.$ui.titlesDialog = pandora.ui.titlesDialog()
)).open();
}
}),
{},
$findButton,
Ox.Button({
2013-05-09 10:13:58 +00:00
title: Ox._('Done'),
width: 48
}).bindEvent({
click: function() {
that.close();
}
})
2011-10-11 11:29:05 +00:00
],
closeButton: true,
content: Ox.SplitPanel({
elements: [
{
element: Ox.Bar({size: 24})
.append($status)
.append(
$findInput
),
size: 24
},
{
element: $list
}
],
orientation: 'vertical'
}),
height: height,
maximizeButton: true,
minHeight: 256,
minWidth: 512,
padding: 0,
2013-05-09 10:13:58 +00:00
title: Ox._('Manage Names'),
width: width
})
.bindEvent({
resizeend: function(data) {
2014-09-26 12:12:25 +00:00
var width = (data.width - 64 - Ox.UI.SCROLLBAR_SIZE) / 2;
[
{id: 'name', width: Math.ceil(width)},
{id: 'sortname', width: Math.floor(width)}
].forEach(function(column) {
$list.resizeColumn(column.id, column.width);
});
}
2011-10-11 11:29:05 +00:00
}),
$status = $('<div>')
.css({
position: 'absolute',
top: '4px',
left: '128px',
right: '128px',
bottom: '4px',
paddingTop: '2px',
fontSize: '9px',
textAlign: 'center'
})
.appendTo(that.find('.OxButtonsbar'));
2011-10-11 11:29:05 +00:00
return that;
};