From: Jan Provaznik <[email protected]>
each UI form is submited to action which generates the form
and after successful save is user redirected to next form.
With this patch it's easy to display validation/save errors for
each form.
Till now, form was submited to next action which also generated next form.
For example 'services' form was processed by 'software' action which also
generated 'software' view/form.
---
src/app/controllers/templates_controller.rb | 97 +++++++++++++--------------
src/app/views/templates/new.haml | 2 +-
src/app/views/templates/services.haml | 2 +-
src/app/views/templates/software.haml | 2 +-
src/app/views/templates/summary.haml | 4 +-
5 files changed, 51 insertions(+), 56 deletions(-)
diff --git a/src/app/controllers/templates_controller.rb
b/src/app/controllers/templates_controller.rb
index 6a06ef4..975d46d 100644
--- a/src/app/controllers/templates_controller.rb
+++ b/src/app/controllers/templates_controller.rb
@@ -2,83 +2,70 @@ require 'util/repository_manager'
class TemplatesController < ApplicationController
layout :layout
- before_filter :require_user, :check_permission
+ before_filter :require_user, :check_permission, :check_for_cancel
def layout
request.xhr? ? false : 'aggregator'
end
def new
- if params[:cancel]
- redirect_to :controller => "dashboard", :action => 'index'
- else
- update_xml
+ update_xml
+ if params[:next]
+ redirect_to :action => 'services', :id => @image_descriptor
end
end
def services
- if params[:cancel]
- redirect_to :controller => "dashboard", :action => 'index'
- else
- update_xml
+ update_xml
+ if params[:back]
+ redirect_to :action => 'new', :id => @image_descriptor
+ elsif params[:next]
+ redirect_to :action => 'software', :id => @image_descriptor
end
end
def software
- if params[:cancel]
- redirect_to :controller => "dashboard", :action => 'index'
+ @repository_manager = RepositoryManager.new
+ @image_descriptor = params[:id] ? ImageDescriptor.find(params[:id]) :
ImageDescriptor.new
+ @groups = @repository_manager.all_groups(params[:repository])
+ if params[:tab].to_s == 'packages'
+ @selected_tab = 'packages'
+ @packages = @repository_manager.all_packages(params[:repository])
else
- @repository_manager = RepositoryManager.new
- @image_descriptor = params[:id] ? ImageDescriptor.find(params[:id]) :
ImageDescriptor.new
- @groups = @repository_manager.all_groups(params[:repository])
- if params[:tab].to_s == 'packages'
- @selected_tab = 'packages'
- @packages = @repository_manager.all_packages(params[:repository])
- else
- @selected_tab = 'groups'
- end
+ @selected_tab = 'groups'
+ end
- if request.xhr?
- render :partial => @selected_tab
- return
- end
+ if request.xhr?
+ render :partial => @selected_tab
+ return
+ end
- @image_descriptor.update_xml_attributes!(params[:xml] || {})
+ @image_descriptor.update_xml_attributes!(params[:xml] || {})
- if params[:back]
- redirect_to :action => 'new', :id => params[:id]
- return
- end
+ if params[:back]
+ redirect_to :action => 'services', :id => @image_descriptor
+ elsif params[:next]
+ redirect_to :action => 'summary', :id => @image_descriptor
end
end
def summary
- if params[:cancel]
- redirect_to :controller => "dashboard", :action => 'index'
- else
- update_xml
- @image_descriptor.complete = true
- @image_descriptor.save!
- @all_targets = ImageDescriptorTarget.available_targets
- if params[:back]
- redirect_to :action => 'services', :id => params[:id]
- return
- end
- end
- end
-
- def build
- if params[:cancel] or params[:done]
- redirect_to :controller => "dashboard", :action => 'index'
- elsif params[:back]
- redirect_to :action => 'software', :id => params[:id]
- else
+ update_xml
+ @all_targets = ImageDescriptorTarget.available_targets
+ if params[:build]
if params[:targets]
params[:targets].each do |target|
ImageDescriptorTarget.new_if_not_exists(:name => target,
:image_descriptor_id => params[:id], :status =>
ImageDescriptorTarget::STATE_QUEUED)
end
end
- redirect_to :action => 'summary', :id => params[:id]
+ else
+ if params[:back]
+ redirect_to :action => 'software', :id => @image_descriptor
+ elsif params[:done]
+ @image_descriptor.complete = true
+ @image_descriptor.save!
+ redirect_to :controller => 'dashboard', :action => 'index'
+ end
end
end
@@ -101,8 +88,16 @@ class TemplatesController < ApplicationController
private
+ def check_for_cancel
+ if params[:cancel]
+ redirect_to :controller => "dashboard", :action => 'index'
+ return false
+ end
+ return true
+ end
+
def check_permission
- #require_privilege(Privilege::IMAGE_MODIFY)
+ require_privilege(Privilege::IMAGE_MODIFY)
end
def update_group_or_package(method, *args)
diff --git a/src/app/views/templates/new.haml b/src/app/views/templates/new.haml
index d4bf011..85c97c6 100644
--- a/src/app/views/templates/new.haml
+++ b/src/app/views/templates/new.haml
@@ -3,7 +3,7 @@
#image_descriptor_form{:class => 'dcloud_form'}
= error_messages_for 'image_descriptor'
- - form_for @image_descriptor, :url => {:action => 'services', :id =>
@image_descriptor} do
+ - form_for @image_descriptor, :url => {:action => controller.action_name,
:id => @image_descriptor} do
%ul
%li
%label Name
diff --git a/src/app/views/templates/services.haml
b/src/app/views/templates/services.haml
index f080f7d..81eed29 100644
--- a/src/app/views/templates/services.haml
+++ b/src/app/views/templates/services.haml
@@ -3,7 +3,7 @@
#image_descriptor_form{:class => 'dcloud_form'}
= error_messages_for 'image_descriptor'
- - form_for @image_descriptor, :url => {:action => 'software', :id =>
@image_descriptor} do
+ - form_for @image_descriptor, :url => {:action => controller.action_name,
:id => @image_descriptor} do
= hidden_field :image_descriptor, :id
= hidden_field_tag 'xml[set_services]', true
%ul
diff --git a/src/app/views/templates/software.haml
b/src/app/views/templates/software.haml
index dee8eeb..998ce9b 100644
--- a/src/app/views/templates/software.haml
+++ b/src/app/views/templates/software.haml
@@ -71,7 +71,7 @@
#image_descriptor_form{:class => 'dcloud_form'}
= error_messages_for 'image_descriptor'
- - form_for @image_descriptor, :url => {:action => 'summary', :id =>
@image_descriptor} do
+ - form_for @image_descriptor, :url => {:action => controller.action_name,
:id => @image_descriptor} do
= hidden_field_tag 'xml[set_packages]', true
.pkglist_wrapper
.pkglist
diff --git a/src/app/views/templates/summary.haml
b/src/app/views/templates/summary.haml
index d32426d..18d286c 100644
--- a/src/app/views/templates/summary.haml
+++ b/src/app/views/templates/summary.haml
@@ -22,7 +22,7 @@
#image_descriptor_form{:class => 'dcloud_form'}
= error_messages_for 'image_descriptor'
- - form_for @image_descriptor, :url => {:action => 'build', :id =>
@image_descriptor} do
+ - form_for @image_descriptor, :url => {:action => controller.action_name,
:id => @image_descriptor} do
.summary_panel
%ul{:class => 'side_panel'}
%li
@@ -57,7 +57,7 @@
= check_box_tag 'targets[]', target_id, false
%span
= target['name']
- = submit_tag "Build"
+ = submit_tag "Build", :name => "build"
= render :partial => 'targets'
.submit
--
1.7.0.1
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel