Created
March 2, 2016 15:40
-
-
Save mirko77/57c25e268ded86612fe5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var askConfirm = function (the_title, the_message, onConfirmCallback, has_data_to_save, the_current_input, is_branch) { | |
var current_input = the_current_input; | |
var response; | |
if (navigator.notification && !EC.Utils.isChrome()) { | |
var _confirmCallback = function (btn_index) { | |
console.log('btn_index: ' + btn_index); | |
if (btn_index === 1) { | |
EC.Utils.executeFunctionByName(onConfirmCallback, window); | |
} else { | |
return; | |
} | |
}; | |
var _saveConfirmCallback = function (btn_index) { | |
switch (btn_index) { | |
case 1: | |
//exit without saving current form data | |
EC.Utils.executeFunctionByName(onConfirmCallback, window); | |
break; | |
case 2: | |
//save data before leaving form | |
EC.Notification.showProgressDialog(); | |
if (is_branch) { | |
EC.BranchInputs.saveValuesOnExit(current_input); | |
} else { | |
EC.Inputs.saveValuesOnExit(current_input); | |
} | |
break; | |
default: | |
return; | |
} | |
}; | |
//cordova async confirm | |
if (has_data_to_save) { | |
//we have a third option: save the data before exiting | |
navigator.notification.confirm(the_message, _saveConfirmCallback, the_title, [EC.Localise.getTranslation('no'), EC.Localise.getTranslation('save'), EC.Localise.getTranslation('dismiss')]); | |
} else { | |
//normal confirmation just 2 options (Android and iOS options | |
// order is inverted, use iOS order) | |
if (window.device.platform === EC.Const.IOS) { | |
navigator.notification.confirm(the_message, _confirmCallback, the_title, [EC.Localise.getTranslation('confirm'), EC.Localise.getTranslation('dismiss')]); | |
} | |
if (window.device.platform === EC.Const.ANDROID) { | |
navigator.notification.confirm(the_message, _confirmCallback, the_title, [EC.Localise.getTranslation('confirm'), EC.Localise.getTranslation('dismiss')]); | |
} | |
} | |
} else { | |
//standard javascript confirm, synced call | |
response = confirm(the_title ? the_title + ': ' + the_message : the_message); | |
if (response) { | |
EC.Utils.executeFunctionByName(onConfirmCallback, window); | |
} else { | |
return; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment