mirror of
https://github.com/Doodle3D/doodle3d-connect.git
synced 2024-12-24 17:43: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");
|
||||
|
||||
_connectAPI.refreshing = onRefreshing;
|
||||
_connectAPI.listFailed = onListFailed;
|
||||
_connectAPI.listSuccess = onlistSuccess;
|
||||
_connectAPI.listUpdated = onListUpdated;
|
||||
_connectAPI.boxAppeared = onBoxAppeared;
|
||||
_connectAPI.boxDisapeared = onBoxDisapeared;
|
||||
@ -38,6 +40,14 @@ var BoxesPage = (function (w) {
|
||||
//console.log("onRefreshing");
|
||||
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) {
|
||||
//console.log("onListUpdated: ",boxesData);
|
||||
}
|
||||
|
@ -132,6 +132,10 @@
|
||||
link = d3d.util.replaceURLParameters(link,linkParams);
|
||||
$.mobile.changePage(link);
|
||||
connectedBoxNetworkAPI.stopAutoRefresh();
|
||||
|
||||
// disable warnings that are enabled on boxes page
|
||||
d3d.util.disableRefreshPrevention();
|
||||
d3d.util.disableLeaveWarning();
|
||||
}
|
||||
};
|
||||
connectedBoxNetworkAPI.startAutoRefresh();
|
||||
|
@ -9,6 +9,8 @@ function ConnectAPI() {
|
||||
|
||||
// callbacks
|
||||
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.boxAppeared; // a new box appeared
|
||||
this.boxDisapeared; // a box disappeared
|
||||
@ -47,12 +49,14 @@ function ConnectAPI() {
|
||||
//console.log("ConnectAPI:list failed: ",response);
|
||||
if(failedHandler) failedHandler(response);
|
||||
} else {
|
||||
if(_self.listSuccess) {_self.listSuccess(); }
|
||||
completeHandler(response.data);
|
||||
}
|
||||
}
|
||||
}).fail(function() {
|
||||
//console.log("ConnectAPI:list failed");
|
||||
if(failedHandler) failedHandler();
|
||||
if(_self.listFailed) {_self.listFailed(); }
|
||||
});
|
||||
};
|
||||
|
||||
@ -71,12 +75,8 @@ function ConnectAPI() {
|
||||
clearTimeout(_refreshDelay);
|
||||
}
|
||||
this.refresh = function(listUpdated) {
|
||||
if(listUpdated) {
|
||||
_self.listUpdated = listUpdated;
|
||||
}
|
||||
if(_self.refreshing) {
|
||||
_self.refreshing();
|
||||
}
|
||||
if(listUpdated) { _self.listUpdated = listUpdated; }
|
||||
if(_self.refreshing) { _self.refreshing(); }
|
||||
|
||||
_self.list(function(foundBoxes) {
|
||||
//console.log(" foundBoxes: ",foundBoxes);
|
||||
@ -86,8 +86,8 @@ function ConnectAPI() {
|
||||
clearTimeout(_refreshDelay);
|
||||
_refreshDelay = setTimeout(_self.refresh, _refreshInterval);
|
||||
}
|
||||
//removeBox(_apBox.localip,true); // TODO: why again?
|
||||
}, function() {
|
||||
console.log("ConnectAPI list retrieve failed");
|
||||
// if web is not accessible try to find a box as an accesspoint
|
||||
// if not found, we look for a wired box
|
||||
_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'];
|
||||
});
|
||||
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