Changeset 1154

Show
Ignore:
Timestamp:
2008-09-15 20:20:44 (4 months ago)
Author:
gaspard
Message:

Added new 't_id' parameter for [form]. This (global) parameter is used with ajax rendering.
It lets you change the node that is used as main node '@node' when rendering the template. This
is useful when you want to update a dropped node and set comments but still want to render the
template in the receiver's context. See 'Node-test.zafu' for an example.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/helpers/application_helper.rb

    r1134 r1154  
    1818  # RJS to update a page after create/update/destroy 
    1919  def update_page_content(page, obj) 
     20    if params[:t_id] && @node.errors.empty? 
     21      @node = secure(Node) { Node.find_by_zip(params[:t_id])} 
     22    end 
     23     
    2024    base_class = obj.kind_of?(Node) ? Node : obj.class 
    2125     
  • trunk/app/views/nodes/update.rjs

    r1098 r1154  
    11if params[:dom_id] && !params[:t_url] 
    2   attribute = params[:node].keys[0] 
     2  attribute = (params[:node].keys - ['v_status'])[0] 
    33  if params[:zazen] == 'true' 
    44    page.replace_html params[:dom_id], "<span class='zazen_edit'>#{link_to_remote(_('edit'), :url => edit_node_path(@node[:zip]) + "?attribute=#{attribute}&dom_id=#{params[:dom_id]}#{params[:publish] == 'true' ? '&publish=true' : ''}&zazen=true", :method => :get)}</span>" + zazen(params[:node][attribute]) 
  • trunk/lib/parser/lib/rules/zena.rb

    r1147 r1154  
    979979         
    980980        hidden_fields['t_url'] = template_url 
     981        if t_id = @params[:t_id] 
     982          hidden_fields['t_id']  = parse_attributes_in_value(t_id) 
     983        end 
    981984         
    982985        erb_dom_id = @context[:saved_template] ? '<%= params[:dom_id] %>' : self.erb_dom_id 
     
    14301433        # normal rendering: not the start of a saved template 
    14311434        if is_draggable || descendant('unlink') 
    1432           @html_tag ||= 'div' 
    14331435          out "<% #{var}_dom_ids = [] -%>" 
    14341436        end 
     
    31563158      else 
    31573159        insert = '' 
    3158       end 
     3160      end   
     3161 
     3162      res = insert + text 
    31593163       
    31603164      if id_hash 
    3161         if @html_tag 
    3162           @html_tag_params.merge!(id_hash) 
    3163           res = insert + text 
    3164         else 
    3165           res = add_params(text, id_hash, insert) 
    3166         end 
    3167       end 
     3165        @html_tag ||= 'div' 
     3166        @html_tag_params.merge!(id_hash) 
     3167      end 
     3168       
    31683169      [res, drag_handle] 
    31693170    end 
  • trunk/test/fixtures/files/Node-test.zafu

    r1147 r1154  
    117117</ul> 
    118118 
    119 <h3>drop reload with param</h3> 
     119<h3>drop reload with param (comment on receiving)</h3> 
    120120 
    121121<div style='border:1px solid #400; min_width:100px; min_height:100px;' do='drop' change='params' d='[id]' do='if' test='param:d'> 
     
    141141<hr/> 
    142142 
     143<h3>drop reload with param (comment on dropped)</h3> 
     144 
     145<div style='border:1px solid #400; min_width:100px; min_height:100px;' do='drop' change='params' d='[id]' do='if' test='param:d'> 
     146  <r:node where='id eq param:d' in='site'> 
     147    Change icon to <r:img mode='tiny'/> ? 
     148    <r:form t_id='[main.id]'> 
     149      <r:input type='hidden' name='icon_for_id' set_value='[main.id]'/> 
     150      <r:input type='hidden' name='m_title' set_value='icon for [main.name]'/> 
     151      <r:textarea name='m_text'/> 
     152      <input type='submit'/> 
     153    </r:form> 
     154  </r:node> 
     155  <r:else> 
     156    please drop a node to change the icon 
     157    <r:icon><r:img mode='pv'/> 
     158    <ul do='comments'> 
     159    <li do='each'><b do='[title]'/> <b do='[author_name]'/> 
     160    <div do='{text}'/> 
     161    </li> 
     162    </ul></r:icon></r:else> 
     163</div> 
     164 
     165<hr/> 
    143166<h2>notes & comments</h2> 
    144167 
  • trunk/test/helpers/zena_parser/ajax.yml

    r1147 r1154  
    7474  context: 
    7575    node: 'wiki' 
    76   src: "<r:children><r:each><li><r:show attr='name'>blah</r:show> <r:edit>edit</r:edit></li>\n</r:each><r:form><li><form>this is the form</form></li></r:form></r:children>" 
     76  src: "<r:children><li do='each'><r:show attr='name'>blah</r:show> <r:edit>edit</r:edit></li>\n<r:form><li><form>this is the form</form></li></r:form></r:children>" 
    7777  res: "/<li id='list1_30'>bird <a href='/nodes/30/edit\?t_url=.*' onclick=\"new Ajax.Request\('/nodes/30/edit\?t_url=%2Feach%2Fedit%2Fwith%2Fform%2Flist/" 
    7878 
     
    8787    node: 'cleanWater' 
    8888    visitor: 'anon' 
    89   src: "<r:children><r:each><li><r:show attr='name'>blah</r:show> <r:edit>edit</r:edit></li>\n</r:each></r:children>" 
     89  src: "<r:children><li do='each'><r:show attr='name'>blah</r:show> <r:edit>edit</r:edit></li>\n</r:children>" 
    9090  res: "/<li id='list1_24'>lake </li>.*/" 
    9191 
     
    192192  tem: "/<div class='drop' id='list1'><%= params\[:d\] %>.*drop\?params\[d\]=%5Bid%5D/" 
    193193 
     194drop_param_in_each: 
     195  src: "<r:pages do='each' do='drop' change='params' d='[id]'><r:show param='d'/></r:pages>" 
     196  tem: "/<div class='drop' id='list1_<%= var1.zip %>'><%= params\[:d\] %>.*drop\?params\[d\]=%5Bid%5D/" 
     197 
    194198swap_in_each: 
    195199  src: "<r:pages><li do='each'><span do='swap' attr='d_status' states='todo,done,alert'/></li></r:pages>"