1 | /** @jsx React.DOM */ |
---|
2 | (function() { |
---|
3 | "use strict"; |
---|
4 | |
---|
5 | var PT = React.PropTypes; |
---|
6 | var ReactCSSTransitionGroup = React.addons.ReactCSSTransitionGroup; |
---|
7 | var ReactTransitionGroup = React.addons.TransitionGroup; |
---|
8 | |
---|
9 | window.MyReact = {}; |
---|
10 | |
---|
11 | var JQuerySlide = React.createClass({displayName: 'JQuerySlide', |
---|
12 | componentWillEnter: function(callback){ |
---|
13 | var el = jQuery(this.getDOMNode()); |
---|
14 | el.css("display", "none"); |
---|
15 | el.slideDown(500, callback); |
---|
16 | $el.slideDown(function(){ |
---|
17 | callback(); |
---|
18 | }); |
---|
19 | }, |
---|
20 | componentWillLeave: function(callback){ |
---|
21 | var $el = jQuery(this.getDOMNode()); |
---|
22 | $el.slideUp(function(){ |
---|
23 | callback(); |
---|
24 | }); |
---|
25 | }, |
---|
26 | render: function(){ |
---|
27 | return this.transferPropsTo(this.props.component({style: {display: 'none'}})); |
---|
28 | } |
---|
29 | }); |
---|
30 | window.MyReact.JQuerySlide = JQuerySlide; |
---|
31 | |
---|
32 | var JQueryFade = React.createClass({displayName: 'JQueryFade', |
---|
33 | componentWillEnter: function(callback){ |
---|
34 | var el = jQuery(this.getDOMNode()); |
---|
35 | el.css("display", "none"); |
---|
36 | el.fadeIn(500, callback); |
---|
37 | }, |
---|
38 | componentWillLeave: function(callback){ |
---|
39 | jQuery(this.getDOMNode()).fadeOut(500, callback); |
---|
40 | }, |
---|
41 | render: function() { |
---|
42 | return this.props.children; |
---|
43 | } |
---|
44 | }); |
---|
45 | window.MyReact.JQueryFade = JQueryFade; |
---|
46 | |
---|
47 | window.MyReact.ErrorPane = React.createClass({displayName: 'ErrorPane', |
---|
48 | propTypes: { |
---|
49 | errorMessages: PT.array.isRequired, |
---|
50 | }, |
---|
51 | |
---|
52 | renderErrorMessage: function(errorMessage, index) { |
---|
53 | return errorMessage ? |
---|
54 | React.createElement(JQueryFade, {key: index}, |
---|
55 | React.createElement("div", {key: index, className: "errorMessage"}, errorMessage) |
---|
56 | ) : |
---|
57 | false; |
---|
58 | }, |
---|
59 | |
---|
60 | render: function() { |
---|
61 | return React.createElement("div", {className: "container errorDiv"}, |
---|
62 | React.createElement("div", {className: "row errorRow"}, |
---|
63 | React.createElement(ReactTransitionGroup, {component: "div"}, |
---|
64 | this.props.errorMessages.map(this.renderErrorMessage) |
---|
65 | ) |
---|
66 | ) |
---|
67 | ); |
---|
68 | } |
---|
69 | }); |
---|
70 | |
---|
71 | |
---|
72 | window.MyReact.Modal = React.createClass({displayName: 'Modal', |
---|
73 | propTypes: { |
---|
74 | title: PT.string.isRequired, |
---|
75 | }, |
---|
76 | componentDidMount: function() { |
---|
77 | $(this.getDOMNode()).modal({background: true, keyboard: true, show: false}); |
---|
78 | }, |
---|
79 | componentWillUnmount: function() { |
---|
80 | $(this.getDOMNode()).off('hidden'); |
---|
81 | }, |
---|
82 | handleClick: function(e) { |
---|
83 | e.stopPropagation(); |
---|
84 | }, |
---|
85 | render: function() { |
---|
86 | return ( |
---|
87 | React.createElement("div", {onClick: this.handleClick, className: "modal fade", role: "dialog", 'aria-hidden': "true"}, |
---|
88 | React.createElement("div", {className: "modal-dialog"}, |
---|
89 | React.createElement("div", {className: "modal-content"}, |
---|
90 | React.createElement("div", {className: "modal-header"}, |
---|
91 | React.createElement("button", {type: "button", className: "close", 'data-dismiss': "modal"}, |
---|
92 | React.createElement("span", {'aria-hidden': "true"}, "Ã"), |
---|
93 | React.createElement("span", {className: "sr-only"}, "Close") |
---|
94 | ), |
---|
95 | React.createElement("h2", {className: "modal-title"}, this.props.title) |
---|
96 | ), |
---|
97 | React.createElement("div", {className: "modal-body"}, |
---|
98 | this.props.children |
---|
99 | ), |
---|
100 | React.createElement("div", {className: "modal-footer"}, |
---|
101 | React.createElement("button", {type: "button", className: "btn btn-default", 'data-dismiss': "modal"}, "Close") |
---|
102 | ) |
---|
103 | ) |
---|
104 | ) |
---|
105 | ) |
---|
106 | ); |
---|
107 | } |
---|
108 | }); |
---|
109 | |
---|
110 | |
---|
111 | var PopoverMixin = window.MyReact.PopoverMixin = { |
---|
112 | getDefaultProps: function(){ |
---|
113 | return {hasPopover: true}; |
---|
114 | }, |
---|
115 | |
---|
116 | componentDidMount: function() { |
---|
117 | this.refresh(); |
---|
118 | }, |
---|
119 | componentDidUpdate: function() { |
---|
120 | this.refresh(); |
---|
121 | }, |
---|
122 | |
---|
123 | refresh: function() { |
---|
124 | $(this.getDOMNode()).popover('destroy'); |
---|
125 | |
---|
126 | var content; |
---|
127 | if (Array.isArray(this.props.children)) |
---|
128 | content = this.props.children.map(React.renderToString).join(" "); |
---|
129 | else |
---|
130 | content = React.renderToString(this.props.children); |
---|
131 | // console.log("children: ", this.props.children); |
---|
132 | // console.log("content: ", content); |
---|
133 | $(this.getDOMNode()).popover({ |
---|
134 | content: content, |
---|
135 | animation: this.props.animation, |
---|
136 | placement: this.props.placement, |
---|
137 | title: this.props.title, |
---|
138 | trigger: 'click', |
---|
139 | html: true, |
---|
140 | }); |
---|
141 | }, |
---|
142 | |
---|
143 | componentWillUnmount: function() { |
---|
144 | $(this.getDOMNode()).popover('destroy'); |
---|
145 | }, |
---|
146 | }; |
---|
147 | |
---|
148 | window.MyReact.Popover = React.createClass({displayName: 'Popover', |
---|
149 | propTypes: { |
---|
150 | placement: PT.string, |
---|
151 | title: PT.string, |
---|
152 | triggerButtonClass: PT.string, |
---|
153 | triggerButtonContent: PT.element.isRequired |
---|
154 | }, |
---|
155 | mixins: [PopoverMixin], |
---|
156 | |
---|
157 | handleClick: function(e) { |
---|
158 | e.stopPropagation(); |
---|
159 | }, |
---|
160 | |
---|
161 | render: function() { |
---|
162 | return React.createElement("button", {className: this.props.triggerButtonClass, onClick: this.handleClick}, |
---|
163 | this.props.triggerButtonContent |
---|
164 | ); |
---|
165 | } |
---|
166 | }); |
---|
167 | |
---|
168 | window.MyReact.InfoPopover = React.createClass({displayName: 'InfoPopover', |
---|
169 | propTypes: { |
---|
170 | title: PT.string.isRequired, |
---|
171 | }, |
---|
172 | mixins: [PopoverMixin], |
---|
173 | |
---|
174 | handleClick: function(e) { |
---|
175 | e.stopPropagation(); |
---|
176 | }, |
---|
177 | |
---|
178 | render: function() { |
---|
179 | var inline = {display:"inline-block"}; |
---|
180 | return React.createElement("button", {style: inline, className: "btn btn-default btn-xs", onClick: this.handleClick}, |
---|
181 | React.createElement("span", {className: "glyphicon glyphicon-info-sign"}) |
---|
182 | ); |
---|
183 | } |
---|
184 | }); |
---|
185 | |
---|
186 | |
---|
187 | window.MyReact.Panel = React.createClass({displayName: 'Panel', |
---|
188 | propTypes: { |
---|
189 | title:PT.object.isRequired, |
---|
190 | info:PT.object.isRequired, |
---|
191 | }, |
---|
192 | |
---|
193 | getInitialState: function() { |
---|
194 | return { |
---|
195 | open: true, |
---|
196 | }; |
---|
197 | }, |
---|
198 | |
---|
199 | toggleState: function(e) { |
---|
200 | this.setState({open: !this.state.open}); |
---|
201 | }, |
---|
202 | |
---|
203 | render: function() { |
---|
204 | var chevron = "glyphicon glyphicon-chevron-" + (this.state.open ? "down":"right"); |
---|
205 | var chevronStyle = {fontSize:12}; |
---|
206 | var right = {float:"right"}; |
---|
207 | return React.createElement("div", {className: "bs-callout bs-callout-info"}, |
---|
208 | React.createElement("div", {className: "panel"}, |
---|
209 | React.createElement("div", {className: "panel-heading unselectable row", onClick: this.toggleState}, |
---|
210 | React.createElement("div", {className: "panel-title unselectable col-sm-11"}, |
---|
211 | React.createElement("span", {className: chevron, style: chevronStyle}), "Â ", |
---|
212 | this.props.title |
---|
213 | ), |
---|
214 | React.createElement("div", {style: right}, |
---|
215 | this.props.info |
---|
216 | ) |
---|
217 | ), |
---|
218 | this.state.open ? |
---|
219 | React.createElement("div", {className: "panel-body"}, this.props.children) : |
---|
220 | false |
---|
221 | ) |
---|
222 | ); |
---|
223 | } |
---|
224 | }); |
---|
225 | |
---|
226 | window.MyReact.PanelGroup = React.createClass({displayName: 'PanelGroup', |
---|
227 | render: function() { |
---|
228 | return React.createElement("div", {className: "panel-group"}, " ", this.props.children, " "); |
---|
229 | }, |
---|
230 | }); |
---|
231 | |
---|
232 | })(); |
---|