Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 1097 to 1155

Definition

 
function config_generate_AutoSaveConfigOption_function($post_url)
    {
    global 
$lang;
    
?>
    
    <script>
    function AutoSaveConfigOption(option_name, reload_page = false)
        {
        jQuery('#AutoSaveStatus-' + option_name).html(' echo escape($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 escape($lang["saved"]); ?>');
                jQuery('#AutoSaveStatus-' + option_name).fadeOut('slow');
                if (reload_page)
                    {
                    location.reload();
                    }
                }
            else if(response.success === false && response.message && response.message.length > 0)
                {
                jQuery('#AutoSaveStatus-' + option_name).html(" echo escape($lang['save-error']); ?> " + response.message);
                }
            else
                {
                jQuery('#AutoSaveStatus-' + option_name).html(" echo escape($lang['save-error']); ?>");
                }

        }, 'json');

        return true;
        }
    </script>
    
    
    
}

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 13th November 2024 15:50 Europe/London time.