Reviewed-by: Aline Manera <alinefm(a)linux.vnet.ibm.com>
On 02/21/2014 06:10 PM, Rodrigo Trujillo wrote:
The tool sosreport only accepts letters, digits and hyphen in the
name
of the report, non alphanumeric characteres are removed from the file
name and then Kimchi is not able to find the file.
This patch modifies the UI html and js in order to show the right
information and catch the right return error message.
Implements name checking in frontend.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo(a)linux.vnet.ibm.com>
---
ui/js/src/kimchi.report_add_main.js | 21 +++++++++++++--------
ui/pages/i18n.html.tmpl | 2 +-
ui/pages/report-add.html.tmpl | 2 +-
3 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/ui/js/src/kimchi.report_add_main.js b/ui/js/src/kimchi.report_add_main.js
index f893d85..757ee21 100644
--- a/ui/js/src/kimchi.report_add_main.js
+++ b/ui/js/src/kimchi.report_add_main.js
@@ -1,8 +1,4 @@
kimchi.report_add_main = function() {
- var generateReportName = function() {
- return 'report-' + new Date().getTime();
- };
-
var addReportForm = $('#form-report-add');
var submitButton = $('#button-report-add');
var nameTextbox = $('input[name="name"]', addReportForm);
@@ -11,8 +7,12 @@ kimchi.report_add_main = function() {
if(submitButton.prop('disabled')) {
return false;
}
- var reportName = nameTextbox.val() || generateReportName();
- nameTextbox.val(reportName);
+ var reportName = nameTextbox.val();
+ var validator = RegExp("^[A-Za-z0-9-]*$");
+ if (!validator.test(reportName)) {
+ errorMessage.text(i18n['KCHDR6011M']);
+ return false;
+ }
var formData = addReportForm.serializeObject();
errorMessage.text('');
submitButton
@@ -25,8 +25,13 @@ kimchi.report_add_main = function() {
result: result
});
}, function(result) {
- result && result['reason'] &&
- $('#report-error-message').text(result['reason']);
+ if (result['reason']) {
+ var errText = result['reason'];
+ }
+ else {
+ var errText = result['responseJSON']['reason'];
+ }
+ result && $('#report-error-message').text(errText);
submitButton
.text(i18n['KCHDR6006M'])
.prop('disabled', false);
diff --git a/ui/pages/i18n.html.tmpl b/ui/pages/i18n.html.tmpl
index 613b707..eabf897 100644
--- a/ui/pages/i18n.html.tmpl
+++ b/ui/pages/i18n.html.tmpl
@@ -92,7 +92,7 @@ var i18n = {
'KCHDR6008M': "$_("Rename")",
'KCHDR6009M': "$_("Remove")",
'KCHDR6010M': "$_("Download")",
-
+ 'KCHDR6011M': "$_("Report name should contain only letters, digits
and/or hyphen ('-').")",
'KCHVM6001M': "$_("This will delete the virtual machine and its
virtual disks. This operation cannot be undone. Would you like to continue?")",
diff --git a/ui/pages/report-add.html.tmpl b/ui/pages/report-add.html.tmpl
index 2a962d4..383175f 100644
--- a/ui/pages/report-add.html.tmpl
+++ b/ui/pages/report-add.html.tmpl
@@ -38,7 +38,7 @@
</h2>
<div class="field">
<span>
- $_("The name used to identify the report. If omitted, a
name will be chosen based on current time. Name can contain: letters, digits,
\"-\", \"_\", or \".\".")
+ $_("The name used to identify the report. If omitted, a
name will be chosen based on current time. Name can contain: letters, digits and hyphen
(\"-\").")
</span>
<input type="text" class="text"
id="report-name-textbox" name="name" />
<span id="report-error-message"></span>