Commit dd955abf authored by ephoto_dam's avatar ephoto_dam

Ephoto Dam Field in progress

parent 75608d37
......@@ -5,9 +5,30 @@
* Module ephoto_dam_field.
*/
use Drupal\Component\Serialization\Json;
use \Drupal\Core\Render\Markup;
/**
* Hook : implements hook_field_widget_form_alter().
*/
function ephoto_dam_field_field_widget_form_alter(&$element, &$form_state, $context) {
$element['#attached']['library'][] = 'ephoto_dam_field/edit';
$field_definition = $context['items']->getFieldDefinition();
if ($field_definition->getType() === 'ephoto_dam_field') {
$settings = $field_definition->getSettings();
$settings_encoded = str_replace('"', "'", Json::encode($settings));
$element['#attached']['library'][] = 'ephoto_dam_field/edit';
// I do not like it
// It would be nice to put the settings AFTER the ".libraries", which would make it possible to call directly EphotoDamField.load($settings_encoded)
$element['#attached']['html_head'][] = [
[
'#tag' => 'script',
'#value' => Markup::create('EphotoDamFieldSettings=' . $settings_encoded . ';'),
'#weight' => 200
],
'ephoto_dam_field_js_settings'
];
}
}
......@@ -7,26 +7,29 @@
(function ($) {
EphotoDamField = {
/**
* EPHOTO ID of Drupal Addon
*/
/**
* EPHOTO ID of Drupal Addon
*/
CLIENT_ID : 'CaCvqS5H',
/**
* Settings
*/
/**
* Settings
*/
settings: null,
/**
* Ephoto Dam instance
*/
/**
* Ephoto Dam instance
*/
ephoto: null,
/**
* Ephoto Dam Server connected
*/
connected: false,
/**
* Ephoto Dam Server connected
*/
connected: false,
/**
* Enable version support
*/
enableVersionSupport: function(el) {
if(el.checked) {
$('.ephoto-dam-field-version-field').removeClass('ephoto-dam-field-hidden');
......@@ -43,49 +46,76 @@
}
},
select: function(settings) {
this.settings = settings;
/**
* Load Ephoto Dam Api
*/
load: function() {
this.settings = EphotoDamFieldSettings;
$.getScript(settings.url + 'api/apiJS.js', this.initApi.bind(this));
},
/**
* Init Ephoto Dam Api
*/
initApi: function() {
var self = this;
var self = this;
if(!ePhoto) {
console.log(Drupal.t('Error loading the Ephoto Dam API'));
return;
}
if (!ePhoto) {
console.log(Drupal.t('Error loading the Ephoto Dam API'));
return;
}
console.log('loaded!');
console.log(this.settings.url);
console.log('loaded!');
console.log(this.settings.url);
this.ephoto = new ePhoto({
'server': this.settings.url,
//'authID': CKEDITOR.tools.getCookie('drupal_ephoto_dam_authid'),
'client': this.CLIENT_ID
});
this.ephoto = new ePhoto({
'server': this.settings.url,
//'authID': CKEDITOR.tools.getCookie('drupal_ephoto_dam_authid'),
'client': this.CLIENT_ID
});
this.ephoto.connect();
this.ephoto.connect();
this.ephoto.callOnConnect(function() {
//var today = expires = new Date();
//expires.setDate(today.getDate() + 2);
//this.ephoto.File.setMode('embed');
//CKEDITOR.tools.setCookie( 'drupal_ephoto_dam_authid', self.ephoto.getAuthID());
//this.ephoto.File.enableDCore();
self.connected = true;
});
this.ephoto.callOnConnect(function() {
//var today = expires = new Date();
//expires.setDate(today.getDate() + 2);
this.ephoto.File.callOnFileReceived(this.insert.bind(this));
this.ephoto.File.get();
//CKEDITOR.tools.setCookie( 'drupal_ephoto_dam_authid', self.ephoto.getAuthID());
self.connected = true;
});
this.ephoto.File.callOnFileReceived(this.insert.bind(this));
},
/**
*
*/
selectVersionUrls: function() {
this.ephoto.File.get();
},
/**
*
*/
selectUrl: function(delta) {
this.ephoto.File.get();
},
/**
*
*/
insert: function() {
}
}
EphotoDamField.load();
})(jQuery);
......@@ -26,13 +26,8 @@ class EphotoDamFieldWidget extends WidgetBase {
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$settings = $this->getFieldSettings();
$settings['delta'] = $delta;
$settings_encoded = str_replace('"', "'", Json::encode($settings));
$is_default_values_form = $this->isDefaultValueWidget($form_state);
$version_support = $settings['version_support'];
$version_support = $this->getFieldSetting('version_support');
if (self::$first) {
$classes = ['ephoto-dam-field-button', 'ephoto-dam-field-version-button'];
......@@ -44,9 +39,9 @@ class EphotoDamFieldWidget extends WidgetBase {
'#disabled' => $is_default_values_form,
'#attributes' => [
'class' => $classes,
'onclick' => 'EphotoDamField.select(' . $settings_encoded . ');return false',
'onclick' => 'EphotoDamField.selectVersionUrls();return false',
'class' => $classes,
]
],
];
self::$first = false;
......@@ -89,7 +84,7 @@ class EphotoDamFieldWidget extends WidgetBase {
'#disabled' => $is_default_values_form,
'#attributes' => [
'class' => $classes,
'onclick' => 'EphotoDamField.select(' . $settings_encoded . ');return false',
'onclick' => 'EphotoDamField.selectUrl(' . $delta . ');return false',
'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