[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/system/js/fields/ -> joomla-field-permissions-es5.js (source)

   1  (function () {
   2    'use strict';
   3  
   4    function _inheritsLoose(subClass, superClass) {
   5      subClass.prototype = Object.create(superClass.prototype);
   6      subClass.prototype.constructor = subClass;
   7  
   8      _setPrototypeOf(subClass, superClass);
   9    }
  10  
  11    function _getPrototypeOf(o) {
  12      _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  13        return o.__proto__ || Object.getPrototypeOf(o);
  14      };
  15      return _getPrototypeOf(o);
  16    }
  17  
  18    function _setPrototypeOf(o, p) {
  19      _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  20        o.__proto__ = p;
  21        return o;
  22      };
  23  
  24      return _setPrototypeOf(o, p);
  25    }
  26  
  27    function _isNativeReflectConstruct() {
  28      if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  29      if (Reflect.construct.sham) return false;
  30      if (typeof Proxy === "function") return true;
  31  
  32      try {
  33        Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  34        return true;
  35      } catch (e) {
  36        return false;
  37      }
  38    }
  39  
  40    function _construct(Parent, args, Class) {
  41      if (_isNativeReflectConstruct()) {
  42        _construct = Reflect.construct;
  43      } else {
  44        _construct = function _construct(Parent, args, Class) {
  45          var a = [null];
  46          a.push.apply(a, args);
  47          var Constructor = Function.bind.apply(Parent, a);
  48          var instance = new Constructor();
  49          if (Class) _setPrototypeOf(instance, Class.prototype);
  50          return instance;
  51        };
  52      }
  53  
  54      return _construct.apply(null, arguments);
  55    }
  56  
  57    function _isNativeFunction(fn) {
  58      return Function.toString.call(fn).indexOf("[native code]") !== -1;
  59    }
  60  
  61    function _wrapNativeSuper(Class) {
  62      var _cache = typeof Map === "function" ? new Map() : undefined;
  63  
  64      _wrapNativeSuper = function _wrapNativeSuper(Class) {
  65        if (Class === null || !_isNativeFunction(Class)) return Class;
  66  
  67        if (typeof Class !== "function") {
  68          throw new TypeError("Super expression must either be null or a function");
  69        }
  70  
  71        if (typeof _cache !== "undefined") {
  72          if (_cache.has(Class)) return _cache.get(Class);
  73  
  74          _cache.set(Class, Wrapper);
  75        }
  76  
  77        function Wrapper() {
  78          return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  79        }
  80  
  81        Wrapper.prototype = Object.create(Class.prototype, {
  82          constructor: {
  83            value: Wrapper,
  84            enumerable: false,
  85            writable: true,
  86            configurable: true
  87          }
  88        });
  89        return _setPrototypeOf(Wrapper, Class);
  90      };
  91  
  92      return _wrapNativeSuper(Class);
  93    }
  94  
  95    function _assertThisInitialized(self) {
  96      if (self === void 0) {
  97        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  98      }
  99  
 100      return self;
 101    }
 102  
 103    /**
 104     * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
 105     * @license    GNU General Public License version 2 or later; see LICENSE.txt
 106     */
 107    window.customElements.define('joomla-field-permissions', /*#__PURE__*/function (_HTMLElement) {
 108      _inheritsLoose(_class, _HTMLElement);
 109  
 110      function _class() {
 111        var _this;
 112  
 113        _this = _HTMLElement.call(this) || this;
 114  
 115        if (!Joomla) {
 116          throw new Error('Joomla API is not properly initiated');
 117        }
 118  
 119        if (!_this.getAttribute('data-uri')) {
 120          throw new Error('No valid url for validation');
 121        }
 122  
 123        _this.query = window.location.search.substring(1);
 124        _this.buttons = '';
 125        _this.buttonDataSelector = 'data-onchange-task';
 126        _this.onDropdownChange = _this.onDropdownChange.bind(_assertThisInitialized(_this));
 127        _this.getUrlParam = _this.getUrlParam.bind(_assertThisInitialized(_this));
 128        _this.component = _this.getUrlParam('component');
 129        _this.extension = _this.getUrlParam('extension');
 130        _this.option = _this.getUrlParam('option');
 131        _this.view = _this.getUrlParam('view');
 132        _this.asset = 'not';
 133        _this.context = '';
 134        return _this;
 135      }
 136      /**
 137       * Lifecycle
 138       */
 139  
 140  
 141      var _proto = _class.prototype;
 142  
 143      _proto.connectedCallback = function connectedCallback() {
 144        var _this2 = this;
 145  
 146        this.buttons = [].slice.call(document.querySelectorAll("[" + this.buttonDataSelector + "]"));
 147  
 148        if (this.buttons) {
 149          this.buttons.forEach(function (button) {
 150            button.addEventListener('change', _this2.onDropdownChange);
 151          });
 152        }
 153      }
 154      /**
 155       * Lifecycle
 156       */
 157      ;
 158  
 159      _proto.disconnectedCallback = function disconnectedCallback() {
 160        var _this3 = this;
 161  
 162        if (this.buttons) {
 163          this.buttons.forEach(function (button) {
 164            button.removeEventListener('change', _this3.onDropdownChange);
 165          });
 166        }
 167      }
 168      /**
 169       * Lifecycle
 170       */
 171      ;
 172  
 173      _proto.onDropdownChange = function onDropdownChange(event) {
 174        event.preventDefault();
 175        var task = event.target.getAttribute(this.buttonDataSelector);
 176  
 177        if (task === 'permissions.apply') {
 178          this.sendPermissions(event);
 179        }
 180      };
 181  
 182      _proto.sendPermissions = function sendPermissions(event) {
 183        var target = event.target; // Set the icon while storing the values
 184  
 185        var icon = document.getElementById("icon_" + target.id);
 186        icon.removeAttribute('class');
 187        icon.setAttribute('class', 'joomla-icon joomla-field-permissions__spinner'); // Get values add prepare GET-Parameter
 188  
 189        var value = target.value;
 190  
 191        if (document.getElementById('jform_context')) {
 192          this.context = document.getElementById('jform_context').value;
 193  
 194          var _this$context$split = this.context.split('.');
 195  
 196          this.context = _this$context$split[0];
 197        }
 198  
 199        if (this.option === 'com_config' && !this.component && !this.extension) {
 200          this.asset = 'root.1';
 201        } else if (!this.extension && this.view === 'component') {
 202          this.asset = this.component;
 203        } else if (this.context) {
 204          if (this.view === 'group') {
 205            this.asset = this.context + ".fieldgroup." + this.getUrlParam('id');
 206          } else {
 207            this.asset = this.context + ".field.{this.getUrlParam('id')}";
 208          }
 209  
 210          this.title = document.getElementById('jform_title').value;
 211        } else if (this.extension && this.view) {
 212          this.asset = this.extension + "." + this.view + "." + this.getUrlParam('id');
 213          this.title = document.getElementById('jform_title').value;
 214        } else if (!this.extension && this.view) {
 215          this.asset = this.option + "." + this.view + "." + this.getUrlParam('id');
 216          this.title = document.getElementById('jform_title').value;
 217        }
 218  
 219        var id = target.id.replace('jform_rules_', '');
 220        var lastUnderscoreIndex = id.lastIndexOf('_');
 221        var permissionData = {
 222          comp: this.asset,
 223          action: id.substring(0, lastUnderscoreIndex),
 224          rule: id.substring(lastUnderscoreIndex + 1),
 225          value: value,
 226          title: this.title
 227        }; // Remove JS messages, if they exist.
 228  
 229        Joomla.removeMessages(); // Ajax request
 230  
 231        Joomla.request({
 232          url: this.getAttribute('data-uri'),
 233          method: 'POST',
 234          data: JSON.stringify(permissionData),
 235          perform: true,
 236          headers: {
 237            'Content-Type': 'application/json'
 238          },
 239          onSuccess: function onSuccess(data) {
 240            var response;
 241  
 242            try {
 243              response = JSON.parse(data);
 244            } catch (e) {
 245              // eslint-disable-next-line no-console
 246              console.error(e);
 247            }
 248  
 249            icon.removeAttribute('class'); // Check if everything is OK
 250  
 251            if (response.data && response.data.result) {
 252              icon.setAttribute('class', 'joomla-icon joomla-field-permissions__allowed');
 253              var badgeSpan = target.parentNode.parentNode.nextElementSibling.querySelector('span');
 254              badgeSpan.removeAttribute('class');
 255              badgeSpan.setAttribute('class', response.data.class);
 256              badgeSpan.innerHTML = Joomla.sanitizeHtml(response.data.text);
 257            } // Render messages, if any. There are only message in case of errors.
 258  
 259  
 260            if (typeof response.messages === 'object' && response.messages !== null) {
 261              Joomla.renderMessages(response.messages);
 262  
 263              if (response.data && response.data.result) {
 264                icon.setAttribute('class', 'joomla-icon joomla-field-permissions__allowed');
 265              } else {
 266                icon.setAttribute('class', 'joomla-icon joomla-field-permissions__denied');
 267              }
 268            }
 269          },
 270          onError: function onError(xhr) {
 271            // Remove the spinning icon.
 272            icon.removeAttribute('style');
 273            Joomla.renderMessages(Joomla.ajaxErrorsMessages(xhr, xhr.statusText));
 274            icon.setAttribute('class', 'joomla-icon joomla-field-permissions__denied');
 275          }
 276        });
 277      };
 278  
 279      _proto.getUrlParam = function getUrlParam(variable) {
 280        var vars = this.query.split('&');
 281        var i = 0;
 282  
 283        for (i; i < vars.length; i += 1) {
 284          var pair = vars[i].split('=');
 285  
 286          if (pair[0] === variable) {
 287            return pair[1];
 288          }
 289        }
 290  
 291        return false;
 292      };
 293  
 294      return _class;
 295    }( /*#__PURE__*/_wrapNativeSuper(HTMLElement)));
 296  
 297  })();


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