diff --git a/www/js/controllers/CreateLessonCtrl.js b/www/js/controllers/CreateLessonCtrl.js index d6ee51a..d42563e 100644 --- a/www/js/controllers/CreateLessonCtrl.js +++ b/www/js/controllers/CreateLessonCtrl.js @@ -1,20 +1,47 @@ angular.module('studionic.controllers') -.controller('CreateLessonCtrl', ['$scope','$stateParams','CourseFactory','RoleFactory','RoomFactory', function($scope, $stateParams, CourseFactory, RoleFactory, RoomFactory){ +.controller('CreateLessonCtrl', ['$scope','$stateParams','CourseFactory','RoleFactory','RoomFactory','LessonFactory', function($scope, $stateParams, CourseFactory, RoleFactory, RoomFactory, LessonFactory){ + + $scope.selectedCourse; + $scope.selectedAttendee; + $scope.selectedTeacher; + $scope.selectedRoom; + CourseFactory.getAll().then(function(courses){ $scope.courses = courses; - console.log(courses); }); RoleFactory.getAll().then(function(groups){ $scope.attendees = groups; - console.log(groups); }); RoleFactory.getTeachers().then(function(teachers){ $scope.teachers = teachers; - console.log(teachers); }); RoomFactory.getAll().then(function(rooms){ $scope.rooms = rooms; - console.log(rooms); }); + + $scope.saveLesson = function(){ + var lesson = new LessonFactory; + + try{ + if(!this.selectedCourse) + throw "Please select a Course"; + if(!this.selectedAttendee) + throw "Please select an Attendee"; + if(!this.selectedTeacher) + throw "Please select a Teacher"; + if(!this.selectedRoom) + throw "Please select a Room"; + + + lesson.relation("course").add(this.selectedCourse); + lesson.relation("attendees").add(this.selectedAttendee); + lesson.relation("speakers").add(this.selectedTeacher); + lesson.relation("room").add(this.selectedRoom); + lesson.save().then(function(lessonAgain){ + $scope.createLessonModal.hide(); + }); + }catch(error){alert(error);} + }; + }]); diff --git a/www/js/factories/LessonFactory.js b/www/js/factories/LessonFactory.js index e6f0dce..d665f6b 100644 --- a/www/js/factories/LessonFactory.js +++ b/www/js/factories/LessonFactory.js @@ -9,7 +9,7 @@ angular.module('studionic.factories') // Class methods ,{ getAll: function(){ - var query = new Parse.Query('Lesson'); + var query = new Parse.Query(this); query.include('course'); return query.find().then(function(lessons){ // do some stuff with lessons @@ -18,7 +18,7 @@ angular.module('studionic.factories') }, // Overrides get: function(id){ - var query = new Parse.Query('Lesson'); + var query = new Parse.Query(this); query.include('course'); return query.get(id).then(function(lesson){ // do some stuff with lesson @@ -27,6 +27,41 @@ angular.module('studionic.factories') } }); + Object.defineProperty(Lesson.prototype, "start", { + get: function() { return this.get("start"); }, + set: function(start) { this.set("start", start); } + }); + + Object.defineProperty(Lesson.prototype, "end", { + get: function() { return this.get("end"); }, + set: function(end) { this.set("end", end); } + }); + + Object.defineProperty(Lesson.prototype, "assignements", { + get: function() { return this.get("assignements"); }, + set: function(assignements) { this.set("assignements", assignements); } + }); + + Object.defineProperty(Lesson.prototype, "speakers", { + get: function() { return this.get("speakers"); }, + set: function(speakers) { this.set("speakers", speakers); } + }); + + Object.defineProperty(Lesson.prototype, "attendees", { + get: function() { return this.get("attendees"); }, + set: function(attendees) { this.set("attendees", attendees); } + }); + + Object.defineProperty(Lesson.prototype, "room", { + get: function() { return this.get("room"); }, + set: function(room) { this.set("room", room); } + }); + + Object.defineProperty(Lesson.prototype, "course", { + get: function() { return this.get("course"); }, + set: function(course) { this.set("course", course); } + }); + return Lesson; }]); diff --git a/www/templates/createLesson.html b/www/templates/createLesson.html index 616f08e..71ff00f 100644 --- a/www/templates/createLesson.html +++ b/www/templates/createLesson.html @@ -10,33 +10,28 @@

New Lesson

- - -
- {{date}} -
- +