Created
March 21, 2016 08:28
-
-
Save ScullWM/fb2053f763fa42bb92fa 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 MyModalConfirmation = { | |
myModalStringSelector: '#myModal', | |
hashConfirmationModal: null, | |
confirmationMessage: 'Certain ?', | |
form: null, | |
saveBtn: null, | |
isConfirmed: false, | |
associationConfirmation: function(e){ | |
_this = this; | |
if (!MyModalConfirmation.isConfirmed) { | |
e.preventDefault(); | |
associationConfirmationModal = $(MyModalConfirmation.myModalStringSelector) | |
.clone() | |
.attr('id', MyModalConfirmation.hashConfirmationModal) | |
.css('margin-top', '80px') | |
; | |
associationConfirmationModal | |
.find('.modal-body') | |
.html(MyModalConfirmation.confirmationMessage) | |
; | |
cBtn = associationConfirmationModal.find('.modal-footer a.btn.btn-primary'); | |
MyModalConfirmation.bindConfirmationModal(cBtn); | |
associationConfirmationModal.modal(); | |
return false; | |
} | |
}, | |
submitForm: function() { | |
MyModalConfirmation.isConfirmed = true; | |
$(MyModalConfirmation.form).off(); | |
initFormAjax($(MyModalConfirmation.form)); | |
$(MyModalConfirmation.hashConfirmationModal).modal('hide'); | |
$(MyModalConfirmation.myModalStringSelector).modal('hide'); | |
}, | |
/** | |
* @param string confirmationMessageString | |
*/ | |
setConfirmationMessage: function(confirmationMessageString) { | |
_this = this; | |
_this.confirmationMessage = confirmationMessageString; | |
}, | |
/** | |
* @param string form form name string selector | |
* @param string saveBtn save btn string selector | |
*/ | |
bindConfirmation: function(form, saveBtn){ | |
_this = this; | |
$(form).submit(MyModalConfirmation.associationConfirmation); | |
$(saveBtn).off().on('click', MyModalConfirmation.associationConfirmation); | |
}, | |
bindConfirmationModal: function(cBtn) { | |
_this = this; | |
cBtn.on('click', MyModalConfirmation.submitForm) | |
}, | |
/** | |
* init construction | |
* | |
* @param string form form name string selector | |
* @param string saveBtn save btn string selector | |
*/ | |
init: function(form, saveBtn){ | |
_this = this; | |
_this.bindConfirmation(form, saveBtn); | |
_this.form = form; | |
_this.saveBtn = saveBtn; | |
// generate a random free id for the confirmation modal | |
_this.hashConfirmationModal = Math.random().toString(36).substring(7); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment