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', '
', '', '', 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', 'No books at this time
Check back later, or verify the course has books