2011-09-01 01:37:30 +02:00
/ * *
2013-04-13 21:00:13 +02:00
* EGroupware eTemplate2 - JS Number object
2011-09-01 01:37:30 +02:00
*
* @ license http : //opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @ package etemplate
* @ subpackage api
2021-06-07 17:33:53 +02:00
* @ link https : //www.egroupware.org
2011-09-01 01:37:30 +02:00
* @ author Nathan Gray
* @ copyright Nathan Gray 2011
* /
/ * e g w : u s e s
2020-02-07 17:41:51 +01:00
et2 _core _inputWidget ;
2021-06-07 17:33:53 +02:00
api . Resumable . resumable ;
2011-09-01 01:37:30 +02:00
* /
2021-06-07 17:33:53 +02:00
import { et2 _inputWidget } from "./et2_core_inputWidget" ;
import { et2 _register _widget } from "./et2_core_widget" ;
import { ClassWithAttributes } from "./et2_core_inheritance" ;
import { et2 _no _init } from "./et2_core_common" ;
import { et2 _vfsSize } from "./et2_widget_vfs" ;
2011-09-01 01:37:30 +02:00
/ * *
* Class which implements file upload
2015-08-07 16:18:07 +02:00
*
2013-04-13 21:00:13 +02:00
* @ augments et2 _inputWidget
2015-08-07 16:18:07 +02:00
* /
2021-06-07 17:33:53 +02:00
export class et2 _file extends et2 _inputWidget {
2020-02-07 17:41:51 +01:00
/ * *
* Constructor
*
* @ memberOf et2 _file
* /
2021-06-07 17:33:53 +02:00
constructor ( _parent , _attrs , _child ) {
2020-02-07 17:41:51 +01:00
// Call the inherited constructor
2021-06-07 17:33:53 +02:00
super ( _parent , _attrs , ClassWithAttributes . extendAttributes ( et2 _file . _attributes , _child || { } ) ) ;
this . asyncOptions = { } ;
this . input = null ;
this . progress = null ;
this . span = null ;
this . node = null ;
this . input = null ;
this . progress = null ;
this . span = null ;
2020-02-07 17:41:51 +01:00
// Contains all submit buttons need to be disabled during upload process
2021-06-07 17:33:53 +02:00
this . disabled _buttons = jQuery ( "input[type='submit'], button" ) ;
2020-06-10 18:20:16 +02:00
// Make sure it's an object, not an array, or values get lost when sent to server
2021-06-07 17:33:53 +02:00
this . options . value = jQuery . extend ( { } , this . options . value ) ;
if ( ! this . options . id ) {
2020-02-07 17:41:51 +01:00
console . warn ( "File widget needs an ID. Used 'file_widget'." ) ;
2021-06-07 17:33:53 +02:00
this . options . id = "file_widget" ;
2020-02-07 17:41:51 +01:00
}
// Legacy - id ending in [] means multiple
2021-06-07 17:33:53 +02:00
if ( this . options . id . substr ( - 2 ) == "[]" ) {
this . options . multiple = true ;
2020-02-07 17:41:51 +01:00
}
// If ID ends in /, it's a directory - allow multiple
2021-06-07 17:33:53 +02:00
else if ( this . options . id . substr ( - 1 ) === "/" ) {
this . options . multiple = true ;
2020-02-07 17:41:51 +01:00
_attrs . multiple = true ;
}
// Set up the URL to have the request ID & the widget ID
2021-06-07 17:33:53 +02:00
var instance = this . getInstanceManager ( ) ;
let self = this ;
this . asyncOptions = jQuery . extend ( { } , this . getAsyncOptions ( this ) ) ;
this . asyncOptions . fieldName = this . options . id ;
this . createInputWidget ( ) ;
this . set _readonly ( this . options . readonly ) ;
2020-02-07 17:41:51 +01:00
}
2021-06-07 17:33:53 +02:00
destroy ( ) {
super . destroy ( ) ;
2020-02-07 17:41:51 +01:00
this . set _drop _target ( null ) ;
this . node = null ;
this . input = null ;
this . span = null ;
this . progress = null ;
2021-06-07 17:33:53 +02:00
}
createInputWidget ( ) {
2020-02-07 17:41:51 +01:00
this . node = jQuery ( document . createElement ( "div" ) ) . addClass ( "et2_file" ) ;
this . span = jQuery ( document . createElement ( "span" ) )
. addClass ( 'et2_file_span et2_button' )
. appendTo ( this . node ) ;
if ( this . options . label != '' )
this . span . addClass ( 'et2_button_text' ) ;
2021-06-07 17:33:53 +02:00
let span = this . span ;
2020-02-07 17:41:51 +01:00
this . input = jQuery ( document . createElement ( "input" ) )
. attr ( "type" , "file" ) . attr ( "placeholder" , this . options . blur )
. addClass ( "et2_file_upload" )
. appendTo ( this . node )
. hover ( function ( ) {
jQuery ( span )
. toggleClass ( 'et2_file_spanHover' ) ;
} )
. on ( {
mousedown : function ( ) {
jQuery ( span ) . addClass ( 'et2_file_spanActive' ) ;
} ,
mouseup : function ( ) {
jQuery ( span ) . removeClass ( 'et2_file_spanActive' ) ;
}
} ) ;
if ( this . options . accept )
this . input . attr ( 'accept' , this . options . accept ) ;
2021-06-07 17:33:53 +02:00
let self = this ;
2020-02-07 17:41:51 +01:00
// trigger native input upload file
if ( ! this . options . readonly )
this . span . click ( function ( ) { self . input . click ( ) ; } ) ;
// Check for File interface, should fall back to normal form submit if missing
if ( typeof File != "undefined" && typeof ( new XMLHttpRequest ( ) ) . upload != "undefined" ) {
this . resumable = new Resumable ( this . asyncOptions ) ;
this . resumable . assignBrowse ( this . input ) ;
this . resumable . on ( 'fileAdded' , jQuery . proxy ( this . _fileAdded , this ) ) ;
this . resumable . on ( 'fileProgress' , jQuery . proxy ( this . _fileProgress , this ) ) ;
this . resumable . on ( 'fileSuccess' , jQuery . proxy ( this . finishUpload , this ) ) ;
this . resumable . on ( 'complete' , jQuery . proxy ( this . onFinish , this ) ) ;
}
else {
// This may be a problem submitting via ajax
}
if ( this . options . progress ) {
2021-06-07 17:33:53 +02:00
let widget = this . getRoot ( ) . getWidgetById ( this . options . progress ) ;
2020-02-07 17:41:51 +01:00
if ( widget ) {
//may be not available at createInputWidget time
this . progress = jQuery ( widget . getDOMNode ( ) ) ;
}
}
if ( ! this . progress ) {
this . progress = jQuery ( document . createElement ( "div" ) ) . appendTo ( this . node ) ;
}
this . progress . addClass ( "progress" ) ;
if ( this . options . multiple ) {
this . input . attr ( "multiple" , "multiple" ) ;
}
this . setDOMNode ( this . node [ 0 ] ) ;
2020-10-19 12:54:16 +02:00
// set drop target to widget dom node if no target option is specified
if ( ! this . options . drop _target )
this . resumable . assignDrop ( [ this . getDOMNode ( ) ] ) ;
2021-06-07 17:33:53 +02:00
}
2020-06-10 18:20:16 +02:00
/ * *
* Get any specific async upload options
* /
2021-06-07 17:33:53 +02:00
getAsyncOptions ( self ) {
2020-06-10 18:20:16 +02:00
return {
// Callbacks
onStart : function ( event , file _count ) {
return self . onStart ( event , file _count ) ;
} ,
onFinish : function ( event , file _count ) {
self . onFinish . apply ( self , [ event , file _count ] ) ;
} ,
onStartOne : function ( event , file _name , index , file _count ) {
} ,
onFinishOne : function ( event , response , name , number , total ) { return self . finishUpload ( event , response , name , number , total ) ; } ,
onProgress : function ( event , progress , name , number , total ) { return self . onProgress ( event , progress , name , number , total ) ; } ,
onError : function ( event , name , error ) { return self . onError ( event , name , error ) ; } ,
beforeSend : function ( form ) { return self . beforeSend ( form ) ; } ,
chunkSize : this . options . chunk _size || 1024 * 1024 ,
target : egw . ajaxUrl ( "EGroupware\\Api\\Etemplate\\Widget\\File::ajax_upload" ) ,
query : function ( file ) { return self . beforeSend ( file ) ; } ,
// Disable checking for already uploaded chunks
testChunks : false
} ;
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* Set a widget or DOM node as a HTML5 file drop target
*
* @ param { string } new _target widget ID or DOM node ID to be used as a new target
* /
2021-06-07 17:33:53 +02:00
set _drop _target ( new _target ) {
2020-02-07 17:41:51 +01:00
// Cancel old drop target
if ( this . options . drop _target ) {
2021-06-07 17:33:53 +02:00
let widget = this . getRoot ( ) . getWidgetById ( this . options . drop _target ) ;
let drop _target = widget && widget . getDOMNode ( ) || document . getElementById ( this . options . drop _target ) ;
if ( drop _target ) {
this . resumable . unAssignDrop ( drop _target ) ;
2020-02-07 17:41:51 +01:00
}
}
this . options . drop _target = new _target ;
if ( ! this . options . drop _target )
return ;
// Set up new drop target
2021-06-07 17:33:53 +02:00
let widget = this . getRoot ( ) . getWidgetById ( this . options . drop _target ) ;
let drop _target = widget && widget . getDOMNode ( ) || document . getElementById ( this . options . drop _target ) ;
2020-02-07 17:41:51 +01:00
if ( drop _target ) {
this . resumable . assignDrop ( [ drop _target ] ) ;
}
else {
this . egw ( ) . debug ( "warn" , "Did not find file drop target %s" , this . options . drop _target ) ;
}
2021-06-07 17:33:53 +02:00
}
attachToDOM ( ) {
let res = super . attachToDOM ( ) ;
2020-02-07 17:41:51 +01:00
// Override parent's change, file widget will fire change when finished uploading
this . input . unbind ( "change.et2_inputWidget" ) ;
return res ;
2021-06-07 17:33:53 +02:00
}
getValue ( ) {
2020-02-07 17:41:51 +01:00
return this . options . value ? this . options . value : this . input . val ( ) ;
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* Set the value of the file widget .
*
* If you pass a FileList or list of files , it will trigger the async upload
*
* @ param { FileList | File [ ] | false } value List of files to be uploaded , or false to reset .
* @ param { Event } event Most browsers require the user to initiate file transfers in some way .
* Pass the event in , if you have it .
* /
2021-06-07 17:33:53 +02:00
set _value ( value , event ) {
2020-02-07 17:41:51 +01:00
if ( ! value || typeof value == "undefined" ) {
value = { } ;
}
if ( jQuery . isEmptyObject ( value ) ) {
this . options . value = { } ;
if ( this . resumable . progress ( ) == 1 )
this . progress . empty ( ) ;
// Reset the HTML element
this . input . wrap ( '<form>' ) . closest ( 'form' ) . get ( 0 ) . reset ( ) ;
this . input . unwrap ( ) ;
return ;
}
2021-06-07 17:33:53 +02:00
let addFile = jQuery . proxy ( function ( i , file ) {
2020-02-07 17:41:51 +01:00
this . resumable . addFile ( file , event ) ;
} , this ) ;
if ( typeof value == 'object' && value . length && typeof value [ 0 ] == 'object' && value [ 0 ] . name ) {
try {
this . input [ 0 ] . files = value ;
jQuery . each ( value , addFile ) ;
}
catch ( e ) {
var self = this ;
var args = arguments ;
jQuery . each ( value , addFile ) ;
}
}
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* Set the value for label
* The label is used as caption for span tag which customize the HTML file upload styling
*
* @ param { string } value text value of label
* /
2021-06-07 17:33:53 +02:00
set _label ( value ) {
2020-02-07 17:41:51 +01:00
if ( this . span != null && value != null ) {
this . span . text ( value ) ;
}
2021-06-07 17:33:53 +02:00
}
getInputNode ( ) {
2020-02-07 17:41:51 +01:00
if ( typeof this . input == 'undefined' )
return false ;
return this . input [ 0 ] ;
2021-06-07 17:33:53 +02:00
}
set _mime ( mime ) {
2020-02-07 17:41:51 +01:00
if ( ! mime ) {
this . options . mime = null ;
}
if ( mime . indexOf ( "/" ) != 0 ) {
// Lower case it now, if it's not a regex
this . options . mime = mime . toLowerCase ( ) ;
}
else {
2020-06-02 14:39:43 +02:00
this . options . mime = mime ;
2020-02-07 17:41:51 +01:00
}
2021-06-07 17:33:53 +02:00
}
set _multiple ( _multiple ) {
2020-02-07 17:41:51 +01:00
this . options . multiple = _multiple ;
if ( _multiple ) {
return this . input . attr ( "multiple" , "multiple" ) ;
}
return this . input . removeAttr ( "multiple" ) ;
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* Check to see if the provided file ' s mimetype matches
*
* @ param f File object
* @ return boolean
* /
2021-06-07 17:33:53 +02:00
checkMime ( f ) {
2020-06-02 18:53:33 +02:00
if ( ! this . options . mime )
return true ;
2021-06-07 17:33:53 +02:00
let mime = '' ;
2020-06-02 14:39:43 +02:00
if ( this . options . mime . indexOf ( "/" ) != 0 ) {
// Lower case it now, if it's not a regex
mime = this . options . mime . toLowerCase ( ) ;
}
else {
// Convert into a js regex
var parts = this . options . mime . substr ( 1 ) . match ( /(.*)\/([igm]?)$/ ) ;
mime = new RegExp ( parts [ 1 ] , parts . length > 2 ? parts [ 2 ] : "" ) ;
}
2020-02-07 17:41:51 +01:00
// If missing, let the server handle it
2020-06-02 14:39:43 +02:00
if ( ! mime || ! f . type )
2020-02-07 17:41:51 +01:00
return true ;
2020-06-02 14:39:43 +02:00
var is _preg = ( typeof mime == "object" ) ;
if ( ! is _preg && f . type . toLowerCase ( ) == mime || is _preg && mime . test ( f . type ) ) {
2020-02-07 17:41:51 +01:00
return true ;
}
// Not right mime
return false ;
2021-06-07 17:33:53 +02:00
}
_fileAdded ( file , event ) {
2020-02-07 17:41:51 +01:00
// Manual additions have no event
if ( typeof event == 'undefined' ) {
event = { } ;
}
// Trigger start of uploading, calls callback
if ( ! this . resumable . isUploading ( ) ) {
if ( ! ( this . onStart ( event , this . resumable . files . length ) ) )
return ;
}
// Here 'this' is the input
if ( this . checkMime ( file . file ) ) {
if ( this . createStatus ( event , file ) ) {
// Disable buttons
this . disabled _buttons
. not ( "[disabled]" )
. attr ( "disabled" , true )
. addClass ( 'et2_button_ro' )
. removeClass ( 'et2_clickable' )
. css ( 'cursor' , 'default' ) ;
// Actually start uploading
this . resumable . upload ( ) ;
}
}
else {
// Wrong mime type - show in the list of files
return this . createStatus ( this . egw ( ) . lang ( "File is of wrong type (%1 != %2)!" , file . file . type , this . options . mime ) , file ) ;
}
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* Add in the request id
* /
2021-06-07 17:33:53 +02:00
beforeSend ( form ) {
2020-02-07 17:41:51 +01:00
var instance = this . getInstanceManager ( ) ;
return {
request _id : instance . etemplate _exec _id ,
widget _id : this . id
} ;
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* Disables submit buttons while uploading
* /
2021-06-07 17:33:53 +02:00
onStart ( event , file _count ) {
2020-02-07 17:41:51 +01:00
// Hide any previous errors
this . hideMessage ( ) ;
event . data = this ;
//Add dropdown_progress
if ( this . options . progress _dropdownlist ) {
this . _build _progressDropDownList ( ) ;
}
// Callback
if ( this . options . onStart )
return et2 _call ( this . options . onStart , event , file _count ) ;
return true ;
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* Re - enables submit buttons when done
* /
2021-06-07 17:33:53 +02:00
onFinish ( ) {
2020-04-21 18:29:46 +02:00
this . disabled _buttons . removeAttr ( "disabled" ) . css ( 'cursor' , 'pointer' ) . removeClass ( 'et2_button_ro' ) ;
2020-02-07 17:41:51 +01:00
var file _count = this . resumable . files . length ;
// Remove files from list
while ( this . resumable . files . length > 0 ) {
this . resumable . removeFile ( this . resumable . files [ this . resumable . files . length - 1 ] ) ;
}
var event = jQuery . Event ( 'upload' ) ;
event . data = this ;
var result = false ;
//Remove progress_dropDown_fileList class and unbind the click handler from body
if ( this . options . progress _dropdownlist ) {
this . progress . removeClass ( "progress_dropDown_fileList" ) ;
jQuery ( this . node ) . find ( 'span' ) . removeClass ( 'totalProgress_loader' ) ;
jQuery ( 'body' ) . off ( 'click' ) ;
}
if ( this . options . onFinish && ! jQuery . isEmptyObject ( this . getValue ( ) ) ) {
result = et2 _call ( this . options . onFinish , event , file _count ) ;
}
else {
result = ( file _count == 0 || ! jQuery . isEmptyObject ( this . getValue ( ) ) ) ;
}
if ( result ) {
// Fire legacy change action when done
this . change ( this . input ) ;
}
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* Build up dropdown progress with total count indicator
*
* @ todo Implement totalProgress bar instead of ajax - loader , in order to show how much percent of uploading is completed
* /
2021-06-07 17:33:53 +02:00
_build _progressDropDownList ( ) {
2020-02-07 17:41:51 +01:00
this . progress . addClass ( "progress_dropDown_fileList" ) ;
//Add uploading indicator and bind hover handler on it
jQuery ( this . node ) . find ( 'span' ) . addClass ( 'totalProgress_loader' ) ;
jQuery ( this . node ) . find ( 'span.et2_file_span' ) . hover ( function ( ) {
jQuery ( '.progress_dropDown_fileList' ) . show ( ) ;
} ) ;
//Bind click handler to dismiss the dropdown while uploading
jQuery ( 'body' ) . on ( 'click' , function ( event ) {
if ( event . target . className != 'remove' ) {
jQuery ( '.progress_dropDown_fileList' ) . hide ( ) ;
}
} ) ;
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* Creates the elements used for displaying the file , and it ' s upload status , and
* attaches them to the DOM
*
* @ param _event Either the event , or an error message
* /
2021-06-07 17:33:53 +02:00
createStatus ( _event , file ) {
2020-02-07 17:41:51 +01:00
var error = ( typeof _event == "object" ? "" : _event ) ;
if ( this . options . max _file _size && file . size > this . options . max _file _size ) {
error = this . egw ( ) . lang ( "File too large. Maximum %1" , et2 _vfsSize . prototype . human _size ( this . options . max _file _size ) ) ;
}
if ( this . options . progress ) {
var widget = this . getRoot ( ) . getWidgetById ( this . options . progress ) ;
if ( widget ) {
this . progress = jQuery ( widget . getDOMNode ( ) ) ;
this . progress . addClass ( "progress" ) ;
}
}
if ( this . progress ) {
var fileName = file . fileName || 'file' ;
var status = jQuery ( "<li data-file='" + fileName . replace ( /'/g , '"' ) + "'>" + fileName
+ "<div class='remove'/><span class='progressBar'><p/></span></li>" )
. appendTo ( this . progress ) ;
jQuery ( "div.remove" , status ) . on ( 'click' , file , jQuery . proxy ( this . cancel , this ) ) ;
if ( error != "" ) {
status . addClass ( "message ui-state-error" ) ;
status . append ( "<div>" + error + "</diff>" ) ;
jQuery ( ".progressBar" , status ) . css ( "display" , "none" ) ;
}
}
return error == "" ;
2021-06-07 17:33:53 +02:00
}
_fileProgress ( file ) {
2020-02-07 17:41:51 +01:00
if ( this . progress ) {
jQuery ( "li[data-file='" + file . fileName . replace ( /'/g , '"' ) + "'] > span.progressBar > p" ) . css ( "width" , Math . ceil ( file . progress ( ) * 100 ) + "%" ) ;
}
return true ;
2021-06-07 17:33:53 +02:00
}
onError ( event , name , error ) {
2020-02-07 17:41:51 +01:00
console . warn ( event , name , error ) ;
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* A file upload is finished , update the UI
* /
2021-06-07 17:33:53 +02:00
finishUpload ( file , response ) {
2020-02-07 17:41:51 +01:00
var name = file . fileName || 'file' ;
if ( typeof response == 'string' )
response = jQuery . parseJSON ( response ) ;
if ( response . response [ 0 ] && typeof response . response [ 0 ] . data . length == 'undefined' ) {
if ( typeof this . options . value !== 'object' || ! this . options . multiple ) {
this . set _value ( { } ) ;
}
for ( var key in response . response [ 0 ] . data ) {
if ( typeof response . response [ 0 ] . data [ key ] == "string" ) {
// Message from server - probably error
jQuery ( "[data-file='" + name . replace ( /'/g , '"' ) + "']" , this . progress )
. addClass ( "error" )
. css ( "display" , "block" )
. text ( response . response [ 0 ] . data [ key ] ) ;
}
else {
this . options . value [ key ] = response . response [ 0 ] . data [ key ] ;
// If not multiple, we already destroyed the status, so re-create it
if ( ! this . options . multiple ) {
this . createStatus ( { } , file ) ;
}
if ( this . progress ) {
jQuery ( "[data-file='" + name . replace ( /'/g , '"' ) + "']" , this . progress ) . addClass ( "message success" ) ;
}
}
}
}
else if ( this . progress ) {
jQuery ( "[data-file='" + name . replace ( /'/g , '"' ) + "']" , this . progress )
. addClass ( "ui-state-error" )
. css ( "display" , "block" )
. text ( this . egw ( ) . lang ( "Server error" ) ) ;
}
var event = jQuery . Event ( 'upload' ) ;
event . data = this ;
// Callback
2020-03-25 03:34:04 +01:00
if ( typeof this . onFinishOne == 'function' ) {
this . onFinishOne ( event , response , name ) ;
}
2020-02-07 17:41:51 +01:00
return true ;
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* Remove a file from the list of values
*
* @ param { File | string } File object , or file name , to remove
* /
2021-06-07 17:33:53 +02:00
remove _file ( file ) {
2020-02-07 17:41:51 +01:00
//console.info(filename);
if ( typeof file == 'string' ) {
file = { fileName : file } ;
}
for ( var key in this . options . value ) {
if ( this . options . value [ key ] . name == file . fileName ) {
delete this . options . value [ key ] ;
jQuery ( '[data-file="' + file . fileName . replace ( /'/g , '"' ) + '"]' , this . node ) . remove ( ) ;
return ;
}
}
if ( file . isComplete && ! file . isComplete ( ) && file . cancel )
file . cancel ( ) ;
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* Cancel a file - event callback
* /
2021-06-07 17:33:53 +02:00
cancel ( e ) {
2020-02-07 17:41:51 +01:00
e . preventDefault ( ) ;
// Look for file name in list
var target = jQuery ( e . target ) . parents ( "li" ) ;
this . remove _file ( e . data ) ;
// In case it didn't make it to the list (error)
target . remove ( ) ;
jQuery ( e . target ) . remove ( ) ;
2021-06-07 17:33:53 +02:00
}
2020-02-07 17:41:51 +01:00
/ * *
* Set readonly
*
* @ param { boolean } _ro boolean readonly state , true means readonly
* /
2021-06-07 17:33:53 +02:00
set _readonly ( _ro ) {
2020-02-07 17:41:51 +01:00
if ( typeof _ro != "undefined" ) {
this . options . readonly = _ro ;
this . span . toggleClass ( 'et2_file_ro' , _ro ) ;
if ( this . options . readonly ) {
this . span . unbind ( 'click' ) ;
}
else {
var self = this ;
this . span . off ( ) . bind ( 'click' , function ( ) { self . input . click ( ) ; } ) ;
}
}
2021-06-07 17:33:53 +02:00
}
}
et2 _file . _attributes = {
"multiple" : {
"name" : "Multiple files" ,
"type" : "boolean" ,
"default" : false ,
"description" : "Allow the user to select more than one file to upload at a time. Subject to browser support."
} ,
"max_file_size" : {
"name" : "Maximum file size" ,
"type" : "integer" ,
"default" : 0 ,
"description" : "Largest file accepted, in bytes. Subject to server limitations. 8MB = 8388608"
} ,
"mime" : {
"name" : "Allowed file types" ,
"type" : "string" ,
"default" : et2 _no _init ,
"description" : "Mime type (eg: image/png) or regex (eg: /^text\//i) for allowed file types"
} ,
"blur" : {
"name" : "Placeholder" ,
"type" : "string" ,
"default" : "" ,
"description" : "This text get displayed if an input-field is empty and does not have the input-focus (blur). It can be used to show a default value or a kind of help-text."
} ,
"progress" : {
"name" : "Progress node" ,
"type" : "string" ,
"default" : et2 _no _init ,
"description" : "The ID of an alternate node (div) to display progress and results. The Node is fetched with et2 getWidgetById so you MUST use the id assigned in XET-File (it may not be available at creation time, so we (re)check on createStatus time)"
} ,
"onStart" : {
"name" : "Start event handler" ,
"type" : "any" ,
"default" : et2 _no _init ,
"description" : "A (js) function called when an upload starts. Return true to continue with upload, false to cancel."
} ,
"onFinish" : {
"name" : "Finish event handler" ,
"type" : "any" ,
"default" : et2 _no _init ,
"description" : "A (js) function called when all files to be uploaded are finished."
} ,
drop _target : {
"name" : "Optional, additional drop target for HTML5 uploads" ,
"type" : "string" ,
"default" : et2 _no _init ,
"description" : "The ID of an additional drop target for HTML5 drag-n-drop file uploads"
} ,
label : {
"name" : "Label of file upload" ,
"type" : "string" ,
"default" : "Choose file..." ,
"description" : "String caption to be displayed on file upload span"
} ,
progress _dropdownlist : {
"name" : "List on files in progress like dropdown" ,
"type" : "boolean" ,
"default" : false ,
"description" : "Style list of files in uploading progress like dropdown list with a total upload progress indicator"
} ,
onFinishOne : {
"name" : "Finish event handler for each one" ,
"type" : "js" ,
"default" : et2 _no _init ,
"description" : "A (js) function called when a file to be uploaded is finished."
} ,
accept : {
"name" : "Acceptable extensions" ,
"type" : "string" ,
"default" : '' ,
"description" : "Define types of files that the server accepts. Multiple types can be seperated by comma and the default is to accept everything."
} ,
chunk _size : {
"name" : "Chunk size" ,
"type" : "integer" ,
"default" : 1024 * 1024 ,
"description" : "Max chunk size, gets set from server-side PHP (max_upload_size-1M)/2" // last chunk can be up to 2*chunk_size!
}
} ;
et2 _register _widget ( et2 _file , [ "file" ] ) ;
2020-02-07 17:41:51 +01:00
//# sourceMappingURL=et2_widget_file.js.map