Commit eed8ea61 authored by carlosperate's avatar carlosperate

Fixes on the Arduino plain and material webapps.

Plain app form data is now properly bind to clicks.
Arduino material minor clean up of settings html.
parent 668c7b56
......@@ -15,6 +15,7 @@ var ArduinoSettings = {};
* Initialize the settings form data on page load.
*/
window.addEventListener('load', function() {
// Populate the form data
ArduServerCompiler.requestCompilerLocation(
ArduinoSettings.setCompilerLocationHtml);
ArduServerCompiler.requestSketchLocation(
......@@ -23,6 +24,16 @@ window.addEventListener('load', function() {
ArduinoSettings.setArduinoBoardsHtml);
ArduServerCompiler.requestSerialPorts(ArduinoSettings.setSerialPortsHtml);
ArduServerCompiler.requestIdeOptions(ArduinoSettings.setIdeHtml);
// Binding clicks to the form items
ArduinoSettings.bindClick_('settings_compiler_location', function() {
ArduServerCompiler.requestNewCompilerLocation(
ArduinoSettings.setCompilerLocationHtml);
});
ArduinoSettings.bindClick_('settings_sketch_location', function() {
ArduServerCompiler.requestNewSketchLocation(
ArduinoSettings.setSketchLocationHtml);
});
});
/**
......@@ -62,9 +73,6 @@ ArduinoSettings.setArduinoBoardsHtml = function(new_el) {
new_el.onchange = ArduinoSettings.setBoard;
board_dropdown.parentNode.replaceChild(new_el, board_dropdown);
}
// Refresh the materialize select menus
// TODO: Currently a reported bug from Materialize
$('select').material_select();
};
/**
......@@ -91,9 +99,6 @@ ArduinoSettings.setSerialPortsHtml = function(new_el) {
new_el.onchange = ArduinoSettings.setSerial;
serial_dropdown.parentNode.replaceChild(new_el, serial_dropdown);
}
// Refresh the materialize select menus
// TODO: Currently a reported bug from Materialize
$('select').material_select();
};
/**
......@@ -120,9 +125,6 @@ ArduinoSettings.setIdeHtml = function(new_el) {
new_el.onchange = ArduinoSettings.setIdeSettings;
ide_dropdown.parentNode.replaceChild(new_el, ide_dropdown);
}
// Refresh the materialize select menus
// TODO: Currently a reported bug from Materialize
$('select').material_select();
};
/**
......@@ -134,3 +136,24 @@ ArduinoSettings.setIdeSettings = function() {
//TODO: check how ArduServerCompiler deals with invalid data and sanitise
ArduServerCompiler.setIdeOptions(ide_value, ArduinoSettings.setIdeHtml);
};
/**
* Bind a function to a button's click event.
* On touch enabled browsers, ontouchend is treated as equivalent to onclick.
* @param {!Element|string} el Button element or ID thereof.
* @param {!function} func Event handler to bind.
* @private
*/
ArduinoSettings.bindClick_ = function(el, func) {
if (typeof el == 'string') {
el = document.getElementById(el);
}
// Need to ensure both, touch and click, events don't fire for the same thing
var propagateOnce = function(e) {
e.stopPropagation();
e.preventDefault();
func();
};
el.addEventListener('ontouchend', propagateOnce);
el.addEventListener('click', propagateOnce);
};
......@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="google" value="notranslate">
<title>Ardublockly: Arduino Code</title>
<title>Ardublockly: Arduino Code Settings</title>
<link rel="stylesheet" href="style_settings.css">
<!-- Arduino Server Compiler -->
<script src="../../ArduinoServerCompiler/js/ArduServerCompiler.js"></script>
......@@ -36,7 +36,7 @@
</div>
<div class="settings_div">
<label>IDE:</label> <br>
<select name="settings_ide" id="ide_settings" onchange="ArduinoMaterial.setIdeSettings(this.value)">
<select name="settings_ide" id="ide_settings">
<option value="ide_upload">Compile</option>
<option value="ide_only">Load</option>
</select>
......
......@@ -167,7 +167,8 @@ ArduinoMaterial.populateSettings = function() {
ArduinoMaterial.setCompilerLocationHtml);
ArduServerCompiler.requestSketchLocation(
ArduinoMaterial.setSketchLocationHtml);
ArduServerCompiler.requestArduinoBoards(ArduinoMaterial.setArduinoBoardsHtml);
ArduServerCompiler.requestArduinoBoards(
ArduinoMaterial.setArduinoBoardsHtml);
ArduServerCompiler.requestSerialPorts(ArduinoMaterial.setSerialPortsHtml);
ArduServerCompiler.requestIdeOptions(ArduinoMaterial.setIdeHtml);
};
......@@ -220,7 +221,7 @@ ArduinoMaterial.setArduinoBoardsHtml = function(new_el) {
ArduinoMaterial.setBoard = function() {
var el = document.getElementById("board");
var board_value = el.options[el.selectedIndex].value;
//TODO: check how ArduServerCompiler deals with invalid data and sanitise here
//TODO: check how ArduServerCompiler deals with invalid data and sanitise
ArduServerCompiler.setArduinoBoard(
board_value, ArduinoMaterial.setArduinoBoardsHtml);
};
......@@ -249,7 +250,7 @@ ArduinoMaterial.setSerialPortsHtml = function(new_el) {
ArduinoMaterial.setSerial = function() {
var el = document.getElementById("serial_port");
var serial_value = el.options[el.selectedIndex].value;
//TODO: check how ArduServerCompiler deals with invalid data and sanitise here
//TODO: check how ArduServerCompiler deals with invalid data and sanitise
ArduServerCompiler.setSerialPort(
serial_value, ArduinoMaterial.setSerialPortsHtml);
};
......@@ -295,7 +296,9 @@ ArduinoMaterial.sendCode = function() {
};
/**
* Send the Arduino Code to the ArduServerCompiler to process
* Receives the IDE data back to be displayed and stops spinner.
* @param {!element} new_el New HTML element to replace the one in the current
* DOM. Should contain a complete select element.
*/
ArduinoMaterial.sendCodeReturn = function(data_back) {
ArduinoMaterial.runButtonSpinner(false);
......
......@@ -18,7 +18,8 @@ var ArduinoMaterial = ArduinoMaterial || {};
ArduinoMaterial.BLOCKLY_INJECTED = false;
/**
* Injects Blockly into a given text area. Reads the toolbox from an XMl file.
* Injects Blockly into a given HTML element. Reads the toolbox from an XMl
* file.
* @param {!Element} el Element to inject Blockly into.
* @param {!string} toolbox_path String containing the toolbox XML file path.
*/
......
......@@ -198,16 +198,14 @@
<div class="settings_div">
<label>COM Port:</label>
<select name="settings_serial" id="serial_port">
<option value="COM4">COM 4</option>
<option value="COM5">COM 5</option>
<option value="COM6">COM 6</option>
<option value="COM4">COM unknown</option>
</select>
</div>
<div class="settings_div">
<label>IDE:</label> <br>
<select name="settings_ide " id="ide_settings" onchange="ArduinoMaterial.setIdeSettings(this.value)">
<option value="ide_upload">Compile and Upload sketchaaa</option>
<option value="ide_only">Load sketch in IDE onlyaaa</option>
<select name="settings_ide" id="ide_settings">
<option value="ide_upload">Compile</option>
<option value="ide_only">Load</option>
</select>
</div>
</div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment