upload.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. function $(id) {return document.getElementById(id);}
  2. var timeout;
  3. document.onmousemove = function(){
  4. clearTimeout(timeout);
  5. timeout = setTimeout(function(){
  6. if (getCGI('goback.cgi?') === true) {
  7. $('count-wrap').style.display = 'block';
  8. $('countdown').style.display = 'block';
  9. countdown();
  10. }
  11. }, 1800000);
  12. };
  13. function countdown() {
  14. var countDown = 5;
  15. setInterval(function () {
  16. if (countDown == 1) {
  17. window.location.href = 'https:' + window.location.origin.substring(window.location.protocol.length);
  18. }
  19. if (countDown > 0){countDown--;}
  20. document.getElementById('count-number').innerHTML = countDown;
  21. return countDown;
  22. }, 1000);
  23. }
  24. function getCGI(url) {
  25. var q,a;
  26. if (url == 'goback.cgi') {
  27. q = confirm("Вы уверены что хотите вернуться в основной интерфейс?");
  28. a = "Возврат отменен.";
  29. } else {q = true;}
  30. if (q) {
  31. if (window.XMLHttpRequest) {
  32. xmlhttp = new XMLHttpRequest();
  33. } else {
  34. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  35. }
  36. // xmlhttp.onreadystatechange = true;
  37. xmlhttp.open("GET", url, true);
  38. xmlhttp.send();
  39. return true;
  40. } else {
  41. alert(a);
  42. }
  43. }
  44. var _validFileName = 'IBP.bin';
  45. function Validate(oForm) {
  46. var arrInputs = oForm.getElementsByTagName('input');
  47. for (var i = 0; i < arrInputs.length; i++) {
  48. var oInput = arrInputs[i];
  49. var blnValid = false;
  50. if (oInput.type == 'file') {
  51. if (oInput.files.length === 0) {
  52. alert('Путь к файлу не указан');
  53. blnValid = false;
  54. return false;
  55. }else{
  56. var sFileName = oInput.files[0].name;
  57. if (sFileName == _validFileName) {
  58. blnValid = true;
  59. $('goback').className += ' disabled';
  60. break;
  61. }
  62. if (!blnValid) {
  63. alert('Файл ' + sFileName + ' не валиден, расширение и имя файла должно соответствовать: [ ' + _validFileName + ' ]');
  64. return false;
  65. }
  66. }
  67. }
  68. }
  69. return true;
  70. }
  71. $('goback').onclick = function(){
  72. a = 'goback.cgi';
  73. if (getCGI(a) === true) {
  74. $('count-wrap').style.display = 'block';
  75. $('countdown').style.display = 'block';
  76. countdown();
  77. }
  78. };
  79. $("uploadBtn").onchange = function () {document.getElementById("uploadFile").value = this.files[0].name;};