opds-web-client
Version:
172 lines (171 loc) • 8.71 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var React = require("react");
var moment = require("moment");
var BorrowButton_1 = require("./BorrowButton");
var DownloadButton_1 = require("./DownloadButton");
var BookCover_1 = require("./BookCover");
var download = require("downloadjs");
var BookDetails = (function (_super) {
__extends(BookDetails, _super);
function BookDetails(props) {
var _this = _super.call(this, props) || this;
_this.borrow = _this.borrow.bind(_this);
return _this;
}
BookDetails.prototype.render = function () {
var fields = this.fields();
return (React.createElement("div", { className: "book-details" },
React.createElement("div", { className: "top", lang: this.props.book.language },
React.createElement("div", { className: "cover" },
React.createElement(BookCover_1.default, { book: this.props.book })),
React.createElement("div", { className: "header" },
React.createElement("h1", { className: "title" }, this.props.book.title),
this.props.book.series && this.props.book.series.name ?
React.createElement("h3", { className: "series" }, this.props.book.series.name) :
"",
this.props.book.authors && this.props.book.authors.length ?
React.createElement("h2", { className: "authors" }, this.props.book.authors.join(", ")) :
"",
this.props.book.contributors && this.props.book.contributors.length ?
React.createElement("h2", { className: "contributors" },
"Contributors: ",
this.props.book.contributors.join(", ")) :
"",
React.createElement("div", { className: "fields", lang: "en" }, this.fields().map(function (field) {
return field.value ? React.createElement("div", { className: field.name.toLowerCase().replace(" ", "-"), key: field.name },
field.name,
": ",
field.value) : null;
})))),
React.createElement("div", { className: "divider" }),
React.createElement("div", { className: "main" },
React.createElement("div", { className: "row" },
React.createElement("div", { className: "col-sm-3" }),
React.createElement("div", { className: "top col-sm-6" },
React.createElement("div", { className: "circulation-links" }, this.circulationLinks()),
React.createElement("div", { className: "circulation-info" }, this.circulationInfo())),
React.createElement("div", { className: "right-column-links col-sm-3" }, this.rightColumnLinks())),
React.createElement("div", { className: "summary", lang: this.props.book.language, dangerouslySetInnerHTML: { __html: this.props.book.summary } }))));
};
BookDetails.prototype.componentDidMount = function () {
this.setBodyOverflow("hidden");
};
BookDetails.prototype.componentWillUnmount = function () {
this.setBodyOverflow("visible");
};
BookDetails.prototype.setBodyOverflow = function (value) {
var elem = document.getElementsByTagName("body")[0];
if (elem) {
elem.style.overflow = value;
}
};
BookDetails.prototype.fields = function () {
return this.props.book ? [
{
name: "Publisher",
value: this.props.book.publisher
},
{
name: "Published",
"value": this.props.book.published
},
{
name: "Categories",
value: this.props.book.categories ?
this.props.book.categories.join(", ") :
null
}
] : [];
};
BookDetails.prototype.circulationLinks = function () {
var _this = this;
var links = [];
if (this.isOpenAccess()) {
links.push(this.props.book.openAccessLinks.map(function (link) {
return (React.createElement(DownloadButton_1.default, { key: link.url, url: link.url, mimeType: link.type, isPlainLink: true }));
}));
}
else if (this.isBorrowed()) {
links.push(this.props.book.fulfillmentLinks.map(function (link) {
var isStreaming = link.type === "text/html;profile=http://librarysimplified.org/terms/profiles/streaming-media";
return (React.createElement(DownloadButton_1.default, { key: link.url, fulfill: _this.props.fulfillBook, indirectFulfill: _this.props.indirectFulfillBook, url: link.url, mimeType: link.type, title: _this.props.book.title, isPlainLink: isStreaming || !_this.props.isSignedIn, indirectType: link.indirectType }));
}));
}
if (this.isReserved()) {
links.push(React.createElement("button", { key: "onhold", className: "btn btn-default disabled" }, "Reserved"));
}
else if (this.props.book.borrowUrl) {
var label = this.props.book.copies &&
this.props.book.copies.available === 0 ?
"Reserve" :
"Get";
links.push(React.createElement(BorrowButton_1.default, { key: this.props.book.borrowUrl, borrow: this.borrow }, label));
}
return links;
};
BookDetails.prototype.circulationInfo = function () {
if (this.isOpenAccess()) {
return [(React.createElement("div", { key: "oa", className: "open-access-info" }, "This open-access book is available to keep."))];
}
if (this.isBorrowed()) {
var availableUntil = this.props.book.availability && this.props.book.availability.until;
if (availableUntil) {
var timeLeft = moment(availableUntil).fromNow(true);
return [(React.createElement("div", { key: "loan", className: "loan-info" },
"You have this book on loan for ",
timeLeft,
"."))];
}
return [];
}
var info = [];
var availableCopies = (this.props.book.copies && this.props.book.copies.available);
var totalCopies = (this.props.book.copies && this.props.book.copies.total);
var totalHolds = (this.props.book.holds && this.props.book.holds.total);
var holdsPosition = (this.props.book.holds && this.props.book.holds.position);
if (availableCopies !== undefined && availableCopies !== null
&& totalCopies !== undefined && totalCopies !== null) {
info.push(React.createElement("div", { key: "copies", className: "copies-info" },
availableCopies,
" of ",
totalCopies,
" copies available"));
}
if (totalHolds && availableCopies === 0) {
info.push(React.createElement("div", { key: "holds", className: "holds-info" },
totalHolds,
" patrons in hold queue"));
if (this.isReserved() && holdsPosition !== undefined && holdsPosition !== null) {
info.push(React.createElement("div", { key: "holds-position", className: "holds-info" },
"Your holds position: ",
holdsPosition));
}
}
return info;
};
BookDetails.prototype.borrow = function () {
return this.props.updateBook(this.props.book.borrowUrl);
};
BookDetails.prototype.isReserved = function () {
return this.props.book.availability &&
this.props.book.availability.status === "reserved";
};
BookDetails.prototype.isBorrowed = function () {
return this.props.book.fulfillmentLinks &&
this.props.book.fulfillmentLinks.length > 0;
};
BookDetails.prototype.isOpenAccess = function () {
return this.props.book.openAccessLinks &&
this.props.book.openAccessLinks.length > 0;
};
BookDetails.prototype.rightColumnLinks = function () {
};
return BookDetails;
}(React.Component));
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = BookDetails;