Template:Team:Paris Saclay/simbox

From 2013.igem.org

(Difference between revisions)
Line 117: Line 117:
  return true;
  return true;
 +
}
 +
 +
function is_posint(str)
 +
{
 +
  var parsed= parseInt(str);
 +
  if(isNaN(parsed)) return false;
 +
  if(!isFinite(parsed)) return false;
 +
  if(parsed < 0) return false;
 +
  return true;
}
}
Line 130: Line 139:
  {
  {
   //TODO START
   //TODO START
 +
  for(var i= 0 ; i < simulations[simid].molecules.length ; ++i)
 +
  {
 +
  if(simulations[simid].molecules[i].curve_show)
 +
  {
 +
    var tmpval= document.getElementById('simbox_ctl_'+simid+'_'+i).value;
 +
    if(!is_posint(tmpval))
 +
    {
 +
    alert('Cannot set negative quantity to molecule "'+simulations[simid].molecules[i].name+'".');
 +
    return false;
 +
    }
 +
    simulations[simid].molecules[i].quantity= parseInt(tmpval);
 +
  }
 +
  }
   simulations[simid].running= true;
   simulations[simid].running= true;
   btn.innerHTML= 'PAUSE';
   btn.innerHTML= 'PAUSE';
 +
  simbox_update_controls(simid);
  }
  }
 +
return true;
}
}
Line 146: Line 170:
   simulations[simid].molecules[i].quantity= simulations[simid].molecules[i].init_qtty;
   simulations[simid].molecules[i].quantity= simulations[simid].molecules[i].init_qtty;
   simulations[simid].molecules[i].history.length= 0;
   simulations[simid].molecules[i].history.length= 0;
 +
}
 +
 +
//Update controls
 +
simbox_update_controls(simid);
 +
}
 +
 +
function simbox_update_controls(simid)
 +
{
 +
for(var i= 0 ; i < simulations[simid].molecules.length ; ++i)
 +
{
 +
  if(simulations[simid].molecules[i].curve_show)
 +
  {
 +
  document.getElementById('simbox_ctl_'+simid+'_'+i).value= simulations[simid].molecules[i].quantity;
 +
  document.getElementById('simbox_ctl_'+simid+'_'+i).disabled= simulations[simid].running;
 +
  }
  }
  }
}
}

Revision as of 21:57, 2 August 2013