Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. $(document).on("submit","#form-modal-user",function(e){
  2. var reqData = {name : uName.val(),
  3. position : uPosition.val(),
  4. country : uCountry.val(),
  5. username : uUser.val(),
  6. password : uPass.val(),
  7. _token : token,
  8. id : $("#db-id").val()
  9. };
  10. postAjaxSubmit('create-or-edit-user',reqData,postModalSubmitWrapper);
  11. e.preventDefault();
  12. });
  13.  
  14. //handle ajax submit, type post(postAjaxSubmit)
  15. function postAjaxSubmit(url,formData,postFunc){
  16. $.ajax({
  17. url : url,
  18. data : formData,
  19. type : 'POST',
  20. dataType : 'json',
  21. success: function(result,status){
  22. if(typeof postFunc != 'undefined'){
  23. postFunc(result,status);
  24. }
  25. },
  26. error : function (result,status){
  27. errorNotification("Unknown error, Please contact your administrator!");
  28. }
  29. });
  30. }
  31.  
  32. //close modal
  33. function postModalSubmitWrapper(result,status){
  34. $('.modal').modal('hide');
  35.  
  36. var succeedMessage = "User has been added successfully";
  37. var failedMessage = "Failed to add user, Please contact administrator";
  38. if($("#db-id").val() != ""){
  39. succeedMessage = "User has been updated succesfully";
  40. failedMessage = "Failed to update user, Please contact administrator";
  41. }
  42.  
  43. $("#db-id").val("");
  44. if(status == successStatus){
  45. reloadTableDataBasedOnVal(result);
  46. infoNotification(succeedMessage);
  47. }else{
  48. errorNotification(failedMessage);
  49. }
  50. }
  51. //handle edit client
  52. $(document).on("click", "a[data-action=user-edit]", function(e) {
  53. var id = $(this).attr("data-id");
  54. $("#db-id").val(id);
  55. var data = {id: id,
  56. _token : token};
  57. postAjaxSubmit('get-user-by-id',data,preEditUser);
  58. });
  59.  
  60. function preEditUser(result,status){
  61. //populate col
  62. if(status == successStatus && result != null){
  63. var contents = result.content;
  64. var data = contents == null ? null : contents[0];
  65. if(data != null){
  66. uName.val(data.cv_name);
  67. uUser.val(data.cv_username);
  68. $('.modal').modal('show');
  69. }
  70. }else{
  71. errorNotification("Error when getting data");
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement