Merge "Copy the selected file name in the object name field."

This commit is contained in:
Jenkins 2014-07-01 14:26:12 +00:00 committed by Gerrit Code Review
commit 56d71e2249
2 changed files with 32 additions and 4 deletions

View File

@ -56,6 +56,34 @@ horizon.forms = {
});
},
/**
* In the container's upload object form, copy the selected file name in the
* object name field if the field is empty. The filename string is stored in
* the input as an attribute "filename". The value is used as comparison to
* compare with the value of the new filename string.
*/
handle_object_upload_source: function() {
$("div.table_wrapper, #modal_wrapper").on("change", "input#id_object_file", function(evt) {
if (typeof($(this).attr("filename")) == 'undefined') {
$(this).attr("filename", "");
}
var $form = $(this).closest("form");
var $obj_name = $form.find("input#id_name");
var $fullPath = $(this).val();
var $startIndex = ($fullPath.indexOf('\\') >= 0 ? $fullPath.lastIndexOf('\\') : $fullPath.lastIndexOf('/'));
var $filename = $fullPath.substring($startIndex);
if ($filename.indexOf('\\') === 0 || $filename.indexOf('/') === 0) {
$filename = $filename.substring(1);
}
if (typeof($obj_name.val()) == 'undefined' || $(this).attr("filename").localeCompare($obj_name.val()) == 0) {
$obj_name.val($filename);
$(this).attr("filename", $filename);
}
});
},
datepicker: function() {
var startDate = $('input#id_start').datepicker()
.on('changeDate', function(ev) {
@ -142,6 +170,7 @@ horizon.addInitFunction(function () {
horizon.forms.handle_snapshot_source();
horizon.forms.handle_volume_source();
horizon.forms.handle_image_source();
horizon.forms.handle_object_upload_source();
horizon.forms.datepicker();
// Bind event handlers to confirm dangerous actions.

View File

@ -81,7 +81,9 @@ class UploadObject(forms.SelfHandlingForm):
path = forms.CharField(max_length=255,
required=False,
widget=forms.HiddenInput)
object_file = forms.FileField(label=_("File"),
required=False,
allow_empty_file=True)
name = forms.CharField(max_length=255,
label=_("Object Name"),
help_text=_("Slashes are allowed, and are treated "
@ -91,9 +93,6 @@ class UploadObject(forms.SelfHandlingForm):
attrs={"ng-model": "name",
"not-blank": ""}
))
object_file = forms.FileField(label=_("File"),
required=False,
allow_empty_file=True)
container_name = forms.CharField(widget=forms.HiddenInput())
def _set_object_path(self, data):