diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 66ae6f9..744e798 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -5,10 +5,10 @@ class ApplicationController < ActionController::Base before_filter :detect_stuff_by_domain attr_reader :virtual_community + before_filter :load_boxes #TODO To diplay the content we need a variable called '@boxes'. #This variable is a set of boxes belongs to a owner #We have to see a better way to do that - before_filter :load_boxes def load_boxes if Profile.exists?(1) owner = Profile.find(1) @@ -17,11 +17,25 @@ class ApplicationController < ActionController::Base end before_filter :load_template + # Load the template belongs to a Profile and set it at @chosen_template variable. + # If no profile exist the @chosen_template variable is set to 'default' def load_template if Profile.exists?(1) - owner = Profile.find(1) + @owner = Profile.find(1) end - @chosen_template = owner.nil? ? "default" : owner.template + @chosen_template = @owner.nil? ? "default" : @owner.template + end + + def set_default_template + p = Profile.find(params[:object_id]) + set_template(p,params[:template_name]) + end + + private + + def set_template(object, template_name) + object.template = template_name + object.save end protected diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 348bb0a..3e2d480 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,11 +1,32 @@ # Methods added to this helper will be available to all templates in the application. module ApplicationHelper + + # Directories to be rejected of the directories list when needed. + # TODO I think the better way is create a Dir class method that returns a list of files of a given path REJECTED_DIRS = %w[ . .. .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) + 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) + end + + def change_tempate(observed_field, object) + observe_field( observed_field, + :url => {:action => 'set_default_template'}, + :with =>"'template_name=' + escape(value) + '&object_id=' + escape(#{object.id})", + :complete => "document.location.reload();" + ) + end + # This method expect an array of boxes and the content retuned of a controller action # It will generate the boxes div according the yaml definition def display_boxes(boxes, main_content = "") @@ -31,9 +52,9 @@ module ApplicationHelper #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/") + d = Dir.new("public/templates/#{template_name}/stylesheets/").to_a - REJECTED_DIRS d.map do |filename| - stylesheet_link_tag("/templates/#{template_name}/stylesheets/#{filename}") unless REJECTED_DIRS.include?(filename.gsub(/.css/,"")) + stylesheet_link_tag("/templates/#{template_name}/stylesheets/#{filename}") end end @@ -46,9 +67,9 @@ module ApplicationHelper #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/") + d = Dir.new("public/templates/#{template_name}/javascripts/").to_a - REJECTED_DIRS d.map do |filename| - javascript_include_tag("/templates/#{template_name}/javascripts/#{filename}") unless REJECTED_DIRS.include?(filename.gsub(/.js/,"")) + javascript_include_tag("/templates/#{template_name}/javascripts/#{filename}") end end @@ -74,43 +95,5 @@ module ApplicationHelper ) end - # Shows the blocks as defined in show_blocks adding the sortable and draggable elements. - # In this case the layout can be manipulated - def edit_blocks(box, main_content = "") - blocks = box.blocks_sort_by_position - content_tag(:ul, - blocks.map {|b| - content_tag(:li, b.main? ? main_content : b.to_html , :class =>"block_item_box_#{box.number}" , :id => "block_#{b.id}" ) + draggable("block_#{b.id}") - }, :id => "sort_#{box.number}" - ) + drag_drop_items(box) + sortable_block(box.number) - end - - # Allows the biven box to have sortable elements - def sortable_block(box_number) - sortable_element "sort_#{box_number}", - :url => {:action => 'sort_box', :box_number => box_number }, - :complete => visual_effect(:highlight, "sort_#{box_number}") - end - - # Allows an element item to be draggable - def draggable(item) - draggable_element(item, :ghosting=>true, :revert=>true) - end - - # Allows an draggable element change between diferrents boxes - def drag_drop_items(box) - boxes = Box.find_not_box(box.id) - - boxes.map{ |b| - drop_receiving_element("box_#{box.number}", - :accept => "block_item_box_#{b.number}", - :complete => "$('spinner').hide();", - :before => "$('spinner').show();", - :hoverclass => 'hover', - :with => "'block=' + encodeURIComponent(element.id.split('_').last())", - :url => {:action=>:change_box, :box_id => box.id}) - }.to_s - end - end diff --git a/app/helpers/edit_template_helper.rb b/app/helpers/edit_template_helper.rb new file mode 100644 index 0000000..b0cdc3c --- /dev/null +++ b/app/helpers/edit_template_helper.rb @@ -0,0 +1,45 @@ +# Methods added to this helper will be available to all templates in the application. +module EditTemplateHelper + + private + + # Shows the blocks as defined in show_blocks adding the sortable and draggable elements. + # In this case the layout can be manipulated + def edit_blocks(box, main_content = "") + blocks = box.blocks_sort_by_position + content_tag(:ul, box.name + + blocks.map {|b| + content_tag(:li, b.name, :class =>"block_item_box_#{box.number}" , :id => "block_#{b.id}" ) + draggable("block_#{b.id}") + }.to_s, :id => "sort_#{box.number}" + ) + drag_drop_items(box) + sortable_block(box.number) + end + + # Allows the biven box to have sortable elements + def sortable_block(box_number) + sortable_element "sort_#{box_number}", + :url => {:action => 'sort_box', :box_number => box_number }, + :complete => visual_effect(:highlight, "sort_#{box_number}") + end + + # Allows an element item to be draggable + def draggable(item) + draggable_element(item, :ghosting=>true, :revert=>true) + end + + # Allows an draggable element change between diferrents boxes + def drag_drop_items(box) + boxes = Box.find_not_box(box.id) + + boxes.map{ |b| + drop_receiving_element("box_#{box.number}", + :accept => "block_item_box_#{b.number}", + :complete => "$('spinner').hide();", + :before => "$('spinner').show();", + :hoverclass => 'hover', + :with => "'block=' + encodeURIComponent(element.id.split('_').last())", + :url => {:action=>:change_box, :box_id => box.id}) + }.to_s + end + + +end diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml index 0df88c2..0a331a1 100644 --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -11,8 +11,14 @@ <%= link_to _('Show Layout'), :controller => 'home' %> <%= link_to _('Edit Layout'), :controller => 'edit_template' %> + <%= select_template(@owner, @chosen_template) %> + <%= display_boxes(@boxes, yield) %> + + diff --git a/public/templates/simple/images/loading.gif b/public/templates/simple/images/loading.gif new file mode 100644 index 0000000..5bb90fd Binary files /dev/null and b/public/templates/simple/images/loading.gif differ diff --git a/public/templates/simple/images/ufba_logo.png b/public/templates/simple/images/ufba_logo.png new file mode 100644 index 0000000..80bbe65 Binary files /dev/null and b/public/templates/simple/images/ufba_logo.png differ diff --git a/public/templates/simple/simple.yml b/public/templates/simple/simple.yml new file mode 100644 index 0000000..0e29273 --- /dev/null +++ b/public/templates/simple/simple.yml @@ -0,0 +1,2 @@ +default: + number_of_boxes: 3 diff --git a/public/templates/simple/stylesheets/default.css b/public/templates/simple/stylesheets/default.css new file mode 100644 index 0000000..39d2e24 --- /dev/null +++ b/public/templates/simple/stylesheets/default.css @@ -0,0 +1,48 @@ +.edit_mode .hover { + background-color: blue; + border: 2px dotted red; +} + +.edit_mode .hover ul li { + border: 2px dotted yellow; +} + +.edit_mode #box_1 ul, .edit_mode #box_2 ul, .edit_mode #box_3 ul { + list-style: none; + cursor: -moz-grab; + margin: 10px; + padding:0px; + +} + +.edit_mode #box_1 ul li, .edit_mode #box_2 ul li, .edit_mode #box_3 ul li { + list-style: none; + cursor: -moz-grab; + border: 5px solid black; + margin: 15px; +} + +.edit_mode #box_1, .edit_mode #box_2, .edit_mode #box_3 { + border: 3px solid brown; +} + +#box_1 { + width: 200px; + float: left; +} +#box_2 { + width: 600px; + float: left; + margin: 0px 10px 0px 10px; +} +#box_3 { + width: 400px; + + clear: both; +} + +#footer{ + font-size: 30px; + background: #FFFFFF url('../images/ufba_logo.png') repeat-x; +} + -- libgit2 0.21.2