HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/RMourik/bassol.nl/wwwroot/CMSScripts/CMSModules/CMS/SettingsKeyTypeConfirmation.js
/** 
 * Module for the Settings key edit control which handles change of the type and show the confirmation message.
 * 
 * Module attributes
 * @param {string} parameters.saveActionClass - CSS class of the OK button. Button that shows the confirmation message and saves the form
 * @param {string} parameters.keyTypeID - ID of the dropdown that holds the key types
 * @param {string} parameters.confirmMessage - Confirmation message to show
 * @param {string} parameters.initialKeyType - Initial key type
 */
cmsdefine(['jQuery'], function ($) {

    var SettingsKeyTypeConfirmation = function (parameters) {
        var that = this;
        this.parameters = parameters;
        this.saveActionButton = $('.' + parameters.saveActionClass);
        this.keyTypeInitialValue = parameters.initialKeyType;
        this.confirmMessage = parameters.confirmMessage;
        this.clickAction = this.saveActionButton.attr('onclick');

        $(function() {
            that.checkKeyTypeDropdownValue();
        });

        $('body').on('change', '#' + parameters.keyTypeID, function () {
            that.checkKeyTypeDropdownValue();
        });
    };

    SettingsKeyTypeConfirmation.prototype.checkKeyTypeDropdownValue = function() {
        if ($('#' + this.parameters.keyTypeID).val() !== this.keyTypeInitialValue) {
            this.saveActionButton.attr('onclick', "if (!confirm('" + this.confirmMessage + "')) { return false; }" + this.clickAction);
        } else {
            this.saveActionButton.attr('onclick', this.clickAction);
        }
    };

    return SettingsKeyTypeConfirmation;
});