Changeset 1063

Show
Ignore:
Timestamp:
2008-06-16 12:49:04 (7 months ago)
Author:
gaspard
Message:

Fixed most ajax zafu tags ([each], [block], [add], [edit], etc) so that they work in list context.
Removed '.' in ids (not legal for id or class names). Closes #99(4).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/README

    r1061 r1063  
    9494    # make && make install 
    9595 
    96 === 3. Gems 
     96=== 3. install Gems 
    9797 
    9898# does not work with gettext > 1.90.0 
  • trunk/app/controllers/nodes_controller.rb

    r1053 r1063  
    272272    positions.each_with_index do |zip,idx| 
    273273      child = secure!(Node) { Node.find_by_zip(zip) } 
    274       child.position = idx 
     274      child.position = idx.to_f + 1.0 
    275275      allOk = child.save && allOK 
    276276    end 
  • trunk/app/helpers/application_helper.rb

    r1061 r1063  
    743743  end 
    744744   
    745   # TODO: test 
     745  # TODO: is this still used ? 
    746746  def show(obj, sym, opt={}) 
    747747    return show_title(obj, opt) if sym == :v_title 
     
    769769        lang = obj.content_lang 
    770770        lang = lang ? " lang='#{lang}'" : "" 
    771         text = "<code#{lang} class='full'>HEYHEY#{text.gsub("\n", '<br/>')}</code>" 
     771        text = "<code#{lang} class='full'>#{text}</code>" 
    772772      end 
    773773      text  = zazen(text, opt) 
  • trunk/app/views/data_entries/edit.rjs

    r1062 r1063  
    1 page.replace "#{params[:dom_id]}.#{@data_entry.zip}", :file => fullpath_from_template_url + "_form.erb" 
     1page.replace "#{params[:dom_id]}_#{@data_entry.zip}", :file => fullpath_from_template_url + "_form.erb" 
  • trunk/app/views/nodes/create.rjs

    r1062 r1063  
    88  @node = @node.parent.new_child(:class => @node.class) 
    99  page.replace "#{params[:dom_id]}_form", :file => fullpath_from_template_url + "_form.erb" 
    10   puts params[:done] 
    1110  if params[:done] 
    1211    page << params[:done] 
  • trunk/lib/parser/lib/rules/zena.rb

    r1062 r1063  
    360360    # Define a block of elements to be used by ajax calls (edit/filter) 
    361361    def r_block 
    362       @context[:dom_id]     = "#{self.dom_id}.\#{#{node_id}}" 
    363       @context[:erb_dom_id] = "#{self.dom_id}.#{erb_node_id}" 
     362      @context[:dom_id]     = "#{self.dom_id}_\#{#{node_id}}" 
     363      @context[:erb_dom_id] = "#{self.dom_id}_#{erb_node_id}" 
    364364       
    365365      if @context[:block] == self 
     
    374374        template_url = get_template_url 
    375375        form_url     = template_url + '_form' 
    376         @context[:dom_id]     = "#{self.dom_id}.\#{#{node_id}}" 
    377         @context[:erb_dom_id] = "#{self.dom_id}.#{erb_node_id}" 
     376        @context[:dom_id]     = "#{self.dom_id}_\#{#{node_id}}" 
     377        @context[:erb_dom_id] = "#{self.dom_id}_#{erb_node_id}" 
    378378       
    379379        @html_tag ||= 'div' 
     
    581581      unless @params[:empty] == 'true' 
    582582        out "<% if #{node}.kind_of?(TextDocument); l = #{node}.content_lang -%>" 
    583         out "<%= zazen(\"<code\#{l ? \" lang='\#{l}'\" : ''} class=\\'full\\'>\#{#{text}}</code>\") %></div>
     583        out "<%= zazen(\"<code\#{l ? \" lang='\#{l}'\" : ''} class=\\'full\\'>\#{#{text}}</code>\") %>
    584584        out "<% else -%>" 
    585585        out "<%= zazen(#{text}#{limit}, :node=>#{node}) %>" 
     
    865865      form << "<%= error_messages_for(#{node}) %>" 
    866866       
    867       unless descendant('cancel') || descendant('edit') || descendant('form_tag') 
    868         # add a descendant before blocks. 
    869         blocks_bak = @blocks.dup # I do not understand why we need 'dup' (but we sure do...) 
    870         @blocks = [make(:void, :method=>'void', :text=>cancel)] + blocks_bak 
     867      if !descendant('cancel') && !descendant('edit') 
     868        if !descendant('form_tag') 
     869          # add a descendant before blocks. 
     870          blocks_bak = @blocks.dup # I do not understand why we need 'dup' (but we sure do...) 
     871          @blocks = [make(:void, :method=>'void', :text=>cancel)] + blocks_bak 
     872        else 
     873          form   = cancel + form 
     874          cancel = '' 
     875          blocks_bak = @blocks 
     876        end 
    871877      else 
    872878        blocks_bak = @blocks 
    873       end 
    874        
    875       if !descendant('cancel') && !descendant('edit') 
    876         form = cancel + form 
    877879      end 
    878880       
     
    10261028      @html_tag_params ||= {} 
    10271029      dom_id = parent.method == 'each' ? @context[:erb_dom_id] : unique_name 
    1028       @html_tag_params[:id] = "#{dom_id}.#{erb_node_id}" 
     1030      @html_tag_params[:id] = "#{dom_id}_#{erb_node_id}" 
    10291031      @html_tag_params[:class] ||= 'drop' 
    10301032       
     
    10501052      @html_tag_params ||= {} 
    10511053      dom_id = unique_name 
    1052       @html_tag_params[:id] = "#{dom_id}.#{erb_node_id}" 
     1054      @html_tag_params[:id] = "#{dom_id}_#{erb_node_id}" 
    10531055      case @params[:revert] 
    10541056      when 'move' 
     
    10741076      end 
    10751077      #dom_id = "#{@context[:dom_id]}.\#{#{node_id}}" 
    1076       erb_dom_id = "#{@context[:erb_dom_id]}.#{erb_node_id}" 
     1078      erb_dom_id = "#{@context[:erb_dom_id]}_#{erb_node_id}" 
    10771079      if node_kind_of?(Node) 
    10781080        out "<% if #{node}[:link_id] -%>" 
     
    10851087        out "</a><% end -%>" 
    10861088      elsif node_kind_of?(DataEntry) 
    1087         dom_id = "#{@context[:dom_id]}.\#{#{node_id}}" 
     1089        dom_id = "#{@context[:dom_id]}_\#{#{node_id}}" 
    10881090        out "<%= link_to_remote(#{text.inspect}, {:url => \"/data_entries/\#{#{node}[:id]}?remove=#{dom_id}\", :method => :delete}, :class=>#{(@params[:class] || 'unlink').inspect}) %>" 
    10891091      end 
     
    11831185          join = @params[:join] || '' 
    11841186          join = join.gsub(/&lt;([^%])/, '<\1').gsub(/([^%])&gt;/, '\1>') 
    1185           out "<% #{list}.each_index do |#{var}_index| -%>" 
    1186           out "<%= #{var}=#{list}[#{var}_index]; #{var}_index > 0 ? #{join.inspect} : '' %>" 
     1187          out "<% #{list}.each_with_index do |#{var},#{var}_index| -%>" 
     1188          out "<%= #{var}_index > 0 ? #{join.inspect} : '' %>" 
    11871189           
    11881190          if alt_class = @params[:alt_class] 
    11891191            if html_class = @html_tag_params.delete(:class) 
    1190               html_append = " class='<%= #{var}_index % 2 != 0 ? #{alt_class.inspect} : #{html_class.inspect} %>'" 
     1192              html_append = " class='#{html_class}<%= #{var}_index % 2 != 0 ? #{(' ' + alt_class).inspect} : '' %>'" 
    11911193            else 
    11921194              html_append = "<%= #{var}_index % 2 != 0 ? ' class=#{alt_class.inspect}' : '' %>" 
     
    12061208         
    12071209        if @params[:draggable] == 'true' 
    1208           out "<% #{var}_dom_ids << \"#{dom_id}.\#{#{node_id(var)}}\" -%>" 
     1210          out "<% #{var}_dom_ids << \"#{dom_id}_\#{#{node_id(var)}}\" -%>" 
    12091211        end 
    12101212         
     
    12151217        if @context[:template_url] || @params[:draggable] == 'true' || descendant('unlink') 
    12161218          # ajax, set id, class 
    1217           id_hash = {:id=> "#{erb_dom_id}.#{erb_node_id(var)}"} 
     1219          id_hash = {:id=> "#{erb_dom_id}_#{erb_node_id(var)}"} 
    12181220          if @html_tag 
    12191221            @html_tag_params.merge!(id_hash) 
     
    12351237        erb_dom_id = "<%= params[:dom_id] %>" 
    12361238        dom_id     = "\#{params[:dom_id]}" 
    1237         id_hash = {:id=>"#{erb_dom_id}.<%= @#{base_class.to_s.underscore}.zip %>"} 
     1239        id_hash = {:id=>"#{erb_dom_id}_<%= @#{base_class.to_s.underscore}.zip %>"} 
    12381240        if @html_tag 
    12391241          @html_tag_params.merge!(id_hash) 
     
    12431245        end 
    12441246        if @params[:draggable] == 'true' 
    1245           out "<script type='text/javascript'>\n//<![CDATA[\nZena.draggable('#{@context[:erb_dom_id]}.<%= @#{base_class.to_s.underscore}.zip %>')\n//]]>\n</script>" 
     1247          out "<script type='text/javascript'>\n//<![CDATA[\nZena.draggable('#{@context[:erb_dom_id]}_<%= @#{base_class.to_s.underscore}.zip %>')\n//]]>\n</script>" 
    12461248        end 
    12471249      else 
     
    19371939       
    19381940      @context.merge!(opts)          # pass options from 'zafu_known_contexts' to @context 
    1939       @context[:dom_id]     = "#{self.dom_id}.\#{#{node_id}}" 
    1940       @context[:erb_dom_id] = "#{self.dom_id}.#{erb_node_id}" 
     1941      @context[:dom_id]     = "#{self.dom_id}_\#{#{node_id}}" 
     1942      @context[:erb_dom_id] = "#{self.dom_id}_#{erb_node_id}" 
    19411943      if (each_block = descendant('each')) && (descendant('edit') || descendant('add') || descendant('add_document') || (descendant('swap') && descendant('swap').parent.method != 'block')) 
    19421944        # ajax, build template. We could merge the following code with 'r_block'. 
     
    19471949        end 
    19481950         
    1949         template_url = each_block.get_template_url(@context) 
     1951        template_url = get_template_url(@context) # each_block.get_template_url(@context) 
    19501952         
    19511953        # should we publish ? 
  • trunk/lib/parser/test/parser/zafu.yml

    r1055 r1063  
    242242  res: "[test][hello/]<!-- this is nothing > <r:hello/>  -->[/test]" 
    243243 
     244html_comments_not_greedy: 
     245  src: "<r:test><!-- first --><r:hello/><!-- this is nothing > <r:hello/>  --></r:test>" 
     246  res: "[test]<!-- first -->[hello/]<!-- this is nothing > <r:hello/>  -->[/test]" 
     247 
    244248html_do_comment: 
    245249  src: "<r:test><r:hello/><!--|this is not a comment <r:hello/>  --></r:test>" 
  • trunk/test/helpers/zena_parser/ajax.yml

    r1061 r1063  
    2121add_each_no_form: 
    2222  src: "<ul do='children' id='things'><li do='each'>I <p do='[name]'>blah</p></li><li do='add'/></ul>" 
    23   res: "/<ul><li.*id='things_add'.*li id='things_form'.*form.*hidden.*I <p><input type='text' id='things_name' name='node\[name\]' value=''\/><\/p><\/form><\/li>/" 
     23  res: "/<ul><li.*id='things_22_add'.*li id='things_22_form'.*form.*hidden.*I <p><input type='text' id='things_22_name' name='node\[name\]' value=''\/><\/p><\/form><\/li>/" 
    2424 
    2525add_each_no_form_date: 
    2626  src: "<ul do='children' id='things'><li do='each'>I <p do='show' date='event_at' tformat='short_date'>blah</p></li><li do='add'/></ul>" 
    27   res: "/<ul><li.*id='things_add'.*li id='things_form'.*form.*hidden.*I <p>.*date_box.*<input id='things_event_at' name='node\[event_at\]' type='text' value.*/m" 
     27  res: "/<ul><li.*id='things_22_add'.*li id='things_22_form'.*form.*hidden.*I <p>.*date_box.*<input id='things_22_event_at' name='node\[event_at\]' type='text' value.*/m" 
    2828 
    2929add_each_no_form_focus: 
    3030  src: "<ul do='children' id='test'><li do='each'>I <p do='[v_title]'>blah</p></li><li do='add' focus='v_title'/></ul>" 
    31   res: "/<ul><li.*id=.*_add.*onclick.*toggle.*test_v_title.*focus.*li id=.*_form.*form.*hidden.*I <p><input type='text' id='test_v_title' name='node\[v_title\]' value=''\/><\/p><\/form><\/li>/" 
     31  res: "/<ul><li.*id=.*_add.*onclick.*toggle.*test_22_v_title.*focus.*li id=.*_form.*form.*hidden.*I <p><input type='text' id='test_22_v_title' name='node\[v_title\]' value=''\/><\/p><\/form><\/li>/" 
    3232 
    3333each_add_with_form: 
     
    4040      <li do='form'><input name='v_title'/> this is the form</li> 
    4141    </r:children> 
    42   res: "/<li.*list.29.30.*>bird.*<li.*list.29.31.*>flower.*<li.*list_add.*list_form.*toggle.*<li .*list_form.*style.*none.*Ajax.Request.*input type='hidden' name='template_url' value=\"/each/add/with/form/list\".*input type='hidden' name='node\[parent_id\]' value=\"29\"/" 
     42  res: "/<li.*list_29_30.*>bird.*<li.*list_29_31.*>flower.*<li.*list_29_add.*list_29_form.*toggle.*<li .*list_29_form.*style.*none.*Ajax.Request.*input type='hidden' name='template_url' value=\"/each/add/with/form/list\".*input type='hidden' name='node\[parent_id\]' value=\"29\"/" 
    4343 
    4444each_add_with_form_klass_set: 
     
    6666make_form: 
    6767  src: "<ul do='children'><li do='each' do='[name]'/><li do='add'/></ul>" 
    68   tem: "/<li id='list_form' style='display:none;'><%= form_remote_tag\(:url => nodes_path\) %>/" 
    69   'make/form/en/list.erb': "<li id='list.<%= @node.zip %>'><%= @node.name %></li>" 
    70   'make/form/en/list_form.erb': "/<li id='list<%= @node.new_record\? \? '_form' : \".#\{@node.zip\}\" %>'>/" 
     68  tem: "/<li id='list_<%= @node.zip %>_form' style='display:none;'><%= form_remote_tag\(:url => nodes_path\) %>/" 
     69  'make/form/en/list.erb': "<li id='<%= params[:dom_id] %>_<%= @node.zip %>'><%= @node.name %></li>" 
     70  'make/form/en/list_form.erb': "/<li id='<%= params\[:dom_id\] %><%= @node.new_record\? \? '_form' : '' %>'>/" 
    7171 
    7272each_edit_cannot_write: 
     
    7979add_each_publish: 
    8080  src: "<ul do='children' id='things'><li do='each'>I <p do='[name]'>blah</p></li><li do='add' publish='true'/></ul>" 
    81   res: "/<ul><li.*id='things_add'.*li id='things_form'.*form.*hidden.*name='node\[v_status\]' value=\"50\"/" 
     81  res: "/<ul><li.*id='things_22_add'.*li id='things_22_form'.*form.*hidden.*name='node\[v_status\]' value=\"50\"/" 
    8282 
    8383block_edit_form: 
  • trunk/test/helpers/zena_parser/basic.yml

    r1061 r1063  
    398398  context: 
    399399    node: 'collections' 
    400   src: "<ol do='pages'><li class='one' alt_class='two' do='each' do='[name]'/></ol>" 
    401   res: "<ol><li class='one'>art</li><li class='two'>menu</li><li class='one'>news</li><li class='two'>wiki_skin</li></ol>" 
     400  src: "<ol do='pages'><li class='post' alt_class='stripe' do='each' do='[name]'/></ol>" 
     401  res: "<ol><li class='post'>art</li><li class='post stripe'>menu</li><li class='post'>news</li><li class='post stripe'>wiki_skin</li></ol>" 
    402402 
    403403each_alternate_class_ajax: 
     
    730730  res: "<div id='v_summary11' class='zazen'><p>This is the root of your peaceful tests.</p></div>" 
    731731 
     732text: 
     733  src: "<r:text/>" 
     734  res: "<div id='v_text22' class='zazen'><p>status text</p></div>" 
     735   
     736text_code: 
     737  context: 
     738    node: 'Project_zafu' 
     739  src: "<r:text/>" 
     740  res: "/\\A<div id='v_text60' class='zazen'><pre class='full'><code class='zafu'>.*</code></pre></div>\\Z/" 
     741 
    732742ztag_in_do: 
    733743  src: "<ol do='parent'><r:children>no error</r:children></ol>" 
     
    790800input_set_value: 
    791801  src: "<r:input type='hidden' name='icon_id' set_value='[main.id]'/>" 
    792   tem: "<input name='node[icon_id]' type='hidden' value='<%= @node.zip %>'/>" 
    793   res: "<input name='node[icon_id]' type='hidden' value='22'/>" 
     802  tem: "<input id='node_icon_id' name='node[icon_id]' type='hidden' value='<%= @node.zip %>'/>" 
     803  res: "<input id='node_icon_id' name='node[icon_id]' type='hidden' value='22'/>" 
    794804 
    795805input: 
     
    797807    node: 'ant' 
    798808  src: "<r:input name='c_first_name'/>" 
    799   tem: "<input name='node[c_first_name]' type='text' value='<%= @node.c_zafu_read(\"first_name\") %>'/>" 
    800   res: "<input name='node[c_first_name]' type='text' value='Solenopsis'/>" 
     809  tem: "<input id='node_c_first_name' name='node[c_first_name]' type='text' value='<%= @node.c_zafu_read(\"first_name\") %>'/>" 
     810  res: "<input id='node_c_first_name' name='node[c_first_name]' type='text' value='Solenopsis'/>" 
    801811 
    802812input_new: 
     
    811821  <tr do='add'><td><b><r:add_btn/></b></td></tr> 
    812822  </table>" 
    813   res: "/<tr class='btn_add' id='list_add'><td><b><a href='#' onclick/" 
     823  res: "/<tr class='btn_add' id='list_22_add'><td><b><a href='#' onclick/" 
    814824 
    815825read_no_content: 
     
    903913    lang: 'fr' 
    904914  src: "<r:captcha theme='clean'/>" 
    905   res: "/RecaptchaOptions = . lang : .fr., theme : .clean., tabindex : 0/" 
     915  res: "/RecaptchaOptions .* theme : .clean./" 
  • trunk/test/helpers/zena_parser/relations.yml

    r1059 r1063  
    9696store_in_block: 
    9797  src: "<r:block><r:node select='18' store='found' do='pages'><r:show attr='name'/>: <r:node select='found' do='[name]'/></r:node></r:block>" 
    98   res: "<div id='list.22'>projects: status</div>" 
     98  res: "<div id='list_22'>projects: status</div>" 
    9999 
    100100store_outside_block: 
    101101  src: "<r:node select='18' store='found' do='pages'><r:block><r:show attr='name'/>: <r:node select='found' do='[name]'/></r:block></r:node>" 
    102   res: "<div id='list.18'>projects: status</div>" 
    103   'store/outside/en/block/list.erb': "/unknown relation 'found'/" 
     102  res: "<div id='list1_18'>projects: status</div>" 
     103  'store/outside/en/block/list1.erb': "/unknown relation 'found'/" 
    104104 
    105105store_node_as_relation: 
  • trunk/test/unit/site_test.rb

    r1061 r1063  
    228228   
    229229  def test_attributes_for_form 
    230     puts Site.attributes_for_form.inspect 
     230    assert Site.attributes_for_form[:bool].include?(:authentication) 
     231    assert Site.attributes_for_form[:text].include?(:default_lang) 
    231232  end 
    232233end