On 11/24/2010 10:54 AM, [email protected] wrote:
> From: Ladislav Martincik<[email protected]>
>
> ---
>   src/app/helpers/providers_helper.rb       |   11 +++++++++++
>   src/app/views/providers/_providers.haml   |    3 +--
>   src/config/navigation.rb                  |    2 +-
>   src/config/routes.rb                      |    2 +-
>   src/spec/helpers/providers_helper_spec.rb |   25 +++++++++++++++++++++++++
>   5 files changed, 39 insertions(+), 4 deletions(-)
>   create mode 100644 src/app/helpers/providers_helper.rb
>   create mode 100644 src/spec/helpers/providers_helper_spec.rb
>
> diff --git a/src/app/helpers/providers_helper.rb 
> b/src/app/helpers/providers_helper.rb
> new file mode 100644
> index 0000000..4da2a0b
> --- /dev/null
> +++ b/src/app/helpers/providers_helper.rb
> @@ -0,0 +1,11 @@
> +module ProvidersHelper
> +
> +  def edit_button(provider, action)
> +    if provider and ['show', 'accounts'].include? action
> +      link_to 'Edit', edit_provider_path(provider), :class =>  'button'
> +    else
> +      content_tag('a', 'Edit', :href =>  '#', :class =>  'button disabled')
> +    end
> +  end
> +
> +end
> diff --git a/src/app/views/providers/_providers.haml 
> b/src/app/views/providers/_providers.haml
> index b1a9bec..2719a7b 100644
> --- a/src/app/views/providers/_providers.haml
> +++ b/src/app/views/providers/_providers.haml
> @@ -7,7 +7,6 @@
>           - selected = 'selected' if @provider and (provider.id == 
> @provider.id)
>           %a{ :href =>  url_for(:controller =>  'providers', :action =>  
> 'show', :id =>  provider), :class =>  selected }
>             = provider.name
> -  - form_tag({:controller =>  'providers', :action =>  'edit', :id =>  
> @provider}, {:method =>  :post , :class =>  'buttononly'}) do
> -    = submit_tag t(:edit), :disabled =>  ('disabled' unless @provider and 
> ['show', 'accounts'].include? controller.action_name)
> +  = edit_button(@provider, controller.action_name)
>     - form_tag({:controller =>  'providers', :action =>  'new'}, {:method =>  
> :get , :class =>  'buttononly'}) do
>       %input{ :type =>  'submit', :value =>  t(:add), :disabled =>  
> ('disabled' unless @providers.length == 0) }
> diff --git a/src/config/navigation.rb b/src/config/navigation.rb
> index caa864b..7e73d8b 100644
> --- a/src/config/navigation.rb
> +++ b/src/config/navigation.rb
> @@ -8,7 +8,7 @@ SimpleNavigation::Configuration.run do |navigation|
>       first_level.item :administration, t(:administration), '#', :class =>  
> 'administration' do |second_level|
>         second_level.item :system_settings, t(:system_settings), :controller 
> =>  'settings' do |third_level|
>           third_level.item :manage_providers, t(:manage_providers), 
> :controller =>  'providers' do |fourth_level|
> -          fourth_level.item :provider_summary, t(:provider_summary), { 
> :controller =>  'providers', :action =>  'show', :id =>  (@provider.id if 
> @provider) }, :highlights_on =>  /\/providers\/(show|edit)/
> +          fourth_level.item :provider_summary, t(:provider_summary), { 
> :controller =>  'providers', :action =>  'show', :id =>  (@provider.id if 
> @provider) }, :highlights_on =>  /\/providers\/([0-9]+)?(show|edit)?/
>             fourth_level.item :provider_accounts, t(:provider_accounts), { 
> :controller =>  'providers', :action =>  'accounts', :id =>  (@provider.id if 
> @provider) }, :highlights_on =>  /\/providers\/accounts/
>             fourth_level.item :scheduling_policies, t(:scheduling_policies), 
> '#'
>             fourth_level.item :services_provided, t(:services_provided), '#'
> diff --git a/src/config/routes.rb b/src/config/routes.rb
> index 8afbb6a..f59a2aa 100644
> --- a/src/config/routes.rb
> +++ b/src/config/routes.rb
> @@ -52,7 +52,7 @@ ActionController::Routing::Routes.draw do |map|
>
>     # Temporarily disable this route, provider stuff is not restful yet.
>     # Will be re-enabled in upcoming patch
> -  # map.resources :provider
> +  map.resources :providers
>
>     # Allow downloading Web Service WSDL as a file with an extension
>     # instead of a file named 'wsdl'
> diff --git a/src/spec/helpers/providers_helper_spec.rb 
> b/src/spec/helpers/providers_helper_spec.rb
> new file mode 100644
> index 0000000..ef7bc30
> --- /dev/null
> +++ b/src/spec/helpers/providers_helper_spec.rb
> @@ -0,0 +1,25 @@
> +require 'spec_helper'
> +
> +describe ProvidersHelper do
> +  include ProvidersHelper
> +
> +  context "edit_button() helper" do
> +
> +    it "formats link with path to edit action if rendered in show or 
> accounts action" do
> +      provider = Factory(:mock_provider)
> +
> +      edit_button(provider, 'show').should =~ /providers\/[0-9]*\/edit/
> +      edit_button(provider, 'accounts').should =~ /providers\/[0-9]*\/edit/
> +    end
> +
> +    it "formats blank link with no action and with disabled class if not in 
> show or accounts action" do
> +      provider = Factory(:mock_provider)
> +
> +      edit_button = edit_button(provider, 'index')
> +      edit_button.should =~ /href="#"/
> +      edit_button.should =~ /disabled/
> +    end
> +
> +  end
> +
> +end

ACK
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to