Browse Source

Return photo ID when upload successful #487

Tobias Reich 8 years ago
parent
commit
d212363ebf
4 changed files with 6 additions and 4 deletions
  1. 0 0
      dist/main.js
  2. 1 1
      php/Access/Admin.php
  3. 2 2
      php/Modules/Photo.php
  4. 3 1
      src/scripts/upload.js

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


+ 1 - 1
php/Access/Admin.php

@@ -231,7 +231,7 @@ final class Admin extends Access {
 		Validator::required(isset($_FILES, $_POST['albumID']), __METHOD__);
 
 		$photo = new Photo(null);
-		Response::json($photo->add($_FILES, $_POST['albumID']));
+		Response::json($photo->add($_FILES, $_POST['albumID']), JSON_NUMERIC_CHECK);
 
 	}
 

+ 2 - 2
php/Modules/Photo.php

@@ -39,7 +39,7 @@ final class Photo {
 	 * Creats new photo(s).
 	 * Exits on error.
 	 * Use $returnOnError if you want to handle errors by your own.
-	 * @return boolean Returns true when successful.
+	 * @return string|false ID of the added photo.
 	 */
 	public function add(array $files, $albumID = 0, $returnOnError = false) {
 
@@ -251,7 +251,7 @@ final class Photo {
 		// Call plugins
 		Plugins::get()->activate(__METHOD__, 1, func_get_args());
 
-		return true;
+		return $id;
 
 	}
 

+ 3 - 1
src/scripts/upload.js

@@ -96,10 +96,12 @@ upload.start = {
 				let wait      = false
 				let errorText = ''
 
+				const isNumber = (n) => (!isNaN(parseFloat(n)) && isFinite(n))
+
 				file.ready = true
 
 				// Set status
-				if (xhr.status===200 && xhr.responseText==='true') {
+				if (xhr.status===200 && isNumber(xhr.responseText)) {
 
 					// Success
 					$('.basicModal .rows .row:nth-child(' + (file.num + 1) + ') .status')

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