<%inherit file="//layout/admin_lite_dialog.html"/>
<%namespace name="lib" file="//lib.html" />
<%namespace name="formset" file="//formset.html" />

<%def name="title()">${_('Change master association')} - ${parent.title()}</%def>
<%def name="get_breadcrumbs()">
    <%
        return [
            [_('Manager'), ['manager']],
            [_('Licensing'), ['manager','system','licensing']],
            [_('Change master association'), None]
        ]
    %>
</%def>

% if controller_exception:
    <div class="error">
        <%lib:render_exception e="${controller_exception}" />
    </div>
% endif


% if is_success:

    <div class="message_block_success"><span class="message_block_success_text">${_('Change successful')}</span></div>
    <p>${_('The master server was successfully changed.')}</p>

% else:

    <h1>${_('Change master association')}</h1>

    % if is_own_master:
        <p>
        ${_('This server, <strong>%s</strong>, is currently acting as a master license server.') % h(local_slave_name)}
        </p>
    % else:
        <p>
        ${_('This server <strong>%(slave)s</strong> is currently associated with the master license server located at: <strong>%(master)s</strong>.') % dict(slave=h(local_slave_name), master=h(master_server_uri))}
        </p>
    % endif

    <table>
        <tr>
            <td>
                <input type="radio" id="ms0" name="formset_master_server_mode" value="this_server" ${'checked="checked"' if master_server_mode == 'this_server' else ''} />
            </td>
            <td>
                <label for="ms0">${_('Designate this Splunk instance, <strong>%s</strong>, as the master license server') % h(local_slave_name)}</label><br />
                <p>${_('Choosing this option will:')}</p>
                <ul>
                    <li>${_('Point the local indexer at the local master license server')}</li>
                    <li>${_('Disconnect the local indexer from any remote license server')}</li>
                </ul>
            </td>
        </tr>
        <tr>
            <td>
                <input type="radio" id="ms1" name="formset_master_server_mode" value="other_server" ${'checked="checked"' if master_server_mode == 'other_server' else ''} />
            </td>
            <td>
                <label for="ms1">${_('Designate a different Splunk instance as the master license server')}</label><br />
                <p>${_('Choosing this option will:')}</p>
                <ul>
                    <li>${_('Deactivate the local master license server')}</li>
                    <li>${_('Point the local indexer at license server specified below')}</li>
                    <li>${_('Discontinue license services to remote indexers currently pointing to this server')}</li>
                </ul>
                <div id="master_entry" style="display:none">
                    <label for="master_server">${_('Master license server URI')}</label><br />
                    ${formset.textbox(name="master_server_uri", value=master_server_uri, id="master_server")}<br />
                    <span class="footnote"><strong>${_('For example: ')}</strong> https://splunk_license_server:8089<br/>${_('Use https and specify the management port.')}</span>
                </div>
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        // enable the hide/show of the optional 'other server' entry box
        function update_self_display() {
            if ($('input[name="formset_master_server_mode"]:checked').val() == 'other_server') {
                $('#master_entry').show();
                $('input', '#master_entry').focus();
            } else {
                $('#master_entry').hide();
            }
        }
        $('input[name="formset_master_server_mode"]').bind('click', update_self_display);
        $(update_self_display());
    </script>
            

% endif


##
## buttons
##

<%def name="gutter()">
    <div class="admin-dialog-tray">
    % if is_success:
        % if requires_restart:
            <%
            qs = {'auto_restart':'1'}
            %>        
            ${formset.button(_('Restart Later'), href=return_to)}
            ${formset.button(_('Restart Now'), is_primary=True, href=make_url(['manager','search','control'], _qs=qs) )}
        % else:
            ${formset.button(_('OK'), is_primary=True, href=return_to)}
        % endif
    % else:
        ${formset.button(_('Cancel'), href=return_to)}
        ${formset.button(_('Save'), is_primary=True, is_submit=True)}
    % endif
    </div>
</%def>
