mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 04:13:31 +00:00
176 lines
4.1 KiB
HTML
176 lines
4.1 KiB
HTML
<script type="text/javascript">
|
|
//<![CDATA[
|
|
var msgInfo;
|
|
|
|
var tokenStr = '<%=token%>';
|
|
var clickToDownloadText = '<%:Click to update%>';
|
|
var inProgressText = '<%:Updating...%>';
|
|
var downloadInProgressNotice = '<%:Updating, are you sure to close?%>';
|
|
var downloadSuccessText = '<%:Update successful%>';
|
|
var unexpectedErrorText = '<%:Unexpected error%>';
|
|
var downloadingText = '<%:Downloading...%>';
|
|
var decompressioningText = '<%:Unpacking...%>';
|
|
var movingText = '<%:Moving...%>';
|
|
var latestVersionText = '<%:The latest version:%>';
|
|
|
|
function addPageNotice() {
|
|
window.onbeforeunload = function (e) {
|
|
e.returnValue = downloadInProgressNotice;
|
|
return downloadInProgressNotice;
|
|
};
|
|
}
|
|
|
|
function removePageNotice() {
|
|
window.onbeforeunload = undefined;
|
|
}
|
|
|
|
function onUpdateSuccess(btn) {
|
|
alert(downloadSuccessText);
|
|
|
|
if (btn) {
|
|
btn.value = downloadSuccessText;
|
|
btn.placeholder = downloadSuccessText;
|
|
btn.disabled = true;
|
|
}
|
|
|
|
window.setTimeout(function () {
|
|
window.location.reload();
|
|
}, 1000);
|
|
}
|
|
|
|
function onRequestError(btn, errorMessage) {
|
|
btn.disabled = false;
|
|
btn.value = btn.placeholder;
|
|
|
|
if (errorMessage) {
|
|
alert(errorMessage);
|
|
}
|
|
}
|
|
|
|
function doAjaxGet(url, data, onResult) {
|
|
new XHR().get(url, data, function (_, json) {
|
|
var resultJson = json || {
|
|
'code': 1,
|
|
'error': unexpectedErrorText
|
|
};
|
|
|
|
if (typeof onResult === 'function') {
|
|
onResult(resultJson);
|
|
}
|
|
})
|
|
}
|
|
|
|
function downloadClick(btn) {
|
|
if (msgInfo === undefined) {
|
|
checkUpdate(btn);
|
|
} else {
|
|
doDownload(btn);
|
|
}
|
|
}
|
|
|
|
function checkUpdate(btn) {
|
|
var text = btn.value;
|
|
btn.disabled = true;
|
|
btn.value = inProgressText;
|
|
|
|
addPageNotice();
|
|
|
|
var ckeckDetailElm = document.getElementById(btn.id + '-detail');
|
|
|
|
doAjaxGet('<%=url([[admin]], [[nas]], [[kodexplorer]], [[check]])%>', {
|
|
token: tokenStr
|
|
}, function (json) {
|
|
removePageNotice();
|
|
if (json.code && json.data.server) {
|
|
var server = json.data.server;
|
|
eval('Info = json');
|
|
btn.disabled = false;
|
|
btn.value = clickToDownloadText;
|
|
btn.placeholder = clickToDownloadText;
|
|
if (ckeckDetailElm) {
|
|
var urlNode = '';
|
|
if (server.version) {
|
|
urlNode = '<em style="color:red;">' + latestVersionText + server.version + '</em>';
|
|
var html_url = 'https://kodcloud.com/download/';
|
|
if (html_url) {
|
|
urlNode = '<a href="' + html_url + '" target="_blank">' + urlNode + '</a>';
|
|
}
|
|
}
|
|
ckeckDetailElm.innerHTML = urlNode;
|
|
}
|
|
msgInfo = server;
|
|
} else {
|
|
removePageNotice();
|
|
btn.disabled = false;
|
|
btn.value = text;
|
|
alert(unexpectedErrorText);
|
|
}
|
|
});
|
|
}
|
|
|
|
function doDownload(btn) {
|
|
btn.disabled = true;
|
|
btn.value = downloadingText;
|
|
|
|
addPageNotice();
|
|
|
|
var UpdateUrl = '<%=url([[admin]], [[nas]], [[kodexplorer]], [[download]])%>';
|
|
// Download file
|
|
doAjaxGet(UpdateUrl, {
|
|
token: tokenStr,
|
|
url: msgInfo ? msgInfo.link : ''
|
|
}, function (json) {
|
|
if (json.code) {
|
|
removePageNotice();
|
|
onRequestError(btn, json.error);
|
|
} else {
|
|
btn.value = decompressioningText;
|
|
|
|
// Extract file
|
|
doAjaxGet(UpdateUrl, {
|
|
token: tokenStr,
|
|
task: 'extract',
|
|
file: json.file
|
|
}, function (json) {
|
|
if (json.code) {
|
|
removePageNotice();
|
|
onRequestError(btn, json.error);
|
|
} else {
|
|
btn.value = movingText;
|
|
|
|
// Move file to target dir
|
|
doAjaxGet(UpdateUrl, {
|
|
token: tokenStr,
|
|
task: 'move',
|
|
file: json.file
|
|
}, function (json) {
|
|
removePageNotice();
|
|
if (json.code) {
|
|
onRequestError(btn, json.error);
|
|
} else {
|
|
onUpdateSuccess(btn);
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
//]]>
|
|
</script>
|
|
|
|
<%+cbi/valueheader%>
|
|
<% if self:cfgvalue(section) ~= false then %>
|
|
<input class="cbi-button cbi-input-<%=self.inputstyle or "button" %>" type="button"<%=
|
|
attr("name", cbid) ..
|
|
attr("id", self.id or cbid) ..
|
|
attr("value", self.inputtitle or self.title) ..
|
|
ifattr(self.btnclick, "onclick", self.btnclick) ..
|
|
ifattr(self.placeholder, "placeholder")
|
|
%> />
|
|
<span id="<%=self.id or cbid%>-detail"></span>
|
|
<% else %>
|
|
-
|
|
<% end %>
|
|
<%+cbi/valuefooter%>
|