<%+cbi/valueheader%>
<label class="cbi-value-title"><%= translate("Update the core") %></label>
<div class="cbi-value-field">
    <input class="btn cbi-button cbi-button-reload" id="update" type="button" size="0" onclick="check_version()" value="<%:Collecting data...%>" />
    <div class="cbi-value-description">
	<span class="cbi-value-helpicon"><img src="/luci-static/resources/cbi/help.gif" alt="帮助"></span>
	<%:If repeated failures occur, you can download the binaries for the corresponding schemas at the following url.%>
	</br>&nbsp;&nbsp;&nbsp;&nbsp;
	<%:https://github.com/ochinchina/supervisord/releases%>
	</br>&nbsp;&nbsp;&nbsp;&nbsp;
	<%:Unpack the package and place it in the top path.%>
	</br>&nbsp;&nbsp;&nbsp;&nbsp;
	<%:The author binary version number may not have changed.%>
	</br>&nbsp;&nbsp;&nbsp;&nbsp;
	<%:If you successfully update, the refresh page is still lower than the latest version.%>
	</br>&nbsp;&nbsp;&nbsp;&nbsp;
	<%:This is normal.%>
	</div>
</div>
<script type="text/javascript">
function getver() {
    XHR.get('<%=url([[admin]], [[services]], [[supervisord]], [[getver]])%>', null,
    	function(x, data) {
            const tb = document.getElementById('update');
            if (data && tb) {
                if (data.newver) {
                    tb.value = '<%:Local version is %>' + data.nowver + '<%:, New version is %>' + data.newver;
                    tb.setAttribute('newver', data.newver); 
                }else{
                    tb.value = '<%:The check failed. Please try again%>';
                }
            }
        }
    );
}
getver()
function check_version() {
    const tb = document.getElementById('update');
    const newver= tb.getAttribute("newver")
    if (newver){
        tb.disabled = true;
        XHR.get('<%=url([[admin]], [[services]], [[supervisord]], [[update]])%>', {version: newver}, (x, r) => {
            if (r.error == 0) {
                tb.disabled = false;
                tb.value = '<%:Local version is %>' + newver + '<%:, New version is %>' + newver;
            } else {
                tb.disabled = false;
                tb.value = '<%:The update failed. Please try again%>';
            }
        });
    }else{
        getver()
    }
}
</script>
<%+cbi/valuefooter%>