X-Git-Url: https://git.mdrn.pl/ReadingsJQM.git/blobdiff_plain/c956fba7332f45e9abab07b2b8ac417b0f6514c8..bdd9d26375a6489d7ff8eac944e29b0789f04a20:/js/app/BooksList.coffee diff --git a/js/app/BooksList.coffee b/js/app/BooksList.coffee new file mode 100644 index 0000000..21b6d19 --- /dev/null +++ b/js/app/BooksList.coffee @@ -0,0 +1,44 @@ + +slug_in_url = /([a-z0-9-]+)[/]?$/ + +class Readings.Book + constructor: (record) -> + @url = record.url + @href = record.href + @cover = record.cover + @author = record.author + @title = record.title + @slug = slug_in_url.exec(@href)[1] + + render: -> + "
  • #{@title}
  • " + + group: -> + @author + + +$.fn.Readings.BookList = (category, tag) -> + this.each -> + $('[data-role=header] h1').text tag.name + list = $('[data-role=listview]', this) + $.ajax + url: "#{tag.href}books/" + #url: Readings.config.get('wlurl') + "/api/#{category}" + contentType: "json" + success: (data) -> + console.log(data) + books = $.map data, (rec) -> new Readings.Book(rec) + list.empty() + last_separator = null + show_separator = !(category == 'authors') + + for b in books + # throw a separator in for some categories + if show_separator + separator = t.group() + if last_separator != separator + list.append "
  • #{separator}
  • " + last_separator = separator + + list.append b.render() + list.listview 'refresh'