Commit 25f9eb43aa7f212d337a9c9ce06e6bd7c6afc896

Authored by Victor Costa
1 parent a9ffbc6e

Fix and refactor link list block edition

app/views/box_organizer/_link_list_block.html.erb
@@ -10,40 +10,15 @@ @@ -10,40 +10,15 @@
10 </ul> 10 </ul>
11 <ul id="dropable-link-list"> 11 <ul id="dropable-link-list">
12 <% for link in @block.links do %> 12 <% for link in @block.links do %>
13 - <li>  
14 - <ul class="link-list-row">  
15 - <li>  
16 - <%= icon_selector(link['icon']) %>  
17 - </li>  
18 - <li>  
19 - <%= text_field_tag 'block[links][][name]', link[:name], :class => 'link-name', :maxlength => 20 %>  
20 - </li>  
21 - <li>  
22 - <%= text_field_tag 'block[links][][address]', link[:address], :class => 'link-address' %>  
23 - </li>  
24 - <li>  
25 - <%= select_tag('block[links][][target]', options_for_select(LinkListBlock::TARGET_OPTIONS, link[:target])) %>  
26 - </li>  
27 - <li>  
28 - <%= button_without_text(:delete, _('Delete'), "#" , :class=>"delete-link-list-row") %>  
29 - </li>  
30 - </ul>  
31 - </li> 13 + <%= render :partial => 'link_list_item', :locals => {:link => link} %>
32 <% end %> 14 <% end %>
33 </ul> 15 </ul>
34 <input type="hidden" id="page_url" value="<%=url_for(:action=>'search_autocomplete')%>" /> 16 <input type="hidden" id="page_url" value="<%=url_for(:action=>'search_autocomplete')%>" />
  17 +
  18 + <div id="new-template">
  19 + <% template_link = {'icon' => 'ok'} %>
  20 + <%= render :partial => 'link_list_item', :locals => {:link => template_link} %>
  21 + </div>
35 </div> 22 </div>
36 23
37 -<%= link_to_function(_('New link'), nil, :class => 'button icon-add with-text') do |page|  
38 - page.insert_html :bottom, 'dropable-link-list', content_tag('li',  
39 - content_tag('ul',  
40 - content_tag('li', icon_selector('ok')) +  
41 - content_tag('li', text_field_tag('block[links][][name]', '', :maxlength => 20)) +  
42 - content_tag('li', text_field_tag('block[links][][address]', nil, :class => 'link-address')) +  
43 - content_tag('li', select_tag('block[links][][target]',  
44 - options_for_select(LinkListBlock::TARGET_OPTIONS, '_self'))) +  
45 - content_tag('li', button_without_text(:delete, _('Delete'), "#" , :class=>"delete-link-list-row")),  
46 - :class=>"link-list-row new_link_row")  
47 - ) +  
48 - javascript_tag("new_link_action()")  
49 -end %> 24 +<%= link_to_function(_('New link'), 'add_new_link();', :class => 'button icon-add with-text') %>
app/views/box_organizer/_link_list_item.html.erb 0 → 100644
@@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
  1 +<li>
  2 + <ul class="link-list-row">
  3 + <li>
  4 + <%= icon_selector(link['icon']) %>
  5 + </li>
  6 + <li>
  7 + <%= text_field_tag 'block[links][][name]', link[:name], :class => 'link-name', :maxlength => 20 %>
  8 + </li>
  9 + <li>
  10 + <%= text_field_tag 'block[links][][address]', link[:address], :class => 'link-address' %>
  11 + </li>
  12 + <li>
  13 + <%= select_tag('block[links][][target]', options_for_select(LinkListBlock::TARGET_OPTIONS, link[:target])) %>
  14 + </li>
  15 + <li>
  16 + <%= button_without_text(:delete, _('Delete'), "#" , :class=>"delete-link-list-row") %>
  17 + </li>
  18 + </ul>
  19 +</li>
public/javascripts/edit-link-list.js
@@ -29,6 +29,13 @@ function new_link_action(){ @@ -29,6 +29,13 @@ function new_link_action(){
29 jQuery(document).scrollTop(jQuery('#dropable-link-list').scrollTop()); 29 jQuery(document).scrollTop(jQuery('#dropable-link-list').scrollTop());
30 } 30 }
31 31
  32 +function add_new_link() {
  33 + var new_link = jQuery('#edit-link-list-block #new-template>li').clone();
  34 + new_link.show();
  35 + jQuery('#dropable-link-list').append(new_link);
  36 + new_link_action();
  37 +}
  38 +
32 jQuery(document).ready(function(){ 39 jQuery(document).ready(function(){
33 new_link_action(); 40 new_link_action();
34 41
@@ -36,4 +43,4 @@ jQuery(document).ready(function(){ @@ -36,4 +43,4 @@ jQuery(document).ready(function(){
36 revert: true, 43 revert: true,
37 axis: "y" 44 axis: "y"
38 }); 45 });
39 -});  
40 \ No newline at end of file 46 \ No newline at end of file
  47 +});
public/stylesheets/application.css
@@ -1864,6 +1864,9 @@ a.button.disabled, input.disabled { @@ -1864,6 +1864,9 @@ a.button.disabled, input.disabled {
1864 position: relative; 1864 position: relative;
1865 left: -24px; 1865 left: -24px;
1866 } 1866 }
  1867 +#edit-link-list-block #new-template {
  1868 + display: none;
  1869 +}
1867 .link-list-header { 1870 .link-list-header {
1868 width: 98%; 1871 width: 98%;
1869 height: 25px; 1872 height: 25px;