source: pro-violet-viettel/sourcecode/assets/js/frontend/user.js @ 906

Last change on this file since 906 was 906, checked in by namnd, 10 years ago
File size: 9.6 KB
Line 
1function updateInfo(us_id) {
2    $.ajax({
3        url: '/frontend/user/update_user/' + us_id,
4        type: 'POST',
5        data: $("#frm1").serialize(),
6        success: function (data, textStatus, jqXHR)
7        {
8            result = jQuery.parseJSON(data);
9            if (result.success == "1")
10            {
11                                $("#updateInfoSuccess").modal('show');
12                                $("#close").click(function(){
13                                        window.location.reload(true);
14                                });
15               
16            }
17            else
18            {
19                for (var key in result.errors)
20                {
21                    $('#' + key).html(result.errors[key]);
22                }
23            }
24        }
25    });
26}
27$("#package_register").submit(function (event)
28{
29        //console.log($(this).attr("action"));
30    $.ajax({
31        url: $(this).attr("action"),
32        type: "POST",
33        data: $("#package_register").serialize(),
34        success: function (data, textStatus, jqXHR)
35        {
36
37            var results = jQuery.parseJSON(data);
38                       
39            $('#package_register_modal').replaceWith(results.modal);
40            $('#package_register_modal').modal('show');
41            $("#package_register_back").click(function () {
42                $("#account-info-tab").click();
43            });
44                       
45                       
46                        if ($(".form-field-province").val() !== 'undefined'){
47                                checkSelectedDistrict();
48                        }
49                        $(".form-field-province").change(function(){
50                                changeEventProvince();
51                        });
52                       
53                       
54                       
55            $("#finish_package_register").click(function () {
56                finish_package_register();
57            });
58
59        },
60        error: function (jqXHR, textStatus, errorThrown)
61        {
62            $(".ajaxloading").hide();
63        }
64    });
65    event.preventDefault();
66});
67
68function finish_package_register()
69{
70    $("#package_register_errors").html("");
71    $.ajax({
72        url: url + "frontend/user/finishRegisterPackage",
73        type: "POST",
74        data: $("#do_package_register").serialize(),
75        success: function (data, textStatus, jqXHR)
76        {
77            var results = jQuery.parseJSON(data);
78            if (results.success == "1")
79            {
80                $("#package_register_modal").modal("hide");
81                $("#success_package_register_content").html(results.message);
82                $("#success_package_register_modal").modal("show");
83               
84                $("#package_register_finish_button").click(function () {
85                window.location.href = url+"frontend/user/profile/services-register";
86               
87            });
88            }
89            else
90            {
91                var er = "<div class=\"alert alert-block alert-success\">";
92                for (var i = 0; i < results.errors.length; i++)
93                {
94                    var item = results.errors[i];
95                    er=er+""+item+"<br />";
96                }
97                $("#package_register_errors").prepend(er+"</div>");
98            }
99        },
100        error: function (jqXHR, textStatus, errorThrown)
101        {
102            $(".ajaxloading").hide();
103        }
104    });
105}
106$("#add_money").click(function () {
107    $("#account-info-tab").click();
108});
109$("#"+current_tab+"-tab").click();
110 
111
112function changePassword(us_id)
113{
114        $('#passwd_old_err').html("");
115        $('#passwd_new_err').html("");
116        $('#confirm_passwd_new_err').html("");
117        $.ajax({
118                url: url+'frontend/user/change_password/' + us_id,
119                type: 'POST',
120                data: $("#frm2").serialize(),
121                success: function (data, textStatus, jqXHR)
122                {       
123                        result = jQuery.parseJSON(data);
124                        if (result.success == "1")
125                        {   
126                                $("#changePassSuccess").modal('show');
127                        }
128                        else
129                        {
130                                for (var key in result.errors)
131                                {
132                                        $('#'+key).html(result.errors[key]);
133                                }
134                        }
135                }
136        });
137}
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('#frm2');
147});
148
149function chargeCard(id)
150{
151        $("#charging").css('display', 'block');
152        $('#btn-charge').attr("disabled", true);
153        $.ajax({
154                url: '/services/recharge/recharge_card/'+id,
155                type: 'POST',
156                data: $("#frm3").serialize(),
157                success: function (data, textStatus, jqXHR)
158                {       
159                        $("#pin_card").val('');
160                        $("#card_serial").val('');
161                        $("#charging").css('display', 'none');
162                        $('#btn-charge').attr("disabled", false);
163                        result = jQuery.parseJSON(data);
164                        if(result.success == "1")
165                        {
166                                //$("#success_charge").find('#success_charge_info > center').text("QuÜ vị đã nạp thành cÃŽng " + result.amount + " VNĐ vào tài khoản " + result.username + ", tài khoản ảo cá»§a QuÜ vị là " + result.acc_balanced + " VNĐ!");
167                                $("#success_charge").find('#success_charge_info > center').text(result.message);
168                                $("#success_charge").modal('show');
169                                $("#vip-regis-money").text(addCommas(result.acc_balanced));
170                                $("#topup-money").text(addCommas(result.acc_balanced) + ' VNĐ');                       
171                        }else
172                        {
173                                $("#not_success_charge").find('div#no_success_charge_info > center').html (result.errMsg);
174                                $("#not_success_charge").modal('show');
175                        }
176                       
177                }
178        });
179}
180
181function tradeHistory(id, page)
182{
183        $.ajax({
184                url: '/frontend/user/trade_history/'+id +'/page/'+page,
185                type: 'POST',
186                success: function(data)
187                {
188                        results = jQuery.parseJSON(data);
189                        paging = results.paging;
190                        result = results.paidlogs;
191                        content = "";
192                        if(result.length>0){
193                                for (var i in result)
194                                {
195                                        content += '<tr><td class="center">'+result[i].source+'</td><td class="center">'+result[i].amount+'</td><td>'+result[i].paid_time+'</td></tr>';
196                                       
197                                }
198                        }else
199                        {
200                                content += '<tr><td class="center" colspan=4>Chưa có giao dịch nào!</td></tr>';
201                        }
202                        $("#trade-history").find("#content-trade-histoty").html(content);
203                        $("#trade-history").find(".pagination").html(paging);
204                         $(".ajax_paging").click(function ()
205                         {
206                                $.ajax({
207                                        url: $(this).attr("href"),
208                                        type: "POST",
209                                        success: function (data, textStatus, jqXHR)
210                                        {
211                                                results = jQuery.parseJSON(data);
212                                                tradeHistory(id, results.current_page);
213                                        },
214                                        error: function ()
215                                        {
216                                                $(".ajaxloading").hide();
217                                        }
218                                });
219                                return false;
220                         });
221                        $("#trade-history").modal('show');
222                }
223        });
224}
225
226function regisHistory(id, page)
227{
228        $.ajax({
229                url: '/frontend/user/regis_history/'+id +'/page/'+page,
230                type: 'POST',
231                success: function(data)
232                {
233                   
234                        results = jQuery.parseJSON(data);
235                        paging = results.paging;
236                        result = results.packagelogs;
237                        content = "";
238                        if(result.length>0){
239                                for (var i in result)
240                                {
241                                        source = result[i].source;
242                                        if (result[i].source == null || result[i].source == '') source = 'Thẻ cào';
243                                        content += '<tr><td class="center">'+source+'</td><td class="center">'+result[i].amount+'</td><td class="center">'+result[i].p_name+'</td><td>'+result[i].created_time+'</td></tr>';
244                                       
245                                }
246                        }else
247                        {
248                                content += '<tr><td class="center" colspan=3>Chưa đăng kí gói dịch vụ nào!</td></tr>';
249                        }
250                        $("#regis-history").find("#content-regis-histoty").html(content);
251                        $("#regis-history").find(".pagination").html(paging);
252                         $(".ajax_paging").click(function ()
253                         {
254                                $.ajax({
255                                        url: $(this).attr("href"),
256                                        type: "POST",
257                                        success: function (data, textStatus, jqXHR)
258                                        {
259                                                results = jQuery.parseJSON(data);
260                                                regisHistory(id, results.current_page);
261                                        },
262                                        error: function ()
263                                        {
264                                                $(".ajaxloading").hide();
265                                        }
266                                });
267                                return false;
268                         });
269                        $("#regis-history").modal('show');
270                }
271        });
272}
273
274function addCommas(nStr)
275{
276        nStr += '';
277        x = nStr.split('.');
278        x1 = x[0];
279        x2 = x.length > 1 ? '.' + x[1] : '';
280        var rgx = /(\d+)(\d{3})/;
281        while (rgx.test(x1)) {
282                x1 = x1.replace(rgx, '$1' + ',' + '$2');
283        }
284        return x1 + x2;
285}
286
287function checkSelectedDistrict(){
288        provinceId = $(".form-field-province").val();
289        $.ajax({
290        url: '/frontend/user/getDistrict/' + provinceId,
291        type: 'POST',
292        success: function (data, textStatus, jqXHR)
293        {
294            result = jQuery.parseJSON(data);   
295                        content = "";
296                        if (result != null){
297                                for (var i in result){
298                                        if (result[i].district_id === district_id){
299                                                content = content + '<option value="' + result[i].district_id + '" selected >' + result[i].type + " " + result[i].district_name + '</option>';
300                                        }else{
301                                                content = content + '<option value="' + result[i].district_id + '">' + result[i].type + " "  + result[i].district_name + '</option>';
302                                        }
303                                }
304                               
305                        }
306                        $(".form-field-district").html(content);
307        }
308    });
309}
310
311function changeEventProvince(){
312        $(".form-field-district").html("");
313        provinceId = $("#form-field-province").val();
314        $.ajax({
315        url: '/frontend/user/getDistrict/' + provinceId,
316        type: 'POST',
317        success: function (data, textStatus, jqXHR)
318        {
319            result = jQuery.parseJSON(data);
320                        content = "<option></option>";
321                        if (result != null){
322                                for (var i in result){                 
323                                        content = content + '<option value="' + result[i].district_id + '">'+ result[i].type + " "  + result[i].district_name + '</option>'
324                                }
325                               
326                        }
327                        $(".form-field-district").html(content);
328        }
329    });
330}
331$(document).ready(function(){
332        if ($(".form-field-province").val() !== 'undefined'){
333                checkSelectedDistrict();
334        }
335        $(".form-field-province").change(function(){
336                changeEventProvince();
337        });
338});
Note: See TracBrowser for help on using the repository browser.