2016-07-15 15:32:40 +08:00
|
|
|
app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', '$location', 'rms', function($scope, $http, auth, config, $location,rms){
|
2016-06-27 17:24:06 +08:00
|
|
|
var vm = $scope;
|
2016-07-28 14:49:45 +08:00
|
|
|
// vm.menus = ['课件', '作业', '测验'];
|
|
|
|
vm.menus = ['课件', '作业'];
|
2016-06-27 17:24:06 +08:00
|
|
|
|
2016-07-15 14:44:37 +08:00
|
|
|
vm.resources = [];
|
|
|
|
vm.homeworks = [];
|
|
|
|
vm.exercise = [];
|
|
|
|
|
2016-07-15 19:18:30 +08:00
|
|
|
vm.resources_tag = false;
|
|
|
|
vm.homeworks_tag = false;
|
|
|
|
vm.exercises_tag = false;
|
|
|
|
|
2016-07-18 11:08:02 +08:00
|
|
|
//课件
|
2016-07-15 15:32:40 +08:00
|
|
|
vm.page = rms.get('page') || 0;
|
|
|
|
vm.resources = rms.get("resources") || [];
|
|
|
|
vm.has_more = rms.get("has_more");
|
2016-07-15 14:44:37 +08:00
|
|
|
|
2016-07-18 11:08:02 +08:00
|
|
|
//作业
|
2016-07-15 15:32:40 +08:00
|
|
|
vm.homework_page = rms.get('homework_page') || 0;
|
|
|
|
vm.homeworks = rms.get("homeworks") || [];
|
|
|
|
vm.homework_has_more = rms.get("homework_has_more");
|
2016-07-15 14:44:37 +08:00
|
|
|
|
2016-07-18 11:08:02 +08:00
|
|
|
//测验
|
2016-07-15 15:32:40 +08:00
|
|
|
vm.exercise_page = rms.get('exercise_page') || 0;
|
|
|
|
vm.exercise = rms.get("exercise") || [];
|
|
|
|
vm.exercise_has_more = rms.get("exercise_has_more");
|
2016-06-27 17:24:06 +08:00
|
|
|
|
2016-07-08 17:11:16 +08:00
|
|
|
vm.searchText = "";
|
|
|
|
|
2016-07-18 11:08:02 +08:00
|
|
|
//发送类别 1课件 2作业 3测验
|
|
|
|
vm.myresource_sendIndex = rms.get('myresource_sendIndex') || 1;
|
|
|
|
|
|
|
|
vm.sendFile = function(r,index){
|
|
|
|
vm.myresource_sendIndex = index;
|
|
|
|
rms.save('myresource_sendIndex',index);
|
|
|
|
|
2016-07-15 14:44:37 +08:00
|
|
|
$location.path("/send_class_list").search({id: r.id});
|
|
|
|
}
|
|
|
|
|
|
|
|
vm.loadResourceData = function (index,page){
|
|
|
|
if(index == 1){
|
|
|
|
vm.page = page;
|
|
|
|
$http({
|
|
|
|
method: 'POST',
|
|
|
|
url: apiUrl+ "resources",
|
|
|
|
data: {token: auth.token(), page: page}
|
|
|
|
}).then(function successCallback(response) {
|
2016-07-15 19:18:30 +08:00
|
|
|
vm.resources_tag = true
|
2016-07-15 14:44:37 +08:00
|
|
|
if(response.data.page >0) {
|
|
|
|
vm.resources = vm.resources.concat(response.data.data);
|
|
|
|
} else {
|
|
|
|
vm.resources = response.data.data;
|
|
|
|
}
|
|
|
|
|
2016-07-15 15:32:40 +08:00
|
|
|
rms.save("resources", vm.resources);
|
|
|
|
vm.has_more = (response.data.count + response.data.page * 10) < response.data.all_count;
|
|
|
|
rms.save('has_more', vm.has_more);
|
|
|
|
rms.save('page', response.data.page);
|
2016-07-15 14:44:37 +08:00
|
|
|
|
2016-06-27 17:24:06 +08:00
|
|
|
console.log(response.data);
|
2016-07-15 14:44:37 +08:00
|
|
|
|
|
|
|
}, function errorCallback(response) {
|
2016-06-27 17:24:06 +08:00
|
|
|
});
|
2016-07-15 14:44:37 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
else if(index==2 ){
|
|
|
|
vm.homework_page = page;
|
|
|
|
$http({
|
|
|
|
method: 'POST',
|
|
|
|
url: apiUrl+ "resources/homeworks",
|
|
|
|
data: {token: auth.token(), page: page}
|
|
|
|
}).then(function successCallback(response) {
|
2016-07-15 19:18:30 +08:00
|
|
|
vm.homeworks_tag = true
|
2016-07-15 14:44:37 +08:00
|
|
|
if(response.data.page >0) {
|
|
|
|
vm.homeworks = vm.homeworks.concat(response.data.data);
|
|
|
|
} else {
|
|
|
|
vm.homeworks = response.data.data;
|
|
|
|
}
|
|
|
|
|
2016-07-15 15:32:40 +08:00
|
|
|
rms.save("homeworks", vm.homeworks);
|
2016-07-15 14:44:37 +08:00
|
|
|
vm.homework_has_more = (response.data.count + response.data.page * 10) < response.data.all_count;
|
2016-07-15 15:32:40 +08:00
|
|
|
rms.save('homework_has_more', vm.has_more);
|
|
|
|
rms.save('homework_page', response.data.page);
|
2016-07-15 14:44:37 +08:00
|
|
|
|
2016-06-27 17:24:06 +08:00
|
|
|
console.log(response.data);
|
2016-07-15 14:44:37 +08:00
|
|
|
|
|
|
|
}, function errorCallback(response) {
|
2016-06-27 17:24:06 +08:00
|
|
|
});
|
2016-07-15 14:44:37 +08:00
|
|
|
}
|
|
|
|
else if(index==3 ){
|
|
|
|
vm.exercise_page = page;
|
|
|
|
$http({
|
|
|
|
method: 'POST',
|
|
|
|
url: apiUrl+ "resources/exercises",
|
|
|
|
data: {token: auth.token(), page: page}
|
|
|
|
}).then(function successCallback(response) {
|
2016-07-15 19:18:30 +08:00
|
|
|
vm.exercises_tag = true;
|
2016-07-15 14:44:37 +08:00
|
|
|
if(response.data.page >0) {
|
|
|
|
vm.exercise = vm.exercise.concat(response.data.data);
|
|
|
|
} else {
|
|
|
|
vm.exercise = response.data.data;
|
|
|
|
}
|
|
|
|
|
2016-07-15 15:32:40 +08:00
|
|
|
rms.save("exercise", vm.exercise);
|
2016-07-15 14:44:37 +08:00
|
|
|
vm.exercise_has_more = (response.data.count + response.data.page * 10) < response.data.all_count;
|
2016-07-15 15:32:40 +08:00
|
|
|
rms.save('exercise_has_more', vm.exercise_has_more);
|
|
|
|
rms.save('exercise_page', response.data.page);
|
2016-07-15 14:44:37 +08:00
|
|
|
|
2016-06-27 17:24:06 +08:00
|
|
|
console.log(response.data);
|
2016-07-15 14:44:37 +08:00
|
|
|
|
|
|
|
}, function errorCallback(response) {
|
2016-06-27 17:24:06 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-15 14:44:37 +08:00
|
|
|
vm.tab = function(index){
|
|
|
|
vm.currentTab = index;
|
|
|
|
vm.searchText = "";
|
2016-07-02 23:46:45 +08:00
|
|
|
|
2016-07-15 14:44:37 +08:00
|
|
|
switch(index){
|
|
|
|
//ALL
|
|
|
|
case 1:
|
|
|
|
if(vm.resources.length<=0){
|
|
|
|
vm.loadResourceData(index,0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
//homework
|
|
|
|
case 2:
|
|
|
|
if(vm.homeworks.length<=0){
|
|
|
|
vm.loadResourceData(index,0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
//exercise
|
|
|
|
case 3:
|
|
|
|
if(vm.exercise.length<=0){
|
|
|
|
vm.loadResourceData(index,0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-07-22 16:44:16 +08:00
|
|
|
rms.save("resource_tab_num",vm.currentTab);
|
2016-07-02 23:46:45 +08:00
|
|
|
}
|
2016-07-15 14:44:37 +08:00
|
|
|
|
2016-07-22 16:44:16 +08:00
|
|
|
var currentTab = rms.get('resource_tab_num') || 1;
|
|
|
|
|
|
|
|
vm.tab(currentTab);
|
2016-07-15 14:44:37 +08:00
|
|
|
|
2016-07-08 17:11:16 +08:00
|
|
|
}] );
|