Skip to content

Commit

Permalink
Merge pull request #22 from unicef-polymer/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
acory authored Nov 14, 2018
2 parents 4024efb + b18fdf8 commit d0a8dfb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "etools-upload",
"description": "Use to upload files",
"version": "1.0.0",
"version": "1.0.1",
"main": "etools-upload.html",
"dependencies": {
"polymer": "Polymer/polymer#^2.0.0",
Expand Down
24 changes: 6 additions & 18 deletions etools-upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -297,29 +297,17 @@
this.serverErrorMsg = null;
}


_fileUrlChanged(fileUrl) {
if (!this.isValidURL(fileUrl)) {
if (fileUrl && !isNaN(fileUrl)) {
// fileUrl is a number after the upload is finished
// and becomes an url after the number is saved on the object=intervention, agreement etc
return;
}
this.resetStatus();
this._filename = this.getFilenameFromURL(fileUrl);
}

/**
* Absolute url str needed to work
* @param str
* @returns {boolean}
*/
isValidURL(str) {
const pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))?'+ // ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ //port + path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i');// hash
return pattern.test(str);
}

getFilenameFromURL(url) {
if (!url) {
return '';
Expand All @@ -328,7 +316,7 @@
}

_showDownloadBtn(fileUrl) {
return !!fileUrl && this.isValidURL(fileUrl);
return !!fileUrl && isNaN(fileUrl);
}

_showChange(readonly, _filename, uploadInProgress) {
Expand Down Expand Up @@ -370,7 +358,7 @@
}

_downloadFile(e) {
if (!this.fileUrl || !this.isValidURL(this.fileUrl)) {
if (!this.fileUrl || !isNaN(this.fileUrl)) {
return;
}
this.downloadFile(this._filename, this.fileUrl, this.openInNewTab);
Expand Down

0 comments on commit d0a8dfb

Please sign in to comment.