-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathEjercicio10.html
More file actions
135 lines (110 loc) · 4.69 KB
/
Ejercicio10.html
File metadata and controls
135 lines (110 loc) · 4.69 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html>
<head>
<script src="http://fb.me/react-with-addons-0.12.0.js"></script>
<script src="http://fb.me/JSXTransformer-0.12.0.js"></script>
<link rel="stylesheet" href="bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-3"></div>
<div id="Tareas" class="col-md-6"></div>
<div class="col-md-3"></div>
</div>
</div>
<script type="text/jsx">
var Espera = {color: 'black'};
var Listo = {color: 'red', textDecoration:'line-through'};
var ListaTareas = React.createClass({
CrearElementosDeLista: function(itemText) {
return <li className="ui-state-default list-group-item" >
<div className="col-md-11">
<input type="checkbox" ref={itemText.estatus} onChange={this.props.EstadoTareaRealizada.bind(this, itemText)} checked={itemText.estatus==0? true :false} />
<span style={itemText.estatus==0? Listo :Espera} > {itemText.titulo}</span>
</div>
<a className="btn btn-danger" onClick={this.props.EstadoBorrar.bind(this, itemText)} >x</a>
</li>;
},
render: function() {
return <ul id="sortable" className="list-unstyled list-group">{this.props.ElementosLista.map(this.CrearElementosDeLista)}</ul>;
}
});
var AplicacionTareas = React.createClass({
componentWillMount: function() {
this.actualizarInformacion();
},
actualizarInformacion: function() {
$.get("Datos/index.php", function(resultado) {
this.setState({ElementosLista: resultado});
this.setState({ElementoListaTemporal: resultado});
}.bind(this));
}
,
getInitialState: function() {
return {ElementosLista: [], text: '',ElementoListaTemporal:[]};
},
EstadoBorrar: function(ElementoAborrar, e) {
$.ajax({
url: "Datos/index.php",
dataType: 'json',
type: 'POST',
data: {id:ElementoAborrar.id,accion:2},
success: function(data) {}.bind(this)
});
this.actualizarInformacion();
},
EstadoCambio: function(event) {
this.setState({text: event.target.value});
var updatedList = this.state.ElementoListaTemporal;
updatedList = updatedList.filter(function(item){
return item.titulo.toLowerCase().search(event.target.value.toLowerCase()) !== -1;
});
this.setState({ElementosLista: updatedList});
},
EstadoTareaRealizada: function(ElementoAborrar, e) {
var indice = this.state.ElementosLista.indexOf(ElementoAborrar);
var valorEstatus=this.state.ElementosLista[indice].estatus=(this.state.ElementosLista[indice].estatus==1)?0:1;
$.ajax({
url: "Datos/index.php",
dataType: 'json',
type: 'POST',
data: {estatus:valorEstatus,id:ElementoAborrar.id,accion:3},
success: function(data) {}.bind(this)
});
this.setState({ElementosLista: this.state.ElementosLista});
this.setState({ElementoListaTemporal: this.state.ElementosLista});
this.actualizarInformacion();
},
EstadoSubmit: function(e) {
$.ajax({
url: "Datos/index.php",
dataType: 'json',
type: 'POST',
data: {titulo:this.state.text,accion:1},
success: function(data) {}.bind(this)
});
this.setState({text: ''});
this.actualizarInformacion();
},
render: function() {
return (
<div>
<h3>Lista de Tareas</h3>
<form onSubmit={this.EstadoSubmit} >
<input className="form-control" placeholder="Agregar a la lista" onChange={this.EstadoCambio} value={this.state.text} />
<br/>
<input type="button" onClick={this.EstadoSubmit} className="btn btn-success btn-block " value={'Agregar a lista #' + (this.state.ElementosLista.length )} />
</form>
<hr/>
<ListaTareas ElementosLista={this.state.ElementosLista}
EstadoBorrar={this.EstadoBorrar} EstadoTareaRealizada={this.EstadoTareaRealizada} />
</div>
);
}
});
React.render(<AplicacionTareas />, document.getElementById('Tareas'));
</script>
</body>
</html>