allow for editing cover url

This commit is contained in:
rlx 2016-01-16 10:44:22 +05:30
parent 280cb56b38
commit d0e2fe0340
3 changed files with 45 additions and 26 deletions

View file

@ -1,30 +1,27 @@
'use strict'; 'use strict';
oml.ui.coverDialog = function(id, url) { oml.ui.coverDialog = function(id, value) {
var $input = Ox.Input({ var ui = oml.user.ui,
value: url,
$input = Ox.Input({
style: 'squared',
value: value,
width: 480 width: 480
}) })
.css({margin: '16px'}) .css({margin: '16px'})
.bindEvent({ .bindEvent({
change: function(value) { submit: function() {
that.close(); that.close();
oml.api.edit({
id: id,
cover: value
}, function(result) {
// ...
});
} }
}), }),
that = Ox.Dialog({ that = Ox.Dialog({
buttons: [ buttons: [
Ox.Button({ Ox.Button({
id: 'close', id: 'done',
style: 'squared', style: 'squared',
title: Ox._('Close') title: Ox._('Done')
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
@ -35,12 +32,31 @@ oml.ui.coverDialog = function(id, url) {
closeButton: true, closeButton: true,
content: $input, content: $input,
height: 48, height: 48,
keys: {escape: 'close', enter: 'close'}, keys: {enter: 'done'},
removeOnClose: true, removeOnClose: true,
title: Ox._('Edit Cover URL'), title: Ox._('Edit Cover URL'),
width: 512 width: 512
}) })
.bindEvent({ .bindEvent({
close: function() {
var inputValue = $input.value();
if (inputValue != value) {
oml.api.edit({
id: id,
cover: inputValue
}, function(result) {
if (ui.icons == 'cover') {
oml.$ui.info.updateElement();
oml.$ui.browser.value(ui.item, {
cover: result.data.cover,
coverRatio: result.data.coverRatio,
modified: result.data.modified
});
oml.$ui.infoView.updateCover();
}
});
}
},
open: function() { open: function() {
$input.focusInput(true); $input.focusInput(true);
} }

View file

@ -15,6 +15,9 @@ oml.ui.info = function() {
toggle: function(data) { toggle: function(data) {
oml.UI.set({showInfo: !data.collapsed}); oml.UI.set({showInfo: !data.collapsed});
}, },
oml_icons: function() {
that.updateElement();
},
oml_item: function() { oml_item: function() {
that.updateElement(); that.updateElement();
}, },

View file

@ -122,14 +122,6 @@ oml.ui.infoView = function(externalData, isMixed) {
}; };
} }
function getIconTooltip() {
return !externalData
? 'Click to see ' + (ui.iconSize == 256 ? 'large' : 'small')
+ ' ' + ui.icons + ', doubleclick to see '
+ (ui.icons == 'cover' ? 'preview' : 'cover')
: '';
}
function renderIdentifyButton(data) { function renderIdentifyButton(data) {
return Ox.Button({ return Ox.Button({
disabled: data.mediastate != 'available', disabled: data.mediastate != 'available',
@ -314,6 +306,11 @@ oml.ui.infoView = function(externalData, isMixed) {
$reflection.css(css.reflection).show(); $reflection.css(css.reflection).show();
} }
that.updateCover = function(url) {
Ox.Request.clearCache('get');
that.updateElement(ui.item, $icon);
};
that.updateElement = function(idOrData, $elements) { that.updateElement = function(idOrData, $elements) {
var data = Ox.isObject(idOrData) ? idOrData : null, var data = Ox.isObject(idOrData) ? idOrData : null,
@ -352,6 +349,8 @@ oml.ui.infoView = function(externalData, isMixed) {
size = iconSize, size = iconSize,
reflectionSize = Math.round(size / 2); reflectionSize = Math.round(size / 2);
Ox.print('SRC', src);
$elements.forEach(function($element) { $elements.forEach(function($element) {
$element.empty(); $element.empty();
@ -360,7 +359,9 @@ oml.ui.infoView = function(externalData, isMixed) {
$image = Ox.Element({ $image = Ox.Element({
element: '<img>', element: '<img>',
tooltip: getIconTooltip() tooltip: !externalData
? Ox._('Doubleclick to edit')
: ''
}) })
.on({ .on({
error: function() { error: function() {
@ -386,10 +387,9 @@ oml.ui.infoView = function(externalData, isMixed) {
.bindEvent({ .bindEvent({
doubleclick: function() { doubleclick: function() {
if (!externalData) { if (!externalData) {
oml.UI.set({ oml.$ui.coverDialog = oml.ui.coverDialog(
icons: ui.icons == 'cover' id, data.cover
? 'preview' : 'cover' ).open();
});
} }
}, },
singleclick: function() { singleclick: function() {