f1b5e450e061e44d1f2c2d33a532448cfddb1338
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / FormEngine / Element / AbstractSortableSelectItems.js
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13 var __values=this&&this.__values||function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}};define(["require","exports","jquery","TYPO3/CMS/Backend/FormEngine","TYPO3/CMS/Backend/FormEngineValidation"],function(e,t,n,r,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(){this.registerSortableEventHandler=function(t){var i=t.closest(".form-wizards-wrap").querySelector(".form-wizards-items-aside");null!==i&&i.addEventListener("click",function(i){var l;if(null!==(l=i.target.closest(".t3js-btn-option"))){i.preventDefault();var a=l.dataset.fieldname;l.classList.contains("t3js-btn-moveoption-top")?e.moveOptionToTop(t):l.classList.contains("t3js-btn-moveoption-up")?e.moveOptionUp(t):l.classList.contains("t3js-btn-moveoption-down")?e.moveOptionDown(t):l.classList.contains("t3js-btn-moveoption-bottom")?e.moveOptionToBottom(t):l.classList.contains("t3js-btn-removeoption")&&e.removeOption(t,r.getFieldElement(a,"_avail").get(0)),r.updateHiddenFieldValueFromSelect(t,r.getFieldElement(a).get(0)),r.legacyFieldChangedCb(),o.markFieldAsChanged(n(t)),o.validate()}else i.target.matches(".t3js-btn-option")&&(l=i.target)})}}return e.moveOptionToTop=function(e){Array.from(e.querySelectorAll(":checked")).reverse().forEach(function(t){e.insertBefore(t,e.firstElementChild)})},e.moveOptionToBottom=function(e){Array.from(e.querySelectorAll(":checked")).forEach(function(t){e.insertBefore(t,null)})},e.moveOptionUp=function(e){var t,n,r=Array.from(e.children),o=Array.from(e.querySelectorAll(":checked"));try{for(var i=__values(o),l=i.next();!l.done;l=i.next()){var a=l.value;if(0===r.indexOf(a)&&null===a.previousElementSibling)break;e.insertBefore(a,a.previousElementSibling)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}},e.moveOptionDown=function(e){var t,n,r=Array.from(e.children).reverse(),o=Array.from(e.querySelectorAll(":checked")).reverse();try{for(var i=__values(o),l=i.next();!l.done;l=i.next()){var a=l.value;if(0===r.indexOf(a)&&null===a.nextElementSibling)break;e.insertBefore(a,a.nextElementSibling.nextElementSibling)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}},e.removeOption=function(e,t){Array.from(e.querySelectorAll(":checked")).forEach(function(n){var r=t.querySelector('option[value="'+n.value+'"]');r.classList.remove("hidden"),r.disabled=!1,e.removeChild(n)})},e}();t.AbstractSortableSelectItems=i});