guy 7 years ago
parent
commit
51d4006d6a
  1. 210
      bi/base.js
  2. 210
      dist/base.js
  3. 210
      dist/bundle.js
  4. 2
      dist/bundle.min.js
  5. 209
      src/base/single/input/file.js

210
bi/base.js

@ -18811,7 +18811,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true; e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
e.preventDefault ? e.preventDefault() : e.returnValue = false; e.preventDefault ? e.preventDefault() : e.returnValue = false;
} }
;
return false; return false;
} }
}; };
@ -18820,7 +18820,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
var multipart = function (boundary, name, file) { var multipart = function (boundary, name, file) {
return "--".concat( return "--".concat(
boundary, CRLF, boundary, CRLF,
'Content-Disposition: form-data; name="', name, '"; filename="', BI.cjkEncode(file.fileName), '"', CRLF, "Content-Disposition: form-data; name=\"", name, "\"; filename=\"", BI.cjkEncode(file.fileName), "\"", CRLF,
"Content-Type: application/octet-stream", CRLF, "Content-Type: application/octet-stream", CRLF,
CRLF, CRLF,
file.getAsBinary(), CRLF, file.getAsBinary(), CRLF,
@ -18846,15 +18846,15 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
return; return;
} }
for (var for (var
xhr = new XMLHttpRequest, xhr = new XMLHttpRequest,
upload = xhr.upload || { upload = xhr.upload || {
addEventListener: function (event, callback) { addEventListener: function (event, callback) {
this["on" + event] = callback this["on" + event] = callback;
} }
}, },
i = 0; i = 0;
i < length; i < length;
i++ i++
) { ) {
upload.addEventListener( upload.addEventListener(
split[i].substring(2), split[i].substring(2),
@ -18889,7 +18889,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
}, },
false false
); );
xhr.open("post", handler.url + '&filename=' + window.encodeURIComponent(handler.file.fileName), true); xhr.open("post", handler.url + "&filename=" + window.encodeURIComponent(handler.file.fileName), true);
if (!xhr.upload) { if (!xhr.upload) {
var rpe = {loaded: 0, total: handler.file.fileSize || handler.file.size, simulation: true}; var rpe = {loaded: 0, total: handler.file.fileSize || handler.file.size, simulation: true};
rpe.interval = setInterval(function () { rpe.interval = setInterval(function () {
@ -18909,8 +18909,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
switch (xhr.readyState) { switch (xhr.readyState) {
case 2: case 2:
case 3: case 3:
if (rpe.total <= rpe.loaded) if (rpe.total <= rpe.loaded) {rpe.loaded = rpe.total;}
rpe.loaded = rpe.total;
upload.onprogress(rpe); upload.onprogress(rpe);
break; break;
case 4: case 4:
@ -18922,7 +18921,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
upload["onload"]({}); upload["onload"]({});
var attachO = BI.jsonDecode(xhr.responseText); var attachO = BI.jsonDecode(xhr.responseText);
attachO.filename = handler.file.fileName; attachO.filename = handler.file.fileName;
if (handler.file.type.indexOf('image') != -1) { if (handler.file.type.indexOf("image") != -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
handler.attach_array.push(attachO); handler.attach_array.push(attachO);
@ -18938,7 +18937,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
switch (xhr.readyState) { switch (xhr.readyState) {
case 4: case 4:
var attachO = BI.jsonDecode(xhr.responseText); var attachO = BI.jsonDecode(xhr.responseText);
if (handler.file.type.indexOf('image') != -1) { if (handler.file.type.indexOf("image") != -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
attachO.filename = handler.file.fileName; attachO.filename = handler.file.fileName;
@ -18950,7 +18949,8 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
} }
break; break;
} }
} };
upload.onloadstart();
} }
var boundary = "AjaxUploadBoundary" + (new Date).getTime(); var boundary = "AjaxUploadBoundary" + (new Date).getTime();
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary); xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
@ -18958,8 +18958,8 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
xhr[xhr.sendAsBinary ? "sendAsBinary" : "send"](multipart(boundary, handler.name, handler.file)); xhr[xhr.sendAsBinary ? "sendAsBinary" : "send"](multipart(boundary, handler.name, handler.file));
} else { } else {
xhr.setRequestHeader("Content-Type", "multipart/form-data"); xhr.setRequestHeader("Content-Type", "multipart/form-data");
// xhr.setRequestHeader("X-Name", handler.name); // xhr.setRequestHeader("X-Name", handler.name);
// xhr.setRequestHeader("X-File-Name", handler.file.fileName); // xhr.setRequestHeader("X-File-Name", handler.file.fileName);
var form = new FormData(); var form = new FormData();
form.append("FileData", handler.file); form.append("FileData", handler.file);
xhr.send(form); xhr.send(form);
@ -18973,10 +18973,8 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"), var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"),
rpe = { rpe = {
loaded: 1, total: 100, simulation: true, interval: setInterval(function () { loaded: 1, total: 100, simulation: true, interval: setInterval(function () {
if (rpe.loaded < rpe.total) if (rpe.loaded < rpe.total) {++rpe.loaded;}
++rpe.loaded; if (isFunction(handler.onprogress)) {handler.onprogress(rpe, {});}
if (isFunction(handler.onprogress))
handler.onprogress(rpe, {});
}, 100) }, 100)
}, },
onload = function () { onload = function () {
@ -18984,15 +18982,15 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
form.parentNode.removeChild(form); form.parentNode.removeChild(form);
form = null; form = null;
clearInterval(rpe.interval); clearInterval(rpe.interval);
//rpe.loaded = rpe.total; // rpe.loaded = rpe.total;
try { try {
var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML; var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML;
var attachO = BI.jsonDecode(responseText); var attachO = BI.jsonDecode(responseText);
if (handler.file.type.indexOf('image') != -1) { if (handler.file.type.indexOf("image") != -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
//attachO.fileSize = responseText.length; // attachO.fileSize = responseText.length;
attachO.filename = BI.cjkDecode(handler.file.fileName); attachO.filename = BI.cjkDecode(handler.file.fileName);
if (handler.maxlength == 1) { if (handler.maxlength == 1) {
handler.attach_array[0] = attachO; handler.attach_array[0] = attachO;
@ -19000,18 +18998,16 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
handler.attach_array.push(attachO); handler.attach_array.push(attachO);
} }
} catch (e) { } catch (e) {
if (isFunction(handler.onerror)) if (isFunction(handler.onerror)) {handler.onerror(rpe, event || window.event);}
handler.onerror(rpe, event || window.event);
} }
if (isFunction(handler.onload)) if (isFunction(handler.onload)) {handler.onload(rpe, {responseText: responseText});}
handler.onload(rpe, {responseText: responseText});
}, },
target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_"); target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_");
try { // IE < 8 does not accept enctype attribute ... try { // IE < 8 does not accept enctype attribute ...
var form = document.createElement('<form enctype="multipart/form-data"></form>'), var form = document.createElement("<form enctype=\"multipart/form-data\"></form>"),
iframe = handler.iframe || (handler.iframe = document.createElement('<iframe id="' + target + '" name="' + target + '" src="' + url + '"></iframe>')); iframe = handler.iframe || (handler.iframe = document.createElement("<iframe id=\"" + target + "\" name=\"" + target + "\" src=\"" + url + "\"></iframe>"));
} catch (e) { } catch (e) {
var form = document.createElement('form'), var form = document.createElement("form"),
iframe = handler.iframe || (handler.iframe = document.createElement("iframe")); iframe = handler.iframe || (handler.iframe = document.createElement("iframe"));
form.setAttribute("enctype", "multipart/form-data"); form.setAttribute("enctype", "multipart/form-data");
iframe.setAttribute("name", iframe.id = target); iframe.setAttribute("name", iframe.id = target);
@ -19029,9 +19025,8 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
if (/loaded|complete/i.test(iframe.readyState)) { if (/loaded|complete/i.test(iframe.readyState)) {
onload(); onload();
//wei : todo,将附件信息放到handler.attach // wei : todo,将附件信息放到handler.attach
} } else if (isFunction(handler.onloadprogress)) {
else if (isFunction(handler.onloadprogress)) {
if (rpe.loaded < rpe.total) { if (rpe.loaded < rpe.total) {
++rpe.loaded; ++rpe.loaded;
} }
@ -19058,7 +19053,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
appendChild(form); appendChild(form);
form.submit(); form.submit();
} }
;
return handler; return handler;
}; };
} }
@ -19134,9 +19129,9 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
name: "", name: "",
url: "", url: "",
multiple: true, multiple: true,
accept: "", /**'*.jpg; *.zip'**/ accept: "", /** '*.jpg; *.zip'**/
maxSize: -1 //1024 * 1024 maxSize: -1 // 1024 * 1024
}) });
}, },
_init: function () { _init: function () {
@ -19146,77 +19141,78 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
this.element.attr("multiple", "multiple"); this.element.attr("multiple", "multiple");
} }
this.element.attr("name", o.name || this.getName()); this.element.attr("name", o.name || this.getName());
},
BI.nextTick(function () { mounted: function () {
// create the noswfupload.wrap Object var self = this, o = this.options;
// wrap.maxSize 文件大小限制 // create the noswfupload.wrap Object
// wrap.maxlength 文件个数限制 // wrap.maxSize 文件大小限制
var _wrap = self.wrap = self._wrap(self.element[0], o.maxSize); // wrap.maxlength 文件个数限制
// fileType could contain whatever text but filter checks *.{extension} var _wrap = this.wrap = this._wrap(this.element[0], o.maxSize);
// if present // fileType could contain whatever text but filter checks *.{extension}
// if present
// handlers
// handlers
_wrap.onloadstart = function (rpe, xhr) {
//BI.Msg.toast("loadstart"); _wrap.onloadstart = function (rpe, xhr) {
self.fireEvent(BI.File.EVENT_UPLOADSTART); // BI.Msg.toast("loadstart");
}; self.fireEvent(BI.File.EVENT_UPLOADSTART, arguments);
};
_wrap.onprogress = function (rpe, xhr) {
//BI.Msg.toast("onprogress");
// percent for each bar
// fileSize is -1 only if browser does not support file info access _wrap.onprogress = function (rpe, xhr) {
// this if splits recent browsers from others // BI.Msg.toast("onprogress");
if (this.file.fileSize !== -1) { // percent for each bar
// simulation property indicates when the progress event is fake
if (rpe.simulation) {
} else { // fileSize is -1 only if browser does not support file info access
// this if splits recent browsers from others
if (this.file.fileSize !== -1) {
// simulation property indicates when the progress event is fake
if (rpe.simulation) {
}
} else { } else {
// if fileSIze is -1 browser is using an iframe because it does
// not support
// files sent via Ajax (XMLHttpRequest)
// We can still show some information
}
self.fireEvent(BI.File.EVENT_PROGRESS, {
file: this.file,
total: rpe.total,
loaded: rpe.loaded,
simulation: rpe.simulation
});
};
// generated if there is something wrong during upload }
_wrap.onerror = function () { } else {
// just inform the user something was wrong // if fileSIze is -1 browser is using an iframe because it does
self.fireEvent(BI.File.EVENT_ERROR); // not support
}; // files sent via Ajax (XMLHttpRequest)
// We can still show some information
}
self.fireEvent(BI.File.EVENT_PROGRESS, {
file: this.file,
total: rpe.total,
loaded: rpe.loaded,
simulation: rpe.simulation
});
};
// generated when every file has been sent (one or more, it does not // generated if there is something wrong during upload
// matter) _wrap.onerror = function () {
_wrap.onload = function (rpe, xhr) { // just inform the user something was wrong
var self_ = this; self.fireEvent(BI.File.EVENT_ERROR);
// just show everything is fine ... };
// ... and after a second reset the component
setTimeout(function () {
self_.clean(); // remove files from list
self_.hide(); // hide progress bars and enable input file
//BI.Msg.toast("onload"); // generated when every file has been sent (one or more, it does not
self.fireEvent(BI.File.EVENT_UPLOADED); // matter)
// enable again the submit button/element _wrap.onload = function (rpe, xhr) {
}, 1000); var self_ = this;
}; // just show everything is fine ...
_wrap.url = o.url ? o.url : BI.servletURL // ... and after a second reset the component
+ '?op=fr_attach&cmd=ah_upload'; setTimeout(function () {
_wrap.fileType = o.accept; //文件类型限制 self_.clean(); // remove files from list
_wrap.attach_array = []; self_.hide(); // hide progress bars and enable input file
_wrap.attach_names = [];
_wrap.attachNum = 0; // BI.Msg.toast("onload");
}); self.fireEvent(BI.File.EVENT_UPLOADED);
// enable again the submit button/element
}, 1000);
};
_wrap.url = o.url ? o.url : BI.servletURL
+ "?op=fr_attach&cmd=ah_upload";
_wrap.fileType = o.accept; // 文件类型限制
_wrap.attach_array = [];
_wrap.attach_names = [];
_wrap.attachNum = 0;
}, },
_events: function (wrap) { _events: function (wrap) {
@ -19230,14 +19226,14 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown", ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown",
size = item.fileSize || item.size; size = item.fileSize || item.size;
if (wrap.fileType && -1 === wrap.fileType.indexOf("*." + ext)) { if (wrap.fileType && -1 === wrap.fileType.indexOf("*." + ext)) {
//文件类型不支持 // 文件类型不支持
BI.Msg.toast(BI.i18nText("BI-Upload_File_Type_Error")); BI.Msg.toast(BI.i18nText("BI-Upload_File_Type_Error"));
self.fireEvent(BI.File.EVENT_ERROR, { self.fireEvent(BI.File.EVENT_ERROR, {
errorType: 0, errorType: 0,
file: item file: item
}); });
} else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) { } else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) {
//文件大小不支持 // 文件大小不支持
BI.Msg.toast(BI.i18nText("BI-Upload_File_Size_Error")); BI.Msg.toast(BI.i18nText("BI-Upload_File_Size_Error"));
self.fireEvent(BI.File.EVENT_ERROR, { self.fireEvent(BI.File.EVENT_ERROR, {
errorType: 1, errorType: 1,
@ -19245,7 +19241,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
}); });
} else { } else {
wrap.files.unshift(item); wrap.files.unshift(item);
//BI.Msg.toast(value); // BI.Msg.toast(value);
self.fireEvent(BI.File.EVENT_CHANGE, { self.fireEvent(BI.File.EVENT_CHANGE, {
file: item file: item
}); });
@ -19277,7 +19273,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
disabled: false // internal use, checks input file state disabled: false // internal use, checks input file state
}, },
name: input.name, // name to send for each file ($_FILES[{name}] in the server) name: input.name, // name to send for each file ($_FILES[{name}] in the server)
// maxSize is the maximum amount of bytes for each file // maxSize is the maximum amount of bytes for each file
maxSize: o.maxSize ? o.maxSize >> 0 : -1, maxSize: o.maxSize ? o.maxSize >> 0 : -1,
files: [], // file list files: [], // file list

210
dist/base.js vendored

@ -18811,7 +18811,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true; e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
e.preventDefault ? e.preventDefault() : e.returnValue = false; e.preventDefault ? e.preventDefault() : e.returnValue = false;
} }
;
return false; return false;
} }
}; };
@ -18820,7 +18820,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
var multipart = function (boundary, name, file) { var multipart = function (boundary, name, file) {
return "--".concat( return "--".concat(
boundary, CRLF, boundary, CRLF,
'Content-Disposition: form-data; name="', name, '"; filename="', BI.cjkEncode(file.fileName), '"', CRLF, "Content-Disposition: form-data; name=\"", name, "\"; filename=\"", BI.cjkEncode(file.fileName), "\"", CRLF,
"Content-Type: application/octet-stream", CRLF, "Content-Type: application/octet-stream", CRLF,
CRLF, CRLF,
file.getAsBinary(), CRLF, file.getAsBinary(), CRLF,
@ -18846,15 +18846,15 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
return; return;
} }
for (var for (var
xhr = new XMLHttpRequest, xhr = new XMLHttpRequest,
upload = xhr.upload || { upload = xhr.upload || {
addEventListener: function (event, callback) { addEventListener: function (event, callback) {
this["on" + event] = callback this["on" + event] = callback;
} }
}, },
i = 0; i = 0;
i < length; i < length;
i++ i++
) { ) {
upload.addEventListener( upload.addEventListener(
split[i].substring(2), split[i].substring(2),
@ -18889,7 +18889,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
}, },
false false
); );
xhr.open("post", handler.url + '&filename=' + window.encodeURIComponent(handler.file.fileName), true); xhr.open("post", handler.url + "&filename=" + window.encodeURIComponent(handler.file.fileName), true);
if (!xhr.upload) { if (!xhr.upload) {
var rpe = {loaded: 0, total: handler.file.fileSize || handler.file.size, simulation: true}; var rpe = {loaded: 0, total: handler.file.fileSize || handler.file.size, simulation: true};
rpe.interval = setInterval(function () { rpe.interval = setInterval(function () {
@ -18909,8 +18909,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
switch (xhr.readyState) { switch (xhr.readyState) {
case 2: case 2:
case 3: case 3:
if (rpe.total <= rpe.loaded) if (rpe.total <= rpe.loaded) {rpe.loaded = rpe.total;}
rpe.loaded = rpe.total;
upload.onprogress(rpe); upload.onprogress(rpe);
break; break;
case 4: case 4:
@ -18922,7 +18921,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
upload["onload"]({}); upload["onload"]({});
var attachO = BI.jsonDecode(xhr.responseText); var attachO = BI.jsonDecode(xhr.responseText);
attachO.filename = handler.file.fileName; attachO.filename = handler.file.fileName;
if (handler.file.type.indexOf('image') != -1) { if (handler.file.type.indexOf("image") != -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
handler.attach_array.push(attachO); handler.attach_array.push(attachO);
@ -18938,7 +18937,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
switch (xhr.readyState) { switch (xhr.readyState) {
case 4: case 4:
var attachO = BI.jsonDecode(xhr.responseText); var attachO = BI.jsonDecode(xhr.responseText);
if (handler.file.type.indexOf('image') != -1) { if (handler.file.type.indexOf("image") != -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
attachO.filename = handler.file.fileName; attachO.filename = handler.file.fileName;
@ -18950,7 +18949,8 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
} }
break; break;
} }
} };
upload.onloadstart();
} }
var boundary = "AjaxUploadBoundary" + (new Date).getTime(); var boundary = "AjaxUploadBoundary" + (new Date).getTime();
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary); xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
@ -18958,8 +18958,8 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
xhr[xhr.sendAsBinary ? "sendAsBinary" : "send"](multipart(boundary, handler.name, handler.file)); xhr[xhr.sendAsBinary ? "sendAsBinary" : "send"](multipart(boundary, handler.name, handler.file));
} else { } else {
xhr.setRequestHeader("Content-Type", "multipart/form-data"); xhr.setRequestHeader("Content-Type", "multipart/form-data");
// xhr.setRequestHeader("X-Name", handler.name); // xhr.setRequestHeader("X-Name", handler.name);
// xhr.setRequestHeader("X-File-Name", handler.file.fileName); // xhr.setRequestHeader("X-File-Name", handler.file.fileName);
var form = new FormData(); var form = new FormData();
form.append("FileData", handler.file); form.append("FileData", handler.file);
xhr.send(form); xhr.send(form);
@ -18973,10 +18973,8 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"), var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"),
rpe = { rpe = {
loaded: 1, total: 100, simulation: true, interval: setInterval(function () { loaded: 1, total: 100, simulation: true, interval: setInterval(function () {
if (rpe.loaded < rpe.total) if (rpe.loaded < rpe.total) {++rpe.loaded;}
++rpe.loaded; if (isFunction(handler.onprogress)) {handler.onprogress(rpe, {});}
if (isFunction(handler.onprogress))
handler.onprogress(rpe, {});
}, 100) }, 100)
}, },
onload = function () { onload = function () {
@ -18984,15 +18982,15 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
form.parentNode.removeChild(form); form.parentNode.removeChild(form);
form = null; form = null;
clearInterval(rpe.interval); clearInterval(rpe.interval);
//rpe.loaded = rpe.total; // rpe.loaded = rpe.total;
try { try {
var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML; var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML;
var attachO = BI.jsonDecode(responseText); var attachO = BI.jsonDecode(responseText);
if (handler.file.type.indexOf('image') != -1) { if (handler.file.type.indexOf("image") != -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
//attachO.fileSize = responseText.length; // attachO.fileSize = responseText.length;
attachO.filename = BI.cjkDecode(handler.file.fileName); attachO.filename = BI.cjkDecode(handler.file.fileName);
if (handler.maxlength == 1) { if (handler.maxlength == 1) {
handler.attach_array[0] = attachO; handler.attach_array[0] = attachO;
@ -19000,18 +18998,16 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
handler.attach_array.push(attachO); handler.attach_array.push(attachO);
} }
} catch (e) { } catch (e) {
if (isFunction(handler.onerror)) if (isFunction(handler.onerror)) {handler.onerror(rpe, event || window.event);}
handler.onerror(rpe, event || window.event);
} }
if (isFunction(handler.onload)) if (isFunction(handler.onload)) {handler.onload(rpe, {responseText: responseText});}
handler.onload(rpe, {responseText: responseText});
}, },
target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_"); target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_");
try { // IE < 8 does not accept enctype attribute ... try { // IE < 8 does not accept enctype attribute ...
var form = document.createElement('<form enctype="multipart/form-data"></form>'), var form = document.createElement("<form enctype=\"multipart/form-data\"></form>"),
iframe = handler.iframe || (handler.iframe = document.createElement('<iframe id="' + target + '" name="' + target + '" src="' + url + '"></iframe>')); iframe = handler.iframe || (handler.iframe = document.createElement("<iframe id=\"" + target + "\" name=\"" + target + "\" src=\"" + url + "\"></iframe>"));
} catch (e) { } catch (e) {
var form = document.createElement('form'), var form = document.createElement("form"),
iframe = handler.iframe || (handler.iframe = document.createElement("iframe")); iframe = handler.iframe || (handler.iframe = document.createElement("iframe"));
form.setAttribute("enctype", "multipart/form-data"); form.setAttribute("enctype", "multipart/form-data");
iframe.setAttribute("name", iframe.id = target); iframe.setAttribute("name", iframe.id = target);
@ -19029,9 +19025,8 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
if (/loaded|complete/i.test(iframe.readyState)) { if (/loaded|complete/i.test(iframe.readyState)) {
onload(); onload();
//wei : todo,将附件信息放到handler.attach // wei : todo,将附件信息放到handler.attach
} } else if (isFunction(handler.onloadprogress)) {
else if (isFunction(handler.onloadprogress)) {
if (rpe.loaded < rpe.total) { if (rpe.loaded < rpe.total) {
++rpe.loaded; ++rpe.loaded;
} }
@ -19058,7 +19053,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
appendChild(form); appendChild(form);
form.submit(); form.submit();
} }
;
return handler; return handler;
}; };
} }
@ -19134,9 +19129,9 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
name: "", name: "",
url: "", url: "",
multiple: true, multiple: true,
accept: "", /**'*.jpg; *.zip'**/ accept: "", /** '*.jpg; *.zip'**/
maxSize: -1 //1024 * 1024 maxSize: -1 // 1024 * 1024
}) });
}, },
_init: function () { _init: function () {
@ -19146,77 +19141,78 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
this.element.attr("multiple", "multiple"); this.element.attr("multiple", "multiple");
} }
this.element.attr("name", o.name || this.getName()); this.element.attr("name", o.name || this.getName());
},
BI.nextTick(function () { mounted: function () {
// create the noswfupload.wrap Object var self = this, o = this.options;
// wrap.maxSize 文件大小限制 // create the noswfupload.wrap Object
// wrap.maxlength 文件个数限制 // wrap.maxSize 文件大小限制
var _wrap = self.wrap = self._wrap(self.element[0], o.maxSize); // wrap.maxlength 文件个数限制
// fileType could contain whatever text but filter checks *.{extension} var _wrap = this.wrap = this._wrap(this.element[0], o.maxSize);
// if present // fileType could contain whatever text but filter checks *.{extension}
// if present
// handlers
// handlers
_wrap.onloadstart = function (rpe, xhr) {
//BI.Msg.toast("loadstart"); _wrap.onloadstart = function (rpe, xhr) {
self.fireEvent(BI.File.EVENT_UPLOADSTART); // BI.Msg.toast("loadstart");
}; self.fireEvent(BI.File.EVENT_UPLOADSTART, arguments);
};
_wrap.onprogress = function (rpe, xhr) {
//BI.Msg.toast("onprogress");
// percent for each bar
// fileSize is -1 only if browser does not support file info access _wrap.onprogress = function (rpe, xhr) {
// this if splits recent browsers from others // BI.Msg.toast("onprogress");
if (this.file.fileSize !== -1) { // percent for each bar
// simulation property indicates when the progress event is fake
if (rpe.simulation) {
} else { // fileSize is -1 only if browser does not support file info access
// this if splits recent browsers from others
if (this.file.fileSize !== -1) {
// simulation property indicates when the progress event is fake
if (rpe.simulation) {
}
} else { } else {
// if fileSIze is -1 browser is using an iframe because it does
// not support
// files sent via Ajax (XMLHttpRequest)
// We can still show some information
}
self.fireEvent(BI.File.EVENT_PROGRESS, {
file: this.file,
total: rpe.total,
loaded: rpe.loaded,
simulation: rpe.simulation
});
};
// generated if there is something wrong during upload }
_wrap.onerror = function () { } else {
// just inform the user something was wrong // if fileSIze is -1 browser is using an iframe because it does
self.fireEvent(BI.File.EVENT_ERROR); // not support
}; // files sent via Ajax (XMLHttpRequest)
// We can still show some information
}
self.fireEvent(BI.File.EVENT_PROGRESS, {
file: this.file,
total: rpe.total,
loaded: rpe.loaded,
simulation: rpe.simulation
});
};
// generated when every file has been sent (one or more, it does not // generated if there is something wrong during upload
// matter) _wrap.onerror = function () {
_wrap.onload = function (rpe, xhr) { // just inform the user something was wrong
var self_ = this; self.fireEvent(BI.File.EVENT_ERROR);
// just show everything is fine ... };
// ... and after a second reset the component
setTimeout(function () {
self_.clean(); // remove files from list
self_.hide(); // hide progress bars and enable input file
//BI.Msg.toast("onload"); // generated when every file has been sent (one or more, it does not
self.fireEvent(BI.File.EVENT_UPLOADED); // matter)
// enable again the submit button/element _wrap.onload = function (rpe, xhr) {
}, 1000); var self_ = this;
}; // just show everything is fine ...
_wrap.url = o.url ? o.url : BI.servletURL // ... and after a second reset the component
+ '?op=fr_attach&cmd=ah_upload'; setTimeout(function () {
_wrap.fileType = o.accept; //文件类型限制 self_.clean(); // remove files from list
_wrap.attach_array = []; self_.hide(); // hide progress bars and enable input file
_wrap.attach_names = [];
_wrap.attachNum = 0; // BI.Msg.toast("onload");
}); self.fireEvent(BI.File.EVENT_UPLOADED);
// enable again the submit button/element
}, 1000);
};
_wrap.url = o.url ? o.url : BI.servletURL
+ "?op=fr_attach&cmd=ah_upload";
_wrap.fileType = o.accept; // 文件类型限制
_wrap.attach_array = [];
_wrap.attach_names = [];
_wrap.attachNum = 0;
}, },
_events: function (wrap) { _events: function (wrap) {
@ -19230,14 +19226,14 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown", ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown",
size = item.fileSize || item.size; size = item.fileSize || item.size;
if (wrap.fileType && -1 === wrap.fileType.indexOf("*." + ext)) { if (wrap.fileType && -1 === wrap.fileType.indexOf("*." + ext)) {
//文件类型不支持 // 文件类型不支持
BI.Msg.toast(BI.i18nText("BI-Upload_File_Type_Error")); BI.Msg.toast(BI.i18nText("BI-Upload_File_Type_Error"));
self.fireEvent(BI.File.EVENT_ERROR, { self.fireEvent(BI.File.EVENT_ERROR, {
errorType: 0, errorType: 0,
file: item file: item
}); });
} else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) { } else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) {
//文件大小不支持 // 文件大小不支持
BI.Msg.toast(BI.i18nText("BI-Upload_File_Size_Error")); BI.Msg.toast(BI.i18nText("BI-Upload_File_Size_Error"));
self.fireEvent(BI.File.EVENT_ERROR, { self.fireEvent(BI.File.EVENT_ERROR, {
errorType: 1, errorType: 1,
@ -19245,7 +19241,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
}); });
} else { } else {
wrap.files.unshift(item); wrap.files.unshift(item);
//BI.Msg.toast(value); // BI.Msg.toast(value);
self.fireEvent(BI.File.EVENT_CHANGE, { self.fireEvent(BI.File.EVENT_CHANGE, {
file: item file: item
}); });
@ -19277,7 +19273,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
disabled: false // internal use, checks input file state disabled: false // internal use, checks input file state
}, },
name: input.name, // name to send for each file ($_FILES[{name}] in the server) name: input.name, // name to send for each file ($_FILES[{name}] in the server)
// maxSize is the maximum amount of bytes for each file // maxSize is the maximum amount of bytes for each file
maxSize: o.maxSize ? o.maxSize >> 0 : -1, maxSize: o.maxSize ? o.maxSize >> 0 : -1,
files: [], // file list files: [], // file list

210
dist/bundle.js vendored

@ -44686,7 +44686,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true; e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
e.preventDefault ? e.preventDefault() : e.returnValue = false; e.preventDefault ? e.preventDefault() : e.returnValue = false;
} }
;
return false; return false;
} }
}; };
@ -44695,7 +44695,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
var multipart = function (boundary, name, file) { var multipart = function (boundary, name, file) {
return "--".concat( return "--".concat(
boundary, CRLF, boundary, CRLF,
'Content-Disposition: form-data; name="', name, '"; filename="', BI.cjkEncode(file.fileName), '"', CRLF, "Content-Disposition: form-data; name=\"", name, "\"; filename=\"", BI.cjkEncode(file.fileName), "\"", CRLF,
"Content-Type: application/octet-stream", CRLF, "Content-Type: application/octet-stream", CRLF,
CRLF, CRLF,
file.getAsBinary(), CRLF, file.getAsBinary(), CRLF,
@ -44721,15 +44721,15 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
return; return;
} }
for (var for (var
xhr = new XMLHttpRequest, xhr = new XMLHttpRequest,
upload = xhr.upload || { upload = xhr.upload || {
addEventListener: function (event, callback) { addEventListener: function (event, callback) {
this["on" + event] = callback this["on" + event] = callback;
} }
}, },
i = 0; i = 0;
i < length; i < length;
i++ i++
) { ) {
upload.addEventListener( upload.addEventListener(
split[i].substring(2), split[i].substring(2),
@ -44764,7 +44764,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
}, },
false false
); );
xhr.open("post", handler.url + '&filename=' + window.encodeURIComponent(handler.file.fileName), true); xhr.open("post", handler.url + "&filename=" + window.encodeURIComponent(handler.file.fileName), true);
if (!xhr.upload) { if (!xhr.upload) {
var rpe = {loaded: 0, total: handler.file.fileSize || handler.file.size, simulation: true}; var rpe = {loaded: 0, total: handler.file.fileSize || handler.file.size, simulation: true};
rpe.interval = setInterval(function () { rpe.interval = setInterval(function () {
@ -44784,8 +44784,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
switch (xhr.readyState) { switch (xhr.readyState) {
case 2: case 2:
case 3: case 3:
if (rpe.total <= rpe.loaded) if (rpe.total <= rpe.loaded) {rpe.loaded = rpe.total;}
rpe.loaded = rpe.total;
upload.onprogress(rpe); upload.onprogress(rpe);
break; break;
case 4: case 4:
@ -44797,7 +44796,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
upload["onload"]({}); upload["onload"]({});
var attachO = BI.jsonDecode(xhr.responseText); var attachO = BI.jsonDecode(xhr.responseText);
attachO.filename = handler.file.fileName; attachO.filename = handler.file.fileName;
if (handler.file.type.indexOf('image') != -1) { if (handler.file.type.indexOf("image") != -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
handler.attach_array.push(attachO); handler.attach_array.push(attachO);
@ -44813,7 +44812,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
switch (xhr.readyState) { switch (xhr.readyState) {
case 4: case 4:
var attachO = BI.jsonDecode(xhr.responseText); var attachO = BI.jsonDecode(xhr.responseText);
if (handler.file.type.indexOf('image') != -1) { if (handler.file.type.indexOf("image") != -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
attachO.filename = handler.file.fileName; attachO.filename = handler.file.fileName;
@ -44825,7 +44824,8 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
} }
break; break;
} }
} };
upload.onloadstart();
} }
var boundary = "AjaxUploadBoundary" + (new Date).getTime(); var boundary = "AjaxUploadBoundary" + (new Date).getTime();
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary); xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
@ -44833,8 +44833,8 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
xhr[xhr.sendAsBinary ? "sendAsBinary" : "send"](multipart(boundary, handler.name, handler.file)); xhr[xhr.sendAsBinary ? "sendAsBinary" : "send"](multipart(boundary, handler.name, handler.file));
} else { } else {
xhr.setRequestHeader("Content-Type", "multipart/form-data"); xhr.setRequestHeader("Content-Type", "multipart/form-data");
// xhr.setRequestHeader("X-Name", handler.name); // xhr.setRequestHeader("X-Name", handler.name);
// xhr.setRequestHeader("X-File-Name", handler.file.fileName); // xhr.setRequestHeader("X-File-Name", handler.file.fileName);
var form = new FormData(); var form = new FormData();
form.append("FileData", handler.file); form.append("FileData", handler.file);
xhr.send(form); xhr.send(form);
@ -44848,10 +44848,8 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"), var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"),
rpe = { rpe = {
loaded: 1, total: 100, simulation: true, interval: setInterval(function () { loaded: 1, total: 100, simulation: true, interval: setInterval(function () {
if (rpe.loaded < rpe.total) if (rpe.loaded < rpe.total) {++rpe.loaded;}
++rpe.loaded; if (isFunction(handler.onprogress)) {handler.onprogress(rpe, {});}
if (isFunction(handler.onprogress))
handler.onprogress(rpe, {});
}, 100) }, 100)
}, },
onload = function () { onload = function () {
@ -44859,15 +44857,15 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
form.parentNode.removeChild(form); form.parentNode.removeChild(form);
form = null; form = null;
clearInterval(rpe.interval); clearInterval(rpe.interval);
//rpe.loaded = rpe.total; // rpe.loaded = rpe.total;
try { try {
var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML; var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML;
var attachO = BI.jsonDecode(responseText); var attachO = BI.jsonDecode(responseText);
if (handler.file.type.indexOf('image') != -1) { if (handler.file.type.indexOf("image") != -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
//attachO.fileSize = responseText.length; // attachO.fileSize = responseText.length;
attachO.filename = BI.cjkDecode(handler.file.fileName); attachO.filename = BI.cjkDecode(handler.file.fileName);
if (handler.maxlength == 1) { if (handler.maxlength == 1) {
handler.attach_array[0] = attachO; handler.attach_array[0] = attachO;
@ -44875,18 +44873,16 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
handler.attach_array.push(attachO); handler.attach_array.push(attachO);
} }
} catch (e) { } catch (e) {
if (isFunction(handler.onerror)) if (isFunction(handler.onerror)) {handler.onerror(rpe, event || window.event);}
handler.onerror(rpe, event || window.event);
} }
if (isFunction(handler.onload)) if (isFunction(handler.onload)) {handler.onload(rpe, {responseText: responseText});}
handler.onload(rpe, {responseText: responseText});
}, },
target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_"); target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_");
try { // IE < 8 does not accept enctype attribute ... try { // IE < 8 does not accept enctype attribute ...
var form = document.createElement('<form enctype="multipart/form-data"></form>'), var form = document.createElement("<form enctype=\"multipart/form-data\"></form>"),
iframe = handler.iframe || (handler.iframe = document.createElement('<iframe id="' + target + '" name="' + target + '" src="' + url + '"></iframe>')); iframe = handler.iframe || (handler.iframe = document.createElement("<iframe id=\"" + target + "\" name=\"" + target + "\" src=\"" + url + "\"></iframe>"));
} catch (e) { } catch (e) {
var form = document.createElement('form'), var form = document.createElement("form"),
iframe = handler.iframe || (handler.iframe = document.createElement("iframe")); iframe = handler.iframe || (handler.iframe = document.createElement("iframe"));
form.setAttribute("enctype", "multipart/form-data"); form.setAttribute("enctype", "multipart/form-data");
iframe.setAttribute("name", iframe.id = target); iframe.setAttribute("name", iframe.id = target);
@ -44904,9 +44900,8 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
if (/loaded|complete/i.test(iframe.readyState)) { if (/loaded|complete/i.test(iframe.readyState)) {
onload(); onload();
//wei : todo,将附件信息放到handler.attach // wei : todo,将附件信息放到handler.attach
} } else if (isFunction(handler.onloadprogress)) {
else if (isFunction(handler.onloadprogress)) {
if (rpe.loaded < rpe.total) { if (rpe.loaded < rpe.total) {
++rpe.loaded; ++rpe.loaded;
} }
@ -44933,7 +44928,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
appendChild(form); appendChild(form);
form.submit(); form.submit();
} }
;
return handler; return handler;
}; };
} }
@ -45009,9 +45004,9 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
name: "", name: "",
url: "", url: "",
multiple: true, multiple: true,
accept: "", /**'*.jpg; *.zip'**/ accept: "", /** '*.jpg; *.zip'**/
maxSize: -1 //1024 * 1024 maxSize: -1 // 1024 * 1024
}) });
}, },
_init: function () { _init: function () {
@ -45021,77 +45016,78 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
this.element.attr("multiple", "multiple"); this.element.attr("multiple", "multiple");
} }
this.element.attr("name", o.name || this.getName()); this.element.attr("name", o.name || this.getName());
},
BI.nextTick(function () { mounted: function () {
// create the noswfupload.wrap Object var self = this, o = this.options;
// wrap.maxSize 文件大小限制 // create the noswfupload.wrap Object
// wrap.maxlength 文件个数限制 // wrap.maxSize 文件大小限制
var _wrap = self.wrap = self._wrap(self.element[0], o.maxSize); // wrap.maxlength 文件个数限制
// fileType could contain whatever text but filter checks *.{extension} var _wrap = this.wrap = this._wrap(this.element[0], o.maxSize);
// if present // fileType could contain whatever text but filter checks *.{extension}
// if present
// handlers
// handlers
_wrap.onloadstart = function (rpe, xhr) {
//BI.Msg.toast("loadstart"); _wrap.onloadstart = function (rpe, xhr) {
self.fireEvent(BI.File.EVENT_UPLOADSTART); // BI.Msg.toast("loadstart");
}; self.fireEvent(BI.File.EVENT_UPLOADSTART, arguments);
};
_wrap.onprogress = function (rpe, xhr) {
//BI.Msg.toast("onprogress");
// percent for each bar
// fileSize is -1 only if browser does not support file info access _wrap.onprogress = function (rpe, xhr) {
// this if splits recent browsers from others // BI.Msg.toast("onprogress");
if (this.file.fileSize !== -1) { // percent for each bar
// simulation property indicates when the progress event is fake
if (rpe.simulation) {
} else { // fileSize is -1 only if browser does not support file info access
// this if splits recent browsers from others
if (this.file.fileSize !== -1) {
// simulation property indicates when the progress event is fake
if (rpe.simulation) {
}
} else { } else {
// if fileSIze is -1 browser is using an iframe because it does
// not support
// files sent via Ajax (XMLHttpRequest)
// We can still show some information
}
self.fireEvent(BI.File.EVENT_PROGRESS, {
file: this.file,
total: rpe.total,
loaded: rpe.loaded,
simulation: rpe.simulation
});
};
// generated if there is something wrong during upload }
_wrap.onerror = function () { } else {
// just inform the user something was wrong // if fileSIze is -1 browser is using an iframe because it does
self.fireEvent(BI.File.EVENT_ERROR); // not support
}; // files sent via Ajax (XMLHttpRequest)
// We can still show some information
}
self.fireEvent(BI.File.EVENT_PROGRESS, {
file: this.file,
total: rpe.total,
loaded: rpe.loaded,
simulation: rpe.simulation
});
};
// generated when every file has been sent (one or more, it does not // generated if there is something wrong during upload
// matter) _wrap.onerror = function () {
_wrap.onload = function (rpe, xhr) { // just inform the user something was wrong
var self_ = this; self.fireEvent(BI.File.EVENT_ERROR);
// just show everything is fine ... };
// ... and after a second reset the component
setTimeout(function () {
self_.clean(); // remove files from list
self_.hide(); // hide progress bars and enable input file
//BI.Msg.toast("onload"); // generated when every file has been sent (one or more, it does not
self.fireEvent(BI.File.EVENT_UPLOADED); // matter)
// enable again the submit button/element _wrap.onload = function (rpe, xhr) {
}, 1000); var self_ = this;
}; // just show everything is fine ...
_wrap.url = o.url ? o.url : BI.servletURL // ... and after a second reset the component
+ '?op=fr_attach&cmd=ah_upload'; setTimeout(function () {
_wrap.fileType = o.accept; //文件类型限制 self_.clean(); // remove files from list
_wrap.attach_array = []; self_.hide(); // hide progress bars and enable input file
_wrap.attach_names = [];
_wrap.attachNum = 0; // BI.Msg.toast("onload");
}); self.fireEvent(BI.File.EVENT_UPLOADED);
// enable again the submit button/element
}, 1000);
};
_wrap.url = o.url ? o.url : BI.servletURL
+ "?op=fr_attach&cmd=ah_upload";
_wrap.fileType = o.accept; // 文件类型限制
_wrap.attach_array = [];
_wrap.attach_names = [];
_wrap.attachNum = 0;
}, },
_events: function (wrap) { _events: function (wrap) {
@ -45105,14 +45101,14 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown", ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown",
size = item.fileSize || item.size; size = item.fileSize || item.size;
if (wrap.fileType && -1 === wrap.fileType.indexOf("*." + ext)) { if (wrap.fileType && -1 === wrap.fileType.indexOf("*." + ext)) {
//文件类型不支持 // 文件类型不支持
BI.Msg.toast(BI.i18nText("BI-Upload_File_Type_Error")); BI.Msg.toast(BI.i18nText("BI-Upload_File_Type_Error"));
self.fireEvent(BI.File.EVENT_ERROR, { self.fireEvent(BI.File.EVENT_ERROR, {
errorType: 0, errorType: 0,
file: item file: item
}); });
} else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) { } else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) {
//文件大小不支持 // 文件大小不支持
BI.Msg.toast(BI.i18nText("BI-Upload_File_Size_Error")); BI.Msg.toast(BI.i18nText("BI-Upload_File_Size_Error"));
self.fireEvent(BI.File.EVENT_ERROR, { self.fireEvent(BI.File.EVENT_ERROR, {
errorType: 1, errorType: 1,
@ -45120,7 +45116,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
}); });
} else { } else {
wrap.files.unshift(item); wrap.files.unshift(item);
//BI.Msg.toast(value); // BI.Msg.toast(value);
self.fireEvent(BI.File.EVENT_CHANGE, { self.fireEvent(BI.File.EVENT_CHANGE, {
file: item file: item
}); });
@ -45152,7 +45148,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/**
disabled: false // internal use, checks input file state disabled: false // internal use, checks input file state
}, },
name: input.name, // name to send for each file ($_FILES[{name}] in the server) name: input.name, // name to send for each file ($_FILES[{name}] in the server)
// maxSize is the maximum amount of bytes for each file // maxSize is the maximum amount of bytes for each file
maxSize: o.maxSize ? o.maxSize >> 0 : -1, maxSize: o.maxSize ? o.maxSize >> 0 : -1,
files: [], // file list files: [], // file list

2
dist/bundle.min.js vendored

File diff suppressed because one or more lines are too long

209
src/base/single/input/file.js

@ -75,7 +75,7 @@
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true; e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
e.preventDefault ? e.preventDefault() : e.returnValue = false; e.preventDefault ? e.preventDefault() : e.returnValue = false;
} }
;
return false; return false;
} }
}; };
@ -84,7 +84,7 @@
var multipart = function (boundary, name, file) { var multipart = function (boundary, name, file) {
return "--".concat( return "--".concat(
boundary, CRLF, boundary, CRLF,
'Content-Disposition: form-data; name="', name, '"; filename="', BI.cjkEncode(file.fileName), '"', CRLF, "Content-Disposition: form-data; name=\"", name, "\"; filename=\"", BI.cjkEncode(file.fileName), "\"", CRLF,
"Content-Type: application/octet-stream", CRLF, "Content-Type: application/octet-stream", CRLF,
CRLF, CRLF,
file.getAsBinary(), CRLF, file.getAsBinary(), CRLF,
@ -110,15 +110,15 @@
return; return;
} }
for (var for (var
xhr = new XMLHttpRequest, xhr = new XMLHttpRequest,
upload = xhr.upload || { upload = xhr.upload || {
addEventListener: function (event, callback) { addEventListener: function (event, callback) {
this["on" + event] = callback this["on" + event] = callback;
} }
}, },
i = 0; i = 0;
i < length; i < length;
i++ i++
) { ) {
upload.addEventListener( upload.addEventListener(
split[i].substring(2), split[i].substring(2),
@ -153,7 +153,7 @@
}, },
false false
); );
xhr.open("post", handler.url + '&filename=' + window.encodeURIComponent(handler.file.fileName), true); xhr.open("post", handler.url + "&filename=" + window.encodeURIComponent(handler.file.fileName), true);
if (!xhr.upload) { if (!xhr.upload) {
var rpe = {loaded: 0, total: handler.file.fileSize || handler.file.size, simulation: true}; var rpe = {loaded: 0, total: handler.file.fileSize || handler.file.size, simulation: true};
rpe.interval = setInterval(function () { rpe.interval = setInterval(function () {
@ -173,8 +173,7 @@
switch (xhr.readyState) { switch (xhr.readyState) {
case 2: case 2:
case 3: case 3:
if (rpe.total <= rpe.loaded) if (rpe.total <= rpe.loaded) {rpe.loaded = rpe.total;}
rpe.loaded = rpe.total;
upload.onprogress(rpe); upload.onprogress(rpe);
break; break;
case 4: case 4:
@ -186,7 +185,7 @@
upload["onload"]({}); upload["onload"]({});
var attachO = BI.jsonDecode(xhr.responseText); var attachO = BI.jsonDecode(xhr.responseText);
attachO.filename = handler.file.fileName; attachO.filename = handler.file.fileName;
if (handler.file.type.indexOf('image') != -1) { if (handler.file.type.indexOf("image") != -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
handler.attach_array.push(attachO); handler.attach_array.push(attachO);
@ -202,7 +201,7 @@
switch (xhr.readyState) { switch (xhr.readyState) {
case 4: case 4:
var attachO = BI.jsonDecode(xhr.responseText); var attachO = BI.jsonDecode(xhr.responseText);
if (handler.file.type.indexOf('image') != -1) { if (handler.file.type.indexOf("image") != -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
attachO.filename = handler.file.fileName; attachO.filename = handler.file.fileName;
@ -214,7 +213,7 @@
} }
break; break;
} }
} };
upload.onloadstart(); upload.onloadstart();
} }
var boundary = "AjaxUploadBoundary" + (new Date).getTime(); var boundary = "AjaxUploadBoundary" + (new Date).getTime();
@ -223,8 +222,8 @@
xhr[xhr.sendAsBinary ? "sendAsBinary" : "send"](multipart(boundary, handler.name, handler.file)); xhr[xhr.sendAsBinary ? "sendAsBinary" : "send"](multipart(boundary, handler.name, handler.file));
} else { } else {
xhr.setRequestHeader("Content-Type", "multipart/form-data"); xhr.setRequestHeader("Content-Type", "multipart/form-data");
// xhr.setRequestHeader("X-Name", handler.name); // xhr.setRequestHeader("X-Name", handler.name);
// xhr.setRequestHeader("X-File-Name", handler.file.fileName); // xhr.setRequestHeader("X-File-Name", handler.file.fileName);
var form = new FormData(); var form = new FormData();
form.append("FileData", handler.file); form.append("FileData", handler.file);
xhr.send(form); xhr.send(form);
@ -238,10 +237,8 @@
var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"), var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"),
rpe = { rpe = {
loaded: 1, total: 100, simulation: true, interval: setInterval(function () { loaded: 1, total: 100, simulation: true, interval: setInterval(function () {
if (rpe.loaded < rpe.total) if (rpe.loaded < rpe.total) {++rpe.loaded;}
++rpe.loaded; if (isFunction(handler.onprogress)) {handler.onprogress(rpe, {});}
if (isFunction(handler.onprogress))
handler.onprogress(rpe, {});
}, 100) }, 100)
}, },
onload = function () { onload = function () {
@ -249,15 +246,15 @@
form.parentNode.removeChild(form); form.parentNode.removeChild(form);
form = null; form = null;
clearInterval(rpe.interval); clearInterval(rpe.interval);
//rpe.loaded = rpe.total; // rpe.loaded = rpe.total;
try { try {
var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML; var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML;
var attachO = BI.jsonDecode(responseText); var attachO = BI.jsonDecode(responseText);
if (handler.file.type.indexOf('image') != -1) { if (handler.file.type.indexOf("image") != -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
//attachO.fileSize = responseText.length; // attachO.fileSize = responseText.length;
attachO.filename = BI.cjkDecode(handler.file.fileName); attachO.filename = BI.cjkDecode(handler.file.fileName);
if (handler.maxlength == 1) { if (handler.maxlength == 1) {
handler.attach_array[0] = attachO; handler.attach_array[0] = attachO;
@ -265,18 +262,16 @@
handler.attach_array.push(attachO); handler.attach_array.push(attachO);
} }
} catch (e) { } catch (e) {
if (isFunction(handler.onerror)) if (isFunction(handler.onerror)) {handler.onerror(rpe, event || window.event);}
handler.onerror(rpe, event || window.event);
} }
if (isFunction(handler.onload)) if (isFunction(handler.onload)) {handler.onload(rpe, {responseText: responseText});}
handler.onload(rpe, {responseText: responseText});
}, },
target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_"); target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_");
try { // IE < 8 does not accept enctype attribute ... try { // IE < 8 does not accept enctype attribute ...
var form = document.createElement('<form enctype="multipart/form-data"></form>'), var form = document.createElement("<form enctype=\"multipart/form-data\"></form>"),
iframe = handler.iframe || (handler.iframe = document.createElement('<iframe id="' + target + '" name="' + target + '" src="' + url + '"></iframe>')); iframe = handler.iframe || (handler.iframe = document.createElement("<iframe id=\"" + target + "\" name=\"" + target + "\" src=\"" + url + "\"></iframe>"));
} catch (e) { } catch (e) {
var form = document.createElement('form'), var form = document.createElement("form"),
iframe = handler.iframe || (handler.iframe = document.createElement("iframe")); iframe = handler.iframe || (handler.iframe = document.createElement("iframe"));
form.setAttribute("enctype", "multipart/form-data"); form.setAttribute("enctype", "multipart/form-data");
iframe.setAttribute("name", iframe.id = target); iframe.setAttribute("name", iframe.id = target);
@ -294,9 +289,8 @@
if (/loaded|complete/i.test(iframe.readyState)) { if (/loaded|complete/i.test(iframe.readyState)) {
onload(); onload();
//wei : todo,将附件信息放到handler.attach // wei : todo,将附件信息放到handler.attach
} } else if (isFunction(handler.onloadprogress)) {
else if (isFunction(handler.onloadprogress)) {
if (rpe.loaded < rpe.total) { if (rpe.loaded < rpe.total) {
++rpe.loaded; ++rpe.loaded;
} }
@ -323,7 +317,7 @@
appendChild(form); appendChild(form);
form.submit(); form.submit();
} }
;
return handler; return handler;
}; };
} }
@ -399,9 +393,9 @@
name: "", name: "",
url: "", url: "",
multiple: true, multiple: true,
accept: "", /**'*.jpg; *.zip'**/ accept: "", /** '*.jpg; *.zip'**/
maxSize: -1 //1024 * 1024 maxSize: -1 // 1024 * 1024
}) });
}, },
_init: function () { _init: function () {
@ -411,77 +405,78 @@
this.element.attr("multiple", "multiple"); this.element.attr("multiple", "multiple");
} }
this.element.attr("name", o.name || this.getName()); this.element.attr("name", o.name || this.getName());
},
BI.nextTick(function () { mounted: function () {
// create the noswfupload.wrap Object var self = this, o = this.options;
// wrap.maxSize 文件大小限制 // create the noswfupload.wrap Object
// wrap.maxlength 文件个数限制 // wrap.maxSize 文件大小限制
var _wrap = self.wrap = self._wrap(self.element[0], o.maxSize); // wrap.maxlength 文件个数限制
// fileType could contain whatever text but filter checks *.{extension} var _wrap = this.wrap = this._wrap(this.element[0], o.maxSize);
// if present // fileType could contain whatever text but filter checks *.{extension}
// if present
// handlers
// handlers
_wrap.onloadstart = function (rpe, xhr) {
//BI.Msg.toast("loadstart"); _wrap.onloadstart = function (rpe, xhr) {
self.fireEvent(BI.File.EVENT_UPLOADSTART, arguments); // BI.Msg.toast("loadstart");
}; self.fireEvent(BI.File.EVENT_UPLOADSTART, arguments);
};
_wrap.onprogress = function (rpe, xhr) { _wrap.onprogress = function (rpe, xhr) {
//BI.Msg.toast("onprogress"); // BI.Msg.toast("onprogress");
// percent for each bar // percent for each bar
// fileSize is -1 only if browser does not support file info access // fileSize is -1 only if browser does not support file info access
// this if splits recent browsers from others // this if splits recent browsers from others
if (this.file.fileSize !== -1) { if (this.file.fileSize !== -1) {
// simulation property indicates when the progress event is fake // simulation property indicates when the progress event is fake
if (rpe.simulation) { if (rpe.simulation) {
} else {
}
} else { } else {
// if fileSIze is -1 browser is using an iframe because it does
// not support
// files sent via Ajax (XMLHttpRequest)
// We can still show some information
}
self.fireEvent(BI.File.EVENT_PROGRESS, {
file: this.file,
total: rpe.total,
loaded: rpe.loaded,
simulation: rpe.simulation
});
};
// generated if there is something wrong during upload }
_wrap.onerror = function () { } else {
// just inform the user something was wrong // if fileSIze is -1 browser is using an iframe because it does
self.fireEvent(BI.File.EVENT_ERROR); // not support
}; // files sent via Ajax (XMLHttpRequest)
// We can still show some information
}
self.fireEvent(BI.File.EVENT_PROGRESS, {
file: this.file,
total: rpe.total,
loaded: rpe.loaded,
simulation: rpe.simulation
});
};
// generated when every file has been sent (one or more, it does not // generated if there is something wrong during upload
// matter) _wrap.onerror = function () {
_wrap.onload = function (rpe, xhr) { // just inform the user something was wrong
var self_ = this; self.fireEvent(BI.File.EVENT_ERROR);
// just show everything is fine ... };
// ... and after a second reset the component
setTimeout(function () {
self_.clean(); // remove files from list
self_.hide(); // hide progress bars and enable input file
//BI.Msg.toast("onload"); // generated when every file has been sent (one or more, it does not
self.fireEvent(BI.File.EVENT_UPLOADED); // matter)
// enable again the submit button/element _wrap.onload = function (rpe, xhr) {
}, 1000); var self_ = this;
}; // just show everything is fine ...
_wrap.url = o.url ? o.url : BI.servletURL // ... and after a second reset the component
+ '?op=fr_attach&cmd=ah_upload'; setTimeout(function () {
_wrap.fileType = o.accept; //文件类型限制 self_.clean(); // remove files from list
_wrap.attach_array = []; self_.hide(); // hide progress bars and enable input file
_wrap.attach_names = [];
_wrap.attachNum = 0; // BI.Msg.toast("onload");
}); self.fireEvent(BI.File.EVENT_UPLOADED);
// enable again the submit button/element
}, 1000);
};
_wrap.url = o.url ? o.url : BI.servletURL
+ "?op=fr_attach&cmd=ah_upload";
_wrap.fileType = o.accept; // 文件类型限制
_wrap.attach_array = [];
_wrap.attach_names = [];
_wrap.attachNum = 0;
}, },
_events: function (wrap) { _events: function (wrap) {
@ -495,14 +490,14 @@
ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown", ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown",
size = item.fileSize || item.size; size = item.fileSize || item.size;
if (wrap.fileType && -1 === wrap.fileType.indexOf("*." + ext)) { if (wrap.fileType && -1 === wrap.fileType.indexOf("*." + ext)) {
//文件类型不支持 // 文件类型不支持
BI.Msg.toast(BI.i18nText("BI-Upload_File_Type_Error")); BI.Msg.toast(BI.i18nText("BI-Upload_File_Type_Error"));
self.fireEvent(BI.File.EVENT_ERROR, { self.fireEvent(BI.File.EVENT_ERROR, {
errorType: 0, errorType: 0,
file: item file: item
}); });
} else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) { } else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) {
//文件大小不支持 // 文件大小不支持
BI.Msg.toast(BI.i18nText("BI-Upload_File_Size_Error")); BI.Msg.toast(BI.i18nText("BI-Upload_File_Size_Error"));
self.fireEvent(BI.File.EVENT_ERROR, { self.fireEvent(BI.File.EVENT_ERROR, {
errorType: 1, errorType: 1,
@ -510,7 +505,7 @@
}); });
} else { } else {
wrap.files.unshift(item); wrap.files.unshift(item);
//BI.Msg.toast(value); // BI.Msg.toast(value);
self.fireEvent(BI.File.EVENT_CHANGE, { self.fireEvent(BI.File.EVENT_CHANGE, {
file: item file: item
}); });
@ -542,7 +537,7 @@
disabled: false // internal use, checks input file state disabled: false // internal use, checks input file state
}, },
name: input.name, // name to send for each file ($_FILES[{name}] in the server) name: input.name, // name to send for each file ($_FILES[{name}] in the server)
// maxSize is the maximum amount of bytes for each file // maxSize is the maximum amount of bytes for each file
maxSize: o.maxSize ? o.maxSize >> 0 : -1, maxSize: o.maxSize ? o.maxSize >> 0 : -1,
files: [], // file list files: [], // file list

Loading…
Cancel
Save