<%!
    title = 'App Install'
%>
<%namespace name="lib" file="//lib.html" import="*"/>
<%namespace name="helpers" file="//admin/_helpers.html"/>
<%inherit file="//layout/admin.html" />
<%
    import splunk
    from splunk.appserver.mrsparkle.lib import util, i18n
    appText = 'add-on' if util.isLite() else 'app'
%>

% if error:
    <%helpers:message content="${error}" level="error"/>
% endif


<script language="JavaScript">
    $(function() {
        $('#installform').submit(function() {
            if ($('button').hasClass('disabled')) {
                $('.spl-license-warn').show();
                return false;
            } else {
                $('button').attr('disabled', 'disabled');
                $('.splButton-primary').text(${_('Processing...')|jsonify});
                return true;
            }
        });
        $('.splButton-secondary').click(function() {
            window.location = ${jsonify(make_url(breadcrumbs[-2][1] if len(breadcrumbs)>1 else state['return_to']))};
            return false;
        });
    });
</script>
<script language="JavaScript">
    function acceptLicense(checkBox) {
        if ($(checkBox).is(':checked')) {
            $(checkBox).val(1);
            $('.splButton-primary').removeClass('disabled');
        } else {
            $(checkBox).val(0);
            $('.splButton-primary').addClass('disabled');
        }
    }
</script>

<div class="spl-gdi-wrapper spl-prompt-message-layout"> 
    <h2 class="spl-page-hdr spl-no-icon-no-padding" > 
        <span> ${_('Login required')} </span> 
    </h2> 

	<div class="jmFormOptions">
	    <!-- start prompt message --> 
	    <form id="installform" method="post" action="${make_url(['/manager/appinstall', appid, 'login'], _qs=dict(state=state) )}" autocomplete="off">
	    <input type="hidden" name="state" value="${state.serialize()|h}">
	    <input type="hidden" name="next" value="${next|h}">
        ${csrf_hidden_input()}
	    <div class="spl-prompt-message-wrapper"> 
	        <p class="spl-main-description spl-dotted-border-bottom"> 
	           ${_('Enter your <strong>Splunk.com</strong> username and password to download the %s' % appText)}<br/> 
	        </p> 
	        <div class="adminFormItem"> 
	            <label> 
	                ${_('Username')}
	            </label> 
	            <input type="text" value="" size="30" name="sbuser" /> 
	        </div> 
	        <div class="adminFormItem"> 
	            <label> 
	                ${_('Password')}
	            </label> 
	            <input type="password" value="" size="30" name="sbpass" /> 
	        </div> 
	        <p class="spl-main-description splunk-components"> 
	            <a href="https://www.splunk.com/page/lost_password" target="_blank">${_('Forgot your password?')}<span class="icon-external external"></span></a> 
	        </p> 
            % if (app_license_url != 'http://www.splunk.com/view/SP-CAAAAAH'):
            <p class="spl-main-description">
               ${_('This %(appText)s is provided by a third party and your rights to use the '
                '%(appText)s is in accordance with the license provided by that third-party licensor. '
                'Splunk is not responsible for any third-party %(appText)ss and does not provide any '
                'warranty or support. If you have any questions, complaints or claims with '
                'respect to this %(appText)s, please contact the licensor directly, whose contact '
                'information can be found on the download page.' % dict(appText=appText))}
            </p>
            % endif
            <p class="spl-main-description splunk-components">
               <a href="${app_license_url}" target="_blank">${app_license}<span class="icon-external external"></span></a>
            </p>
            <p class="spl-main-description splunk-components">
               <a href="${_('http://www.splunk.com/view/SP-CAAAAAH')}" target="_blank">${_('Splunk Websites Terms and Conditions of Use')}<span class="icon-external external"></span></a>
            </p>
            <p class="spl-main-description">
                <input type="checkbox" name="accept-license" value="0" id="accept-license" onclick="acceptLicense(this);"/>
                <label for="accept-license">${_('I have read the terms and conditions of the license and agree to be bound by them.')}</label>
                <p class="spl-license-warn">${_('Please accept the terms and conditions.')}</p>
            </p>
	    </div> 
	</div>
    
    <!-- Start button bar --> 
    <div class="jmFormActions"> 
        <button type="submit" class="splButton-primary disabled"> 
            <span>${_('Login')}</span> 
        </button> 
        % if state['return_to']:
            <button class="splButton-secondary">
                <span>${_('Cancel')}</span> 
            </button>         
        % endif        
    </div> 
    </form>
</div> 

