Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).on("submit","#form-modal-user",function(e){
- var reqData = {name : uName.val(),
- position : uPosition.val(),
- country : uCountry.val(),
- username : uUser.val(),
- password : uPass.val(),
- _token : token,
- id : $("#db-id").val()
- };
- postAjaxSubmit('create-or-edit-user',reqData,postModalSubmitWrapper);
- e.preventDefault();
- });
- //handle ajax submit, type post(postAjaxSubmit)
- function postAjaxSubmit(url,formData,postFunc){
- $.ajax({
- url : url,
- data : formData,
- type : 'POST',
- dataType : 'json',
- success: function(result,status){
- if(typeof postFunc != 'undefined'){
- postFunc(result,status);
- }
- },
- error : function (result,status){
- errorNotification("Unknown error, Please contact your administrator!");
- }
- });
- }
- //close modal
- function postModalSubmitWrapper(result,status){
- $('.modal').modal('hide');
- var succeedMessage = "User has been added successfully";
- var failedMessage = "Failed to add user, Please contact administrator";
- if($("#db-id").val() != ""){
- succeedMessage = "User has been updated succesfully";
- failedMessage = "Failed to update user, Please contact administrator";
- }
- $("#db-id").val("");
- if(status == successStatus){
- reloadTableDataBasedOnVal(result);
- infoNotification(succeedMessage);
- }else{
- errorNotification(failedMessage);
- }
- }
- //handle edit client
- $(document).on("click", "a[data-action=user-edit]", function(e) {
- var id = $(this).attr("data-id");
- $("#db-id").val(id);
- var data = {id: id,
- _token : token};
- postAjaxSubmit('get-user-by-id',data,preEditUser);
- });
- function preEditUser(result,status){
- //populate col
- if(status == successStatus && result != null){
- var contents = result.content;
- var data = contents == null ? null : contents[0];
- if(data != null){
- uName.val(data.cv_name);
- uUser.val(data.cv_username);
- $('.modal').modal('show');
- }
- }else{
- errorNotification("Error when getting data");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement