- Create course api -fixed

This commit is contained in:
Matan Bar Yosef 2015-06-24 14:01:08 +03:00
parent 38ae45aa95
commit ba5939c437
3 changed files with 56 additions and 22 deletions

View file

@ -5,8 +5,11 @@ angular.module('SeHub')
$scope.isCourse = false;
$scope.isNewCourse = false;
$scope.newClassName = false;
$scope.user.createNewCourse = '';
// $scope.course.courseName = '';
$scope.course = {};
var token = $cookies['com.sehub.www'];
$scope.user.finalDate = '';
$scope.user.startDate = '';
$scope.showMyClass = false;
if($scope.user.isLecturer)
@ -42,13 +45,38 @@ angular.module('SeHub')
$scope.submitNewClassClicked = function()
{
if($scope.user.createNewCourse != '' && $scope.user.finalDate != '')
if($scope.course.courseName != '' && $scope.course.endDate != '' && $scope.course.startDate != '')
{
console.log("finalDate " + $scope.user.finalDate);
console.log($scope.user.createNewCourse);
var jsonNewCourse =
{
'courseName': $scope.course.courseName,
'campusName': $scope.course.campusName,
'startDate': {
'year' : $scope.course.startDate.getFullYear(),
'day' : $scope.course.startDate.getDate(),
'month': ($scope.course.startDate.getMonth() + 1)
},
'endDate': {
'year' : $scope.course.endDate.getFullYear(),
'day' : $scope.course.endDate.getDate(),
'month': ($scope.course.endDate.getMonth() + 1)
}
};
console.log("Json here:");
console.log(jsonNewCourse);
apiService.createCourse(token, jsonNewCourse).success(function(data)
{
console.log("createCourse API done");
}).error(function(err)
{
console.log(err);
});
$mdDialog.show($mdDialog.alert().title('Course Created').content('You have created course successfully.')
.ariaLabel('Email verification alert dialog').ok('Lets Start!').targetEvent());
// $window.location.href = 'templates/views/newCourse.html'; // TODO TODO TODO
}
else
{

View file

@ -71,7 +71,7 @@ service.factory('apiService', ['$http', function($http) {
return $http(req);
},
createMessage: function(token, payLoad){
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/getCourseMessages/" + token;
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/createMessage/" + token;
req = {
method : "POST",
url : url,
@ -80,12 +80,22 @@ service.factory('apiService', ['$http', function($http) {
};
return $http(req);
},
getCourseMessages: function(token, courseName){
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/getCourseMessages/" + token + '/' + courseName;
getMessagesByCourseName: function(token, courseName){
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/getMessagesByCourseName/" + token + '/' + courseName;
req = {
method : "GET",
url : url
};
return $http(req);
},
createCourse: function(token, payLoad){
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/create/" + token;
req = {
method : "POST",
url : url,
data: payLoad
};
return $http(req);
}

View file

@ -27,28 +27,24 @@
<form name="createNewCourseForm">
<div layout layout-sm="column">
<md-input-container style="width:80%">
<label>Class Name</label>
<input ng-model="user.createNewCourse" min-length="1" required>
<label flex = "50">Class Name</label>
<input ng-model="course.courseName" min-length="1" required>
</md-input-container>
<md-input-container flex>
<md-input-container flex = "20">
<label>Course Start Date</label>
<input type="date" ng-model="course.startDate" required>
</md-input-container>
<md-input-container flex = "20">
<label>Course Finish Date</label>
<input type="date" ng-model="user.finalDate" required>
<input type="date" ng-model="course.endDate" required>
</md-input-container>
</div>
<div layout layout-sm="column">
<md-input-container flex>
<label>First name</label>
<input ng-model="user.firstName">
</md-input-container>
<md-input-container flex>
<label>Last Name</label>
<input ng-model="theMax">
<md-input-container flex = "50">
<label>Campus name</label>
<input ng-model="course.campusName">
</md-input-container>
</div>
<md-input-container flex>
<label>General Info (optional)</label>
<textarea ng-model="user.courseInfo" columns="1" md-maxlength="150"></textarea>
</md-input-container>
</form>
</md-content>
<div layout-padding layout-margin>