From 9526f3aa5d61aeb3ab5d95e3b5872c5429cf93a2 Mon Sep 17 00:00:00 2001 From: LeandroNunes Date: Sun, 22 Jul 2007 19:09:24 +0000 Subject: [PATCH] ActionItem0: putting selection of themes and icons on system --- app/controllers/application.rb | 71 +++++++++++++++++++++++++++++++++++++++++++---------------------------- app/controllers/edit_template_controller.rb | 5 ----- app/helpers/application_helper.rb | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------ app/views/edit_template/index.rhtml | 1 - app/views/home/index.rhtml | 1 + app/views/layouts/application.rhtml | 8 ++++++++ 6 files changed, 103 insertions(+), 64 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 555086d..757fe8b 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -2,8 +2,9 @@ # available in all controllers. class ApplicationController < ActionController::Base - TEMPLATE_DIR_PATH = 'public/templates' - ICON_DIR_PATH = 'public/icons' + ICONS_DIR_PATH = "#{RAILS_ROOT}/public/icons" + THEME_DIR_PATH = "#{RAILS_ROOT}/public/themes" + before_filter :detect_stuff_by_domain attr_reader :virtual_community @@ -17,49 +18,63 @@ class ApplicationController < ActionController::Base if Profile.exists?(1) @owner = Profile.find(1) end - @chosen_template = @owner.nil? ? "default" : @owner.template + @chosen_template = @owner.template.nil? ? "default" : @owner.template + self.chosen_template = @chosen_template end before_filter :load_boxes - #Load a set of boxes belongs to a owner. We have to situations. - # 1 - The owner has equal or more boxes that boxes defined in template. - # The system limit the max number of boxes to the number permited in template - # 2 - The owner there isn't enough box that defined in template - # The system create the boxes needed to use the current template - def load_boxes - raise _('Template not found') if @chosen_template.nil? - n = boxes_by_template(@chosen_template) - @boxes = Array.new - if Profile.exists?(1) - owner = Profile.find(1) - @boxes = owner.boxes - end - if @boxes.length >= n - @boxes = @boxes.first(n) - else - @boxes = @boxes + before_filter :load_theme + # Load the theme belongs to a Profile and set it at @chosen_theme variable. + # If no profile exist the @chosen_theme variable is set to 'default' + def load_theme + if Profile.exists?(1) + @owner = Profile.find(1) end - + @chosen_theme = @owner.theme.nil? ? "default" : @owner.theme end - def boxes_by_template(template) - f = YAML.load_file("#{RAILS_ROOT}/public/templates/default/default.yml") - number_of_boxes = f[template.to_s]["number_of_boxes"] - raise _("The file #{template}.yml it's not a valid template filename") if number_of_boxes.nil? - number_of_boxes + before_filter :load_icons_theme + # Load the icons belongs to a Profile and set it at @chosen_icons_theme variable. + # If no profile exist the @chosen_icons_theme variable is set to 'default' + def load_icons_theme + if Profile.exists?(1) + @owner = Profile.find(1) + end + @chosen_icons_theme = @owner.icons_theme.nil? ? "default" : @owner.icons_theme end + # Set the default template to the profile def set_default_template p = Profile.find(params[:object_id]) set_template(p,params[:template_name]) end + # Set the default theme to the profile + def set_default_theme + p = Profile.find(params[:object_id]) + set_theme(p,params[:theme_name]) + end + + # Set the default icons theme to the profile + def set_default_icons_theme + p = Profile.find(params[:object_id]) + set_icons_theme(p,params[:icons_theme_name]) + end + + private - def set_template(object, template_name) - object.template = template_name + # Set to the owner the theme choosed + def set_theme(object, theme_name) + object.theme = theme_name + object.save + end + + # Set to the owner the icons theme choosed + def set_icons_theme(object,icons_theme_name) + object.icons_theme = icons_theme_name object.save end diff --git a/app/controllers/edit_template_controller.rb b/app/controllers/edit_template_controller.rb index 5970592..e6381a7 100644 --- a/app/controllers/edit_template_controller.rb +++ b/app/controllers/edit_template_controller.rb @@ -2,9 +2,4 @@ class EditTemplateController < ApplicationController uses_manage_template :edit => true - def test - @bli = true - render :action => 'index' - end - end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1d643ae..cb77098 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -9,51 +9,72 @@ module ApplicationHelper .svn ] - # Generate a select option to choose one of the available templates. - # The available templates are those in 'public/templates' - def select_template(object, chosen_template = nil) + ICONS_DIR_PATH = "#{RAILS_ROOT}/public/icons" + THEME_DIR_PATH = "#{RAILS_ROOT}/public/themes" + + + # Generate a select option to choose one of the available themes. + # The available themes are those in 'public/themes' + def select_theme(object, chosen_theme = nil) return '' if object.nil? - available_templates = Dir.new('public/templates').to_a - REJECTED_DIRS - template_options = options_for_select(available_templates.map{|template| [template, template] }, chosen_template) - select_tag('template_name', template_options ) + - change_tempate('template_name', object) + available_themes = Dir.new("#{THEME_DIR_PATH}").to_a - REJECTED_DIRS + theme_options = options_for_select(available_themes.map{|theme| [theme, theme] }, chosen_theme) + select_tag('theme_name', theme_options ) + + change_theme('theme_name', object) end - def change_tempate(observed_field, object) + # Generate a observer to reload a page when a theme is selected + def change_theme(observed_field, object) observe_field( observed_field, - :url => {:action => 'set_default_template'}, - :with =>"'template_name=' + escape(value) + '&object_id=' + escape(#{object.id})", + :url => {:action => 'set_default_theme'}, + :with =>"'theme_name=' + escape(value) + '&object_id=' + escape(#{object.id})", :complete => "document.location.reload();" ) end - # Load all the css files of a existing template with the template_name passed as argument. - # - # The files loaded are in the path: - # - # 'public/templates/#{template_name}/stylesheets/*' - #TODO I think that implements this idea describe above it's good. Let's discuss about it. - # OBS: If no files are found in path the default template is used - def stylesheet_link_tag_template(template_name) - d = Dir.new("public/templates/#{template_name}/stylesheets/").to_a - REJECTED_DIRS - d.map do |filename| - stylesheet_link_tag("/templates/#{template_name}/stylesheets/#{filename}") - end + + # Generate a select option to choose one of the available icons themes. + # The available icons themes are those in 'public/icons' + def select_icons_theme(object, chosen_icons_theme = nil) + return '' if object.nil? + available_icons_themes = Dir.new("#{ICONS_DIR_PATH}").to_a - REJECTED_DIRS + icons_theme_options = options_for_select(available_icons_themes.map{|icons_theme| [icons_theme, icons_theme] }, chosen_icons_theme) + select_tag('icons_theme_name', icons_theme_options ) + + change_icons_theme('icons_theme_name', object) end - # Load all the javascript files of a existing template with the template_name passed as argument. + # Generate a observer to reload a page when a icons theme is selected + def change_icons_theme(observed_field, object) + observe_field( observed_field, + :url => {:action => 'set_default_icons_theme'}, + :with =>"'icons_theme_name=' + escape(value) + '&object_id=' + escape(#{object.id})", + :complete => "document.location.reload();" + ) + end + + #Display a given icon passed as argument + #The icon path should be '/icons/{icons_theme}/{icon_image}' + def display_icon(icon , icons_theme = "default", options = {}) + image_tag("/icons/#{icons_theme}/#{icon}", options) + end + + # Load all the css files of a existing theme with the theme_name passed as argument. # # The files loaded are in the path: # - # 'public/templates/#{template_name}/javascripts/*' - # - #TODO I think that implements this idea describe above it's good. Let's discuss about it. - # OBS: If no files are found in path the default template is used - def javascript_include_tag_template(template_name) - d = Dir.new("public/templates/#{template_name}/javascripts/").to_a - REJECTED_DIRS + # 'public/themes/#{theme_name}/*' + # If a invalid theme it's passed the 'default' theme is applied + def stylesheet_link_tag_theme(theme_name) + if !File.exists? "#{THEME_DIR_PATH}/#{theme_name}" + flash[:notice] = _("The theme %s it's not a valid theme") % theme_name + theme_name = 'default' + end + + d = Dir.new("#{THEME_DIR_PATH}/#{theme_name}/").to_a - REJECTED_DIRS d.map do |filename| - javascript_include_tag("/templates/#{template_name}/javascripts/#{filename}") + stylesheet_link_tag("/themes/#{theme_name}/#{filename}") end end + end diff --git a/app/views/edit_template/index.rhtml b/app/views/edit_template/index.rhtml index 70a9e73..e69de29 100644 --- a/app/views/edit_template/index.rhtml +++ b/app/views/edit_template/index.rhtml @@ -1 +0,0 @@ -

something

diff --git a/app/views/home/index.rhtml b/app/views/home/index.rhtml index 5a97437..8cdb490 100644 --- a/app/views/home/index.rhtml +++ b/app/views/home/index.rhtml @@ -1 +1,2 @@ +<%= flash[:notice] %> Start page of Virtual Community <%= @virtual_community.name %> diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml index 88962ad..3d95ace 100644 --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -3,15 +3,23 @@ <%= javascript_include_tag :defaults %> <%= javascript_include_tag_template @chosen_template %> <%= stylesheet_link_tag_template @chosen_template %> + <%= stylesheet_link_tag_theme @chosen_theme %> + <%= image_tag 'loading.gif', :id => 'spinner', :style => "display:none; float:right;" %> <%= link_to _('Show Layout'), :controller => 'home' %> <%= link_to _('Edit Layout'), :controller => 'edit_template' %> <%= select_template(@owner, @chosen_template) %> + <%= select_theme(@owner, @chosen_theme) %> + <%= select_icons_theme(@owner, @chosen_icons_theme) %> + + <%= display_icon('back', @chosen_icons_theme )%> + + <%= flash[:notice] %> <%= display_boxes(@boxes, yield) %> -- libgit2 0.21.2