Source: widgets/optional-database-widget.js

define([
    'settings/js/widgets/database-widget',
    'settings/js/controls/enable-view'
], function (DatabaseWidget, EnableView) {
    return DatabaseWidget.extend({
        initialize: function (options) {
            DatabaseWidget.prototype.initialize.call(this, options);
            this.enableView = new EnableView({enableIcon: 'icon-file', strings: this.strings});
        },

        render: function () {
            DatabaseWidget.prototype.render.call(this);
            this.enableView.render();
            this.$validateButtonParent.before(this.enableView.$el);
        },

        getConfig: function () {
            var datasourceConfig = DatabaseWidget.prototype.getConfig.call(this);
            return {
                datasource: datasourceConfig,
                enabled: this.enableView.getConfig()
            };
        },

        /**
         * @returns {boolean} True if the database is enabled; false otherwise
         */
        shouldValidate: function() {
            return this.enableView.getConfig();
        },

        updateConfig: function(config) {
            this.enableView.updateConfig(config.enabled);
            if (config.enabled) {
                DatabaseWidget.prototype.updateConfig.call(this, config.datasource);
            }
        },

        validateInputs: function () {
            var isValid = true;

            if (this.shouldValidate()) {
                var config = this.getConfig();
                isValid = this.validateDatasourceConfig(config.datasource);
            }

            return isValid;
        }
    });
});
Copyright 2013--2018 Micro Focus International plc. Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
Documentation generated by JSDoc 3.4.3 on Fri Jun 22nd 14:40 2018 using the DocStrap template.