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

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