diff e2gallerypro/e2upload/Source/Uploader.js @ 3:3f6b44aa6b35 judyates

[svn r4] added ability to buy stuff, from a Prints page, but it doesn't work well with the css, and it also has not been fitted into the perl make system.
author rlm
date Mon, 22 Feb 2010 08:02:39 -0500
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/e2gallerypro/e2upload/Source/Uploader.js	Mon Feb 22 08:02:39 2010 -0500
     1.3 @@ -0,0 +1,235 @@
     1.4 +/*
     1.5 +Script: Uploader.js
     1.6 +	MooTools FileManager - Implements Upload functionality into the FileManager based on [FancyUpload](http://digitarald.de)
     1.7 +
     1.8 +License:
     1.9 +	MIT-style license.
    1.10 +
    1.11 +Copyright:
    1.12 +	Copyright (c) 2009 [Christoph Pojer](http://og5.net/christoph).
    1.13 +
    1.14 +Dependencies:
    1.15 +	- FileManager.js
    1.16 +
    1.17 +Options:
    1.18 +	- upload: (boolean, defaults to *true*) 
    1.19 +	- uploadAuthData: (object) Data to be send with the GET-Request of an Upload as Flash ignores authenticated clients
    1.20 +	- resizeImages: (boolean, defaults to *true*) Whether to show the option to resize big images or not
    1.21 +*/
    1.22 +
    1.23 +FileManager.implement({
    1.24 +	
    1.25 +	options: {
    1.26 +		resizeImages: false,
    1.27 +		upload: true,
    1.28 +		uploadAuthData: {}
    1.29 +	},
    1.30 +	
    1.31 +	hooks: {
    1.32 +		show: {
    1.33 +			upload: function(){
    1.34 +				this.startUpload();
    1.35 +			}
    1.36 +		},
    1.37 +		
    1.38 +		cleanup: {
    1.39 +			upload: function(){
    1.40 +				if(!this.options.upload || !this.upload) return;
    1.41 +				
    1.42 +				if(this.upload.uploader) this.upload.uploader.set('opacity', 0).dispose();
    1.43 +			}
    1.44 +		}
    1.45 +	},
    1.46 +	
    1.47 +	onDialogOpen: function(){
    1.48 +		if(this.swf && this.swf.box) this.swf.box.setStyle('visibility', 'hidden');
    1.49 +	},
    1.50 +	
    1.51 +	onDialogClose: function(){
    1.52 +		if(this.swf && this.swf.box) this.swf.box.setStyle('visibility', 'visible');
    1.53 +	},
    1.54 +	
    1.55 +	startUpload: function(){
    1.56 +		if(!this.options.upload || this.swf) return;
    1.57 +		
    1.58 +		var self = this;
    1.59 +		this.upload = {
    1.60 +			button: this.addMenuButton('upload').addEvents({
    1.61 +				click: function(){
    1.62 +					return false;
    1.63 +				},
    1.64 +				mouseenter: function(){
    1.65 +					this.addClass('hover');
    1.66 +				},
    1.67 +				mouseleave: function(){
    1.68 +					this.removeClass('hover');
    1.69 +					this.blur();
    1.70 +				},
    1.71 +				mousedown: function(){
    1.72 +					this.focus();
    1.73 +				}
    1.74 +			}),
    1.75 +			list: new Element('ul', {'class': 'filemanager-uploader-list'}),
    1.76 +			uploader: new Element('div', {opacity: 0}).adopt(
    1.77 +				new Element('h2', {text: this.language.upload}),
    1.78 +				new Element('div', {'class': 'filemanager-uploader'})
    1.79 +			)
    1.80 +		};
    1.81 +		this.upload.uploader.getElement('div').adopt(this.upload.list);
    1.82 +		this.closeIcon.appearOn(this.upload.button, 0.8);
    1.83 +		
    1.84 +		if(this.options.resizeImages){
    1.85 +			var resizer = new Element('div', {'class': 'checkbox'}),
    1.86 +				check = (function(){ this.toggleClass('checkboxChecked'); }).bind(resizer);
    1.87 +			check();
    1.88 +			this.upload.label = new Element('label').adopt(
    1.89 +				resizer, new Element('span', {text: this.language.resizeImages})
    1.90 +			).addEvent('click', check).inject(this.menu);
    1.91 +		}
    1.92 +		
    1.93 +		var File = new Class({
    1.94 +
    1.95 +			Extends: Swiff.Uploader.File,
    1.96 +			
    1.97 +			initialize: function(base, data){
    1.98 +				this.parent(base, data);
    1.99 +				this.setOptions({
   1.100 +					url: self.options.url+'?'+Hash.toQueryString($merge({}, self.options.uploadAuthData, {
   1.101 +						event: 'upload',
   1.102 +						directory: self.normalize(self.Directory),
   1.103 +						resize: self.options.resizeImages && resizer.hasClass('checkboxChecked') ? 1 : 0
   1.104 +					}))
   1.105 +				});
   1.106 +			},
   1.107 +			
   1.108 +			render: function(){
   1.109 +				if(this.invalid){
   1.110 +					var message = self.language.uploader.unknown, sub = {
   1.111 +						name: this.name,
   1.112 +						size: Swiff.Uploader.formatUnit(this.size, 'b')
   1.113 +					};
   1.114 +					
   1.115 +					if(self.language.uploader[this.validationError])
   1.116 +						message = self.language.uploader[this.validationError];
   1.117 +					
   1.118 +					if(this.validationError=='sizeLimitMin')
   1.119 +							sub.size_min = Swiff.Uploader.formatUnit(this.base.options.fileSizeMin, 'b');
   1.120 +					else if(this.validationError=='sizeLimitMax')
   1.121 +							sub.size_max = Swiff.Uploader.formatUnit(this.base.options.fileSizeMax, 'b');
   1.122 +					
   1.123 +					new Dialog(new Element('div', {html: message.substitute(sub, /\\?\$\{([^{}]+)\}/g)}) , {language: {confirm: self.language.ok}, buttons: ['confirm']});
   1.124 +					return this;
   1.125 +				}
   1.126 +				
   1.127 +				this.addEvents({
   1.128 +					open: this.onOpen,
   1.129 +					remove: this.onRemove,
   1.130 +					requeue: this.onRequeue,
   1.131 +					progress: this.onProgress,
   1.132 +					stop: this.onStop,
   1.133 +					complete: this.onComplete
   1.134 +				});
   1.135 +				
   1.136 +				this.ui = {};
   1.137 +				this.ui.icon = new Asset.image(self.options.assetBasePath+'Icons/'+this.extension+'.png', {
   1.138 +					onerror: function(){ new Asset.image(self.options.assetBasePath+'Icons/default.png').replaces(this); }
   1.139 +				});
   1.140 +				this.ui.element = new Element('li', {'class': 'file', id: 'file-' + this.id});
   1.141 +				this.ui.title = new Element('span', {'class': 'file-title', text: this.name});
   1.142 +				this.ui.size = new Element('span', {'class': 'file-size', text: Swiff.Uploader.formatUnit(this.size, 'b')});
   1.143 +				
   1.144 +				var tips, file = this;
   1.145 +				this.ui.cancel = new Asset.image(self.options.assetBasePath+'cancel.png', {'class': 'file-cancel', title: self.language.cancel}).addEvent('click', function(){
   1.146 +					file.remove();
   1.147 +					tips.hide();
   1.148 +					tips.detach(this);
   1.149 +				});
   1.150 +				tips = new FileManager.Tips(this.ui.cancel);
   1.151 +				
   1.152 +				var progress = new Element('img', {'class': 'file-progress', src: self.options.assetBasePath+'bar.gif'});
   1.153 +
   1.154 +				this.ui.element.adopt(
   1.155 +					this.ui.cancel,
   1.156 +					progress,
   1.157 +					this.ui.icon,
   1.158 +					this.ui.title,
   1.159 +					this.ui.size
   1.160 +				).inject(self.upload.list).highlight();
   1.161 +				
   1.162 +				this.ui.progress = new Fx.ProgressBar(progress).set(0);
   1.163 +							
   1.164 +				this.base.reposition();
   1.165 +
   1.166 +				return this.parent();
   1.167 +			},
   1.168 +
   1.169 +			onOpen: function(){
   1.170 +				this.ui.element.addClass('file-running');
   1.171 +			},
   1.172 +
   1.173 +			onRemove: function(){
   1.174 +				this.ui = this.ui.element.destroy();
   1.175 +			},
   1.176 +
   1.177 +			onProgress: function(){
   1.178 +				this.ui.progress.start(this.progress.percentLoaded);
   1.179 +			},
   1.180 +
   1.181 +			onStop: function(){
   1.182 +				this.remove();
   1.183 +			},
   1.184 +
   1.185 +			onComplete: function(){
   1.186 +				this.ui.progress = this.ui.progress.cancel().element.destroy();
   1.187 +				this.ui.cancel = this.ui.cancel.destroy();
   1.188 +				
   1.189 +				var response = JSON.decode(this.response.text);
   1.190 +				if(!response.status)
   1.191 +					new Dialog((''+response.error).substitute(self.language, /\\?\$\{([^{}]+)\}/g) , {language: {confirm: self.language.ok}, buttons: ['confirm']});
   1.192 +				
   1.193 +				this.ui.element.set('tween', {duration: 2000}).highlight(response.status ? '#e6efc2' : '#f0c2c2');
   1.194 +				(function(){
   1.195 +					this.ui.element.setStyle('overflow', 'hidden').morph({
   1.196 +						opacity: 0,
   1.197 +						height: 0
   1.198 +					}).get('morph').chain(function(){
   1.199 +						this.element.destroy();
   1.200 +						if(!self.upload.list.getElements('li').length)
   1.201 +							self.upload.uploader.fade(0).get('tween').chain(function(){
   1.202 +								self.fillInfo();
   1.203 +							});
   1.204 +					});
   1.205 +				}).delay(5000, this);
   1.206 +			}
   1.207 +
   1.208 +		});
   1.209 +
   1.210 +		this.swf = new Swiff.Uploader({
   1.211 +			id: 'SwiffFileManagerUpload',
   1.212 +			path: this.options.assetBasePath+'Swiff.Uploader.swf',
   1.213 +			queued: false,
   1.214 +			target: this.upload.button,
   1.215 +			allowDuplicates: true,
   1.216 +			instantStart: true,
   1.217 +			fileClass: File,
   1.218 +			fileSizeMax: 25 * 1024 * 1024,
   1.219 +			onBrowse: function(){},
   1.220 +			onCancel: function(){},
   1.221 +			zIndex: this.SwiffZIndex || 9999,
   1.222 +			onSelectSuccess: function(){
   1.223 +				self.fillInfo();
   1.224 +				self.info.getElement('h2.filemanager-headline').setStyle('display', 'none');
   1.225 +				self.preview.adopt(self.upload.uploader);
   1.226 +				self.upload.uploader.fade(1);
   1.227 +			},
   1.228 +			onComplete: function(){
   1.229 +				self.load(self.Directory, true);
   1.230 +			},
   1.231 +			onFail: function(error){
   1.232 +				$$(self.upload.button, self.upload.label).dispose();
   1.233 +				new Dialog(new Element('div', {html: self.language.flash[error] || self.language.flash.flash}), {language: {confirm: self.language.ok}, buttons: ['confirm']});
   1.234 +			}
   1.235 +		});
   1.236 +	}
   1.237 +	
   1.238 +});
   1.239 \ No newline at end of file