Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

config_generate_AutoSaveConfigOption_function()

Description

Generate Javascript function used for auto saving individual config options

Parameters

ColumnTypeDefaultDescription
$post_url string URL to where the data will be posted

Location

include/config_functions.php lines 906 to 960

Definition

 
function config_generate_AutoSaveConfigOption_function($post_url)
    {
    global 
$lang;
    
?>
    
    <script>
    function AutoSaveConfigOption(option_name)
        {
        jQuery('#AutoSaveStatus-' + option_name).html(' echo $lang["saving"]; ?>');
        jQuery('#AutoSaveStatus-' + option_name).show();

        if (jQuery('input[name=' + option_name + ']').is(':checkbox')) {
            var option_value = jQuery('input[name=' + option_name + ']:checked').map(function(){
            return jQuery(this).val();
          }).get().toString();
        
        }
        
        else {
            var option_value = jQuery('#' + option_name).val();
        }
        
        var post_url  = ' echo $post_url?>';
        var post_data = {
            ajax: true,
            autosave: true,
            autosave_option_name: option_name,
            autosave_option_value: option_value,
             echo generateAjaxToken($post_url); ?>
        };

        jQuery.post(post_url, post_data, function(response) {

            if(response.success === true)
                {
                jQuery('#AutoSaveStatus-' + option_name).html(' echo $lang["saved"]; ?>');
                jQuery('#AutoSaveStatus-' + option_name).fadeOut('slow');
                }
            else if(response.success === false && response.message && response.message.length > 0)
                {
                jQuery('#AutoSaveStatus-' + option_name).html(' echo $lang["save-error"]; ?> ' + response.message);
                }
            else
                {
                jQuery('#AutoSaveStatus-' + option_name).html(' echo $lang["save-error"]; ?>');
                }

        }, 'json');

        return true;
        }
    </script>
    
    
    
}

This article was last updated 23rd November 2020 19:35 Europe/London time based on the source file dated 6th October 2020 10:25 Europe/London time.