You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2010/08/27 14:55:31 UTC

[PATCH core 3/5] Updated views to support assigning instances for EC2

---
 server/public/javascripts/application.js  |   20 +++++++++++++++++++-
 server/views/instances/new.html.haml      |   14 ++++++++++----
 server/views/ip_addresses/index.html.haml |    5 ++++-
 server/views/ip_addresses/new.html.haml   |    9 +++++++++
 4 files changed, 42 insertions(+), 6 deletions(-)
 create mode 100644 server/views/ip_addresses/new.html.haml

diff --git a/server/public/javascripts/application.js b/server/public/javascripts/application.js
index 19ee379..cff7452 100644
--- a/server/public/javascripts/application.js
+++ b/server/public/javascripts/application.js
@@ -31,11 +31,29 @@ $(document).ready(function() {
 
   if ($("select[name=ip_address_id]").length) {
     $.getJSON('/api/ip_addresses', { format : 'json', state : 'unassigned', type : 'public'}, function(data) {
-      $("select[name=ip_address_id]").empty()
+      $("select[name=ip_address_id]").html('<option value="" selected="selected"></option>')
       $.each(data.ip_addresses, function(i, ip_address){
         $("select[name=ip_address_id]").append('<option value="'+ip_address.id+'">'+ip_address.address+'</option>')
       }) 
     }) 
   }
 
+  if ($("select[name=instance_id]").length) {
+    $.getJSON('/api/instances', { format : 'json', state : 'RUNNING'}, function(data) {
+      $("select[name=instance_id]").html('<option value="" selected="selected">No Instance</option>')
+      $.each(data.instances, function(i, instance){
+        $("select[name=instance_id]").append('<option value="'+instance.id+'">'+instance.id+'</option>')
+      }) 
+    }) 
+  }
+
+  if ($("select[name=image_id]").length) {
+    $.getJSON('/api/images', { format : 'json'}, function(data) {
+     $("select[name=image_id]").empty()
+      $.each(data.images, function(i, image){
+        $("select[name=image_id]").append('<option value="'+image.id+'">'+image.description+'</option>')
+      }) 
+    }) 
+  }
+
 })
diff --git a/server/views/instances/new.html.haml b/server/views/instances/new.html.haml
index cf79146..c1a1b8b 100644
--- a/server/views/instances/new.html.haml
+++ b/server/views/instances/new.html.haml
@@ -1,10 +1,16 @@
 %h1 New Instance
 
-%h2= @image.id
-%h3= @image.description
-
 %form{ :action => instances_url, :method => :post }
-  %input{ :name => :image_id, :type => :hidden, :value => @instance.image_id }/
+  - if params[:image_id]
+    %h2= @image.id
+    %h3= @image.description
+    %input{ :name => :image_id, :type => :hidden, :value => @instance.image_id }/
+  - else
+    %p
+      %label
+        Image:
+      %select{ :name => :image_id}
+        %option Loading images...
   %p
     %label
       Instance Name:
diff --git a/server/views/ip_addresses/index.html.haml b/server/views/ip_addresses/index.html.haml
index b0a430b..f66113c 100644
--- a/server/views/ip_addresses/index.html.haml
+++ b/server/views/ip_addresses/index.html.haml
@@ -24,4 +24,7 @@
   %tfoot
     %tr
       %td{:colspan => 5, :style => "text-align:right;"}
-        =link_to 'Create &raquo;', create_ip_address_url, :class => 'post'
+        -if driver_has_feature?(:assign_instance, :ip_addresses)
+          =link_to 'Create &raquo;', url_for('/api/ip_addresses/new')
+        -else
+          =link_to 'Create &raquo;', create_ip_address_url, :class => 'post'
diff --git a/server/views/ip_addresses/new.html.haml b/server/views/ip_addresses/new.html.haml
new file mode 100644
index 0000000..7348d7e
--- /dev/null
+++ b/server/views/ip_addresses/new.html.haml
@@ -0,0 +1,9 @@
+%h1 New IP Address
+
+%form{ :action => '/api/ip_addresses', :method => :post }
+  %p
+    %label
+      Instance to associate:
+    %select{ :name => 'instance_id'}
+      %option Loading...
+    %input{ :type => :submit, :name => "commit", :value => "create" }/
-- 
1.7.2.2