UNPKG

unserver-unify

Version:

246 lines (242 loc) 7.72 kB
"use strict"; angular.module('bamboo.mystudy').controller('MySpaceMessagesCtrl', function($scope, $state, $log, ApiService, CommonService) { var _self = this; this.unreads = []; this.reads = []; this.itemNumber = 10; this.iconlist = { 'reply': 'fa fa-reply' }; this.tab = 'unread'; function getDisplayInfo(_m) { var info = { fullname: _m.author.fullname, loginname: _m.author.loginname, time: _m.create_at, type: _m.type, message: _m.message }; _m.topic = _m.topic || {}; console.log(info); switch (_m.type) { case 'reply': switch (_m.topic.tab) { case 'mvsubject': // info.color = 'color-two'; info.url = 'index.bbss.detail'; info.icon = "fa fa-comments"; break; case 'bbs': // info.color = 'color-two'; info.url = 'index.bbs.tab.detail'; info.icon = "fa fa-commenting-o"; break; default: // info.color = 'color-one'; info.url = 'index.blog.management.detail'; info.icon = "fa fa-comments-o"; break; } info.id = _m.topic._id; info.title = _m.topic.title; info.action = "Reply"; break; case 'blogreply': // info.color = 'color-one'; info.url = 'index.blog.management.detail'; info.icon = "fa fa-comments-o"; info.id = _m.topic._id; info.title = _m.topic.title; info.action = "Reply"; break; case 'bbsreply': // info.color = 'color-one'; info.icon = "fa fa-comments"; info.id = _m.topic._id; info.title = _m.topic.title; info.action = "BBSReply"; break; case 'feedbackreply': // info.color = 'color-one'; info.icon = "fa fa-comments"; info.id = _m.topic._id; info.title = _m.topic.title; info.action = "FeedbackReply"; break; case 'accesscard': info.icon = "fa fa-sign-in"; info.id = _m.topic._id; info.title = _m.message; info.action = "CardRecord"; break; case 'announcement': info.url = 'index.news.announcements.detail'; info.id = _m.content._id; info.title = _m.content.title; info.action = "Announced"; info.icon = "fa fa-bullhorn"; if (_m.content.atype) { switch (_m.content.atype) { case 'thisweektaskremainder': info.icon = 'fa fa-list-ul'; break; case 'examremainder': info.icon = 'fa fa-calendar-check-o'; break; case 'assignmentremainder': info.icon = 'fa fa-file-text-o'; break; } } break; case 'courseapply': // info.color = 'color-three'; info.url = 'index.courses.home'; info.icon = "fa fa-tasks"; info.cid = _m.content._id; info.id = _m.content._id; info.title = "<< " + _m.content.title + " >>"; info.action = "Apply for Course Public Access"; break; case 'follow': // info.color = 'color-four'; info.url = 'index.userprofile'; info.icon = "fa fa-user"; info.id = info.loginname; info.title = "You"; info.action = "Follow"; break; case 'p2p': info.url = 'index.userprofile'; info.icon = "fa fa-envelope-o"; info.id = info.loginname; info.title = info.message; info.action = "MSG"; break; case 'course': info.color = 'color-four'; info.icon = "fa fa-book"; info.title = info.message; info.action = "COURSE"; break; case 'feedback': info.icon = "fa fa-envelope-o"; info.url = "index.feedback.list.detail"; info.id = _m.content._id; info.title = "[ " + _m.content.title + " ]"; info.action = "Feedback"; default: console.log("-- unknown type"); console.log(_m); break; } return info; } this.unreads = []; this.getUnreadMesages = function(tableState) { var limit = tableState.pagination.number; var start = tableState.pagination.start; var info = { start: start, limit: limit, action: "getunreadmsgs" }; ApiService.post("/messages", info).then(function(result) { if (result.data.success && result.data.data) { var unreads = result.data.data.items; console.log(unreads); _self.unreads = []; for (var i = 0; i < unreads.length; i++) { var info = getDisplayInfo(unreads[i]); _self.unreads.push(info); } console.log(_self.unreads); // console.log($scope.displayedItems); $scope.total = result.data.data.counter; // console.log($scope.displayedItems) // console.log($scope.total) tableState.pagination.numberOfPages = Math.ceil(result.data.data.counter / limit); } }); } this.reads = []; this.getReadMesages = function(tableState) { var limit = tableState.pagination.number; var start = tableState.pagination.start; var info = { start: start, limit: limit, action: "getreadmsgs" }; console.log(info); ApiService.post("/messages", info).then(function(result) { if (result.data.success) { var reads = result.data.data.items; console.log(result.data.data); _self.reads = []; for (var i = 0; i < reads.length; i++) { var info = getDisplayInfo(reads[i]); _self.reads.push(info); } console.log(_self.reads); // console.log($scope.displayedItems); $scope.re_total = result.data.data.counter; // console.log($scope.displayedItems) // console.log($scope.total) tableState.pagination.numberOfPages = Math.ceil(result.data.data.counter / limit); } }); } this.readMsg = function(idx, flag) { console.log(idx); var info = { action: 'markread', idx: idx, } console.log(info); ApiService.post("/messages", info).then(function(result) { if (flag && result.data.success) { $state.reload(); } }); } function getUserP2PMsgs() { var info = { action: "getUserP2PMsgs" }; //CommonService.showLoading(); ApiService.post("/messages", info).then(function(result) { //CommonService.stopLoading(); // console.log(result); if (result.data.success) { if (result.data.data) { _self.unreads = result.data.data; console.log(_self.unreads); angular.forEach(_self.unreads, function(msgs) { console.log(msgs); if (msgs.targetUser) { msgs.avatar = CommonService.getAvatarSrc(msgs.targetUser); } }) console.log(_self.unreads); // console.log($scope.displayedItems); } } }); } getUserP2PMsgs(); this.readGroupMsg = function(item) { var info = { action: 'readUserP2PMsgs', author: item.author_id, } console.log(info); ApiService.post("/messages", info).then(function(result) { //getUnreadMesages(); console.log(result); $state.go('.messagethread', { target: item.author_id }); }); } });