[richfaces-svn-commits] JBoss Rich Faces SVN: r6123 - in trunk/sandbox/ui/fileUpload/src/main: templates/org/richfaces and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Feb 15 19:13:50 EST 2008


Author: nbelaevski
Date: 2008-02-15 19:13:50 -0500 (Fri, 15 Feb 2008)
New Revision: 6123

Modified:
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
   trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
Log:
Latest changes for file upload

Modified: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js	2008-02-15 21:14:09 UTC (rev 6122)
+++ trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js	2008-02-16 00:13:50 UTC (rev 6123)
@@ -25,6 +25,18 @@
 		     	new T('Stop')
 		    ]);
 
+FileUploadEntry.cancelControlTemplate = 
+	new E('a',
+			{
+				'style':'text-decoration: none; color:black', 
+				'onclick': function (context) { return 'var entry = FileUploadEntry.getComponent(this); entry.uploadObject.clear(entry); return false;';}, 
+				'className':'upload_anc', 
+				'href':'#'
+			},
+		    [
+		     	new T('Cancel')
+		    ]);
+
 FileUploadEntry.template = 
 	[
 	 new E('table', 
@@ -50,7 +62,7 @@
 					    				 [
 					    				  new E('div',{'className':'upload_font upload_del'}, 
 			    								[
-		    								    	FileUploadEntry.clearControlTemplate
+		    								    	//FileUploadEntry.clearControlTemplate
 		    								    ])
 					    				  ]),
 			    				  new E('td',{'className':'upload_table_td'},
@@ -64,7 +76,7 @@
 
 
 FileUploadEntry.INITIALIZED = "initialized";
-
+FileUploadEntry.READY = "ready";
 FileUploadEntry.UPLOAD_IN_PROGRESS = "progress";
 
 FileUploadEntry.UPLOAD_CANCELED = "canceled";
@@ -74,6 +86,7 @@
 
 FileUploadEntry.LABELS = {};
 FileUploadEntry.LABELS[FileUploadEntry.INITIALIZED] = '';
+FileUploadEntry.LABELS[FileUploadEntry.READY] = '';
 FileUploadEntry.LABELS[FileUploadEntry.UPLOAD_IN_PROGRESS] = 'uploading';
 FileUploadEntry.LABELS[FileUploadEntry.UPLOAD_CANCELED] = 'canceled';
 FileUploadEntry.LABELS[FileUploadEntry.UPLOAD_SUCCESS] = 'done';
@@ -93,17 +106,17 @@
 
 Object.extend(FileUploadEntry.prototype, {
 
-	element: null,
+	fileInput: null,
 	
 	uploadObject: null,
 
 	state: FileUploadEntry.INITIALIZED,
 	
-	initialize: function(element, uploadObject) {
-		this.element = element;
+	initialize: function(fileInput, uploadObject) {
+		this.fileInput = fileInput;
 		this.uploadObject = uploadObject;
 		
-		var content = FileUploadEntry.template.invoke('getContent', {fileName: $F(this.element)}).join('');
+		var content = FileUploadEntry.template.invoke('getContent', {fileName: $F(this.fileInput)}).join('');
 		
 		Element.insert(this.uploadObject.items, content);
 	
@@ -122,9 +135,20 @@
 		this.uploadObject.stopScript(this.uid);
 	},
 	
+	_clearInput: function() {
+		//remove input type="file" element
+		Richfaces.removeNode(this.fileInput);
+		this.fileInput = null;
+	},
+	
+	_clearEntry: function() {
+		Richfaces.removeNode(this.entryElement);
+		this.entryElement = null;
+	},
+	
 	clear: function() {
-		this.element.parentNode.removeChild(this.element);
-		this.entryElement.parentNode.removeChild(this.entryElement);
+		this._clearInput();
+		this._clearEntry();
 	},
 	
 	setState: function(newState) {
@@ -138,10 +162,16 @@
 
 		if (newState == FileUploadEntry.UPLOAD_IN_PROGRESS) {
 			Element.insert(this.controlArea, FileUploadEntry.stopControlTemplate.getContent());
+		} else if (newState == FileUploadEntry.READY) {
+			Element.insert(this.controlArea, FileUploadEntry.cancelControlTemplate.getContent());
 		} else {
 			Element.insert(this.controlArea, FileUploadEntry.clearControlTemplate.getContent());
 		}
 		
+		if (newState == FileUploadEntry.UPLOAD_SUCCESS) {
+			this._clearInput();
+		}
+		
 		this.uploadObject.notifyStateChange(this, oldState);
 	}
 	
@@ -259,8 +289,15 @@
 	},
 	
 	add: function(elt) {
-		this.entries.push(new FileUploadEntry(elt, this));
+		var newEntry = new FileUploadEntry(elt, this);
+		this.entries.push(newEntry);
 		
+		if (this.runUpload) {
+			newEntry.setState(FileUploadEntry.READY);
+		} else {
+			newEntry.setState(FileUploadEntry.INITIALIZED);
+		}
+		
 		var newUpload = elt.cloneNode(true);
 		newUpload.id = this.id + ":file" + (this.idCounter++);
 		$(this.id + ":add1").appendChild(newUpload);
@@ -271,6 +308,7 @@
 	},
 	
 	remove: function(entry) {
+		entry.clear();
 		this.entries = this.entries.without(entry);
 	},
 	
@@ -311,15 +349,15 @@
 	clear: function(entry) {
 		if (entry) {
 			this.remove(entry);
-			entry.clear();
 		} else {
 			//this.entries.length should be evaluated every time!
-			for (var i = 0; i < this.entries.length; i++) {
+			var i = 0;
+			while (i < this.entries.length) {
 				var entry = this.entries[i];
 				if (entry.state != FileUploadEntry.UPLOAD_IN_PROGRESS) {
 					this.remove(entry);
-					i--;
-					entry.clear();
+				} else {
+					i++;
 				}
 			}
 		}
@@ -335,6 +373,28 @@
 		this.progressBar.disable();
 	},
 	
+	_updateEntriesState: function() {
+		var l = this.entries.length;
+		
+		var oldState;
+		var newState;
+		
+		if (this.runUpload) {
+			oldState = FileUploadEntry.INITIALIZED;
+			newState = FileUploadEntry.READY;
+		} else {
+			oldState = FileUploadEntry.READY;
+			newState = FileUploadEntry.INITIALIZED;
+		}
+		
+		for (var i = 0; i < l; i++) {
+			var entry = this.entries[i];
+			if (entry.state == oldState) {
+				entry.setState(newState);
+			}
+		}
+	},
+	
 	notifyStateChange: function(entry, oldState) {
 		var newState = entry.state;
 		
@@ -359,6 +419,8 @@
 				this.setupAutoUpload();
 			}
 			
+			this._updateEntriesState();
+			
 		} else if (newState == FileUploadEntry.UPLOAD_CANCELED ||
 				newState == FileUploadEntry.UPLOAD_TRANSFER_ERROR ||
 				newState == FileUploadEntry.UPLOAD_SERVER_ERROR) {
@@ -368,12 +430,15 @@
 
 			this.runUpload = false;
 			
+			this._updateEntriesState();
+			
 		} else if (newState == FileUploadEntry.UPLOAD_IN_PROGRESS) {
 		
 			this.activeEntry = entry;
 			this.progressBar.setValue(0);
 			this.progressBar.enable();
-			
+		
+			this._updateEntriesState();
 		}
 	},
 	
@@ -401,14 +466,22 @@
 
 		try {
 			var inputs = parentForm.elements;
-			var entryInput = entry.element;
+			var entryInput = entry.fileInput;
 
 			var l = inputs.length;
 			for (var i = 0; i < l; i++) {
 				var input = inputs[i];
-				if ('hidden' != input.type && input != entryInput) {
-					input._name = input.name;
-					input.name = undefined;
+				if (input != entryInput) {
+					if ('hidden' != input.type) {
+						input._name = input.name;
+						input.name = undefined;
+						
+						//TODO for test
+						if ('file' == input.type) {
+							input._disabled = input.disabled;
+							input.disabled = true; 
+						}
+					}
 				}
 			}
 	
@@ -423,10 +496,13 @@
 			
 			for (var i = 0; i < l; i++) {
 				var input = inputs[i];
-				if ('hidden' != input.type && input != entryInput) {
-					if (input._name) {
-						input.name = input._name;
-						input._name = undefined;
+				if ('hidden' != input.type) {
+					input.name = input._name;
+					input._name = undefined;
+					
+					if ('file' == input.type) {
+						input.disabled = input._disabled;
+						input._disabled = undefined; 
 					}
 				}
 			}

Modified: trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx	2008-02-15 21:14:09 UTC (rev 6122)
+++ trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx	2008-02-16 00:13:50 UTC (rev 6123)
@@ -76,7 +76,7 @@
 						 id="#{clientId}:upload3"
 						 onclick="return $('#{clientId}').component.stop();">
 						<a href="#" class="upload_button_selection">
-							<div class="upload_button_content upload_font upload_ico upload_ico_start"
+							<div class="upload_button_content upload_font upload_ico upload_ico_stop"
 								 id="#{clientId}:upload4">
 								<b>Stop</b>
 							</div>




More information about the richfaces-svn-commits mailing list