Commit 987349f83a14d68037f1b88f4e51a3d17f40989e

Authored by AntonioTerceiro
1 parent cdb071c4

r275@sede: terceiro | 2007-07-30 00:06:53 -0300

ActionItem0: trying to fix design editor
 


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@279 3f533792-8f58-4932-b0fe-aaf55b0a4547
vendor/plugins/design/lib/design/editor.rb
... ... @@ -28,40 +28,17 @@ module Design
28 28 end
29 29 end
30 30  
31   - private
32   -
33   - # Set to the owner the template choosed
34   - def design_editor_set_template
35   - if exists_template?(params[:template])
36   - design.template = params[:template]
37   - end
38   - end
39   -
40   - # Set to the owner the theme choosed
41   - def design_editor_set_theme
42   - if exists_theme?(params[:theme])
43   - design.theme = params[:theme]
44   - end
45   - end
46   -
47   - # Set to the owner the icon_theme choosed
48   - def design_editor_set_icon_theme
49   - if request.post? && exists_icon_theme?(params[:icon_theme])
50   - design.icon_theme = params[:icon_theme]
51   - end
52   - end
53   -
54 31 # TODO: see below here
55 32  
56   - def flexible_template_set_sort_mode
  33 + def design_editor_set_sort_mode
57 34 box = design.boxes.find(params[:box_id])
58 35 render :update do |page|
59 36 page.replace_html "box_#{box.number}", edit_blocks(box)
60   - page.sortable "sort_#{box.number}", :url => {:action => 'flexible_template_sort_box', :box_number => box.number}
  37 + page.sortable "sort_#{box.number}", :url => {:action => 'design_editor_sort_box', :box_number => box.number}
61 38 end
62 39 end
63 40  
64   - def flexible_template_sort_box
  41 + def design_editor_sort_box
65 42 box_number = params[:box_number]
66 43 pos = 0
67 44 params["sort_#{box_number}"].each do |block_id|
... ... @@ -75,7 +52,7 @@ module Design
75 52  
76 53 # This method changes a block content to a different box place and
77 54 # updates all boxes at the ends
78   - def flexible_template_change_box
  55 + def design_editor_change_box
79 56 #TODO fix it i tried the source code comment but i have no success
80 57 #b = design.blocks.detect{|b| b.id.to_s == params[:block].to_s }
81 58 b = Block.find(params[:block])
... ... @@ -88,14 +65,14 @@ module Design
88 65 end
89 66 end
90 67  
91   - def flexible_template_new_block
  68 + def design_editor_new_block
92 69 box = design.boxes.find(params[:box_id])
93 70 render :update do |page|
94   - page.replace_html "box_#{box.number}", new_block_form(box)
  71 + page.replace_html "box_#{box.number}", design_editor_new_block_form(box)
95 72 end
96 73 end
97 74  
98   - def flexible_template_create_block
  75 + def design_editor_create_block
99 76 block = Block.new(params[:block])
100 77 block.box = nil if !@ft_config[:boxes].include? block.box
101 78 block.position = block.box.blocks.count + 1 if !block.box.nil?
... ... @@ -105,12 +82,12 @@ module Design
105 82 end
106 83 else
107 84 render :update do |page|
108   - page.replace_html "flexible_template_edit_mode", _('Block cannot be saved')
  85 + page.replace_html "design_editor_edit_mode", _('Block cannot be saved')
109 86 end
110 87 end
111 88 end
112 89  
113   - def flexible_template_destroy_block
  90 + def design_editor_destroy_block
114 91 block = Block.find(params[:block_id])
115 92 box = block.box
116 93 #TO check if the block is of the owner
... ... @@ -161,7 +138,9 @@ module Design
161 138 flash[:notice] = _("The file #{@ft_config[:template]}.yml it's not a valid template filename") if number_of_boxes.nil?
162 139 number_of_boxes
163 140 end
164   -
  141 +
  142 + private
  143 +
165 144 def exists_template?(template)
166 145 Design.available_templates.include?(template)
167 146 end
... ... @@ -173,12 +152,29 @@ module Design
173 152 def exists_icon_theme?(icon_theme)
174 153 Design.available_icon_themes.include?(icon_theme)
175 154 end
176   -
177   - def parse_path(files_path = [], remove_until = 'public')
178   - remove_until = remove_until.gsub(/\//, '\/')
179   - files_path.map{|f| f.gsub(/.*#{remove_until}/, '')}
  155 +
  156 + # Set to the owner the template choosed
  157 + def design_editor_set_template
  158 + if exists_template?(params[:template])
  159 + design.template = params[:template]
  160 + end
  161 + end
  162 +
  163 + # Set to the owner the theme choosed
  164 + def design_editor_set_theme
  165 + if exists_theme?(params[:theme])
  166 + design.theme = params[:theme]
  167 + end
  168 + end
  169 +
  170 + # Set to the owner the icon_theme choosed
  171 + def design_editor_set_icon_theme
  172 + if request.post? && exists_icon_theme?(params[:icon_theme])
  173 + design.icon_theme = params[:icon_theme]
  174 + end
180 175 end
181 176  
  177 +
182 178 end
183 179  
184 180 end
... ...
vendor/plugins/design/lib/design/editor/helper.rb
... ... @@ -35,19 +35,19 @@ module Design
35 35 content_tag(:div, edit_blocks(box, content) , :id=>"box_#{box.number}")
36 36 }].join("\n")
37 37  
38   - content = content_tag(:div, content, :id => 'flexible_template_edit_mode')
  38 + content = content_tag(:div, content, :id => 'design_editor_edit_mode')
39 39 end
40 40  
41 41 # Symbol dictionary used on select when we add or edit a block. This
42 42 # method has the responsability of translate a Block class in a humam
43 43 # name By default the class "MainBlock" has the human name "Main Block".
44 44 # Other classes defined by user are not going to display in a human name
45   - # format until de method flexible_template_block_dict be redefined in a
  45 + # format until de method design_editor_block_dict be redefined in a
46 46 # controller by user
47 47 # #TODO define the method
48   - # flexible_template_block_dict if not defined by helper
49   - # if !self.public_instance_methods.include? "flexible_template_block_dict"
50   - # define_method('flexible_template_block_dict') do |str|
  48 + # design_editor_block_dict if not defined by helper
  49 + # if !self.public_instance_methods.include? "design_editor_block_dict"
  50 + # define_method('design_editor_block_dict') do |str|
51 51 # {
52 52 # 'MainBlock' => _("Main Block")
53 53 # }[str] || str
... ... @@ -56,7 +56,7 @@ module Design
56 56  
57 57  
58 58 # FIXME: WTF?
59   - def flexible_template_block_helper_dict(str)
  59 + def design_editor_block_helper_dict(str)
60 60 {
61 61 'plain_content' => _('Plain Content') ,
62 62 'list_content' => _('List Content')
... ... @@ -158,19 +158,19 @@ module Design
158 158  
159 159 def link_to_active_sort(box)
160 160 link_to_remote(_('Sort'),
161   - {:update => "sort_#{box.number}", :url => {:action => 'flexible_template_set_sort_mode', :box_id => box.id }},
  161 + {:update => "sort_#{box.number}", :url => {:action => 'design_editor_set_sort_mode', :box_id => box.id }},
162 162 :class => 'sort_button')
163 163 end
164 164  
165 165 def link_to_add_block(box)
166 166 link_to_remote(_('Add Block'),
167   - {:update => "sort_#{box.number}", :url => {:action => 'flexible_template_new_block', :box_id => box.id }},
  167 + {:update => "sort_#{box.number}", :url => {:action => 'design_editor_new_block', :box_id => box.id }},
168 168 :class => 'add_block_button')
169 169 end
170 170  
171 171 def link_to_destroy_block(block)
172 172 link_to_remote(_('Remove'),
173   - {:update => "sort_#{block.box.number}", :url => {:action => 'flexible_template_destroy_block', :block_id => block.id }},
  173 + {:update => "sort_#{block.box.number}", :url => {:action => 'design_editor_destroy_block', :block_id => block.id }},
174 174 :class => 'destroy_block_button')
175 175 end
176 176  
... ... @@ -178,7 +178,7 @@ module Design
178 178 # Allows the biven box to have sortable elements
179 179 def sortable_block(box_number)
180 180 sortable_element "sort_#{box_number}",
181   - :url => {:action => 'flexible_template_sort_box', :box_number => box_number },
  181 + :url => {:action => 'design_editor_sort_box', :box_number => box_number },
182 182 :complete => visual_effect(:highlight, "sort_#{box_number}")
183 183 end
184 184  
... ... @@ -198,7 +198,7 @@ module Design
198 198 :before => "$('spinner').show();",
199 199 :hoverclass => 'hover',
200 200 :with => "'block=' + encodeURIComponent(element.id.split('_').last())",
201   - :url => {:action=>:flexible_template_change_box, :box_id => box.id})
  201 + :url => {:action=>:design_editor_change_box, :box_id => box.id})
202 202 }.to_s
203 203 end
204 204  
... ... @@ -223,7 +223,7 @@ module Design
223 223 h
224 224 end
225 225  
226   - def new_block_form(box)
  226 + def design_editor_new_block_form(box)
227 227 type_block_options = options_for_select(available_blocks.collect{|k,v| [v,k] })
228 228 type_block_helper_options = options_for_select(block_helpers.collect{|k,v| [v,k] })
229 229 @block = Block.new
... ... @@ -231,7 +231,7 @@ module Design
231 231  
232 232 _("Adding block on %s") % box.name +
233 233 [
234   - form_remote_tag(:url => {:action => 'flexible_template_create_block'}, :update => "sort_#{box.number}"),
  234 + form_remote_tag(:url => {:action => 'design_editor_create_block'}, :update => "sort_#{box.number}"),
235 235 hidden_field('block', 'box_id'),
236 236 content_tag(
237 237 :p,
... ...