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 2012/02/29 14:57:12 UTC

[PATCH core 4/5] CIMI: Moved :new operations to modal dialogs

From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 clients/cimi/lib/entities/machine.rb         |   19 ++++-----
 clients/cimi/lib/entities/machine_admin.rb   |    6 +--
 clients/cimi/public/app.js                   |   20 +++++++++
 clients/cimi/views/machine_admins/index.haml |   44 +++++++++++++--------
 clients/cimi/views/machine_admins/new.haml   |   54 -------------------------
 clients/cimi/views/machines/index.haml       |   45 +++++++++++++++++----
 clients/cimi/views/machines/new.haml         |   55 --------------------------
 7 files changed, 93 insertions(+), 150 deletions(-)
 delete mode 100644 clients/cimi/views/machine_admins/new.haml
 delete mode 100644 clients/cimi/views/machines/new.haml

diff --git a/clients/cimi/lib/entities/machine.rb b/clients/cimi/lib/entities/machine.rb
index 256ae77..67e5802 100644
--- a/clients/cimi/lib/entities/machine.rb
+++ b/clients/cimi/lib/entities/machine.rb
@@ -15,7 +15,14 @@
 
 class CIMI::Frontend::Machine < CIMI::Frontend::Entity
 
-  get '/cimi/machines/new' do
+  get '/cimi/machines/:id' do
+    machine_xml = get_entity('machines', params[:id], credentials)
+    @machine= CIMI::Model::Machine.from_xml(machine_xml)
+    haml :'machines/show'
+  end
+
+  get '/cimi/machines' do
+    # We need to include this stuff for new Machine Form
     machine_image_xml = get_entity_collection('machine_images', credentials)
     @machine_images = CIMI::Model::MachineImageCollection.from_xml(machine_image_xml)
     machine_conf_xml = get_entity_collection('machine_configurations', credentials)
@@ -27,16 +34,6 @@ class CIMI::Frontend::Machine < CIMI::Frontend::Entity
     rescue RestClient::InternalServerError
       @machine_admins = []
     end
-    haml :'machines/new'
-  end
-
-  get '/cimi/machines/:id' do
-    machine_xml = get_entity('machines', params[:id], credentials)
-    @machine= CIMI::Model::Machine.from_xml(machine_xml)
-    haml :'machines/show'
-  end
-
-  get '/cimi/machines' do
     machine_xml = get_entity_collection('machines', credentials)
     @machines = CIMI::Model::MachineCollection.from_xml(machine_xml)
     haml :'machines/index'
diff --git a/clients/cimi/lib/entities/machine_admin.rb b/clients/cimi/lib/entities/machine_admin.rb
index bfa49ad..027a9d0 100644
--- a/clients/cimi/lib/entities/machine_admin.rb
+++ b/clients/cimi/lib/entities/machine_admin.rb
@@ -37,13 +37,11 @@ class CIMI::Frontend::MachineAdmin < CIMI::Frontend::Entity
 
   get '/cimi/machine_admins' do
     machine_admin_xml = get_entity_collection('machine_admins', credentials)
-    puts machine_admin_xml
     @machine_admins = CIMI::Model::MachineAdminCollection.from_xml(machine_admin_xml)
-    puts @machine_admins.inspect
     haml :'machine_admins/index'
   end
 
- post '/cimi/machine_admin' do
+  post '/cimi/machine_admin' do
     machine_admin_xml = Nokogiri::XML::Builder.new do |xml|
       xml.MachineAdmin(:xmlns => CIMI::Frontend::CMWG_NAMESPACE) {
         xml.name params[:machine_admin][:name]
@@ -60,7 +58,7 @@ class CIMI::Frontend::MachineAdmin < CIMI::Frontend::Entity
       redirect "/cimi/machine_admins/#{machine_admin.name}", 302
     rescue => e
       flash[:error] = "Machine Admin could not be created: #{e.message}"
-      redirect :back
+      redirect(back)
     end
   end
 
diff --git a/clients/cimi/public/app.js b/clients/cimi/public/app.js
index 09acbd5..4e0a8aa 100644
--- a/clients/cimi/public/app.js
+++ b/clients/cimi/public/app.js
@@ -15,3 +15,23 @@ function toggleConfig(driver) {
   $('#providerModal').modal('show');
   return false;
 }
+
+function postModalForm(btn, id) {
+  $('div#'+id+' form').submit(function(e) {
+    e.preventDefault();
+    var frm = $(this);
+    $(btn).button('loading');
+    $.ajax({
+      type : 'POST',
+      url : frm.attr('action'),
+      data : frm.serialize(),
+      success: function(data) {
+        $(btn).button('Complete!');
+        $('div#'+id).modal('hide');
+        location.reload();
+      }
+    })
+    
+  }).submit()
+  return false;
+}
diff --git a/clients/cimi/views/machine_admins/index.haml b/clients/cimi/views/machine_admins/index.haml
index cb04af6..a8bab3c 100644
--- a/clients/cimi/views/machine_admins/index.haml
+++ b/clients/cimi/views/machine_admins/index.haml
@@ -13,7 +13,27 @@
     %a{ :href => "#{@machine_admins.uri}?format=xml", :class => 'label warning' } XML
     %a{ :href => "#{@machine_admins.uri}?format=json", :class => 'label warning' } JSON
   %p
-    %a{ :href => '/cimi/machine_admins/new', :class => 'btn info'} New Machine Admin
+    %a{ :href => '#adminModal', :class => 'btn btn-primary', :'data-toggle' => :modal } New Machine Admin
+
+  %div{ :id => :adminModal, :class => 'modal hide fade' }
+    .modal-header
+      %h3 Create mew MachineAdmin entity
+    .modal-body
+      %form{ :action => "/cimi/machine_admin", :method => :post }
+        %fieldset
+          .control-group
+            %label.control-label{ :for => 'machine_admin[name]' } Key Name
+            .controls
+              %input{ :type => :text, :name => 'machine_admin[name]' }
+            %label.control-label{ :for => 'machine_admin[description]' } Key Description
+            .controls
+              %input{ :type => :text, :name => 'machine_admin[description]' }
+            %label.control-label{ :for => 'machine_admin[key]' } PEM data
+            .controls
+              %textarea{:name => 'machine_admin[key]', :class => 'input-xlarge', :rows => 3}
+    .modal-footer
+      %a{ :href => '#', :class => 'btn btn-primary', :'data-loading-text' => 'Creating MachineAdmin...', :onclick => "postModalForm(this, 'adminModal')"} Continue
+      %a{ :href => '#', :class => 'btn', :'data-dismiss' => 'modal'} Cancel
 
 %blockquote
   %p 
@@ -21,24 +41,14 @@
     entities within a Provider. This entity can be used to locate and create
     MachineAdmins.
 
+%h3 MachineAdminCollection
+
 %ul
   - @machine_admins.machine_admins.each do |conf|
     %li
       %a{ :href => "/cimi/machine_admins/#{conf.href.split('/').last}"}=conf.href.split('/').last
 
-- if @machine_admins.machine_admins.empty?
-  .alert-message.block-message.warning
-    %p
-      There are no MachineAdmin entities defined for this collection.
-    .alert_actions
-      %a{ :href => '/cimi/machine_admins/new', :class => 'btn'} Create new
-
-%h3 Collection details
-
-%dl
-  %dt URI
-  %dd=@machine_admins.uri
-  %dt Description
-  %dd=@machine_admins.description
-  %dt Created
-  %dd=@machine_admins.created
+- details 'Collection details' do
+  - row 'URI', @machine_admins.uri
+  - row 'Description', @machine_admins.description
+  - row 'Created', @machine_admins.created
diff --git a/clients/cimi/views/machine_admins/new.haml b/clients/cimi/views/machine_admins/new.haml
deleted file mode 100644
index b969740..0000000
--- a/clients/cimi/views/machine_admins/new.haml
+++ /dev/null
@@ -1,54 +0,0 @@
-- @title="New MachineAdmin"
-
-- content_for :breadcrumb do
-  %ul.breadcrumb
-    %li
-      %a{ :href => "/cimi/cloudEntryPoint"} CloudEntryPoint
-      %span.divider="/"
-    %li
-      %a{ :href => "/cimi/machine_admins"} MachineAdminCollection
-      %span.divider="/"
-    %li.active New MachineAdmin
-
-
-%form{ :action => "/cimi/machine_admin", :method => :post }
-  %fieldset
-    %legend Create new MachineAdmin
-    %div.clearfix
-      %label{ :for => 'machine_admin[name]' }
-        Name
-      %div.input
-        %input{ :type => :text, :name => 'machine_admin[name]' }
-    %div.clearfix
-      %label{ :for => 'machine_admin[description]' }
-        Description
-      %div.input
-        %input{ :type => :text, :name => 'machine_admin[description]' }
-    %div.clearfix
-      %label{ :for => 'machine_admin[username]' }
-        Username
-      %div.input
-        %input{ :type => :text, :name => 'machine_admin[username]', :value => "root" }
-        %span.help-block
-          %span.label.info NOTE
-          Property could not be supported by cloud provider
-    %div.clearfix
-      %label{ :for => 'machine_admin[password]' }
-        Password
-      %div.input
-        %input{ :type => :text, :name => 'machine_admin[password]' }
-        %span.help-block
-          %span.label.info NOTE
-          Property could not be supported by cloud provider
-    %div.clearfix
-      %label{ :for => 'machine_admin[key]' }
-        Key
-      %div.input
-        %textarea.xlarge{ :name => 'machine_admin[key]', :rows => 3 }
-        %span.help-block
-          %span.label.info NOTE
-          Property could not be supported by cloud provider
-    %div.actions
-      %input{ :type => :submit, :class => 'btn primary', :value => "Create MachineAdmin" }
-      %button{ :type => :reset, :class => 'btn' } Reset
-
diff --git a/clients/cimi/views/machines/index.haml b/clients/cimi/views/machines/index.haml
index 3f436ac..735bd2c 100644
--- a/clients/cimi/views/machines/index.haml
+++ b/clients/cimi/views/machines/index.haml
@@ -13,7 +13,38 @@
     %a{ :href => "#{@machines.uri}?format=xml", :class => 'label warning' } XML
     %a{ :href => "#{@machines.uri}?format=json", :class => 'label warning' } JSON
   %p
-    %a{ :href => '/cimi/machines/new', :class => 'btn info'} New machine 
+    %a{ :href => '#machineModal', :class => 'btn btn-primary', :'data-toggle' => :modal} New Machine 
+
+  %div{ :id => :machineModal, :class => 'modal hide fade' }
+    .modal-header
+      %h3 Create mew Machine entity
+    .modal-body
+      %form{ :action => "/cimi/machines", :method => :post }
+        %fieldset
+          .control-group
+            %label.control-label{ :for => 'machine[name]' } Machine Name
+            .controls
+              %input{ :type => :text, :name => 'machine[name]' }
+            %label.control-label{ :for => 'machine[machine_image]' } Machine Image
+            .controls
+              %select{ :name => 'machine[machine_image]' }
+                - @machine_images.machine_images.each do |image|
+                  %option{ :value => image.href }=href_to_id(image.href)
+            %label.control-label{ :for => 'machine[machine_configuration]' } Machine Configuration
+            .controls
+              %select{ :name => 'machine[machine_configuration]' }
+                - @machine_configurations.machine_configurations.each do |configuration|
+                  %option{ :value => configuration.href }=href_to_id(configuration.href)
+            - unless @machine_admins.kind_of?(Array)
+              %label.control-label{ :for => 'machine[machine_admin]' } Machine Admin
+              .controls
+                %select{ :name => 'machine[machine_admin]' }
+                  - @machine_admins.machine_admins.each do |admin|
+                    %option{ :value => admin.href }=href_to_id(admin.href)
+    .modal-footer
+      %a{ :href => '#', :class => 'btn btn-primary', :'data-loading-text' => 'Creating MachineAdmin...', :onclick => "postModalForm(this, 'machineModal')"} Continue
+      %a{ :href => '#', :class => 'btn', :'data-dismiss' => 'modal'} Cancel
+
 
 
 %blockquote
@@ -34,12 +65,8 @@
     .alert_actions
       %a{ :href => '/cimi/machine/new', :class => 'btn'} Create new
 
-%h3 Collection details
 
-%dl
-  %dt URI
-  %dd=@machines.uri
-  %dt Description
-  %dd=@machines.description
-  %dt Created
-  %dd=@machines.created
+- details('Collection details') do
+  - row 'URI', @machines.uri
+  - row 'Description', @machines.description
+  - row 'Created', @machines.created
diff --git a/clients/cimi/views/machines/new.haml b/clients/cimi/views/machines/new.haml
deleted file mode 100644
index d2a354b..0000000
--- a/clients/cimi/views/machines/new.haml
+++ /dev/null
@@ -1,55 +0,0 @@
-- @title="New Machine"
-
-- content_for :breadcrumb do
-  %ul.breadcrumb
-    %li
-      %a{ :href => "/cimi/cloudEntryPoint"} CloudEntryPoint
-      %span.divider="/"
-    %li
-      %a{ :href => "/cimi/machines"} MachineCollection
-      %span.divider="/"
-    %li.active New Machine
-
-
-%form{ :action => "/cimi/machines", :method => :post }
-  %fieldset
-    %legend Create new Machine
-    %div.clearfix
-      %label{ :for => 'machine[name]' }
-        Name
-      %div.input
-        %input{ :type => :text, :name => 'machine[name]' }
-    %div.clearfix
-      %label{ :for => 'machine[description]' }
-        Description
-      %div.input
-        %input{ :type => :text, :name => 'machine[description]' }
-    %div.clearfix
-      %label{ :for => 'machine[machine_image]' }
-        Machine Image
-      %div.input
-        %select{ :name => 'machine[machine_image]' }
-          - @machine_images.machine_images.each do |image|
-            %option{ :value => image.href }=href_to_id(image.href)
-    %div.clearfix
-      %label{ :for => 'machine[machine_configuration]' }
-        Machine Configuration
-      %div.input
-        %select{ :name => 'machine[machine_configuration]' }
-          - @machine_configurations.machine_configurations.each do |configuration|
-            %option{ :value => configuration.href }=href_to_id(configuration.href)
-    %div.clearfix
-      %label{ :for => 'machine[machine_admin]' }
-        Machine Admin
-      %div.input
-        %select{ :name => 'machine[machine_admin]' }
-          - if @machine_admins.kind_of?(Array)
-            %option{ :value => '', :selected => :selected }
-            - @machine_admins.machine_admins.each do |admin|
-              %option{ :value => admin.href }=href_to_id(admin.href)
-          - else
-            %option{ :disabled => 'disabled'}="Not supported"
-    %div.actions
-      %input{ :type => :submit, :class => 'btn primary', :value => "Create machine" }
-      %button{ :type => :reset, :class => 'btn' } Reset
-
-- 
1.7.9.1