summaryrefslogtreecommitdiffstats
path: root/afb-client/app/Frontend/widgets/FormInput
diff options
context:
space:
mode:
Diffstat (limited to 'afb-client/app/Frontend/widgets/FormInput')
-rw-r--r--afb-client/app/Frontend/widgets/FormInput/UploadFiles.js42
-rw-r--r--afb-client/app/Frontend/widgets/FormInput/newjavascript.js55
2 files changed, 19 insertions, 78 deletions
diff --git a/afb-client/app/Frontend/widgets/FormInput/UploadFiles.js b/afb-client/app/Frontend/widgets/FormInput/UploadFiles.js
index 65269f3..88669a9 100644
--- a/afb-client/app/Frontend/widgets/FormInput/UploadFiles.js
+++ b/afb-client/app/Frontend/widgets/FormInput/UploadFiles.js
@@ -22,12 +22,11 @@
* https://stuk.github.io/jszip/documentation/howto/read_zip.html
* http://onehungrymind.com/zip-parsing-jszip-angular/
* http://stackoverflow.com/questions/15341912/how-to-go-from-blob-to-arraybuffer
+ *
+ * Bugs: zip file sent even when flag as invalid
*/
-
-function changeInput() {
- console.log ('input imgClicked');
-}
+
(function() {
'use strict';
@@ -40,10 +39,6 @@ var tmpl = '<input type="file" name="{{name}}-input" onchange="angular.element(
'</div>';
-function Basename(path) {
- return path.split('/').reverse()[0];
-}
-
// Service Create xform insert files in and Post it to url
function LoadFileSvc (scope, elem, posturl, files, thumbnailCB) {
var xmlReq = new XMLHttpRequest();
@@ -105,16 +100,18 @@ function LoadFileSvc (scope, elem, posturl, files, thumbnailCB) {
return;
}
- scope.Basename=Basename(file.name);
+ scope.Basename= file.name.split('/').reverse()[0];
scope.imgElem[0].file = file;
// If File is an image let display it now
if (thumbnailCB) {
var reader = new FileReader();
reader.readAsArrayBuffer(file);
- reader.onload = thumbnailCB;
- }
-
+ reader.onload = function (target) {
+ var status = thumbnailCB (target);
+ //if (status) xform.append(scope.name, file, file.name);
+ };
+ }
// if everything is OK let's add file to xform
xform.append(scope.name, file, file.name);
}
@@ -123,7 +120,7 @@ function LoadFileSvc (scope, elem, posturl, files, thumbnailCB) {
// everything looks OK let's Post it
xmlReq.open("POST", posturl , true);
xmlReq.send(xform);
-};
+}
angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider'])
@@ -148,11 +145,11 @@ angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider'])
scope.UpLoadFile=function (files) {
var readerCB = function (upload) {
// scope.thumbnail = upload.target.result;
- scope.imgElem[0].src = window.URL.createObjectURL(new Blob([upload.target.result], {type: "image"}));
- scope.$apply('thumbnail'); // we short-circuit Angular resync image
+ scope.imgElem[0].src = window.URL.createObjectURL(new Blob([upload.target.result], {type: "image"}));
+ return true; // true activates post
};
var posturl = attrs.posturl + "?token=" + ConfigApp.session.token;
- LoadFileSvc (scope, elem, posturl, files, readerCB);
+ new LoadFileSvc (scope, elem, posturl, files, readerCB);
};
// Initiallize default values from attributes values
@@ -204,7 +201,7 @@ angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider'])
// Upload is delegated to a shared function
scope.UpLoadFile=function (files) {
var posturl = attrs.posturl + "?token=" + ConfigApp.session.token;
- LoadFileSvc (scope, elem, posturl, files, false);
+ new LoadFileSvc (scope, elem, posturl, files, false);
};
// Initiallize default values from attributes values
@@ -265,15 +262,14 @@ angular.module('UploadFiles',['ConfigApp', 'ModalNotification', 'RangeSlider'])
if (!thumbnail) {
console.log ("This is not a valid Application Framework APP");
scope.thumbnail=ConfigApp.paths[scope.category] + 'isnotvalid.png';
- scope.$apply('thumbnail'); // we short-circuit Angular resync image
- return;
+ scope.$apply('thumbnail'); // we short-circuit Angular resync Image
+ return false; // do not post zip on binder
}
- scope.imgElem[0].src = window.URL.createObjectURL(new Blob([thumbnail.asArrayBuffer()], {type: "image"}));
- scope.$apply('thumbnail'); // we short-circuit Angular resync image
+ scope.imgElem[0].src = window.URL.createObjectURL(new Blob([thumbnail.asArrayBuffer()], {type: "image"}));
+ return true; // true activates post
};
-
var posturl = attrs.posturl + "?token=" + ConfigApp.session.token;
- LoadFileSvc (scope, elem, posturl, files, readerCB);
+ new LoadFileSvc (scope, elem, posturl, files, readerCB);
};
// Initiallize default values from attributes values
diff --git a/afb-client/app/Frontend/widgets/FormInput/newjavascript.js b/afb-client/app/Frontend/widgets/FormInput/newjavascript.js
deleted file mode 100644
index 10280c7..0000000
--- a/afb-client/app/Frontend/widgets/FormInput/newjavascript.js
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2015 fulup
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
- var reader = new FileReader();
- // Closure to capture the file information.
- reader.onload = (function(theFile) {
- return function(e) {
- var $title = $("<h4>", {
- text : theFile.name
- });
- $result.append($title);
- var $fileContent = $("<ul>");
- try {
-
- var dateBefore = new Date();
- // read the content of the file with JSZip
- var zip = new JSZip(e.target.result);
- var dateAfter = new Date();
-
- $title.append($("<span>", {
- text:" (parsed in " + (dateAfter - dateBefore) + "ms)"
- }));
-
- // that, or a good ol' for(var entryName in zip.files)
- $.each(zip.files, function (index, zipEntry) {
- $fileContent.append($("<li>", {
- text : zipEntry.name
- }));
- // the content is here : zipEntry.asText()
- });
- // end of the magic !
-
- } catch(e) {
- $fileContent = $("<div>", {
- "class" : "alert alert-danger",
- text : "Error reading " + theFile.name + " : " + e.message
- });
- }
- $result.append($fileContent);
- }
- })(f); \ No newline at end of file