unserver-unify
Version:
124 lines (118 loc) • 3.37 kB
JavaScript
;
angular.module('bamboo.mystudy').controller('MyNotificationListCtrl', function($log, $stateParams, ApiService, CommonService) {
var _self = this;
var target = $stateParams.target;
function sortByTime(a, b) {
var atime = new Date(a.time);
var btime = new Date(b.time);
return atime - btime;
}
function getTargetThreadMsgs(flag) {
var info = {
action: 'getusertargemsgs',
target: target,
}
console.log(info);
ApiService.post("/messages", info).then(function(result) {
// console.log(result);
if (result.data.success) {
console.log(result.data.data);
var messages = result.data.data;
_self.messages = [];
angular.forEach(messages, function(message) {
getDisplayInfo(message);
// console.log(message.type);
if (message.type !== 'p2p' && message.type !== 'multiple') {
_self.messages.push(message);
}
})
_self.messages.sort(sortByTime);
console.log(_self.messages);
}
});
}
this.deleteMsg = function(msg) {
console.log(msg);
CommonService.showDeleteConfirm(function() {
var info = {
idx: msg.idx,
action: 'delunread',
}
if (msg.group == 'old') {
info.action = 'delread';
} else if (msg.group == 'send') {
info.action = 'delread';
}
ApiService.post("/messages", info).then(function(result) {
if (result.data.success) {
getTargetThreadMsgs();
}
});
});
}
this.readMsg = function(msg) {
console.log(msg);
if (msg.group == 'new') {
var info = {
action: 'markread',
idx: msg.idx,
}
console.log(info);
ApiService.post("/messages", info).then(function(result) {
if (result.data.success) {
// console.log(result);
getTargetThreadMsgs();
}
});
}
}
getTargetThreadMsgs(true);
function getDisplayInfo(info) {
switch (info.type) {
case 'reply':
case 'blogreply':
case 'bbsreply':
case 'feedbackreply':
case 'feedbackreply':
info.icon = "fa fa-commenting-o";
info.action = "Reply";
break;
case 'accesscard':
info.icon = "fa fa-sign-in";
info.action = "CardRecord";
break;
case 'announcement':
info.icon = "fa fa-bullhorn";
info.action = "Announced";
break;
case 'courseapply':
info.icon = "fa fa-tasks";
info.action = "Apply for Course Public Access";
break;
case 'follow':
info.icon = "fa fa-user";
info.action = "Follow";
break;
case 'p2p':
info.icon = "fa fa-envelope-o";
info.action = "MSG";
break;
case 'Following':
info.icon = "fa fa-envelope-o";
info.action = "Following User";
break;
case 'course':
info.icon = "fa fa-book";
info.action = "COURSE";
break;
case 'feedback':
info.icon = "fa fa-envelope-o";
info.action = "Feedback";
break;
default:
console.log("-- unknown type");
break;
}
return info;
}
});