ref: refs/heads/master commit e6beb37ead307852fef380210bfb987cd54e8783 Author: J. Daniel Schmidt <jdsn@suse.de> Date: Sat Nov 14 03:45:15 2009 +0100 change registration client to behave like the other webyast modules fix summary of repo and service changes, change details button to link (bnc#555230) enable spinner during registration bnc#(554714) --- .../app/controllers/registration_controller.rb | 96 +++++++++++++++----- .../app/views/registration/index.rhtml | 87 +++++++----------- 2 files changed, 107 insertions(+), 76 deletions(-) diff --git a/plugins/registration/app/controllers/registration_controller.rb b/plugins/registration/app/controllers/registration_controller.rb index e1adf51..0e2ca08 100644 --- a/plugins/registration/app/controllers/registration_controller.rb +++ b/plugins/registration/app/controllers/registration_controller.rb @@ -6,6 +6,7 @@ require 'yast/service_resource' class RegistrationController < ApplicationController before_filter :login_required layout 'main' + include ProxyLoader private def client_permissions @@ -32,44 +33,57 @@ class RegistrationController < ApplicationController def index return unless client_permissions - if action_name == "detail" - @detail = true - else - @detail = false - end + @detail = action_name == "detail" unless @permissions[:statelessregister] flash[:warning] = _("No permissions for registration") redirect_to root_path return false end - register = @client.new({:arguments=>nil, - :options=>@options}) + + status = nil + @guid = nil begin - register.save - rescue ActiveResource::ClientError => e - error = Hash.from_xml(e.response.body)["registration"] - if error && error["status"] == "missinginfo" && !error["missingarguments"].blank? - logger.debug "missing arguments #{error["missingarguments"].inspect}" - @arguments = error["missingarguments"].sort {|a,b| a["name"] <=> b["name"] } #in order to show it in an unique order - else - logger.error "error while getting arguments: #{error.inspect}" - flash[:error] = _("Arguments for registration cannot be evaluated.") - redirect_to root_path - return false + status = @client.find if @client + rescue + status = nil + end + + if status && status.respond_to?('guid') then + @guid = status.guid unless status.guid.blank? + # flash[:error] = "YES we have a GUI: #{status.guid}" + else + begin + register = @client.new( {:arguments=>nil, + :options=>@options} ) + register.save + rescue ActiveResource::ClientError => e + error = Hash.from_xml(e.response.body)["registration"] + if error && error["status"] == "missinginfo" && !error["missingarguments"].blank? + logger.debug "missing arguments #{error["missingarguments"].inspect}" + @arguments = error["missingarguments"].sort {|a,b| a["name"] <=> b["name"] } #in order to show it in an unique order + else + logger.error "error while getting arguments: #{error.inspect}" + # keep the old message for the translation, in case we need it later + old_error_msg = _("Arguments for registration cannot be evaluated.") + flash[:error] = _("An error occurred during registration. Please try again.") + redirect_to root_path + return false + end end - end + end end def detail - index - render :action => "index" + # different action but same semantic as in update + update end # Calling the register over the service def update return unless client_permissions - @detail = false + + @detail = action_name == "detail" unless @permissions[:statelessregister] flash[:warning] = _("No permissions for registration") @@ -96,6 +110,42 @@ class RegistrationController < ApplicationController @changed_services = register.changedservices if register.respond_to? :changedservices flash[:notice] = _("Registration finished successfully.") success = true + + # inform about added services and its catalogs + if @changed_services && @changed_services.kind_of?(Array) then + flash[:notice] += "<ul>" + @changed_services.each do |c| + if c.respond_to?(:name) && c.name && c.respond_to?(:status) && c.status == 'added' then + flash[:notice] += "<li>" + _("Service added:") + " #{c.name}</li>" + end + if c.respond_to?(:catalogs) && c.catalogs && c.catalogs.respond_to?(:catalog) && c.catalogs.catalog then + if c.catalogs.catalog.respond_to?(:name) && c.catalogs.catalog.respond_to?(:status) && c.catalogs.catalog.status == 'added' then + flash[:notice] += "<ul><li>" + _("Catalog enabled:") + " #{c.catalogs.catalog.name}</li></ul>" + elsif c.catalogs.catalog.kind_of?(Array) then + flash[:notice] += "<ul>" + c.catalogs.catalog.each do |s| + if s && s.respond_to?(:name) && s.respond_to?(:status) && s.status == 'added' then + flash[:notice] += "<li>" + _("Catalog enabled:") + " #{s.name}</li>" + end + end + flash[:notice] += "</ul>" + end + end + end + flash[:notice] += "</ul>" + end + + # inform about added repositories + if @changed_repositories && @changed_repositories.kind_of?(Array) then + flash[:notice] += "<ul>" + @changed_repositories.each do |r| + if r.respond_to?(:name) && r.name && r.respond_to?(:status) && r.status == 'added' then + flash[:notice] += "<li>" + _("Repository added:") + " #{r.name}</li>" + end + end + flash[:notice] += "</ul>" + end + rescue ActiveResource::ClientError => e error = Hash.from_xml(e.response.body)["registration"] if error && error["status"] == "missinginfo" && !error["missingarguments"].blank? @@ -136,7 +186,7 @@ class RegistrationController < ApplicationController respond_to do |format| format.html { render :action => "index" } end - end + end end end diff --git a/plugins/registration/app/views/registration/index.rhtml b/plugins/registration/app/views/registration/index.rhtml index fc89110..88b4985 100644 --- a/plugins/registration/app/views/registration/index.rhtml +++ b/plugins/registration/app/views/registration/index.rhtml @@ -2,63 +2,44 @@ <div class='plugin-content grid_12'> -<% form_tag '/registration/update' do -%> - <table summary="<%= _("This table gives registration settings.") %>"> - <tr><td colspan="2" class="full" align="center"></td></tr> + <% form_target_save = @detail ? '/registration/detail' : '/registration/update' %> + + <% if @guid then %> + <fieldset> + <p><strong><%=_("This system is registered")%></strong></p> + <p><small><%=_("System's GUID:")%> <%= @guid %></small></p> + <p><%= link_to _('Register again'), {:controller => :registration, :action =>:update}, :onclick=>"$('#progress').show()", :class => "button" %></p> + </fieldset> + <% + form_target_save = '/controlpanel' + end + %> + +<% form_tag form_target_save, { :onsubmit => "$('#progress').show()" } do -%> + + <% if @arguments && @arguments.size > 0 then %> + <fieldset> <% for argument in @arguments %> - <% if argument["flag"] == "m" || @detail%> - <tr> - <% if argument["error"] %> - <td><strong><font color=red><%=_(argument["name"])%></font></strong></td> - <% else %> - <td><strong><%=_(argument["name"])%></strong></td> - <% end %> - <td><%= text_field_tag "registration_arg,"+argument["name"], argument["value"], :class=>'aligned-inputs' %></td> - </tr> + <% if argument["flag"] == "m" || @detail then %> + <p> + <label for="<%= 'registration_arg_'+argument['name'] %>" <%= argument["error"] ? 'style="color: red"' : '' %> > + <%=_(argument["name"])%> + </label> + <%= text_field_tag "registration_arg,"+argument["name"], argument["value"] %> + </p> <% else %> - <input type="hidden" id="<%= 'registration_arg_'+argument['name'] %>" name="<%= 'registration_arg_'+argument['name'] %>" value="<%= argument["value"] %>"/> + <%= hidden_field_tag "registration_arg,"+argument["name"], argument["value"], :disabled => 'disabled' %> <% end %> + <% end %> - <% unless @changed_repositories.blank? %> - <tr><td height=10></td></tr> - <% first=true %> - <% for repo in @changed_repositories %> - <tr> - <% if first %> - <td><strong><%=_("Changed Repositories")%></strong></td> - <% first=false %> - <% else %> - <td></td> - <% end %> - <td><%= repo.alias %> (<%= repo.status %>)</td> - </tr> - <% end %> - <% end %> - <% unless @changed_services.blank? %> - <tr><td height=10></td></tr> - <% first=true %> - <% for service in @changed_services %> - <tr> - <% if first %> - <td><strong><%=_("Changed Services")%></strong></td> - <% first=false %> - <% else %> - <td></td> - <% end %> - <td><%= service.alias %> (<%= service.status %>)</td> - </tr> - <% end %> - <% end %> - <% unless @detail || controller.action_name == "update"%> - <tr><td height=10></td></tr> - <tr> - <td></td> - <td align="right"><%= link_to _('Detail'), {:controller => :registration, :action =>:detail}, :onclick=>"$('#progress').show()", :class => "button"%></p></td> - </tr> - <% end %> - </table> - <br/> - <%= form_send_buttons %> + </fieldset> + <% end %> + + <% unless @detail || @guid %> + <p><%= link_to _('Detail'), {:controller => :registration, :action =>:detail}, :onclick=>"$('#progress').show()" %></p> + <% end %> + + <p><%= form_send_buttons %></p> <% end -%> </div> -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org