text: $(function () {
  
      $('input[type=text], textarea').keyup(function () {
          $(this).val($(this).val().toUpperCase());
      });
  
      $('input[type=text], textarea').each(function () {
          $(this).val($(this).val().toUpperCase());
      });
  
      var save_and_close = false;
  
      $('.ptogtitle').click(function () {
          let boxCrud = $(this).closest('div.crud-form')[0];
          let form = $(boxCrud).find('form')[0];
  
          if ($(this).hasClass('vsble')) {
              $(this).removeClass('vsble');
              $(form).slideDown("slow");
          }
          else {
              $(this).addClass('vsble');
              $(form).slideUp("slow");
          }
      });
  
      $('.save-and-go-back-button').click(function () {
          save_and_close = true;
  
          let form = $(this).closest('form')[0];
  
          $(form).trigger('submit');
      });
  
      $('.crud-form').submit(function () {
          let my_crud_form = $(this);
          let formId = '#' + $(this).attr('id');
          let btnSaveAndBack = $(this).find('.save-and-go-back-button')[0];
          let reportSuccess = $(this).find('.report-success')[0];
          let reportError = $(this).find('.report-error')[0];
          let formLoading = $(this).find('.form-loading')[0];
          let e = this;
  
          $(this).ajaxSubmit({
              url: validation_url,
              dataType: 'json',
              cache: 'false',
              beforeSend: function () {
                  $(formLoading).show();
              },
              success: function (data) {
                  if (data.success) {
                      if (confirmation_url == "") {
                          doSubmit(data, my_crud_form, formId, formLoading, btnSaveAndBack, reportSuccess, reportError);
                      } else {
                          $(e).ajaxSubmit({
                              url: confirmation_url + '/' + row_id,
                              dataType: 'json',
                              cache: 'false',
                              beforeSend: function () {
  
                              },
                              success: function (confirmResponse) {
                                  if (confirmResponse.success) {
                                      doSubmit(data, my_crud_form, formId, formLoading, btnSaveAndBack, reportSuccess, reportError);
                                  } else {
                                      bootbox.confirm(confirmResponse.message, function (result) {
                                          if (result) {
                                              doSubmit(data, my_crud_form, formId, formLoading, btnSaveAndBack, reportSuccess, reportError);
                                          } else {
                                              $('#report-error').slideUp('fast');
                                              $('input').removeClass('field_error');
  
                                          }
                                      });
                                  }
                              },
                              error: function () {
  
                              }
                          });
                      }
                  }
                  else {
                      $('.field_error').each(function () {
                          $(this).removeClass('field_error');
                      });
                      $(reportError).slideUp('fast');
                      $(reportError).html(data.error_message);
                      $.each(data.error_fields, function (index, value) {
                          $('input[name=' + index + ']').addClass('field_error');
                      });
  
                      $(reportError).slideDown('normal');
                      $(reportSuccess).slideUp('fast').html('');
  
                  }
              },
              error: function () {
                  alert(message_update_error);
                  $(formLoading).hide();
  
              }
          });
          return false;
      });
  
      function doSubmit(data, my_crud_form, formId, formLoading, btnSaveAndBack, reportSuccess, reportError) {
          $(formId).ajaxSubmit({
              dataType: 'text',
              cache: 'false',
              beforeSend: function () {
                  $(formLoading).show();
              },
              success: function (result) {
  
                  $(formLoading).fadeOut("slow");
                  data = $.parseJSON(result);
  
                  if (data.success) {
                      var data_unique_hash = my_crud_form.closest(".flexigrid").attr("data-unique-hash");
  
                      $('.flexigrid[data-unique-hash=' + data_unique_hash + ']').find('.ajax_refresh_and_loading').trigger('click');
  
                      if (save_and_close) {
                          if ($(btnSaveAndBack).closest('.ui-dialog').length === 0) {
                              window.location = data.success_list_url;
                          } else {
                              $(".ui-dialog-content").dialog("close");
                              success_message(reportSuccess, reportError, data.success_message);
                          }
  
                          return true;
                      }
  
                      form_success_message(reportSuccess, reportError, data.success_message);
                  }
                  else {
                      form_error_message(reportSuccess, reportError, message_update_error);
                  }
              },
              error: function () {
                  form_error_message(reportSuccess, reportError, message_update_error);
              }
          });
      }
  
      if ($('#cancel-button').closest('.ui-dialog').length === 0) {
  
          $('#cancel-button').click(function () {
              window.location = list_url;
  
              return false;
          });
  
      }
  });
  