2016-06-14 14:24:39 +08:00
|
|
|
|
2016-06-14 16:03:10 +08:00
|
|
|
app.controller('ActivityController',
|
2016-06-20 14:39:20 +08:00
|
|
|
['$anchorScroll', '$location','$scope', '$http', '$timeout', 'auth', 'rms', 'common','alertService',
|
|
|
|
function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common, alertService){
|
2016-06-14 14:24:39 +08:00
|
|
|
$scope.replaceUrl = function(url){
|
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
2016-07-06 11:06:32 +08:00
|
|
|
$scope.menus = ['所有动态', '课程动态', '项目动态'];
|
|
|
|
|
2016-06-20 14:39:20 +08:00
|
|
|
$scope.alertService = alertService.create();
|
2016-06-14 14:24:39 +08:00
|
|
|
console.log("ActivityController load");
|
|
|
|
|
|
|
|
$scope.page = rms.get('page') || 0;
|
|
|
|
$scope.activities = rms.get("activities") || [];
|
|
|
|
$scope.has_more = rms.get("has_more");
|
|
|
|
|
2016-07-06 11:06:32 +08:00
|
|
|
$scope.course_page = rms.get('course_page') || 0;
|
|
|
|
$scope.course_activities = rms.get("course_activities") || [];
|
|
|
|
$scope.course_has_more = rms.get("course_has_more");
|
|
|
|
|
|
|
|
$scope.project_page = rms.get('project_page') || 0;
|
|
|
|
$scope.project_activities = rms.get("project_activities") || [];
|
|
|
|
$scope.project_has_more = rms.get("project_has_more");
|
|
|
|
|
|
|
|
$scope.loadActData = function(index,page){
|
|
|
|
container_type = "All";
|
|
|
|
switch(index){
|
|
|
|
case 1:
|
|
|
|
container_type = "All";
|
|
|
|
$scope.page = page;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
container_type = "Course";
|
|
|
|
$scope.course_page = page;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
container_type = "Project";
|
|
|
|
$scope.project_page = page;
|
|
|
|
break;
|
|
|
|
}
|
2016-06-14 14:24:39 +08:00
|
|
|
|
|
|
|
$http({
|
|
|
|
method: 'POST',
|
|
|
|
url: apiUrl+ "activities",
|
2016-07-06 11:06:32 +08:00
|
|
|
data: {token: auth.token(), page: page, container_type: container_type}
|
2016-06-14 14:24:39 +08:00
|
|
|
}).then(function successCallback(response) {
|
|
|
|
if(response.data.page >0) {
|
2016-07-06 11:06:32 +08:00
|
|
|
switch(response.data.container_type){
|
|
|
|
case "All":
|
|
|
|
$scope.activities = $scope.activities.concat(response.data.data);
|
|
|
|
break;
|
|
|
|
case "Course":
|
|
|
|
$scope.course_activities = $scope.course_activities.concat(response.data.data);
|
|
|
|
break;
|
|
|
|
case "Project":
|
|
|
|
$scope.project_activities = $scope.project_activities.concat(response.data.data);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
}
|
2016-06-14 14:24:39 +08:00
|
|
|
} else {
|
2016-07-06 11:06:32 +08:00
|
|
|
switch(response.data.container_type){
|
|
|
|
case "All":
|
|
|
|
$scope.activities = response.data.data;
|
|
|
|
break;
|
|
|
|
case "Course":
|
|
|
|
$scope.course_activities = response.data.data;
|
|
|
|
break;
|
|
|
|
case "Project":
|
|
|
|
$scope.project_activities = response.data.data;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
}
|
2016-06-14 14:24:39 +08:00
|
|
|
}
|
|
|
|
|
2016-07-06 11:06:32 +08:00
|
|
|
switch(response.data.container_type){
|
|
|
|
case "All":
|
|
|
|
rms.save("activities", $scope.activities);
|
|
|
|
$scope.has_more = (response.data.count + response.data.page * 10) < response.data.all_count;
|
|
|
|
rms.save('has_more', $scope.has_more);
|
|
|
|
rms.save('page', response.data.page);
|
|
|
|
break;
|
|
|
|
case "Course":
|
|
|
|
rms.save("course_activities", $scope.course_activities);
|
|
|
|
$scope.course_has_more = (response.data.count + response.data.page * 10) < response.data.all_count;
|
|
|
|
rms.save('course_has_more', $scope.course_has_more);
|
|
|
|
rms.save('course_page', response.data.page);
|
|
|
|
break;
|
|
|
|
case "Project":
|
|
|
|
rms.save("project_activities", $scope.project_activities);
|
|
|
|
$scope.project_has_more = (response.data.count + response.data.page * 10) < response.data.all_count;
|
|
|
|
rms.save('project_has_more', $scope.project_has_more);
|
|
|
|
rms.save('project_page', response.data.page);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
}
|
2016-06-14 14:24:39 +08:00
|
|
|
console.log(response.data);
|
|
|
|
|
|
|
|
}, function errorCallback(response) {
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-07-06 11:06:32 +08:00
|
|
|
$scope.tab = function(index){
|
|
|
|
$scope.currentTab = index;
|
|
|
|
switch(index){
|
|
|
|
//ALL
|
|
|
|
case 1:
|
|
|
|
if($scope.activities.length<=0){
|
|
|
|
$scope.loadActData(index,0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
//Course
|
|
|
|
case 2:
|
|
|
|
if($scope.course_activities.length<=0){
|
|
|
|
$scope.loadActData(index,0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
//Project
|
|
|
|
case 3:
|
|
|
|
if($scope.project_activities.length<=0){
|
|
|
|
$scope.loadActData(index,0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.currentTab = 1;
|
|
|
|
|
2016-06-14 14:24:39 +08:00
|
|
|
if($scope.activities.length<=0){
|
2016-07-06 11:06:32 +08:00
|
|
|
$scope.loadActData(1,0);
|
2016-06-14 14:24:39 +08:00
|
|
|
} else {
|
|
|
|
$timeout(function(){
|
|
|
|
window.scrollTo(0, rms.get("yoffset"));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//跳到详情页
|
|
|
|
$scope.goDetail = function(type, act_id,id){
|
|
|
|
rms.save("yoffset", window.document.body.scrollTop);
|
|
|
|
$location.path('/'+type+'/'+act_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.addPraise = function(act){
|
|
|
|
common.addCommonPraise(act);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.decreasePraise = function(act){
|
|
|
|
common.decreaseCommonPraise(act);
|
|
|
|
};
|
2016-06-14 16:03:10 +08:00
|
|
|
}]);
|