Skip to content

Instantly share code, notes, and snippets.

@BramKaashoek

BramKaashoek/AMISblog1-CRUDservice Secret

Last active Sep 21, 2017
Embed
What would you like to do?
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