opds-web-client
Version:
41 lines (40 loc) • 1.88 kB
JavaScript
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 Search = (function (_super) {
__extends(Search, _super);
function Search(props) {
_super.call(this, props);
this.onSubmit = this.onSubmit.bind(this);
}
Search.prototype.render = function () {
return (React.createElement("div", {className: "search"}, this.props.searchData && (React.createElement("form", {onSubmit: this.onSubmit, className: this.props.className || "form-inline"}, React.createElement("input", {className: "form-control", ref: "input", type: "text", placeholder: this.props.searchData.shortName}), " ", React.createElement("button", {className: "btn btn btn-default", type: "submit"}, "Search")))));
};
Search.prototype.componentWillMount = function () {
if (this.props.url) {
this.props.fetchSearchDescription(this.props.url);
}
};
Search.prototype.componentWillUpdate = function (props) {
if (props.url && props.url !== this.props.url) {
props.fetchSearchDescription(props.url);
}
};
Search.prototype.onSubmit = function (event) {
var searchTerms = encodeURIComponent(this.refs["input"]["value"]);
var url = this.props.searchData.template(searchTerms);
this.context.router.push(this.context.pathFor(url, null));
event.preventDefault();
};
Search.contextTypes = {
router: React.PropTypes.object.isRequired,
pathFor: React.PropTypes.func.isRequired
};
return Search;
}(React.Component));
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Search;
;