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

Last change on this file since 838 was 838, 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                                checkSelecteDistrict();
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                console.log(data);
124                        result = jQuery.parseJSON(data);
125                        if (result.success == "1")
126                        {   
127                                $("#changePassSuccess").modal('show');
128                        }
129                        else
130                        {
131                                for (var key in result.errors)
132                                {
133                                        $('#'+key).html(result.errors[key]);
134                                }
135                        }
136                }
137        });
138}
139
140function clearFormFields(id){
141        $(id).find('input:text, input:hidden, input:password, input:file, select, textarea').val('');
142        $(id).find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
143                $(id).find('.help-block').html("");
144}
145
146$('body').on('hidden.bs.modal', '.modal', function () {
147        clearFormFields('#frm2');
148});
149
150function chargeCard(id)
151{
152        $("#charging").css('display', 'block');
153        $('#btn-charge').attr("disabled", true);
154        $.ajax({
155                url: '/services/recharge/recharge_card/'+id,
156                type: 'POST',
157                data: $("#frm3").serialize(),
158                success: function (data, textStatus, jqXHR)
159                {       
160                        $("#pin_card").val('');
161                        $("#card_serial").val('');
162                        $("#charging").css('display', 'none');
163                        $('#btn-charge').attr("disabled", false);
164                        result = jQuery.parseJSON(data);
165                        if(result.success == "1")
166                        {
167                                //$("#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Đ!");
168                                $("#success_charge").find('#success_charge_info > center').text(result.message);
169                                $("#success_charge").modal('show');
170                                $("#vip-regis-money").text(addCommas(result.acc_balanced));
171                                $("#topup-money").text(addCommas(result.acc_balanced) + ' VNĐ');                       
172                        }else
173                        {
174                                $("#not_success_charge").find('div#no_success_charge_info > center').html (result.errMsg);
175                                $("#not_success_charge").modal('show');
176                        }
177                       
178                }
179        });
180}
181
182function tradeHistory(id, page)
183{
184        $.ajax({
185                url: '/frontend/user/trade_history/'+id +'/page/'+page,
186                type: 'POST',
187                success: function(data)
188                {
189                        results = jQuery.parseJSON(data);
190                        paging = results.paging;
191                        result = results.paidlogs;
192                        content = "";
193                        if(result.length>0){
194                                for (var i in result)
195                                {
196                                        content += '<tr><td class="center">'+result[i].source+'</td><td class="center">'+result[i].amount+'</td><td>'+result[i].paid_time+'</td></tr>';
197                                       
198                                }
199                        }else
200                        {
201                                content += '<tr><td class="center" colspan=4>Chưa có giao dịch nào!</td></tr>';
202                        }
203                        $("#trade-history").find("#content-trade-histoty").html(content);
204                        $("#trade-history").find(".pagination").html(paging);
205                         $(".ajax_paging").click(function ()
206                         {
207                                $.ajax({
208                                        url: $(this).attr("href"),
209                                        type: "POST",
210                                        success: function (data, textStatus, jqXHR)
211                                        {
212                                                results = jQuery.parseJSON(data);
213                                                tradeHistory(id, results.current_page);
214                                        },
215                                        error: function ()
216                                        {
217                                                $(".ajaxloading").hide();
218                                        }
219                                });
220                                return false;
221                         });
222                        $("#trade-history").modal('show');
223                }
224        });
225}
226
227function regisHistory(id, page)
228{
229        $.ajax({
230                url: '/frontend/user/regis_history/'+id +'/page/'+page,
231                type: 'POST',
232                success: function(data)
233                {
234                   
235                        results = jQuery.parseJSON(data);
236                        paging = results.paging;
237                        result = results.packagelogs;
238                        content = "";
239                        if(result.length>0){
240                                for (var i in result)
241                                {
242                                        source = result[i].source;
243                                        if (result[i].source == null || result[i].source == '') source = 'Thẻ cào';
244                                        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>';
245                                       
246                                }
247                        }else
248                        {
249                                content += '<tr><td class="center" colspan=3>Chưa đăng kí gói dịch vụ nào!</td></tr>';
250                        }
251                        $("#regis-history").find("#content-regis-histoty").html(content);
252                        $("#regis-history").find(".pagination").html(paging);
253                         $(".ajax_paging").click(function ()
254                         {
255                                $.ajax({
256                                        url: $(this).attr("href"),
257                                        type: "POST",
258                                        success: function (data, textStatus, jqXHR)
259                                        {
260                                                results = jQuery.parseJSON(data);
261                                                regisHistory(id, results.current_page);
262                                        },
263                                        error: function ()
264                                        {
265                                                $(".ajaxloading").hide();
266                                        }
267                                });
268                                return false;
269                         });
270                        $("#regis-history").modal('show');
271                }
272        });
273}
274
275function addCommas(nStr)
276{
277        nStr += '';
278        x = nStr.split('.');
279        x1 = x[0];
280        x2 = x.length > 1 ? '.' + x[1] : '';
281        var rgx = /(\d+)(\d{3})/;
282        while (rgx.test(x1)) {
283                x1 = x1.replace(rgx, '$1' + ',' + '$2');
284        }
285        return x1 + x2;
286}
287
288function checkSelecteDistrict(){
289        provinceId = $(".form-field-province").val();
290        $.ajax({
291        url: '/frontend/user/getDistrict/' + provinceId,
292        type: 'POST',
293        success: function (data, textStatus, jqXHR)
294        {
295            result = jQuery.parseJSON(data);   
296                        content = "";
297                        if (result != null){
298                                for (var i in result){
299                                        if (result[i].district_id === district_id){
300                                                content = content + '<option value="' + result[i].district_id + '" selected >' + result[i].type + " " + result[i].district_name + '</option>';
301                                        }else{
302                                                content = content + '<option value="' + result[i].district_id + '">' + result[i].type + " "  + result[i].district_name + '</option>';
303                                        }
304                                }
305                                $(".form-field-district").html(content);
306                        }
307        }
308    });
309}
310
311if ($(".form-field-province").val() !== 'undefined'){
312        checkSelecteDistrict();
313}
314
315function changeEventProvince(){
316        $(".form-field-district").html("");
317        provinceId = $("#form-field-province").val();
318        $.ajax({
319        url: '/frontend/user/getDistrict/' + provinceId,
320        type: 'POST',
321        success: function (data, textStatus, jqXHR)
322        {
323            result = jQuery.parseJSON(data);
324                        content = "";
325                        if (result != null){
326                                for (var i in result){                 
327                                        content = content + '<option value="' + result[i].district_id + '">'+ result[i].type + " "  + result[i].district_name + '</option>'
328                                }
329                                $(".form-field-district").html(content);
330                        }
331        }
332    });
333}
334
335$(".form-field-province").change(function(){
336        changeEventProvince();
337});
Note: See TracBrowser for help on using the repository browser.