Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
added talk loading by session
Browse files Browse the repository at this point in the history
  • Loading branch information
Sectimus committed Dec 15, 2019
1 parent d64946d commit 11b076a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 97 deletions.
95 changes: 0 additions & 95 deletions public/js/classes.js

This file was deleted.

7 changes: 5 additions & 2 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $("<div>");
//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;
Expand Down Expand Up @@ -83,7 +86,6 @@ function loadTalks() {

$(document).ready(function() {
$("#test").on("click", function() {
startSwitch("talks");
switchPage("talks", loadTalks());
});
});
Expand All @@ -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);
});
Expand Down
31 changes: 31 additions & 0 deletions public/js/modules/talk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "/";

Expand Down

0 comments on commit 11b076a

Please sign in to comment.