/**
 * Created by c14hht on 2016-04-28.
 *
 * Class that when entering the studentid, assignmentid, courseid and submitting gets the feedback and view it.
 */

window.Feedback = React.createClass ({

    handleClick: function () {
        var xmlHttp = new XMLHttpRequest();
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                var infoFromDb = JSON.parse(xmlHttp.responseText);
                return (
                    ReactDOM.render(
                        <NewFeedback feedbackResponse={infoFromDb}
                        sourceInfo={"https://" + window.globalURL + "/feedback/video?studentID=" + document.getElementById('student').value
            + "&assignmentID=" + document.getElementById('ass').value + "&courseID=" + document.getElementById('course').value}/>,
                        document.getElementById('courseContent')
                    )
                )
            }
        };
        xmlHttp.open("GET", "https://" + window.globalURL + "/feedback/get?studentID=" + document.getElementById('student').value
            + "&assignmentID=" + document.getElementById('ass').value + "&courseID=" + document.getElementById('course').value, true);
        xmlHttp.send();
    },
    render: function () {
        return (
            <div>
                <form>
                    StudentID: <br />
                    <input id="student"type="text" name="studentid"></input> <br />
                    AssID: <br />
                    <input id="ass" type="text" name="assid"></input> <br />
                    CourseID: <br />
                    <input id="course" type="text" name="courseid"></input>
                </form>
                <button style={{backgroundColor: 'black',color:'white'}} onClick={this.handleClick}>Submit</button>
            </div>
        )
    }
});

var NewFeedback = React.createClass ({

    render: function () {

        var feedbackResponse = this.props.feedbackResponse;
        console.log(this.props.sourceInfo);

        return (
            <div>
                Teacher: {feedbackResponse.teacher} <br />
                Grade: {feedbackResponse.grade} <br />
                Time: {feedbackResponse.time} <br />
                <video width="720" height="460" src={this.props.sourceInfo} preload="auto" controls></video>
            </div>
        )
    }
});

/*ReactDOM.render(
    <Feedback />,
    document.getElementById('courseContent')
);
*/


@@ -494,20 +494,16 @@
         
-    
 ReactDOM
@@ -511,24 +511,16 @@
 render(%0A
-        
         
@@ -586,24 +586,16 @@
         
-        
 sourceIn
@@ -598,29 +598,16 @@
 ceInfo=%7B
-%22https://%22 + 
 window.g
@@ -681,32 +681,40 @@
 student').value%0A
+        
             + %22&
@@ -844,24 +844,16 @@
         
- 
-       
 document
@@ -893,38 +893,26 @@
             
-      
-  )%0A    
+)%0A
             
@@ -969,22 +969,8 @@
 ET%22,
- %22https://%22 + 
 wind
@@ -1297,27 +1297,15 @@
     
-    
 %3Cform%3E%0A
-        
     
@@ -1334,36 +1334,24 @@
  /%3E%0A        
-     
-       
 %3Cinput id=%22s
@@ -1414,24 +1414,16 @@
         
-        
 AssID: %3C
@@ -1424,36 +1424,24 @@
 sID: %3Cbr /%3E%0A
-            
         %3Cinp
@@ -1505,24 +1505,16 @@
         
-        
 CourseID
@@ -1518,36 +1518,24 @@
 eID: %3Cbr /%3E%0A
-            
         %3Cinp
@@ -1602,20 +1602,16 @@
     
-    
 %3C/form%3E%0A
     
@@ -1602,28 +1602,24 @@
     %3C/form%3E%0A
-    
             
@@ -1718,20 +1718,16 @@
 button%3E%0A
-    
         
@@ -1925,17 +1925,140 @@
 eInfo);%0A
-%0A
+        console.log(feedbackResponse.error + %22 feedback response%22);%0A%0A        if(feedbackResponse.error === undefined) %7B%0A    
         
@@ -2058,32 +2058,36 @@
        return (%0A
+    
             %3Cdiv
@@ -2159,20 +2159,16 @@
         
-    
 Grade: %7B
@@ -2190,36 +2190,32 @@
 e.grade%7D %3Cbr /%3E%0A
-    
             Time
@@ -2259,20 +2259,16 @@
         
-    
 %3Cvideo w
@@ -2373,32 +2373,186 @@
 /div%3E%0A        )%0A
+        %7D else %7B%0A            return (%0A                %3Cdiv%3E%0A                Error: %7BfeedbackResponse.error%7D %3Cbr /%3E%0A            %3C/div%3E%0A        )%0A        %7D%0A
     %7D%0A%7D);%0A%0A/*Rea
@@ -2565,19 +2565,16 @@
 render(%0A
-   
  %3CFeedba
@@ -2580,19 +2580,16 @@
 ack /%3E,%0A
-   
  documen
@@ -2622,15 +2622,17 @@
 ntent')%0A
+ 
 );%0A
+ 
 */%0A%0A

Add error handling