Commit 005cf83a authored by Arnaud Bour's avatar Arnaud Bour

Ephoto Dam Field in progress

parent cda14bcf
......@@ -33,7 +33,7 @@
padding-right:0
}
.ephoto-dam-field-legend-field {
.ephoto-dam-field-caption-field {
width:50em !important;
resize:none;
box-shadow:none !important;
......
......@@ -111,7 +111,7 @@
* Select a file versions
*/
selectVersions: function() {
if (!this._getFieldValues()) {
if (!this._getFields()) {
console.log('Error : field selection error');
return;
}
......@@ -137,6 +137,8 @@
return;
}
const caption = this._buildCaption(dcore);
const id = parseInt(dcore['dc:identifier:number'], 10);
if (!id) {
......@@ -145,7 +147,7 @@
}
this.ephoto.File.getVersions(id, function(versions) {
const fields = this._getFieldValues();
const fields = this._getFields();
for (const inc in fields) {
if (typeof versions[fields[inc].name] === 'undefined') continue;
......@@ -163,6 +165,7 @@
button.getLink([file], function(url) {
fields[inc].input.val(url);
fields[inc].caption.val(caption);
});
}
......@@ -175,7 +178,7 @@
* @param {number} Field index
*/
selectFile: function(delta) {
this.fieldSelected = this._getFieldValues()[delta];
this.fieldSelected = this._getFields()[delta];
if (!this.fieldSelected) {
console.log('Error : field selection error');
......@@ -234,23 +237,38 @@
},
/**
* Get all field values
* Get all fields
*/
_getFieldValues: function() {
_getFields: function() {
var fields = [];
var sizes = $('.ephoto-dam-field-imagesize-field').toArray();
var inputs = $('.ephoto-dam-field-url-field').toArray();
var captions = $('.ephoto-dam-field-caption-field').toArray();
$('.ephoto-dam-field-version-field').map(function(index, el) {
fields.push({
'name' : $(el).val(),
'size' : $(sizes[index]).val(),
'input' : $(inputs[index])
'input' : $(inputs[index]),
'caption' : $(captions[index]),
});
});
return fields;
},
},
/**
* Build the caption width a DublinCore
*/
_buildCaption: function(dcore) {
var result = this.settings.captions_format;
for (const property in dcore) {
result = result.replace('[' + property + ']', dcore[property]);
}
return result;
},
}
})(jQuery);
......
......@@ -64,6 +64,10 @@ class EphotoDamField extends FieldItemBase {
'version' => [
'type' => 'varchar',
'length' => 20
],
'caption' => [
'type' => 'varchar',
'length' => 256
]
]
];
......@@ -72,7 +76,7 @@ class EphotoDamField extends FieldItemBase {
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['url'] = DataDefinition::create('string')
->setLabel(t('Url'));
......@@ -81,6 +85,9 @@ class EphotoDamField extends FieldItemBase {
$properties['version'] = DataDefinition::create('string')
->setLabel(t('Version'));
$properties['caption'] = DataDefinition::create('string')
->setLabel(t('Caption'));
return $properties;
}
......
......@@ -43,21 +43,19 @@ class EphotoDamFieldWidget extends WidgetBase {
];
if (!$is_default_values_form && $version_support) {
$element['legend'] = [
$element['caption'] = [
'#type' => 'textarea',
'#title' => t('Legend'),
'#default_value' => isset($items[$delta]->legend) ? $items[$delta]->legend : null,
'#title' => t('Caption'),
'#default_value' => isset($items[$delta]->caption) ? $items[$delta]->caption : null,
'#rows' => 1,
'#maxlength' => 256,
'#attributes' => [
'class' => ['ephoto-dam-field-legend-field'],
'class' => ['ephoto-dam-field-caption-field'],
'readonly' => 'readonly',
'onclick' => 'this.focus();this.select()'
]
];
}
self::$_first = false;
}
}
$classes = ['ephoto-dam-field-field', 'ephoto-dam-field-url-field'];
......@@ -137,15 +135,15 @@ class EphotoDamFieldWidget extends WidgetBase {
]
];
if (!$is_default_values_form && !$version_support) {
$element['legend'] = [
'#type' => 'textarea',
'#title' => t('Legend') . ' ' . ($delta + 1),
'#default_value' => isset($items[$delta]->legend) ? $items[$delta]->legend : null,
if (!$is_default_values_form && (!$version_support || !self::$_first)) {
$element['caption'] = [
'#type' => $version_support ? 'hidden' : 'textarea',
'#title' => t('Caption') . ' ' . ($delta + 1),
'#default_value' => isset($items[$delta]->caption) ? $items[$delta]->caption : null,
'#rows' => 1,
'#maxlength' => 256,
'#attributes' => [
'class' => ['ephoto-dam-field-legend-field'],
'class' => ['ephoto-dam-field-caption-field'],
'readonly' => 'readonly',
'onclick' => 'this.focus();this.select()'
]
......@@ -155,7 +153,9 @@ class EphotoDamFieldWidget extends WidgetBase {
if (!$is_default_values_form) {
$element['image_size']['#attributes']['readonly'] = 'readonly';
$element['version']['#attributes']['readonly'] = 'readonly';
}
}
self::$_first = false;
return $element;
}
......
......@@ -130,8 +130,5 @@ msgstr "Le champ \"Taille\" doit respecter un des paternes suivant : \"x{hauteur
msgid "The version of Ephoto Dam is not compatible with this feature"
msgstr "La version d'Ephoto Dam n'est pas compatible avec cette fonctionnalité"
msgid "Legend"
msgstr "Légende"
msgid "Please enter the server URL first from the <a href=\":config_ephoto_dam\">module configuration form</a>"
msgstr "Veuillez d'abord saisir l'URL du serveur à partir du <a href=\":config_ephoto_dam\">formulaire de configuration du module</a>"
\ No newline at end of file
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