<div id="jdisc-module-config">
    <h3 class="p5 bg-neutral-200 border-top border-bottom mt10">[{isys type='lang' ident='LC__MODULE__JDISC__CONFIGURATION__COMMON_SETTINGS'}]</h3>
    [{isys type='f_text' p_bInvisible=1 name='C__MODULE__JDISC__CONFIGURATION__ID'}]

    <table class="contentTable" style="border-top: none;">
        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__DEFAULT_SERVER' ident='LC__MODULE__JDISC__CONFIGURATION__DEFAULT_SERVER'}]</td>
            <td class="value">[{isys type='f_dialog' name='C__MODULE__JDISC__CONFIGURATION__DEFAULT_SERVER' p_bDbFieldNN="1"}]</td>
        </tr>
        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__TITLE' ident='LC__MODULE__JDISC__CONFIGURATION__TITLE'}]</td>
            <td class="value">[{isys type='f_text' name='C__MODULE__JDISC__CONFIGURATION__TITLE'}]</td>
        </tr>

        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__HOST' ident='LC__MODULE__JDISC__CONFIGURATION__HOST'}]</td>
            <td class="value">[{isys type='f_text' name='C__MODULE__JDISC__CONFIGURATION__HOST'}]</td>
        </tr>
        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__PORT' ident='LC__MODULE__JDISC__CONFIGURATION__PORT'}]</td>
            <td class="value">[{isys type='f_text' name='C__MODULE__JDISC__CONFIGURATION__PORT'}]</td>
        </tr>
        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__DATABASE' ident='LC__MODULE__JDISC__CONFIGURATION__DATABASE'}]</td>
            <td class="value">[{isys type='f_text' name='C__MODULE__JDISC__CONFIGURATION__DATABASE'}]</td>
        </tr>
        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__USERNAME' ident='LC__MODULE__JDISC__CONFIGURATION__USERNAME'}]</td>
            <td class="value">[{isys type='f_text' name='C__MODULE__JDISC__CONFIGURATION__USERNAME'}]</td>
        </tr>
        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__PASSWORD' ident='LC__MODULE__JDISC__CONFIGURATION__PASSWORD'}]</td>
            <td class="value">[{isys type='f_password' name='C__MODULE__JDISC__CONFIGURATION__PASSWORD'}]</td>
        </tr>

        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__VERSION_CHECK' ident='LC__MODULE__JDISC__CONFIGURATION__ALLOW_IMPORT_OLDER_VERSION'}]</td>
            <td class="value">[{isys type='f_dialog' name='C__MODULE__JDISC__CONFIGURATION__VERSION_CHECK' p_bDbFieldNN="1"}]</td>
        </tr>

        [{if !isys_glob_is_edit_mode()}]
        <tr>
            <td class="key">
                <button type="button" class="btn fr" id="check_button">
                    <img src="[{$dir_images}]axialis/database/server-database.svg" /><span>[{isys type="lang" ident="LC__MODULE__JDISC__CONNECTION_CHECK"}]</span>
                </button>
            </td>
            <td>
                <p id="connection_result" class="p5 ml20 mr5 hide"></p>
            </td>
        </tr>
        [{/if}]
    </table>

    <h3 class="p5 bg-neutral-200 border-top border-bottom mt10">[{isys type='lang' ident='LC__MODULE__JDISC__CONFIGURATION__DISCOVERY_SETTINGS'}]</h3>
    <table class="contentTable" style="border-top: none;">
        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__DISCOVERY_USERNAME' ident='LC__MODULE__JDISC__CONFIGURATION__USERNAME'}]</td>
            <td class="value">[{isys type='f_text' name='C__MODULE__JDISC__CONFIGURATION__DISCOVERY_USERNAME'}]</td>
        </tr>
        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__DISCOVERY_PASSWORD' ident='LC__MODULE__JDISC__CONFIGURATION__PASSWORD'}]</td>
            <td class="value">[{isys type='f_password' name='C__MODULE__JDISC__CONFIGURATION__DISCOVERY_PASSWORD'}]</td>
        </tr>
        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__DISCOVERY_PORT' ident='LC__MODULE__JDISC__CONFIGURATION__PORT'}]</td>
            <td class="value">[{isys type='f_text' name='C__MODULE__JDISC__CONFIGURATION__DISCOVERY_PORT'}]</td>
        </tr>
        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__DISCOVERY_PROTOCOL' ident='LC__CATD__PROTOCOL'}]</td>
            <td class="value">[{isys type='f_text' name='C__MODULE__JDISC__CONFIGURATION__DISCOVERY_PROTOCOL'}]</td>
        </tr>

        [{if !isys_glob_is_edit_mode()}]
        <tr>
            <td class="key">
                <button type="button" class="btn fr" id="check_button_discovery">
                    <img src="[{$dir_images}]axialis/database/server-database.svg" /><span>[{isys type="lang" ident="LC__MODULE__JDISC__CONNECTION_CHECK"}]</span>
                </button>
            </td>
            <td>
                <p id="connection_result_discovery" class="p5 ml20 mr5 hide"></p>
            </td>
        </tr>
        [{/if}]

    </table>

    <h3 class="p5 bg-neutral-200 border-top border-bottom mt10">[{isys type='lang' ident='LC__MODULE__JDISC__CONFIGURATION__DISCOVERY_CATEGORY_SETTINGS'}]</h3>
    <table class="contentTable" style="border-top: none;">
        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__DISCOVERY_TIMEOUT' description='LC__MODULE__JDISC__CONFIGURATION__DISCOVERY_TIMEOUT_DESCRIPTION' ident='LC__MODULE__JDISC__CONFIGURATION__DISCOVERY_TIMEOUT'}]</td>
            <td class="value">[{isys type='f_text' name='C__MODULE__JDISC__CONFIGURATION__DISCOVERY_TIMEOUT'}]</td>
        </tr>
        <tr>
            <td class="key">[{isys type='f_label' name='C__MODULE__JDISC__CONFIGURATION__DISCOVERY_IMPORT_RETRIES' description='LC__MODULE__JDISC__CONFIGURATION__DISCOVERY_IMPORT_RETRIES_DESCRIPTION' ident='LC__MODULE__JDISC__CONFIGURATION__DISCOVERY_IMPORT_RETRIES'}]</td>
            <td class="value">[{isys type='f_text' name='C__MODULE__JDISC__CONFIGURATION__DISCOVERY_IMPORT_RETRIES'}]</td>
        </tr>
    </table>

    [{if !isys_glob_is_edit_mode()}]
    <script type="text/javascript">

        [{if $jdisc_id}]
        document.isys_form.id.value = '[{$jdisc_id}]';
        [{/if}]

        var $checkButton = $('check_button'),
            $checkButtonDiscovery = $('check_button_discovery');

        $checkButton.on('click', function () {
            $checkButton
                .disable()
                .update(new Element('img', { src: window.dir_images + 'axialis/user-interface/loading.svg', className: 'animation-rotate' }))
                .insert(new Element('span').update('[{isys type="lang" ident="LC__UNIVERSAL__LOADING"}]'));

            new Ajax.Request('?call=jdisc&ajax=1&func=check_connection', {
                method: "post",
                parameters: {
                    'jdisc_server': '[{$jdisc_id}]'
                },
                onComplete: function (transport) {
                    var json = transport.responseJSON,
                        $result = $('connection_result')
                            .removeClassName('box-green')
                            .removeClassName('box-red')
                            .removeClassName('hide')
                            .update(json.message);

                    $checkButton
                        .enable()
                        .update(new Element('img', { src: window.dir_images + 'axialis/database/server-database.svg' }))
                        .insert(new Element('span').update('[{isys type="lang" ident="LC__MODULE__JDISC__CONNECTION_CHECK"}]'));

                    if (json.connection) {
                        $result.addClassName('box-green');
                    } else {
                        $result.addClassName('box-red');
                    }
                }.bind(this)
            });
        });

        $checkButtonDiscovery.on('click', function () {
            $checkButtonDiscovery
                .disable()
                .update(new Element('img', { src: window.dir_images + 'axialis/user-interface/loading.svg', className: 'animation-rotate' }))
                .insert(new Element('span').update('[{isys type="lang" ident="LC__UNIVERSAL__LOADING"}]'));

            new Ajax.Request('?call=jdisc&ajax=1&func=check_connection_discovery', {
                method: "post",
                parameters: {
                    'jdisc_server': '[{$jdisc_id}]'
                },
                onSuccess: function (transport) {
                    var json = transport.responseJSON,
                        $result = $('connection_result_discovery')
                            .removeClassName('box-green')
                            .removeClassName('box-red')
                            .removeClassName('hide')
                            .update(json.message);

                    if (json.success) {
                        $result.addClassName('box-green');
                    } else {
                        $result.addClassName('box-red');
                    }

                    $checkButtonDiscovery
                        .enable()
                        .update(new Element('img', { src: window.dir_images + 'axialis/database/server-database.svg' }))
                        .insert(new Element('span').update('[{isys type="lang" ident="LC__MODULE__JDISC__CONNECTION_CHECK"}]'));
                }.bind(this)
            });
        });

    </script>
    [{/if}]
</div>
