function StandardNote(noteObject) { this.noteObject = noteObject; this.noteQuestion = null; this.noteType = null; this.isNoteValid = false; this.noteAnswer = null; this.isRequired = null; this.init = function() { if ( ( this.noteObject ) && ( this.noteObject.question ) && ( this.noteObject.type == "textField" ) && ( typeof this.noteObject.required === "boolean" ) ) { this.noteQuestion = this.noteObject.question; this.noteType = this.noteObject.type; this.isRequired = this.noteObject.required; this.isNoteValid = true; return true; } return false; }; this.getNoteObject = function() { return this.noteObject; }; this.getNoteQuestion = function() { return this.noteQuestion; }; this.getNoteType = function() { return this.noteType; }; this.isValidQ = function() { return this.isNoteValid; }; this.getNoteAnswer = function() { return this.noteAnswer; }; this.getIsRequired = function() { return this.isRequired; }; this.getNoteAnswerObject = function() { return (this.isValidQ()) ? {"question": this.getNoteQuestion(), "answer": this.getNoteAnswer(), "required": this.getIsRequired() } : null; }; this.setNoteAnswer = function(noteAnswer) { this.noteAnswer = noteAnswer; return true; }; this.defineStandardNoteProcess = function(callbackSuccess, callbackFailure) { if (this.isValidQ()) { var isRequired = this.getIsRequired(); Swal.fire({ title: this.getNoteQuestion(), input: 'text', showCancelButton: true, confirmButtonText: 'Confirm', cancelButtonText: 'Cancelar', customClass: "animated fadeIn", inputPlaceholder: 'Write Here!', onClose: function(modal) { $(".swal2-popup").removeClass('fadeIn'); }, preConfirm: function(value) { return ((value) || (!isRequired)) ? value : Swal.showValidationMessage('There must be a answer'); } }).then((result) => { if ((result.value) || (!isRequired)) { this.setNoteAnswer(result.value); callbackSuccess(); return; } else { callbackFailure(); return; } }); } else { callbackSuccess(); return; } }; this.init(); }