Author: dsvyatobatsko
Date: 2008-02-20 06:57:05 -0500 (Wed, 20 Feb 2008)
New Revision: 6192
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:
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-20
11:42:22 UTC (rev 6191)
+++
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-02-20
11:57:05 UTC (rev 6192)
@@ -285,8 +285,12 @@
options: null,
runUpload: false,
-
- initialize: function(id, stopScript, progressBarId, options) {
+
+ classes: null,
+
+ maxFileBatchSize: 5,
+
+ initialize: function(id, stopScript, progressBarId, classes, options) {
this.id = id;
this.element = $(this.id);
//this.progressBarId = progressBarId;
@@ -299,11 +303,12 @@
this.iframe = $(this.id + "_iframe");
this.items = $(this.id + ":fileItems");
+ this.classes = classes;
+
this.options = options || {};
-
this.setupAutoUpload();
},
-
+
prepareProgressBar: function () {
this.progressBar.setValue(0);
Element.show(this._progressBar);
@@ -318,17 +323,17 @@
setupAutoUpload: function() {
this.runUpload = this.options.autoUpload;
},
-
+
add: function(elt) {
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);
@@ -336,13 +341,17 @@
if (this.runUpload) {
this.upload();
}
+
+ this.disableAddButton(this.entries.length > this.maxFileBatchSize);
},
-
+
remove: function(entry) {
entry.clear();
this.entries = this.entries.without(entry);
+
+ this.disableAddButton(this.entries.length > this.maxFileBatchSize);
},
-
+
_selectEntryForUpload: function() {
var l = this.entries.length;
for (var i = 0; i < l; i++) {
@@ -358,7 +367,7 @@
upload: function() {
this.runUpload = true;
-
+
if (!this.activeEntry) {
//no upload is being run now
@@ -371,7 +380,7 @@
stop: function() {
this.runUpload = false;
-
+
if (this.activeEntry) {
this.activeEntry.stop();
}
@@ -396,8 +405,38 @@
if (this.entries.length == 0) {
this.setupAutoUpload();
}
+
+ this.disableAddButton(this.entries.length > this.maxFileBatchSize);
},
+ disableCleanButton: function(disabled) {
+ if(disabled) {
+ $(this.id + ":clean1").onclick = function() {return false;};
+ } else {
+ $(this.id + ":clean1").onclick = function() {return
this.clear();}.bind(this);
+ }
+
+ $(this.id+":clean1").className = (disabled? this.classes.CLEAN.DISABLED :
this.classes.CLEAN.ENABLED);
+ $(this.id+":clean2").className = (disabled?
this.classes.CLEAN_CONTENT.DISABLED : this.classes.CLEAN_CONTENT.ENABLED);
+ },
+
+ disableAddButton: function(disabled) {
+ $(this.id+":file").disabled = disabled;
+ $(this.id+":add1").className = (disabled? this.classes.ADD.DISABLED :
this.classes.ADD.ENABLED);
+ $(this.id+":add2").className = (disabled?
this.classes.ADD_CONTENT.DISABLED : this.classes.ADD_CONTENT.ENABLED);
+ },
+
+ disableUploadButton: function (disabled) {
+ if(disabled) {
+ $(this.id + ":upload1").onclick = function() {return false;};
+ } else {
+ $(this.id + ":upload1").onclick = function() {return
this.upload();}.bind(this);
+ }
+
+ $(this.id + ":upload1").className = (disabled?
this.classes.UPDATE.DISABLED : this.classes.UPDATE.ENABLED);
+ $(this.id + ":upload2").className = (disabled?
this.classes.UPDATE_CONTENT.DISABLED : this.classes.UPDATE_CONTENT.ENABLED);
+ },
+
_endUpload: function() {
this.activeEntry = null;
//this.progressBar.setValue(100);
@@ -450,9 +489,10 @@
//has been requested to stop by user
this.setupAutoUpload();
}
-
+
this._updateEntriesState();
-
+ this.disableUploadButton(false);
+
} else if (newState == FileUploadEntry.UPLOAD_CANCELED ||
newState == FileUploadEntry.UPLOAD_TRANSFER_ERROR ||
newState == FileUploadEntry.UPLOAD_SERVER_ERROR) {
@@ -463,7 +503,9 @@
this.runUpload = false;
this._updateEntriesState();
-
+
+ this.disableUploadButton(false);
+
} else if (newState == FileUploadEntry.UPLOAD_IN_PROGRESS) {
this.activeEntry = entry;
@@ -471,6 +513,8 @@
this.progressBar.enable();
this._updateEntriesState();
+
+ this.disableUploadButton(true);
}
},
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-20
11:42:22 UTC (rev 6191)
+++
trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx 2008-02-20
11:57:05 UTC (rev 6192)
@@ -103,7 +103,42 @@
<span>
<script type="text/javascript">
- new FileUpload('#{clientId}', #{this:getStopScript(context, component)},
'#{this:getProgressBarId(context, component)}');
+ FileUpload.CLASSES = {
+ ADD : {
+ ENABLED : 'upload_button upload_font
#{component.attributes["addStyle"]}',
+ DISABLED : 'upload_button_dis upload_font
#{component.attributes["addStyleDisabled"]}'
+ },
+ ADD_CONTENT : {
+ ENABLED : 'upload_button_content upload_font upload_ico upload_ico_add
#{component.attributes["addStyle"]}',
+ DISABLED : 'upload_button_content upload_font upload_ico upload_ico_add_dis
#{component.attributes["addStyleDisabled"]}'
+ },
+ UPDATE : {
+ ENABLED : 'upload_button upload_font
#{component.attributes["uploadStyle"]}',
+ DISABLED : 'upload_button_dis upload_font
#{component.attributes["uploadStyleDisabled"]}'
+ },
+ UPDATE_CONTENT : {
+ ENABLED : 'upload_button_content upload_font upload_ico upload_ico_start
#{component.attributes["uploadStyle"]}',
+ DISABLED : 'upload_button_content upload_font upload_ico upload_ico_start_dis
#{component.attributes["uploadStyleDisabled"]}'
+ },
+ CANCEL : {
+ ENABLED : 'upload_button upload_font
#{component.attributes["cancelStyle"]}',
+ DISABLED : 'upload_button_dis upload_font
#{component.attributes["cancelStyleDisabled"]}'
+ },
+ CANCEL_CONTENT : {
+ ENABLED : 'upload_button_content upload_font upload_ico upload_ico_stop
#{component.attributes["cancelStyle"]}',
+ DISABLED : 'upload_button_content upload_font upload_ico upload_ico_stop_dis
#{component.attributes["cancelStyleDisabled"]}'
+ },
+ CLEAN : {
+ ENABLED : 'upload_button upload_font
#{component.attributes["cleanStyle"]}',
+ DISABLED : 'upload_button_dis upload_font
#{component.attributes["cleanStyleDisabled"]}'
+ },
+ CLEAN_CONTENT : {
+ ENABLED : 'upload_button_content upload_font upload_ico upload_ico_clear
#{component.attributes["cleanStyle"]}',
+ DISABLED : 'upload_button_content upload_font upload_ico upload_ico_clear_dis
#{component.attributes["cleanStyleDisabled"]}'
+ }
+ };
+
+ new FileUpload('#{clientId}', #{this:getStopScript(context, component)},
'#{this:getProgressBarId(context, component)}', FileUpload.CLASSES);
</script>
</span>