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

Last change on this file since 423 was 423, checked in by namnd, 11 years ago
File size: 3.4 KB
RevLine 
[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]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                                /*
92                                for(var i =0;i < $result.errors.length;i++)
93                                {
94                                  var er= $result.errors[i];
95                                  $("#add_user_"+id).append("<div class='error'>"+er+"</div>");
96                                }*/
97                        }
98                },
99                error: function (jqXHR, textStatus, errorThrown)
100                {
101                        $(".ajaxloading").hide();
102                }
103        });
104        return false;
105}
106
[375]107$('#deleteAdmin').on('show.bs.modal', function(e) {
108        var id = $(e.relatedTarget).data('admin-id');
[416]109        var us = $(e.relatedTarget).data('admin-us');
[375]110        //$(e.currentTarget).find('input[name="id"]').val(id);
[416]111        $("#us").html(us);
[375]112        $(".btn#delete").click(function(){
113                $.ajax({
114                        url: "quan_tri_vien/xoa/" + id,
115                        type: "POST",
116                        success: function (data, textStatus, jqXHR)
117                        {
118                                result = jQuery.parseJSON(data)
119                                if (result.success=="1"){
120                                        filter();
121                                        $('#deleteAdmin').modal('hide');
122                                }else
123                                {
124                                        console.log("Delete error !");
125                                }
126                        }
127                });
128        });
[384]129});
130
131(function($){
132    $.fn.setCursorToTextEnd = function() {
133        $initialVal = this.val();
134        this.val($initialVal + ' ');
135        this.val($initialVal);
136    };
[398]137})(jQuery);
138
139function clearFormFields(id){
140        $(id).find('input:text, input:hidden, input:password, input:file, select, textarea').val('');
141        $(id).find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
142                $(id).find('.help-block').html("");
143}
144
145$('body').on('hidden.bs.modal', '.modal', function () {
146        clearFormFields('#add_frm');
147        clearFormFields('#edit_frm');
148        clearFormFields('#delete_frm');
149});
[423]150
151$("#edit_tab").click(function(){
152});
Note: See TracBrowser for help on using the repository browser.