From 8e309f728275cfdc5f36518b6a198e57e3090086 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1s=C3=A1ry=20D=C3=A1niel?= Date: Tue, 20 Feb 2024 18:15:04 +0100 Subject: [PATCH] Drop upload (not working) --- .../main/java/net/elgekko/zkoss/Dropfile.java | 268 +++++++ .../main/java/net/elgekko/zkoss/Version.java | 8 + .../src/main/java/org/example/Dropfile.java | 60 -- .../src/main/java/org/example/Version.java | 7 - .../main/resources/metainfo/zk/lang-addon.xml | 52 +- .../resources/web/js/dropfile/Dropfile.js | 748 +++++++++++++++--- .../web/js/dropfile/css/dropfile.css.dsp | 9 +- .../web/js/dropfile/less/dropfile.less | 8 + .../web/js/dropfile/mold/dropfile.js | 22 +- .../src/main/resources/web/js/dropfile/zk.wpd | 58 -- .../java/test/ctrl/DemoWindowComposer.java | 25 - dropfile/src/test/webapp/META-INF/MANIFEST.MF | 3 - dropfile/src/test/webapp/WEB-INF/web.xml | 53 -- dropfile/src/test/webapp/WEB-INF/zk.xml | 22 - dropfile/src/test/webapp/index.zul | 6 - dropfile/src/test/webapp/timeout.zul | 7 - .../user/lis/ui/config/WebSecurityConfig.java | 4 +- .../hu/user/lis/ui/view/IndexViewModel.java | 11 + .../hu/user/lis/ui/view/LoginViewModel.java | 1 + .../editor/import-invoice-approve-editor.zul | 12 +- .../editor/import-invoice-assign-editor.zul | 12 +- .../main/resources/web/form/invoice-form.zul | 6 +- lis-ui/src/main/resources/web/index.zul | 22 + lis-ui/src/main/resources/web/login.zul | 1 + 24 files changed, 1007 insertions(+), 418 deletions(-) create mode 100644 dropfile/src/main/java/net/elgekko/zkoss/Dropfile.java create mode 100644 dropfile/src/main/java/net/elgekko/zkoss/Version.java delete mode 100644 dropfile/src/main/java/org/example/Dropfile.java delete mode 100644 dropfile/src/main/java/org/example/Version.java create mode 100644 dropfile/src/main/resources/web/js/dropfile/less/dropfile.less delete mode 100644 dropfile/src/test/java/test/ctrl/DemoWindowComposer.java delete mode 100644 dropfile/src/test/webapp/META-INF/MANIFEST.MF delete mode 100644 dropfile/src/test/webapp/WEB-INF/web.xml delete mode 100644 dropfile/src/test/webapp/WEB-INF/zk.xml delete mode 100644 dropfile/src/test/webapp/index.zul delete mode 100644 dropfile/src/test/webapp/timeout.zul diff --git a/dropfile/src/main/java/net/elgekko/zkoss/Dropfile.java b/dropfile/src/main/java/net/elgekko/zkoss/Dropfile.java new file mode 100644 index 0000000..38271a3 --- /dev/null +++ b/dropfile/src/main/java/net/elgekko/zkoss/Dropfile.java @@ -0,0 +1,268 @@ +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/Version.java b/dropfile/src/main/java/net/elgekko/zkoss/Version.java new file mode 100644 index 0000000..ae13c65 --- /dev/null +++ b/dropfile/src/main/java/net/elgekko/zkoss/Version.java @@ -0,0 +1,8 @@ +package net.elgekko.zkoss; + +public class Version { + /** + * Returns the version UID. + */ + public static final String UID = "0.0.1-SNAPSHOT"; +} diff --git a/dropfile/src/main/java/org/example/Dropfile.java b/dropfile/src/main/java/org/example/Dropfile.java deleted file mode 100644 index c5882c6..0000000 --- a/dropfile/src/main/java/org/example/Dropfile.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.example; - -import org.zkoss.lang.Objects; -import org.zkoss.zk.au.AuRequest; -import org.zkoss.zk.ui.event.Event; -import org.zkoss.zk.ui.event.Events; -import org.zkoss.zul.impl.XulElement; - -import java.util.Map; - -public class Dropfile extends XulElement { - - static { - addClientEvent(Dropfile.class, "onFoo", 0); - } - - /* Here's a simple example for how to implements a member field */ - - private String _text; - - public String getText() { - return _text; - } - - public void setText(String text) { - if (!Objects.equals(_text, text)) { - _text = text; - smartUpdate("text", _text); - } - } - - - //super// - protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) - throws java.io.IOException { - super.renderProperties(renderer); - - render(renderer, "text", _text); - } - - public void service(AuRequest request, boolean everError) { - final String cmd = request.getCommand(); - final Map data = request.getData(); - - if (cmd.equals("onFoo")) { - final String foo = (String) data.get("foo"); - System.out.println("do onFoo, data:" + foo); - Events.postEvent(Event.getEvent(request)); - } else - super.service(request, everError); - } - - /** - * The default zclass is "z-dropfile" - */ - public String getZclass() { - return (this._zclass != null ? this._zclass : "z-dropfile"); - } -} - diff --git a/dropfile/src/main/java/org/example/Version.java b/dropfile/src/main/java/org/example/Version.java deleted file mode 100644 index 8414022..0000000 --- a/dropfile/src/main/java/org/example/Version.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.example; - -public class Version { - /** Returns the version UID. - */ - public static final String UID = "0.0.1-SNAPSHOT"; -} diff --git a/dropfile/src/main/resources/metainfo/zk/lang-addon.xml b/dropfile/src/main/resources/metainfo/zk/lang-addon.xml index d5f89ad..f901505 100644 --- a/dropfile/src/main/resources/metainfo/zk/lang-addon.xml +++ b/dropfile/src/main/resources/metainfo/zk/lang-addon.xml @@ -1,32 +1,32 @@ dropfile - - org.example.Version - 0.0.1-SNAPSHOT - 9.6.0 - - - xul/html - - dropfile - org.example.Dropfile - dropfile.Dropfile - - default - mold/dropfile.js + + net.elgekko.zkoss.Version + 0.0.1-SNAPSHOT + 9.6.0 + - + net.elgekko.zkoss.Dropfile + dropfile.Dropfile + + default + mold/dropfile.js - You could assign a .css file ,too. + - css/dropfile.css.dsp - - + You could assign a .css file ,too. + + The css.dsp is almost as same as CSS file , + but have more powerful enhancement. (like EL support.) + ==== + --> + css/dropfile.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 index 2616c23..9db4d89 100644 --- a/dropfile/src/main/resources/web/js/dropfile/Dropfile.js +++ b/dropfile/src/main/resources/web/js/dropfile/Dropfile.js @@ -1,105 +1,643 @@ -/** - * - * Base naming rule: - * The stuff start with "_" means private , end with "_" means protect , - * others mean public. - * - * All the member field should be private. - * - * Life cycle: (It's very important to know when we bind the event) - * A widget will do this by order : - * 1. $init - * 2. set attributes (setters) - * 3. rendering mold (@see mold/dropfile.js ) - * 4. call bind_ to bind the event to dom . - * - * this.deskop will be assigned after super bind_ is called, - * so we use it to determine whether we need to update view - * manually in setter or not. - * If this.desktop exist , means it's after mold rendering. - * - */ -dropfile.Dropfile = zk.$extends(zul.Widget, { - _text:'', //default value for text attribute - - /** - * Don't use array/object as a member field, it's a restriction for ZK object, - * it will work like a static , share with all the same Widget class instance. - * - * if you really need this , assign it in bind_ method to prevent any trouble. - * - * TODO:check array or object , must be one of them ...I forgot. -_- by Tony - */ - - $define: { - /** - * The member in $define means that it has its own setter/getter. - * (It's a coding sugar.) - * - * If you don't get this , - * you could see the comment below for another way to do this. - * - * It's more clear. - * - */ - text: function() { //this function will be called after setText() . - - if(this.desktop) { - //updated UI here. - } - } - }, - /** - * If you don't like the way in $define , - * you could do the setter/getter by yourself here. - * - * Like the example below, they are the same as we mentioned in $define section. - */ - /* - getText:function(){ return this._text; }, - setText:function(val){ - this._text = val; - if(this.desktop){ - //update the UI here. - } - }, - */ - bind_: function () { - /** - * For widget lifecycle , the super bind_ should be called - * as FIRST STATEMENT in the function. - * DONT'T forget to call supers in bind_ , or you will get error. - */ - this.$supers(dropfile.Dropfile,'bind_', arguments); - - //A example for domListen_ , REMEMBER to do domUnlisten in unbind_. - //this.domListen_(this.$n("cave"), "onClick", "_doItemsClick"); - }, - /* - A example for domListen_ listener. - */ - /* - _doItemsClick: function (evt) { - alert("item click event fired"); - }, - */ - unbind_: function () { - - // A example for domUnlisten_ , should be paired with bind_ - // this.domUnlisten_(this.$n("cave"), "onClick", "_doItemsClick"); - - /* - * For widget lifecycle , the super unbind_ should be called - * as LAST STATEMENT in the function. - */ - this.$supers(dropfile.Dropfile,'unbind_', arguments); - }, - /* - widget event, more detail - please refer to http://books.zkoss.org/wiki/ZK%20Client-side%20Reference/Notifications - */ - doClick_: function (evt) { - this.$super('doClick_', evt, true);//the super doClick_ should be called - this.fire('onFoo', {foo: 'myData'}); - } -}); \ No newline at end of file +(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 index ae850e9..c9895ac 100644 --- a/dropfile/src/main/resources/web/js/dropfile/css/dropfile.css.dsp +++ b/dropfile/src/main/resources/web/js/dropfile/css/dropfile.css.dsp @@ -1,8 +1 @@ -<%-- - Here you could do any styling job you want , all CSS stuff. ---%> -<%@ taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" %> - -.z-dropfile{ - color:black; -} \ No newline at end of file +<%@ 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/less/dropfile.less b/dropfile/src/main/resources/web/js/dropfile/less/dropfile.less new file mode 100644 index 0000000..8d836d9 --- /dev/null +++ b/dropfile/src/main/resources/web/js/dropfile/less/dropfile.less @@ -0,0 +1,8 @@ +@import "~./zul/less/_header.less"; + +.z-dropfile { + .size(100px, 100px); + .borderRadius(10px); + padding: 2px; + background: #E6E6E6; +} \ No newline at end of file diff --git a/dropfile/src/main/resources/web/js/dropfile/mold/dropfile.js b/dropfile/src/main/resources/web/js/dropfile/mold/dropfile.js index 42e8584..27f13f8 100644 --- a/dropfile/src/main/resources/web/js/dropfile/mold/dropfile.js +++ b/dropfile/src/main/resources/web/js/dropfile/mold/dropfile.js @@ -1,21 +1 @@ -/** -* Here's the mold file , a mold means a HTML struct that the widget really presented. -* yep, we build html in Javascript , that make it more clear and powerful. -*/ -function (out) { - - //Here you call the "this" means the widget instance. (@see Dropfile.js) - - var zcls = this.getZclass(), - uuid = this.uuid; - - //The this.domAttrs_() means it will prepare some dom attributes, - //like the pseudo code below - /* - class="${zcls} ${this.getSclass()}" id="${uuid}" - */ - out.push(''); - out.push(this._text); - out.push(''); - -} \ No newline at end of file +function(a){a.push("",this.domContent_(),"")}; \ 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 index 05ee18f..75a5316 100644 --- a/dropfile/src/main/resources/web/js/dropfile/zk.wpd +++ b/dropfile/src/main/resources/web/js/dropfile/zk.wpd @@ -1,62 +1,4 @@ - - - - - \ No newline at end of file diff --git a/dropfile/src/test/java/test/ctrl/DemoWindowComposer.java b/dropfile/src/test/java/test/ctrl/DemoWindowComposer.java deleted file mode 100644 index 63136b6..0000000 --- a/dropfile/src/test/java/test/ctrl/DemoWindowComposer.java +++ /dev/null @@ -1,25 +0,0 @@ -package test.ctrl; - -import org.example.Dropfile; - -import org.zkoss.zk.ui.Component; -import org.zkoss.zk.ui.event.Event; -import org.zkoss.zk.ui.event.ForwardEvent; -import org.zkoss.zk.ui.select.SelectorComposer; -import org.zkoss.zk.ui.select.annotation.Wire; - -public class DemoWindowComposer extends SelectorComposer { - - @Wire - private Dropfile myComp; - - public void doAfterCompose(Component comp) throws Exception { - super.doAfterCompose(comp); - myComp.setText("Hello ZK Component!! Please click me."); - } - - public void onFoo$myComp (ForwardEvent event) { - Event mouseEvent = (Event) event.getOrigin(); - alert("You listen onFoo: " + mouseEvent.getTarget()); - } -} \ No newline at end of file diff --git a/dropfile/src/test/webapp/META-INF/MANIFEST.MF b/dropfile/src/test/webapp/META-INF/MANIFEST.MF deleted file mode 100644 index 254272e..0000000 --- a/dropfile/src/test/webapp/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Class-Path: - diff --git a/dropfile/src/test/webapp/WEB-INF/web.xml b/dropfile/src/test/webapp/WEB-INF/web.xml deleted file mode 100644 index 826f642..0000000 --- a/dropfile/src/test/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - dropfiledemo - - Used to cleanup when a session is destroyed - ZK Session cleaner - org.zkoss.zk.ui.http.HttpSessionListener - - - The ZK loader for ZUML pages - zkLoader - org.zkoss.zk.ui.http.DHtmlLayoutServlet - - update-uri - /zkau - - 1 - - - The asynchronous update engine for ZK - auEngine - org.zkoss.zk.au.http.DHtmlUpdateServlet - - - zkLoader - *.zul - - - zkLoader - *.zhtml - - - auEngine - /zkau/* - - - dspLoader - org.zkoss.web.servlet.dsp.InterpreterServlet - - - dspLoader - *.dsp - - - index.html - index.htm - index.jsp - default.html - default.htm - default.jsp - index.zul - - \ No newline at end of file diff --git a/dropfile/src/test/webapp/WEB-INF/zk.xml b/dropfile/src/test/webapp/WEB-INF/zk.xml deleted file mode 100644 index b3ba275..0000000 --- a/dropfile/src/test/webapp/WEB-INF/zk.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - true - - - ajax - /timeout.zul - - - org.zkoss.zk.WPD.cache - false - - - org.zkoss.zk.WCS.cache - false - - diff --git a/dropfile/src/test/webapp/index.zul b/dropfile/src/test/webapp/index.zul deleted file mode 100644 index ec0ad7b..0000000 --- a/dropfile/src/test/webapp/index.zul +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/dropfile/src/test/webapp/timeout.zul b/dropfile/src/test/webapp/timeout.zul deleted file mode 100644 index 1516297..0000000 --- a/dropfile/src/test/webapp/timeout.zul +++ /dev/null @@ -1,7 +0,0 @@ - - -The page or component you request is no longer available. -This is normally caused by timeout, opening too many Web pages, or rebooting -the server. - - \ No newline at end of file diff --git a/lis-ui/src/main/java/hu/user/lis/ui/config/WebSecurityConfig.java b/lis-ui/src/main/java/hu/user/lis/ui/config/WebSecurityConfig.java index 27916b9..7b3f801 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/config/WebSecurityConfig.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/config/WebSecurityConfig.java @@ -22,7 +22,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { public static final String REMOVE_DESKTOP_REGEX = "/zkau\\?dtid=.*&cmd_0=rmDesktop&.*"; - public static final String[] ZK_RESOURCES = {"/zkau/web/**/js/**", "/zkau/web/**/zul/css/**", "/zkau/web/**/img/**", "/zkau/web/**/static/**"}; + public static final String[] ZK_RESOURCES = {"/zkau/web/**/js/**", "/zkau/web/**/zul/css/**", "/zkau/web/**/zul/less/**", "/zkau/web/**/img/**", "/zkau/web/**/static/**"}; @Autowired LocalAuthProvider localAuthProvider; @@ -37,7 +37,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { http.authorizeRequests() .antMatchers(ZUL_FILES).denyAll() // block direct access to zul files .antMatchers(HttpMethod.GET, ZK_RESOURCES).permitAll() // allow zk resources - .antMatchers(HttpMethod.POST, "/zkau/upload/**").permitAll() // allow zk resources + .antMatchers(HttpMethod.POST, "/zkau/upload/**", "/zkau/dropupload/**").permitAll() // allow zk resources .regexMatchers(HttpMethod.GET, REMOVE_DESKTOP_REGEX).permitAll() // allow desktop cleanup .requestMatchers(req -> "rmDesktop".equals(req.getParameter("cmd_0"))).permitAll() // allow desktop cleanup from ZATS .mvcMatchers(Constants.NAV_ROOT, Constants.NAV_LOGIN, Constants.NAV_LOGOUT, Constants.NAV_API + "/**").permitAll() 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 5a6228a..d7b6658 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,6 +21,7 @@ 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; @@ -237,6 +238,16 @@ public class IndexViewModel implements EventListener { Editors.doShowEdit(Editors.POPUP_EDITOR, arg, modifiedEntity -> { }); + } + + @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/java/hu/user/lis/ui/view/LoginViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/LoginViewModel.java index c57966f..9c75c76 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/LoginViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/LoginViewModel.java @@ -44,4 +44,5 @@ public class LoginViewModel { message = Strings.EMPTY; } } + } diff --git a/lis-ui/src/main/resources/web/editor/import-invoice-approve-editor.zul b/lis-ui/src/main/resources/web/editor/import-invoice-approve-editor.zul index b785be5..a40ddfe 100644 --- a/lis-ui/src/main/resources/web/editor/import-invoice-approve-editor.zul +++ b/lis-ui/src/main/resources/web/editor/import-invoice-approve-editor.zul @@ -51,21 +51,21 @@ diff --git a/lis-ui/src/main/resources/web/index.zul b/lis-ui/src/main/resources/web/index.zul index 8ec3888..28abbca 100644 --- a/lis-ui/src/main/resources/web/index.zul +++ b/lis-ui/src/main/resources/web/index.zul @@ -66,6 +66,28 @@ + + + + + Drop Here
+ size < 5MB + ]]> +
+
+
+ diff --git a/lis-ui/src/main/resources/web/login.zul b/lis-ui/src/main/resources/web/login.zul index 65e7f3d..7d84377 100644 --- a/lis-ui/src/main/resources/web/login.zul +++ b/lis-ui/src/main/resources/web/login.zul @@ -65,6 +65,7 @@ + \ No newline at end of file -- 2.54.0