function retrieve_circuit(){
    
    // Due to Cross-Origin Resource Sharing (CORS) policy restrictions the following request will
    // not work if request is sent to Django local development server from the Vue.js development server
    // In order to test while developeing, launch chrome in the following flags:
    // google-chrome --disable-site-isolation-trials --disable-web-security --user-data-dir="/tmp"
    window.circuitId = get_request_param('circuitid');
    let authToken = getCookie('auth-token');
    if (window.circuitId && authToken){
  
        let xmlHttpReq = new XMLHttpRequest();
        let url = '/projects/circuits-api/?circuitid='.concat(window.circuitId);
        xmlHttpReq.open( 'GET', url, false); //TODO: this must be changed to an async request
        xmlHttpReq.setRequestHeader('Authorization', authToken);
        xmlHttpReq.setRequestHeader('Accept', 'application/json');

        let retries = 0;
        while (xmlHttpReq.status != 200 && retries < 3) {
          xmlHttpReq.send(null);
          if (xmlHttpReq.responseText && xmlHttpReq.status == 200){
              let jsonObj = JSON.parse(xmlHttpReq.responseText);
              if (!jsonObj.version || jsonObj.version == "1.0"){
                alert("Unfortunately this circuit format is outdated. We will refrain from introducing backwards incompatible changes in the future.")
                jsonObj = JSON.parse('{"version": "1.1", "circuit-type": "simple", "steps": []}');
              }
              return jsonObj;
          } 
          retries += 1;
        }
        alert('Failed to retrieve the circuit code. Please try to reload the page.');
    }
        
    return JSON.parse('{"version": "1.1", "circuit-type": "simple", "steps": []}');
  }
/* use Django REST API to retrieve circuit */
use Django REST API to retrieve circuit
use Django REST API to retrieve circuit
function retrieve_circuit(){
    window.circuitId = get_request_param('circuitid');
    let authToken = getCookie('auth-token');
    if (window.circuitId && authToken){
        let xmlHttpReq = new XMLHttpRequest();
        let url = '/projects/circuits-api/?circuitid='.concat(window.circuitId);
        xmlHttpReq.open( 'GET', url, false); 
        xmlHttpReq.setRequestHeader('Authorization', authToken);
        xmlHttpReq.setRequestHeader('Accept', 'application/json');
        let retries = 0;
        while (xmlHttpReq.status != 200 && retries < 3) {
          xmlHttpReq.send(null);
          if (xmlHttpReq.responseText && xmlHttpReq.status == 200){
              let jsonObj = JSON.parse(xmlHttpReq.responseText);
              if (!jsonObj.version || jsonObj.version == "1.0"){
                alert("Unfortunately this circuit format is outdated. We will refrain from introducing backwards incompatible changes in the future.")
                jsonObj = JSON.parse('{"version": "1.1", "circuit-type": "simple", "steps": []}');
              }
              return jsonObj;
          } 
          retries += 1;
        }
        alert('Failed to retrieve the circuit code. Please try to reload the page.');
    }
    return JSON.parse('{"version": "1.1", "circuit-type": "simple", "steps": []}');
  }
function retrieve_circuit ( ) { window . circuitId = get_request_param ( 'circuitid' ) ; let authToken = getCookie ( 'auth-token' ) ; if ( window . circuitId && authToken ) { let xmlHttpReq = new XMLHttpRequest ( ) ; let url = '/projects/circuits-api/?circuitid=' . concat ( window . circuitId ) ; xmlHttpReq . open ( 'GET' , url , false ) ; xmlHttpReq . setRequestHeader ( 'Authorization' , authToken ) ; xmlHttpReq . setRequestHeader ( 'Accept' , 'application/json' ) ; let retries = 0 ; while ( xmlHttpReq . status != 200 && retries < 3 ) { xmlHttpReq . send ( null ) ; if ( xmlHttpReq . responseText && xmlHttpReq . status == 200 ) { let jsonObj = JSON . parse ( xmlHttpReq . responseText ) ; if ( ! jsonObj . version || jsonObj . version == "1.0" ) { alert ( "Unfortunately this circuit format is outdated. We will refrain from introducing backwards incompatible changes in the future." ) jsonObj = JSON . parse ( '{"version": "1.1", "circuit-type": "simple", "steps": []}' ) ; } return jsonObj ; } retries += 1 ; } alert ( 'Failed to retrieve the circuit code. Please try to reload the page.' ) ; } return JSON . parse ( '{"version": "1.1", "circuit-type": "simple", "steps": []}' ) ; }
use Django REST API to retrieve circuit
use Django REST API to retrieve circuit
// Due to Cross-Origin Resource Sharing (CORS) policy restrictions the following request will // not work if request is sent to Django local development server from the Vue.js development server // In order to test while developeing, launch chrome in the following flags: // google-chrome --disable-site-isolation-trials --disable-web-security --user-data-dir="/tmp" //TODO: this must be changed to an async request