From: Vásáry Dániel Date: Tue, 20 Feb 2024 21:16:11 +0000 (+0100) Subject: Drop upload working X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=d4106aaa6282db119140885ff711a18741c1048d;p=sly-crm.git Drop upload working --- diff --git a/dropfile/src/main/java/net/elgekko/zkoss/Dropfile.java b/dropfile/src/main/java/net/elgekko/zkoss/Dropfile.java deleted file mode 100644 index 38271a3..0000000 --- a/dropfile/src/main/java/net/elgekko/zkoss/Dropfile.java +++ /dev/null @@ -1,268 +0,0 @@ -package net.elgekko.zkoss; - -import org.zkoss.lang.Generics; -import org.zkoss.lang.Objects; -import org.zkoss.util.media.Media; -import org.zkoss.zk.au.AuRequest; -import org.zkoss.zk.ui.Component; -import org.zkoss.zk.ui.Desktop; -import org.zkoss.zk.ui.event.Events; -import org.zkoss.zk.ui.event.UploadEvent; -import org.zkoss.zk.ui.sys.ContentRenderer; -import org.zkoss.zul.impl.XulElement; - -import java.io.IOException; -import java.util.Iterator; -import java.util.List; - -public class Dropfile extends XulElement { - private static final String DEFAULT_DETECTION = "browser"; - - static { - addClientEvent(Dropfile.class, "onUpload", 1); - } - - private int _maxsize; - private String _viewerClass; - - - private String _detection = "browser"; - - - private String _content; - - - private boolean _native; - - - private Component _anchor; - - - private static Media[] parseResult(List result) { - /* 245 */ - if (result != null) { - /* */ - /* 247 */ - for (Iterator it = result.iterator(); it.hasNext(); ) { - /* 248 */ - Media media = it.next(); - /* 249 */ - if (media != null && media.inMemory() && media.isBinary()) { - /* 250 */ - String nm = media.getName(); - /* 251 */ - if (nm == null || nm.length() == 0) { - /* 252 */ - byte[] bs = media.getByteData(); - /* 253 */ - if (bs == null || bs.length == 0) { - /* 254 */ - it.remove(); - /* */ - } - /* */ - } - /* */ - } - /* */ - } - /* */ - /* 260 */ - if (!result.isEmpty()) - /* 261 */ return result.toArray(new Media[result.size()]); - /* */ - } - /* 263 */ - return null; - /* */ - } - - public int getMaxsize() { - /* 95 */ - return this._maxsize; - /* */ - } - - public void setMaxsize(int value) { - /* 79 */ - if (value < 0) { - /* 80 */ - value = -1; - /* */ - } - /* */ - /* 83 */ - if (this._maxsize != value) { - /* 84 */ - this._maxsize = value; - /* 85 */ - setAttribute("org.zkoss.zk.upload.maxsize", Integer.valueOf(value)); - /* 86 */ - smartUpdate("maxsize", this._maxsize); - /* */ - } - /* */ - } - - public String getDetection() { - /* 122 */ - return this._detection; - /* */ - } - - public void setDetection(String value) { - /* 112 */ - if (!this._detection.equals(value)) { - /* 113 */ - this._detection = value; - /* 114 */ - smartUpdate("detection", this._detection); - /* */ - } - /* */ - } - - public String getViewerClass() { - /* 144 */ - return this._viewerClass; - /* */ - } - - public void setViewerClass(String value) { - /* 130 */ - if (value != null && value.length() == 0) { - /* 131 */ - value = null; - /* */ - } - /* */ - /* 134 */ - if (!Objects.equals(this._viewerClass, value)) { - /* 135 */ - this._viewerClass = value; - /* 136 */ - smartUpdate("viewerClass", this._viewerClass); - /* */ - } - /* */ - } - - public String getContent() { - /* 163 */ - return this._content; - /* */ - } - - public void setContent(String value) { - /* 153 */ - if (value != null && !value.equals(this._content)) { - /* 154 */ - this._content = value; - /* 155 */ - smartUpdate("content", this._content); - /* */ - } - /* */ - } - - public boolean isNative() { - /* 183 */ - return this._native; - /* */ - } - - public void setNative(boolean value) { - /* 172 */ - if (value != this._native) { - /* 173 */ - this._native = value; - /* 174 */ - smartUpdate("native", this._native); - /* */ - } - /* */ - } - - public Component getAnchor() { - /* 203 */ - return this._anchor; - /* */ - } - - public void setAnchor(Component anchor) { - /* 192 */ - if (anchor != this._anchor) { - /* 193 */ - this._anchor = anchor; - /* 194 */ - smartUpdate("anchorUuid", (this._anchor != null) ? this._anchor.getUuid() : ""); - /* */ - } - /* */ - } - - protected void renderProperties(ContentRenderer renderer) throws IOException { - - if (this._maxsize == 0) { - /* 210 */ - this._maxsize = getDesktop().getWebApp().getConfiguration().getMaxUploadSize(); - /* */ - } - /* */ - /* 213 */ - super.renderProperties(renderer); - /* 214 */ - if (!Objects.equals(this._detection, "browser")) { - /* 215 */ - render(renderer, "detection", this._detection); - /* */ - } - /* 217 */ - render(renderer, "maxsize", Integer.valueOf(this._maxsize)); - /* 218 */ - render(renderer, "viewerClass", this._viewerClass); - /* 219 */ - render(renderer, "content", this._content); - /* 220 */ - render(renderer, "native", this._native); - /* 221 */ - if (this._anchor != null) { - /* 222 */ - render(renderer, "anchorUuid", (this._anchor != null) ? this._anchor.getUuid() : ""); - /* */ - } - /* */ - } - - public void service(AuRequest request, boolean everError) { - /* 230 */ - String cmd = request.getCommand(); - /* 231 */ - if ("onUpload".equals(cmd)) { - /* 232 */ - Desktop desktop = getDesktop(); - /* 233 */ - List result = Generics.cast((List) desktop.getAttribute(getUuid())); - /* 234 */ - desktop.removeAttribute(getUuid()); - /* 235 */ - UploadEvent uploadEvent = new UploadEvent("onUpload", desktop.getComponentByUuid(getUuid()), parseResult(result)); - /* */ - /* 237 */ - Events.postEvent(uploadEvent); - /* */ - } else { - /* 239 */ - super.service(request, everError); - /* */ - } - /* */ - } - /* */ -} - - -/* Location: C:\temp\zk\zkmax\!\org\zkoss\zkmax\zul\Dropupload.class - * Java compiler version: 5 (49.0) - * JD-Core Version: 1.1.3 - */ \ No newline at end of file diff --git a/dropfile/src/main/java/net/elgekko/zkoss/Dropupload.java b/dropfile/src/main/java/net/elgekko/zkoss/Dropupload.java new file mode 100644 index 0000000..894e19f --- /dev/null +++ b/dropfile/src/main/java/net/elgekko/zkoss/Dropupload.java @@ -0,0 +1,167 @@ +package net.elgekko.zkoss; + +import org.zkoss.lang.Objects; +import org.zkoss.zk.au.AuRequest; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.Events; +import org.zkoss.zk.ui.event.UploadEvent; +import org.zkoss.zk.ui.ext.Uploadable; +import org.zkoss.zk.ui.sys.ContentRenderer; +import org.zkoss.zul.impl.XulElement; + +import java.io.IOException; +import java.util.Collection; +import java.util.stream.Collectors; + +public class Dropupload extends XulElement { + private static final String DEFAULT_DETECTION = "browser"; + + static { + addClientEvent(Dropupload.class, "onUpload", 1); + addClientEvent(Dropupload.class, "onMaxFileCountExceed", 1); + } + + private int _maxsize; + private int _maxFileCount = -1; + + private String _viewerClass; + + private String _detection = "browser"; + + private String _content; + + private boolean _native; + + private Component _anchor; + + private String _suppressedErrors; + + public int getMaxsize() { + return this._maxsize; + } + + public void setMaxsize(int value) { + if (value < 0) + value = -1; + if (this._maxsize != value) { + this._maxsize = value; + setAttribute("org.zkoss.zk.upload.maxsize", Integer.valueOf(value)); + smartUpdate("maxsize", this._maxsize); + } + } + + public String getDetection() { + return this._detection; + } + + public void setDetection(String value) { + if (!this._detection.equals(value)) { + this._detection = value; + smartUpdate("detection", this._detection); + } + } + + public String getViewerClass() { + return this._viewerClass; + } + + public void setViewerClass(String value) { + if (value != null && value.length() == 0) + value = null; + if (!Objects.equals(this._viewerClass, value)) { + this._viewerClass = value; + smartUpdate("viewerClass", this._viewerClass); + } + } + + public String getContent() { + return this._content; + } + + public void setContent(String value) { + if (value != null && !value.equals(this._content)) { + this._content = value; + smartUpdate("content", this._content); + } + } + + public boolean isNative() { + return this._native; + } + + public void setNative(boolean value) { + if (value != this._native) { + this._native = value; + setAttribute("org.zkoss.zk.upload.native", Boolean.valueOf(value)); + } + } + + public Component getAnchor() { + return this._anchor; + } + + public void setAnchor(Component anchor) { + if (anchor != this._anchor) { + this._anchor = anchor; + smartUpdate("anchorUuid", (this._anchor != null) ? this._anchor.getUuid() : ""); + } + } + + public int getMaxFileCount() { + return this._maxFileCount; + } + + public void setMaxFileCount(int maxFileCount) { + if (maxFileCount < 0) + maxFileCount = -1; + if (maxFileCount != this._maxFileCount) { + this._maxFileCount = maxFileCount; + smartUpdate("maxFileCount", this._maxFileCount); + } + } + + public String getSuppressedErrors() { + return this._suppressedErrors; + } + + public void setSuppressedErrors(String suppressedErrors) { + if (!Objects.equals(this._suppressedErrors, suppressedErrors)) { + this._suppressedErrors = suppressedErrors; + smartUpdate("suppressedErrors", suppressedErrors); + } + } + + public void setSuppressedErrors(Collection suppressedErrors) { + setSuppressedErrors((suppressedErrors == null) ? null : suppressedErrors.stream() + .map(Object::toString) + .collect(Collectors.joining("|"))); + } + + protected void renderProperties(ContentRenderer renderer) throws IOException { + if (this._maxsize == 0) + this._maxsize = getDesktop().getWebApp().getConfiguration().getMaxUploadSize(); + super.renderProperties(renderer); + if (!Objects.equals(this._detection, "browser")) + render(renderer, "detection", this._detection); + render(renderer, "maxsize", Integer.valueOf(this._maxsize)); + render(renderer, "viewerClass", this._viewerClass); + render(renderer, "content", this._content); + if (this._anchor != null) + render(renderer, "anchorUuid", (this._anchor != null) ? this._anchor.getUuid() : ""); + if (this._maxFileCount != -1) + render(renderer, "maxFileCount", Integer.valueOf(this._maxFileCount)); + render(renderer, "suppressedErrors", this._suppressedErrors); + } + + public void service(AuRequest request, boolean everError) { + String cmd = request.getCommand(); + if ("onUpload".equals(cmd)) { + Events.postEvent(UploadEvent.getLatestUploadEvent(cmd, this, request)); + } else if ("onMaxFileCountExceed".equals(cmd)) { + Events.postEvent(new Event("onMaxFileCountExceed", this, request.getData().get("filesCount"))); + } else { + super.service(request, everError); + } + } +} diff --git a/dropfile/src/main/resources/metainfo/zk/lang-addon.xml b/dropfile/src/main/resources/metainfo/zk/lang-addon.xml index f901505..640903d 100644 --- a/dropfile/src/main/resources/metainfo/zk/lang-addon.xml +++ b/dropfile/src/main/resources/metainfo/zk/lang-addon.xml @@ -1,5 +1,5 @@ - dropfile + dropupload net.elgekko.zkoss.Version 0.0.1-SNAPSHOT @@ -8,12 +8,12 @@ xul/html - dropfile - net.elgekko.zkoss.Dropfile - dropfile.Dropfile + dropupload + net.elgekko.zkoss.Dropupload + dropupload.Dropupload default - mold/dropfile.js + mold/dropupload.js - css/dropfile.css.dsp + css/dropupload.css.dsp \ No newline at end of file diff --git a/dropfile/src/main/resources/web/js/dropfile/Dropfile.js b/dropfile/src/main/resources/web/js/dropfile/Dropfile.js deleted file mode 100644 index 9db4d89..0000000 --- a/dropfile/src/main/resources/web/js/dropfile/Dropfile.js +++ /dev/null @@ -1,643 +0,0 @@ -(function () { - var j = {}; - function e(m) { - m.stop() - } - function f(m) { - m.originalEvent.dataTransfer.dropEffect = "copy" - } - function g(m) { - m.originalEvent.dataTransfer.dropEffect = "none" - } - function i(m) { - e(m); - f(m) - } - function h(m) { - e(m); - g(m) - } - function a() { - jq(document).bind("dragenter dragover", h) - } - function k() { - jq(document).unbind("dragenter dragover", h) - } - function d(m) { - jq(document).bind("dragenter dragover", m.proxy(m._dragShow)).bind("dragleave drop", m.proxy(m._dragHide)) - } - function l(m) { - jq(document).unbind("dragenter dragover", m.proxy(m._dragShow)).unbind("dragleave drop", m.proxy(m._dragHide)) - } - dropfile.Dropfile = zk.$extends(zul.Widget, { - _sid: 0, - _detection: "browser", - _content: "", - _native: false, - _anchorUuid: "", - $init: function () { - this.$supers("$init", arguments); - this._uploaders = {}; - this._last = {}; - this._error = true - }, - setMaxsize: (function (m) { - return function (n) { - this[m] = n; - return this - } - })("_maxsize"), - getMaxsize: _zkf$ = function () { - return this._maxsize - }, - isMaxsize: _zkf$, - setViewerClass: (function (m) { - return function (n) { - this[m] = n; - return this - } - })("_viewerClass"), - getViewerClass: _zkf$ = function () { - return this._viewerClass - }, - isViewerClass: _zkf$, - setDetection: (function (m) { - return function (n) { - this[m] = n; - return this - } - })("_detection"), - getDetection: _zkf$ = function () { - return this._detection - }, - isDetection: _zkf$, - setContent: (function (m, n) { - return function () { - this.__fname__ = m.substring(1); - this[m] = n.apply(this, arguments); - this.__fname__ = null; - return this - } - })("_content", (function (m) { - return m ? m : "" - })), - getContent: _zkf$ = function () { - return this._content - }, - isContent: _zkf$, - setAnchorUuid: (function (m, n) { - return function (p, q) { - var r = this[m]; - this[m] = p; - if (r !== p || (q && q.force)) { - this.__fname__ = m.substring(1); - n.apply(this, arguments); - this.__fname__ = null - } - return this - } - })("_anchorUuid", (function (m) { - this._shallSyncSize = true - })), - getAnchorUuid: _zkf$ = function () { - return this._anchorUuid - }, - isAnchorUuid: _zkf$, - setNative: function (m) { - this._native = m - }, - isNative: function () { - return this._native - }, - bind_: function (r, q, p) { - this.$supers("bind_", arguments); - var o = this.getDetection(), - m = jq(this.$n()); - m.bind("drop", this.proxy(this._dropAction)); - switch (o) { - case "self": - m.bind("dragenter dragover", this.proxy(this._showContent)).bind("dragleave", this.proxy(this._hideContent)); - a(); - this._setContentVisible(false); - break; - case "browser": - m.bind("dragenter dragover", f).bind("dragleave", g); - d(this); - this.hide(); - break; - case "none": - m.bind("dragenter dragover", i); - a(); - break; - default: - var n = this; - p.push(function () { - var s = jq(n.$f(o)); - if (s.length) { - m.bind("dragenter dragover", i); - s.bind("dragenter dragover", n.proxy(n._showContentNoneDrop)).bind("dragleave", n.proxy(n._hideContent)); - a(); - n._setContentVisible(false) - } else { - m.bind("dragenter dragover", f).bind("dragleave", g); - d(n); - n.hide() - } - }) - } - }, - unbind_: function () { - var n = this.getDetection(), - m = jq(this.$n()).unbind("drop", this.proxy(this._dropAction)); - var o = jq(this.$f(n)); - if (n == "self") { - m.unbind("dragenter dragover", this.proxy(this._showContent)).unbind("dragleave", this.proxy(this._hideContent)); - k() - } else { - if (n == "none") { - m.unbind("dragenter dragover", i); - k() - } else { - if (n == "browser" || !o.length) { - m.unbind("dragenter dragover", f).unbind("dragleave", g); - l(this) - } else { - m.unbind("dragenter dragover", i); - o.unbind("dragenter dragover", this.proxy(this._showContentNoneDrop)).unbind("dragleave", this.proxy(this._hideContent)); - k() - } - } - } - if (j[this.uuid]) { - delete j[this.uuid] - } - this.$supers("unbind_", arguments) - }, - _showContent: function (m) { - i(m); - this._setContentVisible(true); - this._shallContentHide = false - }, - _showContentNoneDrop: function (m) { - h(m); - this._setContentVisible(true); - this._shallContentHide = false - }, - _hideContent: function (n) { - e(n); - if (!this._shallContentHide) { - var m = this; - setTimeout(function () { - if (m && m.desktop && m._shallContentHide) { - m._setContentVisible(false) - } - }, 50) - } - this._shallContentHide = true - }, - _setContentVisible: function (m) { - var n = jq(this.$n()).children(); - m ? n.show() : n.hide() - }, - _dragHide: function (n) { - e(n); - delete j[this.uuid]; - if (!this._shallHide) { - var m = this; - setTimeout(function () { - if (m && m.desktop && m._shallHide) { - m.setVisible(false) - } - }, 50) - } - this._shallHide = true - }, - _dragShow: function (p) { - e(p); - if (p.originalEvent.dataTransfer.types.length) { - var o = p.originalEvent.dataTransfer.types[0]; - if (o != "Files" && o != "public.file-url" && o != "application/x-moz-file") { - a(); - return - } - k() - } - if (p.originalEvent.dataTransfer.dropEffect != "copy") { - g(p) - } - this._shallHide = false; - j[this.uuid] = this; - var z = this.$n(), - s = this._last, - x = this._anchorUuid, - w = 0, - F; - for (F in s) { - if (s[F]) { - w++ - } - } - var A = this._shallSyncSize; - if (z) { - if (x) { - var v = this._lastAnchor || {}; - var u = jq(x, zk), - D = jq(z), - B = u.offset(), - m = D.offset(); - var t = u.width(), - C = u.height(), - r = B.top, - y = B.left; - if (v.w != t || v.h != C || v.t != r || v.l != y) { - A = true; - v.w = t; - v.h = C; - v.t = r; - v.l = y; - this._lastAnchor = v - } - if (A) { - z.style.position = "fixed"; - z.style.zIndex = "10000"; - if (w == 0) { - var q = D.width(), - E = D.height(); - s.w = q ? q + "px" : ""; - s.h = E ? E + "px" : ""; - s.t = m.top ? m.top + "px" : ""; - s.l = m.left ? m.left + "px" : "" - } - if (u.size() > 0) { - z.style.width = t + "px"; - z.style.height = C + "px"; - z.style.top = r + "px"; - z.style.left = y + "px" - } - } - } else { - if (A) { - z.style.position = "static"; - z.style.zIndex = "auto"; - z.style.width = s.w || "100px"; - z.style.height = s.h || "100px"; - z.style.top = s.t || "auto"; - z.style.left = s.l || "auto"; - this._last = {} - } - } - this._shallSyncSize = false - } - this.setVisible(true) - }, - _dropAction: function (s) { - e(s); - for (var y in j) { - this._dragHide.call(j[y], s) - } - if (this.getDetection() == "self") { - this._setContentVisible(false) - } - var r = s.originalEvent.dataTransfer.files; - console.log("_dropAction", r); - var C = this._maxsize > 0 ? this._maxsize * 1024 : -1; - if (C != -1) { - var p = []; - for (var A = 0; A < r.length; A++) { - var B = r[A], - w = B.size, - u = w / 1024, - q = C / 1024, - t = " " + msgzk.KBYTES, - m = " " + msgzk.MBYTES, - v = Math.round(u) + t, - n = Math.round(q) + t; - if (w > C) { - p.push(B.name); - p.push(zk.fmt.Text.format(msgzul.UPLOAD_ERROR_EXCEED_MAXSIZE, v, n, w, C, v, n, Math.round(u / 1024) + m, Math.round(q / 1024) + m)) - } - } - if (p.length > 0) { - zk.load("zul.wnd,zul.wgt,zul.box", function () { - var H = []; - for (var E = 0; E < p.length; E += 2) { - H.push(new zul.wgt.Label({ - id: "msg" + E, - value: p[E], - style: "font-weight: bold" - })); - H.push(new zul.wgt.Label({ - id: "msg" + E + 1, - value: p[E + 1] - })); - if (!(E == p.length - 2)) { - H.push(new zul.wgt.Separator({ - bar: true - })) - } - } - var F = new zul.wnd.Window({ - id: "aualert", - closable: true, - width: "250pt", - title: zk.appName, - border: "normal", - children: [new zul.box.Box({ - mold: "horizontal", - children: [new zul.wgt.Div({ - sclass: "z-messagebox-icon z-messagebox-error" - }), new zul.wgt.Div({ - id: "content", - sclass: "z-messagebox", - width: "210pt", - style: "overflow:auto", - children: [new zul.box.Box({ - mold: "vertical", - children: H - })] - })] - }), new zul.wgt.Separator({ - bar: true - }), new zul.box.Box({ - mold: "horizontal", - style: "margin-left:auto; margin-right:auto", - children: [new zul.wgt.Button({ - label: "OK", - listeners: { - onClick: function (I) { - this.$o().detach() - } - } - })] - })], - mode: "modal" - }); - var G = zk.Desktop.$(); - if (G && (G = G.firstChild) && G.desktop) { - G.appendChild(F) - } else { - jq(document.body).append(F) - } - }); - return - } - } - var x = s.originalEvent.dataTransfer.items; - for (var A = 0; A < r.length; A++) { - var D = false; - if (x) { - var o = x[A]; - if (o.getAsEntry) { - D = o.getAsEntry().isDirectory - } else { - if (o.webkitGetAsEntry) { - D = o.webkitGetAsEntry().isDirectory - } - } - } - if (!D) { - this._sid++; - var z = new dropfile.DropUploader(this, this._genKey(), r[A]); - this._uploaders[z.id] = z - } - } - this.checkFinish() - }, - _genKey: function () { - return this.uuid + "_uplder_" + this._sid - }, - cancel: function (m) { - delete this._uploaders[m]; - this.checkFinish() - }, - checkFinish: function () { - var m = false; - for (var o in this._uploaders) { - if (!(m = this._uploaders[o].isFinish())) { - this._uploaders[o].start(); - break - } - var n = this._uploaders[o].xhr.responseText; - n.startsWith("error") ? jq.alert(n.substring(6), { - icon: "ERROR" - }) : this._error = false; - delete this._uploaders[o] - } - if (m && !this._error) { - this.fire("onUpload"); - this._error = true - } - }, - domContent_: function () { - return '
' + this.getContent() + "
" - } - }); - function c(n) { - var m = dropfile.DropUploadViewer.fileManager; - if (!m || !m.desktop) { - if (m) { - m.detach() - } - dropfile.DropUploadViewer.fileManager = m = new dropfile.DropUploadManager(); - n.getWidget().getPage().appendChild(m) - } - m.removeFile(n); - m.addFile(n) - } - function b(m) { - if (dropfile.DropUploadManager) { - return c(m) - } - zk.load("zul.wgt,zul.box", function () { - dropfile.DropUploadManager = zk.$extends(zul.wgt.Popup, { - $init: function () { - this.$supers("$init", arguments); - this._files = {}; - this.setSclass("z-fileupload-manager") - }, - onFloatUp: function (n) { - if (!this.isVisible()) { - return - } - this.setTopmost() - }, - getFileItem: function (n) { - return this._files[n] || zk.Widget.$(n) - }, - addFile: function (p) { - var r = p.id, - q = p.file.name, - o = this.getFileItem(r); - if (!o) { - o = new zul.wgt.Div({ - uuid: r, - children: [new zul.wgt.Label({ - value: q + ":" - }), new zul.box.Box({ - mold: "horizontal", - children: [new dropfile.Dropuploadprogress({ - id: r, - sclass: "z-fileupload-progress" - }), new zul.wgt.Div({ - sclass: "z-fileupload-remove z-icon-times", - listeners: { - onClick: function () { - p.cancel() - } - } - })] - }), new zul.wgt.Label({ - id: r + "_total" - }), new zul.wgt.Separator()] - }); - try { - this.appendChild(o) - } catch (n) {} - this._files[r] = o - } - return o - }, - updateFile: function (p, q, n) { - var r = p.id, - o = this.getFileItem(r); - if (!o) { - return - } - o.$f(r).setValue(q); - o.$f(r + "_total").setValue(n) - }, - removeFile: function (q) { - var s = q.id, - o = this.getFileItem(s); - if (o) { - o.detach() - } - delete this._files[s]; - var r = true; - for (var n in this._files) { - if (!(r = false)) { - break - } - } - if (r) { - this.close() - } - }, - open: function (o, n) { - this.$super("open", o, null, n || "after_start", { - sendOnOpen: false, - disableMask: true - }) - } - }); - c(m) - }) - } - dropfile.DropUploadViewer = zk.$extends(zk.Object, { - $init: function (n, m) { - this.uploader = n; - b(n) - }, - update: function (m, n) { - var o = dropfile.DropUploadViewer.fileManager; - if (o) { - if (!o.isOpen()) { - o.open(this.uploader.getWidget()) - } - o.updateFile(this.uploader, m * 100 / n, msgzk.FILE_SIZE + Math.round(n / 1024) + msgzk.KBYTES) - } - }, - destroy: function () { - var m = dropfile.DropUploadViewer.fileManager; - if (m) { - m.removeFile(this.uploader) - } - } - }); - dropfile.DropUploader = zk.$extends(zk.Object, { - _status: 100, - $init: function (n, q, o) { - this.upload = n; - this.id = q; - this.file = o; - var p, - m = this; - if (n.getViewerClass()) { - zk.$import(n.getViewerClass(), function (r) { - p = new r(m, o) - }) - } else { - p = new dropfile.DropUploadViewer(this, o) - } - this.viewer = p; - this.xhr = new XMLHttpRequest(); - this.xhr.upload.onprogress = this.progressFunc(); - this.xhr.onload = this.completeFunc(); - this.xhr.onerror = this.errorFunc() - }, - getWidget: function () { - return this.upload - }, - isFinish: function () { - return this._status == 300 - }, - start: function () { - if (this._status == 200) { - return - } - this._status = 200; - var o = new FormData(); - o.append("file", this.file); - var m = this.upload; - var n = m.desktop; - var q = zk.ajaxURI("/dropupload", { - desktop: n, - au: true - }) + "?uuid=" + m.uuid + "&dtid=" + n.id + "&native=" + m._native; - var p = this.xhr; - p.open("POST", q, true); - p.send(o) - }, - cancel: function () { - if (this.xhr) { - this.xhr.abort() - } - this.viewer.destroy(); - this.upload.cancel(this.id) - }, - progressFunc: function () { - var m = this.viewer; - return function (n) { - m.update(n.loaded, n.total) - } - }, - completeFunc: function () { - var m = this; - return function (n) { - m._status = 300; - m.viewer.destroy(); - m.upload.checkFinish() - } - }, - errorFunc: function () { - var m = this; - return function (n) { - m.cancel() - } - } - }); - dropfile.Dropuploadprogress = zk.$extends(zul.wgt.Progressmeter, { - _fixImgWidth: _zkf = function () { - var p = this.$n(), - m = this.$n("img"); - if (m) { - if (zk(p).isRealVisible()) { - var o = jq(m) - } - o.animate({ - width: Math.round((p.clientWidth * this._value) / 100) + "px" - }, o.zk.getAnimationSpeed(100)) - } - } - }) -})(); diff --git a/dropfile/src/main/resources/web/js/dropfile/css/dropfile.css.dsp b/dropfile/src/main/resources/web/js/dropfile/css/dropfile.css.dsp deleted file mode 100644 index c9895ac..0000000 --- a/dropfile/src/main/resources/web/js/dropfile/css/dropfile.css.dsp +++ /dev/null @@ -1 +0,0 @@ -<%@ taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" %><%@ taglib uri="http://www.zkoss.org/dsp/zk/core" prefix="z" %><%@ taglib uri="http://www.zkoss.org/dsp/web/theme" prefix="t" %>.z-dropfile{width:100px;height:100px;-webkit-border-radius:10px;-moz-border-radius:10px;-o-border-radius:10px;-ms-border-radius:10px;border-radius:10px;padding:2px;background:#e6e6e6} \ No newline at end of file diff --git a/dropfile/src/main/resources/web/js/dropfile/zk.wpd b/dropfile/src/main/resources/web/js/dropfile/zk.wpd deleted file mode 100644 index 75a5316..0000000 --- a/dropfile/src/main/resources/web/js/dropfile/zk.wpd +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/dropfile/src/main/resources/web/js/dropupload/Dropupload.js b/dropfile/src/main/resources/web/js/dropupload/Dropupload.js new file mode 100644 index 0000000..e7e4bca --- /dev/null +++ b/dropfile/src/main/resources/web/js/dropupload/Dropupload.js @@ -0,0 +1,661 @@ +var $jscomp = $jscomp || {}; +$jscomp.scope = {}; +$jscomp.checkStringArgs = function (c, d, e) { + if (null == c) + throw new TypeError("The 'this' value for String.prototype." + e + " must not be null or undefined"); + if (d instanceof RegExp) + throw new TypeError("First argument to String.prototype." + e + " must not be a regular expression"); + return c + "" +}; +$jscomp.ASSUME_ES5 = !1; +$jscomp.ASSUME_NO_NATIVE_MAP = !1; +$jscomp.ASSUME_NO_NATIVE_SET = !1; +$jscomp.SIMPLE_FROUND_POLYFILL = !1; +$jscomp.ISOLATE_POLYFILLS = !1; +$jscomp.FORCE_POLYFILL_PROMISE = !1; +$jscomp.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION = !1; +$jscomp.defineProperty = $jscomp.ASSUME_ES5 || "function" == typeof Object.defineProperties ? Object.defineProperty : function (c, d, e) { + if (c == Array.prototype || c == Object.prototype) + return c; + c[d] = e.value; + return c +}; +$jscomp.getGlobal = function (c) { + c = ["object" == typeof globalThis && globalThis, c, "object" == typeof window && window, "object" == typeof self && self, "object" == typeof global && global]; + for (var d = 0; d < c.length; ++d) { + var e = c[d]; + if (e && e.Math == Math) + return e + } + throw Error("Cannot find global object"); +}; +$jscomp.global = $jscomp.getGlobal(this); +$jscomp.IS_SYMBOL_NATIVE = "function" === typeof Symbol && "symbol" === typeof Symbol("x"); +$jscomp.TRUST_ES6_POLYFILLS = !$jscomp.ISOLATE_POLYFILLS || $jscomp.IS_SYMBOL_NATIVE; +$jscomp.polyfills = {}; +$jscomp.propertyToPolyfillSymbol = {}; +$jscomp.POLYFILL_PREFIX = "$jscp$"; +var $jscomp$lookupPolyfilledValue = function (c, d) { + var e = $jscomp.propertyToPolyfillSymbol[d]; + if (null == e) + return c[d]; + e = c[e]; + return void 0 !== e ? e : c[d] +}; +$jscomp.polyfill = function (c, d, e, k) { + d && ($jscomp.ISOLATE_POLYFILLS ? $jscomp.polyfillIsolated(c, d, e, k) : $jscomp.polyfillUnisolated(c, d, e, k)) +}; +$jscomp.polyfillUnisolated = function (c, d, e, k) { + e = $jscomp.global; + c = c.split("."); + for (k = 0; k < c.length - 1; k++) { + var m = c[k]; + if (!(m in e)) + return; + e = e[m] + } + c = c[c.length - 1]; + k = e[c]; + d = d(k); + d != k && null != d && $jscomp.defineProperty(e, c, { + configurable: !0, + writable: !0, + value: d + }) +}; +$jscomp.polyfillIsolated = function (c, d, e, k) { + var m = c.split("."); + c = 1 === m.length; + k = m[0]; + k = !c && k in $jscomp.polyfills ? $jscomp.polyfills : $jscomp.global; + for (var n = 0; n < m.length - 1; n++) { + var p = m[n]; + if (!(p in k)) + return; + k = k[p] + } + m = m[m.length - 1]; + e = $jscomp.IS_SYMBOL_NATIVE && "es6" === e ? k[m] : null; + d = d(e); + null != d && (c ? $jscomp.defineProperty($jscomp.polyfills, m, { + configurable: !0, + writable: !0, + value: d + }) : d !== e && (void 0 === $jscomp.propertyToPolyfillSymbol[m] && (e = 1E9 * Math.random() >>> 0, $jscomp.propertyToPolyfillSymbol[m] = $jscomp.IS_SYMBOL_NATIVE ? + $jscomp.global.Symbol(m) : $jscomp.POLYFILL_PREFIX + e + "$" + m), $jscomp.defineProperty(k, $jscomp.propertyToPolyfillSymbol[m], { + configurable: !0, + writable: !0, + value: d + }))) +}; +$jscomp.polyfill("String.prototype.startsWith", function (c) { + return c ? c : function (d, e) { + var k = $jscomp.checkStringArgs(this, d, "startsWith"); + d += ""; + var m = k.length, + n = d.length; + e = Math.max(0, Math.min(e | 0, k.length)); + for (var p = 0; p < n && e < m; ) + if (k[e++] != d[p++]) + return !1; + return p >= n + } +}, "es6", "es3"); +$jscomp.arrayIteratorImpl = function (c) { + var d = 0; + return function () { + return d < c.length ? { + done: !1, + value: c[d++] + } + : { + done: !0 + } + } +}; +$jscomp.arrayIterator = function (c) { + return { + next: $jscomp.arrayIteratorImpl(c) + } +}; +$jscomp.initSymbol = function () {}; +$jscomp.polyfill("Symbol", function (c) { + if (c) + return c; + var d = function (n, p) { + this.$jscomp$symbol$id_ = n; + $jscomp.defineProperty(this, "description", { + configurable: !0, + writable: !0, + value: p + }) + }; + d.prototype.toString = function () { + return this.$jscomp$symbol$id_ + }; + var e = "jscomp_symbol_" + (1E9 * Math.random() >>> 0) + "_", + k = 0, + m = function (n) { + if (this instanceof m) + throw new TypeError("Symbol is not a constructor"); + return new d(e + (n || "") + "_" + k++, n) + }; + return m +}, "es6", "es3"); +$jscomp.polyfill("Symbol.iterator", function (c) { + if (c) + return c; + c = Symbol("Symbol.iterator"); + for (var d = "Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "), e = 0; e < d.length; e++) { + var k = $jscomp.global[d[e]]; + "function" === typeof k && "function" != typeof k.prototype[c] && $jscomp.defineProperty(k.prototype, c, { + configurable: !0, + writable: !0, + value: function () { + return $jscomp.iteratorPrototype($jscomp.arrayIteratorImpl(this)) + } + }) + } + return c +}, "es6", + "es3"); +$jscomp.iteratorPrototype = function (c) { + c = { + next: c + }; + c[Symbol.iterator] = function () { + return this + }; + return c +}; +$jscomp.iteratorFromArray = function (c, d) { + c instanceof String && (c += ""); + var e = 0, + k = !1, + m = { + next: function () { + if (!k && e < c.length) { + var n = e++; + return { + value: d(n, c[n]), + done: !1 + } + } + k = !0; + return { + done: !0, + value: void 0 + } + } + }; + m[Symbol.iterator] = function () { + return m + }; + return m +}; +$jscomp.polyfill("Array.prototype.keys", function (c) { + return c ? c : function () { + return $jscomp.iteratorFromArray(this, function (d) { + return d + }) + } +}, "es6", "es3"); +(function () { + function c(a) { + a.originalEvent.dataTransfer.dropEffect = "copy" + } + function d(a) { + a.originalEvent.dataTransfer.dropEffect = "none" + } + function e(a) { + a.stop(); + c(a) + } + function k(a) { + a.stop(); + d(a) + } + function m() { + jq(document).on("dragenter dragover", k) + } + function n() { + jq(document).off("dragenter dragover", k) + } + function p(a) { + jq(document).on("dragenter dragover", a.proxy(a._dragShow)).on("dragleave drop", a.proxy(a._dragHide)) + } + function y(a) { + var b = dropupload.DropUploadViewer.fileManager; + b && b.desktop || (b && b.detach(), dropupload.DropUploadViewer.fileManager = + b = new dropupload.DropUploadManager, a.getWidget().getPage().appendChild(b)); + b.removeFile(a); + b.addFile(a) + } + function A(a) { + if (dropupload.DropUploadManager) + return y(a); + zk.load("zul.wgt,zul.box", function () { + dropupload.DropUploadManager = zk.$extends(zul.wgt.Popup, { + $init: function () { + this.$supers("$init", arguments); + this._files = {}; + this.setSclass("z-fileupload-manager") + }, + onFloatUp: function (b) { + this.isVisible() && this.setTopmost() + }, + getFileItem: function (b) { + return this._files[b] || zk.Widget.$(b) + }, + addFile: function (b) { + var g = + b.id, + h = b.file.name, + f = this.getFileItem(g); + if (!f) { + f = new zul.wgt.Div({ + uuid: g, + children: [new zul.wgt.Label({ + value: h + ":" + }), new zul.box.Box({ + mold: "horizontal", + children: [new zul.wgt.Progressmeter({ + id: g, + sclass: "z-fileupload-progress" + }), new zul.wgt.Div({ + sclass: "z-fileupload-remove z-icon-times", + listeners: { + onClick: function () { + b.cancel() + } + } + })] + }), new zul.wgt.Label({ + id: g + "_total" + }), new zul.wgt.Separator] + }); + try { + this.appendChild(f) + } catch (l) { + zk.debugLog(l.message || l) + } + this._files[g] = f + } + return f + }, + updateFile: function (b, + g, h) { + b = b.id; + var f = this.getFileItem(b); + f && (f.$f(b).setValue(g), f.$f(b + "_total").setValue(h)) + }, + removeFile: function (b) { + b = b.id; + var g = this.getFileItem(b); + g && g.detach(); + delete this._files[b]; + 0 === Object.keys(this._files).length && this.close() + }, + open: function (b, g) { + this.$super("open", b, null, g || "after_start", { + sendOnOpen: !1, + disableMask: !0 + }) + } + }); + y(a) + }) + } + var v = {}; + dropupload.Dropupload = zk.$extends(zul.Widget, { + _sid: 0, + _detection: "browser", + _content: "", + _anchorUuid: "", + _maxFileCount: -1, + $init: function () { + this.$supers("$init", + arguments); + this._uploaders = {}; + this._last = {}; + this._error = !0; + this._suppressedErrors = [] + }, + $define: { + maxsize: null, + viewerClass: null, + detection: null, + content: [function (a) { + return a ? a : "" + }, null], + anchorUuid: function (a) { + this._shallSyncSize = !0 + }, + maxFileCount: null, + suppressedErrors: function (a) { + this._suppressedErrors = a ? a.split("|") : [] + } + }, + setNative: function (a) {}, + isNative: function () { + return !1 + }, + bind_: function (a, b, g) { + this.$supers("bind_", arguments); + var h = this.getDetection(), + f = jq(this.$n()); + f.on("drop", this.proxy(this._dropAction)); + switch (h) { + case "self": + f.on("dragenter dragover", this.proxy(this._showContent)).on("dragleave", this.proxy(this._hideContent)); + m(); + this._setContentVisible(!1); + break; + case "browser": + f.on("dragenter dragover", c).on("dragleave", d); + p(this); + this.hide(); + break; + case "none": + f.on("dragenter dragover", e); + m(); + break; + default: + var l = this; + g.push(function () { + var r = jq(l.$f(h)); + r.length ? (f.on("dragenter dragover", e), r.on("dragenter dragover", l.proxy(l._showContentNoneDrop)).on("dragleave", l.proxy(l._hideContent)), m(), l._setContentVisible(!1)) : + (f.on("dragenter dragover", c).on("dragleave", d), p(l), l.hide()) + }) + } + }, + unbind_: function () { + var a = this.getDetection(), + b = jq(this.$n()).off("drop", this.proxy(this._dropAction)), + g = jq(this.$f(a)); + "self" == a ? (b.off("dragenter dragover", this.proxy(this._showContent)).off("dragleave", this.proxy(this._hideContent)), n()) : "none" == a ? (b.off("dragenter dragover", e), n()) : "browser" != a && g.length ? (b.off("dragenter dragover", e), g.off("dragenter dragover", this.proxy(this._showContentNoneDrop)).off("dragleave", this.proxy(this._hideContent)), + n()) : (b.off("dragenter dragover", c).off("dragleave", d), jq(document).off("dragenter dragover", this.proxy(this._dragShow)).off("dragleave drop", this.proxy(this._dragHide))); + v[this.uuid] && delete v[this.uuid]; + this.$supers("unbind_", arguments) + }, + _showContent: function (a) { + e(a); + this._setContentVisible(!0); + this._shallContentHide = !1 + }, + _showContentNoneDrop: function (a) { + k(a); + this._setContentVisible(!0); + this._shallContentHide = !1 + }, + _hideContent: function (a) { + a.stop(); + if (!this._shallContentHide) { + var b = this; + setTimeout(function () { + b && + b.desktop && b._shallContentHide && b._setContentVisible(!1) + }, 50) + } + this._shallContentHide = !0 + }, + _setContentVisible: function (a) { + var b = jq(this.$n()).children(); + a ? b.show() : b.hide() + }, + _dragHide: function (a) { + a.stop(); + delete v[this.uuid]; + if (!this._shallHide) { + var b = this; + setTimeout(function () { + b && b.desktop && b._shallHide && b.setVisible(!1) + }, 50) + } + this._shallHide = !0 + }, + _dragShow: function (a) { + a.stop(); + if (a.originalEvent.dataTransfer.types.length) { + var b = a.originalEvent.dataTransfer.types[0]; + if ("Files" != b && "public.file-url" != + b && "application/x-moz-file" != b) { + m(); + return + } + n() + } + "copy" != a.originalEvent.dataTransfer.dropEffect && d(a); + this._shallHide = !1; + v[this.uuid] = this; + a = this.$n(); + b = this._last; + var g = this._anchorUuid, + h = 0; + for (t in b) + b[t] && h++; + var f = this._shallSyncSize; + if (a) { + if (g) { + var l = this._lastAnchor || {}; + g = jq(g, zk); + var r = jq(a), + q = g.offset(); + var t = r.offset(); + var w = g.width(), + u = g.height(), + x = q.top; + q = q.left; + if (l.w != w || l.h != u || l.t != x || l.l != q) + f = !0, l.w = w, l.h = u, l.t = x, l.l = q, this._lastAnchor = l; + f && (a.style.position = "fixed", a.style.zIndex = + "10000", 0 == h && (h = r.width(), f = r.height(), b.w = h ? h + "px" : "", b.h = f ? f + "px" : "", b.t = t.top ? t.top + "px" : "", b.l = t.left ? t.left + "px" : ""), 0 < g.length && (a.style.width = w + "px", a.style.height = u + "px", a.style.top = x + "px", a.style.left = q + "px")) + } else + f && (a.style.position = "static", a.style.zIndex = "auto", a.style.width = b.w || "100px", a.style.height = b.h || "100px", a.style.top = b.t || "auto", a.style.left = b.l || "auto", this._last = {}); + this._shallSyncSize = !1 + } + this.setVisible(!0) + }, + _dropAction: function (a) { + a.stop(); + for (var b in v) + this._dragHide.call(v[b], + a); + "self" == this.getDetection() && this._setContentVisible(!1); + b = a.originalEvent.dataTransfer.files; + var g = b.length; + if (-1 != this._maxFileCount && g > this._maxFileCount) + this.fire("onMaxFileCountExceed", { + filesCount: g + }); + else { + var h = 0 < this._maxsize ? 1024 * this._maxsize : -1; + if (-1 != h) { + for (var f = [], l = 0; l < g; l++) { + var r = b[l], + q = r.size, + t = q / 1024, + w = h / 1024, + u = " " + msgzk.KBYTES, + x = " " + msgzk.MBYTES, + B = Math.round(t) + u; + u = Math.round(w) + u; + if (q > h) { + var z = zk.fmt.Text.formatFileSize; + f.push(r.name); + f.push(zk.fmt.Text.format(msgzul.UPLOAD_ERROR_EXCEED_MAXSIZE, + z(q), z(h), q, h, B, u, Math.round(t / 1024) + x, Math.round(w / 1024) + x)) + } + } + if (0 < f.length) { + this.showError_(f); + return + } + } + a = a.originalEvent.dataTransfer.items; + for (l = 0; l < g; l++) + h = !1, a && (f = a[l], f.getAsEntry ? h = f.getAsEntry().isDirectory : f.webkitGetAsEntry && (h = f.webkitGetAsEntry().isDirectory)), h || (this._sid++, h = new dropupload.DropUploader(this, this._genKey(), b[l]), this._uploaders[h.id] = h); + this.checkFinish() + } + }, + _genKey: function () { + return this.uuid + "_uplder_" + this._sid + }, + cancel: function (a) { + delete this._uploaders[a]; + this.checkFinish() + }, + checkFinish: function () { + var a = !1, + b; + for (b in this._uploaders) { + if (!(a = this._uploaders[b].isFinish())) { + this._uploaders[b].start(); + break + } + var g = this._uploaders[b].xhr.responseText; + g.startsWith("error:") ? this.showError_(g.substring(6)) : this._error = !1; + delete this._uploaders[b] + } + a && !this._error && (this.fire("onUpload"), this._error = !0) + }, + showError_: function (a) { + if (Array.isArray(a)) + - 1 === this._suppressedErrors.indexOf("size-limit-exceeded") && zk.load("zul.wnd,zul.wgt,zul.box", function () { + for (var h = [], f = 0; f < a.length; f += + 2) + h.push(new zul.wgt.Label({ + id: "msg" + f, + value: a[f], + style: "font-weight: bold" + })), h.push(new zul.wgt.Label({ + id: "msg" + f + 1, + value: a[f + 1] + })), f != a.length - 2 && h.push(new zul.wgt.Separator({ + bar: !0 + })); + h = new zul.wnd.Window({ + id: "aualert", + closable: !0, + width: "250pt", + title: zk.appName, + border: "normal", + children: [new zul.box.Box({ + mold: "horizontal", + children: [new zul.wgt.Div({ + sclass: "z-messagebox-icon z-messagebox-error" + }), new zul.wgt.Div({ + id: "content", + sclass: "z-messagebox", + style: "overflow:auto", + children: [new zul.box.Box({ + mold: "vertical", + children: h + })] + })] + }), new zul.wgt.Separator({ + bar: !0 + }), new zul.box.Box({ + mold: "horizontal", + style: "margin-left:auto; margin-right:auto", + children: [new zul.wgt.Button({ + label: "OK", + listeners: { + onClick: function (l) { + this.$o().detach() + } + } + })] + })], + mode: "modal" + }); + (f = zk.Desktop.$()) && (f = f.firstChild) && f.desktop ? f.appendChild(h) : jq(document.body).append(h) + }); + else { + var b = a.match("^([\\w-]+?):"); + if (b) { + a = a.replace(b[0], ""); + var g = b[1] + } + g && -1 !== this._suppressedErrors.indexOf(g) || jq.alert(a, { + icon: "ERROR" + }) + } + }, + domContent_: function () { + return '
' + this.getContent() + "
" + } + }); + dropupload.DropUploadViewer = zk.$extends(zk.Object, { + $init: function (a, b) { + this.uploader = a; + A(a) + }, + update: function (a, b) { + var g = dropupload.DropUploadViewer.fileManager; + g && (g.isOpen() || g.open(this.uploader.getWidget()), g.updateFile(this.uploader, 100 * a / b, msgzk.FILE_SIZE + Math.round(b / 1024) + msgzk.KBYTES)) + }, + destroy: function () { + var a = dropupload.DropUploadViewer.fileManager; + a && a.removeFile(this.uploader) + } + }); + dropupload.DropUploader = zk.$extends(zk.Object, { + _status: 100, + $init: function (a, b, g) { + this.upload = a; + this.id = b; + this.file = g; + var h, + f = this; + a.getViewerClass() ? zk.$import(a.getViewerClass(), function (l) { + h = new l(f, g) + }) : h = new dropupload.DropUploadViewer(this, g); + this.viewer = h; + this.xhr = new XMLHttpRequest; + this.xhr.upload.onprogress = this.progressFunc(); + this.xhr.onload = this.completeFunc(); + this.xhr.onerror = this.errorFunc() + }, + getWidget: function () { + return this.upload + }, + isFinish: function () { + return 300 == this._status + }, + start: function () { + if (200 != this._status) { + this._status = 200; + var a = new FormData; + a.append("file", this.file); + zk.UploadUtils.ajaxUpload(this.upload, this.xhr, a) + } + }, + cancel: function () { + this.xhr && this.xhr.abort(); + this.viewer.destroy(); + this.upload.cancel(this.id) + }, + progressFunc: function () { + var a = this.viewer; + return function (b) { + a.update(b.loaded, b.total) + } + }, + completeFunc: function () { + var a = this; + return function (b) { + a._status = 300; + a.viewer.destroy(); + a.upload.checkFinish() + } + }, + errorFunc: function () { + var a = this; + return function (b) { + a.cancel() + } + } + }) +})(); diff --git a/dropfile/src/main/resources/web/js/dropupload/css/dropupload.css.dsp b/dropfile/src/main/resources/web/js/dropupload/css/dropupload.css.dsp new file mode 100644 index 0000000..d99bcd9 --- /dev/null +++ b/dropfile/src/main/resources/web/js/dropupload/css/dropupload.css.dsp @@ -0,0 +1,14 @@ +<%@ taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" %> +<%@ taglib uri="http://www.zkoss.org/dsp/zk/core" prefix="z" %> +<%@ taglib uri="http://www.zkoss.org/dsp/web/theme" prefix="t" %> +.z-dropupload { + width:100px; + height:100px; + -webkit-border-radius:10px; + -moz-border-radius:10px; + -o-border-radius:10px; + -ms-border-radius:10px; + border-radius:10px; + padding:2px; + background:#e6e6e6 +} diff --git a/dropfile/src/main/resources/web/js/dropfile/less/dropfile.less b/dropfile/src/main/resources/web/js/dropupload/less/dropupload.less similarity index 88% rename from dropfile/src/main/resources/web/js/dropfile/less/dropfile.less rename to dropfile/src/main/resources/web/js/dropupload/less/dropupload.less index 8d836d9..b02e26a 100644 --- a/dropfile/src/main/resources/web/js/dropfile/less/dropfile.less +++ b/dropfile/src/main/resources/web/js/dropupload/less/dropupload.less @@ -1,6 +1,6 @@ @import "~./zul/less/_header.less"; -.z-dropfile { +.z-dropupload { .size(100px, 100px); .borderRadius(10px); padding: 2px; diff --git a/dropfile/src/main/resources/web/js/dropfile/mold/dropfile.js b/dropfile/src/main/resources/web/js/dropupload/mold/dropupload.js similarity index 100% rename from dropfile/src/main/resources/web/js/dropfile/mold/dropfile.js rename to dropfile/src/main/resources/web/js/dropupload/mold/dropupload.js diff --git a/dropfile/src/main/resources/web/js/dropupload/zk.wpd b/dropfile/src/main/resources/web/js/dropupload/zk.wpd new file mode 100644 index 0000000..e35102c --- /dev/null +++ b/dropfile/src/main/resources/web/js/dropupload/zk.wpd @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/common/EntityAttachmentEditorModel.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/common/EntityAttachmentEditorModel.java index 6147b5b..62ac12d 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/editor/common/EntityAttachmentEditorModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/common/EntityAttachmentEditorModel.java @@ -14,15 +14,18 @@ import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.ContextParam; import org.zkoss.bind.annotation.ContextType; +import org.zkoss.util.media.Media; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.UploadEvent; import org.zkoss.zk.ui.select.annotation.WireVariable; -import org.zkoss.zul.Messagebox; import org.zkoss.zul.Window; import java.io.Serializable; +import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.Objects; @Getter @Log4j2 @@ -49,17 +52,31 @@ public abstract class EntityAttachmentEditorModel extend @Command public void onUploadFile(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) { UploadEvent evt = (UploadEvent) ctx.getTriggerEvent(); - if (!evt.getMedia().getName().toLowerCase().endsWith(".pdf")) { - Messagebox.show("Csak PDF állomány feltöltése támogatott."); - return; +// if (!evt.getMedia().getName().toLowerCase().endsWith(".pdf")) { +// Messagebox.show("Csak PDF állomány feltöltése támogatott."); +// return; +// } + Media media = evt.getMedia(); + onFilesUploaded(Collections.singletonList(media)); + } + + @Command + public void doUploadFiles(@BindingParam("files") Media[] files) { + if (Objects.nonNull(files)) { + onFilesUploaded(Arrays.asList(files)); } - EDocument document = EDocument.builder() - .documentType(getDocumentType().getSimpleName()) - .file(evt.getMedia().getByteData()) - .size(evt.getMedia().getByteData().length) - .name(evt.getMedia().getName()) - .build(); - entityDocumentDataModel.addNew(document); + } + + private void onFilesUploaded(List media) { + media.forEach(m -> { + EDocument document = EDocument.builder() + .documentType(getDocumentType().getSimpleName()) + .file(m.getByteData()) + .size(m.getByteData().length) + .name(m.getName()) + .build(); + entityDocumentDataModel.addNew(document); + }); BindUtils.postNotifyChange(entityDocumentDataModel, "*"); validate(); } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java index d7b6658..d24589d 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java @@ -21,7 +21,6 @@ import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Destroy; import org.zkoss.bind.annotation.Init; import org.zkoss.lang.Strings; -import org.zkoss.util.media.Media; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.select.annotation.VariableResolver; @@ -240,14 +239,4 @@ public class IndexViewModel implements EventListener { }); } - - @Command - public void doUploadFiles(@BindingParam("files") Media[] files) { - if (Objects.nonNull(files)) { - for (Media file : files) { - log.info(file.getName()); - } - } - } - } diff --git a/lis-ui/src/main/resources/web/form/attachment-form.zul b/lis-ui/src/main/resources/web/form/attachment-form.zul index 7b50fcf..d560574 100644 --- a/lis-ui/src/main/resources/web/form/attachment-form.zul +++ b/lis-ui/src/main/resources/web/form/attachment-form.zul @@ -10,7 +10,8 @@ - @@ -27,8 +28,13 @@
-