upload.js 2.3 KB

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