On 2014年06月26日 21:46, Sheldon wrote:
On 06/26/2014 02:47 PM, lvroyce(a)linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
>
> Add function for cdrom and disk form validation,
> so that cdrom will not be created when no path given.
>
> Signed-off-by: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
> ---
> ui/js/src/kimchi.guest_storage_add.main.js | 28
> ++++++++++++++++++++++++++++
> ui/pages/i18n.json.tmpl | 7 +++++--
> 2 files changed, 33 insertions(+), 2 deletions(-)
>
> diff --git a/ui/js/src/kimchi.guest_storage_add.main.js
> b/ui/js/src/kimchi.guest_storage_add.main.js
> index 80045d3..a7e4c4c 100644
> --- a/ui/js/src/kimchi.guest_storage_add.main.js
> +++ b/ui/js/src/kimchi.guest_storage_add.main.js
> @@ -135,6 +135,25 @@ kimchi.guest_storage_add_main = function() {
> });
> });
>
> + var validateCDROM = function(settings) {
> + if (/(^\/.*)$/.test(settings['path']))
the RE looks like strangely. But It can works well.
seem you you can check the path is starts with "/"
/^(\/.*)+$/.test(settings['path'] )
My fault, I put bracket in the wrong
place.
or
/^(\/.*)$/.test(settings['path'] )
or
/^\//.test
?
> + return true;
> + else {
> + kimchi.message.error.code('KCHVMSTOR0001E');
> + return false;
> + }
> + }
> +
> + var validateDisk = function(settings) {
> + if (settings['pool'] && settings['vol'])
> + return true;
> + else {
> + kimchi.message.error.code('KCHVMSTOR0002E');
> + return false;
> + }
> + }
> +
> + validator = {cdrom: validateCDROM, disk: validateDisk};
> var submitForm = function(event) {
> if (submitButton.prop('disabled')) {
> return false;
> @@ -155,6 +174,15 @@ kimchi.guest_storage_add_main = function() {
> settings[$(c).attr('name')] = $(c).val();
> }
> });
> + // Validate form for cdrom and disk
> + validateSpecifiedForm = validator[settings['type']];
> + if (!validateSpecifiedForm(settings)) {
> + $(submitButton).prop('disabled', false);
> + $.each([submitButton, nameTextbox, pathTextbox,
> poolTextbox, volTextbox], function(i, c) {
> + $(c).prop('disabled', false);
> + });
> + return false;
> + }
> $(submitButton).addClass('loading').text(i18n['KCHVMCD6003M']);
>
> kimchi.addVMStorage(settings, function(result) {
> diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl
> index ce23bc4..d765cf2 100644
> --- a/ui/pages/i18n.json.tmpl
> +++ b/ui/pages/i18n.json.tmpl
> @@ -162,5 +162,8 @@
> "KCHPOOL6009E": "$_("This is not a valid Server Name or IP.
> please, modify it.")",
> "KCHPOOL6010M": "$_("Looking for available partitions
...")",
> "KCHPOOL6011M": "$_("No available partitions
found.")",
> - "KCHPOOL6012M": "$_("This storage pool is not persistent.
> Instead of deactivate, this action will permanently delete it. Would
> you like to continue?")"
> -}
> \ No newline at end of file
> + "KCHPOOL6012M": "$_("This storage pool is not persistent.
> Instead of deactivate, this action will permanently delete it. Would
> you like to continue?")",
> +
> + "KCHVMSTOR0001E": "$_("CDROM path need to be a valid local
path
> and cannot be blank.")",
> + "KCHVMSTOR0002E": "$_("Disk pool or volume cannot be
blank.")"
> +}
just a question about the difference among "cannot", "can not" and
"can't"? :-)
I check the dictionary, seems they are same.