[Kimchi-devel] [PATCH] [Kimchi] Fix issue #1069: Allow user specifies the Template name when creating it

Aline Manera alinefm at linux.vnet.ibm.com
Thu Jan 5 16:47:50 UTC 2017


When user creates a Template, now he/she can specify the Template name
otherwise, it will be automatically chosen.

The Template name is not taken in count when the user selected more than
one Image Template. In that case, a name will be automatically chosen
for each Image Template selected.

Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.template_add_main.js | 24 +++++++++++++++++++++++-
 ui/pages/template-add.html.tmpl       | 10 +++++++++-
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/ui/js/src/kimchi.template_add_main.js b/ui/js/src/kimchi.template_add_main.js
index 64d67c1..89d86e3 100644
--- a/ui/js/src/kimchi.template_add_main.js
+++ b/ui/js/src/kimchi.template_add_main.js
@@ -1,7 +1,7 @@
 /*
  * Project Kimchi
  *
- * Copyright IBM Corp, 2013-2016
+ * Copyright IBM Corp, 2013-2017
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -255,6 +255,13 @@ kimchi.template_add_main = function() {
         $('#iso-file').val('');
         $('#iso-url').val('');
 
+        if (checkedLength && checkedLength != 1) {
+            $('#tmpl-name').val('');
+            $('#tmpl-name').attr('disabled', 'disabled');
+        } else {
+            $('#tmpl-name').removeAttr('disabled');
+        }
+
         $('#btn-template-file-create').attr('disabled', 'disabled').css('display', 'none'); // 1 - Folder path
         $('#btn-template-local-iso-create').attr('disabled', 'disabled').css('display', 'inline-block'); // 2 - Selected ISOs
         $('#btn-template-netboot-create').attr('disabled', 'disabled').css('display', 'none'); // 3 - Netboot
@@ -271,9 +278,15 @@ kimchi.template_add_main = function() {
     });
 
     $('#btn-template-netboot-create').click(function() {
+        var tmpl_name = $('#tmpl-name').val();
         var data = {
             "source_media": {"type": "netboot"}
         };
+
+        if (tmpl_name && tmpl_name != "") {
+            data['name'] = tmpl_name
+        }
+
         addTemplate(data, function() {
             $('#btn-template-netboot-create').text(i18n['KCHAPI6005M']);
             $('#btn-template-netboot-create').prop('disabled', false);
@@ -281,6 +294,7 @@ kimchi.template_add_main = function() {
     });
 
     $('#btn-template-local-iso-create').click(function() {
+        var tmpl_name = $('#tmpl-name').val();
         $('input', '#iso-file-box').prop('disabled', true);
         $('#btn-template-local-iso-create').text(i18n['KCHAPI6008M']);
         $('#btn-template-local-iso-create').prop('disabled', true);
@@ -288,6 +302,7 @@ kimchi.template_add_main = function() {
     });
 
     $('#btn-template-file-create').click(function() {
+        var tmpl_name = $('#tmpl-name').val();
         var isoFile = $('#iso-file').val();
         $('input', '#iso-file-box').prop('disabled', true);
         $('#btn-template-file-create').text(i18n['KCHAPI6008M']);
@@ -299,6 +314,9 @@ kimchi.template_add_main = function() {
         var data = {
             "source_media": {"type": "disk", "path": isoFile}
         };
+        if (tmpl_name && tmpl_name != "") {
+            data['name'] = tmpl_name
+        }
         addTemplate(data, function() {
             $('input', '#iso-file-box').prop('disabled', false);
             $('#btn-template-file-create').text(i18n['KCHAPI6005M']);
@@ -440,11 +458,15 @@ kimchi.template_add_main = function() {
             var length = 0;
             var successNum = 0;
             var addTemplate = function(isoInfo) {
+                var tmpl_name = $('#tmpl-name').val();
                 var data = {
                     "os_distro": isoInfo.os_distro,
                     "os_version": isoInfo.os_version,
                     "source_media": {"type": "disk", "path": isoInfo.path}
                 };
+                if (length == 1 && tmpl_name && tmpl_name != "") {
+                    data['name'] = tmpl_name
+                }
                 kimchi.createTemplate(data, function() {
                     successNum++;
                     $('input[value="' + isoInfo.isoId + '"]').prop('checked', false);
diff --git a/ui/pages/template-add.html.tmpl b/ui/pages/template-add.html.tmpl
index 4028f90..007511f 100644
--- a/ui/pages/template-add.html.tmpl
+++ b/ui/pages/template-add.html.tmpl
@@ -1,7 +1,7 @@
 #*
  * Project Kimchi
  *
- * Copyright IBM Corp, 2013-2016
+ * Copyright IBM Corp, 2013-2017
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -30,6 +30,14 @@
             <div class="modal-body">
                 <div class="template-modal-container">
                     <div id="alert-modal-container"></div>
+                    <div class="form-group">
+                        <label for="tmpl-name">$_("Template Name")</label>
+                        <input type="text" class="form-control" name="name" id="tmpl-name" />
+                        <p class="help-block"><i class="fa fa-info-circle"></i> $_("The name used to identify the template. If omitted, a name will be automatically chosen.")
+                        </p>
+                        <p class="help-block"><i class="fa fa-info-circle"></i> $_("When selecting more than one Image Template, a name will be automatically chosen for each Image Template selected.")
+                        </p>
+                    </div>
                     <div>
                         <h5>$_("Where is the source media for this template? ")</h5>
                         <input type="radio" checked="checked" name="iso-source" id="image-src" value="image-src" class="wok-radio">
-- 
2.7.4



More information about the Kimchi-devel mailing list