From 7a868b085ac7ed0be5893b69c86cee0c876d1c73 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilbu@DESKTOP-SBHQII6.(none)>
Date: Tue, 9 Aug 2016 19:41:27 -0700
Subject: [PATCH] Add icons to buttons and minimal error handling

---
 js/photonic3d.js | 48 ++++++++++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/js/photonic3d.js b/js/photonic3d.js
index 823846a..c2ba993 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -18,6 +18,17 @@ function setPrinterCalibrationSettings(printer) {
 	var buildVolYmm = Math.round(monitorDriverConfig.DLP_Y_Res / dotsPermmXYAverage);
 	var diagonalMM = Math.round(findPythagoreanC(buildVolXmm, buildVolYmm));
 
+	// Update global javascript object with slicer settings
+	$slicerSpeedYes[0].checked = true;
+	$slicerSpeedNo[0].checked = false;
+	$slicerSpeedDelay.val(0);
+	// // Convert mm to microns
+	// $slicerLayerHeight.val(/*slicingProfile.InkConfig.SliceHeight * 1000*/100);
+	// console.log($slicerLayerHeight.val());
+    settings.set('slicer.speed', $slicerSpeedYes[0].checked);
+    settings.set('slicer.speedDelay', $slicerSpeedDelay.val());
+    // settings.set('slicer.layers.height', $slicerLayerHeight.val());
+	
     /* This is part of updateBuildVolumeSettings() from main.js. I only copied
     the necessary code that won't result in geometry error */
     $buildVolumeX.val(buildVolXmm);
@@ -31,6 +42,8 @@ function setPrinterCalibrationSettings(printer) {
 	
 	// After manually checking the mm unit, set the values then update UI
 	$screenDiagonalSize.val(diagonalMM);
+	$screenWidth.val(monitorDriverConfig.DLP_X_Res);
+	$screenHeight.val(monitorDriverConfig.DLP_Y_Res);
 	updateScreenSettings();
 
 	// No error occurred so return false
@@ -39,17 +52,10 @@ function setPrinterCalibrationSettings(printer) {
 
 // Initialize values
 function initializeValues() {
-	$slicerSpeedYes[0].checked = true;
-	$slicerSpeedNo[0].checked = false;
-	$slicerSpeedDelay.val(0);
 	makeButton();
 
-	// Update global javascript object with slicer settings
-    settings.set('slicer.speed', $slicerSpeedYes[0].checked);
-    settings.set('slicer.speedDelay', $slicerSpeedDelay.val());
-	
-	settings.set('#slicer.panel.collapsed', true);
-	$slicerBody.collapse('hide');
+	// settings.set('#slicer.panel.collapsed', true);
+	// $slicerBody.collapse('hide');
 
 	var XYerr = false;
 	var printer = $.get( "/services/printers/getFirstAvailablePrinter", function( data ) {
@@ -60,21 +66,20 @@ function initializeValues() {
 
 	if (XYerr) {
 		// Error handling
+		alert("Your DotsPermmX and DotsPermmY are more than 0.1 mm apart");
 	}
 
-	
-
-	// loader.load(/*insert file here*/);
 }
 
 function makeZip() {
-	if (zipFile) {
+	if (zipFile === null || zipFile === undefined) {
+		alert("You must first slice images to generate a zip file.");
+	} else {
         var name = 'SLAcer';
         if (loadedFile && loadedFile.name) {
             name = loadedFile.name;
         }
-        uploadZip(zipFile.generate({type: 'blob'}), name + '.zip');
-        //window.location = "/printablesPage";
+        uploadZip(zipFile.generate({type: 'blob'}), name + '.zip' + '.zip');
     }
 }
 
@@ -84,13 +89,19 @@ function uploadZip(zipFile, fileName) {
 	form.append("file",blob,fileName);
 	request = new XMLHttpRequest();
 	request.open("POST", "/services/printables/uploadPrintableFile");
-	request.send(form);
+	// When the request is successfully sent, load the tab to printablesPage
+	request.onreadystatechange = function () {
+		if (request.readyState == 4 && request.status == 200) {
+			window.open('/printablesPage', '_self');
+		}
+	}
+    request.send(form);
 }
 
 function makeButton() {
 	//rename original zip button
 	var btn	= document.getElementById("zip-button");
-	btn.innerHTML = "Download Zip";	
+	btn.innerHTML = '<span class="glyphicon glyphicon-compressed"></span> Download ZIP'	
 	//create new zip button
 	var newbtn = document.createElement("BUTTON");
 	newbtn.onclick = function () {
@@ -98,7 +109,8 @@ function makeButton() {
 	}
 	newbtn.id = "new-zip-button";
 	newbtn.className = "btn btn-primary";
-	newbtn.innerHTML = "Upload ZIP To Printables";
+	// $('#new-zip-button').prop('disabled', 'disabled');
+	newbtn.innerHTML = '<span class="glyphicon glyphicon-upload"></span> Upload ZIP To Printables'
 	btn.parentNode.insertBefore(newbtn, btn);
 }
 
