';
$("#table_gcodes").append(item);
e.preventDefault();
});
$("#btn_add_head_temp").click(function(e) {
var temperature = checkBoundaries($("#input_add_head_temp").val(), 0, -273.15, 300);
var type = $('input[name="temp_selection"]:checked').val();
var item = '
' + temperature + ' °C';
item += '
';
$("#ul_" + type + "_temps").append(item);
e.preventDefault();
});
$("#btn_add_bed_temp").click(function(e) {
var temperature = checkBoundaries($("#input_add_bed_temp").val(), 0, -273.15, 180);
var item = '
' + temperature + ' °C';
item += '
';
$("#ul_bed_temps").append(item);
e.preventDefault();
});
$("#btn_add_tool").click(function(e) {
var gcode = "M563 P" + $("#input_tool_number").val();
var drives = $("input[name='tool_drives']:checked");
if (drives != undefined) {
var driveList = [];
drives.each(function() { driveList.push($(this).val()); });
gcode += " D" + driveList.reduce(function(a, b) { return a + ":" + b; });
}
var heaters = $("input[name='tool_heaters']:checked");
if (heaters != undefined) {
var heaterList = [];
heaters.each(function() { heaterList.push($(this).val()); });
gcode += " H" + heaterList.reduce(function(a, b) { return a + ":" + b; });
}
sendGCode(gcode);
extendedStatusCounter = settings.extendedStatusInterval;
e.preventDefault();
});
$("#btn_cancel").click(function() {
sendGCode("M0"); // Stop / Cancel Print
$(this).addClass("disabled");
});
$("#btn_cancel_upload").click(function() {
cancelUpload();
});
$(".btn-connect").click(function() {
if (!isConnected) {
// Attempt to connect with the last-known password first
connect(sessionPassword, true);
} else {
disconnect();
}
});
$(".btn-emergency-stop").click(function() {
if (settings.confirmStop) {
showConfirmationDialog(T("Emergency STOP"), T("This will turn off everything and perform a software reset.
Are you REALLY sure you want to do this?"), function() {
sendGCode("M112\nM999");
});
} else {
sendGCode("M112\nM999");
}
});
$("#btn_clear_log").click(function(e) {
$("#console_log").html("");
log("info", "" + T("Message Log cleared!") + "");
e.preventDefault();
});
// TODO: deal with mixing drives
$("#btn_extrude").click(function(e) {
var feedrate = $("#panel_extrude input[name=feedrate]:checked").val() * 60;
var amount = $("#panel_extrude input[name=feed]:checked").val();
sendGCode("M120\nM83\nG1 E" + amount + " F" + feedrate + "\nM121");
});
$("#btn_retract").click(function(e) {
var feedrate = $("#panel_extrude input[name=feedrate]:checked").val() * 60;
var amount = $("#panel_extrude input[name=feed]:checked").val();
sendGCode("M120\nM83\nG1 E-" + amount + " F" + feedrate + "\nM121");
});
$(".btn-hide-info").click(function() {
if ($(this).hasClass("active")) {
$("#row_info").addClass("hidden-xs hidden-sm");
setTimeout(function() {
$(".btn-hide-info").removeClass("active");
}, 100);
} else {
$("#row_info").removeClass("hidden-xs hidden-sm");
setTimeout(function() {
$(".btn-hide-info").addClass("active");
}, 100);
}
$(this).blur();
});
$(".btn-home-x").resize(function() {
if (!$(this).hasClass("hidden")) {
var width = $(this).parent().width();
if (width > 0) {
$("#btn_homeall").css("width", width);
}
}
}).resize();
$("#mobile_home_buttons button, #btn_homeall, #table_move_head a").click(function(e) {
$this = $(this);
if ($this.data("home") != undefined) {
if ($this.data("home") == "all") {
sendGCode("G28");
} else {
sendGCode("G28 " + $this.data("home"));
}
} else {
var moveString = "M120\nG91\nG1";
if ($this.data("x") != undefined) {
moveString += " X" + $this.data("x");
}
if ($this.data("y") != undefined) {
moveString += " Y" + $this.data("y");
}
if ($this.data("z") != undefined) {
moveString += " Z" + $this.data("z");
}
moveString += " F" + settings.moveFeedrate + "\nM121";
sendGCode(moveString);
}
e.preventDefault();
});
$("#btn_load_filament").click(function() {
// Load first 85% of filament at high speed
sendGCode("G1 E" + (settings.bowdenLength * 0.85) + " F6000");
// Then feed last 15% at lower speed
sendGCode("G1 E" + (settings.bowdenLength * 0.15) + " F450");
});
$("#btn_unload_filament").click(function() {
// Start slowly for the first 15% at low speed
sendGCode("G1 E-" + (settings.bowdenLength * 0.15) + " F450");
// Eject last 85% of filament at higher speed
sendGCode("G1 E-" + (settings.bowdenLength * 0.85) + " F6000");
});
$("#btn_new_gcode_directory").click(function() {
showTextInput(T("New directory"), T("Please enter a name:"), function(value) {
$.ajax("rr_mkdir?dir=" + currentGCodeDirectory + "/" + value, {
dataType: "json",
success: function(response) {
if (response.err == 0) {
gcodeUpdateIndex = -1;
updateGCodeFiles();
} else {
showMessage("warning-sign", T("Error"), T("Could not create this directory!"), "sm");
}
}
});
});
});
$("#btn_new_macro_directory").click(function() {
showTextInput(T("New directory"), T("Please enter a name:"), function(value) {
$.ajax("rr_mkdir?dir=" + currentMacroDirectory + "/" + value, {
dataType: "json",
success: function(response) {
if (response.err == 0) {
macroUpdateIndex = -1;
updateMacroFiles();
} else {
showMessage("warning-sign", T("Error"), T("Could not create this directory!"), "sm");
}
}
});
});
});
$("#btn_pause").click(function() {
if (isPaused) {
sendGCode("M24"); // Resume
} else if (isPrinting) {
sendGCode("M25"); // Pause
}
$(this).addClass("disabled");
});
$(".btn-upload").click(function(e) {
$("#input_file_upload").data("type", $(this).data("type")).click();
e.preventDefault();
});
$("#btn_reset_settings").click(function(e) {
showConfirmationDialog(T("Reset Settings"), T("Are you sure you want to revert to Factory Settings?"), function() {
if (defaultSettings.language != settings.language) {
showMessage("info-sign", T("Language has changed"), T("You have changed the current language.
Please reload the web interface to apply this change."), "md");
}
settings = jQuery.extend(true, {}, defaultSettings);
$("#btn_language").data("language", "en").children("span:first-child").text("English");
applySettings();
saveSettings();
});
e.preventDefault();
});
["print", "gcode", "macro", "generic"].forEach(function(type) {
var child = $(".btn-upload[data-type='" + type + "']");
// Drag Enter
child.on("dragover", function(e) {
$(this).removeClass($(this).data("style")).addClass("btn-success");
e.preventDefault();
e.stopPropagation();
});
// Drag Leave
child.on("dragleave", function(e) {
$(this).removeClass("btn-success").addClass($(this).data("style"));
e.preventDefault();
e.stopPropagation();
});
// Drop
child.on("drop", function(e) {
$(this).removeClass("btn-success").addClass($(this).data("style"));
e.preventDefault();
e.stopPropagation();
var files = e.originalEvent.dataTransfer.files;
if (files != null && files.length > 0) {
// Start new file upload
startUpload($(this).data("type"), files);
}
});
});
$(".gcode-input").submit(function(e) {
if (isConnected) {
var gcode = $(this).find("input").val();
if (settings.uppercaseGCode) {
gcode = gcode.toUpperCase();
}
sendGCode(gcode, true);
$(this).find("input").select();
}
e.preventDefault();
});
// Make the auto-complete dropdown items look proper.
// This should be replaced by proper CSS someday, but
// for now we only check which elements may float around.
$(".div-gcodes").bind("shown.bs.dropdown", function() {
var maxWidth = 0;
$(this).find("ul > li > a").each(function() {
var rowWidth = 0;
$(this).find("span").each(function() {
rowWidth += $(this).width();
});
if (rowWidth > maxWidth) {
maxWidth = rowWidth;
}
});
if (maxWidth > 0) {
$(this).find("ul > li > a").each(function() {
var rowWidth = 0;
$(this).find("span").each(function() {
rowWidth += $(this).width();
});
if (rowWidth < maxWidth) {
$(this).addClass("gcode-float");
}
});
}
});
$("#frm_settings").submit(function(e) {
saveSettings();
applySettings();
e.preventDefault();
});
$("input[type='number']").focus(function() {
var input = $(this);
setTimeout(function() {
input.select();
}, 10);
});
$("input[name='temp_selection']:radio").change(function() {
if ($(this).val() == "active") {
$("#ul_active_temps").removeClass("hidden");
$("#ul_standby_temps").addClass("hidden");
} else {
$("#ul_standby_temps").removeClass("hidden");
$("#ul_active_temps").addClass("hidden");
}
});
$("#input_bowden_length").blur(function() {
// NOTE: This is a temporary solution
settings.bowdenLength = checkBoundaries($(this).val(), 300, 0);
$.cookie("settings", JSON.stringify(settings), { expires: 999999 });
});
$("#input_file_upload").change(function(e) {
if (this.files.length > 0) {
// For POST uploads, we need file blobs
startUpload($(this).data("type"), this.files);
}
});
$("#input_temp_bed").keydown(function(e) {
var enterKeyPressed = (e.which == 13);
enterKeyPressed |= (e.which == 9 && window.matchMedia('(max-width: 991px)').matches); // need this for Android
if (isConnected && enterKeyPressed) {
sendGCode("M140 S" + $(this).val());
$(this).select();
e.preventDefault();
}
});
$("#input_temp_chamber").keydown(function(e) {
var enterKeyPressed = (e.which == 13);
enterKeyPressed |= (e.which == 9 && window.matchMedia('(max-width: 991px)').matches); // need this for Android
if (isConnected && enterKeyPressed) {
sendGCode("M141 S" + $(this).val());
$(this).select();
e.preventDefault();
}
});
$("input[id^='input_temp_h']").keydown(function(e) {
var enterKeyPressed = (e.which == 13);
enterKeyPressed |= (e.which == 9 && window.matchMedia('(max-width: 991px)').matches); // need this for Android
if (isConnected && enterKeyPressed) {
var activeOrStandby = ($(this).prop("id").match("active$")) ? "S" : "R";
var heater = $(this).prop("id").match("_h(.)_")[1];
var temperature = $(this).val();
getToolsByHeater(heater).forEach(function(toolNumber) {
sendGCode("G10 P" + toolNumber + " " + activeOrStandby + temperature);
});
$(this).select();
e.preventDefault();
}
});
$("#input_temp_all_active, #input_temp_all_standby").keydown(function(e) {
if (isConnected && e.which == 13) {
if (toolMapping != undefined) {
var activeOrStandby = ($(this).prop("id").match("active$")) ? "S" : "R";
var temperature = $(this).val();
for(var i=0; i This will turn off all drives, heaters and fans."), function() {
sendGCode("M81");
});
}
});
$("#panel_extrude label.btn").click(function() {
$(this).parent().find("label.btn").removeClass("btn-primary").addClass("btn-default");
$(this).removeClass("btn-default").addClass("btn-primary");
});
$(".span-refresh-files").click(function() {
gcodeUpdateIndex = -1;
updateGCodeFiles();
$(".span-refresh-files").addClass("hidden");
});
$(".span-refresh-macros").click(function() {
macroUpdateIndex = -1;
updateMacroFiles();
$(".span-refresh-macros").addClass("hidden");
});
$(".panel-chart").resize(function() {
resizeCharts();
});
$("#table_heaters a").click(function(e) {
if (isConnected && lastStatusResponse != undefined) {
if ($(this).parents("#tr_bed").length > 0) {
var bedState = lastStatusResponse.temps.bed.state;
if (bedState == 3) {
showMessage("exclamation-sign", T("Heater Fault"), T("Error: A heater fault has occured on this particular heater.
Please turn off your machine and check your wiring for loose connections."), "md");
} else if (bedState == 2) {
// Put bed into standby mode
sendGCode("M144");
} else {
// Bed is either off or in standby mode, send M140 to turn it back on
sendGCode("M140 S" + $("#input_temp_bed").val());
}
} else {
var heater = $(this).parents("tr").index();
var heaterState = lastStatusResponse.temps.heads.state[heater - 1];
if (heaterState == 3) {
showMessage("exclamation-sign", T("Heater Fault"), T("Error: A heater fault has occured on this particular heater.
Please turn off your machine and check your wiring for loose connections."), "md");
} else {
var tools = getToolsByHeater(heater), hasToolSelected = false;
tools.forEach(function(tool) {
if (tool == lastStatusResponse.currentTool) {
hasToolSelected = true;
}
});
if (hasToolSelected) {
sendGCode("T-1");
$(this).blur();
} else if (tools.length == 1) {
sendGCode("T" + tools[0]);
$(this).blur();
} else if (tools.length > 0) {
var popover = $(this).parent().children("div.popover");
if (popover.length) {
$(this).popover("hide");
$(this).blur();
} else {
var content = '
';
$("#table_gcodes").append(item);
}
function addGCodeFile(filename) {
$("#page_files h1").addClass("hidden");
var row = '
';
row += '
' + filename + '
';
row += '
' + T("loading") + '
';
row += '
loading
';
row += '
loading
';
row += '
loading
';
row += '
loading
';
$("#table_gcode_files").append(row).removeClass("hidden");
}
function addMacroFile(filename) {
// Control Page
if (currentMacroDirectory == "/macros") {
var label = stripMacroFilename(filename);
var macroButton = '