Advertisement
katermarc

Untitled

Apr 30th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var React = require('react');
  4. var ReactDom = require('react-dom');
  5. var client = require('./client');
  6.  
  7. class ValuesDialog extends React.Component {
  8.     constructor(props) {
  9.         super(props);
  10.         this.handleSubmit = this.handleSubmit.bind(this);
  11.         // this.sendValuesArray = this.sendValuesArray.bind(this);
  12.         //this.getValuesArray = this.getValuesArray.bind(this);
  13.     };
  14.  
  15.     handleSubmit(event) {
  16.         event.preventDefault();
  17.         var values = [];
  18.         var i = 0;
  19.         for (var k = 0; k < (this.props.rows); k++, i++) {
  20.             values[k] = [];
  21.             for (var j = 0; j < this.props.cols + 1; j++, i++) {
  22.                 values[k][j] = this.refs["x" + i].value.trim();
  23.             }
  24.         }
  25.         values = JSON.stringify(values);
  26.         var sendValuesArray = function (values) {
  27.             fetch('/result', {
  28.                 method: 'POST',
  29.                 headers: {
  30.                     'Content-Type': 'application/json'
  31.                 },
  32.                 body: values
  33.             })
  34.         }(values);
  35.         window.location = "#";
  36.     };
  37.  
  38.     render() {
  39.         var inputs = [];
  40.         var i = 0;
  41.         for (var k = 0; k < (this.props.rows); k++, i++) {
  42.             for (var j = 0; j < this.props.cols - 1; j++, i++) {
  43.                 inputs[i] = function () {
  44.                     return (
  45.                         <text>
  46.                             <input type="text" ref={"x" + (i)} className="field" placeholder={"x" + (j + 1)}
  47.                                    key={"x" + (i)}/>
  48.                             +
  49.                         </text>
  50.                     )
  51.                 }();
  52.             }
  53.             inputs[i] = function () {
  54.                 return (
  55.                     <input type="text" className="field" ref={"x" + (i)} placeholder={"x" + (j + 1)} key={"x" + (i)}/>
  56.                 )
  57.             }();
  58.  
  59.             i++;
  60.             var sign = "<";
  61.             inputs[i] = function () {
  62.                 return (
  63.                     <text>
  64.                         {sign}
  65.                         <input type="text" className="field" ref={"x" + (i)} placeholder={"srct" + (k + 1)}
  66.                                key={"srct" + (k + 1)}/><br/>
  67.                     </text>
  68.  
  69.                 )
  70.             }();
  71.         }
  72.  
  73.         var dialogId = "setValues";
  74.  
  75.         return (
  76.             <div>
  77.                 <a href={"#" + dialogId}>setValues</a>
  78.  
  79.                 <div id={dialogId} className="modalDialog">
  80.                     <div>
  81.                         <a href="#" title="Close" className="close">X</a>
  82.  
  83.                         <h2>Задайте уравнения и ограничения</h2>
  84.                         <h4>*(если переменной нет, задайте 0)</h4>
  85.                         <br/>
  86.                         <form action="result" method="get">
  87.                             <div className="inputs-array">{inputs}</div>
  88.                             <button onClick={this.handleSubmit.bind(this)}>NEXT</button>
  89.                         </form>
  90.                     </div>
  91.                 </div>
  92.             </div>
  93.         );
  94.     };
  95. }
  96.  
  97. class App extends React.Component {
  98.     constructor() {
  99.         super();
  100.         this.state = {
  101.             cols: '2',
  102.             rows: '3'
  103.         };
  104.         this.handleChangeCols = this.handleChangeCols.bind(this);
  105.         this.handleChangeRows = this.handleChangeRows.bind(this);
  106.         this.onButtonClick = this.onButtonClick.bind(this);
  107.     }
  108.  
  109.     handleChangeCols(event) {
  110.         this.setState({
  111.             cols: event.target.value
  112.         });
  113.     }
  114.  
  115.     handleChangeRows(event) {
  116.         this.setState({
  117.             rows: event.target.value
  118.         });
  119.     }
  120.  
  121.     onButtonClick(event) {
  122.         return (
  123.             <ValuesDialog cols={this.state.cols} rows={this.state.rows}/>
  124.         );
  125.     }
  126.  
  127.     render() {
  128.         return (
  129.             <div>
  130.                 <form onSubmit={this.handleSubmit}>
  131.                     <span className="instruction"> Количество переменных  </span>
  132.                     <select name="cols" className="input" value={this.state.cols} onChange={this.handleChangeCols}>
  133.                         <option value="2">2</option>
  134.                         <option value="3">3</option>
  135.                         <option value="4">4</option>
  136.                         <option value="5">5</option>
  137.                         <option value="6">6</option>
  138.                         <option value="7">7</option>
  139.                     </select>
  140.                     <br/>
  141.                     <br/>
  142.                     <span className="instruction"> Количество ограничений  </span>
  143.                     <select name="rows" className="input" value={this.state.rows} onChange={this.handleChangeRows}>
  144.                         <option value="2">2</option>
  145.                         <option value="3">3</option>
  146.                         <option value="4">4</option>
  147.                         <option value="5">5</option>
  148.                         <option value="6">6</option>
  149.                         <option value="7">7</option>
  150.                     </select>
  151.                 </form>
  152.                 <br/>
  153.                 <imaginary><ValuesDialog cols={this.state.cols} rows={this.state.rows}/></imaginary>
  154.                 <br/>
  155.                 <a href="/index.html#setValues" className="button"> <b className="boldText">{this.state.cols}</b>
  156.                     переменных и <b className="boldText">{this.state.rows}</b> ограничения</a>
  157.                 <br/>
  158.             </div>
  159.         );
  160.     }
  161. }
  162.  
  163. ReactDom.render(<App />, document.getElementById('react'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement