Commit 793c8f74 authored by ephoto_dam's avatar ephoto_dam

Ephoto Dam Field in progress

parent d95110b4
...@@ -86,13 +86,7 @@ ...@@ -86,13 +86,7 @@
this.ephoto.connect(); this.ephoto.connect();
if (this.settings.version_support === '1') { this.ephoto.File.callOnFileReceived(this.getUrl.bind(this));
this.ephoto.File.callOnFileReceived(this.getVersionUrls.bind(this));
}
else {
this.ephoto.File.callOnFileReceived(this.getFileUrl.bind(this));
}
this.ephoto.File.setMode('manual'); this.ephoto.File.setMode('manual');
...@@ -127,14 +121,7 @@ ...@@ -127,14 +121,7 @@
/** /**
* *
*/ */
getVersionUrls: function() { selectFile: function(delta) {
console.log('get version urls!');
},
/**
*
*/
select: function(delta) {
this.fieldSelected = this._getFieldValues()[delta]; this.fieldSelected = this._getFieldValues()[delta];
if (!this.fieldSelected) { if (!this.fieldSelected) {
...@@ -156,17 +143,18 @@ ...@@ -156,17 +143,18 @@
/** /**
* *
*/ */
getFileUrl: function() { getUrl: function() {
console.log('get file url!'); var self = this;
var version_support = this.settings.version_support === '1';
if (!this._fieldSelected) { if (!this.fieldSelected) {
alert(Drupal.t('Field selection error')); alert(Drupal.t('Field selection error'));
return; return;
} }
this.ephoto.File.store(function(url) { this.ephoto.File.store(function(url) {
this._fieldSelected.value = url; self.fieldSelected.input.val(url);
this._fieldSelected = null; self.fieldSelected = null;
}); });
}, },
...@@ -176,11 +164,13 @@ ...@@ -176,11 +164,13 @@
_getFieldValues: function() { _getFieldValues: function() {
var fields = []; var fields = [];
var sizes = $('.ephoto-dam-field-imagesize-field').toArray(); var sizes = $('.ephoto-dam-field-imagesize-field').toArray();
var inputs = $('.ephoto-dam-field-value-field').toArray();
$('.ephoto-dam-field-version-field').map(function(index, el) { $('.ephoto-dam-field-version-field').map(function(index, el) {
fields.push({ fields.push({
'name' : $(el).val(), 'name' : $(el).val(),
'size' : $(sizes[index]).val() 'size' : $(sizes[index]).val(),
'input' : $(inputs[index])
}); });
}); });
......
...@@ -63,16 +63,16 @@ class EphotoDamField extends FieldItemBase { ...@@ -63,16 +63,16 @@ class EphotoDamField extends FieldItemBase {
*/ */
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string') $properties['value'] = DataDefinition::create('string')
->setLabel(t('Url')) ->setLabel(t('Url'));
->setRequired(true); //->setRequired(true);
$properties['image_size'] = DataDefinition::create('integer') $properties['image_size'] = DataDefinition::create('integer')
->setLabel(t('Image size')) ->setLabel(t('Image size'));
->setRequired(true); //->setRequired(true);
$properties['version'] = DataDefinition::create('string') $properties['version'] = DataDefinition::create('string')
->setLabel(t('Version')) ->setLabel(t('Version'));
->setRequired(true); //->setRequired(true);
return $properties; return $properties;
} }
...@@ -92,6 +92,8 @@ class EphotoDamField extends FieldItemBase { ...@@ -92,6 +92,8 @@ class EphotoDamField extends FieldItemBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fieldSettingsForm(array $form, FormStateInterface $form_state) { public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$form = [];
$form['server_url'] = [ $form['server_url'] = [
'#title' => $this->t('Server URL'), '#title' => $this->t('Server URL'),
'#type' => 'url', '#type' => 'url',
......
...@@ -38,7 +38,7 @@ class EphotoDamFieldWidget extends WidgetBase { ...@@ -38,7 +38,7 @@ class EphotoDamFieldWidget extends WidgetBase {
'#disabled' => $is_default_values_form, '#disabled' => $is_default_values_form,
'#attributes' => [ '#attributes' => [
'class' => $classes, 'class' => $classes,
'onclick' => 'Drupal.ephotoDamField.selectVersionUrls();return false', 'onclick' => 'Drupal.ephotoDamField.selectVersions();return false',
'class' => $classes, 'class' => $classes,
], ],
]; ];
...@@ -61,7 +61,7 @@ class EphotoDamFieldWidget extends WidgetBase { ...@@ -61,7 +61,7 @@ class EphotoDamFieldWidget extends WidgetBase {
$element['image_size'] = [ $element['image_size'] = [
'#type' => 'number', '#type' => 'number',
'#title' => ' ', '#title' => ' ',
'#default_value' => isset($items[$delta]->image_size) ? $items[$delta]->image_size : 0, '#default_value' => isset($items[$delta]->image_size) ? $items[$delta]->image_size : null,
'#disabled' => !$is_default_values_form, '#disabled' => !$is_default_values_form,
'#size' => 12, '#size' => 12,
'#maxlength' => 60, '#maxlength' => 60,
...@@ -69,7 +69,6 @@ class EphotoDamFieldWidget extends WidgetBase { ...@@ -69,7 +69,6 @@ class EphotoDamFieldWidget extends WidgetBase {
'#attributes' => [ '#attributes' => [
'class' => ['form-url', 'ephoto-dam-field-imagesize-field'], 'class' => ['form-url', 'ephoto-dam-field-imagesize-field'],
'placeholder' => $this->t('Image size'), 'placeholder' => $this->t('Image size'),
'min' => 20,
'max' => 1600 'max' => 1600
] ]
]; ];
...@@ -99,7 +98,7 @@ class EphotoDamFieldWidget extends WidgetBase { ...@@ -99,7 +98,7 @@ class EphotoDamFieldWidget extends WidgetBase {
'#disabled' => $is_default_values_form, '#disabled' => $is_default_values_form,
'#attributes' => [ '#attributes' => [
'class' => $classes, 'class' => $classes,
'onclick' => 'Drupal.ephotoDamField.selectUrl(' . $delta . ');return false', 'onclick' => 'Drupal.ephotoDamField.selectFile(' . $delta . ');return false',
'class' => $classes 'class' => $classes
] ]
]; ];
......
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