Changeset 1090

Show
Ignore:
Timestamp:
2008-07-01 11:14:08 (6 months ago)
Author:
gaspard
Message:

Added the possibility to update distant block (and self) in [swap] and [unlink]:

<p do='block' do='swap' states='1,2' attr='custom_a' update='swa'>value: <r:show attr='custom_a'/></p>
<div id='swa' do='block'>...</div>

If update == '_page' => reload full page.

Files:

Legend:

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

    r1082 r1090  
    1313      "#{params[:dom_id]}_#{node.zip}" 
    1414    else 
    15       params[:udom_id] || params[:dom_id] 
     15      @dom_id || params[:udom_id] || params[:dom_id] 
    1616    end 
    1717  end 
     
    3232        page.replace "#{params[:dom_id]}_form", :file => fullpath_from_template_url + "_form.erb" 
    3333      end 
    34     elsif params[:u_url] 
    35       # C. update another part of the page 
    36       if node_id = params[:u_id] 
    37         if node_id.to_i != obj.zip 
    38           if base_class == Node 
    39             instance_variable_set("@#{base_class.to_s.underscore}", secure(base_class) { base_class.find_by_zip(node_id) }) 
    40           else 
    41             instance_variable_set("@#{base_class.to_s.underscore}", secure(base_class) { base_class.find_by_id(node_id) }) 
     34    elsif params[:udom_id] 
     35      if params[:udom_id] == '_page' 
     36        # reload page 
     37        page << "document.location.href = document.location.href;" 
     38      else 
     39        # C. update another part of the page 
     40        if node_id = params[:u_id] 
     41          if node_id.to_i != obj.zip 
     42            if base_class == Node 
     43              instance_variable_set("@#{base_class.to_s.underscore}", secure(base_class) { base_class.find_by_zip(node_id) }) 
     44            else 
     45              instance_variable_set("@#{base_class.to_s.underscore}", secure(base_class) { base_class.find_by_id(node_id) }) 
     46            end 
    4247          end 
    4348        end 
    44       end 
    45       page.replace params[:udom_id], :file => fullpath_from_template_url(params[:u_url]) + ".erb" 
    46       if params[:done] 
    47         page.toggle "#{params[:dom_id]}_form", "#{params[:dom_id]}_add" 
    48         page << params[:done] 
     49        page.replace params[:udom_id], :file => fullpath_from_template_url(params[:u_url]) + ".erb" 
     50        if params[:upd_both] 
     51          @dom_id = params[:dom_id] 
     52          page.replace params[:dom_id], :file => fullpath_from_template_url + ".erb" 
     53        end 
     54        if params[:done] 
     55          page.toggle "#{params[:dom_id]}_form", "#{params[:dom_id]}_add" 
     56          page << params[:done] 
     57        end 
    4958      end 
    5059    else 
    5160      # D. normal update 
     61      #if params[:dom_id] == '_page' 
     62      #  # reload page 
     63      #  page << "document.location.href = document.location.href;" 
     64      #   
    5265      case params[:action] 
    5366      when 'edit' 
  • trunk/lib/parser/lib/rules/zena.rb

    r1087 r1090  
    503503    # swap an attribute 
    504504    # TODO: test 
    505     def r_swap 
    506       if block = ancestor('block') || ancestor('each') 
     505    def r_swap       
     506      if upd = @params[:update] 
     507        if upd == '_page' 
     508          block = nil 
     509        elsif block = find_target(upd) 
     510          # ok 
     511          if ancestor('block') || ancestor('each') 
     512            upd_both = '&upd_both=true' 
     513          else 
     514            upd_both = '' 
     515          end 
     516        else 
     517          return 
     518        end 
     519      elsif ancestor('block') || ancestor('each') 
    507520        # ancestor: ok 
     521        block = self 
    508522      elsif parent && block = parent.descendant('block') 
    509523        # sibling: ok 
     524        upd_both = '' 
    510525      else 
    511526        return parser_error("missing 'block' in same parent") 
     
    513528      states = ((@params[:states] || 'todo, done') + ' ').split(',').map(&:strip) 
    514529       
    515       url_params = "node[#{@params[:attr]}]=\#{#{states.inspect}[ ((#{states.inspect}.index(#{node_attribute(@params[:attr])}.to_s) || 0)+1) % #{states.size}]}" 
     530      url_params = "node[#{@params[:attr]}]=\#{#{states.inspect}[ ((#{states.inspect}.index(#{node_attribute(@params[:attr])}.to_s) || 0)+1) % #{states.size}]}#{upd_both}" 
     531       
    516532       
    517533      out link_to_update(block, :url_params => url_params, :method => :put, :html_params => get_html_params(@params)) 
     
    11591175      opts = {} 
    11601176       
     1177      if upd = @params[:update] 
     1178        if upd == '_page' 
     1179          target = nil 
     1180        elsif target = find_target(upd) 
     1181          # ok 
     1182        else 
     1183          return 
     1184        end 
     1185      end 
     1186       
    11611187      unless target = ancestor('block') 
    11621188        target = self 
     
    16381664        @html_tag_done = true 
    16391665      end 
    1640        
    16411666       
    16421667      if upd = @params[:update] 
     
    26172642       
    26182643      if method == :get 
    2619         url_params << "t_url=#{CGI.escape(target.template_url)}" 
    2620         url_params << "dom_id=#{target.dom_id}" 
     2644        if target 
     2645          url_params << "t_url=#{CGI.escape(target.template_url)}"  
     2646          url_params << "dom_id=#{target.dom_id}" 
     2647        else 
     2648          url_params << "dom_id=_page" 
     2649        end 
    26212650      else 
    26222651        url_params << "t_url=#{CGI.escape(template_url)}" if method != :delete 
     
    26242653        url_params << "dom_id=#{dom_id}" 
    26252654        if target != self 
    2626           url_params << "u_url=#{CGI.escape(target.template_url)}" 
    2627           url_params << "udom_id=#{target.dom_id}" 
     2655          if target 
     2656            url_params << "u_url=#{CGI.escape(target.template_url)}" 
     2657            url_params << "udom_id=#{target.dom_id}" 
     2658          else 
     2659            url_params << "udom_id=_page" 
     2660          end 
    26282661        end 
    26292662      end