Created
April 12, 2020 08:02
-
-
Save chanakaDe/0b9b8710f9b3d05e470acbfc5f423b7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.addNewReview = function () { | |
var fd = new FormData() | |
for (var i in $scope.files) { | |
fd.append("review_img", $scope.files[i]) | |
} | |
fd.append("description", $scope.review.description); | |
fd.append("date", $scope.review.date); | |
fd.append("featured", new_featured); | |
fd.append("email", $scope.review.email); | |
fd.append("name", $scope.review.name); | |
fd.append("approved", "yes"); | |
var xhr = new XMLHttpRequest() | |
xhr.upload.addEventListener("progress", uploadProgress, false) | |
xhr.addEventListener("load", uploadComplete, false) | |
xhr.addEventListener("error", uploadFailed, false) | |
xhr.addEventListener("abort", uploadCanceled, false) | |
xhr.open("POST", host.review_manage + '/review') | |
$scope.progressVisibleMain = true | |
xhr.send(fd) | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState == XMLHttpRequest.DONE) { | |
$scope.saved_project_id = JSON.parse(xhr.responseText).data.insertId; | |
// $scope.saved_project_id = 17; | |
$scope.progressVisibleMain = false; | |
} | |
} | |
}; | |
// Image upload functions. | |
$scope.setFiles = function (element) { | |
$scope.showSelectedBoxImg = true; | |
$scope.$apply(function ($scope) { | |
// console.log('files:', element.files); | |
// Turn the FileList object into an Array | |
$scope.files = [] | |
for (var i = 0; i < element.files.length; i++) { | |
$scope.files.push(element.files[i]) | |
} | |
$scope.progressVisibleMain = false | |
var reader = new FileReader(); | |
reader.onload = function (e) { | |
$('#display_img') | |
.attr('src', e.target.result); | |
}; | |
reader.readAsDataURL($scope.files[0]); | |
}); | |
}; | |
function uploadProgress(evt) { | |
$scope.$apply(function () { | |
if (evt.lengthComputable) { | |
$scope.progress = Math.round(evt.loaded * 100 / evt.total) | |
// console.log("pro : ", $scope.progress); | |
} else { | |
$scope.progress = 'unable to compute' | |
} | |
}) | |
} | |
function uploadComplete(evt) { | |
// console.log(evt.target.responseText, "done"); | |
$scope.progressVisibleMain = false; | |
$.notify("NEW WINK ADDED SUCCESSFULLY", "success"); | |
$scope.showSelectedBoxImg = false; | |
$scope.review.description = ""; | |
$route.reload(); | |
} | |
function uploadFailed(evt) { | |
alert("There was an error attempting to upload the file.") | |
$.notify("ERROR UPLOADING", "error"); | |
} | |
function uploadCanceled(evt) { | |
$scope.$apply(function () { | |
$scope.progressVisibleMain = false | |
}) | |
alert("The upload has been canceled by the user or the browser dropped the connection.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment