<%!
    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
%>

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

<script language="JavaScript">
    $(function() {
        $('#upgradeform').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>

<%
    implicit_id_required = splunk.util.normalizeBoolean(state.get('implicit_id_required', None))
    appText = 'add-on' if util.isLite() else 'app'
%>
<div class="spl-gdi-wrapper spl-prompt-message-layout"> 
	<div class="jmFormOptions">
	    <h2 class="spl-page-hdr spl-icon-attention-md" > 
	        <span> 
	            <!-- replace with page title --> 
	            ${_('%s update available' % appText.capitalize())}
	            <!-- end replace with page title --> 
	        </span> 
	    </h2> 
	    <span class="spl-hr-solid-lite"></span> 
	    <!-- start prompt message --> 
	    <form id="upgradeform" method="POST" action="${make_url(['/manager/appinstall', appid, 'update'], _qs=dict(state=state) )}">
	    <input type="hidden" name="state" value="${state.serialize()}">
        ${csrf_hidden_input()}
	    <div class="spl-prompt-message-wrapper"> 
	        <h3 class="spl-main-description-hdr"> 
	            % if implicit_id_required:
	            ${_('Overwrite from SplunkApps')}
	            % else:
	            ${_('Update from SplunkApps')}
	            % endif
	        </h3> 
	        <p class="spl-main-description"> 
	            % if not implicit_id_required:
	            ${_('Your %(appText)s does not have a valid %(appText)s ID and may not have originated from SplunkApps. Be sure to first back up your configuration as this operation is irreversible.' % dict(appText=appText))}<br><br>
	            ${_('Click the button below if you are sure you would like to overwrite the local copy of this %(appText)s with the newest version on SplunkApps.' % dict(appText=appText))}<br>
	            % else:
	            ${_('The requested %(appText)s is already installed, but a newer version is available on SplunkApps.' % dict(appText=appText))}<br><br>
	            ${_('Click the button below to update the %(appText)s to the newer version now.' % dict(appText=appText))}<br>
	            % endif
	           ${_('Note that a restart of Splunk may be required after update.')}
	        </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 class="splButton-secondary">
            <span>${_('Cancel')}</span> 
        </button> 
        <button class="splButton-primary disabled" type="submit"> 
            % if implicit_id_required:
            <span>${_('Overwrite')}</span> 
            % else:
            <span>${_('Update')}</span> 
            % endif
        </button> 
    </div> 
    </form>
</div> 

