[Kimchi-devel] [PATCH v2] Add template clone support

Adam King rak at linux.vnet.ibm.com
Thu Apr 3 16:42:16 UTC 2014


Add support for cloning templates to the clone tab.

Signed-off-by: Adam King <rak at linux.vnet.ibm.com>
---
 ui/css/theme-default/template_list.css |  4 ++++
 ui/js/src/kimchi.api.js                | 11 +++++++++++
 ui/js/src/kimchi.template_main.js      | 16 ++++++++++++++--
 ui/pages/tabs/templates.html.tmpl      |  1 +
 4 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/ui/css/theme-default/template_list.css b/ui/css/theme-default/template_list.css
index c0d51e0..df84a8f 100644
--- a/ui/css/theme-default/template_list.css
+++ b/ui/css/theme-default/template_list.css
@@ -253,3 +253,7 @@ template-hidden {
     text-overflow: ellipsis;
     white-space: nowrap;
 }
+
+.processing {
+    cursor: wait;
+}
diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index 0c5c790..376bc86 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -143,6 +143,17 @@ var kimchi = {
         });
     },
 
+    cloneTemplate : function(tem, suc, err) {
+        kimchi.requestJSON({
+            url : kimchi.url + 'templates/' + encodeURIComponent(tem) + "/clone",
+            type : 'POST',
+            contentType : 'application/json',
+            dataType : 'json',
+            success : suc,
+            error : err
+        });
+    },
+
     listTemplates : function(suc, err) {
         kimchi.requestJSON({
             url : kimchi.url + 'templates',
diff --git a/ui/js/src/kimchi.template_main.js b/ui/js/src/kimchi.template_main.js
index 5de6e8c..160ecc8 100644
--- a/ui/js/src/kimchi.template_main.js
+++ b/ui/js/src/kimchi.template_main.js
@@ -25,22 +25,34 @@ kimchi.doListTemplates = function() {
                 listHtml += kimchi.template(templateHtml, value);
             });
             $('#templateList').html(listHtml);
-            kimchi.bindClick();
+            kimchi.templateBindClick();
         } else {
             $('#templateList').html('');
             $('#noTemplates').show();
         }
+        $('html').removeClass('processing');
     }, function(err) {
         kimchi.message.error(err.responseJSON.reason);
+        $('html').removeClass('processing');
     });
 };
 
-kimchi.bindClick = function() {
+kimchi.templateBindClick = function() {
     $('.template-edit').on('click', function(event) {
         var templateName = $(this).data('template');
         kimchi.selectedTemplate = templateName;
         kimchi.window.open("template-edit.html");
     });
+    $('.template-clone').on('click', function(event) {
+        kimchi.selectedTemplate = $(this).data('template');
+        $('html').addClass('processing');
+        kimchi.cloneTemplate(kimchi.selectedTemplate, function() {
+                kimchi.doListTemplates();
+            }, function(err) {
+                kimchi.message.error(err.responseJSON.reason);
+                kimchi.doListTemplates();
+            });
+    });
     $('.template-delete').on('click', function(event) {
         var $template = $(this);
         var settings = {
diff --git a/ui/pages/tabs/templates.html.tmpl b/ui/pages/tabs/templates.html.tmpl
index b6edbaf..6ae6640 100644
--- a/ui/pages/tabs/templates.html.tmpl
+++ b/ui/pages/tabs/templates.html.tmpl
@@ -43,6 +43,7 @@
                 <span class="text">$_("Actions")</span><span class="arrow"></span>
                 <div class="popover actionsheet right-side" style="width: 250px">
                     <a class="button-big template-edit" data-template='{name}'>$_("Edit")</a>
+                    <a class="button-big template-clone" data-template='{name}'>$_("Clone")</a>
                     <a class="button-big red template-delete" data-template='{name}'>$_("Delete")</a>
                 </div>
             </div>
-- 
1.8.1.4




More information about the Kimchi-devel mailing list