util.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, Drupal) {
  8. Drupal.quickedit.util = Drupal.quickedit.util || {};
  9. Drupal.quickedit.util.constants = {};
  10. Drupal.quickedit.util.constants.transitionEnd = 'transitionEnd.quickedit webkitTransitionEnd.quickedit transitionend.quickedit msTransitionEnd.quickedit oTransitionEnd.quickedit';
  11. Drupal.quickedit.util.buildUrl = function (id, urlFormat) {
  12. var parts = id.split('/');
  13. return Drupal.formatString(decodeURIComponent(urlFormat), {
  14. '!entity_type': parts[0],
  15. '!id': parts[1],
  16. '!field_name': parts[2],
  17. '!langcode': parts[3],
  18. '!view_mode': parts[4]
  19. });
  20. };
  21. Drupal.quickedit.util.networkErrorModal = function (title, message) {
  22. var $message = $('<div>' + message + '</div>');
  23. var networkErrorModal = Drupal.dialog($message.get(0), {
  24. title: title,
  25. dialogClass: 'quickedit-network-error',
  26. buttons: [{
  27. text: Drupal.t('OK'),
  28. click: function click() {
  29. networkErrorModal.close();
  30. },
  31. primary: true
  32. }],
  33. create: function create() {
  34. $(this).parent().find('.ui-dialog-titlebar-close').remove();
  35. },
  36. close: function close(event) {
  37. $(event.target).remove();
  38. }
  39. });
  40. networkErrorModal.showModal();
  41. };
  42. Drupal.quickedit.util.form = {
  43. load: function load(options, callback) {
  44. var fieldID = options.fieldID;
  45. var formLoaderAjax = Drupal.ajax({
  46. url: Drupal.quickedit.util.buildUrl(fieldID, Drupal.url('quickedit/form/!entity_type/!id/!field_name/!langcode/!view_mode')),
  47. submit: {
  48. nocssjs: options.nocssjs,
  49. reset: options.reset
  50. },
  51. error: function error(xhr, url) {
  52. var fieldLabel = Drupal.quickedit.metadata.get(fieldID, 'label');
  53. 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 });
  54. Drupal.quickedit.util.networkErrorModal(Drupal.t('Network problem!'), message);
  55. var fieldModel = Drupal.quickedit.app.model.get('activeField');
  56. fieldModel.set('state', 'candidate');
  57. }
  58. });
  59. formLoaderAjax.commands.quickeditFieldForm = function (ajax, response, status) {
  60. callback(response.data, ajax);
  61. Drupal.ajax.instances[this.instanceIndex] = null;
  62. };
  63. formLoaderAjax.execute();
  64. },
  65. ajaxifySaving: function ajaxifySaving(options, $submit) {
  66. var settings = {
  67. url: $submit.closest('form').attr('action'),
  68. setClick: true,
  69. event: 'click.quickedit',
  70. progress: false,
  71. submit: {
  72. nocssjs: options.nocssjs,
  73. other_view_modes: options.other_view_modes
  74. },
  75. success: function success(response, status) {
  76. var _this = this;
  77. Object.keys(response || {}).forEach(function (i) {
  78. if (response[i].command && _this.commands[response[i].command]) {
  79. _this.commands[response[i].command](_this, response[i], status);
  80. }
  81. });
  82. },
  83. base: $submit.attr('id'),
  84. element: $submit[0]
  85. };
  86. return Drupal.ajax(settings);
  87. },
  88. unajaxifySaving: function unajaxifySaving(ajax) {
  89. $(ajax.element).off('click.quickedit');
  90. }
  91. };
  92. })(jQuery, Drupal);