diff --git a/public/js/classes.js b/public/js/classes.js deleted file mode 100644 index 7c94a9b..0000000 --- a/public/js/classes.js +++ /dev/null @@ -1,95 +0,0 @@ -export class Session { - constructor(id, title, location) { - this._id = id; - this._title = title; - this._location = location; - } - get id() { - return this._id; - } - set id(id) { - this._id = id; - } - - get title() { - return this._title; - } - set title(title) { - this._title = title; - } - - get location() { - return this._location; - } - set location(location) { - this._location = location; - } -} - -export class Talk { - constructor(id, speaker, title, description, session, time, tags, ratings) { - this._id = id; - this._speaker = speaker; - this._title = title; - this._description = description; - this._session = session; - this._time = time; - this._tags = tags; - this._ratings = ratings; - } - get id() { - return this._id; - } - set id(id) { - this._id = id; - } - - get speaker() { - return this._speaker; - } - set speaker(speaker) { - this._speaker = speaker; - } - - get title() { - return this._title; - } - set title(title) { - this._title = title; - } - - get description() { - return this._description; - } - set description(description) { - this._description = description; - } - - get session() { - return this._session; - } - set session(session) { - this._session = session; - } - - get time() { - return this._time; - } - set time(time) { - this._time = time; - } - - get tags() { - return this._tags; - } - set tags(tags) { - this._tags = tags; - } - - get ratings() { - return this._ratings; - } - set ratings(ratings) { - this._ratings = ratings; - } -} diff --git a/public/js/index.js b/public/js/index.js index b1ebbc8..8ed6318 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -16,11 +16,14 @@ function loadSessions() { } function loadTalks() { + return drawTalks(Talk.loadBySessionId("B")); +} +function drawTalks(talksPromise) { //create holding div to append to (only children are returned) var content = $("
"); //return a promise that has the html generated for this page //this is executed when both the document is ready and talks have been loaded from the server - return $.when(Talk.loadAll(), $.ready) + return $.when(talksPromise, $.ready) .done(function(data_talks) { //setup talks global talks = data_talks; @@ -83,7 +86,6 @@ function loadTalks() { $(document).ready(function() { $("#test").on("click", function() { - startSwitch("talks"); switchPage("talks", loadTalks()); }); }); @@ -95,6 +97,7 @@ $(document).ready(function() { //takes a promise that child elements will be provided function switchPage(pagename, promise) { var animation = startSwitch(pagename); + //when the page data has loaded, animation completed and the document is ready $.when(promise, animation, $.ready).done(function(content) { endSwitch(content); }); diff --git a/public/js/modules/talk.js b/public/js/modules/talk.js index 1c104eb..c20d704 100644 --- a/public/js/modules/talk.js +++ b/public/js/modules/talk.js @@ -41,6 +41,37 @@ export default class Talk { }); } + //returns a promise for loading all sessions that resolves with all session objects in an array + static loadBySessionId(session) { + return new Promise(function(resolve, reject) { + var url = "/talks/session/" + session; + $.ajax({ + url: url, + method: "GET", + success: function(data) { + var talks = []; + data.forEach(talk => { + var obj = new Talk( + talk.id, + talk.speaker, + talk.title, + talk.description, + talk.session, + talk.time, + talk.tags, + talk.ratings + ); + talks.push(obj); + }); + resolve(talks); + }, + error: function(a, b, c) { + reject(Error([a, b, c])); + } + }); + }); + } + rate(rating) { var url = "/talks/rate/" + this.id + "/" + rating + "/";