pandora/static/js/allItems.js

210 lines
6.8 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
var canAddItems = !pandora.site.itemRequiresVideo && pandora.hasCapability('canAddItems'),
canUploadVideo = pandora.hasCapability('canAddItems'),
canAddDocuments = pandora.hasCapability('canAddDocuments'),
2016-10-04 22:00:03 +00:00
isSelected = pandora.user.ui._list || pandora.user.ui._collection,
2013-03-03 06:34:42 +00:00
that = Ox.Element()
2016-10-04 22:00:03 +00:00
.addClass('OxSelectableElement' + (isSelected ? '' : ' OxSelected'))
2013-03-03 06:34:42 +00:00
.css({
height: '16px',
cursor: 'default',
overflow: 'hidden'
})
.on({
click: function() {
that.gainFocus();
2013-07-15 11:39:23 +00:00
if (section == 'items') {
2017-06-09 10:25:38 +00:00
pandora.UI.set({
find: {conditions: [], operator: '&'},
item: ''
2016-10-04 22:00:03 +00:00
});
} else if (section == 'documents') {
2017-06-09 10:25:38 +00:00
pandora.UI.set({
findDocuments: {conditions: [], operator: '&'},
document: ''
2016-10-04 22:00:03 +00:00
});
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({
2016-10-04 22:00:03 +00:00
pandora_document: updateSelected,
pandora_finddocuments: updateSelected,
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);
});
2016-10-04 22:00:03 +00:00
} else if (section == 'documents') {
$items = $('<div>')
.css({
float: 'left',
width: '42px',
margin: '1px 4px 1px 3px',
textAlign: 'right'
})
.appendTo(that);
$buttons[0] = Ox.Button({
style: 'symbol',
title: 'add',
tooltip: canAddDocuments ? Ox._('Add {0}', [Ox._('Document')]) : '',
type: 'image'
})
.css({opacity: canAddDocuments ? 1 : 0.25})
.hide()
.bindEvent({
click: function(data) {
if (canAddDocuments) {
pandora.$ui.addDocumentDialog = pandora.ui.addDocumentDialog({
selected: 'add'
}).open();
}
}
})
.appendTo(that);
$buttons[1] = Ox.Button({
style: 'symbol',
title: 'upload',
tooltip: canAddDocuments ? Ox._('Upload {0}', [Ox._('Document')]) : '',
type: 'image'
})
.css({opacity: canAddDocuments ? 1 : 0.25})
.hide()
.bindEvent({
click: function() {
if (canAddDocuments) {
pandora.$ui.addDocumentDialog = pandora.ui.addDocumentDialog({
selected: 'upload'
}).open();
}
}
})
.appendTo(that);
pandora.api.findDocuments({
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)
2016-10-04 22:00:03 +00:00
|| (section == 'documents' && pandora.user.ui._collection)
2013-07-15 11:39:23 +00:00
|| (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;
};