make 'Embed Document...' available in both documents view and documents dialog

This commit is contained in:
rolux 2014-02-04 05:53:28 +00:00
parent 6448f1b1f5
commit 42ffdf3358
2 changed files with 32 additions and 52 deletions

View file

@ -239,6 +239,7 @@ pandora.ui.documentsPanel = function(options) {
{}, {},
{id: 'open', title: '', keyboard: 'return'}, {id: 'open', title: '', keyboard: 'return'},
{id: 'edit', title: ''}, {id: 'edit', title: ''},
{id: 'embed', title: Ox._('Embed Document...')},
{}, {},
{id: 'remove', title: '', keyboard: 'delete'} {id: 'remove', title: '', keyboard: 'delete'}
] : [ ] : [
@ -246,6 +247,7 @@ pandora.ui.documentsPanel = function(options) {
{}, {},
{id: 'open', title: '', keyboard: 'return'}, {id: 'open', title: '', keyboard: 'return'},
{id: 'add', title: ''}, {id: 'add', title: ''},
{id: 'embed', title: Ox._('Embed Document...')},
{}, {},
{id: 'replace', title: Ox._('Replace Document...')}, {id: 'replace', title: Ox._('Replace Document...')},
{id: 'delete', title: '', keyboard: 'delete'} {id: 'delete', title: '', keyboard: 'delete'}
@ -259,18 +261,20 @@ pandora.ui.documentsPanel = function(options) {
click: function(data) { click: function(data) {
if (data.id == 'add') { if (data.id == 'add') {
isItemView ? openDocumentsDialog() : addDocuments(); isItemView ? openDocumentsDialog() : addDocuments();
} else if (data.id == 'upload') {
uploadDocuments(data);
} else if (data.id == 'open') {
openDocuments();
} else if (data.id == 'edit') {
editDocuments();
} else if (data.id == 'replace') {
replaceDocument(data.files);
} else if (data.id == 'remove') {
removeDocuments();
} else if (data.id == 'delete') { } else if (data.id == 'delete') {
deleteDocuments(); deleteDocuments();
} else if (data.id == 'edit') {
editDocuments();
} else if (data.id == 'embed') {
openEmbedDialog();
} else if (data.id == 'open') {
openDocuments();
} else if (data.id == 'remove') {
removeDocuments();
} else if (data.id == 'replace') {
replaceDocument(data.files);
} else if (data.id == 'upload') {
uploadDocuments(data);
} }
} }
}) })
@ -303,18 +307,7 @@ pandora.ui.documentsPanel = function(options) {
.css({float: 'right', margin: '4px 2px'}) .css({float: 'right', margin: '4px 2px'})
.bindEvent({ .bindEvent({
click: function(data) { click: function(data) {
var selected = $list.options('selected'); $list.selectSelected(data.id == 'previous' ? -1 : 1);
if (data.id == 'next') {
selected.push(selected.shift());
} else {
selected.splice(0, 0, selected.pop());
}
$list.options('selected', selected);
$item.empty();
if (selected.length) {
$preview = renderPreview().appendTo($item);
$data = renderData().appendTo($item);
}
} }
}) })
.hide() .hide()
@ -448,12 +441,6 @@ pandora.ui.documentsPanel = function(options) {
openDocumentsDialog(); openDocumentsDialog();
} }
function getEmbed(item) {
return '<a href="/documents/'
+ item.id + '"><img src="/documents/'
+ item.id + '/256p.jpg"></a>';
}
function getOrderButtonTitle() { function getOrderButtonTitle() {
return ui.documentsSort[0].operator == '+' ? 'up' : 'down'; return ui.documentsSort[0].operator == '+' ? 'up' : 'down';
} }
@ -494,6 +481,12 @@ pandora.ui.documentsPanel = function(options) {
pandora.$ui.documentsDialog = pandora.ui.documentsDialog().open(); pandora.$ui.documentsDialog = pandora.ui.documentsDialog().open();
} }
function openEmbedDialog() {
pandora.$ui.embedDocumentDialog = pandora.ui.embedDocumentDialog(
ui.documentsSelection[isItemView ? ui.item : ''][0]
).open();
}
function replaceDocument(file) { function replaceDocument(file) {
var id = $list.options('selected')[0]; var id = $list.options('selected')[0];
} }
@ -655,15 +648,6 @@ pandora.ui.documentsPanel = function(options) {
type: 'textarea', type: 'textarea',
value: item.description, value: item.description,
width: width width: width
}),
Ox.Input({
disabled: true,
height: 36,
id: 'embed',
placeholder: Ox._('HTML Embed'),
type: 'textarea',
value: getEmbed(item),
width: width
}) })
], ],
width: 240 width: 240
@ -817,6 +801,7 @@ pandora.ui.documentsPanel = function(options) {
+ pandora.site.itemName.singular + pandora.site.itemName.singular
)) ))
[selected.length ? 'enableItem' : 'disableItem']('edit') [selected.length ? 'enableItem' : 'disableItem']('edit')
[selected.length ? 'enableItem' : 'disableItem']('embed')
[selected.length ? 'enableItem' : 'disableItem']('remove'); [selected.length ? 'enableItem' : 'disableItem']('remove');
} else { } else {
$itemMenu.setItemTitle('add', Ox._( $itemMenu.setItemTitle('add', Ox._(
@ -826,6 +811,7 @@ pandora.ui.documentsPanel = function(options) {
.setItemTitle('replace', Ox._('Replace ' + string + '...')) .setItemTitle('replace', Ox._('Replace ' + string + '...'))
.setItemTitle('delete', Ox._('Delete ' + string + '...')) .setItemTitle('delete', Ox._('Delete ' + string + '...'))
[selected.length ? 'enableItem' : 'disableItem']('add') [selected.length ? 'enableItem' : 'disableItem']('add')
[selected.length ? 'enableItem' : 'disableItem']('embed')
[selected.length == 1 ? 'enableItem' : 'disableItem']('replace') [selected.length == 1 ? 'enableItem' : 'disableItem']('replace')
[selected.length ? 'enableItem' : 'disableItem']('delete'); [selected.length ? 'enableItem' : 'disableItem']('delete');
} }
@ -899,4 +885,4 @@ pandora.ui.documentsPanel = function(options) {
return that; return that;
} };

View file

@ -3,26 +3,20 @@
pandora.ui.embedDocumentDialog = function(id) { pandora.ui.embedDocumentDialog = function(id) {
var isImage = Ox.contains(['jpg', 'png'], selected.split('.').pop()), var $content = Ox.Element()
url = 'http' + (pandora.site.site.https ? 's' : '') + '://'
+ pandora.site.site.url + '/documents/' + id,
$content = Ox.Element()
.css({margin: '16px'}) .css({margin: '16px'})
.html( .html(Ox._('To embed this document, use the following HTML:')),
Ox._('To embed this file, use the following HTML:<br>')
),
$embed = $('<textarea>') $embed = $('<textarea>')
.css({ .css({
width: '336px', width: '322px',
height: '64px', height: '64px',
marginTop: '8px', marginTop: '8px'
}) })
.val( .val(
isImage '<a href="/documents/'
? '<img src="' + url + '">' + id + '"><img src="/documents/'
: '<a href="' + url + '"><img src="' + url + '.jpg"></a>' + id + '/256p.jpg"></a>'
) )
.on({ .on({
click: function() { click: function() {
@ -49,7 +43,7 @@ pandora.ui.embedDocumentDialog = function(id) {
height: 128, height: 128,
keys: {escape: 'close'}, keys: {escape: 'close'},
removeOnClose: true, removeOnClose: true,
title: Ox._('Embed File'), title: Ox._('Embed Document'),
width: 368 width: 368
}); });