diff core/modules/quickedit/js/util.js @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/modules/quickedit/js/util.js	Wed Nov 29 16:09:58 2017 +0000
@@ -0,0 +1,105 @@
+/**
+* DO NOT EDIT THIS FILE.
+* See the following change record for more information,
+* https://www.drupal.org/node/2815083
+* @preserve
+**/
+
+(function ($, Drupal) {
+  Drupal.quickedit.util = Drupal.quickedit.util || {};
+
+  Drupal.quickedit.util.constants = {};
+
+  Drupal.quickedit.util.constants.transitionEnd = 'transitionEnd.quickedit webkitTransitionEnd.quickedit transitionend.quickedit msTransitionEnd.quickedit oTransitionEnd.quickedit';
+
+  Drupal.quickedit.util.buildUrl = function (id, urlFormat) {
+    var parts = id.split('/');
+    return Drupal.formatString(decodeURIComponent(urlFormat), {
+      '!entity_type': parts[0],
+      '!id': parts[1],
+      '!field_name': parts[2],
+      '!langcode': parts[3],
+      '!view_mode': parts[4]
+    });
+  };
+
+  Drupal.quickedit.util.networkErrorModal = function (title, message) {
+    var $message = $('<div>' + message + '</div>');
+    var networkErrorModal = Drupal.dialog($message.get(0), {
+      title: title,
+      dialogClass: 'quickedit-network-error',
+      buttons: [{
+        text: Drupal.t('OK'),
+        click: function click() {
+          networkErrorModal.close();
+        },
+
+        primary: true
+      }],
+      create: function create() {
+        $(this).parent().find('.ui-dialog-titlebar-close').remove();
+      },
+      close: function close(event) {
+        $(event.target).remove();
+      }
+    });
+    networkErrorModal.showModal();
+  };
+
+  Drupal.quickedit.util.form = {
+    load: function load(options, callback) {
+      var fieldID = options.fieldID;
+
+      var formLoaderAjax = Drupal.ajax({
+        url: Drupal.quickedit.util.buildUrl(fieldID, Drupal.url('quickedit/form/!entity_type/!id/!field_name/!langcode/!view_mode')),
+        submit: {
+          nocssjs: options.nocssjs,
+          reset: options.reset
+        },
+        error: function error(xhr, url) {
+          var fieldLabel = Drupal.quickedit.metadata.get(fieldID, 'label');
+          var message = Drupal.t('Could not load the form for <q>@field-label</q>, either due to a website problem or a network connection problem.<br>Please try again.', { '@field-label': fieldLabel });
+          Drupal.quickedit.util.networkErrorModal(Drupal.t('Network problem!'), message);
+
+          var fieldModel = Drupal.quickedit.app.model.get('activeField');
+          fieldModel.set('state', 'candidate');
+        }
+      });
+
+      formLoaderAjax.commands.quickeditFieldForm = function (ajax, response, status) {
+        callback(response.data, ajax);
+        Drupal.ajax.instances[this.instanceIndex] = null;
+      };
+
+      formLoaderAjax.execute();
+    },
+    ajaxifySaving: function ajaxifySaving(options, $submit) {
+      var settings = {
+        url: $submit.closest('form').attr('action'),
+        setClick: true,
+        event: 'click.quickedit',
+        progress: false,
+        submit: {
+          nocssjs: options.nocssjs,
+          other_view_modes: options.other_view_modes
+        },
+
+        success: function success(response, status) {
+          for (var i in response) {
+            if (response.hasOwnProperty(i) && response[i].command && this.commands[response[i].command]) {
+              this.commands[response[i].command](this, response[i], status);
+            }
+          }
+        },
+
+        base: $submit.attr('id'),
+        element: $submit[0]
+      };
+
+      return Drupal.ajax(settings);
+    },
+    unajaxifySaving: function unajaxifySaving(ajax) {
+      $(ajax.element).off('click.quickedit');
+    }
+  };
+})(jQuery, Drupal);
\ No newline at end of file