pandora/static/js/allItems.js

147 lines
4.5 KiB
JavaScript
Raw Normal View History

2011-11-06 18:36:40 +00:00
'use strict';
2013-07-15 11:39:23 +00:00
pandora.ui.allItems = function(section) {
// FIXME: Why is this not a list?
2013-07-15 11:39:23 +00:00
section = section || pandora.user.ui.section;
2011-11-06 18:36:40 +00:00
2013-03-03 06:34:42 +00:00
var canAddItems = !pandora.site.itemRequiresVideo && pandora.site.capabilities.canAddItems[pandora.user.level],
canUploadVideo = pandora.site.capabilities.canAddItems[pandora.user.level],
that = Ox.Element()
.addClass('OxSelectableElement' + (pandora.user.ui._list ? '' : ' OxSelected'))
.css({
height: '16px',
cursor: 'default',
overflow: 'hidden'
})
.on({
click: function() {
that.gainFocus();
2013-07-15 11:39:23 +00:00
if (section == 'items') {
2013-07-14 15:36:49 +00:00
pandora.user.ui._list && pandora.UI.set({find: {conditions: [], operator: '&'}});
2013-03-03 06:34:42 +00:00
} else {
2013-07-15 11:39:23 +00:00
pandora.UI.set(section.slice(0, -1), '');
2013-03-03 06:34:42 +00:00
}
}
})
.bindEvent({
2013-07-14 17:49:24 +00:00
pandora_edit: updateSelected,
pandora_find: updateSelected,
pandora_section: updateSelected,
pandora_text: updateSelected
2013-03-03 06:34:42 +00:00
}),
$icon = $('<img>')
.attr({src: '/static/png/icon.png'})
.css({float: 'left', width: '14px', height: '14px', margin: '1px'})
.appendTo(that),
$name = $('<div>')
.css({
float: 'left',
height: '14px',
margin: '1px 4px 1px 3px',
textOverflow: 'ellipsis',
overflow: 'hidden',
whiteSpace: 'nowrap'
})
.html(pandora.getAllItemsTitle(section))
2013-03-03 06:34:42 +00:00
.appendTo(that),
$items,
$buttons = [];
2011-11-06 18:36:40 +00:00
2013-07-15 11:39:23 +00:00
if (section == 'items') {
$items = $('<div>')
2013-02-16 01:20:40 +00:00
.css({
float: 'left',
width: '42px',
margin: '1px 4px 1px 3px',
textAlign: 'right'
})
.appendTo(that);
$buttons[0] = Ox.Button({
2013-02-16 01:20:40 +00:00
style: 'symbol',
2013-03-03 06:34:42 +00:00
title: 'add',
2013-05-09 10:13:58 +00:00
tooltip: canAddItems ? Ox._('Add {0}', [Ox._(pandora.site.itemName.singular)]) : '',
2013-02-16 01:20:40 +00:00
type: 'image'
})
2013-03-03 06:34:42 +00:00
.css({opacity: canAddItems ? 1 : 0.25})
.hide()
2013-03-03 06:34:42 +00:00
.bindEvent({
2016-09-15 15:20:24 +00:00
click: function() {
pandora.$ui.addItemDialog = pandora.ui.addItemDialog({
selected: 'add'
}).open();
}
2013-03-03 06:34:42 +00:00
})
.appendTo(that);
$buttons[1] = Ox.Button({
2013-02-16 01:20:40 +00:00
style: 'symbol',
title: 'upload',
2013-05-09 10:13:58 +00:00
tooltip: canUploadVideo ? Ox._('Upload Video...') : '',
2013-02-16 01:20:40 +00:00
type: 'image'
})
2013-03-03 06:34:42 +00:00
.css({opacity: canUploadVideo ? 1 : 0.25})
.hide()
2013-03-03 06:34:42 +00:00
.bindEvent({
click: function() {
2016-09-15 15:20:24 +00:00
pandora.$ui.addItemDialog = pandora.ui.addItemDialog({
selected: 'upload'
}).open();
2013-03-03 06:34:42 +00:00
}
})
2013-02-16 01:20:40 +00:00
.appendTo(that);
pandora.api.find({
query: {conditions: [], operator: '&'}
}, function(result) {
that.update(result.data.items);
});
2013-07-15 11:39:23 +00:00
} else if (section == 'texts') {
$buttons[0] = Ox.Button({
2013-03-03 06:05:25 +00:00
style: 'symbol',
title: 'file',
2013-05-09 10:13:58 +00:00
tooltip: Ox._('HTML'),
2013-03-03 06:05:25 +00:00
type: 'image'
})
.hide()
2013-03-03 06:05:25 +00:00
.appendTo(that);
$buttons[1] = Ox.Button({
2013-03-03 06:05:25 +00:00
style: 'symbol',
title: 'help',
2013-05-09 10:13:58 +00:00
tooltip: Ox._('Help'),
2013-03-03 06:05:25 +00:00
type: 'image'
})
.hide()
.bindEvent({
click: function() {
pandora.UI.set({page: 'help'});
}
})
2013-03-03 06:05:25 +00:00
.appendTo(that);
2013-02-16 01:20:40 +00:00
}
2011-11-06 18:36:40 +00:00
updateSelected();
function updateSelected() {
that[
2013-07-15 11:39:23 +00:00
(section == 'items' && pandora.user.ui._list)
|| (section == 'edits' && pandora.user.ui.edit)
|| (section == 'texts' && pandora.user.ui.text)
? 'removeClass' : 'addClass'
]('OxSelected');
}
that.update = function(items) {
$items && $items.html(Ox.formatNumber(items));
};
2011-11-06 18:36:40 +00:00
that.resizeElement = function(width) {
$name.css({width: width + 'px'});
$buttons.forEach(function($button) {
$button.show();
});
2011-11-06 18:36:40 +00:00
};
return that;
};