[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 /** 2 * @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org> 3 * @license GNU General Public License version 2 or later; see LICENSE.txt 4 */ 5 (Joomla => { 6 7 Joomla.submitbutton = (task, type) => { 8 if (task === 'item.setType' || task === 'item.setMenuType') { 9 if (task === 'item.setType') { 10 const list = [].slice.call(document.querySelectorAll('#item-form input[name="jform[type]"]')); 11 list.forEach(item => { 12 item.value = type; 13 }); 14 document.getElementById('fieldtype').value = 'type'; 15 } else { 16 const list = [].slice.call(document.querySelectorAll('#item-form input[name="jform[menutype]"]')); 17 list.forEach(item => { 18 item.value = type; 19 }); 20 } 21 22 Joomla.submitform('item.setType', document.getElementById('item-form')); 23 } else if (task === 'item.cancel' || document.formvalidator.isValid(document.getElementById('item-form'))) { 24 Joomla.submitform(task, document.getElementById('item-form')); 25 } else { 26 // special case for modal popups validation response 27 const list = [].slice.call(document.querySelectorAll('#item-form .modal-value.invalid')); 28 list.forEach(field => { 29 const idReversed = field.getAttribute('id').split('').reverse().join(''); 30 const separatorLocation = idReversed.indexOf('_'); 31 const nameId = `$idReversed.substr(separatorLocation).split('').reverse().join('')}name`; 32 document.getElementById(nameId).classList.add('invalid'); 33 }); 34 } 35 }; 36 37 const onChange = ({ 38 target 39 }) => { 40 const menuType = target.value; 41 Joomla.request({ 42 url: `index.php?option=com_menus&task=item.getParentItem&menutype=$menuType}`, 43 headers: { 44 'Content-Type': 'application/json' 45 }, 46 47 onSuccess(response) { 48 const data = JSON.parse(response); 49 const list = [].slice.call(document.querySelectorAll('#jform_parent_id option')); 50 list.forEach(item => { 51 if (item.value !== '1') { 52 item.parentNode.removeChild(item); 53 } 54 }); 55 data.forEach(value => { 56 const option = document.createElement('option'); 57 option.innerText = value.title; 58 option.id = value.id; 59 document.getElementById('jform_parent_id').appendChild(option); 60 }); 61 const newEvent = document.createEvent('HTMLEvents'); 62 newEvent.initEvent('change', true, false); 63 document.getElementById('jform_parent_id').dispatchEvent(newEvent); 64 }, 65 66 onError: xhr => { 67 Joomla.renderMessages(Joomla.ajaxErrorsMessages(xhr)); 68 } 69 }); 70 }; 71 72 if (!Joomla || typeof Joomla.request !== 'function') { 73 throw new Error('core.js was not properly initialised'); 74 } 75 76 const element = document.getElementById('jform_menutype'); 77 78 if (element) { 79 element.addEventListener('change', onChange); 80 } // Menu type Login Form specific 81 82 83 document.getElementById('item-form').addEventListener('submit', () => { 84 if (document.getElementById('jform_params_login_redirect_url') && document.getElementById('jform_params_logout_redirect_url')) { 85 // Login 86 if (!document.getElementById('jform_params_login_redirect_url').closest('.control-group').classList.contains('hidden')) { 87 document.getElementById('jform_params_login_redirect_menuitem_id').value = ''; 88 } 89 90 if (!document.getElementById('jform_params_login_redirect_menuitem_name').closest('.control-group').classList.contains('hidden')) { 91 document.getElementById('jform_params_login_redirect_url').value = ''; 92 } // Logout 93 94 95 if (!document.getElementById('jform_params_logout_redirect_url').closest('.control-group').classList.contains('hidden')) { 96 document.getElementById('jform_params_logout_redirect_menuitem_id').value = ''; 97 } 98 99 if (!document.getElementById('jform_params_logout_redirect_menuitem_id').closest('.control-group').classList.contains('hidden')) { 100 document.getElementById('jform_params_logout_redirect_url').value = ''; 101 } 102 } 103 }); 104 })(Joomla);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |