55b6ff3e3301e6dd1bb64233366deeed29ad4c7d
[workouts] /
1 <script type="text/javascript">
2 var WorkoutManagementWorkoutTableRows = React.createClass({//Workout Management Table Rows
3         getInitialState: function () {
4                 var attrs = JSON.parse(JSON.stringify(this.props.data.attrs));
5                 return {workout_name:this.props.data.name,comments:this.props.data.comments,attributes:attrs,view:""};
6         },
7         handleValueChange: function(type,event) {
8                 switch(type){
9                         case "workout_name":
10                                 this.setState({workout_name:event.target.value});
11                                 break;
12                         case "comments":
13                                 this.setState({comments:event.target.value});
14                                 break;
15                         default:
16                                 console.log('error');
17                 }
18         },
19         sendValues: function () {
20                 $.ajax({
21                         url: 'php/dbq.php',
22                         type: 'POST',
23                         data: {query_type:'workout_management_edit',id:this.props.data.id,workout_name:this.state.workout_name,attributes:this.state.attributes,comments:this.state.comments},
24                         success: function(data){
25                                 console.log(data);
26                         },
27                         error: function (xhr,status,err) {
28                                 console.error("WorkoutManagementWorkoutTableRows.php","workout_management_edit",status,err.toString());
29                         }
30                 });
31         },
32         handleAttrToggle: function (attr) {
33                 var attrs = JSON.parse(JSON.stringify(this.state.attributes));
34                 attrs[attr]=(attrs[attr]=="No")?"Yes":"No";
35                 this.setState({attributes:attrs},function () {
36                         this.sendValues();
37                 });
38         },
39         deleteToggle: function (type) {
40                 this.setState({deletetd:type});
41         },
42         deleteEntry: function () {
43                 var c = confirm("Are you sure you wish to delete this workout? This will also delete all data of completion of this workout.");
44                 if(c==true){
45                         this.setState({view:"hidden"},function () {
46                                 $.ajax({
47                                         url: 'php/dbq.php',
48                                         type: 'POST',
49                                         data: {query_type:'workout_management_delete',id:this.props.data.id},
50                                         success: function(data){
51                                                 console.log(data);
52                                         },
53                                         error: function (xhr,status,err) {
54                                                 console.error("WorkoutManagementWorkoutTableRows.php","workout_management_delete",status,err.toString());
55                                         }
56                                 });
57                         });
58                 }
59         },
60         render: function () {
61                 var cells = [];
62                 for(var attr in this.state.attributes){
63                         cells.push(React.createElement("td",{key:"wm-row-"+this.props.data.id+"-attr-"+attr,onClick:this.handleAttrToggle.bind(this,attr)},
64                                 React.createElement("span",null,this.state.attributes[attr])
65                         ));
66                 }
67                 return React.createElement("tr",{className:this.props.rowtype+" "+this.state.view},
68                         React.createElement("td",{className:"inputok"},
69                                 React.createElement("input",{className:"workout-management-table-input",value:this.state.workout_name,type:"text",onChange:this.handleValueChange.bind(this,"workout_name"),onBlur:this.sendValues})
70                         ),
71                         cells,
72                         React.createElement("td",null,
73                                 React.createElement("span",null,this.props.data['times_done'])
74                         ),
75                         React.createElement("td",null,
76                                 React.createElement("span",null,this.props.data['last_done'])
77                         ),
78                         React.createElement("td",{className:"inputok"},
79                                 React.createElement("textarea",{className:"workout-management-table-comments",value:this.state.comments,onChange:this.handleValueChange.bind(this,"comments"),onBlur:this.sendValues}),
80                                 React.createElement("div",{className:this.state.deletetd},
81                                         React.createElement("div",{className:"workout-management-table-delete-container"},
82                                                 React.createElement("i",{className:"fa fa-trash-o",onClick:this.deleteEntry})
83                                         )
84                                 )
85                         )
86                 );
87         }
88 });
89 </script>