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

Last change on this file since 398 was 398, checked in by namnd, 11 years ago
File size: 2.7 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
76$('#deleteAdmin').on('show.bs.modal', function(e) {
77        var id = $(e.relatedTarget).data('admin-id');
78        //$(e.currentTarget).find('input[name="id"]').val(id);
79        $(".btn#delete").click(function(){
80                $.ajax({
81                        url: "quan_tri_vien/xoa/" + id,
82                        type: "POST",
83                        success: function (data, textStatus, jqXHR)
84                        {
85                                result = jQuery.parseJSON(data)
86                                if (result.success=="1"){
87                                        filter();
88                                        $('#deleteAdmin').modal('hide');
89                                }else
90                                {
91                                        console.log("Delete error !");
92                                }
93                        }
94                });
95        });
96});
97
98(function($){
99    $.fn.setCursorToTextEnd = function() {
100        $initialVal = this.val();
101        this.val($initialVal + ' ');
102        this.val($initialVal);
103    };
104})(jQuery);
105
106function clearFormFields(id){
107        $(id).find('input:text, input:hidden, input:password, input:file, select, textarea').val('');
108        $(id).find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
109                $(id).find('.help-block').html("");
110}
111
112$('body').on('hidden.bs.modal', '.modal', function () {
113        clearFormFields('#add_frm');
114        clearFormFields('#edit_frm');
115        clearFormFields('#delete_frm');
116});
Note: See TracBrowser for help on using the repository browser.