$(".btn#add").click(function (){ $('#full_name_err').html(""); $('#login_name_err').html(""); $('#pwd1_err').html(""); $('#pwd2_err').html(""); $('#email_err').html(""); $('#phone_err').html(""); $.ajax({ url: "quan_tri_vien/them", type: "POST", data: $("#add_frm").serialize(), success: function (data, textStatus, jqXHR) { result = jQuery.parseJSON(data); if (result.success == "1") { filter(); $('#addAdmin').modal('hide'); } else { for (var key in result.errors) { $('#'+key).html(result.errors[key]); } } }, }); }); $('#editAdmin').on('show.bs.modal', function(e) { var id = $(e.relatedTarget).data('admin-id'); $.ajax({ url: "quan_tri_vien/id/" + id, type: "POST", success: function (data, textStatus, jqXHR) { result = jQuery.parseJSON(data); if (result.success=="1") { item = result.item; $("#edit_full_name").val(item['full_name']); $("#edit_login_name").val(item['login_name']); $("#edit_email").val(item['email']); $("#edit_phone").val(item['phone']); }else { console.log("Item not found !"); } } }); $(".btn#edit").click(function(){ $.ajax({ url: "quan_tri_vien/sua/" + id, type: "POST", data: $("#edit_frm").serialize(), success: function (data, textStatus, jqXHR) { result = jQuery.parseJSON(data) if (result.success=="1"){ filter(); $('#editAdmin').modal('hide'); }else { console.log("Edit error !"); } } }); }); }); $('#deleteAdmin').on('show.bs.modal', function(e) { var id = $(e.relatedTarget).data('admin-id'); //$(e.currentTarget).find('input[name="id"]').val(id); $(".btn#delete").click(function(){ $.ajax({ url: "quan_tri_vien/xoa/" + id, type: "POST", success: function (data, textStatus, jqXHR) { result = jQuery.parseJSON(data) if (result.success=="1"){ filter(); $('#deleteAdmin').modal('hide'); }else { console.log("Delete error !"); } } }); }); }); (function($){ $.fn.setCursorToTextEnd = function() { $initialVal = this.val(); this.val($initialVal + ' '); this.val($initialVal); }; })(jQuery); function clearFormFields(id){ $(id).find('input:text, input:hidden, input:password, input:file, select, textarea').val(''); $(id).find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected'); $(id).find('.help-block').html(""); } $('body').on('hidden.bs.modal', '.modal', function () { clearFormFields('#add_frm'); clearFormFields('#edit_frm'); clearFormFields('#delete_frm'); });