Browse Source

Improved error handling

Tobias Reich 10 years ago
parent
commit
e9f1c21406
6 changed files with 43 additions and 29 deletions
  1. 12 1
      assets/css/upload.css
  2. 6 13
      assets/js/build.js
  3. 25 15
      assets/js/upload.js
  4. 0 0
      assets/min/main.css
  5. 0 0
      assets/min/main.js
  6. 0 0
      assets/min/view.js

+ 12 - 1
assets/css/upload.css

@@ -118,4 +118,15 @@
 
 			.upload_message .rows .row a.status.success {
 				color: rgb(42, 213, 0);
-			}
+			}
+
+		.upload_message .rows .row p.notice {
+			display: none;
+			float: left;
+			padding: 2px 10px 5px;
+			width: calc(100% - 20px);
+			color: rgba(255,255,255,.5);
+			font-size: 12px;
+			overflow: hidden;
+			line-height: 16px;
+		}

+ 6 - 13
assets/js/build.js

@@ -220,21 +220,14 @@ build = {
 
 			if (files[i].name.length>40) files[i].name = files[i].name.substr(0, 17) + "..." + files[i].name.substr(files[i].name.length-20, 20);
 
-			if (files[i].supported===true) {
+			modal += "<div class='row'>";
+			modal +=	"<a class='name'>" + lychee.escapeHTML(files[i].name) + "</a>";
 
-				modal += "<div class='row'>"
-				modal +=	"<a class='name'>" + lychee.escapeHTML(files[i].name) + "</a>"
-				modal +=	"<a class='status'></a>"
-				modal += "</div>";
+			if (files[i].supported===true)	modal += "<a class='status'></a>";
+			else							modal += "<a class='status error'>Not supported</a>";
 
-			} else {
-
-				modal += "<div class='row'>"
-				modal +=	"<a class='name'>" + lychee.escapeHTML(files[i].name) + "</a>"
-				modal +=	"<a class='status error'>Not supported</a>"
-				modal += "</div>";
-
-			}
+			modal +=	"<p class='notice'></p>";
+			modal += "</div>";
 
 		}
 

+ 25 - 15
assets/js/upload.js

@@ -69,6 +69,7 @@ upload = {
 							$("#upload_files").val("");
 
 							upload.close();
+							upload.notify("Upload complete");
 
 							if (album.getID()===false) lychee.goto("0");
 							else album.load(albumID);
@@ -112,34 +113,43 @@ upload = {
 
 					xhr.onload = function() {
 
-						// On success
-						if (xhr.status===200) {
+						var wait = false;
 
-							var wait;
+						file.ready = true;
 
-							// Set status to finished
+						// Set status
+						if (xhr.status===200&&xhr.responseText==="1") {
+
+							// Success
 							$(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status")
 								.html("Finished")
 								.addClass("success");
 
-							file.ready = true;
-							wait = false;
+						} else {
 
-							// Check if there are file which are not finished
-							for (var i = 0; i < files.length; i++) {
+							// Error
+							$(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status")
+								.html("Error")
+								.addClass("error");
+							$(".upload_message .rows .row:nth-child(" + (file.num+1) + ") p.notice")
+								.html("Server returned the status code " + xhr.status)
+								.show();
 
-								if (files[i].ready===false) {
-									wait = true;
-									break;
-								}
+						}
 
-							}
+						// Check if there are file which are not finished
+						for (var i = 0; i < files.length; i++) {
 
-							// Finish upload when all files are finished
-							if (wait===false) finish();
+							if (files[i].ready===false) {
+								wait = true;
+								break;
+							}
 
 						}
 
+						// Finish upload when all files are finished
+						if (wait===false) finish();
+
 					};
 
 					xhr.upload.onprogress = function(e) {

File diff suppressed because it is too large
+ 0 - 0
assets/min/main.css


File diff suppressed because it is too large
+ 0 - 0
assets/min/main.js


File diff suppressed because it is too large
+ 0 - 0
assets/min/view.js


Some files were not shown because too many files changed in this diff