Commit 6cef6bc2 authored by ephoto_dam's avatar ephoto_dam

module "Ephoto Dam Field" in progress

parent 538573fc
......@@ -16,6 +16,25 @@
display:none;
}
.ephoto-dam-field-field:read-only, .ephoto-dam-field-field:read-only:focus {
box-shadow:none;
border:0;
background:none;
padding:0
}
.ephoto-dam-field-url-field:read-only {
border-bottom:1px solid #888 !important
}
.ephoto-dam-field-imagesize-field {
text-align:right
}
.ephoto-dam-field-version-field {
text-align:left
}
.ephoto-dam-field-button {
border-radius:2em !important;
margin:5px 0 0 0 !important;
......@@ -25,20 +44,14 @@
display:block !important
}
.ephoto-dam-field-field-button {
margin:30px 0 0 0 !important;
.ephoto-dam-field-file-button {
margin:2.1em 0 0 0 !important;
}
.ephoto-dam-field-hidden {
display:none !important
#edit-default-value-input .ephoto-dam-field-file-button {
margin:1.8em 0 0 0 !important;
}
#edit-settings-url {
width:350px
}
#edit-settings-captions-format {
width:350px;
height:50px;
resize:none
.ephoto-dam-field-hidden {
display:none !important
}
......@@ -44,15 +44,15 @@
if(el.checked) {
$('.ephoto-dam-field-version-field').removeClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-version-button').removeClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-field-button').addClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-versions-button').removeClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-file-button').addClass('ephoto-dam-field-hidden');
}
else {
$('.ephoto-dam-field-version-field').addClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-version-button').addClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-field-button').removeClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-versions-button').addClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-file-button').removeClass('ephoto-dam-field-hidden');
}
},
......@@ -88,6 +88,8 @@
this.ephoto.File.callOnFileReceived(this.getUrl.bind(this));
this.ephoto.File.enableDCore();
this.ephoto.File.setMode('manual');
this.ephoto.callOnConnect(function() {
......@@ -114,8 +116,7 @@
let versions = this._getFieldValues();
// this.ephoto.File.setButtons !!
this.ephoto.File.get();
//this.ephoto.File.get();
},
/**
......@@ -130,9 +131,14 @@
alert(Drupal.t('Field selection error'));
return;
}
let size = parseInt(this.fieldSelected.size, 10);
size = (size > 1600) ? 1600 : ((size < 0) ? 0 : size);
let size = this.fieldSelected.size.toString().split('x').map(function(val) {
val = val === '' || isNaN(val) ? 0 : parseInt(val, 10);
return (val > 1600) ? 1600 : ((val <= 0) ? '' : val);
}).join('x');
if (size === '' || size === 0) return;
this.ephoto.File.setButtons( this.ephoto.IMAGE_FILES, [ {
'definition': 'custom',
......@@ -148,12 +154,15 @@
/**
* Get URL of selected file
*/
getUrl: function() {
getUrl: function(none, dcore) {
if (dcore === 'fileDoesNotExist') {
return;
}
var self = this;
var version_support = this.settings.version_support === '1';
if (!this.fieldSelected) {
alert(Drupal.t('Field selection error'));
return;
}
......
......@@ -41,14 +41,13 @@ class EphotoDamField extends FieldItemBase {
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'url' => [
'type' => 'varchar',
'length' => 256
],
'image_size' => [
'type' => 'int',
'unsigned' => true,
'size' => 'small'
'type' => 'varchar',
'length' => 9
],
'version' => [
'type' => 'varchar',
......@@ -62,11 +61,11 @@ class EphotoDamField extends FieldItemBase {
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string')
$properties['url'] = DataDefinition::create('string')
->setLabel(t('Url'));
//->setRequired(true);
$properties['image_size'] = DataDefinition::create('integer')
$properties['image_size'] = DataDefinition::create('string')
->setLabel(t('Image size'));
//->setRequired(true);
......@@ -81,11 +80,11 @@ class EphotoDamField extends FieldItemBase {
* {@inheritdoc}
*/
public function isEmpty() {
$value = $this->get('value')->getValue();
$url = $this->get('url')->getValue();
$image_size = $this->get('image_size')->getValue();
$version = $this->get('version')->getValue();
return empty($value) && empty($image_size) && empty($version);
return empty($url) && empty($image_size) && empty($version);
}
/**
......@@ -100,7 +99,10 @@ class EphotoDamField extends FieldItemBase {
'#default_value' => $this->getSetting('server_url'),
'#description' => $this->t('Please enter the URL of your Ephoto Dam software'),
'#required' => true,
'#attributes' => ['placeholder' => $this->t('https://ephoto.mycompany.com/')],
'#attributes' => [
'class' => ['form-text', 'ephoto-dam-field-settings-url'],
'placeholder' => $this->t('https://ephoto.mycompany.com/')
],
'#size' => 50,
];
......@@ -110,6 +112,7 @@ class EphotoDamField extends FieldItemBase {
'#type' => 'checkbox',
'#default_value' => $this->getSetting('version_support'),
'#attributes' => [
'class' => ['ephoto-dam-field-settings-version-support'],
'onclick' => 'Drupal.ephotoDamField.enableVersionSupport(this)'
]
];
......
......@@ -29,80 +29,89 @@ class EphotoDamFieldWidget extends WidgetBase {
$version_support = $this->getFieldSetting('version_support');
if (self::$first) {
$classes = ['button', 'ephoto-dam-field-button', 'ephoto-dam-field-version-button'];
$classes = ['button', 'ephoto-dam-field-button', 'ephoto-dam-field-versions-button'];
if (!$version_support) $classes[] = 'ephoto-dam-field-hidden';
$element['version-import'] = [
$element['versions-select'] = [
'#type' => 'button',
'#value' => $this->t('Select'),
'#disabled' => $is_default_values_form,
'#attributes' => [
'class' => $classes,
'onclick' => 'Drupal.ephotoDamField.selectVersions();return false',
'class' => $classes,
'class' => $classes,
'onclick' => 'Drupal.ephotoDamField.selectVersions();return false'
],
];
self::$first = false;
}
$element['value'] = [
$classes = ['ephoto-dam-field-field', 'ephoto-dam-field-url-field'];
if (!$is_default_values_form) $classes[] = 'ephoto-dam-field-hidden';
$element['url'] = [
'#type' => 'textfield',
'#title' => $this->t('URL') . ' ' . ($delta + 1),
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : null,
'#size' => 100,
'#size' => 60,
'#maxlength' => 256,
'#disabled' => $is_default_values_form,
'#field_suffix' => ' &nbsp;',
'#attributes' => [
'class' => ['form-url', 'ephoto-dam-field-value-field'],
'class' => ['ephoto-dam-field-field', 'ephoto-dam-field-url-field'],
'readonly' => 'readonly',
'onclick' => 'this.focus();this.select()'
]
];
$element['image_size'] = [
'#type' => 'number',
'#type' => 'textfield',
'#title' => '&nbsp;',
'#default_value' => isset($items[$delta]->image_size) ? $items[$delta]->image_size : null,
'#disabled' => !$is_default_values_form,
'#size' => 12,
'#size' => 5,
'#maxlength' => 60,
'#field_suffix' => 'px',
'#field_suffix' => 'px, &nbsp;',
'#attributes' => [
'class' => ['form-url', 'ephoto-dam-field-imagesize-field'],
'class' => ['ephoto-dam-field-field', 'ephoto-dam-field-imagesize-field'],
'placeholder' => $this->t('Image size'),
'max' => 1600
'max' => 1600,
'onclick' => 'this.focus();this.select()'
]
];
];
$classes = ['form-url', 'ephoto-dam-field-version-field'];
$classes = ['ephoto-dam-field-field', 'ephoto-dam-field-version-field'];
if (!$version_support) $classes[] = 'ephoto-dam-field-hidden';
$element['version'] = [
'#type' => 'textfield',
'#title' => '&nbsp;',
'#default_value' => isset($items[$delta]->version) ? $items[$delta]->version : null,
'#disabled' => !$is_default_values_form,
'#size' => 20,
'#default_value' => !empty($items[$delta]->version) ? $items[$delta]->version : ($is_default_values_form ? null : $this->t('Current version')),
'#size' => 10,
'#maxlength' => 60,
'#field_prefix' => $this->t('version'),
'#attributes' => [
'class' => $classes,
'placeholder' => $this->t('Version name')
'placeholder' => $this->t('Version name'),
'onclick' => 'this.focus();this.select()'
]
];
$classes = ['button', 'ephoto-dam-field-button', 'ephoto-dam-field-field-button'];
$classes = ['button', 'ephoto-dam-field-button', 'ephoto-dam-field-file-button'];
if ($version_support) $classes[] = 'ephoto-dam-field-hidden';
$element['field-import'] = [
$element['file-select'] = [
'#type' => 'button',
'#value' => $this->t('Import'),
'#value' => $this->t('Select'),
'#disabled' => $is_default_values_form,
'#attributes' => [
'class' => $classes,
'onclick' => 'Drupal.ephotoDamField.selectFile(' . $delta . ');return false',
'class' => $classes
'onclick' => 'Drupal.ephotoDamField.selectFile(' . $delta . ');return false'
]
];
if (!$is_default_values_form) {
$element['image_size']['#attributes']['readonly'] = 'readonly';
$element['version']['#attributes']['readonly'] = 'readonly';
}
return $element;
}
}
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