Browse Source

Fix unecessary alert() when cancelling prompt() and change extend logic a little bit..

Aubort Jean-Baptiste 5 years ago
parent
commit
b85bb3fafd
2 changed files with 9 additions and 14 deletions
  1. 8 13
      main.js
  2. 1 1
      trigger.html

+ 8 - 13
main.js

@@ -89,9 +89,9 @@ function updateSpaceInformation() {
                     toggleDiv(closeBlock, 0);
                     document.hoursform.hours.focus();
                 }
-                
+
                 launchAutoRefresh(closing_time);
-                
+
                 msgBlock.innerHTML = parsed_text.state.message;
                 toggleDiv(msgBlock, 1);
                 toggleDiv(loadBlock, 0);
@@ -132,11 +132,12 @@ function onPageLoad() {
 }
 
 
-function openSpace(hoursOpen) {
+function openSpace(extend) {
     "use strict";
-    if (hoursOpen === undefined) {
-        var hoursForm = document.hoursform.hours;
-        hoursOpen = hoursForm.value;
+    var hoursOpen = document.hoursform.hours.value;
+    if (hoursOpen === undefined || extend) {
+        hoursOpen = prompt("Hours:", 1);
+        if (hoursOpen === null) return;
     }
     var confirm_return = confirm("Are you sure you want to open the hackerspace ?");
     if (confirm_return) {
@@ -155,12 +156,6 @@ function openSpace(hoursOpen) {
     }
 }
 
-function promptOpenSpace(){
-    "use strict";
-    var hours = prompt("Hours:", 1);
-    openSpace(hours);
-}
-
 function closeSpace() {
     "use strict";
     var requestUrl = baseUrl + "?do=close";
@@ -194,7 +189,7 @@ function update_date(date) {
         minutes = "0" + minutes;
     }
     setTextForId("minute", minutes);
-    
+
     var seconds = String(date.getSeconds());
     if (seconds.length == 1) {
         seconds = "0" + seconds;

+ 1 - 1
trigger.html

@@ -32,7 +32,7 @@
             <form>
               <input type="button" onclick="closeSpace()" value="Close"
               class="button">
-              <input type="button" onclick="promptOpenSpace()" value="Extend"
+              <input type="button" onclick="openSpace(true)" value="Extend"
               class="button">
               <br>
             <p>The space is still open for:</p>