aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/notice.js
blob: 4389d40692d0c7f49f17da6130e2c93ef53c0309 (plain) (blame)
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
66
67
68
69
var notice = new function(){
    var that = this;
    var j_noticetag;
    var j_noticelist;

    that.ready = function(){
        function _set_unseen_count(count){
            if(count == 0){
                j_noticetag.removeClass('notice_hl');
            }else{
                j_noticetag.addClass('notice_hl');
            }
            j_noticetag.text('[' + count + ']');
        }

        j_noticetag = $('#index_paneltag > div.notice');
        j_noticelist = $('#index_panel > div.notice');

        j_noticetag.on('click',function(e){
            j_noticelist.empty();

            com.call_backend('core/notice/','list_notice',function(result){
                var i;
                var data = result.data;
                var notice;
                var j_item;

                if(com.is_callerr(result)){
                    index.add_alert('','警告','通知發生錯誤');
                }else{       
                    for(i = 0;i < data.length;i++){
                        notice = data[i];

                        j_item = $('<a class="list-group-item"><h5></h5><p></p></a>'); 
                        j_item.find('h5').text(notice.title);
                        j_item.find('p').text(notice.content);

                        if(notice.noticemodid == null){
                            j_item.attr('href','/toj' + notice.metadata); 
                        }

                        j_noticelist.append(j_item);
                    }
                }
            });
        });
        
        user.datachg_callback.add(function(type){
            if(type == 'login'){
                imc.Proxy.instance.register_call('core/notice/','update_notice',function(callback,unseen_count){
                    _set_unseen_count(unseen_count);
                    callback('Success');
                });

                com.call_backend('core/notice/','get_unseen_count',function(result){
                    var data = result.data;

                    if(com.is_callerr(result)){
                        index.add_alert('','警告','通知發生錯誤');
                    }else{
                        _set_unseen_count(data.unseen_count);
                    }         
                });

                j_noticetag.show();
            }
        });
    };
};