Skip to content

Instantly share code, notes, and snippets.

@johnpapa
Created August 7, 2012 01:56
Show Gist options
  • Save johnpapa/3280640 to your computer and use it in GitHub Desktop.
Save johnpapa/3280640 to your computer and use it in GitHub Desktop.
model.attendance.js
define('model.attendance',
['ko'],
function (ko) {
var attendanceMakeId = function (personId, sessionId) {
return (personId + ',' + sessionId);
};
var Attendance = function () {
var self = this;
self.sessionId = ko.observable();
self.personId = ko.observable();
// id is string compound key {personId,sessionId} like '3,10'
self.id = ko.computed({
read: function () {
return attendanceMakeId(self.personId(), self.sessionId());
},
write: function (value) {
var idparts = value.split(',');
self.personId(parseInt(idparts[0]));
self.sessionId(parseInt(idparts[1]));
}
}),
self.rating = ko.observable();
self.text = ko.observable();
self.isNullo = false;
self.dirtyFlag = new ko.DirtyFlag([self.rating, self.text]);
return self;
};
Attendance.Nullo = new Attendance()
.sessionId(0)
.personId(0)
.rating(0)
.text('');
Attendance.Nullo.isNullo = true;
Attendance.Nullo.dirtyFlag().reset();
Attendance.prototype = function () {
var
person = function () {
return datacontext.persons.getLocalById(self.personId());
},
session = function () {
return datacontext.sessions.getLocalById(self.sessionId());
};
return {
isNullo: false,
person: person,
session: session
};
}();
return {
Attendance: Attendance
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment