Commit 6309e63a authored by Arnaud Bour's avatar Arnaud Bour

Ephoto Dam Field in progress

parent 005cf83a
......@@ -33,8 +33,22 @@
padding-right:0
}
.ephoto-dam-field-thumbnail-image {
width:60px;
height:60px;
object-fit:cover;
border-radius:3px;
margin:10px 10px 40px 0;
float:left;
background:no-repeat center #AAA url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="rgb(255, 255, 255)"><path d="M0 0h24v24H0z" fill="none"/><path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/></svg>');
}
.ephoto-dam-field-thumbnail-version {
margin:10px 10px 0 0;
}
.ephoto-dam-field-caption-field {
width:50em !important;
width:40em !important;
resize:none;
box-shadow:none !important;
border:0 !important;
......
......@@ -133,24 +133,33 @@
*/
getVersionsUrls: function(empty, dcore) {
if (dcore === 'fileDoesNotExist') {
console.log('Error : file does not exist');
console.log('Notice : file does not exist');
return;
}
const caption = this._buildCaption(dcore);
const id = parseInt(dcore['dc:identifier:number'], 10);
const constid = dcore['dc:identifier:string'];
const thumbnail = dcore['dc:description.thumbnail'];
if (!id) {
console.log('Error : dc:identifier missing');
if (!id || !constid || !thumbnail) {
console.log('Notice : dublincore values missing');
return;
}
const caption = this._buildCaption(dcore);
this.ephoto.File.getVersions(id, function(versions) {
const fields = this._getFields();
for (const inc in fields) {
if (typeof versions[fields[inc].name] === 'undefined') continue;
if (typeof versions[fields[inc].name] === 'undefined') {
fields[inc].input.val('');
fields[inc].caption.val('');
fields[inc].thumbnail.val('');
fields[inc].thumbnail.prev().attr('src', '');
continue;
}
let size = this._checkSizeValue(fields[inc].size);
let version = fields[inc].name;
......@@ -166,6 +175,9 @@
button.getLink([file], function(url) {
fields[inc].input.val(url);
fields[inc].caption.val(caption);
fields[inc].thumbnail.val(thumbnail);
fields[inc].thumbnail.prev().attr('src', thumbnail);
});
}
......@@ -208,19 +220,23 @@
*/
getFileUrl: function(url, dcore) {
if (url === 'fileDoesNotExist') {
console.log('Error : file does not exist');
console.log('Notice : file does not exist');
return;
}
var self = this;
if (!this.fieldSelected) {
console.log('Error : field selected missing');
console.log('Notice : field selected missing');
return;
}
self.fieldSelected.input.val(url);
self.fieldSelected = null;
const thumbnail = dcore['dc:description.thumbnail'];
const caption = this._buildCaption(dcore);
this.fieldSelected.input.val(url);
this.fieldSelected.caption.val(caption);
this.fieldSelected.thumbnail.val(thumbnail);
this.fieldSelected.thumbnail.prev().attr('src', thumbnail);
},
/**
......@@ -244,6 +260,7 @@
var sizes = $('.ephoto-dam-field-imagesize-field').toArray();
var inputs = $('.ephoto-dam-field-url-field').toArray();
var captions = $('.ephoto-dam-field-caption-field').toArray();
var thumbnails = $('.ephoto-dam-field-thumbnail').toArray();
$('.ephoto-dam-field-version-field').map(function(index, el) {
fields.push({
......@@ -251,6 +268,7 @@
'size' : $(sizes[index]).val(),
'input' : $(inputs[index]),
'caption' : $(captions[index]),
'thumbnail' : $(thumbnails[index])
});
});
......@@ -264,7 +282,7 @@
var result = this.settings.captions_format;
for (const property in dcore) {
result = result.replace('[' + property + ']', dcore[property]);
result = result.replace('[' + property + ']', dcore[property]);
}
return result;
......
......@@ -68,7 +68,11 @@ class EphotoDamField extends FieldItemBase {
'caption' => [
'type' => 'varchar',
'length' => 256
]
],
'thumbnail' => [
'type' => 'varchar',
'length' => 256
],
]
];
}
......@@ -87,7 +91,10 @@ class EphotoDamField extends FieldItemBase {
->setLabel(t('Version'));
$properties['caption'] = DataDefinition::create('string')
->setLabel(t('Caption'));
->setLabel(t('Caption'));
$properties['thumbnail'] = DataDefinition::create('string')
->setLabel(t('Thumbnail'));
return $properties;
}
......
......@@ -43,6 +43,18 @@ class EphotoDamFieldWidget extends WidgetBase {
];
if (!$is_default_values_form && $version_support) {
$thumbnail = !empty($items[$delta]->thumbnail) ? $items[$delta]->thumbnail : null;
$element['thumbnail'] = [
'#type' => 'hidden',
'#maxlength' => 256,
'#default_value' => $thumbnail,
'#prefix' => '<img class="ephoto-dam-field-thumbnail-image ephoto-dam-field-thumbnail-version" src="' . $thumbnail . '"/>',
'#attributes' => [
'class' => ['ephoto-dam-field-thumbnail']
]
];
$element['caption'] = [
'#type' => 'textarea',
'#title' => t('Caption'),
......@@ -136,6 +148,21 @@ class EphotoDamFieldWidget extends WidgetBase {
];
if (!$is_default_values_form && (!$version_support || !self::$_first)) {
$prefix_classes = ['ephoto-dam-field-thumbnail-image'];
if ($version_support) $prefix_classes[] = 'ephoto-dam-field-hidden';
$thumbnail = !empty($items[$delta]->thumbnail) ? $items[$delta]->thumbnail : null;
$element['thumbnail'] = [
'#type' => 'hidden',
'#maxlength' => 256,
'#default_value' => $thumbnail,
'#prefix' => '<img class="' . implode(' ', $prefix_classes). '" src="' . $thumbnail . '"/>',
'#attributes' => [
'class' => ['ephoto-dam-field-thumbnail'],
]
];
$element['caption'] = [
'#type' => $version_support ? 'hidden' : 'textarea',
'#title' => t('Caption') . ' ' . ($delta + 1),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment