Commit ecb566a8 authored by ephoto_dam's avatar ephoto_dam

Ephoto Dam Field in progress

parent 51af3b2d
......@@ -3,6 +3,11 @@
margin-right:5px;
}
.field--type-ephoto-dam-field .form-type-number {
float:left;
margin-right:10px;
}
.field--type-ephoto-dam-field .field-multiple-drag {
display:none;
}
......@@ -16,12 +21,12 @@
margin:5px 0 0 0 !important;
padding-left:2.5em !important;
padding-right:1em !important;
background:#fff url(/modules/contrib/ephoto_dam/plugin/icon.png) 0.8em no-repeat !important;
background:#f2f1eb url(/modules/contrib/ephoto_dam/plugin/icon.png) 0.8em no-repeat !important;
display:block !important
}
.ephoto-dam-field-field-button {
margin:26px 0 0 0 !important;
margin:30px 0 0 0 !important;
}
.ephoto-dam-field-hidden {
......
......@@ -16,7 +16,7 @@ function ephoto_dam_field_field_widget_form_alter(&$element, &$form_state, $cont
if ($field_definition->getType() === 'ephoto_dam_field') {
$element['#attached']['library'][] = 'ephoto_dam_field/edit';
$element['#attached']['drupalSettings']['ephotoDamField'] = $field_definition->getSettings();
$element['#attached']['drupalSettings']['ephotoDamField'] = $field_definition->getSettings();
}
}
......@@ -50,7 +50,9 @@
* Load Ephoto Dam Api
*/
load: function() {
$.getScript(this.settings.url + 'api/apiJS.js', this.init.bind(this));
if (this.settings && this.settings.server_url) {
$.getScript(this.settings.server_url + '/api/apiJS.js', this.init.bind(this));
}
},
/**
......@@ -59,29 +61,20 @@
init: function() {
var self = this;
//console.log(Drupal.attachBehaviors);
/*
Drupal.attachBehaviors(context, settings) {
console.log(settings);
};
*/
if (!ePhoto) {
console.log(Drupal.t('Error loading the Ephoto Dam API'));
return;
}
this.ephoto = new ePhoto({
'server': this.settings.url,
'server': this.settings.server_url,
'authID': $.cookie('drupal_ephoto_dam_authid'),
'client': this.CLIENT_ID
});
this.ephoto.connect();
//this.ephoto.File.setMode('embed');
this.ephoto.File.setMode('link');
//this.ephoto.File.enableDCore();
......@@ -98,7 +91,9 @@
/**
*
*/
selectVersionUrls: function() {
selectUrls: function() {
let versions = this._getFieldValues();
this.ephoto.File.get();
},
......@@ -106,6 +101,16 @@
*
*/
selectUrl: function(delta) {
let field = this._getFieldValues()[delta];
this.ephoto.File.setButtons( this.ephoto.IMAGE_FILES, [ {
'definition': field.size ? 'custom' : 'middle',
'size': field.size.toString(),
'dpi': '72',
'format': 'jpeg',
'notEnlarge': '1'
} ] );
this.ephoto.File.get();
},
......@@ -114,7 +119,24 @@
*/
insert: function() {
}
},
/**
* Get all field values
*/
_getFieldValues: function() {
var fields = [];
var sizes = $('.ephoto-dam-field-imagesize-field').toArray();
$('.ephoto-dam-field-version-field').map(function(index, el) {
fields.push({
'name' : $(el).val(),
'size' : $(sizes[index]).val()
});
});
return fields;
},
}
})(jQuery);
......
......@@ -45,6 +45,11 @@ class EphotoDamField extends FieldItemBase {
'type' => 'varchar',
'length' => 256
],
'image_size' => [
'type' => 'int',
'unsigned' => true,
'size' => 'small'
],
'version' => [
'type' => 'varchar',
'length' => 20
......@@ -59,14 +64,15 @@ class EphotoDamField extends FieldItemBase {
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string')
->setLabel(t('Url'))
//->setRequired(true)
//->setDescription(t('The node UUID.'))
;
->setRequired(true);
$properties['image_size'] = DataDefinition::create('integer')
->setLabel(t('Image size'))
->setRequired(true);
$properties['version'] = DataDefinition::create('string')
->setLabel(t('Version'))
->setRequired(true)
;
->setRequired(true);
return $properties;
}
......@@ -76,19 +82,20 @@ class EphotoDamField extends FieldItemBase {
*/
public function isEmpty() {
$value = $this->get('value')->getValue();
$image_size = $this->get('image_size')->getValue();
$version = $this->get('version')->getValue();
return empty($value) && empty($version);
return empty($value) && empty($image_size) && empty($version);
}
/**
* {@inheritdoc}
*/
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$form['url'] = [
$form['server_url'] = [
'#title' => $this->t('Server URL'),
'#type' => 'url',
'#default_value' => $this->getSetting('url'),
'#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/')],
......@@ -103,7 +110,7 @@ class EphotoDamField extends FieldItemBase {
'#attributes' => [
'onclick' => 'Drupal.ephotoDamField.enableVersionSupport(this)'
]
];
];
return $form;
}
......@@ -113,7 +120,7 @@ class EphotoDamField extends FieldItemBase {
*/
public static function defaultFieldSettings() {
return [
'url' => '',
'server_url' => '',
'version_support' => false
];
}
......
......@@ -29,7 +29,7 @@ class EphotoDamFieldWidget extends WidgetBase {
$version_support = $this->getFieldSetting('version_support');
if (self::$first) {
$classes = ['ephoto-dam-field-button', 'ephoto-dam-field-version-button'];
$classes = ['button', 'ephoto-dam-field-button', 'ephoto-dam-field-version-button'];
if (!$version_support) $classes[] = 'ephoto-dam-field-hidden';
$element['version-import'] = [
......@@ -58,6 +58,22 @@ class EphotoDamFieldWidget extends WidgetBase {
]
];
$element['image_size'] = [
'#type' => 'number',
'#title' => ' ',
'#default_value' => isset($items[$delta]->image_size) ? $items[$delta]->image_size : 0,
'#disabled' => !$is_default_values_form,
'#size' => 12,
'#maxlength' => 60,
'#field_suffix' => 'px',
'#attributes' => [
'class' => ['form-url', 'ephoto-dam-field-imagesize-field'],
'placeholder' => $this->t('Image size'),
'min' => 20,
'max' => 1600
]
];
$classes = ['form-url', 'ephoto-dam-field-version-field'];
if (!$version_support) $classes[] = 'ephoto-dam-field-hidden';
......@@ -74,7 +90,7 @@ class EphotoDamFieldWidget extends WidgetBase {
]
];
$classes = ['ephoto-dam-field-button', 'ephoto-dam-field-field-button'];
$classes = ['button', 'ephoto-dam-field-button', 'ephoto-dam-field-field-button'];
if ($version_support) $classes[] = 'ephoto-dam-field-hidden';
$element['field-import'] = [
......
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