ref: refs/heads/master
commit f313c0edf297819a0cc24b2fd02d0e458fd44d80
Author: Martin Kudlvasr
Date: Wed Oct 14 21:43:20 2009 +0200
finally working eula client
---
plugins/eulas/app/controllers/eulas_controller.rb | 62 ++++++++++++++++++---
plugins/eulas/app/views/eulas/show.html.erb | 59 ++++++++++++-------
plugins/eulas/app/views/eulas/show_text.erb | 3 +
3 files changed, 93 insertions(+), 31 deletions(-)
diff --git a/plugins/eulas/app/controllers/eulas_controller.rb b/plugins/eulas/app/controllers/eulas_controller.rb
index 96c93fc..aa3d257 100644
--- a/plugins/eulas/app/controllers/eulas_controller.rb
+++ b/plugins/eulas/app/controllers/eulas_controller.rb
@@ -1,9 +1,11 @@
require "yast/service_resource"
+require 'enumerator'
class EulasController < ApplicationController
before_filter :login_required
before_filter :ensure_eula_list, :only => [:next, :show]
+ before_filter :ensure_id, :only => [:show, :update, :update_text, :show_text]
layout 'main'
include ProxyLoader
@@ -11,30 +13,72 @@ class EulasController < ApplicationController
# Initialize GetText and Content-Type.
init_gettext "yast_webclient_language" # textdomain, options(:charset, :content_type)
+ def load_proxy_without_permissions (*args)
+ proxy = YaST::ServiceResource.proxy_for args[0]
+ raise "No proxy_for for #{args[0]}" if proxy.nil?
+ found_objects = proxy.find *(args[1..-1])
+ raise "Error when proxy.find for #{args[0]}" if found_objects.nil?
+ found_objects # can be array or single
+ end
+
def ensure_eula_list
- if session[:eula_unaccepted_ids].nil? then
- eulas = load_proxy "org.opensuse.yast.modules.eulas", :all
- session[:eula_unaccepted_ids] = eulas.each_with_index{|eula,index| eula.accepted ? nil : (index+1)}.compact
+ if session[:eula_unaccepted_ids_cache].nil? then
+ 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
end
end
+ def ensure_id
+ redirect_to :action => :next and return if params[:id].nil?
+ @eula_id = params[:id]
+ end
+
def index
redirect_to :action => :next
end
def next
- next_id = session[:eula_unaccepted_ids][0]
+ next_id = session[:eula_unaccepted_ids_cache][0]
if next_id.nil? then
- render :all_accepted
+ redirect_success
else
- redirect_to :action => :show, :id => next_id
+ redirect_to :action => :show, :id => next_id, :eula_lang => params[:eula_lang]
+ end
+ end
+
+ def update_text
+ eula_params = params[:lang].nil? ? Hash.new : { :lang => params[:lang][0] }
+ @eula = load_proxy_without_permissions "org.opensuse.yast.modules.eulas", @eula_id, :params => eula_params
+ render :update do |page|
+ page.replace_html 'eula-text', @eula.text
end
end
+ def show_text
+ eula_params = params[:lang].nil? ? Hash.new : { :lang => params[:lang][0] }
+ @eula = load_proxy_without_permissions "org.opensuse.yast.modules.eulas", @eula_id, :params => eula_params
+ render :text => @eula.text
+ end
+
def show
- redirect_to :action => :next and return if params[:id].nil?
- @eula = load_proxy "org.opensuse.yast.modules.eulas", params[:id].nil?
- @last_eula = session[:eula_unaccepted_ids].length == 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
+
+ def update
+ @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
+ else
+ flash[:error] = _("You must accept all licences before using this product!")
+ end
+ redirect_to :action => :next, :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 7caf128..71f7042 100644
--- a/plugins/eulas/app/views/eulas/show.html.erb
+++ b/plugins/eulas/app/views/eulas/show.html.erb
@@ -1,23 +1,38 @@
-<h1><%=_("Accept End User Licence Agreement")-%> - <%= @license.name -%></h1><br/>
+<h1><%=_("Accept End User Licence Agreement")-%> - <%= @eula.name -%></h1><br/>
-<table>
-<tr>
- <td>Accepted?</td>
- <td><%= @license.accepted.to_s -%></td>
-</tr>
-<tr>
- <td>Only show?</td>
- <td><%= @license.only_show.to_s -%></td>
-</tr>
-<tr>
- <td>Available translations:</td>
- <td><%= @license.langs_list.collect{ |lang| link_to lang, :only_path => :true, :controller => "eulas", :action => :show, :id => @id, :params => {:lang => lang} }.join(", ") -%></td>
-</tr>
-<tr>
- <td>Current translation:</td>
- <td><%= @license.text_lang -%></td>
-</tr>
-</table>
-<pre>
-<%= @license.text -%>
-</pre>
+<% form_tag :method => :post, :controller => :eulas, :action => :update, :id => @eula_id, :class => 'container' do -%>
+ <%= _("Available translations:") -%>
+<!--
+ :onchange => remote_function(:update => "eula-text",
+ :url => {:id => @eula_id, :action => :show_text},
+ :with => "'lang='+value")
+
+ :onchange => remote_function(:url => {:id => @eula_id, :action => :update_text},
+ :with => "'lang='+value")
+-->
+ <%= select_tag "text_lang",
+ options_for_select(@eula.available_langs, :selected => @eula.text_lang),
+ :onchange => "location.href='" + (url_for :controller => "eulas", :id => @eula_id, :action => :show) + "?eula_lang=' + value"
+ %>
+
+ <br/>
+