Skip to content
This repository has been archived by the owner on Nov 4, 2018. It is now read-only.

Commit

Permalink
Basic Lesson saving + Lesson Model treatment
Browse files Browse the repository at this point in the history
- We can select a course, an attendee, a teacher, a room and press
"Save" to get it pushed to Parse
- LessonFactory get the defineProperty Model treatment with getters and
setters
- createLesson.html: on a <select> element, ng-model creates an entire
new scope so we need to pass it the $parent reference to catch it in
the createLessonCtrl.
see angular-ui/ui-select#18
  • Loading branch information
dotlouis committed Oct 25, 2014
1 parent f8ca3ed commit 547903b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 20 deletions.
37 changes: 32 additions & 5 deletions www/js/controllers/CreateLessonCtrl.js
Original file line number Diff line number Diff line change
@@ -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);}
};

}]);
39 changes: 37 additions & 2 deletions www/js/factories/LessonFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;

}]);
21 changes: 8 additions & 13 deletions www/templates/createLesson.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,28 @@ <h1 class="title">New Lesson</h1>

<label class="item item-input item-select">
<div class="input-label">Course</div>
<select ng-model="course" ng-change="updateStuff()" ng-options="c.get('name') for c in courses" ></select>
<!-- why $parent ? see https://github.com/angular-ui/ui-select/issues/18 -->
<select ng-model="$parent.selectedCourse" ng-options="course.name for course in courses" ></select>
</label>

<label class="item item-input item-select">
<div class="input-label">Attendees</div>
<select ng-model="attendee" ng-change="updateStuff()" ng-options="at.get('name') for at in attendees" ></select>
<select ng-model="$parent.selectedAttendee" ng-options="attendee.name for attendee in attendees" ></select>
</label>

<label class="item item-input item-select">
<div class="input-label">Teacher</div>
<select ng-model="teacher" ng-change="updateStuff()" ng-options="t.get('fullname') for t in teachers" ></select>
<select ng-model="$parent.selectedTeacher" ng-options="teacher.fullname for teacher in teachers" ></select>
</label>

<label class="item item-input item-select">
<div class="input-label">Room</div>
<select ng-model="room" ng-change="updateStuff()" ng-options="r.get('fullname') for r in rooms" ></select>
<select ng-model="$parent.selectedRoom" ng-options="room.fullname for room in rooms" ></select>
</label>

<label class="item item-input">
<span class="input-label">Date</span>
<input type="date" ng-model="date">
</label>

<div>
{{date}}
</div>

</div>
</ion-content>
<div class="bar bar-footer">
<button class="button button-clear button-royal" ng-click="saveLesson()" ng-disabled="!selectedCourse || !selectedAttendee || !selectedTeacher || !selectedRoom">Save</button>
</div>
</ion-modal-view>

0 comments on commit 547903b

Please sign in to comment.