Commit b0874b74bcd78cd1a6a356620972449dda50a2d1

Authored by Eduardo Tourinho Edington
Committed by Gust
1 parent 8625b2c8

Allow the admin users to change the environment theme on the admin panel.

app/controllers/admin/environment_themes_controller.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class EnvironmentThemesController < ThemesController
  2 +
  3 + protect 'edit_appearance', :environment
  4 +
  5 + no_design_blocks
  6 +
  7 + def target
  8 + @target = environment
  9 + end
  10 +
  11 +end
... ...
app/controllers/my_profile/profile_themes_controller.rb 0 → 100644
... ... @@ -0,0 +1,75 @@
  1 +class ProfileThemesController < ThemesController
  2 +
  3 + needs_profile
  4 +
  5 + protect 'edit_appearance', :profile
  6 +
  7 + no_design_blocks
  8 +
  9 + def target
  10 + @target = profile
  11 + end
  12 +
  13 + def new
  14 + if !request.xhr?
  15 + id = params[:name] ? params[:name].to_slug : 'my-theme'
  16 + t = Theme.new(id, :name => params[:name], :owner => profile, :public => false)
  17 + t.save
  18 + redirect_to :action => 'index'
  19 + else
  20 + render :action => 'new', :layout => false
  21 + end
  22 + end
  23 +
  24 + def edit
  25 + @theme = profile.find_theme(params[:id])
  26 + @css_files = @theme.css_files
  27 + @image_files = @theme.image_files
  28 + end
  29 +
  30 + def add_css
  31 + @theme = profile.find_theme(params[:id])
  32 + if request.xhr?
  33 + render :action => 'add_css', :layout => false
  34 + else
  35 + @theme.add_css(params[:css])
  36 + redirect_to :action => 'edit', :id => @theme.id
  37 + end
  38 + end
  39 +
  40 + def css_editor
  41 + @theme = profile.find_theme(params[:id])
  42 + @css = params[:css]
  43 +
  44 + @code = @theme.read_css(@css)
  45 + render :action => 'css_editor', :layout => false
  46 + end
  47 +
  48 + post_only :update_css
  49 + def update_css
  50 + @theme = profile.find_theme(params[:id])
  51 + @theme.update_css(params[:css], params[:csscode])
  52 + redirect_to :action => 'edit', :id => @theme.id
  53 + end
  54 +
  55 + def add_image
  56 + @theme = profile.find_theme(params[:id])
  57 + if request.xhr?
  58 + render :action => 'add_image', :layout => false
  59 + else
  60 + @theme.add_image(params[:image].original_filename, params[:image].read)
  61 + redirect_to :action => 'edit', :id => @theme.id
  62 + end
  63 + end
  64 +
  65 + def start_test
  66 + session[:theme] = params[:id]
  67 + redirect_to :controller => 'content_viewer', :profile => profile.identifier, :action => 'view_page'
  68 + end
  69 +
  70 + def stop_test
  71 + session[:theme] = nil
  72 + redirect_to :action => 'index'
  73 + end
  74 +
  75 +end
... ...
app/controllers/my_profile/themes_controller.rb
... ... @@ -1,91 +0,0 @@
1   -class ThemesController < MyProfileController
2   -
3   - protect 'edit_appearance', :profile
4   - no_design_blocks
5   -
6   - def set
7   - profile.update_theme(params[:id])
8   - redirect_to :action => 'index'
9   - end
10   -
11   - def unset
12   - profile.update_theme(nil)
13   - redirect_to :action => 'index'
14   - end
15   -
16   - def index
17   - @themes = profile.environment.themes + Theme.approved_themes(profile)
18   - @current_theme = profile.theme
19   -
20   - @layout_templates = LayoutTemplate.all
21   - @current_template = profile.layout_template
22   - end
23   -
24   - def new
25   - if !request.xhr?
26   - id = params[:name] ? params[:name].to_slug : 'my-theme'
27   - t = Theme.new(id, :name => params[:name], :owner => profile, :public => false)
28   - t.save
29   - redirect_to :action => 'index'
30   - else
31   - render :action => 'new', :layout => false
32   - end
33   - end
34   -
35   - def edit
36   - @theme = profile.find_theme(params[:id])
37   - @css_files = @theme.css_files
38   - @image_files = @theme.image_files
39   - end
40   -
41   - def add_css
42   - @theme = profile.find_theme(params[:id])
43   - if request.xhr?
44   - render :action => 'add_css', :layout => false
45   - else
46   - @theme.add_css(params[:css])
47   - redirect_to :action => 'edit', :id => @theme.id
48   - end
49   - end
50   -
51   - def css_editor
52   - @theme = profile.find_theme(params[:id])
53   - @css = params[:css]
54   -
55   - @code = @theme.read_css(@css)
56   - render :action => 'css_editor', :layout => false
57   - end
58   -
59   - post_only :update_css
60   - def update_css
61   - @theme = profile.find_theme(params[:id])
62   - @theme.update_css(params[:css], params[:csscode])
63   - redirect_to :action => 'edit', :id => @theme.id
64   - end
65   -
66   - def add_image
67   - @theme = profile.find_theme(params[:id])
68   - if request.xhr?
69   - render :action => 'add_image', :layout => false
70   - else
71   - @theme.add_image(params[:image].original_filename, params[:image].read)
72   - redirect_to :action => 'edit', :id => @theme.id
73   - end
74   - end
75   -
76   - def start_test
77   - session[:theme] = params[:id]
78   - redirect_to :controller => 'content_viewer', :profile => profile.identifier, :action => 'view_page'
79   - end
80   -
81   - def stop_test
82   - session[:theme] = nil
83   - redirect_to :action => 'index'
84   - end
85   -
86   - def set_layout_template
87   - profile.update_layout_template(params[:id])
88   - redirect_to :action => 'index'
89   - end
90   -
91   -end
app/controllers/themes_controller.rb 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +class ThemesController < ApplicationController
  2 +
  3 + before_filter :login_required
  4 +
  5 + no_design_blocks
  6 +
  7 + # attr_reader :target
  8 +
  9 + def target
  10 + @target
  11 + end
  12 +
  13 + def index
  14 + @environment = environment
  15 + @themes = environment.themes + Theme.approved_themes(target)
  16 +
  17 + @current_theme = target.theme
  18 +
  19 + @layout_templates = LayoutTemplate.all
  20 + @current_template = target.layout_template
  21 + end
  22 +
  23 + def set
  24 + target.update_theme(params[:id])
  25 + redirect_to :action => 'index'
  26 + end
  27 +
  28 + def unset
  29 + if target.kind_of?(Environment)
  30 + target.update_theme('default')
  31 + else
  32 + target.update_theme(nil)
  33 + end
  34 + redirect_to :action => 'index'
  35 + end
  36 +
  37 + def set_layout_template
  38 + target.update_layout_template(params[:id])
  39 + redirect_to :action => 'index'
  40 + end
  41 +
  42 +end
... ...
app/models/environment.rb
... ... @@ -26,7 +26,8 @@ class Environment &lt; ActiveRecord::Base
26 26 'manage_environment_users' => N_('Manage environment users'),
27 27 'manage_environment_templates' => N_('Manage environment templates'),
28 28 'manage_environment_licenses' => N_('Manage environment licenses'),
29   - 'manage_environment_trusted_sites' => N_('Manage environment trusted sites')
  29 + 'manage_environment_trusted_sites' => N_('Manage environment trusted sites'),
  30 + 'edit_appearance' => N_('Edit appearance'),
30 31 }
31 32  
32 33 module Roles
... ... @@ -677,6 +678,14 @@ class Environment &lt; ActiveRecord::Base
677 678 end
678 679 end
679 680  
  681 + def update_theme(theme)
  682 + self.update_attribute(:theme, theme)
  683 + end
  684 +
  685 + def update_layout_template(template)
  686 + self.update_attribute(:layout_template, template)
  687 + end
  688 +
680 689 before_create do |env|
681 690 env.settings[:themes] ||= %w[
682 691 aluminium
... ...
app/views/admin_panel/index.rhtml
... ... @@ -6,6 +6,7 @@
6 6 <tr><td><%= link_to _('Environment settings'), :action => 'site_info' %></td></tr>
7 7 <tr><td><%= link_to _('Features'), :controller => 'features' %></td></tr>
8 8 <tr><td><%= link_to _('Plugins'), :controller => 'plugins' %></td></tr>
  9 + <tr><td><%= link_to _('Appearance'), :controller =>'environment_themes' %></td></tr>
9 10 <tr><td><%= link_to _('Sideboxes'), :controller => 'environment_design'%></td></tr>
10 11 <tr><td><%= link_to _('Homepage'), :action => 'set_portal_community' %></td></tr>
11 12 <tr><td><%= link_to _('Licenses'), :controller =>'licenses' %></td></tr>
... ...
app/views/environment_themes/index.rhtml 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<%= render :partial => 'themes/select_template' %>
  2 +<%= render :partial => 'themes/select_theme' %>
  3 +
  4 +<br style="clear:both" />
  5 +
  6 +<% button_bar do %>
  7 + <%= button(:back, _('Back'), :controller => 'admin_panel', :action => 'index') %>
  8 +<% end %>
... ...
app/views/profile_editor/index.rhtml
... ... @@ -22,7 +22,7 @@
22 22  
23 23 <%= control_panel_button(_('Edit sideboxes'), 'blocks', :controller => 'profile_design', :action => 'index') %>
24 24  
25   - <%= control_panel_button(_('Edit Appearance'), 'design-editor', :controller => 'themes', :action => 'index') %>
  25 + <%= control_panel_button(_('Edit Appearance'), 'design-editor', :controller => 'profile_themes', :action => 'index') %>
26 26  
27 27 <%= control_panel_button(_('Edit Header and Footer'), 'header-and-footer', :controller => 'profile_editor', :action => 'header_footer') unless profile.enterprise? && environment.enabled?('disable_header_and_footer') && !user.is_admin?(environment) %>
28 28  
... ...
app/views/profile_themes/add_css.rhtml 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +<h2><%= _('Add a CSS file') %></h2>
  2 +
  3 +<% form_tag do %>
  4 + <%= labelled_form_field(_('File name'), text_field_tag('css')) %>
  5 +
  6 + <% button_bar do %>
  7 + <%= submit_button(:add, _('Add')) %>
  8 + <%= lightbox_close_button(_('Cancel')) %>
  9 + <% end %>
  10 +
  11 +<% end %>
... ...
app/views/profile_themes/add_image.rhtml 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<% form_tag({:action => 'add_image', :id => @theme.id}, :multipart => true) do %>
  2 + <%= labelled_form_field(_('Choose the image file'), file_field_tag(:image)) %>
  3 + <% button_bar do %>
  4 + <%= submit_button(:add, _('Add image')) %>
  5 + <% end %>
  6 +<% end %>
... ...
app/views/profile_themes/css_editor.rhtml 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +<h2><%= _('CSS code: "%s"') % @css %></h2>
  2 +
  3 +<% form_tag({:action => 'update_css', :id => @theme.id }, :name => 'csscode_form') do %>
  4 + <%= hidden_field_tag('css', @css) %>
  5 + <%= text_area_tag('csscode', @code, :id => "codepressWindow", :class => 'codepress css') %>
  6 + <% button_bar do %>
  7 + <%= submit_button(:save, _('Save')) %>
  8 + <% end %>
  9 +<% end %>
  10 +
  11 +<!--<script type='text/javascript'>-->
  12 + <!--CodePress.run();-->
  13 +<!--</script>-->
... ...
app/views/profile_themes/edit.rhtml 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +<form>
  2 + <%# FIXME %>
  3 + <h1 id='theme-name'>
  4 + <%= _('Editing theme "%s"') % @theme.name %>
  5 + <%= button(:eyes, _('Preview this theme'), :action => 'start_test', :id => @theme.id) %>
  6 + <%= button(:back, _('Back'), :action => 'index') %>
  7 + </h1>
  8 +</form>
  9 +
  10 +
  11 +<div id='css-files-list'>
  12 + <h2><%= _('CSS files') %></h2>
  13 + <ul>
  14 + <% for css in @css_files %>
  15 + <li><%= link_to_remote(css, :url => { :action => 'css_editor', :id => @theme.id, :css => css }, :update => { :success => 'css-code' }) %></li>
  16 + <% end %>
  17 + </ul>
  18 + <% button_bar do %>
  19 + <%= lightbox_button(:add, _('New CSS'), :action => 'add_css', :id => @theme.id) %>
  20 + <% end %>
  21 +</div>
  22 +
  23 +<div id='image-files-list'>
  24 + <h2><%= _('Images') %></h2>
  25 + <ul>
  26 + <% for image in @image_files %>
  27 + <li><%= image_tag("/user_themes/#{@theme.id}/images/#{image}") %></li>
  28 + <% end %>
  29 + </ul>
  30 + <% button_bar do %>
  31 + <%= lightbox_button(:add, _('Add image'), :action => 'add_image', :id => @theme.id) %>
  32 + <% end %>
  33 +</div>
  34 +
  35 +<div id='css-code'>
  36 + <center style='padding-top: 5em;'>
  37 + <em><%= _('Select a CSS file to edit') %></em>
  38 + </center>
  39 +</div>
  40 +
  41 +<%# javascript_include_tag 'codepress/codepress' %>
... ...
app/views/profile_themes/index.rhtml 0 → 100644
... ... @@ -0,0 +1,48 @@
  1 +<%= render :partial => 'themes/select_template' %>
  2 +<%= render :partial => 'themes/select_theme' %>
  3 +
  4 +<% if environment.enabled?('user_themes') %>
  5 + <div id="user-themes" class="list-options">
  6 +
  7 + <h2><%= _('My themes') %></h2>
  8 +
  9 + <% for themes in profile.themes.in_groups_of(3) %>
  10 + <div class="list-group">
  11 + <% for theme in themes %><%=
  12 + if theme
  13 +
  14 + selected = theme.id == @current_theme
  15 + sel_html = selected ?
  16 + content_tag('big', _('(current)') ) :
  17 + link_to(_('Use this theme'), :action => 'set', :id => theme.id)
  18 +
  19 + content_tag( 'div',
  20 + image_tag(
  21 + '/images/icons-app/design-editor.png',
  22 + :alt => (_('The "%s" theme.') % theme.name)) +
  23 + '<div class="opt-info">' +
  24 + content_tag('strong', theme.name, :class => 'name') +
  25 + ' <br/> '+ sel_html +' <br/> ' +
  26 + link_to(_('Edit this theme'), :action => 'edit', :id => theme.id) +
  27 + ' <br/> ' +
  28 + link_to(_('Test this theme'), :action => 'start_test', :id => theme.id) +
  29 + '</div>',
  30 + :class => 'theme-opt list-opt' + (selected ? ' selected' : '')
  31 + )
  32 +
  33 + end
  34 + %><% end %>
  35 + </div>
  36 + <% end %>
  37 +
  38 + </div><!-- end id="user-themes" -->
  39 +<% end %>
  40 +
  41 +<br style="clear:both" />
  42 +
  43 +<% button_bar do %>
  44 + <% if environment.enabled?('user_themes') %>
  45 + <%= lightbox_button(:add, _('New theme ...'), :action => 'new') %>
  46 + <% end %>
  47 + <%= button(:back, _('Back'), :controller => 'profile_editor', :action => 'index') %>
  48 +<% end %>
... ...
app/views/profile_themes/new.rhtml 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +<h2><%= _('Create new theme') %></h2>
  2 +
  3 +<% form_tag(:action => 'new') do %>
  4 +
  5 + <%= labelled_form_field(_('Name of the new theme:'), text_field_tag(:name)) %>
  6 +
  7 + <% button_bar do %>
  8 + <%= submit_button(:save, _('Create')) %>
  9 + <% end %>
  10 +<% end %>
... ...
app/views/shared/theme_test_panel.rhtml
... ... @@ -6,8 +6,8 @@
6 6 <p><small><em><%= _('You can move this window away to have a better visualization of specific parts of screen.') %></em></small></p>
7 7  
8 8 <% button_bar do %>
9   - <%= button(:ok, _('Finished testing'), :controller => 'themes', :profile => theme_owner, :action => 'stop_test', :id => current_theme) %>
10   - <%= button(:edit, _('Edit theme'), :controller => 'themes', :profile => theme_owner, :action => 'edit', :id => current_theme) %>
  9 + <%= button(:ok, _('Finished testing'), :controller => 'profile_themes', :profile => theme_owner, :action => 'stop_test', :id => current_theme) %>
  10 + <%= button(:edit, _('Edit theme'), :controller => 'profile_themes', :profile => theme_owner, :action => 'edit', :id => current_theme) %>
11 11 <% end %>
12 12 </div>
13 13 <%= draggable_element('theme-test-panel') %>
... ...
app/views/themes/_select_template.rhtml 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +<h1><%= _('Editing Appearance') %></h1>
  2 +
  3 +<div id="template-options" class="list-options">
  4 +
  5 +<h2><%= _('Select template') %></h2>
  6 +
  7 +<% for templates in @layout_templates.in_groups_of(3) %>
  8 + <div class="list-group">
  9 + <% for template in templates %><%=
  10 + if template
  11 + base_content = image_tag(
  12 + "/designs/templates/#{template.id}/thumbnail.png",
  13 + :alt => _('The "%s" template')) +
  14 + '<div class="opt-info">'.html_safe +
  15 + content_tag('strong', template.name, :class => 'name') +
  16 + ' <br/> '.html_safe
  17 +
  18 + if @current_template == template.id # selected
  19 + content_tag( 'div',
  20 + base_content + content_tag('big', _('(current)') ) +'</div>'.html_safe,
  21 + :class => 'template-opt list-opt selected')
  22 + else # Not selected
  23 + link_to(
  24 + base_content +'</div>'.html_safe,
  25 + { :action => 'set_layout_template', :id => template.id },
  26 + :class => 'template-opt list-opt')
  27 + end
  28 +
  29 + end
  30 + %><% end %>
  31 + </div>
  32 +<% end %>
  33 +
  34 +</div><!-- end id="template-options" -->
  35 +
... ...
app/views/themes/_select_theme.rhtml 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +<% if !@themes.empty? %>
  2 +<div id="theme-options" class="list-options">
  3 +
  4 +<h2><%= _('Select theme') %></h2>
  5 +<%= button :home, _('Use the default theme'), { :action => 'unset'}, :method => 'post', :confirm => _('Are you sure you want to use the environment default theme?') %>
  6 +
  7 +<% for themes in @themes.in_groups_of(3) %>
  8 + <div class="list-group">
  9 + <% for theme in themes %><%=
  10 + if theme
  11 +
  12 + base_content = image_tag(
  13 + "/designs/themes/#{theme.id}/preview.png",
  14 + :alt => (_('The "%s" theme.') % theme.name)) +
  15 + '<div class="opt-info">'.html_safe +
  16 + content_tag('strong', theme.name, :class => 'name') +
  17 + ' <br/> '.html_safe
  18 +
  19 + if theme.id == @current_theme # selected
  20 + content_tag( 'div',
  21 + base_content + content_tag('big', _('(current)') ) +'</div>'.html_safe,
  22 + :class => 'theme-opt list-opt selected')
  23 + else # Not selected
  24 + link_to(
  25 + base_content + '</div>'.html_safe,
  26 + { :action => 'set', :id => theme.id },
  27 + :class => 'theme-opt list-opt')
  28 + end
  29 +
  30 + end
  31 + %><% end %>
  32 + </div>
  33 +<% end %>
  34 +
  35 +</div><!-- end id="theme-options" -->
  36 +<% end %>
  37 +
... ...
app/views/themes/add_css.rhtml
... ... @@ -1,11 +0,0 @@
1   -<h2><%= _('Add a CSS file') %></h2>
2   -
3   -<% form_tag do %>
4   - <%= labelled_form_field(_('File name'), text_field_tag('css')) %>
5   -
6   - <% button_bar do %>
7   - <%= submit_button(:add, _('Add')) %>
8   - <%= lightbox_close_button(_('Cancel')) %>
9   - <% end %>
10   -
11   -<% end %>
app/views/themes/add_image.rhtml
... ... @@ -1,6 +0,0 @@
1   -<% form_tag({:action => 'add_image', :id => @theme.id}, :multipart => true) do %>
2   - <%= labelled_form_field(_('Choose the image file'), file_field_tag(:image)) %>
3   - <% button_bar do %>
4   - <%= submit_button(:add, _('Add image')) %>
5   - <% end %>
6   -<% end %>
app/views/themes/css_editor.rhtml
... ... @@ -1,13 +0,0 @@
1   -<h2><%= _('CSS code: "%s"') % @css %></h2>
2   -
3   -<% form_tag({:action => 'update_css', :id => @theme.id }, :name => 'csscode_form') do %>
4   - <%= hidden_field_tag('css', @css) %>
5   - <%= text_area_tag('csscode', @code, :id => "codepressWindow", :class => 'codepress css') %>
6   - <% button_bar do %>
7   - <%= submit_button(:save, _('Save')) %>
8   - <% end %>
9   -<% end %>
10   -
11   -<!--<script type='text/javascript'>-->
12   - <!--CodePress.run();-->
13   -<!--</script>-->
app/views/themes/edit.rhtml
... ... @@ -1,41 +0,0 @@
1   -<form>
2   - <%# FIXME %>
3   - <h1 id='theme-name'>
4   - <%= _('Editing theme "%s"') % @theme.name %>
5   - <%= button(:eyes, _('Preview this theme'), :action => 'start_test', :id => @theme.id) %>
6   - <%= button(:back, _('Back'), :action => 'index') %>
7   - </h1>
8   -</form>
9   -
10   -
11   -<div id='css-files-list'>
12   - <h2><%= _('CSS files') %></h2>
13   - <ul>
14   - <% for css in @css_files %>
15   - <li><%= link_to_remote(css, :url => { :action => 'css_editor', :id => @theme.id, :css => css }, :update => { :success => 'css-code' }) %></li>
16   - <% end %>
17   - </ul>
18   - <% button_bar do %>
19   - <%= lightbox_button(:add, _('New CSS'), :action => 'add_css', :id => @theme.id) %>
20   - <% end %>
21   -</div>
22   -
23   -<div id='image-files-list'>
24   - <h2><%= _('Images') %></h2>
25   - <ul>
26   - <% for image in @image_files %>
27   - <li><%= image_tag("/user_themes/#{@theme.id}/images/#{image}") %></li>
28   - <% end %>
29   - </ul>
30   - <% button_bar do %>
31   - <%= lightbox_button(:add, _('Add image'), :action => 'add_image', :id => @theme.id) %>
32   - <% end %>
33   -</div>
34   -
35   -<div id='css-code'>
36   - <center style='padding-top: 5em;'>
37   - <em><%= _('Select a CSS file to edit') %></em>
38   - </center>
39   -</div>
40   -
41   -<%# javascript_include_tag 'codepress/codepress' %>
app/views/themes/index.rhtml
... ... @@ -1,120 +0,0 @@
1   -<h1><%= _('Editing Appearance') %></h1>
2   -
3   -<div id="template-options" class="list-options">
4   -
5   -<h2><%= _('Select template') %></h2>
6   -
7   -<% for templates in @layout_templates.in_groups_of(3) %>
8   - <div class="list-group">
9   - <% for template in templates %><%=
10   - if template
11   - base_content = image_tag(
12   - "/designs/templates/#{template.id}/thumbnail.png",
13   - :alt => _('The "%s" template')) +
14   - '<div class="opt-info">'.html_safe +
15   - content_tag('strong', template.name, :class => 'name') +
16   - ' <br/> '.html_safe
17   -
18   - if @current_template == template.id # selected
19   - content_tag( 'div',
20   - base_content + content_tag('big', _('(current)') ) +'</div>'.html_safe,
21   - :class => 'template-opt list-opt selected')
22   - else # Not selected
23   - link_to(
24   - base_content +'</div>'.html_safe,
25   - { :action => 'set_layout_template', :id => template.id },
26   - :class => 'template-opt list-opt')
27   - end
28   -
29   - end
30   - %><% end %>
31   - </div>
32   -<% end %>
33   -
34   -</div><!-- end id="template-options" -->
35   -
36   -
37   -<% if !@themes.empty? %>
38   -<div id="theme-options" class="list-options">
39   -
40   -<h2><%= _('Select theme') %></h2>
41   -<%= button :home, _('Use the default theme'), { :action => 'unset'}, :method => 'post', :confirm => _('Are you sure you want to use the environment default theme?') %>
42   -
43   -<% for themes in @themes.in_groups_of(3) %>
44   - <div class="list-group">
45   - <% for theme in themes %><%=
46   - if theme
47   -
48   - base_content = image_tag(
49   - "/designs/themes/#{theme.id}/preview.png",
50   - :alt => (_('The "%s" theme.') % theme.name)) +
51   - '<div class="opt-info">'.html_safe +
52   - content_tag('strong', theme.name, :class => 'name') +
53   - ' <br/> '.html_safe
54   -
55   - if theme.id == @current_theme # selected
56   - content_tag( 'div',
57   - base_content + content_tag('big', _('(current)') ) +'</div>'.html_safe,
58   - :class => 'theme-opt list-opt selected')
59   - else # Not selected
60   - link_to(
61   - base_content + '</div>'.html_safe,
62   - { :action => 'set', :id => theme.id },
63   - :class => 'theme-opt list-opt')
64   - end
65   -
66   - end
67   - %><% end %>
68   - </div>
69   -<% end %>
70   -
71   -</div><!-- end id="theme-options" -->
72   -<% end %>
73   -
74   -
75   -
76   -<% if environment.enabled?('user_themes') %>
77   - <div id="user-themes" class="list-options">
78   -
79   - <h2><%= _('My themes') %></h2>
80   -
81   - <% for themes in profile.themes.in_groups_of(3) %>
82   - <div class="list-group">
83   - <% for theme in themes %><%=
84   - if theme
85   -
86   - selected = theme.id == @current_theme
87   - sel_html = selected ?
88   - content_tag('big', _('(current)') ) :
89   - link_to(_('Use this theme'), :action => 'set', :id => theme.id)
90   -
91   - content_tag( 'div',
92   - image_tag(
93   - '/images/icons-app/design-editor.png',
94   - :alt => (_('The "%s" theme.') % theme.name)) +
95   - '<div class="opt-info">' +
96   - content_tag('strong', theme.name, :class => 'name') +
97   - ' <br/> '+ sel_html +' <br/> ' +
98   - link_to(_('Edit this theme'), :action => 'edit', :id => theme.id) +
99   - ' <br/> ' +
100   - link_to(_('Test this theme'), :action => 'start_test', :id => theme.id) +
101   - '</div>',
102   - :class => 'theme-opt list-opt' + (selected ? ' selected' : '')
103   - )
104   -
105   - end
106   - %><% end %>
107   - </div>
108   - <% end %>
109   -
110   - </div><!-- end id="user-themes" -->
111   -<% end %>
112   -
113   -<br style="clear:both" />
114   -
115   -<% button_bar do %>
116   - <% if environment.enabled?('user_themes') %>
117   - <%= lightbox_button(:add, _('New theme ...'), :action => 'new') %>
118   - <% end %>
119   - <%= button(:back, _('Back'), :controller => 'profile_editor', :action => 'index') %>
120   -<% end %>
app/views/themes/new.rhtml
... ... @@ -1,10 +0,0 @@
1   -<h2><%= _('Create new theme') %></h2>
2   -
3   -<% form_tag(:action => 'new') do %>
4   -
5   - <%= labelled_form_field(_('Name of the new theme:'), text_field_tag(:name)) %>
6   -
7   - <% button_bar do %>
8   - <%= submit_button(:save, _('Create')) %>
9   - <% end %>
10   -<% end %>
public/stylesheets/application.css
... ... @@ -4319,7 +4319,7 @@ h1#agenda-title {
4319 4319 padding-left: 0px;
4320 4320 list-style-type: none;
4321 4321 }
4322   -/* ==> public/stylesheets/controller_themes.css <== */
  4322 +/* ==> public/stylesheets/profile_controller_themes.css <== */
4323 4323  
4324 4324 .action-themes-index .button-bar {
4325 4325 padding-top: 20px;
... ... @@ -4393,23 +4393,23 @@ h1#agenda-title {
4393 4393 #user-themes a:hover {
4394 4394 text-decoration: underline;
4395 4395 }
4396   -.controller-themes .template-preview-cell {
  4396 +.controller-profile_themes .template-preview-cell {
4397 4397 text-align: center;
4398 4398 }
4399   -.controller-themes .theme-preview {
  4399 +.controller-profile_themes .theme-preview {
4400 4400 border: 1px solid #BBB;
4401 4401 }
4402   -.controller-themes #css-files-list h2, .controller-themes #image-files-list h2 {
  4402 +.controller-profile_themes #css-files-list h2, .controller-profile_themes #image-files-list h2 {
4403 4403 margin-top: 0px;
4404 4404 }
4405   -.controller-themes #css-files-list ul, .controller-themes #image-files-list ul, .controller-themes #css-code textarea {
  4405 +.controller-profile_themes #css-files-list ul, .controller-profile_themes #image-files-list ul, .controller-profile_themes #css-code textarea {
4406 4406 height: 280px;
4407 4407 }
4408   -.controller-themes #css-files-list ul, .controller-themes #image-files-list ul {
  4408 +.controller-profile_themes #css-files-list ul, .controller-profile_themes #image-files-list ul {
4409 4409 overflow: auto;
4410 4410 }
4411 4411 /* header stuff */
4412   -.controller-themes #theme-name input {
  4412 +.controller-profile_themes #theme-name input {
4413 4413 font-size: 18px;
4414 4414 border: 1px solid black;
4415 4415 background: white;
... ... @@ -4418,78 +4418,78 @@ h1#agenda-title {
4418 4418 }
4419 4419 /* files list */
4420 4420  
4421   -.controller-themes #css-files-list {
  4421 +.controller-profile_themes #css-files-list {
4422 4422 width: 200px;
4423 4423 float: left;
4424 4424 margin-left: 10px;
4425 4425 }
4426   -.controller-themes #css-files-list ul {
  4426 +.controller-profile_themes #css-files-list ul {
4427 4427 margin: 0px;
4428 4428 padding-left: 0px;
4429 4429 background: white;
4430 4430 border: 1px solid #bbb;
4431 4431 }
4432   -.controller-themes #css-files-list li {
  4432 +.controller-profile_themes #css-files-list li {
4433 4433 list-style: none;
4434 4434 margin-bottom: 5px;
4435 4435 border-bottom: 1px solid #bbb;
4436 4436 }
4437   -.controller-themes #css-files-list li a {
  4437 +.controller-profile_themes #css-files-list li a {
4438 4438 display: block;
4439 4439 padding: 1px 5px;
4440 4440 }
4441   -.controller-themes #css-files-list a:hover {
  4441 +.controller-profile_themes #css-files-list a:hover {
4442 4442 color: red;
4443 4443 }
4444 4444 /* images list */
4445 4445  
4446   -.controller-themes #image-files-list {
  4446 +.controller-profile_themes #image-files-list {
4447 4447 width: 200px;
4448 4448 float: right;
4449 4449 margin-right: 10px;
4450 4450 }
4451   -.controller-themes #image-files-list ul {
  4451 +.controller-profile_themes #image-files-list ul {
4452 4452 background: white;
4453 4453 border: 1px solid #bbb;
4454 4454 }
4455   -.controller-themes #image-files-list ul, .controller-themes #image-files-list li {
  4455 +.controller-profile_themes #image-files-list ul, .controller-profile_themes #image-files-list li {
4456 4456 padding: 0px;
4457 4457 margin: 0px;
4458 4458 list-style: none;
4459 4459 }
4460   -.controller-themes #image-files-list li {
  4460 +.controller-profile_themes #image-files-list li {
4461 4461 border-bottom: 1px solid #bbb;
4462 4462 padding: 5px 0px;
4463 4463 text-align: center;
4464 4464 }
4465   -.controller-themes #image-files-list img {
  4465 +.controller-profile_themes #image-files-list img {
4466 4466 max-width: 98%;
4467 4467 max-height: 40px;
4468 4468 }
4469   -.controller-themes .msie6 #image-files-list img {
  4469 +.controller-profile_themes .msie6 #image-files-list img {
4470 4470 width: 50%;
4471 4471 height: 40px;
4472 4472 }
4473   -.controller-themes #image-files-list li span {
  4473 +.controller-profile_themes #image-files-list li span {
4474 4474 display: block;
4475 4475 width: 100%;
4476 4476 overflow: hidden;
4477 4477 }
4478 4478 /* textbox */
4479 4479  
4480   -.controller-themes #css-code {
  4480 +.controller-profile_themes #css-code {
4481 4481 margin-left: 220px;
4482 4482 margin-right: 220px;
4483 4483 }
4484   -.controller-themes .msie6 #css-code {
  4484 +.controller-profile_themes .msie6 #css-code {
4485 4485 float: left;
4486 4486 margin-left: 20px;
4487 4487 margin-right: 240px;
4488 4488 }
4489   -.controller-themes #css-code textarea {
  4489 +.controller-profile_themes #css-code textarea {
4490 4490 width: 100%;
4491 4491 }
4492   -.controller-themes .msie6 #css-code textarea {
  4492 +.controller-profile_themes .msie6 #css-code textarea {
4493 4493 width: 500px;
4494 4494 }
4495 4495 /* highlights block stuff */
... ...
test/factories.rb
... ... @@ -55,7 +55,7 @@ module Noosfero::Factory
55 55 ###### old stuff to be rearranged
56 56 def create_admin_user(env)
57 57 admin_user = User.find_by_login('adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser', :environment => env)
58   - admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_trusted_sites', 'manage_environment_validators', 'manage_environment_users', 'manage_environment_templates', 'manage_environment_licenses'])
  58 + admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_trusted_sites', 'manage_environment_validators', 'manage_environment_users', 'manage_environment_templates', 'manage_environment_licenses', 'edit_appearance'])
59 59 RoleAssignment.create!(:accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env])
60 60 admin_user.login
61 61 end
... ...
test/functional/environment_themes_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,138 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class EnvironmentThemesController; def rescue_action(e) raise e end; end
  4 +
  5 +class EnvironmentThemesControllerTest < ActionController::TestCase
  6 +
  7 + def setup
  8 + @controller = EnvironmentThemesController.new
  9 + @request = ActionController::TestRequest.new
  10 + @response = ActionController::TestResponse.new
  11 +
  12 + Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR)
  13 +
  14 + @env = Environment.default
  15 + login = create_admin_user(@env)
  16 + login_as(login)
  17 + @profile = User.find_by_login(login).person
  18 + end
  19 +
  20 + def teardown
  21 + FileUtils.rm_rf(TMP_THEMES_DIR)
  22 + end
  23 +
  24 + TMP_THEMES_DIR = RAILS_ROOT + '/test/tmp/environment_themes_controller'
  25 +
  26 + should 'display themes that can be applied' do
  27 + env = Environment.default
  28 + Theme.stubs(:approved_themes).with(@env).returns([])
  29 + t1 = 't1'
  30 + t2 = 't2'
  31 + t3 = 't3'
  32 + env.themes = [t1, t2]
  33 + env.save
  34 +
  35 + Theme.stubs(:system_themes).returns([Theme.new(t1), Theme.new(t2), Theme.new(t3)])
  36 + get :index
  37 +
  38 + %w[ t1 t2 ].each do |item|
  39 + assert_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set/#{item}" }
  40 + end
  41 +
  42 + assert_no_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set/t3" }
  43 + end
  44 +
  45 + should 'highlight current theme' do
  46 + env = Environment.default
  47 + t1 = 'one'
  48 + t2 = 'two'
  49 + env.themes = [t1, t2]
  50 + env.save
  51 +
  52 + Theme.stubs(:system_themes).returns([Theme.new(t1), Theme.new(t2)])
  53 + env.update_theme(t1)
  54 + get :index
  55 +
  56 + assert_tag :attributes => { :class => 'theme-opt list-opt selected' }
  57 + assert_no_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set/one" }
  58 + end
  59 +
  60 + should 'save selection of theme' do
  61 + get :set, :id => 'onetheme'
  62 + env = Environment.default
  63 + assert_equal 'onetheme', env.theme
  64 + end
  65 +
  66 +
  67 + should 'unset selection of theme' do
  68 + get :unset
  69 + env = Environment.default
  70 + assert_equal 'default', env.theme
  71 + end
  72 +
  73 + should 'display link to use the default theme' do
  74 + env = Environment.default
  75 + env.themes = ['new-theme']
  76 + env.save
  77 +
  78 + Theme.stubs(:system_themes).returns([Theme.new('new-theme')])
  79 +
  80 + get :index
  81 + assert_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/unset" }
  82 + end
  83 +
  84 + should 'point back to admin panel' do
  85 + get :index
  86 + assert_tag :tag => 'a', :attributes => { :href => '/admin' }, :content => 'Back'
  87 + end
  88 +
  89 + should 'list templates' do
  90 + all = LayoutTemplate.all
  91 +
  92 + LayoutTemplate.expects(:all).returns(all)
  93 + get :index
  94 + assert_same all, assigns(:layout_templates)
  95 + end
  96 +
  97 + should 'display links to set template' do
  98 + env = Environment.default
  99 + env.update_attributes!(:layout_template => 'rightbar')
  100 + t1 = LayoutTemplate.find('default')
  101 + t2 = LayoutTemplate.find('leftbar')
  102 + LayoutTemplate.expects(:all).returns([t1, t2])
  103 +
  104 + get :index
  105 + assert_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set_layout_template/default"}
  106 + assert_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set_layout_template/leftbar"}
  107 + end
  108 +
  109 + should 'highlight current template' do
  110 + env = Environment.default
  111 + env.update_attributes!(:layout_template => 'default')
  112 +
  113 + t1 = LayoutTemplate.find('default')
  114 + t2 = LayoutTemplate.find('leftbar')
  115 + LayoutTemplate.expects(:all).returns([t1, t2])
  116 +
  117 + get :index
  118 + assert_tag :attributes => { :class => 'template-opt list-opt selected' }
  119 + assert_no_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set_layout_template/default"}
  120 + end
  121 +
  122 + should 'set template' do
  123 + env = Environment.default
  124 + post :set_layout_template, :id => 'leftbar'
  125 + env.reload
  126 + assert_equal 'leftbar', env.layout_template
  127 + assert_redirected_to :action => 'index'
  128 + end
  129 +
  130 + should 'not display the "Select themes" section if there are no themes to choose from' do
  131 + env = Environment.default
  132 + env.themes = []; env.save!
  133 + Theme.stubs(:system_themes_dir).returns(TMP_THEMES_DIR) # an empty dir
  134 + get :index
  135 + assert_no_tag :content => "Select theme"
  136 + end
  137 +
  138 +end
... ...
test/functional/profile_themes_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,311 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +# require 'profile_themes_controller'
  3 +
  4 +class ProfileThemesController; def rescue_action(e) raise e end; end
  5 +
  6 +class ProfileThemesControllerTest < ActionController::TestCase
  7 +
  8 + def setup
  9 + @controller = ProfileThemesController.new
  10 + @request = ActionController::TestRequest.new
  11 + @response = ActionController::TestResponse.new
  12 +
  13 + Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR)
  14 +
  15 + @profile = create_user('testinguser').person
  16 + login_as('testinguser')
  17 +
  18 + @env = Environment.default
  19 + @env.enable('user_themes')
  20 + @env.save!
  21 + end
  22 + attr_reader :profile, :env
  23 +
  24 + def teardown
  25 + FileUtils.rm_rf(TMP_THEMES_DIR)
  26 + end
  27 +
  28 + TMP_THEMES_DIR = RAILS_ROOT + '/test/tmp/profile_themes_controller'
  29 +
  30 + should 'display themes that can be applied' do
  31 + env = Environment.default
  32 + Theme.stubs(:approved_themes).with(@profile).returns([Theme.new('t1', :name => 't1')])
  33 + t2 = 't2'
  34 + t3 = 't3'
  35 + env.themes = [t2]
  36 + env.save
  37 +
  38 + Theme.stubs(:system_themes).returns([Theme.new(t2), Theme.new(t3)])
  39 + get :index, :profile => 'testinguser'
  40 +
  41 + %w[ t1 t2 ].each do |item|
  42 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/set/#{item}" }
  43 + end
  44 +
  45 + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/set/t3" }
  46 + end
  47 +
  48 + should 'highlight current theme' do
  49 + env = Environment.default
  50 + t1 = 'one'
  51 + t2 = 'two'
  52 + env.themes = [t1, t2]
  53 + env.save
  54 +
  55 + Theme.stubs(:system_themes).returns([Theme.new(t1), Theme.new(t2)])
  56 + profile.update_theme(t1)
  57 + get :index, :profile => 'testinguser'
  58 +
  59 + assert_tag :attributes => { :class => 'theme-opt list-opt selected' }
  60 + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/set/one" }
  61 + end
  62 +
  63 + should 'display list of my themes for edition' do
  64 + Theme.create('three', :owner => profile)
  65 + Theme.create('four', :owner => profile)
  66 +
  67 + get :index, :profile => 'testinguser'
  68 +
  69 + %w[ three four ].each do |item|
  70 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/edit/#{item}" }
  71 + end
  72 + end
  73 +
  74 + should 'save selection of theme' do
  75 + get :set, :profile => 'testinguser', :id => 'onetheme'
  76 + profile = Profile.find(@profile.id)
  77 + assert_equal 'onetheme', profile.theme
  78 + end
  79 +
  80 + should 'save selection of theme even if model is invalid' do
  81 + @profile.sex = nil
  82 + @profile.save!
  83 + @profile.environment.custom_person_fields = { 'sex' => {'required' => 'true', 'active' => 'true'} }; @profile.environment.save!
  84 +
  85 + get :set, :profile => 'testinguser', :id => 'onetheme'
  86 + profile = Profile.find(@profile.id)
  87 + assert_equal 'onetheme', profile.theme
  88 + end
  89 +
  90 + should 'unset selection of theme' do
  91 + get :unset, :profile => 'testinguser'
  92 + assert_equal nil, profile.theme
  93 + end
  94 +
  95 + should 'display link to use the default theme' do
  96 + env = Environment.default
  97 + env.themes = ['new-theme']
  98 + env.save
  99 +
  100 + Theme.stubs(:system_themes).returns([Theme.new('new-theme')])
  101 +
  102 + get :index, :profile => 'testinguser'
  103 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/unset" }
  104 + end
  105 +
  106 + should 'point back to control panel' do
  107 + get :index, :profile => 'testinguser'
  108 + assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser' }, :content => 'Back'
  109 + end
  110 +
  111 + should 'display screen for creating new theme' do
  112 + @request.expects(:xhr?).returns(true).at_least_once
  113 + get :new, :profile => 'testinguser'
  114 + assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/profile_themes/new', :method => /post/i }, :descendant => { :tag => 'input', :attributes => { :type => 'text', :name => 'name' } }
  115 + end
  116 +
  117 + should 'create a new theme' do
  118 + post :new, :profile => 'testinguser', :name => 'My theme'
  119 +
  120 + ok('theme should be created') do
  121 + profile.themes.first.id == 'my-theme'
  122 + end
  123 + end
  124 +
  125 + should 'edit a theme' do
  126 + theme = Theme.create('mytheme', :owner => profile)
  127 + get :edit, :profile => 'testinguser', :id => 'mytheme'
  128 +
  129 + assert_equal theme, assigns(:theme)
  130 + end
  131 +
  132 + should 'list CSS files in theme' do
  133 + theme = Theme.create('mytheme', :owner => profile)
  134 + theme.add_css('one.css')
  135 + theme.add_css('two.css')
  136 +
  137 + get :edit, :profile => 'testinguser', :id => 'mytheme'
  138 +
  139 + %w[ one.css two.css ].each do |item|
  140 + assert_includes assigns(:css_files), item
  141 + assert_tag :tag => 'li', :descendant => { :tag => 'a', :content => item}
  142 + end
  143 + end
  144 +
  145 + should 'display dialog for creating new CSS' do
  146 + theme = Theme.create('mytheme', :owner => profile)
  147 + @request.stubs(:xhr?).returns(true)
  148 + get :add_css, :profile => 'testinguser', :id => 'mytheme'
  149 +
  150 + assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/profile_themes/add_css/mytheme', :method => /post/i}
  151 + assert_tag :tag => 'input', :attributes => { :name => 'css', :type => 'text' }
  152 + assert_tag :tag => 'input', :attributes => { :type => 'submit' }
  153 + end
  154 +
  155 + should 'be able to add new CSS to theme' do
  156 + theme = Theme.create('mytheme', :owner => profile)
  157 + post :add_css, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css'
  158 +
  159 + assert_response :redirect
  160 +
  161 + reloaded_theme = Theme.find('mytheme')
  162 + assert_includes reloaded_theme.css_files, 'test.css'
  163 + end
  164 +
  165 + should 'load code from a given CSS file' do
  166 + theme = Theme.create('mytheme', :owner => profile); theme.update_css('test.css', '/* sample code */')
  167 + get :css_editor, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css'
  168 +
  169 + assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/profile_themes/update_css/mytheme' }, :descendant => { :tag => 'textarea', :content => '/* sample code */' }
  170 + end
  171 +
  172 + should 'be able to save CSS code' do
  173 + theme = Theme.create('mytheme', :owner => profile); theme.update_css('test.css', '/* sample code */')
  174 + get :css_editor, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css'
  175 +
  176 + assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/profile_themes/update_css/mytheme' }, :descendant => { :tag => 'input', :attributes => { :type => 'submit' } }
  177 + assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/profile_themes/update_css/mytheme' }, :descendant => { :tag => 'input', :attributes => { :type => 'hidden', :name => 'css', :value => 'test.css' } }
  178 + end
  179 +
  180 + should 'update css code when saving' do
  181 + theme = Theme.create('mytheme', :owner => profile); theme.update_css('test.css', '/* sample code */')
  182 + post :update_css, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css', :csscode => 'body { background: white; }'
  183 + assert_equal 'body { background: white; }', theme.read_css('test.css')
  184 + end
  185 +
  186 + should 'list image files in theme' do
  187 + theme = Theme.create('mytheme', :owner => profile)
  188 + theme.add_image('one.png', 'FAKE IMAGE DATA 1')
  189 + theme.add_image('two.png', 'FAKE IMAGE DATA 2')
  190 +
  191 + get :edit, :profile => 'testinguser', :id => 'mytheme'
  192 +
  193 + assert_tag :tag => 'img', :attributes => { :src => '/user_themes/mytheme/images/one.png' }
  194 + assert_tag :tag => 'img', :attributes => { :src => '/user_themes/mytheme/images/two.png' }
  195 + end
  196 +
  197 + should 'display "add image" button' do
  198 + theme = Theme.create('mytheme', :owner => profile)
  199 + get :edit, :profile => 'testinguser', :id => 'mytheme'
  200 +
  201 + assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/profile_themes/add_image/mytheme' }
  202 + end
  203 +
  204 + should 'display the "add image" dialog' do
  205 + theme = Theme.create('mytheme', :owner => profile)
  206 + @request.stubs(:xhr?).returns(true)
  207 +
  208 + get :add_image, :profile => 'testinguser', :id => 'mytheme'
  209 + assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/profile_themes/add_image/mytheme', :method => /post/i, :enctype => 'multipart/form-data' }, :descendant => { :tag => 'input', :attributes => { :name => 'image', :type => 'file' } }
  210 + end
  211 +
  212 + should 'be able to add new image to theme' do
  213 + theme = Theme.create('mytheme', :owner => profile)
  214 + @request.stubs(:xhr?).returns(false)
  215 +
  216 + post :add_image, :profile => 'testinguser', :id => 'mytheme', :image => fixture_file_upload('/files/rails.png', 'image/png', :binary)
  217 + assert_redirected_to :action => "edit", :id => 'mytheme'
  218 + assert theme.image_files.include?('rails.png')
  219 + assert(system('diff', RAILS_ROOT + '/test/fixtures/files/rails.png', TMP_THEMES_DIR + '/mytheme/images/rails.png'), 'should put the correct uploaded file in the right place')
  220 + end
  221 +
  222 + should 'link to "test theme"' do
  223 + Theme.create('one', :owner => profile)
  224 + Theme.create('two', :owner => profile)
  225 + get :index, :profile => 'testinguser'
  226 +
  227 + %w[ one two ].each do |item|
  228 + assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/profile_themes/start_test/' + item }
  229 + end
  230 + end
  231 +
  232 + should 'start testing theme' do
  233 + theme = Theme.create('theme-under-test', :owner => profile)
  234 + post :start_test, :profile => 'testinguser', :id => 'theme-under-test'
  235 +
  236 + assert_equal 'theme-under-test', session[:theme]
  237 + assert_redirected_to :controller => 'content_viewer', :profile => 'testinguser', :action => 'view_page'
  238 + end
  239 +
  240 + should 'stop testing theme' do
  241 + theme = Theme.create('theme-under-test', :owner => profile)
  242 + post :stop_test, :profile => 'testinguser', :id => 'theme-under-test'
  243 +
  244 + assert_nil session[:theme]
  245 + assert_redirected_to :action => 'index'
  246 + end
  247 +
  248 + should 'list templates' do
  249 + all = LayoutTemplate.all
  250 +
  251 + LayoutTemplate.expects(:all).returns(all)
  252 + get :index, :profile => 'testinguser'
  253 + assert_same all, assigns(:layout_templates)
  254 + end
  255 +
  256 + should 'display links to set template' do
  257 + profile.update_attributes!(:layout_template => 'rightbar')
  258 + t1 = LayoutTemplate.find('default')
  259 + t2 = LayoutTemplate.find('leftbar')
  260 + LayoutTemplate.expects(:all).returns([t1, t2])
  261 +
  262 + get :index, :profile => 'testinguser'
  263 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/set_layout_template/default"}
  264 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/set_layout_template/leftbar"}
  265 + end
  266 +
  267 + should 'highlight current template' do
  268 + profile.update_attributes!(:layout_template => 'default')
  269 +
  270 + t1 = LayoutTemplate.find('default')
  271 + t2 = LayoutTemplate.find('leftbar')
  272 + LayoutTemplate.expects(:all).returns([t1, t2])
  273 +
  274 + get :index, :profile => 'testinguser'
  275 + assert_tag :attributes => { :class => 'template-opt list-opt selected' }
  276 + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/set_layout_template/default"}
  277 + end
  278 +
  279 + should 'set template' do
  280 + post :set_layout_template, :profile => 'testinguser', :id => 'leftbar'
  281 + profile = Profile.find(@profile.id)
  282 + assert_equal 'leftbar', profile.layout_template
  283 + assert_redirected_to :action => 'index'
  284 + end
  285 +
  286 + should 'set template even if the model is invalid' do
  287 + @profile.sex = nil
  288 + @profile.save!
  289 + @profile.environment.custom_person_fields = { 'sex' => {'required' => 'true', 'active' => 'true'} }; @profile.environment.save!
  290 +
  291 + post :set_layout_template, :profile => 'testinguser', :id => 'leftbar'
  292 + profile = Profile.find(@profile.id)
  293 + assert_equal 'leftbar', profile.layout_template
  294 + assert_redirected_to :action => 'index'
  295 + end
  296 +
  297 + should 'not display "new theme" button when user themes are disabled' do
  298 + env.disable('user_themes')
  299 + env.save!
  300 + get :index, :profile => 'testinguser'
  301 + assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/profile_themes/new' }
  302 + end
  303 +
  304 + should 'not display the "Select themes" section if there are no themes to choose from' do
  305 + env.themes = []; env.save!
  306 + Theme.stubs(:system_themes_dir).returns(TMP_THEMES_DIR) # an empty dir
  307 + get :index, :profile => "testinguser"
  308 + assert_no_tag :content => "Select theme"
  309 + end
  310 +
  311 +end
... ...
test/functional/themes_controller_test.rb
... ... @@ -1,311 +0,0 @@
1   -require File.dirname(__FILE__) + '/../test_helper'
2   -require 'themes_controller'
3   -
4   -class ThemesController; def rescue_action(e) raise e end; end
5   -
6   -class ThemesControllerTest < ActionController::TestCase
7   -
8   - def setup
9   - @controller = ThemesController.new
10   - @request = ActionController::TestRequest.new
11   - @response = ActionController::TestResponse.new
12   -
13   - Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR)
14   -
15   - @profile = create_user('testinguser').person
16   - login_as('testinguser')
17   -
18   - @env = Environment.default
19   - @env.enable('user_themes')
20   - @env.save!
21   - end
22   - attr_reader :profile, :env
23   -
24   - def teardown
25   - FileUtils.rm_rf(TMP_THEMES_DIR)
26   - end
27   -
28   - TMP_THEMES_DIR = RAILS_ROOT + '/test/tmp/themes_controller'
29   -
30   - should 'display themes that can be applied' do
31   - env = Environment.default
32   - Theme.stubs(:approved_themes).with(@profile).returns([Theme.new('t1', :name => 't1')])
33   - t2 = 't2'
34   - t3 = 't3'
35   - env.themes = [t2]
36   - env.save
37   -
38   - Theme.stubs(:system_themes).returns([Theme.new(t2), Theme.new(t3)])
39   - get :index, :profile => 'testinguser'
40   -
41   - %w[ t1 t2 ].each do |item|
42   - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set/#{item}" }
43   - end
44   -
45   - assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set/t3" }
46   - end
47   -
48   - should 'highlight current theme' do
49   - env = Environment.default
50   - t1 = 'one'
51   - t2 = 'two'
52   - env.themes = [t1, t2]
53   - env.save
54   -
55   - Theme.stubs(:system_themes).returns([Theme.new(t1), Theme.new(t2)])
56   - profile.update_theme(t1)
57   - get :index, :profile => 'testinguser'
58   -
59   - assert_tag :attributes => { :class => 'theme-opt list-opt selected' }
60   - assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set/one" }
61   - end
62   -
63   - should 'display list of my themes for edition' do
64   - Theme.create('three', :owner => profile)
65   - Theme.create('four', :owner => profile)
66   -
67   - get :index, :profile => 'testinguser'
68   -
69   - %w[ three four ].each do |item|
70   - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/edit/#{item}" }
71   - end
72   - end
73   -
74   - should 'save selection of theme' do
75   - get :set, :profile => 'testinguser', :id => 'onetheme'
76   - profile = Profile.find(@profile.id)
77   - assert_equal 'onetheme', profile.theme
78   - end
79   -
80   - should 'save selection of theme even if model is invalid' do
81   - @profile.sex = nil
82   - @profile.save!
83   - @profile.environment.custom_person_fields = { 'sex' => {'required' => 'true', 'active' => 'true'} }; @profile.environment.save!
84   -
85   - get :set, :profile => 'testinguser', :id => 'onetheme'
86   - profile = Profile.find(@profile.id)
87   - assert_equal 'onetheme', profile.theme
88   - end
89   -
90   - should 'unset selection of theme' do
91   - get :unset, :profile => 'testinguser'
92   - assert_equal nil, profile.theme
93   - end
94   -
95   - should 'display link to use the default theme' do
96   - env = Environment.default
97   - env.themes = ['new-theme']
98   - env.save
99   -
100   - Theme.stubs(:system_themes).returns([Theme.new('new-theme')])
101   -
102   - get :index, :profile => 'testinguser'
103   - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/unset" }
104   - end
105   -
106   - should 'point back to control panel' do
107   - get :index, :profile => 'testinguser'
108   - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser' }, :content => 'Back'
109   - end
110   -
111   - should 'display screen for creating new theme' do
112   - @request.expects(:xhr?).returns(true).at_least_once
113   - get :new, :profile => 'testinguser'
114   - assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/themes/new', :method => /post/i }, :descendant => { :tag => 'input', :attributes => { :type => 'text', :name => 'name' } }
115   - end
116   -
117   - should 'create a new theme' do
118   - post :new, :profile => 'testinguser', :name => 'My theme'
119   -
120   - ok('theme should be created') do
121   - profile.themes.first.id == 'my-theme'
122   - end
123   - end
124   -
125   - should 'edit a theme' do
126   - theme = Theme.create('mytheme', :owner => profile)
127   - get :edit, :profile => 'testinguser', :id => 'mytheme'
128   -
129   - assert_equal theme, assigns(:theme)
130   - end
131   -
132   - should 'list CSS files in theme' do
133   - theme = Theme.create('mytheme', :owner => profile)
134   - theme.add_css('one.css')
135   - theme.add_css('two.css')
136   -
137   - get :edit, :profile => 'testinguser', :id => 'mytheme'
138   -
139   - %w[ one.css two.css ].each do |item|
140   - assert_includes assigns(:css_files), item
141   - assert_tag :tag => 'li', :descendant => { :tag => 'a', :content => item}
142   - end
143   - end
144   -
145   - should 'display dialog for creating new CSS' do
146   - theme = Theme.create('mytheme', :owner => profile)
147   - @request.stubs(:xhr?).returns(true)
148   - get :add_css, :profile => 'testinguser', :id => 'mytheme'
149   -
150   - assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/themes/add_css/mytheme', :method => /post/i}
151   - assert_tag :tag => 'input', :attributes => { :name => 'css', :type => 'text' }
152   - assert_tag :tag => 'input', :attributes => { :type => 'submit' }
153   - end
154   -
155   - should 'be able to add new CSS to theme' do
156   - theme = Theme.create('mytheme', :owner => profile)
157   - post :add_css, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css'
158   -
159   - assert_response :redirect
160   -
161   - reloaded_theme = Theme.find('mytheme')
162   - assert_includes reloaded_theme.css_files, 'test.css'
163   - end
164   -
165   - should 'load code from a given CSS file' do
166   - theme = Theme.create('mytheme', :owner => profile); theme.update_css('test.css', '/* sample code */')
167   - get :css_editor, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css'
168   -
169   - assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/themes/update_css/mytheme' }, :descendant => { :tag => 'textarea', :content => '/* sample code */' }
170   - end
171   -
172   - should 'be able to save CSS code' do
173   - theme = Theme.create('mytheme', :owner => profile); theme.update_css('test.css', '/* sample code */')
174   - get :css_editor, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css'
175   -
176   - assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/themes/update_css/mytheme' }, :descendant => { :tag => 'input', :attributes => { :type => 'submit' } }
177   - assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/themes/update_css/mytheme' }, :descendant => { :tag => 'input', :attributes => { :type => 'hidden', :name => 'css', :value => 'test.css' } }
178   - end
179   -
180   - should 'update css code when saving' do
181   - theme = Theme.create('mytheme', :owner => profile); theme.update_css('test.css', '/* sample code */')
182   - post :update_css, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css', :csscode => 'body { background: white; }'
183   - assert_equal 'body { background: white; }', theme.read_css('test.css')
184   - end
185   -
186   - should 'list image files in theme' do
187   - theme = Theme.create('mytheme', :owner => profile)
188   - theme.add_image('one.png', 'FAKE IMAGE DATA 1')
189   - theme.add_image('two.png', 'FAKE IMAGE DATA 2')
190   -
191   - get :edit, :profile => 'testinguser', :id => 'mytheme'
192   -
193   - assert_tag :tag => 'img', :attributes => { :src => '/user_themes/mytheme/images/one.png' }
194   - assert_tag :tag => 'img', :attributes => { :src => '/user_themes/mytheme/images/two.png' }
195   - end
196   -
197   - should 'display "add image" button' do
198   - theme = Theme.create('mytheme', :owner => profile)
199   - get :edit, :profile => 'testinguser', :id => 'mytheme'
200   -
201   - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/themes/add_image/mytheme' }
202   - end
203   -
204   - should 'display the "add image" dialog' do
205   - theme = Theme.create('mytheme', :owner => profile)
206   - @request.stubs(:xhr?).returns(true)
207   -
208   - get :add_image, :profile => 'testinguser', :id => 'mytheme'
209   - assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/themes/add_image/mytheme', :method => /post/i, :enctype => 'multipart/form-data' }, :descendant => { :tag => 'input', :attributes => { :name => 'image', :type => 'file' } }
210   - end
211   -
212   - should 'be able to add new image to theme' do
213   - theme = Theme.create('mytheme', :owner => profile)
214   - @request.stubs(:xhr?).returns(false)
215   -
216   - post :add_image, :profile => 'testinguser', :id => 'mytheme', :image => fixture_file_upload('/files/rails.png', 'image/png', :binary)
217   - assert_redirected_to :action => "edit", :id => 'mytheme'
218   - assert theme.image_files.include?('rails.png')
219   - assert(system('diff', RAILS_ROOT + '/test/fixtures/files/rails.png', TMP_THEMES_DIR + '/mytheme/images/rails.png'), 'should put the correct uploaded file in the right place')
220   - end
221   -
222   - should 'link to "test theme"' do
223   - Theme.create('one', :owner => profile)
224   - Theme.create('two', :owner => profile)
225   - get :index, :profile => 'testinguser'
226   -
227   - %w[ one two ].each do |item|
228   - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/themes/start_test/' + item }
229   - end
230   - end
231   -
232   - should 'start testing theme' do
233   - theme = Theme.create('theme-under-test', :owner => profile)
234   - post :start_test, :profile => 'testinguser', :id => 'theme-under-test'
235   -
236   - assert_equal 'theme-under-test', session[:theme]
237   - assert_redirected_to :controller => 'content_viewer', :profile => 'testinguser', :action => 'view_page'
238   - end
239   -
240   - should 'stop testing theme' do
241   - theme = Theme.create('theme-under-test', :owner => profile)
242   - post :stop_test, :profile => 'testinguser', :id => 'theme-under-test'
243   -
244   - assert_nil session[:theme]
245   - assert_redirected_to :action => 'index'
246   - end
247   -
248   - should 'list templates' do
249   - all = LayoutTemplate.all
250   -
251   - LayoutTemplate.expects(:all).returns(all)
252   - get :index, :profile => 'testinguser'
253   - assert_same all, assigns(:layout_templates)
254   - end
255   -
256   - should 'display links to set template' do
257   - profile.update_attributes!(:layout_template => 'rightbar')
258   - t1 = LayoutTemplate.find('default')
259   - t2 = LayoutTemplate.find('leftbar')
260   - LayoutTemplate.expects(:all).returns([t1, t2])
261   -
262   - get :index, :profile => 'testinguser'
263   - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set_layout_template/default"}
264   - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set_layout_template/leftbar"}
265   - end
266   -
267   - should 'highlight current template' do
268   - profile.update_attributes!(:layout_template => 'default')
269   -
270   - t1 = LayoutTemplate.find('default')
271   - t2 = LayoutTemplate.find('leftbar')
272   - LayoutTemplate.expects(:all).returns([t1, t2])
273   -
274   - get :index, :profile => 'testinguser'
275   - assert_tag :attributes => { :class => 'template-opt list-opt selected' }
276   - assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set_layout_template/default"}
277   - end
278   -
279   - should 'set template' do
280   - post :set_layout_template, :profile => 'testinguser', :id => 'leftbar'
281   - profile = Profile.find(@profile.id)
282   - assert_equal 'leftbar', profile.layout_template
283   - assert_redirected_to :action => 'index'
284   - end
285   -
286   - should 'set template even if the model is invalid' do
287   - @profile.sex = nil
288   - @profile.save!
289   - @profile.environment.custom_person_fields = { 'sex' => {'required' => 'true', 'active' => 'true'} }; @profile.environment.save!
290   -
291   - post :set_layout_template, :profile => 'testinguser', :id => 'leftbar'
292   - profile = Profile.find(@profile.id)
293   - assert_equal 'leftbar', profile.layout_template
294   - assert_redirected_to :action => 'index'
295   - end
296   -
297   - should 'not display "new theme" button when user themes are disabled' do
298   - env.disable('user_themes')
299   - env.save!
300   - get :index, :profile => 'testinguser'
301   - assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/themes/new' }
302   - end
303   -
304   - should 'not display the "Select themes" section if there are no themes to choose from' do
305   - env.themes = []; env.save!
306   - Theme.stubs(:system_themes_dir).returns(TMP_THEMES_DIR) # an empty dir
307   - get :index, :profile => "testinguser"
308   - assert_no_tag :content => "Select theme"
309   - end
310   -
311   -end