[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/system/js/fields/ -> modal-fields.js (source)

   1  /**
   2   * @copyright  (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
   3   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   4   */
   5  
   6  (function() {
   7      "use strict";
   8  
   9      /**
  10       * Process modal fields in parent.
  11       *
  12       * @param   string  fieldPrefix  The fields to be updated prefix.
  13       * @param   string  id           The new id for the item.
  14       * @param   string  title        The new title for the item.
  15       * @param   string  catid        Future usage.
  16       * @param   object  object       Future usage.
  17       * @param   string  url          Future usage.
  18       * @param   string  language     Future usage.
  19       *
  20       * @return  boolean
  21       *
  22       * @since   3.7.0
  23       */
  24      window.processModalParent = function (fieldPrefix, id, title, catid, url, language, object)
  25      {
  26          var fieldId = document.getElementById(fieldPrefix + '_id'), fieldTitle = document.getElementById(fieldPrefix + '_name');
  27  
  28          // Default values.
  29          id       = id || '';
  30          title    = title || '';
  31          catid    = catid || '';
  32          object   = object || '';
  33          url      = url || '';
  34          language = language || '';
  35  
  36          if (id)
  37          {
  38              fieldId.value    = id;
  39              fieldTitle.value = title;
  40  
  41              if (document.getElementById(fieldPrefix + '_select'))
  42              {
  43                  document.getElementById(fieldPrefix + '_select').classList.add('hidden');
  44              }
  45              if (document.getElementById(fieldPrefix + '_new'))
  46              {
  47                  document.getElementById(fieldPrefix + '_new').classList.add('hidden');
  48              }
  49              if (document.getElementById(fieldPrefix + '_edit'))
  50              {
  51                  document.getElementById(fieldPrefix + '_edit').classList.remove('hidden');
  52              }
  53              if (document.getElementById(fieldPrefix + '_clear'))
  54              {
  55                  document.getElementById(fieldPrefix + '_clear').classList.remove('hidden');
  56              }
  57              if (document.getElementById(fieldPrefix + '_propagate'))
  58              {
  59                  document.getElementById(fieldPrefix + '_propagate').classList.remove('hidden');
  60              }
  61          }
  62          else
  63          {
  64              fieldId.value    = '';
  65              fieldTitle.value = fieldId.getAttribute('data-text');
  66  
  67              if (document.getElementById(fieldPrefix + '_select'))
  68              {
  69                  document.getElementById(fieldPrefix + '_select').classList.remove('hidden');
  70              }
  71              if (document.getElementById(fieldPrefix + '_new'))
  72              {
  73                  document.getElementById(fieldPrefix + '_new').classList.remove('hidden');
  74              }
  75              if (document.getElementById(fieldPrefix + '_edit'))
  76              {
  77                  document.getElementById(fieldPrefix + '_edit').classList.add('hidden');
  78              }
  79              if (document.getElementById(fieldPrefix + '_clear'))
  80              {
  81                  document.getElementById(fieldPrefix + '_clear').classList.add('hidden');
  82              }
  83              if (document.getElementById(fieldPrefix + '_propagate'))
  84              {
  85                  document.getElementById(fieldPrefix + '_propagate').classList.add('hidden');
  86              }
  87          }
  88  
  89          if (fieldId.getAttribute('data-required') == '1')
  90          {
  91              document.formvalidator.validate(fieldId);
  92              document.formvalidator.validate(fieldTitle);
  93          }
  94  
  95          return false;
  96      };
  97  
  98      /**
  99       * Process new/edit modal fields in child.
 100       *
 101       * @param   object  element       The modal footer button element.
 102       * @param   string  fieldPrefix   The fields to be updated prefix.
 103       * @param   string  action        Modal action (add, edit).
 104       * @param   string  itemType      The item type (Article, Contact, etc).
 105       * @param   string  task          Task to be done (apply, save, cancel).
 106       * @param   string  formId        Id of the form field (defaults to itemtype-form).
 107       * @param   string  idFieldId     Id of the id field (defaults to jform_id).
 108       * @param   string  titleFieldId  Id of the title field (defaults to jform_title).
 109       *
 110       * @return  boolean
 111       *
 112       * @since   3.7.0
 113       */
 114      window.processModalEdit = function (element, fieldPrefix, action, itemType, task, formId, idFieldId, titleFieldId)
 115      {
 116          formId       = formId || itemType.toLowerCase() + '-form';
 117          idFieldId    = idFieldId || 'jform_id';
 118          titleFieldId = titleFieldId || 'jform_title';
 119  
 120          var modalId = element.parentNode.parentNode.parentNode.parentNode.id, submittedTask = task;
 121          var iframe  = document.getElementById(modalId).getElementsByTagName('iframe')[0];
 122  
 123          // Set frame id.
 124          iframe.id = 'Frame_' + modalId;
 125  
 126          var iframeDocument = iframe.contentDocument;
 127  
 128          // If Close (cancel task), close the modal.
 129          if (task === 'cancel')
 130          {
 131              // Submit button on child iframe so we can check out.
 132              iframe.contentWindow.Joomla.submitbutton(itemType.toLowerCase() + '.' + task);
 133  
 134              Joomla.Modal.getCurrent().close();
 135          }
 136          // For Save (apply task) and Save & Close (save task).
 137          else
 138          {
 139              // Attach onload event to the iframe.
 140              iframe.addEventListener('load', function()
 141              {
 142                  // Reload iframe document var value.
 143                  iframeDocument = this.contentDocument;
 144  
 145                  // Validate the child form and update parent form.
 146                  if (iframeDocument.getElementById(idFieldId) && iframeDocument.getElementById(idFieldId).value != '0')
 147                  {
 148                      window.processModalParent(fieldPrefix, iframeDocument.getElementById(idFieldId).value, iframeDocument.getElementById(titleFieldId).value);
 149  
 150                      // If Save & Close (save task), submit the edit close action (so we don't have checked out items).
 151                      if (task === 'save')
 152                      {
 153                          window.processModalEdit(element, fieldPrefix, 'edit', itemType, 'cancel', formId, idFieldId, titleFieldId);
 154                      }
 155                  }
 156  
 157                  // Show the iframe again for future modals or in case of error.
 158                  iframe.classList.remove('visually-hidden');
 159              });
 160  
 161              // Submit button on child iframe.
 162              if (iframeDocument.formvalidator.isValid(iframeDocument.getElementById(formId)))
 163              {
 164                  // For Save & Close (save task) when creating we need to replace the task as apply because of redirects after submit and hide the iframe.
 165                  if (task === 'save')
 166                  {
 167                      submittedTask = 'apply';
 168                      iframe.classList.add('visually-hidden');
 169                  }
 170  
 171                  iframe.contentWindow.Joomla.submitbutton(itemType.toLowerCase() + '.' + submittedTask);
 172              }
 173          }
 174  
 175          return false;
 176      };
 177  
 178      /**
 179       * Process select modal fields in child.
 180       *
 181       * @param   string  itemType     The item type (Article, Contact, etc).
 182       * @param   string  fieldPrefix  The fields to be updated prefix.
 183       * @param   string  id           The new id for the item.
 184       * @param   string  title        The new title for the item.
 185       * @param   string  catid        Future usage.
 186       * @param   object  object       Future usage.
 187       * @param   string  url          Future usage.
 188       * @param   string  language     Future usage.
 189       *
 190       * @return  boolean
 191       *
 192       * @since   3.7.0
 193       */
 194      window.processModalSelect = function(itemType, fieldPrefix, id, title, catid, object, url, language) {
 195          window.processModalParent(fieldPrefix, id, title, catid, url, language, object);
 196  
 197          // Close Modal only when necessary.
 198          if (Joomla.Modal.getCurrent())
 199          {
 200              Joomla.Modal.getCurrent().close();
 201          }
 202  
 203          return false;
 204      };
 205  
 206  }());


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer