Skip to content

Instantly share code, notes, and snippets.

@BramKaashoek
Last active September 21, 2017 07:34
Show Gist options
  • Save BramKaashoek/cdc217817aa394de21ef64eceaf6197f to your computer and use it in GitHub Desktop.
Save BramKaashoek/cdc217817aa394de21ef64eceaf6197f to your computer and use it in GitHub Desktop.
define(['ojs/ojcore', 'knockout', 'jquery', 'ojs/ojknockout', 'promise', 'ojs/ojmodel'],
function (oj, ko, $) {
function MeetingsService() {
var meetingUrl = "http://localhost:3030/meetings";
function parseMeeting(response) {
return {
_id: response['_id'],
title: response['title'],
startDate: response['startDate'],
endDate: response['endDate'],
location: response['location'],
description: response['description'],
owner: response['owner']
}
};
function parseSaveMeeting(response) {
return {
title: response['title'],
startDate: response['startDate'],
endDate: response['endDate'],
location: response['location'],
description: response['description']
}
};
function meetingModel() {
var Meeting = oj.Model.extend({
urlRoot: meetingUrl,
parse: parseMeeting,
parseSave: parseSaveMeeting,
idAttribute: '_id'
});
return new Meeting();
};
function meetingCollection() {
var Meetings = oj.Collection.extend({
url: meetingUrl,
model: meetingModel(),
comparator: 'startDate'
});
return new Meetings();
};
this.meetingsCol = meetingCollection();
}
return new MeetingsService();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment