-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathmynotice.js
More file actions
98 lines (90 loc) · 2.86 KB
/
mynotice.js
File metadata and controls
98 lines (90 loc) · 2.86 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
$(document).ready(function() {
$('#notice_prev_button').prop('disabled', true);
$('#notice_next_button').prop('disabled', true);
$('#showagain').prop('checked', false);
var shown = 0;
var notices = [];
var showNotice = function(notice) {
parseMarkdown(notice.title, notice.message, '#notice_content_area', '#notice_title_area').then(function() {
return processMathJax('#notice_content_area');
}).then(function() {
return processMermaid();
});
if (notice.showNextTime) {
$('#showagain').prop('checked', true);
} else {
$('#showagain').prop('checked', false);
}
readMark(notice.no, notice.showNextTime);
};
var readMark = function(no, showNextTime) {
if (_LOGIN_USER_ID) {
if (!showNextTime) {
showNextTime = 0;
} else {
showNextTime = 1;
}
var url = _CONTEXT + '/open.api/readmark/' + no + '?showNextTime=' + showNextTime;
$.ajax({
type : 'put',
url : url
}).then(function(success) {
console.log(success);
}, function(err) {
console.log(err);
});
}
};
var loadList = function () {
$.ajax({
type : 'get',
url : _CONTEXT + '/open.api/mynotices'
}).then(function(items) {
notices = items;
console.log(notices);
if (notices.length > 0) {
showNotice(notices[shown]);
$('#noticeModal').modal('show');
if (notices.length > 1) {
$('#notice_next_button').prop('disabled', false);
}
}
}, function(err) {
console.log(err);
});
};
$('#notice_next_button').click(function() {
shown++;
var notice = notices[shown];
if (notice) {
showNotice(notice);
$('#notice_prev_button').prop('disabled', false);
if (notices.length <= shown + 1) {
$('#notice_next_button').prop('disabled', true);
}
}
});
$('#notice_prev_button').click(function() {
shown--;
var notice = notices[shown];
if (notice) {
showNotice(notice);
$('#notice_next_button').prop('disabled', false);
if (shown === 0) {
$('#notice_prev_button').prop('disabled', true);
}
}
});
$('#showagain').on('change', function () {
var notice = notices[shown];
if (!notice) {
return;
}
if ($(this).prop('checked')) {
readMark(notice.no, 1);
} else {
readMark(notice.no, 0);
}
});
loadList();
});