more encoding fun

This commit is contained in:
Rolux 2016-01-08 15:29:02 +05:30
parent b94ead03c6
commit 214e6a7e36
2 changed files with 37 additions and 47 deletions

View file

@ -46,10 +46,9 @@ oml.ui.editDialog = function() {
function editMetadata(key, value) { function editMetadata(key, value) {
var edit = {id: ids}; var edit = {id: ids};
if (Ox.contains(arrayKeys, key)) { if (Ox.contains(arrayKeys, key)) {
edit[key] = value edit[key] = value ? value.split(separator) : [];
? Ox.decodeHTMLEntities(value).split(separator) : [];
} else { } else {
edit[key] = Ox.decodeHTMLEntities(value); edit[key] = value;
} }
oml.api.edit(edit, function(result) { oml.api.edit(edit, function(result) {
Ox.Request.clearCache(); Ox.Request.clearCache();
@ -81,9 +80,7 @@ oml.ui.editDialog = function() {
: key == 'description' ? 'Mixed Description' : key == 'description' ? 'Mixed Description'
: 'mixed' : 'mixed'
)) : value ? (Ox.isArray(value) ? value : [value]).map(function(value) { )) : value ? (Ox.isArray(value) ? value : [value]).map(function(value) {
return Ox.encodeHTMLEntities( return key == 'date' && value ? value.slice(0, 4) : value;
key == 'date' && value ? value.slice(0, 4) : value
);
}).join(separator) : ''; }).join(separator) : '';
} }
@ -139,7 +136,7 @@ oml.ui.editDialog = function() {
}, },
placeholder: formatLight(Ox._('No Title')), placeholder: formatLight(Ox._('No Title')),
tooltip: tooltip, tooltip: tooltip,
value: data.title || '' value: data.title ? Ox.encodeHTMLEntities(data.title) : ''
}) })
.css({ .css({
fontWeight: 'bold', fontWeight: 'bold',
@ -147,7 +144,7 @@ oml.ui.editDialog = function() {
}) })
.bindEvent({ .bindEvent({
submit: function(event) { submit: function(event) {
editMetadata('title', event.value); editMetadata('title', Ox.decodeHTMLEntities(event.value));
} }
}) })
) )
@ -167,7 +164,7 @@ oml.ui.editDialog = function() {
}, },
placeholder: formatLight(Ox._('Unknown Author')), placeholder: formatLight(Ox._('Unknown Author')),
tooltip: tooltip, tooltip: tooltip,
value: data.author ? data.author.join(separator) : '' value: data.author ? Ox.encodeHTMLEntities(data.author.join(separator)) : ''
}) })
.css({ .css({
marginBottom: '-3px', marginBottom: '-3px',
@ -176,7 +173,7 @@ oml.ui.editDialog = function() {
}) })
.bindEvent({ .bindEvent({
submit: function(event) { submit: function(event) {
editMetadata('author', event.value); editMetadata('author', Ox.decodeHTMLEntities(event.value));
} }
}) })
) )
@ -206,14 +203,14 @@ oml.ui.editDialog = function() {
}, },
placeholder: formatLight(Ox._('unknown')), placeholder: formatLight(Ox._('unknown')),
tooltip: tooltip, tooltip: tooltip,
value: data[key] ? ( value: data[key] ? Ox.encodeHTMLEntities(
Ox.contains(arrayKeys, key) && Ox.isArray(data[key]) Ox.contains(arrayKeys, key) && Ox.isArray(data[key])
? data[key].join('; ') : data[key] ? data[key].join('; ') : data[key]
) : '' ) : ''
}) })
.bindEvent({ .bindEvent({
submit: function(event) { submit: function(event) {
editMetadata(key, event.value); editMetadata(key, Ox.decodeHTMLEntities(event.value));
} }
}) })
.appendTo($div); .appendTo($div);
@ -243,14 +240,14 @@ oml.ui.editDialog = function() {
}, },
placeholder: formatLight(Ox._('unknown')), placeholder: formatLight(Ox._('unknown')),
tooltip: tooltip, tooltip: tooltip,
value: data[key] ? ( value: data[key] ? Ox.encodeHTMLEntities(
Ox.contains(arrayKeys, key) && Ox.isArray(data[key]) Ox.contains(arrayKeys, key) && Ox.isArray(data[key])
? data[key].join(separator) : data[key] ? data[key].join(separator) : data[key]
) : '' ) : ''
}) })
.bindEvent({ .bindEvent({
submit: function(event) { submit: function(event) {
editMetadata(key, event.value); editMetadata(key, Ox.decodeHTMLEntities(event.value));
} }
}) })
.appendTo($div); .appendTo($div);
@ -265,17 +262,17 @@ oml.ui.editDialog = function() {
}).append( }).append(
Ox.EditableContent({ Ox.EditableContent({
editable: true, editable: true,
format: function(value) {
return formatValue(value, 'description');
},
placeholder: formatLight('No Description'), placeholder: formatLight('No Description'),
tooltip: tooltip, tooltip: tooltip,
type: 'textarea', type: 'textarea',
value: data.description || '' value: data.description ? Ox.encodeHTMLEntities(data.description) : ''
}) })
.bindEvent({ .bindEvent({
submit: function(event) { submit: function(event) {
editMetadata('description', event.value); editMetadata(
'description',
Ox.decodeHTMLEntities(event.value).replace(/<br>/g, '\n')
);
} }
}) })
).appendTo($info); ).appendTo($info);

View file

@ -115,7 +115,6 @@ oml.ui.infoView = function(identifyData) {
function formatValue(value, key) { function formatValue(value, key) {
return value ? (Ox.isArray(value) ? value : [value]).map(function(value) { return value ? (Ox.isArray(value) ? value : [value]).map(function(value) {
value = Ox.encodeHTMLEntities(value);
if (key == 'date' && value) { if (key == 'date' && value) {
value = value.slice(0, 4); value = value.slice(0, 4);
} }
@ -460,9 +459,8 @@ oml.ui.infoView = function(identifyData) {
Ox.EditableContent({ Ox.EditableContent({
clickLink: oml.clickLink, clickLink: oml.clickLink,
editable: isEditable, editable: isEditable,
format: Ox.encodeHTMLEntities,
tooltip: isEditable ? oml.getEditTooltip() : '', tooltip: isEditable ? oml.getEditTooltip() : '',
value: data.title || 'No Title' value: data.title ? Ox.encodeHTMLEntities(data.title) : 'No Title'
}) })
.css({ .css({
fontWeight: 'bold', fontWeight: 'bold',
@ -470,7 +468,7 @@ oml.ui.infoView = function(identifyData) {
}) })
.bindEvent({ .bindEvent({
submit: function(event) { submit: function(event) {
editMetadata('title', event.value); editMetadata('title', Ox.decodeHTMLEntities(event.value));
} }
}) })
) )
@ -487,11 +485,11 @@ oml.ui.infoView = function(identifyData) {
clickLink: oml.clickLink, clickLink: oml.clickLink,
editable: isEditable, editable: isEditable,
format: function(value) { format: function(value) {
return formatValue(splitValue(value), 'author'); return formatValue(value.split('; '), 'author');
}, },
placeholder: formatLight(Ox._('Unknown Author')), placeholder: formatLight(Ox._('Unknown Author')),
tooltip: isEditable ? oml.getEditTooltip() : '', tooltip: isEditable ? oml.getEditTooltip() : '',
value: data.author ? data.author.join('; ') : '' value: data.author ? Ox.encodeHTMLEntities(data.author.join('; ')) : ''
}) })
.css({ .css({
marginBottom: '-3px', marginBottom: '-3px',
@ -500,7 +498,7 @@ oml.ui.infoView = function(identifyData) {
}) })
.bindEvent({ .bindEvent({
submit: function(event) { submit: function(event) {
editMetadata('author', event.value); editMetadata('author', Ox.decodeHTMLEntities(event.value));
} }
}) })
) )
@ -526,20 +524,20 @@ oml.ui.infoView = function(identifyData) {
format: function(value) { format: function(value) {
return formatValue( return formatValue(
Ox.contains(arrayKeys, key) Ox.contains(arrayKeys, key)
? splitValue(value) : value, ? value.split('; ') : value,
key key
); );
}, },
placeholder: formatLight(Ox._('unknown')), placeholder: formatLight(Ox._('unknown')),
tooltip: isEditable ? oml.getEditTooltip() : '', tooltip: isEditable ? oml.getEditTooltip() : '',
value: data[key] ? ( value: data[key] ? Ox.encodeHTMLEntities(
Ox.contains(arrayKeys, key) Ox.contains(arrayKeys, key)
? data[key].join('; ') : data[key] ? data[key].join('; ') : data[key]
) : '' ) : ''
}) })
.bindEvent({ .bindEvent({
submit: function(event) { submit: function(event) {
editMetadata(key, event.value); editMetadata(key, Ox.decodeHTMLEntities(event.value));
} }
}) })
.appendTo($div); .appendTo($div);
@ -563,20 +561,22 @@ oml.ui.infoView = function(identifyData) {
clickLink: oml.clickLink, clickLink: oml.clickLink,
editable: isEditable, editable: isEditable,
format: function(value) { format: function(value) {
return key == 'language' return formatValue(
? formatValue(splitValue(value), key) Ox.contains(arrayKeys, key)
: Ox.encodeHTMLEntities(value); ? value.split('; ') : value,
key
);
}, },
placeholder: formatLight('unknown'), placeholder: formatLight('unknown'),
tooltip: isEditable ? oml.getEditTooltip() : '', tooltip: isEditable ? oml.getEditTooltip() : '',
value: data[key] ? ( value: data[key] ? Ox.encodeHTMLEntities(
Ox.contains(arrayKeys, key) Ox.contains(arrayKeys, key)
? data[key].join('; ') : data[key] ? data[key].join('; ') : data[key]
) : '' ) : ''
}) })
.bindEvent({ .bindEvent({
submit: function(event) { submit: function(event) {
editMetadata(key, event.value); editMetadata(key, Ox.decodeHTMLEntities(event.value));
} }
}) })
.appendTo($div); .appendTo($div);
@ -609,11 +609,11 @@ oml.ui.infoView = function(identifyData) {
editable: isEditable, editable: isEditable,
placeholder: formatLight('No Classification'), placeholder: formatLight('No Classification'),
tooltip: isEditable ? oml.getEditTooltip() : '', tooltip: isEditable ? oml.getEditTooltip() : '',
value: data.classification || '', value: data.classification ? Ox.encodeHTMLEntities(data.classification) : '',
}) })
.bindEvent({ .bindEvent({
submit: function(event) { submit: function(event) {
editMetadata('classification', event.value); editMetadata('classification', Ox.decodeHTMLEntities(event.value));
} }
}) })
) )
@ -631,19 +631,16 @@ oml.ui.infoView = function(identifyData) {
Ox.EditableContent({ Ox.EditableContent({
clickLink: oml.clickLink, clickLink: oml.clickLink,
editable: isEditable, editable: isEditable,
format: function(value) {
return Ox.encodeHTMLEntities(value);
},
placeholder: formatLight('No Description'), placeholder: formatLight('No Description'),
tooltip: isEditable ? oml.getEditTooltip() : '', tooltip: isEditable ? oml.getEditTooltip() : '',
type: 'textarea', type: 'textarea',
value: data.description || '' value: data.description ? Ox.encodeHTMLEntities(data.description) : ''
}) })
.bindEvent({ .bindEvent({
submit: function(event) { submit: function(event) {
editMetadata( editMetadata(
'description', 'description',
event.value.replace(/<br>/g, '\n') Ox.decodeHTMLEntities(event.value).replace(/<br>/g, '\n')
); );
} }
}) })
@ -730,9 +727,9 @@ oml.ui.infoView = function(identifyData) {
if (value != data[key]) { if (value != data[key]) {
var edit = {id: data.id}; var edit = {id: data.id};
if (Ox.contains(arrayKeys, key)) { if (Ox.contains(arrayKeys, key)) {
edit[key] = value ? splitValue(value) : []; edit[key] = value ? value.split('; ') : [];
} else { } else {
edit[key] = Ox.decodeHTMLEntities(value); edit[key] = value;
} }
oml.api.edit(edit, function(result) { oml.api.edit(edit, function(result) {
Ox.Request.clearCache(); Ox.Request.clearCache();
@ -751,10 +748,6 @@ oml.ui.infoView = function(identifyData) {
}); });
function splitValue(value) {
return Ox.decodeHTMLEntities(value).split('; ');
}
}; };
if (!identifyData) { if (!identifyData) {