From eb8e53d73cf93ec75b0260e253ace41b970d98bb Mon Sep 17 00:00:00 2001 From: wes Date: Sat, 25 Feb 2017 13:16:38 -0500 Subject: [PATCH] updates --- src/scripts/tags.js | 114 ++++++++++++++++++++++++++++++++++++++ src/templates/search.html | 2 +- 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/scripts/tags.js diff --git a/src/scripts/tags.js b/src/scripts/tags.js new file mode 100644 index 0000000..f591e32 --- /dev/null +++ b/src/scripts/tags.js @@ -0,0 +1,114 @@ +riot.tag2('book', '

Couldn\'t find anything, sorry :(

', '', '', function(opts) { +this.iarchive = false; +this.openlib = false; +this.noresources = false; + +var self = this; + +this.getresources = function(ev) { + ev.preventDefault(); + self.loading = true; + self.update(); + var params = { + "title" : self.booktitle, + "author" : self.bookauthor + }; + var url = "/search/resources"; + + fetch(url, { + method : "POST", + body : JSON.stringify(params), + headers: { + 'Content-Type': 'application/json' + } + }).then( + function(response) { + if (response.ok) { + return response.json() + } + }).then( + function(results) { + if (results.iarchive) { + self.iarchive = results.iarchive[0]; + } + if (results.openlib) { + self.openlib = results.openlib[0]; + } + if (!(results.openlib && results.iarchive)) { + self.noresources = true; + } + self.loading = false; + self.update(); + }) +}.bind(this) + +}); + +riot.tag2('class', '
{dept} {title}
Taught by: {prof}
Running: {sem}

No books at this time

Check back later, or verify the course has books

', '', '', function(opts) { +booksshown = false; + +var self = this; + +this.showbooks = function() { + self.booksshown = !self.booksshown; + self.update(); +}.bind(this) + +this.update(); +}); + +riot.tag2('results', '
No Results, Sorry!
', '', '', function(opts) { +this.clicker = function() { + alert("clicked"); +}.bind(this) +this.rows = []; +var self = this; + +resultsEv.on("loading", + function() { + self.notLoading = false; + self.update(); + }); + +resultsEv.on("newResults", + function(data) { + console.log("new search results detected"); + console.log(data); + self.rows = data; + self.notLoading = true; + self.update(); +}); +}); + +riot.tag2('row', ' ', '', '', function(opts) { +this.classrow = opts.classrow +}); + + +riot.tag2('search', '
', '', '', function(opts) { +var self = this; + +this.submit = function(ev) { + ev.preventDefault(); + this.showedHelp = true; + this.opts.showHelp = false; + console.log("submitted"); + this.opts.booksLoading = true; + this.update(); + resultsEv.trigger("loading"); + console.log(ev); + fetch("/search/fc?title="+this.title.value+"&sem="+this.sem.value).then( + function(response) { + if (response.ok) { + response.json().then( + function(courses) { + var fcourses = filterCourses(courses); + var cgroups = groupsof(3, fcourses); + resultsEv.trigger("newResults", cgroups); + self.opts.booksLoading = false; + self.update(); + }); + } + }); +}.bind(this) +}); diff --git a/src/templates/search.html b/src/templates/search.html index 9186761..9c693a5 100644 --- a/src/templates/search.html +++ b/src/templates/search.html @@ -14,7 +14,7 @@
-
Search for your course and start saving money on your books
+
Search for a course and start saving money on your books