IDEMPIERE-1635 Upgrade to zk7. Upgrade to Zk 7.0.1
This commit is contained in:
parent
ecefaaa6e7
commit
a1bb9643c5
|
@ -1,4 +1,17 @@
|
|||
/* util.js
|
||||
|
||||
Purpose:
|
||||
|
||||
Description:
|
||||
|
||||
History:
|
||||
Tue Sep 30 09:02:06 2008, Created by tomyeh
|
||||
|
||||
Copyright (C) 2008 Potix Corporation. All Rights Reserved.
|
||||
|
||||
This program is distributed under LGPL Version 2.1 in the hope that
|
||||
it will be useful, but WITHOUT ANY WARRANTY.
|
||||
*/
|
||||
(function () {
|
||||
var _decs = {lt: '<', gt: '>', amp: '&', quot: '"'},
|
||||
_encs = {};
|
||||
|
@ -19,7 +32,11 @@
|
|||
for (var fs = w.frames, j = 0, l = fs.length; j < l; ++j)
|
||||
_frames(ary, fs[j]);
|
||||
}
|
||||
|
||||
/* Returns the onSize target of the given widget.
|
||||
* The following code is dirty since it checks _hflexsz (which is implementation)
|
||||
* FUTRE: consider to have zk.Widget.beforeSize to clean up _hflexsz and
|
||||
* this method considers only if _hflex is min
|
||||
*/
|
||||
function _onSizeTarget(wgt) {
|
||||
var r1 = wgt, p1 = r1,
|
||||
j1 = -1;
|
||||
|
@ -27,7 +44,7 @@
|
|||
delete p1._hflexsz;
|
||||
r1 = p1;
|
||||
++j1;
|
||||
if (p1.ignoreFlexSize_('w'))
|
||||
if (p1.ignoreFlexSize_('w')) //p1 will not affect its parent's flex size
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -37,16 +54,60 @@
|
|||
delete p2._vflexsz;
|
||||
r2 = p2;
|
||||
++j2;
|
||||
if (p2.ignoreFlexSize_('h'))
|
||||
if (p2.ignoreFlexSize_('h')) //p2 will not affect its parent's flex size
|
||||
break;
|
||||
}
|
||||
return j1 > 0 || j2 > 0 ? j1 > j2 ? r1 : r2: wgt;
|
||||
}
|
||||
|
||||
|
||||
zUtl = {
|
||||
|
||||
|
||||
/** @class zUtl
|
||||
* @import zk.Widget
|
||||
* @import zk.xml.Utl
|
||||
* The basic utilties.
|
||||
* <p>For more utilities, refer to {@link Utl}.
|
||||
*/
|
||||
zUtl = { //static methods
|
||||
//Character
|
||||
/**
|
||||
* Returns whether the character is according to its opts.
|
||||
* @param char cc the character
|
||||
* @param Map opts the options.
|
||||
<table border="1" cellspacing="0" width="100%">
|
||||
<caption> Allowed Options
|
||||
</caption>
|
||||
<tr>
|
||||
<th> Name
|
||||
</th><th> Allowed Values
|
||||
</th><th> Description
|
||||
</th></tr>
|
||||
<tr>
|
||||
<td> digit
|
||||
</td><td> true, false
|
||||
</td><td> Specifies the character is digit only.
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td> upper
|
||||
</td><td> true, false
|
||||
</td><td> Specifies the character is upper case only.
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td> lower
|
||||
</td><td> true, false
|
||||
</td><td> Specifies the character is lower case only.
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td> whitespace
|
||||
</td><td> true, false
|
||||
</td><td> Specifies the character is whitespace only.
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td> opts[cc]
|
||||
</td><td> true, false
|
||||
</td><td> Specifies the character is allowed only.
|
||||
</td></tr>
|
||||
</table>
|
||||
* @return boolean
|
||||
*/
|
||||
isChar: function (cc, opts) {
|
||||
return (opts.digit && cc >= '0' && cc <= '9')
|
||||
|| (opts.upper && cc >= 'A' && cc <= 'Z')
|
||||
|
@ -55,8 +116,19 @@ zUtl = {
|
|||
|| opts[cc];
|
||||
},
|
||||
|
||||
|
||||
|
||||
//HTML/XML
|
||||
/** Parses the specifie text into a map.
|
||||
* For example
|
||||
*<pre><code>
|
||||
zUtl.parseMap("a=b,c=d");
|
||||
zUtl.parseMap("a='b c',c=de", ',', "'\"");
|
||||
</code></pre>
|
||||
* @param String text the text to parse
|
||||
* @param String separator the separator. If omitted, <code>','</code>
|
||||
* is assumed
|
||||
* @param String quote the quote to handle. Ignored if omitted.
|
||||
* @return Map the map
|
||||
*/
|
||||
parseMap: function (text, separator, quote) {
|
||||
var map = {};
|
||||
if (text) {
|
||||
|
@ -85,7 +157,17 @@ zUtl = {
|
|||
return map;
|
||||
},
|
||||
|
||||
|
||||
/** Encodes the string to a valid XML string.
|
||||
* Refer to {@link Utl} for more XML utilities.
|
||||
* @param String txt the text to encode
|
||||
* @param Map opts [optional] the options. Allowd value:
|
||||
* <ul>
|
||||
* <li>pre - whether to replace whitespace with &nbsp;</li>
|
||||
* <li>multiline - whether to replace linefeed with <br/></li>
|
||||
* <li>maxlength - the maximal allowed length of the text</li>
|
||||
* </ul>
|
||||
* @return String the encoded text.
|
||||
*/
|
||||
encodeXML: function (txt, opts) {
|
||||
txt = txt != null ? String(txt):'';
|
||||
var tl = txt.length,
|
||||
|
@ -97,7 +179,7 @@ zUtl = {
|
|||
var j = maxlength;
|
||||
while (j > 0 && txt.charAt(j - 1) == ' ')
|
||||
--j;
|
||||
opts.maxlength = 0;
|
||||
opts.maxlength = 0; //no limit
|
||||
return zUtl.encodeXML(txt.substring(0, j) + '...', opts);
|
||||
}
|
||||
|
||||
|
@ -130,7 +212,11 @@ zUtl = {
|
|||
out.push(txt.substring(k));
|
||||
return out.join('');
|
||||
},
|
||||
|
||||
/** Decodes the XML string into a normal string.
|
||||
* For example, &lt; is convert to <
|
||||
* @param String txt the text to decode
|
||||
* @return String the decoded string
|
||||
*/
|
||||
decodeXML: function (txt) {
|
||||
var out = '';
|
||||
if (!txt) return out;
|
||||
|
@ -157,17 +243,39 @@ zUtl = {
|
|||
k < tl ? out + txt.substring(k): out;
|
||||
},
|
||||
|
||||
|
||||
/** A shortcut of <code>' cellpadding="0" cellspacing="0" border="0"'</code>.
|
||||
* @type String
|
||||
*/
|
||||
cellps0: ' cellpadding="0" cellspacing="0" border="0"',
|
||||
|
||||
/** A shortcut of <code>'<img style="height:0;width:0"/>'</code>.
|
||||
* @type String
|
||||
*/
|
||||
img0: '<img style="height:0;width:0"/>',
|
||||
|
||||
/** A shortcut of <code>'<i style="height:0;width:0"/>'</code>.
|
||||
* @type String
|
||||
*/
|
||||
i0: '<i style="height:0;width:0"/>',
|
||||
|
||||
|
||||
/** Returns a long value representing the current time (unit: miliseconds).
|
||||
* @return long
|
||||
* @deprecated As of release 5.0.6, replaced with jq.now().
|
||||
*/
|
||||
now: jq.now,
|
||||
|
||||
|
||||
/** Returns today.
|
||||
* @param boolean full if true, returns the full time,
|
||||
* else only returns year, month, and day.
|
||||
* If omitted, false is assumed
|
||||
* @return Date
|
||||
*/
|
||||
/** Returns today.
|
||||
* @param String fmt the time format, such as HH:mm:ss.SSS
|
||||
* If a time element such as seconds not specified in the format, it will
|
||||
* be considered as 0. For example, if the format is "HH:mm", then
|
||||
* the returned object will be today, this hour and this minute, but
|
||||
* the second and milliseconds will be zero.
|
||||
* @return Date
|
||||
* @since 5.0.6
|
||||
*/
|
||||
today: function (fmt) {
|
||||
var d = new Date(), hr = 0, min = 0, sec = 0, msec = 0;
|
||||
if (typeof fmt == 'string') {
|
||||
|
@ -182,7 +290,20 @@ zUtl = {
|
|||
hr, min, sec, msec);
|
||||
},
|
||||
|
||||
|
||||
/** Returns if one is ancestor of the other.
|
||||
* It assumes the object has either a method called <code>getParent</code>
|
||||
* or a field called <code>parent</code>.
|
||||
* A typical example is used to test the widgets ({@link Widget}).
|
||||
*
|
||||
* <p>Notice that, if you want to test DOM elements, please use
|
||||
* {@link jq#isAncestor} instead.
|
||||
*
|
||||
* @param Object p the parent. This method return true if p is null
|
||||
or p is the same as c
|
||||
* @param Object c the child
|
||||
* @return boolean
|
||||
* @see jq#isAncestor
|
||||
*/
|
||||
isAncestor: function (p, c) {
|
||||
if (!p) return true;
|
||||
for (; c; c = c.getParent ? c.getParent(): c.parent)
|
||||
|
@ -191,8 +312,16 @@ zUtl = {
|
|||
return false;
|
||||
},
|
||||
|
||||
|
||||
|
||||
//progress//
|
||||
/** Creates a message box to indicate something is being processed
|
||||
* @param String id the ID of the DOM element being created
|
||||
* @param String msg the message to shown
|
||||
* @param boolean mask whether to show sem-transparent mask to prevent
|
||||
* the user from accessing it.
|
||||
* @param String icon the CSS class used to shown an icon in the box.
|
||||
* Ignored if not specified.
|
||||
* @see #destroyProgressbox
|
||||
*/
|
||||
progressbox: function (id, msg, mask, icon, _opts) {
|
||||
if (mask && zk.Page.contained.length) {
|
||||
for (var c = zk.Page.contained.length, e = zk.Page.contained[--c]; e; e = zk.Page.contained[--c]) {
|
||||
|
@ -208,7 +337,7 @@ zUtl = {
|
|||
|
||||
if (_opts && _opts.busy) {
|
||||
zk.busy++;
|
||||
jq.focusOut();
|
||||
jq.focusOut(); //Bug 2912533
|
||||
}
|
||||
|
||||
var x = jq.innerX(), y = jq.innerY(),
|
||||
|
@ -241,7 +370,7 @@ zUtl = {
|
|||
});
|
||||
}
|
||||
|
||||
if (mask && $txt.length) {
|
||||
if (mask && $txt.length) { //center
|
||||
st.left = jq.px((jq.innerWidth() - txt.offsetWidth) / 2 + x);
|
||||
st.top = jq.px((jq.innerHeight() - txt.offsetHeight) / 2 + y);
|
||||
} else {
|
||||
|
@ -279,7 +408,9 @@ zUtl = {
|
|||
|
||||
$n.zk.cleanVisibility();
|
||||
},
|
||||
|
||||
/** Removes the message box created by {@link #progressbox}.
|
||||
* @param String id the ID of the DOM element of the message box
|
||||
*/
|
||||
destroyProgressbox: function (id, _opts) {
|
||||
if (_opts && _opts.busy && --zk.busy < 0)
|
||||
zk.busy = 0;
|
||||
|
@ -296,8 +427,19 @@ zUtl = {
|
|||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
//HTTP//
|
||||
/** Navigates to the specified URL.
|
||||
* @param String url the URL to go to
|
||||
* @param Map opts [optional] the options. Allowed values:
|
||||
* <ul>
|
||||
* <li>target - the name of the target browser window. The same browswer
|
||||
* window is assumed if omitted. You can use any value allowed in
|
||||
* the target attribute of the HTML FORM tag, such as _self, _blank,
|
||||
* _parent and _top.</li>
|
||||
* <li>overwrite - whether load a new page in the current browser window.
|
||||
* If true, the new page replaces the previous page's position in the history list.</li>
|
||||
* </ul>
|
||||
*/
|
||||
go: function (url, opts) {
|
||||
opts = opts || {};
|
||||
if (opts.target) {
|
||||
|
@ -309,7 +451,7 @@ zUtl = {
|
|||
location.href = url;
|
||||
|
||||
var j = url.indexOf('#');
|
||||
|
||||
//bug 3363687, only if '#" exist, has to reload()
|
||||
if(j < 0)
|
||||
return;
|
||||
|
||||
|
@ -320,20 +462,32 @@ zUtl = {
|
|||
if (j >= 0) pn = pn.substring(0, j);
|
||||
if (pn != un)
|
||||
return;
|
||||
|
||||
//fall thru (bug 2882149)
|
||||
}
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/** Returns all descendant frames of the given window.
|
||||
* <p>To retrieve all, invoke <code>zUtl.frames(top)</code>.
|
||||
* Notice: w is included in the returned array.
|
||||
* If you want to exclude it, invoke <code>zUtl.frames(w).$remove(w)</code>.
|
||||
* @param Window w the browser window
|
||||
* @return Array
|
||||
* @since 5.0.4
|
||||
*/
|
||||
frames: function (w) {
|
||||
var ary = [];
|
||||
_frames(ary, w);
|
||||
return ary;
|
||||
},
|
||||
|
||||
|
||||
/** Converts an integer array to a string (separated by comma).
|
||||
* @param int[] ary the integer array to convert.
|
||||
* If null, an empty string is returned.
|
||||
* @return String
|
||||
* @see #stringToInts
|
||||
*/
|
||||
intsToString: function (ary) {
|
||||
if (!ary) return '';
|
||||
|
||||
|
@ -342,7 +496,14 @@ zUtl = {
|
|||
sb.push(ary[j]);
|
||||
return sb.join();
|
||||
},
|
||||
|
||||
/** Converts a string separated by comma to an array of integers.
|
||||
* @see #intsToString
|
||||
* @param String text the string to convert.
|
||||
* If null, null is returned.
|
||||
* @param int defaultValue the default value used if the value
|
||||
* is not specified. For example, zUtl.stringToInts("1,,3", 2) returns [1, 2, 3].
|
||||
* @return int[]
|
||||
*/
|
||||
stringToInts: function (text, defaultValue) {
|
||||
if (text == null)
|
||||
return null;
|
||||
|
@ -362,7 +523,13 @@ zUtl = {
|
|||
}
|
||||
return list;
|
||||
},
|
||||
|
||||
/** Converts a map to a string
|
||||
* @see #intsToString
|
||||
* @param Map map the map to convert
|
||||
* @param String assign the symbol for assignment. If omitted, '=' is assumed.
|
||||
* @param String separator the symbol for separator. If omitted, ',' is assumed.
|
||||
* @return String
|
||||
*/
|
||||
mapToString: function (map, assign, separator) {
|
||||
assign = assign || '=';
|
||||
separator = separator || ' ';
|
||||
|
@ -372,12 +539,38 @@ zUtl = {
|
|||
out[0] = '';
|
||||
return out.join('');
|
||||
},
|
||||
|
||||
|
||||
/** Appends an attribute.
|
||||
* Notice that the attribute won't be appended if val is empty or false.
|
||||
* In other words, it is equivalent to<br/>
|
||||
* <code>val ? ' ' + nm + '="' + val + '"': ""</code>.
|
||||
* <p>If you want to generate the attribute no matter what val is, use
|
||||
* {@link #appendAttr(String, Object, boolean)}.
|
||||
* @param String nm the name of the attribute
|
||||
* @param Object val the value of the attribute
|
||||
* @since 5.0.3
|
||||
*/
|
||||
/** Appends an attribute.
|
||||
* Notice that the attribute won't be appended.
|
||||
* @param String nm the name of the attribute
|
||||
* @param Object val the value of the attribute
|
||||
* @param boolean force whether to append attribute no matter what value it is.
|
||||
* If false (or omitted), it is the same as {@link #appendAttr(String, Object)}.
|
||||
* @since 5.0.3
|
||||
*/
|
||||
appendAttr: function (nm, val, force) {
|
||||
return val || force ? ' ' + nm + '="' + val + '"': '';
|
||||
},
|
||||
|
||||
/** Fires beforeSize, onFitSize and onSize
|
||||
* @param Widget wgt the widget which the zWatch event will be fired against.
|
||||
* @param int bfsz the beforeSize mode:
|
||||
* <ul>
|
||||
* <li>0 (null/undefined/false): beforeSize sent normally.</li>
|
||||
* <li>-1: beforeSize won't be sent.</li>
|
||||
* <li>1: beforeSize will be sent with an additional cleanup option,
|
||||
* which will clean up the cached minimal size (if flex=min).</li>
|
||||
* </ul>
|
||||
* @since 5.0.8
|
||||
*/
|
||||
fireSized: function (wgt, bfsz) {
|
||||
if (zUtl.isImageLoading() || zk.clientinfo) {
|
||||
var f = arguments.callee;
|
||||
|
@ -387,24 +580,42 @@ zUtl = {
|
|||
return;
|
||||
}
|
||||
wgt = _onSizeTarget(wgt);
|
||||
if (!(bfsz < 0))
|
||||
if (!(bfsz < 0)) //don't use >= (because bfsz might be undefined)
|
||||
zWatch.fireDown('beforeSize', wgt, null, bfsz > 0);
|
||||
zWatch.fireDown('onFitSize', wgt, {reverse: true});
|
||||
zWatch.fireDown('onSize', wgt);
|
||||
},
|
||||
|
||||
/** Fires onBeforeSize, onShow, onFitSize, and onSize
|
||||
* @param Widget wgt the widget which the zWatch event will be fired against.
|
||||
* @param int bfsz the beforeSize mode:
|
||||
* <ul>
|
||||
* <li>0 (null/undefined/false): beforeSize sent normally.</li>
|
||||
* <li>-1: beforeSize won't be sent.</li>
|
||||
* <li>1: beforeSize will be sent with an additional cleanup option,
|
||||
* which will clean up the cached minimal size (if flex=min).</li>
|
||||
* </ul>
|
||||
* @since 5.0.8
|
||||
*/
|
||||
fireShown: function (wgt, bfsz) {
|
||||
zWatch.fireDown('onShow', wgt);
|
||||
zUtl.fireSized(wgt, bfsz);
|
||||
},
|
||||
|
||||
/**
|
||||
* Loads an image before ZK client engine to calculate the widget's layout.
|
||||
* @param String url the loading image's localation
|
||||
* @since 6.0.0
|
||||
*/
|
||||
loadImage: function (url) {
|
||||
if (!_imgMap[url]) {
|
||||
_imgMap[url] = true;
|
||||
_loadImage(url);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether all the loading images are finish.
|
||||
* @see #loadImage
|
||||
* @since 6.0.0
|
||||
*/
|
||||
isImageLoading: function () {
|
||||
for (var url in _imgObjectMap) {
|
||||
var img = _imgObjectMap[url];
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,514 +0,0 @@
|
|||
|
||||
(function () {
|
||||
|
||||
function _cancel(o, sid, finish) {
|
||||
var key = o.getKey(sid),
|
||||
uplder = o.uploaders[key];
|
||||
if (uplder)
|
||||
uplder.destroy(finish);
|
||||
delete o.uploaders[key];
|
||||
}
|
||||
function _initUploader(o, form, val) {
|
||||
var key = o.getKey(o.sid),
|
||||
uplder = new zul.Uploader(o, key, form, val);
|
||||
zul.Upload.start(uplder);
|
||||
o.uploaders[key] = uplder;
|
||||
}
|
||||
function _start(o, form, val) {
|
||||
|
||||
|
||||
_initUploader(o, form, val);
|
||||
o.sid++;
|
||||
o.initContent();
|
||||
}
|
||||
function _onchange(evt) {
|
||||
var n = this,
|
||||
upload = n._ctrl,
|
||||
wgt = upload._wgt,
|
||||
dt = wgt.desktop,
|
||||
action = zk.ajaxURI('/upload', {desktop:dt,au:true}) + '?uuid=' + wgt.uuid + '&dtid=' + dt.id + '&sid=' + upload.sid
|
||||
+ (upload.maxsize !== '' ? '&maxsize=' + upload.maxsize : '')
|
||||
+ (upload.isNative ? '&native=true' : ''),
|
||||
form = n.form;
|
||||
form.action = action;
|
||||
|
||||
|
||||
var p = form.parentNode;
|
||||
p.parentNode.removeChild(p);
|
||||
upload._formDetached = true;
|
||||
var fileName = !n.files || n.files.length == 1 ? n.value : (function(files){
|
||||
var fns = [];
|
||||
for (var len = files.length; len--;)
|
||||
fns.unshift(files[len].name);
|
||||
return fns.join(",");
|
||||
})(n.files);
|
||||
_start(n._ctrl, form, fileName);
|
||||
}
|
||||
|
||||
if (zk.opera) {
|
||||
var _syncQue = [], _syncId;
|
||||
function _syncNow() {
|
||||
for (var j = _syncQue.length; j--;)
|
||||
_syncQue[j].sync();
|
||||
}
|
||||
function _addSyncQue(upld) {
|
||||
if (!_syncQue.length)
|
||||
_syncId = setInterval(_syncNow, 1500);
|
||||
|
||||
_syncQue.push(upld);
|
||||
}
|
||||
function _rmSyncQue(upld) {
|
||||
_syncQue.$remove(upld);
|
||||
if (_syncId && !_syncQue.length) {
|
||||
clearInterval(_syncId);
|
||||
_syncId = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
zul.Upload = zk.$extends(zk.Object, {
|
||||
sid: 0,
|
||||
|
||||
$init: function(wgt, parent, clsnm) {
|
||||
this.uploaders = {};
|
||||
|
||||
var cls;
|
||||
for (var attrs = clsnm.split(','), i = 0, len = attrs.length; i < len; i++) {
|
||||
var attr = attrs[i].trim();
|
||||
if (attr.startsWith('maxsize='))
|
||||
this.maxsize = attr.match(new RegExp(/maxsize=([^,]*)/))[1];
|
||||
else if (attr.startsWith('multiple='))
|
||||
this.multiple = attr.match(new RegExp(/multiple=([^,]*)/))[1];
|
||||
else if (attr.startsWith('accept='))
|
||||
this.accept = attr.match(new RegExp(/accept=([^,]*)/))[1];
|
||||
else if (attr == 'native')
|
||||
this.isNative = true;
|
||||
else if (attr != 'true')
|
||||
cls = attr;
|
||||
}
|
||||
|
||||
this._clsnm = cls || '';
|
||||
|
||||
this._wgt = wgt;
|
||||
this._parent = parent;
|
||||
if (wgt._tooltiptext)
|
||||
this._tooltiptext = wgt._tooltiptext;
|
||||
|
||||
this.initContent();
|
||||
},
|
||||
|
||||
sync: function () {
|
||||
if (!this._formDetached) {
|
||||
var wgt = this._wgt,
|
||||
ref = wgt.$n(),
|
||||
parent = this._parent,
|
||||
outer = parent ? parent.lastChild : ref.nextSibling,
|
||||
inp = outer.firstChild.firstChild,
|
||||
refof = zk(ref).revisedOffset(),
|
||||
outerof = jq(outer).css({top: '0', left: '0'}).zk.revisedOffset(),
|
||||
diff = inp.offsetWidth - ref.offsetWidth,
|
||||
st = outer.style;
|
||||
st.top = (refof[1] - outerof[1]) + "px";
|
||||
st.left = refof[0] - outerof[0] - diff + "px";
|
||||
|
||||
inp.style.height = ref.offsetHeight + 'px';
|
||||
inp.style.clip = 'rect(auto,auto,auto,' + diff + 'px)';
|
||||
}
|
||||
},
|
||||
initContent: function () {
|
||||
var wgt = this._wgt,
|
||||
parent = this._parent,
|
||||
ref = wgt.$n(), dt = wgt.desktop,
|
||||
html = '<span class="z-upload"'
|
||||
+ (this._tooltiptext? ' title="'+ this._tooltiptext+'"' : '')
|
||||
+'><form enctype="multipart/form-data" method="POST">'
|
||||
+ '<input name="file" type="file"'
|
||||
|
||||
+ (this.multiple == 'true' ? ' multiple="" multiple' : '')
|
||||
+ (this.accept ? ' accept="' + this.accept + '"' : '')
|
||||
+ ' hidefocus="true" style="height:'
|
||||
+ ref.offsetHeight + 'px"/></form></span>';
|
||||
|
||||
if (parent)
|
||||
jq(parent).append(html);
|
||||
else
|
||||
jq(wgt).after(html);
|
||||
delete this._formDetached;
|
||||
|
||||
|
||||
if (!wgt._autodisable_self)
|
||||
this.sync();
|
||||
|
||||
var outer = this._outer = parent ? parent.lastChild : ref.nextSibling,
|
||||
inp = outer.firstChild.firstChild;
|
||||
|
||||
if (zk.opera) {
|
||||
outer.style.position = 'absolute';
|
||||
_addSyncQue(this);
|
||||
}
|
||||
|
||||
inp.z$proxy = ref;
|
||||
inp._ctrl = this;
|
||||
|
||||
jq(inp).change(_onchange);
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
if (zk.opera)
|
||||
_rmSyncQue(this);
|
||||
|
||||
jq(this._outer).remove();
|
||||
this._wgt = this._parent = null;
|
||||
for (var v in this.uploaders) {
|
||||
var uplder = this.uploaders[v];
|
||||
if (uplder) {
|
||||
delete this.uploaders[v];
|
||||
uplder.destroy();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
getKey: function (sid) {
|
||||
return (this._wgt ? this._wgt.uuid : '' )+ '_uplder_' + sid;
|
||||
},
|
||||
|
||||
cancel: function (sid) {
|
||||
_cancel(this, sid);
|
||||
},
|
||||
|
||||
finish: function (sid) {
|
||||
_cancel(this, sid, true);
|
||||
}
|
||||
},{
|
||||
|
||||
error: function (msg, uuid, sid) {
|
||||
var wgt = zk.Widget.$(uuid);
|
||||
if (wgt) {
|
||||
jq.alert(msg, {desktop: wgt.desktop, icon: 'ERROR'});
|
||||
zul.Upload.close(uuid, sid);
|
||||
}
|
||||
},
|
||||
|
||||
close: function (uuid, sid) {
|
||||
var wgt = zk.Widget.$(uuid);
|
||||
if (!wgt || !wgt._uplder) return;
|
||||
wgt._uplder.cancel(sid);
|
||||
},
|
||||
|
||||
sendResult: function (uuid, contentId, sid) {
|
||||
var wgt = zk.Widget.$(uuid);
|
||||
if (!wgt || !wgt._uplder) return;
|
||||
wgt._uplder.finish(sid);
|
||||
zAu.send(new zk.Event(wgt.desktop, "updateResult", {
|
||||
contentId: contentId,
|
||||
wid: wgt.uuid,
|
||||
sid: sid
|
||||
}));
|
||||
},
|
||||
|
||||
isFinish: function (wgt) {
|
||||
for (var key = (typeof wgt == 'string' ? wgt : wgt.uuid) + '_uplder_',
|
||||
f = zul.Upload.files, i = f.length; i--;)
|
||||
if (f[0].id.startsWith(key))
|
||||
return false;
|
||||
return true;
|
||||
},
|
||||
|
||||
start: function (uplder) {
|
||||
var files = zul.Upload.files;
|
||||
if (uplder)
|
||||
files.push(uplder);
|
||||
if (files[0] && !files[0].isStart) {
|
||||
files[0].isStart = true;
|
||||
files[0].start();
|
||||
}
|
||||
},
|
||||
|
||||
destroy: function (uplder) {
|
||||
for (var files = zul.Upload.files, i = files.length; i--;)
|
||||
if (files[i].id == uplder.id) {
|
||||
files.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
zul.Upload.start();
|
||||
},
|
||||
files: []
|
||||
});
|
||||
|
||||
zul.Uploader = zk.$extends(zk.Object, {
|
||||
|
||||
$init: function (upload, id, form, flnm) {
|
||||
this.id = id;
|
||||
this.flnm = flnm;
|
||||
this._upload = upload;
|
||||
this._form = form;
|
||||
this._parent = form.parentNode;
|
||||
this._sid = upload.sid;
|
||||
this._wgt = upload._wgt;
|
||||
|
||||
var viewer, self = this;
|
||||
if (!upload._clsnm) viewer = new zul.UploadViewer(this, flnm);
|
||||
else
|
||||
zk.$import(upload._clsnm, function (cls) {
|
||||
viewer = new cls(self, flnm);
|
||||
});
|
||||
this.viewer = viewer;
|
||||
},
|
||||
|
||||
getWidget: function () {
|
||||
return this._wgt;
|
||||
},
|
||||
|
||||
destroy: function (finish) {
|
||||
this.end(finish);
|
||||
if (this._form) {
|
||||
jq(this._form.parentNode).remove();
|
||||
jq('#' + this.id + '_ifm').remove();
|
||||
}
|
||||
this._form = this._upload = this._wgt = null;
|
||||
},
|
||||
|
||||
start: function () {
|
||||
var wgt = this._wgt,
|
||||
frameId = this.id + '_ifm';
|
||||
|
||||
document.body.appendChild(this._parent);
|
||||
if (!jq('#' + frameId).length)
|
||||
jq.newFrame(frameId);
|
||||
this._form.target = frameId;
|
||||
this._form.submit();
|
||||
this._form.style.display = "none";
|
||||
|
||||
var self = this,
|
||||
data = 'cmd=uploadInfo&dtid=' + wgt.desktop.id
|
||||
+ '&wid=' + wgt.uuid + '&sid=' + this._sid;
|
||||
|
||||
if (zul.Uploader._tmupload)
|
||||
clearInterval(zul.Uploader._tmupload);
|
||||
|
||||
function t() {
|
||||
jq.ajax({
|
||||
type: 'POST',
|
||||
url: zk.ajaxURI('/upload', {desktop: wgt.desktop, au: true}),
|
||||
data: data,
|
||||
dataType: 'text',
|
||||
success: function(data) {
|
||||
var d = data.split(',');
|
||||
if (data.startsWith('error:')) {
|
||||
self._echo = true;
|
||||
zul.Uploader.clearInterval(self.id);
|
||||
if (wgt) {
|
||||
self.cancel();
|
||||
zul.Upload.error(data.substring(6, data.length), wgt.uuid, self._sid);
|
||||
}
|
||||
} else if (!self.update(zk.parseInt(d[0]), zk.parseInt(d[1])))
|
||||
zul.Uploader.clearInterval(self.id);
|
||||
},
|
||||
complete: function(req, status) {
|
||||
var v;
|
||||
if ((v = req.getResponseHeader("ZK-Error")) == "404"
|
||||
|| v == "410" || status == 'error'
|
||||
|| status == 404 || status == 405 || status == 410) {
|
||||
zul.Uploader.clearInterval(self.id);
|
||||
var wgt = self.getWidget();
|
||||
if (wgt) {
|
||||
self.cancel();
|
||||
zul.Upload.error(msgzk.FAILED_TO_RESPONSE, wgt.uuid, self._sid);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
t.id = this.id;
|
||||
|
||||
zul.Uploader.clearInterval = function (id) {
|
||||
if (t.id == id) {
|
||||
clearInterval(zul.Uploader._tmupload);
|
||||
zul.Uploader._tmupload = undefined;
|
||||
}
|
||||
};
|
||||
zul.Uploader._tmupload = setInterval(t, 1000);
|
||||
|
||||
zul.wgt.ADBS.autodisable(wgt);
|
||||
},
|
||||
|
||||
cancel: function () {
|
||||
zul.Uploader.clearInterval(this.id);
|
||||
if (this._upload)
|
||||
this._upload.cancel(this._sid);
|
||||
},
|
||||
|
||||
update: function (sent, total) {
|
||||
var wgt = this.getWidget();
|
||||
if (!wgt || total <= 0)
|
||||
if (this._echo)
|
||||
this.end();
|
||||
else
|
||||
return true;
|
||||
else if (zul.Uploader._tmupload) {
|
||||
this._echo = true;
|
||||
if (sent >= 0 && sent <= 100)
|
||||
this.viewer.update(sent, total);
|
||||
return sent >= 0 && sent < 100;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
end: function (finish) {
|
||||
this.viewer.destroy(finish);
|
||||
zul.Upload.destroy(this);
|
||||
this._echo = true;
|
||||
|
||||
|
||||
var wgt, upload, aded, parent;
|
||||
if ((wgt = this._wgt) && (upload = this._upload) &&
|
||||
(aded = upload._aded)) {
|
||||
wgt._uplder = null;
|
||||
aded.onResponse();
|
||||
upload._aded = null;
|
||||
|
||||
|
||||
if (wgt._uplder != null)
|
||||
wgt._uplder.destroy();
|
||||
if ((parent = upload._parent) && !jq(parent).parents('html').length) {
|
||||
upload._parent = wgt._getUploadRef();
|
||||
upload.initContent();
|
||||
}
|
||||
wgt._uplder = upload;
|
||||
wgt._uplder.sync();
|
||||
delete wgt._autodisable_self;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function _addUM(uplder, flnm) {
|
||||
var flman = zul.UploadViewer.flman;
|
||||
if (!flman || !flman.desktop) {
|
||||
if (flman) flman.detach();
|
||||
zul.UploadViewer.flman = flman = new zul.UploadManager();
|
||||
uplder.getWidget().getPage().appendChild(flman);
|
||||
}
|
||||
flman.removeFile(uplder);
|
||||
flman.addFile(uplder);
|
||||
}
|
||||
function _initUM(uplder, flnm) {
|
||||
if (zul.UploadManager)
|
||||
return _addUM(uplder, flnm);
|
||||
|
||||
zk.load('zul.wgt,zul.box', function() {
|
||||
|
||||
zul.UploadManager = zk.$extends(zul.wgt.Popup, {
|
||||
$init: function () {
|
||||
this.$supers('$init', arguments);
|
||||
this._files = {};
|
||||
this.setSclass('z-fileupload-manager');
|
||||
},
|
||||
onFloatUp: function(ctl) {
|
||||
var wgt = ctl.origin;
|
||||
if (!this.isVisible())
|
||||
return;
|
||||
this.setTopmost();
|
||||
},
|
||||
|
||||
getFileItem: function(id) {
|
||||
return this._files[id] || zk.Widget.$(id);
|
||||
},
|
||||
|
||||
addFile: function(uplder) {
|
||||
var id = uplder.id,
|
||||
flnm = uplder.flnm,
|
||||
prog = this.getFileItem(id);
|
||||
if (!prog) {
|
||||
prog = new zul.wgt.Div({
|
||||
uuid: id,
|
||||
children: [new zul.wgt.Label({
|
||||
value: flnm + ':'
|
||||
}), new zul.box.Box({
|
||||
mold: 'horizontal',
|
||||
children: [new zul.wgt.Progressmeter({
|
||||
id: id,
|
||||
sclass: 'z-fileupload-progress'
|
||||
})
|
||||
, new zul.wgt.Div({
|
||||
sclass: 'z-fileupload-remove z-icon-times',
|
||||
listeners: {
|
||||
onClick: function () {
|
||||
var uuid = id.substring(0, id.indexOf('_uplder_'));
|
||||
zul.Uploader.clearInterval(id);
|
||||
var wgt = zk.Widget.$(uuid);
|
||||
if (wgt) wgt._uplder.cancel(id.substring(id.lastIndexOf('_')+1, id.length));
|
||||
}
|
||||
}
|
||||
})]
|
||||
}), new zul.wgt.Label({id: id + '_total'}), new zul.wgt.Separator()]
|
||||
});
|
||||
|
||||
try {
|
||||
this.appendChild(prog);
|
||||
} catch (e) {}
|
||||
this._files[id] = prog;
|
||||
}
|
||||
return prog;
|
||||
},
|
||||
|
||||
updateFile: function(uplder, val, total) {
|
||||
var id = uplder.id,
|
||||
prog = this.getFileItem(id);
|
||||
if (!prog) return;
|
||||
prog.$f(id).setValue(val);
|
||||
prog.$f(id + '_total').setValue(total);
|
||||
},
|
||||
|
||||
removeFile: function(uplder) {
|
||||
var id = uplder.id,
|
||||
prog = this.getFileItem(id);
|
||||
if (prog)
|
||||
prog.detach();
|
||||
delete this._files[id];
|
||||
var close = true;
|
||||
for (var p in this._files)
|
||||
if (!(close = false))
|
||||
break;
|
||||
|
||||
if (close)
|
||||
this.close();
|
||||
},
|
||||
|
||||
open: function(wgt, position) {
|
||||
this.$super('open', wgt, null, position || 'after_start', {
|
||||
sendOnOpen: false,
|
||||
disableMask: true
|
||||
});
|
||||
}
|
||||
});
|
||||
_addUM(uplder, flnm);
|
||||
});
|
||||
}
|
||||
|
||||
zul.UploadViewer = zk.$extends(zk.Object, {
|
||||
|
||||
$init: function (uplder, flnm) {
|
||||
this._uplder = uplder;
|
||||
_initUM(uplder, flnm);
|
||||
},
|
||||
|
||||
update: function (sent, total) {
|
||||
var flman = zul.UploadViewer.flman;
|
||||
if (flman) {
|
||||
if (!flman.isOpen())
|
||||
flman.open(this._uplder.getWidget());
|
||||
flman.updateFile(this._uplder, sent, msgzk.FILE_SIZE+Math.round(total/1024)+msgzk.KBYTES);
|
||||
}
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
var flman = zul.UploadViewer.flman;
|
||||
if (flman)
|
||||
flman.removeFile(this._uplder);
|
||||
}
|
||||
});
|
||||
|
||||
})();
|
|
@ -2,7 +2,7 @@
|
|||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/ckez.jar" sourcepath="lib/src/ckez-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/calendar.jar" sourcepath="lib/src/calendar-source.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/calendar.jar" sourcepath="lib/src/calendar-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/asm.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/cglib.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/commons-el.jar"/>
|
||||
|
|
Loading…
Reference in New Issue