Merge "Copy the selected file name in the object name field."
This commit is contained in:
commit
56d71e2249
@ -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() {
|
datepicker: function() {
|
||||||
var startDate = $('input#id_start').datepicker()
|
var startDate = $('input#id_start').datepicker()
|
||||||
.on('changeDate', function(ev) {
|
.on('changeDate', function(ev) {
|
||||||
@ -142,6 +170,7 @@ horizon.addInitFunction(function () {
|
|||||||
horizon.forms.handle_snapshot_source();
|
horizon.forms.handle_snapshot_source();
|
||||||
horizon.forms.handle_volume_source();
|
horizon.forms.handle_volume_source();
|
||||||
horizon.forms.handle_image_source();
|
horizon.forms.handle_image_source();
|
||||||
|
horizon.forms.handle_object_upload_source();
|
||||||
horizon.forms.datepicker();
|
horizon.forms.datepicker();
|
||||||
|
|
||||||
// Bind event handlers to confirm dangerous actions.
|
// Bind event handlers to confirm dangerous actions.
|
||||||
|
@ -81,7 +81,9 @@ class UploadObject(forms.SelfHandlingForm):
|
|||||||
path = forms.CharField(max_length=255,
|
path = forms.CharField(max_length=255,
|
||||||
required=False,
|
required=False,
|
||||||
widget=forms.HiddenInput)
|
widget=forms.HiddenInput)
|
||||||
|
object_file = forms.FileField(label=_("File"),
|
||||||
|
required=False,
|
||||||
|
allow_empty_file=True)
|
||||||
name = forms.CharField(max_length=255,
|
name = forms.CharField(max_length=255,
|
||||||
label=_("Object Name"),
|
label=_("Object Name"),
|
||||||
help_text=_("Slashes are allowed, and are treated "
|
help_text=_("Slashes are allowed, and are treated "
|
||||||
@ -91,9 +93,6 @@ class UploadObject(forms.SelfHandlingForm):
|
|||||||
attrs={"ng-model": "name",
|
attrs={"ng-model": "name",
|
||||||
"not-blank": ""}
|
"not-blank": ""}
|
||||||
))
|
))
|
||||||
object_file = forms.FileField(label=_("File"),
|
|
||||||
required=False,
|
|
||||||
allow_empty_file=True)
|
|
||||||
container_name = forms.CharField(widget=forms.HiddenInput())
|
container_name = forms.CharField(widget=forms.HiddenInput())
|
||||||
|
|
||||||
def _set_object_path(self, data):
|
def _set_object_path(self, data):
|
||||||
|
Loading…
Reference in New Issue
Block a user