Commit 00dacfc25b70dd86f30770bcde110f64a7eaa662
Committed by
Daniela Feitosa
1 parent
3fc192fc
Exists in
master
and in
22 other branches
[multiple-templates] Manage templates views and controllers
(ActionItem2378)
Showing
9 changed files
with
150 additions
and
11 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,52 @@ |
| 1 | +class TemplatesController < AdminController | |
| 2 | + protect 'manage_environment_templates', :environment | |
| 3 | + | |
| 4 | + def create_person_template | |
| 5 | + if request.post? | |
| 6 | + begin | |
| 7 | + identifier = params[:name].to_slug | |
| 8 | + password = Digest::MD5.hexdigest(rand.to_s) | |
| 9 | + template = User.new(:login => identifier, :email => identifier+'@templates.noo', :password => password, :password_confirmation => password, :person_data => {:name => params[:name], :is_template => true}) | |
| 10 | + template.save! | |
| 11 | + session[:notice] = _('New template created') | |
| 12 | + redirect_to :action => 'edit_templates' | |
| 13 | + rescue | |
| 14 | + @error = _('Name has already been taken') | |
| 15 | + end | |
| 16 | + end | |
| 17 | + end | |
| 18 | + | |
| 19 | + def create_community_template | |
| 20 | + if request.post? | |
| 21 | + begin | |
| 22 | + create_organization_template(Community) | |
| 23 | + session[:notice] = _('New template created') | |
| 24 | + redirect_to :action => 'edit_templates' | |
| 25 | + rescue | |
| 26 | + @error = _('Name has already been taken') | |
| 27 | + end | |
| 28 | + end | |
| 29 | + end | |
| 30 | + | |
| 31 | + def create_enterprise_template | |
| 32 | + if request.post? | |
| 33 | + begin | |
| 34 | + create_organization_template(Enterprise) | |
| 35 | + session[:notice] = _('New template created') | |
| 36 | + redirect_to :action => 'edit_templates' | |
| 37 | + rescue | |
| 38 | + @error = _('Name has already been taken') | |
| 39 | + end | |
| 40 | + end | |
| 41 | + end | |
| 42 | + | |
| 43 | + private | |
| 44 | + | |
| 45 | + def create_organization_template(klass) | |
| 46 | + identifier = params[:name].to_slug | |
| 47 | + template = klass.new(:name => params[:name], :identifier => identifier, :is_template => true) | |
| 48 | + template.save! | |
| 49 | + end | |
| 50 | + | |
| 51 | +end | |
| 52 | + | ... | ... |
app/views/admin_panel/edit_templates.rhtml
| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | -<h1><%= _('Edit Templates') %></h1> | |
| 2 | - | |
| 3 | -<ul> | |
| 4 | -<% [[_('Edit Person Template'), environment.person_template], | |
| 5 | - [_('Edit Community Template'), environment.community_template], | |
| 6 | - [__('Edit Enterprise Template'), environment.enterprise_template], | |
| 7 | - [__('Edit Inactive Enterprise Template'), environment.inactive_enterprise_template]].select{|i| i[1]}.each do |row| %> | |
| 8 | -<li><%= link_to row[0], :controller => 'profile_editor', :profile => row[1].identifier %></li> | |
| 9 | -<% end %> | |
| 10 | -</ul> |
app/views/admin_panel/index.rhtml
| ... | ... | @@ -12,7 +12,7 @@ |
| 12 | 12 | <tr><td><%= link_to _('Manage User roles'), :controller => 'role' %></td></tr> |
| 13 | 13 | <tr><td><%= link_to _('Manage users'), :controller => 'users' %></td></tr> |
| 14 | 14 | <tr><td><%= link_to _('Manage Validators by region'), :controller => 'region_validators' %></td></tr> |
| 15 | - <tr><td><%= link_to _('Edit Templates'), :action => 'edit_templates' %></td></tr> | |
| 15 | + <tr><td><%= link_to _('Edit Templates'), :controller => 'templates' %></td></tr> | |
| 16 | 16 | <tr><td><%= link_to _('Manage Fields'), :controller => 'features', :action => 'manage_fields' %></td></tr> |
| 17 | 17 | <tr><td><%= link_to _('Set Portal'), :action => 'set_portal_community' %></td></tr> |
| 18 | 18 | <% @plugins.dispatch(:admin_panel_links).each do |link| %> | ... | ... |
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +<% if @error %> | |
| 2 | + <div class="errorExplanation" id="errorExplanation"> | |
| 3 | + <h2><%= _('The template could not be saved') %></h2> | |
| 4 | + <p><%= _('There were problems with the following fields:') %> </p> | |
| 5 | + <ul> | |
| 6 | + <li><%= @error %></li> | |
| 7 | + </ul> | |
| 8 | + </div> | |
| 9 | +<% end %> | |
| 10 | + | |
| 11 | +<% form_tag do %> | |
| 12 | + <%= labelled_text_field(_('Name')+': ', :name)%> | |
| 13 | + | |
| 14 | + <% button_bar do %> | |
| 15 | + <%= submit_button('save', _('Save'))%> | |
| 16 | + <%= button('cancel', _('Cancel'), {:action => 'index'})%> | |
| 17 | + <% end %> | |
| 18 | +<% end %> | |
| 19 | + | ... | ... |
| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | +<% title = case @kind | |
| 2 | + when 'person' | |
| 3 | + | |
| 4 | + when 'community' | |
| 5 | + _('Create community template') | |
| 6 | + when 'enterprise' | |
| 7 | + _('Create enterprise template') | |
| 8 | +end %> | |
| 9 | + | |
| 10 | +<h1><%= _('Create person template') %></h1> | |
| 11 | + | |
| 12 | +<%= render :partial => 'create_template_form' %> | ... | ... |
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +<h1><%= _('Edit Templates') %></h1> | |
| 2 | + | |
| 3 | +<% list_of_templates = [[_('Person') , Person.templates , 'person' ], | |
| 4 | + [_('Community') , Community.templates , 'community' ], | |
| 5 | + [_('Enterprise'), Enterprise.templates, 'enterprise']] %> | |
| 6 | + | |
| 7 | +<ul> | |
| 8 | + <% list_of_templates.each do |title, templates, kind|%> | |
| 9 | + <li><%= title %></li> | |
| 10 | + <ul> | |
| 11 | + <% templates.each do |template| %> | |
| 12 | + <li><%= link_to(template.name, {:controller => 'profile_editor', :profile => template.identifier}) %></li> | |
| 13 | + <% end %> | |
| 14 | + <li><strong> | |
| 15 | + <%= link_to(_('New...'), {:action => "create_#{kind}_template"}) %> | |
| 16 | + </strong></li> | |
| 17 | + </ul> | |
| 18 | + <% end %> | |
| 19 | +</ul> | ... | ... |
| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | +require 'templates_controller' | |
| 3 | + | |
| 4 | +# Re-raise errors caught by the controller. | |
| 5 | +class TemplatesController; def rescue_action(e) raise e end; end | |
| 6 | + | |
| 7 | +class TemplatesControllerTest < ActionController::TestCase | |
| 8 | + | |
| 9 | + all_fixtures | |
| 10 | + def setup | |
| 11 | + @controller = TemplatesController.new | |
| 12 | + @request = ActionController::TestRequest.new | |
| 13 | + @response = ActionController::TestResponse.new | |
| 14 | + login_as(create_admin_user(Environment.default)) | |
| 15 | + end | |
| 16 | + | |
| 17 | + should 'create person template' do | |
| 18 | + post :create_person_template, :name => 'Developer' | |
| 19 | + assert Person['developer'].is_template | |
| 20 | + end | |
| 21 | + | |
| 22 | + should 'create community template' do | |
| 23 | + post :create_community_template, :name => 'Debian' | |
| 24 | + assert Community['debian'].is_template | |
| 25 | + end | |
| 26 | + | |
| 27 | + should 'create enterprise template' do | |
| 28 | + post :create_enterprise_template, :name => 'Free Software Foundation' | |
| 29 | + assert Enterprise['free-software-foundation'].is_template | |
| 30 | + end | |
| 31 | +end | |
| 32 | + | ... | ... |