Advertisement
Guest User

TESTTEST

a guest
May 26th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Hello React</title>
  4. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
  5. <script src="https://fb.me/react-0.13.3.js"></script>
  6. <script src="https://fb.me/JSXTransformer-0.13.3.js"></script>
  7. <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
  8. <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.2/marked.min.js"></script>
  9. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
  10. </head>
  11. <body>
  12. <style>
  13. .bold {
  14. font-weight: bold;
  15. }
  16.  
  17. .textcenter {
  18. text-align: center;
  19. }
  20.  
  21. .margin-bot-20 {
  22. margin-bottom: 20px;
  23. }
  24.  
  25. .productSearchImage {
  26. width: 80%;
  27. }
  28.  
  29. .productSearchName {
  30. margin-top: 5px;
  31. font-size: 20px;
  32. }
  33.  
  34. </style>
  35. <div id="content"></div>
  36. <script type="text/jsx">
  37.  
  38. /*var ProductBox = React.createClass({
  39. loadProductsFromServer: function() {
  40. $.ajax({
  41. url: this.props.url,
  42. dataType: 'json',
  43. cache: false,
  44. success: function(data) {
  45. this.setState({data: data});
  46. }.bind(this),
  47. error: function(xhr, status, err) {
  48. console.error(this.props.url, status, err.toString());
  49. }.bind(this)
  50. });
  51. },
  52. getInitialState: function() {
  53. return {data: []};
  54. },
  55. componentDidMount: function() {
  56. this.loadProductsFromServer();
  57. setInterval(this.loadProductsFromServer, this.props.pollInterval);
  58. },
  59. render: function() {
  60. return (
  61. <div>
  62. <h1>PRODUCTS</h1>
  63. <ProductList products={this.props.products} />
  64. </div>
  65. )
  66. }
  67. });*/
  68.  
  69. var FilteredProductTable = React.createClass({
  70. loadProductsFromServer: function() {
  71. $.ajax({
  72. url: this.props.url,
  73. dataType: 'json',
  74. cache: false,
  75. success: function(data) {
  76. this.setState({data: data});
  77. }.bind(this),
  78. error: function(xhr, status, err) {
  79. console.error(this.props.url, status, err.toString());
  80. }.bind(this)
  81. });
  82. },
  83. getInitialState: function() {
  84. return {data: []};
  85. },
  86. componentDidMount: function() {
  87. this.loadProductsFromServer();
  88. setInterval(this.loadProductsFromServer, this.props.pollInterval);
  89. },
  90. render: function() {
  91. return (
  92. <div>
  93. <h1>PRODUCTS</h1>
  94. <ProductTable products={this.state.data} />
  95.  
  96. </div>
  97. );
  98. }
  99. });
  100.  
  101. var ProductTable = React.createClass({
  102. render: function() {
  103. var rows = [];
  104. var lastCategory = null;
  105. this.props.products.forEach(function(product) {
  106. rows.push(<ProductRow product={product} key={product.name} />);
  107. });
  108. return (
  109. <div className="container">
  110. {rows}
  111. </div>
  112. );
  113. }
  114. });
  115.  
  116.  
  117. var ProductRow = React.createClass({
  118. render: function() {
  119. return (
  120. <div className="col-md-4 textcenter margin-bot-20">
  121. <img src={this.props.product.thumbnail} alt="boohoo" className="productSearchImage" />
  122. <p className="productSearchName bold">{this.props.product.name}</p>
  123. <p className="productSearchPrice bold">Kr.{this.props.product.variants[0].price},-</p>
  124. <a href="/products/{this.props.product.number}"><button className="bold">Se mere</button></a>
  125. </div>
  126. );
  127. }
  128. });
  129.  
  130. var ProductCategoryRow = React.createClass({
  131. render: function() {
  132. return (<tr><th colSpan="2">{this.props.category}</th></tr>);
  133. }
  134. });
  135.  
  136. /*var ProductName = React.createClass({
  137.  
  138. });
  139.  
  140. var ProductPrice = React.createClass({
  141.  
  142. });
  143.  
  144. var Button = React.createClass({
  145.  
  146. });*/
  147.  
  148. React.render(
  149. <FilteredProductTable url="http://52.16.142.71:3000/api/products" pollInterval={2000} />,
  150. document.getElementById('content')
  151. );
  152.  
  153. </script>
  154. </body>
  155. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement