You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2011/08/20 03:02:08 UTC
[PATCH 4/4] addresses: make creation from HTML UI work
From: David Lutterkort <lu...@redhat.com>
Signed-off-by: David Lutterkort <lu...@redhat.com>
---
server/public/javascripts/application.js | 9 +++++++++
server/server.rb | 2 +-
server/views/addresses/_address.html.haml | 6 ++++++
server/views/addresses/index.html.haml | 12 +++---------
4 files changed, 19 insertions(+), 10 deletions(-)
create mode 100644 server/views/addresses/_address.html.haml
diff --git a/server/public/javascripts/application.js b/server/public/javascripts/application.js
index 2e3e82b..e82ea76 100644
--- a/server/public/javascripts/application.js
+++ b/server/public/javascripts/application.js
@@ -132,3 +132,12 @@ function create_rule_source_field(name, label, hint)
$(html).insertBefore("#new_rule_form_fields")
}
+
+function create_address(url)
+{
+ $.post(url, function(data) {
+ var ul = $('#address_list')
+ ul.append($(data))
+ ul.listview('refresh')
+ })
+}
diff --git a/server/server.rb b/server/server.rb
index e579eca..78aaffc 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -994,7 +994,7 @@ collection :addresses do
response['Location'] = address_url(@address.id)
respond_to do |format|
format.xml { haml :"addresses/show", :ugly => true }
- format.html { haml :"addresses/show" }
+ format.html { haml :"addresses/_address", :layout => false }
format.json { convert_to_json(:address, @address) }
end
end
diff --git a/server/views/addresses/_address.html.haml b/server/views/addresses/_address.html.haml
new file mode 100644
index 0000000..28420a1
--- /dev/null
+++ b/server/views/addresses/_address.html.haml
@@ -0,0 +1,6 @@
+%li
+ %a{ :href => address_url(@address.id), :'data-ajax' => 'false'}
+ %img{ :class => 'ui-link-thumb', :src => '/images/address.png'}
+ %h3= @address.id
+ %span{ :class => 'ui-li-count'}
+ = @address.instance_id ? @address.instance_id : 'Free'
diff --git a/server/views/addresses/index.html.haml b/server/views/addresses/index.html.haml
index fd48540..9cac99f 100644
--- a/server/views/addresses/index.html.haml
+++ b/server/views/addresses/index.html.haml
@@ -1,15 +1,9 @@
=header "Addresses" do
- %a{ :href => create_address_url, :'data-icon' => :plus, :'data-role' => :button, :class => 'ui-btn-right', :'data-ajax' => "false", :'method' => :post} Create new address
+ %a{ :href => "#", :onclick => "create_address('#{create_address_url}')", :'data-icon' => :plus, :'data-role' => :button, :class => 'ui-btn-right', :'data-ajax' => "false", :method => :post} Create new address
=subheader "#{Thread::current[:provider] || ENV['API_PROVIDER'] || 'default'}"
%div{ :'data-role' => :content, :'data-theme' => 'c'}
- %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' => 'a'}
+ %ul#address_list{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' => 'a'}
%li{ :'data-role' => 'list-divider'}=driver_symbol
- @elements.each do |address|
- %li
- %a{ :href => address_url(address.id), :'data-ajax' => 'false'}
- %img{ :class => 'ui-link-thumb', :src => '/images/address.png'}
- %h3=address.id
- %span{ :class => 'ui-li-count'}=address.instance_id ? address.instance_id : 'Free'
-
-
+ = haml :"addresses/_address", :locals => { :@address => address, :partial => true }
--
1.7.6