This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activities.ejs
453 lines (426 loc) · 12.2 KB
/
activities.ejs
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<script>
$('#id_core_well_news')
.click(function(e){
e.stopPropagation();
})
.on('hidden.bs.collapse',function(){
$('#id_navbar_news').parent().removeClass('active');
})
socket.emit('populate activities',function(o){
for (var i = 0; i<o.data.length; i++){
arrDelay.push(false);
arrData.push(o.data[i]);
}
for (var j = 0; j<o.data.length; j++){
decodeJson(o.data[j],j,function(string,_int){
arrDelay.splice(0,1);
o.user.notes1.replace(/subscription:.*?;/,function(s){
var sPruned = s.replace(/subscription:|\;/g,'');
if(sPruned.replace(/ /g,'')!=''){
var ssplit = sPruned.split(',');
for (var k = 0; k<ssplit.length; k++){
var patt = new RegExp(ssplit[k]);
if(patt.test(string)||ssplit[k]=='all'){
jsonString[_int] = string;
break;
}
}
}
})
populateActivities(o.data.length);
});
}
})
var arrData = []
var arrDelay = [];
var jsonString = {};
function populateActivities(l){
if(arrDelay.length!=0){
return;
}
var maxNews = 10;
for(var i = 0; i<l; i++){
if(jsonString[i]&&maxNews!=0){
$('#id_activities_div_activities').append(jsonString[i]);
maxNews--;
}
}
bindActivities();
decodeUsername(null);
}
socket.on('receive news',function(o){
decodeJson(o,null,function(string,_int){
$('#id_activities_div_activities').prepend(string);
decodeUsername(null);
if(!$('#id_core_well_news').hasClass('in')){
redPill('add','#id_navbar_news')
}
bindActivities();
})
})
function decodeJson(json,j,cb){
var stringOut = '';
if(/\{\{.*?\}\}/.test(json.requester)){
/*
stringOut = '<div class = "row">'+
'<div class = "alert alert-'+name+'">'+
escapeHtml(comment)+
' <span class = "text-muted">(' + +escapeHtml(timestamp.split('T')[0])+' '+escapeHtml(timestamp.split('T')[1].split('.')[0])+')</span>'+
'</div>'+
'</div>'
*/
}else{
stringOut += '<span class = "hidden class_core_span_userName">'+escapeHtml(json.requester)+'</span>';
var auxClass = '';
switch(json.mode){
case 'admin':
auxClass = 'side-info';
var ssplit = json.notes1.split(' ');
switch(ssplit[0]){
case 'approve':
stringOut += ' approved a submission.'
break;
case 'reject':
stringOut += ' rejected a submission.'
break;
case 'undo':
stringOut += ' undid a change.'
break;
default:
break;
}
cb(infoStyler(stringOut,json,auxClass),j);
break;
case 'add submit':
auxClass = 'side-primary';
stringOut += ' added a new question';
moreInfo(json.id,function(o){
if(o.error){
info_modal(o.error);
}else{
stringOut += ' under <strong>' + escapeHtml(o.data.subject) +'</strong>';
cb(infoStyler(stringOut,json,auxClass),j);
}
})
break;
case 'add new curriculum':
auxClass = 'side-success';
moreInfo(json.id,function(o){
stringOut += ' added a new curriculum named <strong>' + escapeHtml(o.data) + '</strong>';
cb(infoStyler(stringOut,json,auxClass),j);
})
break;
case 'add dp':
auxClass = 'side-success';
moreInfo(json.id,function(o){
stringOut += ' added a new dot point <strong>'+escapeHtml(o.data.value)+'</strong> under the syllabus named <strong>' + escapeHtml(o.data.target_syl) + '</strong>';
cb(infoStyler(stringOut,json,auxClass),j);
})
break;
case 'categorise':
auxClass = 'side-success';
moreInfo(json.id,function(o){
if(o.error){
info_modal(o.error);
}else{
switch(o.data.mode){
case 'add':
stringOut += ' categorised an existing question under';
break;
case 'delete':
stringOut += ' removed the categorisation of an existing question from'
break;
default:
stringOut += ' did something in categorisation with'
break;
}
stringOut += ' <strong>' + escapeHtml(o.data.target_syl) + ' : ' + escapeHtml(o.data.lvl) +'</strong>';
cb(infoStyler(stringOut,json,auxClass),j);
}
})
break;
case 'save':
auxClass = 'side-warning';
stringOut += ' updated an existing question';
moreInfo(json.id,function(o){
if(o.error){
info_modal(o.error);
}else{
stringOut += ' under <strong>' + escapeHtml(o.data.subject) +'</strong>';
cb(infoStyler(stringOut,json,auxClass),j);
}
})
break;
case 'remove':
auxClass = 'side-danger';
stringOut += ' removed an existing question';
moreInfo(json.id,function(o){
if(o.error){
info_modal(o.error);
}else{
stringOut += ' under <strong>' + escapeHtml(o.data.subject) +'</strong>';
cb(infoStyler(stringOut,json,auxClass),j);
}
})
break;
default:
stringOut += ' did something'
cb(stringOut,j)
break;
}
}
}
function infoStyler(stringOut,json,auxClass){
if(json.mode!='admin'){
if(!/true/.test(json.notes1)){
if(/approve|reject/.test(json.notes1)){
json.notes1.replace(/approve.*?\;|reject.*?\;/,function(s){
var ssplit = s.replace(';','').split(':');
stringOut += ' (' + ssplit[0] + ' by <span class = "hidden class_core_span_userName">'+escapeHtml(ssplit[1])+'</span>)'
})
}else{
stringOut += ' (pending approval)'
}
}else{
if(/undo/.test(json.notes1)){
json.notes1.replace(/undo [0-9]*/,function(s){
stringOut += ' (undone by <span class = "hidden class_core_span_userName">'+s.replace(/ |undo/g,'')+'</span>)'
})
}
}
}
return '<div class = "col-xs-12 col-sm-12 col-md-12 col-lg-12 side '+auxClass+'" id="id_activities_alert_'+json.id+'">'+stringOut+'<% if (user){} %></div>';
}
function moreInfo(id,cb){
$.ajax({
type : 'GET',
url : 'reqlog/'+id+'.json',
success : function(o){
cb(o)
}
})
}
function bindActivityModalBtn(row){
$('#id_core_modal_activityPreviewer').click(function(e){
e.stopPropagation();
})
if(!row||/approve|reject|undo/.test(row.notes1)){
$('#id_core_modal_activityPreviewer').find('div.btn-primary').addClass('disabled');
$('#id_core_modal_activityPreviewer').find('div.btn-success').addClass('disabled');
$('#id_core_modal_activityPreviewer').find('div.btn-danger').addClass('disabled');
}else if(/true/.test(row.notes1)){
/* need to test if approved/rejected */
$('#id_core_modal_activityPreviewer').find('div.btn-primary').removeClass('disabled');
$('#id_core_modal_activityPreviewer').find('div.btn-success').addClass('disabled');
$('#id_core_modal_activityPreviewer').find('div.btn-danger').addClass('disabled');
}else{
$('#id_core_modal_activityPreviewer').find('div.btn-primary').addClass('disabled');
$('#id_core_modal_activityPreviewer').find('div.btn-success').removeClass('disabled');
$('#id_core_modal_activityPreviewer').find('div.btn-danger').removeClass('disabled');
}
$('#id_core_modal_activityPreviewer').find('div.btn-default').removeClass('disabled');
$('#id_core_modal_activityPreviewer').find('div.btn').off('click').click(function(){
if($(this).hasClass('disabled')){
return;
}
$(this).addClass('disabled');
var _this = $(this);
var json = {}
var successMessage;
switch($(this).attr('id')){
case 'id_core_btn_previewerUndo':
json.mode = 'undo';
successMessage = 'Action undone.';
break;
case 'id_core_btn_previewerReject':
json.mode = 'reject';
successMessage = 'Submission rejected.';
break;
case 'id_core_btn_previewerApprove':
json.mode = 'approve';
successMessage = 'Submission approved.';
break;
default:
break;
}
json.target = row.id;
socket.emit('admin moderation',json,function(o){
if(o.error){
info_modal(o.error)
}else{
_this.removeClass('disabled');
$('#id_core_modal_activityPreviewer').modal('hide');
info_modal(successMessage);
}
})
})
}
function bindActivities(){
$('#id_activities_div_activities div.side')
/* http://stackoverflow.com/questions/805133/how-do-i-unbind-hover-in-jquery */
/* so I can't just go $(this).off('hover') huh... */
.unbind('mouseenter mouseleave')
.hover(function(){
$(this).animate({'background-color':'#efefef'},100)
},function(){
$(this).animate({'background-color':'#fff'},300)
})
.off('click').click(function(){
$('#id_core_modal_activityPreviewer').find('div.modal-body').empty();
$('#id_core_modal_activityPreviewer').modal('show')
socket.emit('ping activity',$(this).attr('id').split('_')[3],function(o){
if(o.error){
info_modal(o.error);
}else{
bindActivityModalBtn(o.row);
decodeJson(o.row,null,function(string){
$('#id_core_modal_activityPreviewer').find('div.modal-body').append('<div class = "row">'+string+'</div><hr>');
decodeUsername(null);
if(o.row.mode!='admin'){
if(o.json.question){
$('#id_core_modal_activityPreviewer').find('div.modal-body').append(appendModalNews(o));
}else{
/* no question field in json, there should be a hashed_id field */
$.ajax({
type : 'POST',
url : 'pingQ',
data : {mode : 'all', hashed_id : o.json.hashed_id},
success : function(p){
console.log(p)
if(p.message=='failed'){
info_modal(p.reason)
}else{
var jsonIn = {row:o.row,json:p[0]}
$('#id_core_modal_activityPreviewer').find('div.modal-body').append(appendModalNews(jsonIn))
}
}
})
}
}
})
}
})
})
}
function appendModalNews(o){
var appendString;
if(o.overwritten){
appendString =
'<div class = "row">'+
'<div class = "col-xs-12 col-sm-12 col-md-12 col-lg-12">'+
'<div class = "panel panel-success">'+
'<div class = "panel-heading"><span class = "glyphicon glyphicon-ok"></span> newly saved'+
'</div>'+
'<div class = "panel-body">'+
'<div class = "row">'+
'<div class = "col-xs-12 col-sm12 col-md-12 col-lg-12">'+parsing_preview(o.json.question,o.json.hashed_id)+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'<hr>'+
'<div class = "col-xs-12 col-sm-12 col-md-12 col-lg-12">'+
'<div class = "panel panel-danger">'+
'<div class = "panel-heading"><span class = "glyphicon glyphicon-remove"></span> discarded'+
'</div>'+
'<div class = "panel-body">'+
'<div class = "row">'+
'<div class = "col-xs-12 col-sm-12 col-md-12 col-lg-12">'+parsing_preview(o.overwritten.question,o.overwritten.hashed_id)+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>';
}else{
var auxClass;
var doNotShow = '';
var parsePreview = [];
switch(o.row.mode){
case 'add submit':
auxClass = 'primary';
glyphClass = 'plus';
title = 'newly submitted';
break;
case 'categorise':
auxClass = 'success';
glyphClass = 'tags';
title = 'newly categorised';
break;
case 'remove':
auxClass = 'danger';
glyphClass = 'remove';
title = 'removed';
break;
default:
doNotShow = 'hidden';
auxClass = 'default';
glyphClass = 'info-sign';
title = 'information';
break;
}
appendString =
'<div class = "row">'+
'<div class = "col-xs-12 col-sm-12 col-md-12 col-lg-12">'+
'<div class = "'+doNotShow+' panel panel-'+auxClass+'">'+
'<div class = "panel-heading"><span class = "glyphicon glyphicon-'+glyphClass+'"></span> '+ title +
'</div>'+
'<div class = "panel-body">'+
'<div class = "row">'+
'<div class = "col-xs-12 col-sm12 col-md-12 col-lg-12">'+parsing_preview(o.json.question,o.json.hashed_id)+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>';
}
return appendString;
}
</script>
<style>
#id_activities_div_activities .side:hover
{
cursor:pointer;
}
.side
{
padding-top:25px;
padding-bottom:20px;
margin-bottom:1px;
margin-left:1px;
border-left:10px solid;
}
.side-primary
{
border-color: #428bca;
}
.side-success
{
border-color: #5cb85c;
}
.side-info
{
border-color: #5bc0de;
}
.side-danger
{
border-color: #d9534f;
}
.side-default
{
border-color: #f9f9f9;
}
.side-warning
{
border-color: #fcf8e3;
}
</style>
<div class = "row">
<div id = "id_activities_div_activities" class = "col-xs-12 col-sm-12 col-md-12 col-lg-12">
</div>
<div class = "btn btn-link col-xs-12 col-sm-12 col-md-12 col-lg-12 text-center">
see more activities (to be implemented)
</div>
</div>