]> infiniteadaptability.org Git - workouts/blob
34cad126462163c8837ab2577fb1694abee43539
[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                 serverRequest({query_type:'workout_management_edit',id:this.props.data.id,workout_name:this.state.workout_name,attributes:this.state.attributes,comments:this.state.comments})
21                 .then(function(data) {
22                         console.log(data);
23                 })
24                 .catch(function(error) {
25                         console.error("WorkoutManagementWorkoutTableRows.php","workout_management_edit",error);
26                 });
27         },
28         handleAttrToggle: function (attr) {
29                 var attrs = JSON.parse(JSON.stringify(this.state.attributes));
30                 attrs[attr]=(attrs[attr]=="No")?"Yes":"No";
31                 this.setState({attributes:attrs},function () {
32                         this.sendValues();
33                 });
34         },
35         deleteToggle: function (type) {
36                 this.setState({deletetd:type});
37         },
38         deleteEntry: function () {
39                 var c = confirm("Are you sure you wish to delete this workout? This will also delete all data of completion of this workout.");
40                 if(c==true){
41                         this.setState({view:"hidden"},function () {
42                                 serverRequest({query_type:'workout_management_delete',id:this.props.data.id})
43                                 .then(function(data) {
44                                         console.log(data);
45                                 })
46                                 .catch(function(error) {
47                                         console.error("WorkoutManagementWorkoutTableRows.php","workout_management_delete",error);
48                                 });
49                         });
50                 }
51         },
52         render: function () {
53                 var cells = [];
54                 for(var attr in this.state.attributes){
55                         cells.push(React.createElement("td",{key:"wm-row-"+this.props.data.id+"-attr-"+attr,onClick:this.handleAttrToggle.bind(this,attr)},
56                                 React.createElement("span",null,this.state.attributes[attr])
57                         ));
58                 }
59                 return React.createElement("tr",{className:this.props.rowtype+" "+this.state.view},
60                         React.createElement("td",{className:"inputok"},
61                                 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})
62                         ),
63                         cells,
64                         React.createElement("td",null,
65                                 React.createElement("span",null,this.props.data['times_done'])
66                         ),
67                         React.createElement("td",null,
68                                 React.createElement("span",null,this.props.data['last_done'])
69                         ),
70                         React.createElement("td",{className:"inputok"},
71                                 React.createElement("textarea",{className:"workout-management-table-comments",value:this.state.comments,onChange:this.handleValueChange.bind(this,"comments"),onBlur:this.sendValues}),
72                                 React.createElement("div",{className:this.state.deletetd},
73                                         React.createElement("div",{className:"workout-management-table-delete-container"},
74                                                 React.createElement("i",{className:"fa fa-trash-o",onClick:this.deleteEntry})
75                                         )
76                                 )
77                         )
78                 );
79         }
80 });
81 </script>