[375] | 1 | $(".btn#add").click(function (){
|
---|
| 2 | $('#full_name_err').html("");
|
---|
| 3 | $('#login_name_err').html("");
|
---|
| 4 | $('#pwd1_err').html("");
|
---|
| 5 | $('#pwd2_err').html("");
|
---|
| 6 | $('#email_err').html("");
|
---|
| 7 | $('#phone_err').html("");
|
---|
| 8 | $.ajax({
|
---|
| 9 | url: "quan_tri_vien/them",
|
---|
| 10 | type: "POST",
|
---|
| 11 | data: $("#add_frm").serialize(),
|
---|
| 12 | success: function (data, textStatus, jqXHR)
|
---|
| 13 | {
|
---|
| 14 | result = jQuery.parseJSON(data);
|
---|
| 15 | if (result.success == "1")
|
---|
| 16 | {
|
---|
| 17 | filter();
|
---|
| 18 | $('#addAdmin').modal('hide');
|
---|
| 19 | }
|
---|
| 20 | else
|
---|
| 21 | {
|
---|
| 22 | for (var key in result.errors)
|
---|
| 23 | {
|
---|
| 24 | $('#'+key).html(result.errors[key]);
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | },
|
---|
| 29 |
|
---|
| 30 | });
|
---|
| 31 |
|
---|
| 32 | });
|
---|
| 33 |
|
---|
| 34 | $('#editAdmin').on('show.bs.modal', function(e) {
|
---|
| 35 | var id = $(e.relatedTarget).data('admin-id');
|
---|
| 36 | $.ajax({
|
---|
| 37 | url: "quan_tri_vien/id/" + id,
|
---|
| 38 | type: "POST",
|
---|
| 39 | success: function (data, textStatus, jqXHR)
|
---|
| 40 | {
|
---|
| 41 | result = jQuery.parseJSON(data);
|
---|
| 42 | if (result.success=="1")
|
---|
| 43 | {
|
---|
| 44 | item = result.item;
|
---|
[384] | 45 | $("#edit_full_name").val(item['full_name']);
|
---|
| 46 | $("#edit_login_name").val(item['login_name']);
|
---|
| 47 | $("#edit_email").val(item['email']);
|
---|
| 48 | $("#edit_phone").val(item['phone']);
|
---|
[375] | 49 | }else
|
---|
| 50 | {
|
---|
| 51 | console.log("Item not found !");
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | });
|
---|
| 55 |
|
---|
| 56 | $(".btn#edit").click(function(){
|
---|
| 57 | $.ajax({
|
---|
| 58 | url: "quan_tri_vien/sua/" + id,
|
---|
| 59 | type: "POST",
|
---|
[376] | 60 | data: $("#edit_frm").serialize(),
|
---|
[375] | 61 | success: function (data, textStatus, jqXHR)
|
---|
| 62 | {
|
---|
| 63 | result = jQuery.parseJSON(data)
|
---|
| 64 | if (result.success=="1"){
|
---|
| 65 | filter();
|
---|
| 66 | $('#editAdmin').modal('hide');
|
---|
| 67 | }else
|
---|
| 68 | {
|
---|
| 69 | console.log("Edit error !");
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | });
|
---|
| 73 | });
|
---|
| 74 | });
|
---|
| 75 |
|
---|
[423] | 76 | function updateAdmin(id){
|
---|
| 77 | $.ajax({
|
---|
| 78 | url: 'quan_tri_vien/cap_nhat',
|
---|
| 79 | type: "POST",
|
---|
| 80 | data: $("#editAdmin_"+id).serialize(),
|
---|
| 81 | success: function (data, textStatus, jqXHR)
|
---|
| 82 | {
|
---|
| 83 | $result = jQuery.parseJSON(data);
|
---|
| 84 | if ($result.success == "1")
|
---|
| 85 | {
|
---|
| 86 | filter();
|
---|
| 87 | $('#close_'+id).click();
|
---|
| 88 | }
|
---|
| 89 | else
|
---|
| 90 | {
|
---|
[424] | 91 | console.log("Update error");
|
---|
[423] | 92 | }
|
---|
| 93 | },
|
---|
| 94 | error: function (jqXHR, textStatus, errorThrown)
|
---|
| 95 | {
|
---|
| 96 | $(".ajaxloading").hide();
|
---|
| 97 | }
|
---|
| 98 | });
|
---|
| 99 | return false;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[375] | 102 | $('#deleteAdmin').on('show.bs.modal', function(e) {
|
---|
| 103 | var id = $(e.relatedTarget).data('admin-id');
|
---|
[416] | 104 | var us = $(e.relatedTarget).data('admin-us');
|
---|
[375] | 105 | //$(e.currentTarget).find('input[name="id"]').val(id);
|
---|
[416] | 106 | $("#us").html(us);
|
---|
[375] | 107 | $(".btn#delete").click(function(){
|
---|
| 108 | $.ajax({
|
---|
| 109 | url: "quan_tri_vien/xoa/" + id,
|
---|
| 110 | type: "POST",
|
---|
| 111 | success: function (data, textStatus, jqXHR)
|
---|
| 112 | {
|
---|
| 113 | result = jQuery.parseJSON(data)
|
---|
| 114 | if (result.success=="1"){
|
---|
| 115 | filter();
|
---|
| 116 | $('#deleteAdmin').modal('hide');
|
---|
| 117 | }else
|
---|
| 118 | {
|
---|
| 119 | console.log("Delete error !");
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 | });
|
---|
| 123 | });
|
---|
[384] | 124 | });
|
---|
| 125 |
|
---|
| 126 | (function($){
|
---|
| 127 | $.fn.setCursorToTextEnd = function() {
|
---|
| 128 | $initialVal = this.val();
|
---|
| 129 | this.val($initialVal + ' ');
|
---|
| 130 | this.val($initialVal);
|
---|
| 131 | };
|
---|
[398] | 132 | })(jQuery);
|
---|
| 133 |
|
---|
| 134 | function clearFormFields(id){
|
---|
| 135 | $(id).find('input:text, input:hidden, input:password, input:file, select, textarea').val('');
|
---|
| 136 | $(id).find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
|
---|
| 137 | $(id).find('.help-block').html("");
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | $('body').on('hidden.bs.modal', '.modal', function () {
|
---|
| 141 | clearFormFields('#add_frm');
|
---|
| 142 | clearFormFields('#edit_frm');
|
---|
| 143 | clearFormFields('#delete_frm');
|
---|
| 144 | });
|
---|
[423] | 145 |
|
---|
[424] | 146 | function updateInfo()
|
---|
| 147 | {
|
---|
| 148 | $('#email_err').html("");
|
---|
| 149 | $('#phone_err').html("");
|
---|
| 150 | $.ajax({
|
---|
| 151 | url: "cap_nhat_thong_tin_ca_nhan",
|
---|
| 152 | type: "POST",
|
---|
| 153 | data: $("#frm1").serialize(),
|
---|
| 154 | success: function (data, textStatus, jqXHR)
|
---|
| 155 | {
|
---|
| 156 | result = jQuery.parseJSON(data);
|
---|
| 157 | if (result.success == "1")
|
---|
| 158 | {
|
---|
| 159 | window.location.reload(true);
|
---|
| 160 | }
|
---|
| 161 | else
|
---|
| 162 | {
|
---|
| 163 | for (var key in result.errors)
|
---|
| 164 | {
|
---|
| 165 | //console.log(result.errors[key]);
|
---|
| 166 | $('#'+key).html(result.errors[key]);
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | },
|
---|
| 171 |
|
---|
| 172 | });
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | function changePassword()
|
---|
| 176 | {
|
---|
| 177 | $('#passwd_old_err').html("");
|
---|
| 178 | $('#passwd_new_err').html("");
|
---|
| 179 | $('#confirm_passwd_new_err').html("");
|
---|
| 180 | $.ajax({
|
---|
| 181 | url: "doi_mat_khau",
|
---|
| 182 | type: "POST",
|
---|
| 183 | data: $("#frm2").serialize(),
|
---|
| 184 | success: function (data, textStatus, jqXHR)
|
---|
| 185 | {
|
---|
| 186 | result = jQuery.parseJSON(data);
|
---|
| 187 | if (result.success == "1")
|
---|
| 188 | {
|
---|
| 189 | window.location.reload(true);
|
---|
| 190 | }
|
---|
| 191 | else
|
---|
| 192 | {
|
---|
| 193 | for (var key in result.errors)
|
---|
| 194 | {
|
---|
| 195 | //console.log(result.errors[key]);
|
---|
| 196 | $('#'+key).html(result.errors[key]);
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | },
|
---|
| 201 |
|
---|
| 202 | });
|
---|
| 203 | } |
---|