Bill board feature up and running
This commit is contained in:
@ -124,6 +124,28 @@ main = (function(main, global) {
|
|||||||
Mousetrap.bind('g c', toggleMainChat);
|
Mousetrap.bind('g c', toggleMainChat);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function localStorageIO(item = '', input = null) {
|
||||||
|
if (input) {
|
||||||
|
try {
|
||||||
|
input = typeof input === 'string' ? input : JSON.stringify(input);
|
||||||
|
} catch (e) {
|
||||||
|
// Do Nothing
|
||||||
|
}
|
||||||
|
localStorage.setItem(item, input);
|
||||||
|
return input;
|
||||||
|
} else {
|
||||||
|
let data = localStorage.getItem(item);
|
||||||
|
try {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
} catch (e) {
|
||||||
|
// Do Nothing
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main.localStorageIO = localStorageIO;
|
||||||
|
|
||||||
return main;
|
return main;
|
||||||
}(main, window));
|
}(main, window));
|
||||||
|
|
||||||
@ -621,29 +643,26 @@ $(document).ready(function() {
|
|||||||
}).done((resp) => {
|
}).done((resp) => {
|
||||||
cb(resp);
|
cb(resp);
|
||||||
});
|
});
|
||||||
|
$('#dismissBill').on('click', (e) => {
|
||||||
|
const elemData
|
||||||
|
= e.target.parentNode.parentNode.children;
|
||||||
|
|
||||||
|
const res
|
||||||
|
= elemData[Object.keys(elemData).filter((key)=> {
|
||||||
|
return elemData[key].id === 'billContent';
|
||||||
|
|
||||||
|
})[0]].innerHTML;
|
||||||
|
|
||||||
|
main.localStorageIO('lastBillBoardSeen', res);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleNewBillBoard(message) {
|
function handleNewBillBoard(message) {
|
||||||
const seen = typeof localStorage.getItem('billboardSeen') !== "undefined" ? localStorage.getItem('billboardSeen') : 'false';
|
if (main.localStorageIO('lastBillBoardSeen') !== message.data) {
|
||||||
let old = typeof localStorage.getItem('billboard') !== "undefined" ? localStorage.getItem('billboard') : 'false';
|
$('#billContent').text(message.data);
|
||||||
if(seen !== 'true') {
|
$('#billBoard').fadeIn();
|
||||||
old = null;
|
|
||||||
}
|
|
||||||
if(message.data !== old) {
|
|
||||||
if(!message.err) {
|
|
||||||
$('#billContent').text(message.data);
|
|
||||||
localStorage.setItem('billboard', message.data)
|
|
||||||
} else {
|
|
||||||
console.error(message.err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentBillBoard(handleNewBillBoard);
|
getCurrentBillBoard(handleNewBillBoard);
|
||||||
|
|
||||||
$('#dismissBill').on('click', () => {
|
|
||||||
console.log("test");
|
|
||||||
localStorage.setItem('billboardSeen', 'true');
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -85,21 +85,44 @@ module.exports = function(app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function billBoard(req, res) {
|
function billBoard(req, res) {
|
||||||
if(req.user && typeof req.user.currentChallenge.challengeId !== "undefined"){
|
if (
|
||||||
BillBoard.findOne({}, function(err, data){
|
req.user
|
||||||
if(err){
|
&& typeof req.user.currentChallenge.challengeId !== 'undefined'
|
||||||
res.send({err: {type: "Error", message: "Database Error"}, data: null});
|
) {
|
||||||
|
BillBoard.findOne({}, function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
res.send({
|
||||||
|
err: {
|
||||||
|
type: 'Error',
|
||||||
|
message: 'Database Error'
|
||||||
|
},
|
||||||
|
data: null
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
if (data.active) {
|
if (data.active) {
|
||||||
res.send({err: null, data: data.message});
|
res.send({
|
||||||
|
err: null,
|
||||||
|
data: data.message
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
res.send({err: {type: "warning", message: "Bill Board is not active"}, data: null});
|
res.send({
|
||||||
|
err: {
|
||||||
|
type: 'warning',
|
||||||
|
message: 'Bill Board is not active'
|
||||||
|
},
|
||||||
|
data: null
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
res.send({
|
||||||
res.send({err: {type: "warning", message: "User Not Signed In"}, data: null});
|
err: {
|
||||||
|
type: 'warning',
|
||||||
|
message: 'User Not Signed In'
|
||||||
|
},
|
||||||
|
data: null
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
div!= success.msg
|
div!= success.msg
|
||||||
.row.flashMessage
|
.row.flashMessage
|
||||||
.col-xs-12
|
.col-xs-12
|
||||||
.alert.alert-success.fade.in
|
#billBoard.alert.alert-success.fade.in(style="display: none;")
|
||||||
button.close(type='button', data-dismiss='alert')
|
button.close(type='button', data-dismiss='alert')
|
||||||
span.ion-close-circled#dismissBill
|
span.ion-close-circled#dismissBill
|
||||||
#billContent
|
#billContent
|
Reference in New Issue
Block a user