var React = require("react");
var _ = require("lodash");
var common = require("../common.js");
var actions = require("../../actions.js");
var flowutils = require("../../flow/utils.js");
var utils = require("../../utils.js");
var ContentView = require("./contentview.js");
var Headers = React.createClass({
render: function () {
var rows = this.props.message.headers.map(function (header, i) {
return (
{header[0] + ":"} |
{header[1]} |
);
});
return (
);
}
});
var InlineInput = React.createClass({
mixins: [common.ChildFocus],
getInitialState: function () {
return {
editable: false
};
},
render: function () {
var Tag = this.props.tag || "span";
var className = "inline-input " + (this.props.className || "");
var html = {__html: _.escape(this.props.content)};
return ;
},
onKeyDown: function (e) {
e.stopPropagation();
switch (e.keyCode) {
case utils.Key.ESC:
this.blur();
break;
case utils.Key.ENTER:
e.preventDefault();
if (!e.ctrlKey) {
this.blur();
} else {
this.props.onDone && this.props.onDone();
}
break;
default:
break;
}
},
blur: function(){
this.getDOMNode().blur();
this.context.returnFocus && this.context.returnFocus();
},
selectContents: function () {
var range = document.createRange();
range.selectNodeContents(this.getDOMNode());
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
},
onFocus: function () {
this.setState({editable: true}, this.selectContents);
},
onBlur: function (e) {
this.setState({editable: false});
this.handleChange();
this.props.onDone && this.props.onDone();
},
onInput: function () {
this.handleChange();
},
handleChange: function () {
var content = this.getDOMNode().textContent;
if (content !== this.props.content) {
this.props.onChange(content);
}
}
});
var ValidateInlineInput = React.createClass({
getInitialState: function () {
return {
content: ""+this.props.content,
originalContent: ""+this.props.content
};
},
onChange: function (val) {
this.setState({
content: val
});
},
onDone: function () {
if (this.state.content === this.state.originalContent) {
return true;
}
if (this.props.isValid(this.state.content)) {
this.props.onChange(this.state.content);
} else {
this.setState({
content: this.state.originalContent
});
}
},
componentWillReceiveProps: function (nextProps) {
if (nextProps.content !== this.state.content) {
this.setState({
content: ""+nextProps.content,
originalContent: ""+nextProps.content
})
}
},
render: function () {
var className = this.props.className || "";
if (this.props.isValid(this.state.content)) {
className += " has-success";
} else {
className += " has-warning"
}
return ;
}
});
var RequestLine = React.createClass({
render: function () {
var flow = this.props.flow;
var url = flowutils.RequestUtils.pretty_url(flow.request);
var httpver = "HTTP/" + flow.request.httpversion.join(".");
return
},
isValidMethod: function (method) {
return true;
},
isValidUrl: function (url) {
var u = flowutils.parseUrl(url);
return !!u.host;
},
onMethodChange: function (nextMethod) {
actions.FlowActions.update(
this.props.flow,
{request: {method: nextMethod}}
);
},
onUrlChange: function (nextUrl) {
var props = flowutils.parseUrl(nextUrl);
props.path = props.path || "";
actions.FlowActions.update(
this.props.flow,
{request: props}
);
},
onHttpVersionChange: function (nextVer) {
var ver = flowutils.parseHttpVersion(nextVer);
actions.FlowActions.update(
this.props.flow,
{request: {httpversion: ver}}
);
}
});
var ResponseLine = React.createClass({
render: function () {
var flow = this.props.flow;
var httpver = "HTTP/" + flow.response.httpversion.join(".");
return
;
},
isValidCode: function (code) {
return /^\d+$/.test(code);
},
isValidMsg: function () {
return true;
},
onHttpVersionChange: function (nextVer) {
var ver = flowutils.parseHttpVersion(nextVer);
actions.FlowActions.update(
this.props.flow,
{response: {httpversion: ver}}
);
},
onMsgChange: function(nextMsg){
actions.FlowActions.update(
this.props.flow,
{response: {msg: nextMsg}}
);
},
onCodeChange: function(nextCode){
nextCode = parseInt(nextCode);
actions.FlowActions.update(
this.props.flow,
{response: {code: nextCode}}
);
}
});
var Request = React.createClass({
render: function () {
var flow = this.props.flow;
return (
);
}
});
var Response = React.createClass({
render: function () {
var flow = this.props.flow;
return (
);
}
});
var Error = React.createClass({
render: function () {
var flow = this.props.flow;
return (
{flow.error.msg}
{ utils.formatTimeStamp(flow.error.timestamp) }
);
}
});
module.exports = {
Request: Request,
Response: Response,
Error: Error
};