opds-web-client
Version:
99 lines (98 loc) • 6.29 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 CatalogLink_1 = require("./CatalogLink");
var BorrowButton_1 = require("./BorrowButton");
var DownloadButton_1 = require("./DownloadButton");
var download = require("downloadjs");
var BookDetails = (function (_super) {
__extends(BookDetails, _super);
function BookDetails(props) {
_super.call(this, props);
this.borrow = this.borrow.bind(this);
}
BookDetails.prototype.render = function () {
var bookSummaryStyle = {
paddingTop: "2em",
borderTop: "1px solid #ccc"
};
var fields = this.fields();
return (React.createElement("div", {className: "bookDetails"}, React.createElement("div", {className: "bookDetailsTop", style: { textAlign: "left", display: "table-row" }}, this.props.book.imageUrl &&
React.createElement("div", {className: "bookImage", style: { display: "table-cell", paddingRight: "20px", verticalAlign: "top" }}, React.createElement("img", {src: this.props.book.imageUrl, style: { height: "150px" }})), React.createElement("div", {className: "bookDetailsHeader", style: { display: "table-cell", verticalAlign: "top", textAlign: "left", maxWidth: "500px" }}, React.createElement("h1", {className: "bookDetailsTitle", style: { margin: 0 }}, this.props.book.title), this.props.book.authors && this.props.book.authors.length ?
React.createElement("h2", {className: "bookDetailsAuthors", style: { marginTop: "0.5em", fontSize: "1.2em" }}, this.props.book.authors.join(", ")) :
"", this.props.book.contributors && this.props.book.contributors.length ?
React.createElement("h2", {className: "bookDetailsContributors", style: { marginTop: "0.5em", fontSize: "1.2em" }}, "Contributors: ", this.props.book.contributors.join(", ")) :
"", React.createElement("div", {style: { marginTop: "2em", color: "#888", fontSize: "0.9em" }}, this.fieldNames().map(function (key) {
return fields[key] ? React.createElement("div", {className: "bookDetails" + key, key: key}, key, ": ", fields[key]) : null;
})))), React.createElement("div", {style: { clear: "both", marginTop: "1em" }}), React.createElement("div", {style: bookSummaryStyle}, React.createElement("div", {className: "row"}, React.createElement("div", {className: "col-sm-3"}, this.props.book.url &&
React.createElement(CatalogLink_1.default, {className: "btn btn-link", target: "_blank", bookUrl: this.props.book.url}, "Permalink")), React.createElement("div", {className: "col-sm-6", style: { textAlign: "center", marginBottom: "30px" }}, this.circulationLinks()), React.createElement("div", {className: "col-sm-3", style: { textAlign: "right" }}, this.rightColumnLinks())), React.createElement("div", {className: "bookDetailsSummary", 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.fieldNames = function () {
return ["Publisher", "Published", "Categories"];
};
BookDetails.prototype.fields = function () {
return this.props.book ? {
Published: this.props.book.published,
Publisher: this.props.book.publisher,
Categories: this.props.book.categories ?
this.props.book.categories.join(", ") :
null
} : {};
};
BookDetails.prototype.circulationLinks = function () {
var _this = this;
var links = [];
if (this.props.book.openAccessLinks &&
this.props.book.openAccessLinks.length > 0) {
links.push(this.props.book.openAccessLinks.map(function (link) {
return (React.createElement(DownloadButton_1.default, {key: link.url, style: { marginRight: "0.5em" }, url: link.url, mimeType: link.type, isPlainLink: true}));
}));
}
else if (this.props.book.fulfillmentLinks &&
this.props.book.fulfillmentLinks.length > 0) {
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, style: { marginRight: "0.5em" }, 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"}, "On Hold"));
}
else if (this.props.book.borrowUrl) {
var label = this.props.book.copies &&
this.props.book.copies.available === 0 ?
"Hold" :
"Borrow";
links.push(React.createElement(BorrowButton_1.default, {key: this.props.book.borrowUrl, style: { marginRight: "0.5em" }, borrow: this.borrow}, label));
}
return links;
};
BookDetails.prototype.borrow = function () {
return this.props.borrowBook(this.props.book.borrowUrl);
};
BookDetails.prototype.isReserved = function () {
return this.props.book.availability &&
this.props.book.availability.status === "reserved";
};
BookDetails.prototype.rightColumnLinks = function () {
};
return BookDetails;
}(React.Component));
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = BookDetails;