UNPKG

unserver-unify

Version:

451 lines (444 loc) 14.2 kB
'use strict'; angular.module('bamboo.mystudy').controller('MessagesCtrl', function($scope, $state, ApiService, CommonService) { var _self = this; this.unreads = []; this.reads = []; this.tab = "unread"; this.colorlist = { 'reply': 'color-one', 'blogreply': 'color-one', 'announcement': 'color-two', 'course': 'color-three', 'exam': 'color-four', 'test': 'color-five', 'news': 'color-six', 'notice': 'color-seven', 'accesscard': 'color-seven' }; this.iconlist = { 'reply': 'fa fa-reply' }; function getDisplayInfo(_m) { var info = { fullname: _m.author.fullname, loginname: _m.author.loginname, time: _m.create_at, target_id: _m.author_id, type: _m.type, message: _m.message, idx: _m.idx, }; _m.topic = _m.topic || {}; _m.content = _m.content || {}; switch (_m.type) { case 'reply': switch (_m.topic.tab) { case 'mvsubject': info.color = 'color-two'; info.url = 'index.forums.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.blogs.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.blogs.detail'; info.icon = "fa fa-comments-o"; if (_m.topic) { info.id = _m.topic._id; info.title = _m.topic.title; } info.action = "Reply"; break; case 'bbsreply': info.color = 'color-one'; info.url = 'index.bbs.tab.detail'; info.icon = "fa fa-comments"; if (_m.topic) { info.id = _m.topic._id; info.title = _m.topic.title; } info.action = "Reply"; break; case 'feedbackreply': info.color = 'color-one'; info.url = 'index'; info.icon = "fa fa-comments"; info.id = _m.topic._id; info.title = _m.topic.title; info.action = "FeedbackReply"; break; case 'accesscard': info.color = 'color-one'; info.url = 'index.myspace.game'; info.icon = "fa fa-sign-in"; info.id = _m.topic._id; info.title = _m.message; info.action = "CardRecord"; break; case 'announcement': info.color = 'color-three'; info.url = 'index.announcements.detail'; info.icon = "fa fa-bullhorn"; if (_m.content) { info.id = _m.content._id; info.title = _m.content.title; 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; } } } info.action = "Announced"; break; case 'courseapply': info.color = 'color-three'; info.url = 'index.courses.course'; info.icon = "fa fa-tasks"; info.cid = _m.content._id; info.cs = ApiService.getCheckSum(_m.content.cid); 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.setting.profile'; info.icon = "fa fa-user"; info.id = info.loginname; info.cs = ApiService.getCheckSum(info.loginname); info.title = "You"; info.action = "Follow"; break; case 'p2p': info.color = 'color-four'; info.url = 'index.setting.profile'; info.icon = "fa fa-envelope-o"; info.id = info.loginname; info.cs = ApiService.getCheckSum(info.loginname); info.title = info.message; info.action = "MSG"; break; case 'Following': info.color = 'color-four'; info.url = 'index.setting.profile'; info.icon = "fa fa-envelope-o"; info.id = info.loginname; info.cs = ApiService.getCheckSum(info.loginname); info.title = info.message; info.action = "Following User"; break; case 'course': info.color = 'color-four'; info.icon = "fa fa-book"; info.title = info.message; info.action = "COURSE"; info.url = 'index.courses.info'; info.cid = _m.content_id || _m.author_id; info.cs = ApiService.getCheckSum(info.cid); break; case 'feedback': info.color = 'color-three'; info.icon = "fa fa-envelope-o"; info.url = "index"; info.id = info.loginname; info.id = _m.content._id; info.title = "[ " + _m.content.title + " ]"; info.action = "Feedback"; break; default: console.log("-- unknown type"); break; } return info; } /* ApiService.get('/messages/all').then(function(result) { if (result.data.success&&result.data.data) { console.log(result.data.data); var _reads = []; for (var i = 0; i < result.data.data.has_read_messages.length; i++) { var info = getDisplayInfo(result.data.data.has_read_messages[i]); _reads.push(info); } _self.reads = _reads; var _unreads = []; for (var i = 0; i < result.data.data.hasnot_read_messages.length; i++) { var info = getDisplayInfo(result.data.data.hasnot_read_messages[i]); _unreads.push(info); } _self.unreads = _unreads; } });*/ this.unreads = []; this.getUnreadMesages = function(tableState) { var limit = tableState.pagination.number; var start = tableState.pagination.start; var search = tableState.search.predicateObject; var info = { start: start, limit: limit, //search: search, search: { type: 'p2p' }, sort: tableState.sort, action: "getunreadmsgs" }; console.log(info); ApiService.post("/messages", info).then(function(result) { console.log(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 || 0; // console.log($scope.displayedItems) console.log($scope.total) tableState.pagination.numberOfPages = Math.ceil(result.data.data.counter / limit); } else { $scope.total = 0; } }); } this.getUnreadNotP2p = function(tableState) { var limit = tableState.pagination.number; var start = tableState.pagination.start; var search = tableState.search.predicateObject; var info = { start: start, limit: limit, search: search, exclude: 'p2p', sort: tableState.sort, action: "getunreadmsgs" }; console.log(info); 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 || 0; // console.log($scope.displayedItems) console.log($scope.total) tableState.pagination.numberOfPages = Math.ceil(result.data.data.counter / limit); } else { $scope.total = 0; } }); } this.reads = []; this.getReadMesages = function(tableState) { var limit = tableState.pagination.number; var start = tableState.pagination.start; var search = tableState.search.predicateObject; var info = { start: start, limit: limit, search: { type: 'p2p' }, //search: search, sort: tableState.sort, action: "getreadmsgs" }; console.log(info); ApiService.post("/messages", info).then(function(result) { if (result.data.success && result.data.data) { var reads = result.data.data.items; console.log(result.data.data); _self.reads = []; if (!reads) { return; } 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 || 0; // console.log($scope.displayedItems) // console.log($scope.total) tableState.pagination.numberOfPages = Math.ceil(result.data.data.counter / limit); } }); } this.getReadNotP2P = function(tableState) { var limit = tableState.pagination.number; var start = tableState.pagination.start; var search = tableState.search.predicateObject; var info = { start: start, limit: limit, search: search, sort: tableState.sort, exclude: 'p2p', action: "getreadmsgs" }; console.log(info); ApiService.post("/messages", info).then(function(result) { if (result.data.success && result.data.data) { var reads = result.data.data.items; console.log(result.data.data); _self.reads = []; if (!reads) { return; } 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 || 0; // console.log($scope.displayedItems) // console.log($scope.total) tableState.pagination.numberOfPages = Math.ceil(result.data.data.counter / limit); } }); } // search:{type:'p2p'}, // exclude:'p2p', this.getSendMesages = function(tableState) { var limit = tableState.pagination.number; var start = tableState.pagination.start; var info = { start: start, limit: limit, action: "getsendmsgs" }; console.log(info); ApiService.post("/messages", info).then(function(result) { if (result.data.success && result.data.data) { var sends = result.data.data.items; angular.forEach(sends, function(msg) { if (msg.type == 'p2p') { msg.icon = "fa fa-envelope-o"; } else if (msg.type == "multiple") { msg.icon = "fa fa-modx"; } }) console.log(sends); _self.sends = sends; if (!sends) { return; } $scope.se_total = result.data.data.counter || 0; 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) { console.log(result); $state.reload(); } }); } this.delUnreadMsg = function(idx, index) { console.log(idx + ' -- ' + index); var info = { action: 'delunread', idx: idx, } console.log(info); ApiService.post("/messages", info).then(function(result) { if (result.data.success) { _self.unreads.splice(index, 1); //$state.reload(); } }); } this.delReadMsg = function(idx, index) { console.log(idx + ' -- ' + index); var info = { action: 'delread', idx: idx, } console.log(info); ApiService.post("/messages", info).then(function(result) { if (result.data.success) { // _self.unreads.splice(index,1); _self.reads.splice(index, 1); // $state.reload(); } }); } this.delSendMsg = function(idx, index) { console.log(idx + ' -- ' + index); var info = { action: 'delsend', idx: idx, } console.log(info); ApiService.post("/messages", info).then(function(result) { if (result.data.success) { // _self.unreads.splice(index,1); _self.sends.splice(index, 1); // $state.reload(); } }); } this.cleanReadMsg = function() { var info = { action: 'cleanread', } console.log(info); ApiService.post("/messages", info).then(function(result) { if (result.data.success) { $state.reload(); } }); } this.deleteTargetMsgs=function(id){ console.log('deleteTargetMsgs'); CommonService.showDeleteConfirm(function(){ var info={ action:'deleteTarget', id:id, } console.log(info); ApiService.post("/messages", info).then(function(result) { CommonService.showNoBlockSuccess("Delete Successfully!"); $state.reload(); }); }); } });