0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-22 09:17:56 +01:00

Change settings window to use popup handlers as well.

This commit is contained in:
Wouter R 2014-01-17 17:59:26 +01:00
parent 74b9149175
commit 7288ac8b1e
2 changed files with 22 additions and 15 deletions

View File

@ -1,4 +1,6 @@
function Popup(element, mask) { function Popup(element, mask) {
var autoCloseEnabled = true;
var enterEnabled = true;
var self = this; var self = this;
this.open = function(complete, disableMaskClick) { this.open = function(complete, disableMaskClick) {
@ -11,7 +13,7 @@ function Popup(element, mask) {
document.body.removeEventListener('touchmove', prevent, false); document.body.removeEventListener('touchmove', prevent, false);
mask.bind("onButtonClick", self.cancel); mask.bind("onButtonClick", self.cancel);
$(document).bind("onEscapeKey", self.cancel); $(document).bind("onEscapeKey", self.cancel);
$(document).bind("onEnterKey", self.commit); if (enterEnabled) $(document).bind("onEnterKey", self.commit);
} }
this.close = function(complete) { this.close = function(complete) {
@ -24,16 +26,20 @@ function Popup(element, mask) {
document.body.addEventListener('touchmove', prevent, false); document.body.addEventListener('touchmove', prevent, false);
mask.unbind("onButtonClick", self.cancel); mask.unbind("onButtonClick", self.cancel);
$(document).unbind("onEscapeKey", self.cancel); $(document).unbind("onEscapeKey", self.cancel);
$(document).unbind("onEnterKey", self.commit); if (enterEnabled) $(document).unbind("onEnterKey", self.commit);
} }
this.setEnterEnabled = function(enabled) { enterEnabled = enabled; }
this.setAutoCloseEnabled = function(enabled) { autoCloseEnabled = enabled; }
this.cancel = function() { this.cancel = function() {
self.close();
$(element).trigger('onPopupCancel'); $(element).trigger('onPopupCancel');
if (autoCloseEnabled) self.close();
} }
this.commit = function() { this.commit = function() {
self.close();
$(element).trigger('onPopupCommit'); $(element).trigger('onPopupCommit');
if (autoCloseEnabled) self.close();
} }
} }

View File

@ -90,9 +90,13 @@ function SettingsWindow() {
this.window = $("#popupSettings"); this.window = $("#popupSettings");
this.btnOK = this.window.find(".btnOK"); this.btnOK = this.window.find(".btnOK");
enableButton(this.btnOK,this.submitwindow);
settingsPopup = new Popup($("#popupSettings"), $("#popupMask")); settingsPopup = new Popup($("#popupSettings"), $("#popupMask"));
settingsPopup.setEnterEnabled(false);
settingsPopup.setAutoCloseEnabled(false);
enableButton(this.btnOK,settingsPopup.commit);
$("#popupSettings").bind("onPopupCancel", function() { settingsPopup.close(); } );
$("#popupSettings").bind("onPopupCommit", self.submitwindow);
this.window.find("#settingsContainer").load("settings.html", function() { this.window.find("#settingsContainer").load("settings.html", function() {
console.log("Settings:finished loading settings.html, now loading settings..."); console.log("Settings:finished loading settings.html, now loading settings...");
@ -155,23 +159,20 @@ function SettingsWindow() {
}); });
}; };
this.closeSettings = function(complete) { // this.closeSettings = function(complete) {
settingsPopup.close(complete); // settingsPopup.close(complete);
}; // };
this.submitwindow = function(e) { this.submitwindow = function(e) {
disableButton(self.btnOK,self.submitwindow); disableButton(self.btnOK,settingsPopup.commit);
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
self.saveSettings(self.readForm(),function(success){ self.saveSettings(self.readForm(),function(success){
if(success) { if(success) {
self.closeSettings(function() { settingsPopup.close();
enableButton(self.btnOK,self.submitwindow);
});
self.signin(); self.signin();
} else {
enableButton(self.btnOK,self.submitwindow);
} }
enableButton(self.btnOK,settingsPopup.commit);
}); });
clearTimeout(self.retryRetrieveNetworkStatusDelay); clearTimeout(self.retryRetrieveNetworkStatusDelay);