diff --git a/css/scenebuilder_format_strawberryfield.css b/css/scenebuilder_format_strawberryfield.css new file mode 100644 index 0000000..9fd0ccd --- /dev/null +++ b/css/scenebuilder_format_strawberryfield.css @@ -0,0 +1,40 @@ +.hotspot_marker_wrapper { + background-color: deepskyblue; + border-radius: 50%; + position: absolute; + top: 0px; + left: 0px; + display: none; + opacity: 0; + -moz-transition: opacity .3s ease-in-out; + -webkit-transition: opacity .3s ease-in-out; + -o-transition: opacity .3s ease-in-out; + -ms-transition: opacity .3s ease-in-out; + transition: opacity .3s ease-in-out; + z-index: 1 +} +.hotspot_editor_marker { + border-radius: 50%; + background-color: deepskyblue; + width: 150px; + height: 150px; + position: absolute; + left:-75px; + top:-75px; + opacity: 0; + animation: scaleIn 4s infinite cubic-bezier(.36, .11, .89, .32); +} +@keyframes scaleIn { + from { + transform: scale(.5, .5); + opacity: .5; + } + to { + transform: scale(2.5, 2.5); + opacity: 0; + } +} + + + + diff --git a/js/hidenodeaction-webform_strawberryfield.js b/js/hidenodeaction-webform_strawberryfield.js index 95ef0aa..dd5b9e1 100644 --- a/js/hidenodeaction-webform_strawberryfield.js +++ b/js/hidenodeaction-webform_strawberryfield.js @@ -21,9 +21,9 @@ if ($('.path-node fieldset[data-strawberryfield-selector="strawberry-webform-widget"]').length) { if ($('.webform-confirmation',context).length) { // Exclude webform own edit-actions containter - $('.path-node div[data-drupal-selector="edit-actions"]').not('.webform-actions').show(); + $('.path-node .node-form div[data-drupal-selector="edit-actions"]').not('.webform-actions').show(); } else if ($('div.field--widget-strawberryfield-webform-inline-widget').length) { - $('.path-node div[data-drupal-selector="edit-actions"]').not('.webform-actions').hide(); + $('.path-node .node-form div[data-drupal-selector="edit-actions"]').not('.webform-actions').hide(); } @@ -31,14 +31,14 @@ if ($moderationstate.length) { var $select = $moderationstate.on('change', function () { - $('.path-node div[data-drupal-selector="edit-actions"]').not('.webform-actions').show(); + $('.path-node .node-form div[data-drupal-selector="edit-actions"]').not('.webform-actions').show(); }); } var $nodetitle = $('input[data-drupal-selector="edit-title-0-value"]', context).once('show-hide-actions'); if ($nodetitle.length) { var $select = $nodetitle.on('input', function () { - $('.path-node div[data-drupal-selector="edit-actions"]').not('.webform-actions').show(); + $('.path-node .node-form div[data-drupal-selector="edit-actions"]').not('.webform-actions').show(); }); } diff --git a/js/scenebuilder-pannellum_strawberryfield.js b/js/scenebuilder-pannellum_strawberryfield.js new file mode 100644 index 0000000..e8591a9 --- /dev/null +++ b/js/scenebuilder-pannellum_strawberryfield.js @@ -0,0 +1,111 @@ +(function ($, Drupal, drupalSettings, pannellum) { + + + + function marker(event, $marker, $container) { + var pos = mousePosition(event,$container); + $marker.css("left", pos.x + 'px'); + $marker.css("top", pos.y + 'px'); + $marker.css("opacity", '1.0'); + $marker.css("display", 'block'); + $marker.fadeIn('slow'); + $marker.fadeOut('slow'); + } + + + function mousePosition(event,$container) { + var bounds = $container.getBoundingClientRect(); + var pos = {}; + // pageX / pageY needed for iOS + pos.x = (event.clientX || event.pageX) - bounds.left; + pos.y = (event.clientY || event.pageY) - bounds.top; + return pos; + } + + Drupal.AjaxCommands.prototype.webform_strawberryfield_pannellum_editor_addHotSpot = function(ajax, response, status) { + console.log('adding hotspot'); + // we need to find the first '.strawberry-panorama-item' id that is child of data-drupal-selector="edit-panorama-tour-hotspots" + console.log(response.selector); + $targetScene = $(response.selector).find('.strawberry-panorama-item').attr("id"); + console.log($targetScene); + if (response.hasOwnProperty('hotspot')) { + $scene = Drupal.FormatStrawberryfieldPanoramas.panoramas.get($targetScene); + // add click handlers for new Hotspots if they have an URL. + // Empty URLs are handled by Drupal.FormatStrawberryfieldhotspotPopUp() + console.log(response); + if (response.hotspot.hasOwnProperty('URL')) { + response.hotspot.clickHandlerFunc = Drupal.FormatStrawberryfieldhotspotPopUp; + response.hotspot.clickHandlerArgs = response.hotspot.URL; + } + + $scene.panorama.addHotSpot(response.hotspot); + } + }; + + + Drupal.behaviors.webform_strawberryfield_pannellum_editor = { + attach: function(context, settings) { + $('.strawberry-panorama-item[data-iiif-image]').once('attache_pne') + .each(function (index, value) { + var hotspots = []; + // Get the node uuid for this element + var element_id = $(this).attr("id"); + console.log('Checking for loaded Panoramatour builder Hotspots'); + console.log(drupalSettings.webform_strawberryfield.WebformPanoramaTour); + // Feed with existing Hotspots comming from the Webform Element data. + for (var parentselector in drupalSettings.webform_strawberryfield.WebformPanoramaTour) { + if (Object.prototype.hasOwnProperty.call(drupalSettings.webform_strawberryfield.WebformPanoramaTour, parentselector)) { + $targetScene = $("[data-webform_strawberryfield-selector='" + parentselector + "']").find('.strawberry-panorama-item').attr("id"); + console.log(parentselector); + console.log($targetScene); + $scene = Drupal.FormatStrawberryfieldPanoramas.panoramas.get($targetScene); + if ((typeof $scene !== 'undefined')) { + if (drupalSettings.webform_strawberryfield.WebformPanoramaTour[parentselector]!== null + && typeof drupalSettings.webform_strawberryfield.WebformPanoramaTour[parentselector][Symbol.iterator] === 'function' + ) { + drupalSettings.webform_strawberryfield.WebformPanoramaTour[parentselector].forEach(function (hotspotdata, key) { + console.log(hotspotdata); + if (hotspotdata.hasOwnProperty('URL')) { + hotspotdata.clickHandlerFunc = Drupal.FormatStrawberryfieldhotspotPopUp; + hotspotdata.clickHandlerArgs = hotspotdata.URL; + } + $scene.panorama.addHotSpot(hotspotdata); + }); + } + } + } + } + + // Check if we got some data passed via Drupal settings. + if (typeof(drupalSettings.format_strawberryfield.pannellum[element_id]) != 'undefined') { + console.log('initializing Panellum Panorama Builder') + console.log(Drupal.FormatStrawberryfieldPanoramas.panoramas); + Drupal.FormatStrawberryfieldPanoramas.panoramas.forEach(function(item, key) { + + var element_id_marker = element_id + '_marker'; + var $newmarker = $( "
%data
', [
- '@webformid' => $this->getWebform()->id(),
- '%data' => print_r($webform_submission->getData(), TRUE),
- '@error' => $e->getMessage(),
- ]);
+ $this->messenger()->addError(
+ $this->t(
+ 'Sorry, we have issues writing metadata to your session storage. Please reload this form and/or contact your system admin.'
+ )
+ );
+ $this->loggerFactory->get('archipelago')->error(
+ 'Webform @webformid can not write to temp storage! with error @message. Attempted Metadata input was %data
',
+ [
+ '@webformid' => $this->getWebform()->id(),
+ '%data' => print_r($webform_submission->getData(), TRUE),
+ '@error' => $e->getMessage(),
+ ]
+ );
}
- } elseif ($this->IsWidgetDriven()) {
- $this->messenger()->addError($this->t('We lost TV reception in the middle of the match...Please contact your system admin.'));
- $this->loggerFactory->get('archipelago')->error('Webform @webformid lost connection to temp storage and its Widget!. No Widget State id present. Attempted Metadata input was %data
', [
- '@webformid' => $this->getWebform()->id(),
- '%data' => print_r($webform_submission->getData(), TRUE),
- ]);
+ }
+ elseif ($this->IsWidgetDriven()) {
+ $this->messenger()->addError(
+ $this->t(
+ 'We lost TV reception in the middle of the match...Please contact your system admin.'
+ )
+ );
+ $this->loggerFactory->get('archipelago')->error(
+ 'Webform @webformid lost connection to temp storage and its Widget!. No Widget State id present. Attempted Metadata input was %data
',
+ [
+ '@webformid' => $this->getWebform()->id(),
+ '%data' => print_r($webform_submission->getData(), TRUE),
+ ]
+ );
}
parent::preSave($webform_submission); // TODO: Change the autogenerated stub
@@ -298,41 +360,59 @@ public function preSave(WebformSubmissionInterface $webform_submission)
/**
* {@inheritdoc}
*/
- public function validateForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission)
- {
+ public function validateForm(
+ array &$form,
+ FormStateInterface $form_state,
+ WebformSubmissionInterface $webform_submission
+ ) {
$values = $webform_submission->getData();
- if ((!isset($values["strawberry_field_widget_state_id"]) || empty($values["strawberry_field_widget_state_id"])) && $this->IsWidgetDriven()) {
- $this->messenger()->addError($this->t('Sorry, we have issues reading your session storage identifier. Error was logged. Please reload this form and/or contact your system admin.'));
-
- $this->loggerFactory->get('archipelago')->error('Webform @webformid lost connection to temp storage!. No Widget State id present. Attempted Metadata input was %data
', [
- '@webformid' => $this->getWebform()->id(),
- '%data' => print_r($webform_submission->getData(), TRUE),
- ]);
+ if ((!isset($values["strawberry_field_widget_state_id"]) || empty($values["strawberry_field_widget_state_id"])) && $this->IsWidgetDriven(
+ )) {
+ $this->messenger()->addError(
+ $this->t(
+ 'Sorry, we have issues reading your session storage identifier. Error was logged. Please reload this form and/or contact your system admin.'
+ )
+ );
+
+ $this->loggerFactory->get('archipelago')->error(
+ 'Webform @webformid lost connection to temp storage!. No Widget State id present. Attempted Metadata input was %data
',
+ [
+ '@webformid' => $this->getWebform()->id(),
+ '%data' => print_r($webform_submission->getData(), TRUE),
+ ]
+ );
}
// All data is available here $webform_submission->getData()));
// @TODO what should be validated here?
- parent::validateForm($form, $form_state, $webform_submission); // TODO: Change the autogenerated stub
+ parent::validateForm(
+ $form,
+ $form_state,
+ $webform_submission
+ ); // TODO: Change the autogenerated stub
}
/**
* {@inheritdoc}
*/
- public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission)
- {
+ public function submitForm(
+ array &$form,
+ FormStateInterface $form_state,
+ WebformSubmissionInterface $webform_submission
+ ) {
$values = $webform_submission->getData();
if (isset($values["strawberry_field_widget_state_id"])) {
- $this->setIsWidgetDriven(true);
+ $this->setIsWidgetDriven(TRUE);
}
- // @TODO add a full-blown values cleaner
- // @TODO add the webform name used to create this as additional KEY
- // @TODO make sure widget can read that too.
- // @If Widget != setup form, ask for User feedback
- // @TODO, i need to alter node submit handler to add also the
- // Entities full URL as an @id to the top of the saved JSON.
- // FUN!
+ // @TODO add a full-blown values cleaner
+ // @TODO add the webform name used to create this as additional KEY
+ // @TODO make sure widget can read that too.
+ // @If Widget != setup form, ask for User feedback
+ // @TODO, i need to alter node submit handler to add also the
+ // Entities full URL as an @id to the top of the saved JSON.
+ // FUN!
// Get the URL to post the data to.
// @todo esmero a.k.a as Fedora-mockingbird
$post_url = $this->configuration['submission_url'];
@@ -349,7 +429,11 @@ public function submitForm(array &$form, FormStateInterface $form_state, Webform
* @return array
* Associative array keyed by AS type with binary info.
*/
- public function processFileField(array $element, WebformSubmissionInterface $webform_submission, $cleanvalues) {
+ public function processFileField(
+ array $element,
+ WebformSubmissionInterface $webform_submission,
+ $cleanvalues
+ ) {
$key = $element['#webform_key'];
$type = $element['#type'];
@@ -361,7 +445,9 @@ public function processFileField(array $element, WebformSubmissionInterface $web
$fids = (is_array($value)) ? $value : [$value];
$original_value = isset($original_data[$key]) ? $original_data[$key] : [];
- $original_fids = (is_array($original_value)) ? $original_value : [$original_value];
+ $original_fids = (is_array(
+ $original_value
+ )) ? $original_value : [$original_value];
// Delete the old file uploads?
// @TODO build some cleanup logic here. Could be moved to attached field hook.
@@ -381,7 +467,8 @@ public function processFileField(array $element, WebformSubmissionInterface $web
}
/* @see \Drupal\strawberryfield\StrawberryfieldFilePersisterService */
- $processedAsValues = \Drupal::service('strawberryfield.file_persister')->generateAsFileStructure($fids, $key, $cleanvalues);
+ $processedAsValues = \Drupal::service('strawberryfield.file_persister')
+ ->generateAsFileStructure($fids, $key, $cleanvalues);
return $processedAsValues;
}
@@ -389,7 +476,11 @@ public function processFileField(array $element, WebformSubmissionInterface $web
/**
* {@inheritdoc}
*/
- public function confirmForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
+ public function confirmForm(
+ array &$form,
+ FormStateInterface $form_state,
+ WebformSubmissionInterface $webform_submission
+ ) {
// We really want to avoid being redirected. This is how it is done.
//@TODO manage file upload if there is no submission save handler
//@ see \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::postSave
@@ -400,12 +491,12 @@ public function confirmForm(array &$form, FormStateInterface $form_state, Webfor
/**
* {@inheritdoc}
*/
- public function preprocessConfirmation(array &$variables)
- {
+ public function preprocessConfirmation(array &$variables) {
if ($this->isWidgetDriven()) {
unset($variables['back']);
}
}
+
/**
* {@inheritdoc}
*/
@@ -444,7 +535,8 @@ protected function getUriSchemeForManagedFile(array $element) {
if (isset($element['#uri_scheme'])) {
return $element['#uri_scheme'];
}
- $scheme_options = \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::getVisibleStreamWrappers();
+ $scheme_options = \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::getVisibleStreamWrappers(
+ );
if (isset($scheme_options['private'])) {
return 'private';
}
diff --git a/templates/webform-metadata-panoramatour.html.twig b/templates/webform-metadata-panoramatour.html.twig
new file mode 100644
index 0000000..2d35edb
--- /dev/null
+++ b/templates/webform-metadata-panoramatour.html.twig
@@ -0,0 +1,17 @@
+{#
+/**
+ * @file
+ * Default theme implementation of a Nominatim metadata composite webform element.
+ *
+ * Available variables:
+ * - content: The Panoramatour webform element to be output.
+ * - sceneselect: The select form/select dropdown user to choose a Panorama Object
+ * - hotspotui: All the Inputs used on the UI
+ * - hotspotbuttons: All the buttons used for doing stuff on loaded scenes
+ * - node: the actual loaded Panorama Viewer
+ * @see template_preprocess_webform_metadata_panoramatour()
+ *
+ * @ingroup themeable
+ */
+#}
+{{ content }}
\ No newline at end of file
diff --git a/templates/webform_strawberryfield-inlinefieldwidget.html.twig b/templates/webform_strawberryfield-inlinefieldwidget.html.twig
new file mode 100644
index 0000000..93c0a2d
--- /dev/null
+++ b/templates/webform_strawberryfield-inlinefieldwidget.html.twig
@@ -0,0 +1,28 @@
+{#
+/**
+ * @file
+ * Theme implementation for a 'webform' element overriden by our module
+ *
+ * This is an copy of the webform.html.twig theme_wrapper but changeas
+ * form element for a div, so it can live in HTML DOM inside an Entity Form
+ * as a Widget
+ * 'title_prefix' and 'title_suffix' variables needed for
+ *
+ * Available variables
+ * - attributes: A list of HTML attributes for the wrapper element.
+ * - children: The child elements of the webform.
+ * - title_prefix: Additional output populated by modules, intended to be
+ * displayed in front of the main title tag that appears in the template.
+ * - title_suffix: Additional output populated by modules, intended to be
+ * displayed after the main title tag that appears in the template.
+ *
+ * @see template_preprocess_webform()
+ *
+ * @ingroup themeable
+ */
+#}
+