source: pro-violet-viettel/sourcecode/assets/js/admin/admin.js @ 690

Last change on this file since 690 was 424, checked in by namnd, 11 years ago
File size: 4.4 KB
Line 
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;
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']);
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",
60                        data: $("#edit_frm").serialize(),
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
76function 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                        {       
91                                console.log("Update error");
92                        }
93                },
94                error: function (jqXHR, textStatus, errorThrown)
95                {
96                        $(".ajaxloading").hide();
97                }
98        });
99        return false;
100}
101
102$('#deleteAdmin').on('show.bs.modal', function(e) {
103        var id = $(e.relatedTarget).data('admin-id');
104        var us = $(e.relatedTarget).data('admin-us');
105        //$(e.currentTarget).find('input[name="id"]').val(id);
106        $("#us").html(us);
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        });
124});
125
126(function($){
127    $.fn.setCursorToTextEnd = function() {
128        $initialVal = this.val();
129        this.val($initialVal + ' ');
130        this.val($initialVal);
131    };
132})(jQuery);
133
134function 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});
145
146function 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
175function 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}
Note: See TracBrowser for help on using the repository browser.