summaryrefslogtreecommitdiff
path: root/js/codeq/profile.js
blob: 133c947f820045f13776e8dd8727508f77c99950 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
 * Created by markop on 9/29/15.
 */

(function(){

    var jqBtnChangePass = $("#change_pass_profile");

    codeq.profile = {
    };

    codeq.globalStateMachine.register('profile',{
        'enter': function(){
            $("#screen_profile").css('display', '');
            $('#disabled').css('display', 'none');
            codeq.comms.getUserStat()
                .then(function (data) {
                    if (data.code !== 0) throw new Error('GetUserStat failed, code: ' + data.code + ', message: ' + data.message);
                    data = data.stat;

                    var columns = ['language', 'problem_group', 'problems_count', 'done', 'in_progress'],
                        labels = ['Language', 'Problem group', 'All', 'Done', 'In progress'],
                        items='<thead><tr>',
                        tr_gui = codeq.tr.getDictionary('gui');

                    console.log(tr_gui);

                    $.each(columns, function( key, val ) {
                        items+='<th data-tkey="'+ val + '">'+tr_gui[val][codeq.settings['gui_lang']]+'</th>';
                    });
                    items+='</tr></thead>';

                    $.each( data, function( object, row ) {
                        items+='<tr>';
                        if(row['problem_group']) {
                            $.each( columns, function( key, val ) {
                                items+='<td style="white-space: nowrap">'+row[val]||""+'</td>';
                            });
                        }
                        else {
                            $.each( columns, function( key, val ) {
                                items+='<td style="white-space: nowrap"><strong>'+(row[val]==null?'(all)':row[val])+'</strong></td>';
                            });
                        }
                        items+='</td>';
                    });

                    $('#table1').html(items)

                })
                .fail(function (reason) {
                    codeq.log.error('GetUserStat failed: ' + reason, reason);
                    alert('GetUserStat failed: ' + reason);
                })
                .done();
            jqBtnChangePass.on('click',function(){
                codeq.globalStateMachine.transition('changePassword');
            });
        },
        'exit' : function(){
            $("#screen_profile").css('display', 'none');
            jqBtnChangePass.off('click');
        }
    });
})();