mirror of
https://github.com/Doodle3D/doodle3d-connect.git
synced 2024-12-25 18:13:48 +01:00
Page leave prevention when appropriate
This commit is contained in:
parent
e3492a7567
commit
21598c1afc
@ -21,6 +21,8 @@ var BoxesPage = (function (w) {
|
|||||||
_findItem = _list.find("#findItem");
|
_findItem = _list.find("#findItem");
|
||||||
|
|
||||||
_connectAPI.refreshing = onRefreshing;
|
_connectAPI.refreshing = onRefreshing;
|
||||||
|
_connectAPI.listFailed = onListFailed;
|
||||||
|
_connectAPI.listSuccess = onlistSuccess;
|
||||||
_connectAPI.listUpdated = onListUpdated;
|
_connectAPI.listUpdated = onListUpdated;
|
||||||
_connectAPI.boxAppeared = onBoxAppeared;
|
_connectAPI.boxAppeared = onBoxAppeared;
|
||||||
_connectAPI.boxDisapeared = onBoxDisapeared;
|
_connectAPI.boxDisapeared = onBoxDisapeared;
|
||||||
@ -38,6 +40,14 @@ var BoxesPage = (function (w) {
|
|||||||
//console.log("onRefreshing");
|
//console.log("onRefreshing");
|
||||||
d3d.util.showLoader(true);
|
d3d.util.showLoader(true);
|
||||||
}
|
}
|
||||||
|
function onListFailed() {
|
||||||
|
d3d.util.enableRefreshPrevention();
|
||||||
|
d3d.util.enableLeaveWarning("You're not connecting to the internet, leaving now will interrupt the connection proces");
|
||||||
|
}
|
||||||
|
function onlistSuccess() {
|
||||||
|
d3d.util.disableRefreshPrevention();
|
||||||
|
d3d.util.disableLeaveWarning();
|
||||||
|
}
|
||||||
function onListUpdated(boxesData) {
|
function onListUpdated(boxesData) {
|
||||||
//console.log("onListUpdated: ",boxesData);
|
//console.log("onListUpdated: ",boxesData);
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,10 @@
|
|||||||
link = d3d.util.replaceURLParameters(link,linkParams);
|
link = d3d.util.replaceURLParameters(link,linkParams);
|
||||||
$.mobile.changePage(link);
|
$.mobile.changePage(link);
|
||||||
connectedBoxNetworkAPI.stopAutoRefresh();
|
connectedBoxNetworkAPI.stopAutoRefresh();
|
||||||
|
|
||||||
|
// disable warnings that are enabled on boxes page
|
||||||
|
d3d.util.disableRefreshPrevention();
|
||||||
|
d3d.util.disableLeaveWarning();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
connectedBoxNetworkAPI.startAutoRefresh();
|
connectedBoxNetworkAPI.startAutoRefresh();
|
||||||
|
@ -9,6 +9,8 @@ function ConnectAPI() {
|
|||||||
|
|
||||||
// callbacks
|
// callbacks
|
||||||
this.refreshing; // I'm refreshing my list
|
this.refreshing; // I'm refreshing my list
|
||||||
|
this.listFailed; // list retrieval from connect.doodle3d.com failed
|
||||||
|
this.listSuccess; // list retrieval from connect.doodle3d.com succeeded
|
||||||
this.listUpdated; // the list of boxes is updated / changed
|
this.listUpdated; // the list of boxes is updated / changed
|
||||||
this.boxAppeared; // a new box appeared
|
this.boxAppeared; // a new box appeared
|
||||||
this.boxDisapeared; // a box disappeared
|
this.boxDisapeared; // a box disappeared
|
||||||
@ -47,12 +49,14 @@ function ConnectAPI() {
|
|||||||
//console.log("ConnectAPI:list failed: ",response);
|
//console.log("ConnectAPI:list failed: ",response);
|
||||||
if(failedHandler) failedHandler(response);
|
if(failedHandler) failedHandler(response);
|
||||||
} else {
|
} else {
|
||||||
|
if(_self.listSuccess) {_self.listSuccess(); }
|
||||||
completeHandler(response.data);
|
completeHandler(response.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
//console.log("ConnectAPI:list failed");
|
//console.log("ConnectAPI:list failed");
|
||||||
if(failedHandler) failedHandler();
|
if(failedHandler) failedHandler();
|
||||||
|
if(_self.listFailed) {_self.listFailed(); }
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -71,12 +75,8 @@ function ConnectAPI() {
|
|||||||
clearTimeout(_refreshDelay);
|
clearTimeout(_refreshDelay);
|
||||||
}
|
}
|
||||||
this.refresh = function(listUpdated) {
|
this.refresh = function(listUpdated) {
|
||||||
if(listUpdated) {
|
if(listUpdated) { _self.listUpdated = listUpdated; }
|
||||||
_self.listUpdated = listUpdated;
|
if(_self.refreshing) { _self.refreshing(); }
|
||||||
}
|
|
||||||
if(_self.refreshing) {
|
|
||||||
_self.refreshing();
|
|
||||||
}
|
|
||||||
|
|
||||||
_self.list(function(foundBoxes) {
|
_self.list(function(foundBoxes) {
|
||||||
//console.log(" foundBoxes: ",foundBoxes);
|
//console.log(" foundBoxes: ",foundBoxes);
|
||||||
@ -86,8 +86,8 @@ function ConnectAPI() {
|
|||||||
clearTimeout(_refreshDelay);
|
clearTimeout(_refreshDelay);
|
||||||
_refreshDelay = setTimeout(_self.refresh, _refreshInterval);
|
_refreshDelay = setTimeout(_self.refresh, _refreshInterval);
|
||||||
}
|
}
|
||||||
//removeBox(_apBox.localip,true); // TODO: why again?
|
|
||||||
}, function() {
|
}, function() {
|
||||||
|
console.log("ConnectAPI list retrieve failed");
|
||||||
// if web is not accessible try to find a box as an accesspoint
|
// if web is not accessible try to find a box as an accesspoint
|
||||||
// if not found, we look for a wired box
|
// if not found, we look for a wired box
|
||||||
_networkAPI.alive(_apBox.localip,_boxTimeoutTime,function() {
|
_networkAPI.alive(_apBox.localip,_boxTimeoutTime,function() {
|
||||||
|
27
js/main.js
27
js/main.js
@ -64,6 +64,33 @@ d3d.util = {
|
|||||||
formData[field['name']] = field['value'];
|
formData[field['name']] = field['value'];
|
||||||
});
|
});
|
||||||
return formData;
|
return formData;
|
||||||
|
},
|
||||||
|
enableRefreshPrevention:function() {
|
||||||
|
$(document).on("keydown",d3d.util.preventRefresh);
|
||||||
|
},
|
||||||
|
disableRefreshPrevention:function() {
|
||||||
|
$(document).off("keydown",d3d.util.preventRefresh);
|
||||||
|
},
|
||||||
|
preventRefresh:function(event) {
|
||||||
|
if((event.which === 82 && (event.ctrlKey || event.metaKey)) || // ctrl+r
|
||||||
|
event.which === 116) { // F5
|
||||||
|
console.log("d3d.util.preventRefresh");
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
disableLeaveWarning:function() {
|
||||||
|
window.onbeforeunload = null;
|
||||||
|
},
|
||||||
|
enableLeaveWarning:function(warning) {
|
||||||
|
if(warning === undefined) {
|
||||||
|
warning = "Are you sure you want to leave?";
|
||||||
|
}
|
||||||
|
window.onbeforeunload = function() {
|
||||||
|
console.log("WARNING:"+warning);
|
||||||
|
return warning;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user