ref: refs/heads/master
commit ab3d64539c68ad3cdea652e60dd178e64d126a5a
Author: Martin Kudlvasr
Date: Tue Nov 3 17:01:26 2009 +0100
fix bnc#552069 (Back button in Administrator Settings does not work)
---
plugins/eulas/app/controllers/eulas_controller.rb | 58 ++++++++++++--------
plugins/eulas/app/views/eulas/show.html.erb | 17 +++++-
.../eulas/test/functional/eulas_controller_test.rb | 20 ++++---
webclient/app/helpers/application_helper.rb | 31 +++++++----
4 files changed, 81 insertions(+), 45 deletions(-)
diff --git a/plugins/eulas/app/controllers/eulas_controller.rb b/plugins/eulas/app/controllers/eulas_controller.rb
index 1d66efc..cee7076 100644
--- a/plugins/eulas/app/controllers/eulas_controller.rb
+++ b/plugins/eulas/app/controllers/eulas_controller.rb
@@ -4,7 +4,7 @@ require 'enumerator'
class EulasController < ApplicationController
before_filter :login_required
- before_filter :ensure_eula_list, :only => [:next, :show, :index]
+ before_filter :ensure_eula_count, :only => [:show, :index, :update]
before_filter :ensure_id, :only => [:show, :update]
layout 'main'
@@ -21,36 +21,39 @@ class EulasController < ApplicationController
found_objects # can be array or single
end
- def ensure_eula_list
- if session[:eula_unaccepted_ids_cache].nil? then
+ def ensure_eula_count
+ if session[:eula_count].nil?
eulas = load_proxy_without_permissions "org.opensuse.yast.modules.eulas", :all
- session[:eula_unaccepted_ids_cache] = eulas.to_enum(:each_with_index).collect{|eula,index| eula.accepted ? nil : (index+1)}.compact
+ session[:eula_count] = eulas.length
end
+ @eula_count = session[:eula_count]
end
def ensure_id
- redirect_to :action => :next and return if params[:id].nil?
- @eula_id = params[:id]
+ redirect_to :action => :show, :id => 1 and return if params[:id].nil?
+ @eula_id = [1,params[:id].to_i].max
end
def index
- if session[:eula_unaccepted_ids_cache].empty? then
- render :all_accepted
+ if session[:eula_count] == 0
+ render :no_licenses
else
- redirect_to :action => :next
+ redirect_to :action => :show, :id => 1
end
end
- def next
- next_id = session[:eula_unaccepted_ids_cache][0]
- if next_id.nil? then
- redirect_success
- else
- redirect_to :action => :show, :id => next_id, :eula_lang => params[:eula_lang]
- end
+ def next_in_range(range, current)
+ [current+1, range.max].min
+ end
+
+ def prev_in_range(range, current)
+ [current-1, range.min].max
end
def show
+ @prev_id = prev_in_range( (1..@eula_count), @eula_id)
+ @last_eula = @eula_id == @eula_count
+ @first_eula= @eula_id == 1
eula_params = params[:eula_lang].nil? ? Hash.new : { :lang => params[:eula_lang] }
@eula = load_proxy_without_permissions "org.opensuse.yast.modules.eulas", @eula_id, :params => eula_params
end
@@ -59,16 +62,25 @@ class EulasController < ApplicationController
@eula = load_proxy_without_permissions "org.opensuse.yast.modules.eulas", @eula_id
@eula.text = ""
@eula.available_langs = []
- @eula.accepted = params[:accepted]
@eula.id = @eula_id # XXX Why is this not set by the load_proxy !!!!
- @eula.save
- if @eula.accepted
- session[:eula_unaccepted_ids_cache].shift
+ if params[:accepted]
+ unless @eula.accepted
+ @eula.accepted = params[:accepted]
+ @eula.save # do not save again if there is no change
+ end
+ if @eula_count == @eula_id
+ redirect_success
+ return
+ end
+ next_id = next_in_range( (1..@eula_count), @eula_id)
+ elsif @eula.accepted
+ flash[:error] = _("You cannot reject a license once it has been accepted!")
+ next_id = @eula_id
else
flash[:error] = _("You must accept all licences before using this product!")
+ next_id = @eula_id
end
- redirect_to :action => :next, :eula_lang => params[:eula_lang]
+
+ redirect_to :action => :show, :id => next_id, :eula_lang => params[:eula_lang]
end
-
-
end
diff --git a/plugins/eulas/app/views/eulas/show.html.erb b/plugins/eulas/app/views/eulas/show.html.erb
index e175cb1..8757a97 100644
--- a/plugins/eulas/app/views/eulas/show.html.erb
+++ b/plugins/eulas/app/views/eulas/show.html.erb
@@ -15,10 +15,16 @@
<% if @eula.only_show then -%>
<input type="hidden" name="accepted" value="true"/>
<% else -%>
- <input type="radio" name="accepted" value="true">
+
+ <%= @eula.accepted ? 'readonly="readonly"' : "" %>
+ >
<%= _("Yes, I agree to the license agreement.") %>
<br/>
- <input type="radio" checked="checked" name="accepted" value="false">
+
+ <%= @eula.accepted ? 'readonly="readonly"' : '' %>
+ >
<%= _("No, I do not agree.") %>
<br/>
<% end -%>
@@ -26,5 +32,10 @@
<input type="hidden" name="eula_lang" value="<%= @eula.text_lang %>"/>
<% end %>
- <%= form_send_buttons( {:disabled => false} ) %>
+ <%= if @first_eula
+ form_back_button
+ else
+ link_to "Back", :action => :show, :id => @prev_id
+ end %>
+ <%= form_str_spacer + form_next_button %>
<% end -%>
diff --git a/plugins/eulas/test/functional/eulas_controller_test.rb b/plugins/eulas/test/functional/eulas_controller_test.rb
index 8a2867f..87d0ac1 100644
--- a/plugins/eulas/test/functional/eulas_controller_test.rb
+++ b/plugins/eulas/test/functional/eulas_controller_test.rb
@@ -17,7 +17,7 @@ class EulasControllerTest < ActionController::TestCase
if args[0] == :all then
@result
else
- @result[0]
+ @result[args[0]-1]
end
end
@@ -51,22 +51,24 @@ class EulasControllerTest < ActionController::TestCase
end
def test_eula_start
- session[:eula_unaccepted_ids_cache] = nil
+ session[:eula_count] = nil
get :index
- assert_redirected_to "/eulas/next"
- assert_not_nil session[:eula_unaccepted_ids_cache]
- get :next
assert_redirected_to "/eulas/show/1"
+ assert_not_nil session[:eula_count]
end
def test_eula_step
@opensuse_eula.accepted = false
- session[:eula_unaccepted_ids_cache] = [1,2]
+ get :index
post :update, "accepted" => true, "id" => "1"
- assert_equal( session[:eula_unaccepted_ids_cache], [2] )
+ assert( @opensuse_eula.accepted )
+ assert_redirected_to "/eulas/show/2"
post :update, "accepted" => false, "id" => "2"
- assert_equal( session[:eula_unaccepted_ids_cache], [2] )
- assert_redirected_to "/eulas/next"
+ assert_false(@sles_eula.accepted)
+ assert_redirected_to "/eulas/show/2"
+ post :update, "accepted" => true, "id" => "2"
+ assert(@sles_eula.accepted)
+ assert_redirected_to "/eulas" # in basesystem redirected to "/controller/nextstep"
end
end
diff --git a/webclient/app/helpers/application_helper.rb b/webclient/app/helpers/application_helper.rb
index f0cf1a2..475ce12 100644
--- a/webclient/app/helpers/application_helper.rb
+++ b/webclient/app/helpers/application_helper.rb
@@ -7,16 +7,27 @@ module ApplicationHelper
# Example:
# <%= form_send_buttons :disabled => write_disabled %>
def form_send_buttons (send_options={})
- str_spacer = _(' or ')
- if session[:wizard_current].nil? or session[:wizard_current] == "FINISH"
- submit = submit_tag _("Save"),send_options
- back = link_to _("Cancel"), :controller => "controlpanel"
- return submit+str_spacer+back
- else
- back = link_to "Back", :controller => "controlpanel", :action => "backstep"
- nextb = submit_tag _("Next"),send_options
- return back+str_spacer+nextb
- end
+ form_back_button + form_str_spacer + form_next_button(send_options)
+ end
+
+ def form_str_spacer
+ _(' or ')
+ end
+
+ def form_back_button
+ if session[:wizard_current].nil? or session[:wizard_current] == "FINISH"
+ link_to _("Cancel"), :controller => "controlpanel"
+ else
+ link_to "Back", :controller => "controlpanel", :action => "backstep"
+ end
+ end
+
+ def form_next_button(send_options={})
+ if session[:wizard_current].nil? or session[:wizard_current] == "FINISH"
+ submit_tag _("Save"),send_options
+ else
+ submit_tag _("Next"),send_options
+ end
end
end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org