diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 75c3a418..e4790364 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -118,6 +118,12 @@ var ComunicWeb = { * Prompt the user to input a string */ inputString: function(title, message, defaultValue, callback){}, + + /** + * Prompt the user to enter his password + */ + promptPassword: function(info){}, + }, /** diff --git a/assets/js/common/messages.js b/assets/js/common/messages.js index 85821a39..118f5e9e 100644 --- a/assets/js/common/messages.js +++ b/assets/js/common/messages.js @@ -382,4 +382,85 @@ ComunicWeb.common.messages.inputString = function(title, message, defaultValue, //Show the modal $(modal).modal('show'); +} + +/** + * Prompt the user to input his password + * + * @param {Object} info Additionnal information + */ +ComunicWeb.common.messages.promptPassword = function(info){ + + var dialog = ComunicWeb.common.messages.createDialogSkeleton({ + type: "danger", + title: "Password required" + }); + $(dialog.modal).modal("show"); + + //Create modal close function + var closeModal = function(e, password){ + $(dialog.modal).modal("hide"); + emptyElem(dialog.modal); + dialog.modal.remove(); + + //Callback + if(info.callback) + info.callback(password); + }; + dialog.cancelButton.addEventListener("click", closeModal); + dialog.closeModal.addEventListener("click", closeModal); + + //Set dialog body + var passwordForm = createElem2({ + appendTo: dialog.modalBody, + type: "div" + }); + + createElem2({ + appendTo: passwordForm, + type: "p", + innerHTML: "We need your password to continue." + }); + + //Create pasword input group + var inputGroup = createElem2({ + appendTo: passwordForm, + type: "div", + class: "input-group input-group-sm" + }); + + //Create password input + var passwordInput = createElem2({ + appendTo: inputGroup, + type: "input", + class: "form-control", + elemType: "password" + }); + + //Create input group + var inputGroupContainer = createElem2({ + appendTo: inputGroup, + type: "span", + class: "input-group-btn" + }); + + //Add submit button + var submitButton = createElem2({ + appendTo: inputGroupContainer, + type: "button", + class: "btn btn-danger", + innerHTML: "Confirm deletion" + }); + + submitButton.addEventListener("click", function(e){ + + //Check given password + var password = passwordInput.value; + if(password.length < 4) + return notify("Please check given password !", "danger"); + + //Close modal + closeModal(null, password); + + }); } \ No newline at end of file