From a0cb911ce9d9a9a62787f511d6097b029b3a1c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Sat, 15 Jun 2013 16:09:37 +0200 Subject: [PATCH] Bookdetail is handled with ajax. Template is not complete though. re #73 Fixes some small bugs with the other template. --- base.php | 5 ++-- book.php | 39 +++++++++++++++++++++++++++++-- getJSON.php | 6 ++++- index.php | 13 ++++------- templates/default/bookdetail.html | 34 +++++++++++++++++++++++++++ templates/default/frontpage.html | 2 +- util.js | 18 ++++++++++++-- 7 files changed, 101 insertions(+), 16 deletions(-) create mode 100644 templates/default/bookdetail.html diff --git a/base.php b/base.php index 85081ac..36f8f0f 100644 --- a/base.php +++ b/base.php @@ -343,6 +343,7 @@ class Page public $query; public $favicon; public $n; + public $book; public $totalNumber = -1; public $entryArray = array(); @@ -678,8 +679,8 @@ class PageBookDetail extends Page { public function InitializeContent () { - $book = Book::getBookById ($this->idGet); - $this->title = $book->title; + $this->book = Book::getBookById ($this->idGet); + $this->title = $this->book->title; } } diff --git a/book.php b/book.php index 1b3459c..11ab661 100644 --- a/book.php +++ b/book.php @@ -115,7 +115,16 @@ class Book extends Base { } } $serie = $this->getSerie (); - if (is_null ($serie)) $serie = ""; + if (is_null ($serie)) { + $sn = ""; + $scn = ""; + $su = ""; + } else { + $sn = $serie->name; + $scn = str_format (localize ("content.series.data"), $this->seriesIndex, $serie->name); + $link = new LinkNavigation ($serie->getUri ()); + $su = $link->hrefXhtml (); + } return array ("hasCover" => $this->hasCover, "preferedData" => $preferedData, @@ -124,7 +133,33 @@ class Book extends Base { "pubDate" => $this->getPubDate (), "authorsName" => $this->getAuthorsName (), "tagsName" => $this->getTagsName (), - "seriesName" => $serie); + "seriesName" => $sn, + "seriesCompleteName" => $scn, + "seriesurl" => $su); + + } + public function getFullContentArray () { + $out = $this->getContentArray (); + + $out ["detailurl"] = $this->getDetailUrl (true); + $out ["coverurl"] = Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)->hrefXhtml (); + $out ["thumbnailurl"] = Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL, NULL, 150)->hrefXhtml (); + $out ["datas"] = array (); + foreach ($this->getDatas() as $data) { + array_push ($out ["datas"], array ("format" => $data->format, "url" => $data->getHtmlLink ())); + } + $out ["authors"] = array (); + foreach ($this->getAuthors () as $author) { + $link = new LinkNavigation ($author->getUri ()); + array_push ($out ["authors"], array ("name" => $author->name, "url" => $link->hrefXhtml ())); + } + $out ["tags"] = array (); + foreach ($this->getTags () as $tag) { + $link = new LinkNavigation ($tag->getUri ()); + array_push ($out ["tags"], array ("name" => $tag->name, "url" => $link->hrefXhtml ())); + } + ; + return $out; } public function getDetailUrl ($permalink = false) { diff --git a/getJSON.php b/getJSON.php index e5bfeb2..e40113d 100644 --- a/getJSON.php +++ b/getJSON.php @@ -31,6 +31,9 @@ foreach ($currentPage->entryArray as $entry) { array_push ($entries, $entry->getContentArray ()); } + if (!is_null ($currentPage->book)) { + $out ["book"] = $currentPage->book->getFullContentArray (); + } $out ["databaseId"] = GetUrlParam (DB, ""); $out ["databaseName"] = Base::getDbName (); $out ["page"] = $page; @@ -60,7 +63,8 @@ "previousAlt" => localize ("paging.previous.alternate"), "nextAlt" => localize ("paging.next.alternate"), "searchAlt" => localize ("search.alternate"), - "homeAlt" => localize ("home.alternate")); + "homeAlt" => localize ("home.alternate"), + "permalinkAlt" => localize ("permalink.alternate")); $out ["containsBook"] = 0; if ($currentPage->containsBook ()) { diff --git a/index.php b/index.php index 19f0063..7b1e2cd 100644 --- a/index.php +++ b/index.php @@ -94,14 +94,7 @@ prevEffect : 'none', nextEffect : 'none' - }); - - $(".fancydetail").fancybox({ - 'type' : 'ajax', - prevEffect : 'none', - nextEffect : 'none' - - }); + }); $(".headright").click(function(){ @@ -114,6 +107,10 @@ } }); + $.get('templates/default/bookdetail.html', function(data){ + templateBookDetail = doT.template (data); + }); + $.get('templates/default/frontpage.html', function(data){ template = doT.template(data); $.getJSON('', function(data) { diff --git a/templates/default/bookdetail.html b/templates/default/bookdetail.html new file mode 100644 index 0000000..5efa948 --- /dev/null +++ b/templates/default/bookdetail.html @@ -0,0 +1,34 @@ +
+ + {{? it.book.hasCover == 1}} + + {{=it.i18n.coverAlt}} + + {{?}} + +

+ {{~it.book.datas:data:i}} + {{=data.format}}
+ {{~}} +

+

{{=it.i18n.permalinkAlt}}{{=htmlEscape (it.title)}}

+

+

{{=it.i18n.authorsTitle}}:

+ {{~it.book.authors:author:j}} + {{? j > 0}}, {{?}}{{=htmlEscape (author.name)}} + {{~}} +

+ {{? it.book.tagsName != ""}} +

+

{{=it.i18n.tagsTitle}}:

+ {{~it.book.tags:tag:k}} + {{? k > 0}}, {{?}}{{=htmlEscape (tag.name)}} + {{~}} +

+ {{?}} + {{? it.book.seriesName != ""}} +

+

{{=it.i18n.seriesTitle}} :

{{=htmlEscape (it.book.seriesCompleteName)}} +

+ {{?}} +
\ No newline at end of file diff --git a/templates/default/frontpage.html b/templates/default/frontpage.html index bda2b7c..c28c255 100644 --- a/templates/default/frontpage.html +++ b/templates/default/frontpage.html @@ -55,7 +55,7 @@

{{=it.i18n.authorsTitle}} :

{{=htmlEscape (entry.book.authorsName)}}
{{? entry.book.tagsName != ""}}

{{=it.i18n.tagsTitle}} :

{{=htmlEscape (entry.book.tagsName)}}
{{?}} - {{? entry.book.seriesName != ""}}

{{=it.i18n.seriesTitle}} :

{{=htmlEscape (entry.book.SeriesName)}}
{{?}} + {{? entry.book.seriesName != ""}}

{{=it.i18n.seriesTitle}} :

{{=htmlEscape (entry.book.seriesName)}}
{{?}} {{?}} diff --git a/util.js b/util.js index 3f11ce8..204f238 100644 --- a/util.js +++ b/util.js @@ -1,4 +1,4 @@ -var template, result; +var template, templateBookDetail, result; function htmlEscape(str) { return String(str) @@ -10,7 +10,7 @@ function htmlEscape(str) { } function navigateTo (url) { - jsonurl = url.replace ("index", "getJSON"); + var jsonurl = url.replace ("index", "getJSON"); $.getJSON(jsonurl, function(data) { history.pushState(data, "", url); updatePage (data); @@ -23,6 +23,20 @@ function updatePage (data) { $(".container").html (result); ajaxifyLinks (); + + $(".fancydetail").click(function(event){ + event.preventDefault(); + var url = $(this).attr("href"); + var jsonurl = url.replace ("bookdetail", "getJSON"); + $.getJSON(jsonurl, function(data) { + var detail = templateBookDetail (data); + $.fancybox( { + content: detail, + autoSize: true + }); + }); + }); + } function ajaxifyLinks () {