|
|
@ -46,6 +46,35 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var create = {};
|
|
|
|
var create = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var formatData = function (data) {
|
|
|
|
|
|
|
|
return JSON.stringify(data.content.msg.content);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var createElement = function (data) {
|
|
|
|
|
|
|
|
var notif;
|
|
|
|
|
|
|
|
notif = h('div.cp-notification', {
|
|
|
|
|
|
|
|
'data-hash': data.content.hash
|
|
|
|
|
|
|
|
}, [h('div.cp-notification-content', h('p', formatData(data)))]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (data.content.getFormatText) {
|
|
|
|
|
|
|
|
$(notif).find('.cp-notification-content p').html(data.content.getFormatText());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (data.content.isClickable) {
|
|
|
|
|
|
|
|
$(notif).find('.cp-notification-content').addClass("cp-clickable")
|
|
|
|
|
|
|
|
.click(data.content.handler);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.content.isDismissible) {
|
|
|
|
|
|
|
|
var dismissIcon = h('span.fa.fa-times');
|
|
|
|
|
|
|
|
var dismiss = h('div.cp-notification-dismiss', {
|
|
|
|
|
|
|
|
title: Messages.notifications_dismiss
|
|
|
|
|
|
|
|
}, dismissIcon);
|
|
|
|
|
|
|
|
$(dismiss).addClass("cp-clickable").click(data.content.dismissHandler);
|
|
|
|
|
|
|
|
$(notif).append(dismiss);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return notif;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create the list of notifications
|
|
|
|
// create the list of notifications
|
|
|
|
// show only notifs with type in filterTypes array. If filterTypes empty, don't filter.
|
|
|
|
// show only notifs with type in filterTypes array. If filterTypes empty, don't filter.
|
|
|
|
var makeNotificationList = function (key, filterTypes) {
|
|
|
|
var makeNotificationList = function (key, filterTypes) {
|
|
|
@ -69,29 +98,47 @@ define([
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add notification
|
|
|
|
|
|
|
|
function addNotification (data, el) {
|
|
|
|
|
|
|
|
// if the type of notification correspond
|
|
|
|
|
|
|
|
if (filterTypes.length === 0 || filterTypes.indexOf(data.content.msg.type) !== -1) {
|
|
|
|
|
|
|
|
notifsData.push(data);
|
|
|
|
|
|
|
|
$(notifsList).prepend(el);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function addArchivedNotification (data) {
|
|
|
|
|
|
|
|
if (data.content.archived) {
|
|
|
|
|
|
|
|
notifsData.push(data);
|
|
|
|
|
|
|
|
var el = createElement(data);
|
|
|
|
|
|
|
|
$(el).addClass("cp-app-notification-archived");
|
|
|
|
|
|
|
|
$(notifsList).prepend(el);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$div.append(notifsPanel);
|
|
|
|
$div.append(notifsPanel);
|
|
|
|
if (key === "archived") {
|
|
|
|
if (key === "archived") {
|
|
|
|
var loadmore;
|
|
|
|
var loadmore;
|
|
|
|
|
|
|
|
var lastKnownHash;
|
|
|
|
|
|
|
|
$(dismissAll).remove();
|
|
|
|
loadmore = h("div.cp-app-notification-loadmore.cp-clickable", Messages.loadMore || "Load more ...");
|
|
|
|
loadmore = h("div.cp-app-notification-loadmore.cp-clickable", Messages.loadMore || "Load more ...");
|
|
|
|
$div.append(loadmore);
|
|
|
|
$(loadmore).click(function () {
|
|
|
|
|
|
|
|
common.mailbox.getNotificationsHistory('notifications', 5, lastKnownHash, function (err, messages) {
|
|
|
|
|
|
|
|
console.log(messages);
|
|
|
|
|
|
|
|
messages.forEach(function (data) {
|
|
|
|
|
|
|
|
data.content.archived = true;
|
|
|
|
|
|
|
|
addArchivedNotification(data);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
lastKnownHash = messages[0].content.hash;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
notifsList.before(loadmore);
|
|
|
|
|
|
|
|
$(loadmore).click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
common.mailbox.subscribe(["notifications"], {
|
|
|
|
common.mailbox.subscribe(["notifications"], {
|
|
|
|
onMessage: function (data, el) {
|
|
|
|
onMessage: function (data, el) {
|
|
|
|
console.log(data);
|
|
|
|
console.log(data);
|
|
|
|
if (el) {
|
|
|
|
addNotification(data, el);
|
|
|
|
// if the type of notification correspond
|
|
|
|
|
|
|
|
if (filterTypes.length === 0 || filterTypes.indexOf(data.content.msg.type) !== -1) {
|
|
|
|
|
|
|
|
var dismissHandler = data.content.dismissHandler;
|
|
|
|
|
|
|
|
data.content.dismissHandler = function () {
|
|
|
|
|
|
|
|
$(el).addClass("dismissed");
|
|
|
|
|
|
|
|
dismissHandler();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
notifsData.push(data);
|
|
|
|
|
|
|
|
$(notifsList).prepend(el);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onViewed: function () {}
|
|
|
|
onViewed: function () {}
|
|
|
|
});
|
|
|
|
});
|
|
|
|