This repository was archived by the owner on Aug 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFormHeader.js
More file actions
66 lines (54 loc) · 1.92 KB
/
FormHeader.js
File metadata and controls
66 lines (54 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/** @jsx React.DOM */
"use strict";
var React = require("react");
var TEMPLATE = (
"{{formName}}\n" +
"---------------------\n" +
"\n" +
" * User Link: {{userlink}}\n" +
" * Admin Link: {{adminlink}}"
);
var FormHeader = React.createClass({
render: function() {
var userLink, reportLink, downloadButton;
if (this.props.userLink) {
userLink = <div><a href={this.props.userLink} title="Share this URL to display the online form.">
<i className="fa-link fa fa-1x"></i> {this.props.userLink}
</a></div>;
}
if (this.props.reportLink) {
reportLink = <div><a href={this.props.reportLink} title="Share this URL to display the form answers.">
<i className="fa-link fa fa-1x"></i> {this.props.reportLink}
</a></div>;
var filename = "form-" + this.props.metadata.formName + ".txt";
var fileContent = "data:text/plain;base64," + btoa(
TEMPLATE
.replace("{{userlink}}", this.props.userLink)
.replace("{{adminlink}}", this.props.reportLink)
.replace("{{formName}}", this.props.metadata.formName)
);
downloadButton = <a download={filename} href={fileContent} className="btn btn-primary pull-right">Download</a>;
}
var buttonClasses = "btn btn-success pull-right";
if (!this.props.formReady) {
buttonClasses = buttonClasses + " disabled";
}
var saveButtonValue = "Save form";
if (this.props.formStatus === "saved") {
saveButtonValue = <div><i className="fa fa-check"></i> Saved</div>;
} else if (this.props.formStatus == "pending") {
saveButtonValue = <div><i className="fa fa-refresh spin"></i> Save form</div>;
}
return <header>
<button
className={buttonClasses}
onClick={this.props.submitForm} >
{saveButtonValue}
</button>
{downloadButton}
{userLink}
{reportLink}
</header>;
}
});
module.exports = FormHeader;