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

View File

@ -90,9 +90,13 @@ function SettingsWindow() {
this.window = $("#popupSettings");
this.btnOK = this.window.find(".btnOK");
enableButton(this.btnOK,this.submitwindow);
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() {
console.log("Settings:finished loading settings.html, now loading settings...");
@ -155,23 +159,20 @@ function SettingsWindow() {
});
};
this.closeSettings = function(complete) {
settingsPopup.close(complete);
};
// this.closeSettings = function(complete) {
// settingsPopup.close(complete);
// };
this.submitwindow = function(e) {
disableButton(self.btnOK,self.submitwindow);
disableButton(self.btnOK,settingsPopup.commit);
e.preventDefault();
e.stopPropagation();
self.saveSettings(self.readForm(),function(success){
if(success) {
self.closeSettings(function() {
enableButton(self.btnOK,self.submitwindow);
});
settingsPopup.close();
self.signin();
} else {
enableButton(self.btnOK,self.submitwindow);
}
enableButton(self.btnOK,settingsPopup.commit);
});
clearTimeout(self.retryRetrieveNetworkStatusDelay);