Members-Manager/media/js/type.js

112 lines
3.3 KiB
JavaScript
Raw Normal View History

2022-03-03 02:58:38 +00:00
/**
* @package Joomla.Members.Manager
*
* @created 6th July, 2018
* @author Llewellyn van der Merwe <https://www.joomlacomponentbuilder.com/>
* @github Joomla Members Manager <https://github.com/vdm-io/Joomla-Members-Manager>
* @copyright Copyright (C) 2015. All Rights Reserved
* @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
*/
2018-12-27 10:38:37 +00:00
// Some Global Values
2021-01-06 14:00:15 +00:00
jform_vvvvvvyvvy_required = false;
2018-12-27 10:38:37 +00:00
// Initial Script
jQuery(document).ready(function()
{
var add_relationship_vvvvvvy = jQuery("#jform_add_relationship input[type='radio']:checked").val();
vvvvvvy(add_relationship_vvvvvvy);
});
// the vvvvvvy function
function vvvvvvy(add_relationship_vvvvvvy)
{
// set the function logic
if (add_relationship_vvvvvvy == 1)
{
jQuery('#jform_communicate').closest('.control-group').show();
jQuery('#jform_field_type').closest('.control-group').show();
// add required attribute to field_type field
2021-01-06 14:00:15 +00:00
if (jform_vvvvvvyvvy_required)
2018-12-27 10:38:37 +00:00
{
updateFieldRequired('field_type',0);
jQuery('#jform_field_type').prop('required','required');
jQuery('#jform_field_type').attr('aria-required',true);
jQuery('#jform_field_type').addClass('required');
2021-01-06 14:00:15 +00:00
jform_vvvvvvyvvy_required = false;
2018-12-27 10:38:37 +00:00
}
jQuery('#jform_edit_relationship').closest('.control-group').show();
jQuery('#jform_type').closest('.control-group').show();
jQuery('#jform_view_relationship').closest('.control-group').show();
}
else
{
jQuery('#jform_communicate').closest('.control-group').hide();
jQuery('#jform_field_type').closest('.control-group').hide();
// remove required attribute from field_type field
2021-01-06 14:00:15 +00:00
if (!jform_vvvvvvyvvy_required)
2018-12-27 10:38:37 +00:00
{
updateFieldRequired('field_type',1);
jQuery('#jform_field_type').removeAttr('required');
jQuery('#jform_field_type').removeAttr('aria-required');
jQuery('#jform_field_type').removeClass('required');
2021-01-06 14:00:15 +00:00
jform_vvvvvvyvvy_required = true;
2018-12-27 10:38:37 +00:00
}
jQuery('#jform_edit_relationship').closest('.control-group').hide();
jQuery('#jform_type').closest('.control-group').hide();
jQuery('#jform_view_relationship').closest('.control-group').hide();
}
}
2021-01-06 14:00:15 +00:00
// update fields required
function updateFieldRequired(name, status) {
// check if not_required exist
if (jQuery('#jform_not_required').length > 0) {
var not_required = jQuery('#jform_not_required').val().split(",");
2018-12-27 10:38:37 +00:00
2021-01-06 14:00:15 +00:00
if(status == 1)
2018-12-27 10:38:37 +00:00
{
2021-01-06 14:00:15 +00:00
not_required.push(name);
2018-12-27 10:38:37 +00:00
}
else
{
2021-01-06 14:00:15 +00:00
not_required = removeFieldFromNotRequired(not_required, name);
2018-12-27 10:38:37 +00:00
}
2021-01-06 14:00:15 +00:00
jQuery('#jform_not_required').val(fixNotRequiredArray(not_required).toString());
2018-12-27 10:38:37 +00:00
}
2021-01-06 14:00:15 +00:00
}
// remove field from not_required
function removeFieldFromNotRequired(array, what) {
return array.filter(function(element){
return element !== what;
});
}
// fix not required array
function fixNotRequiredArray(array) {
var seen = {};
return removeEmptyFromNotRequiredArray(array).filter(function(item) {
return seen.hasOwnProperty(item) ? false : (seen[item] = true);
});
}
2018-12-27 10:38:37 +00:00
2021-01-06 14:00:15 +00:00
// remove empty from not_required array
function removeEmptyFromNotRequiredArray(array) {
return array.filter(function (el) {
// remove ( 一_一) as well - lol
return (el.length > 0 && '一_一' !== el);
});
2018-12-27 10:38:37 +00:00
}
// the isSet function
function isSet(val)
{
if ((val != undefined) && (val != null) && 0 !== val.length){
return true;
}
return false;
2022-03-03 02:58:38 +00:00
}