|
|
@ -36,59 +36,81 @@ define([
|
|
|
|
'cp-notifications-all',
|
|
|
|
'cp-notifications-all',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'friends': [
|
|
|
|
'friends': [
|
|
|
|
'cp-notifications-friend-requests',
|
|
|
|
'cp-notifications-friends',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'pads': [
|
|
|
|
'pads': [
|
|
|
|
'cp-notifications-shared-app',
|
|
|
|
'cp-notifications-pads',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var create = {};
|
|
|
|
var create = {};
|
|
|
|
|
|
|
|
|
|
|
|
var makeBlock = function (key, addButton) {
|
|
|
|
// create the list of notifications
|
|
|
|
// Convert to camlCase for translation keys
|
|
|
|
// show only notifs with type in filterTypes array. If filterTypes empty, don't filter.
|
|
|
|
|
|
|
|
var makeNotificationList = function (key, filterTypes) {
|
|
|
|
|
|
|
|
filterTypes = filterTypes || [];
|
|
|
|
var safeKey = key.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
|
|
|
|
var safeKey = key.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
|
|
|
|
|
|
|
|
var categoryName = Messages['notification_cat_' + safeKey] || safeKey;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var notifsData = [];
|
|
|
|
var $div = $('<div>', {'class': 'cp-notifications-' + key + ' cp-sidebarlayout-element'});
|
|
|
|
var $div = $('<div>', {'class': 'cp-notifications-' + key + ' cp-sidebarlayout-element'});
|
|
|
|
$('<label>').text(Messages['notification_'+safeKey+'Title'] || key).appendTo($div);
|
|
|
|
var notifsPanel;
|
|
|
|
$('<span>', {'class': 'cp-sidebarlayout-description'})
|
|
|
|
var notifsList;
|
|
|
|
.text(Messages['notification_'+safeKey+'Hint'] || 'Coming soon...').appendTo($div);
|
|
|
|
var dismissAll;
|
|
|
|
if (addButton) {
|
|
|
|
notifsPanel = h("div.cp-app-notifications-panel", [
|
|
|
|
$('<button>', {
|
|
|
|
h('div.cp-app-notifications-panel-titlebar', [
|
|
|
|
'class': 'btn btn-primary'
|
|
|
|
h("span.cp-app-notifications-panel-title",
|
|
|
|
}).text(Messages['notification_'+safeKey+'Button'] || safeKey).appendTo($div);
|
|
|
|
(Messages.notificationsPage || "Notifications") + " - " + categoryName),
|
|
|
|
}
|
|
|
|
h("div.cp-app-notifications-panel-titlebar-buttons", [
|
|
|
|
return $div;
|
|
|
|
dismissAll = h("div.cp-app-notifications-dismissall.cp-clickable", { title: Messages.dismissAll || "Dismiss All" }, h("span.fa.fa-trash")),
|
|
|
|
};
|
|
|
|
]),
|
|
|
|
create['all'] = function () {
|
|
|
|
]),
|
|
|
|
var key = 'all';
|
|
|
|
notifsList = h("div.cp-app-notifications-panel-list"),
|
|
|
|
var $div = makeBlock(key);
|
|
|
|
|
|
|
|
var dismissAll = h("div.cp-app-notifications-dismissall.cp-clickable", { title: Messages.dismissAll || "Dismiss All" }, h("span.fa.fa-trash"));
|
|
|
|
|
|
|
|
var titleButtons = h("div.cp-app-notifications-panel-titlebar-buttons", dismissAll);
|
|
|
|
|
|
|
|
var notifsTitlebar = h('div.cp-app-notifications-panel-titlebar', [
|
|
|
|
|
|
|
|
h("span.cp-app-notifications-panel-title", (Messages.notifications || "Notifications") + " - " + key),
|
|
|
|
|
|
|
|
titleButtons
|
|
|
|
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
var notifsList = h("div.cp-app-notifications-panel-list");
|
|
|
|
|
|
|
|
var notifsPanel = h("div.cp-app-notifications-panel", [
|
|
|
|
|
|
|
|
notifsTitlebar,
|
|
|
|
|
|
|
|
notifsList
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
$(notifsPanel).append(notifsList);
|
|
|
|
|
|
|
|
$div.append(notifsPanel);
|
|
|
|
$div.append(notifsPanel);
|
|
|
|
|
|
|
|
|
|
|
|
common.mailbox.subscribe(["notifications"], {
|
|
|
|
common.mailbox.subscribe(["notifications"], {
|
|
|
|
onMessage: function (data, el) {
|
|
|
|
onMessage: function (data, el) {
|
|
|
|
console.log("data : ", data);
|
|
|
|
console.log(data);
|
|
|
|
if (el) {
|
|
|
|
if (el) {
|
|
|
|
$(notifsList).prepend(el);
|
|
|
|
// if the type of notification correspond
|
|
|
|
|
|
|
|
if (filterTypes.length === 0 || filterTypes.indexOf(data.content.msg.type) !== -1) {
|
|
|
|
|
|
|
|
notifsData.push(data);
|
|
|
|
|
|
|
|
$(notifsList).prepend(el);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onViewed: function () {}
|
|
|
|
onViewed: function () {}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// common.mailbox.dismiss(data)
|
|
|
|
|
|
|
|
|
|
|
|
$(dismissAll).click(function () {
|
|
|
|
|
|
|
|
notifsData.forEach(function (data) {
|
|
|
|
|
|
|
|
if (data.content.isDismissible) {
|
|
|
|
|
|
|
|
data.content.dismissHandler();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return $div;
|
|
|
|
return $div;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
create['all'] = function () {
|
|
|
|
|
|
|
|
var key = 'all';
|
|
|
|
|
|
|
|
return makeNotificationList(key);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
create['friends'] = function () {
|
|
|
|
|
|
|
|
var key = 'friends';
|
|
|
|
|
|
|
|
var filter = ["FRIEND_REQUEST", "FRIEND_REQUEST_ACCEPTED", "FRIEND_REQUEST_DECLINED"];
|
|
|
|
|
|
|
|
return makeNotificationList(key, filter);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
create['pads'] = function () {
|
|
|
|
|
|
|
|
var key = 'pads';
|
|
|
|
|
|
|
|
var filter = ["SHARE_PAD"];
|
|
|
|
|
|
|
|
return makeNotificationList(key, filter);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var hideCategories = function () {
|
|
|
|
var hideCategories = function () {
|
|
|
|
APP.$rightside.find('> div').hide();
|
|
|
|
APP.$rightside.find('> div').hide();
|
|
|
|