Changeset 1147 for trunk/lib/parser

Show
Ignore:
Timestamp:
2008-09-15 13:51:17 (4 months ago)
Author:
gaspard
Message:

Improved [drop]: the drop element can now alter query parameters. This can be used to preload forms and ask for validation, with comments.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/parser/lib/rules/zena.rb

    r1138 r1147  
    278278      elsif @params[:attr] 
    279279        attribute_method = node_attribute(@params[:attr], :else=>@params[:else], :default=>@params[:default]) 
     280      elsif p = @params[:param] 
     281        return "<%= params[#{p.to_sym.inspect}] %>" 
    280282      elsif @params[:date] 
    281283        # date can be any attribute v_created_at or updated_at etc. 
     
    482484 
    483485            context_bak = @context.dup # avoid side effects when rendering the same block 
    484             template    = expand_block(self, :block=>self, :list=>false, :saved_template=>true, :ignore =>['form']) 
     486            ignore_list = @method == 'block' ? ['form'] : [] # do not show the form in the normal template of a block 
     487            template    = expand_block(self, :block=>self, :list=>false, :saved_template=>true, :ignore => ignore_list) 
    485488            @context    = context_bak 
    486489            @result     = '' 
     
    523526      end 
    524527      return parser_error("cannot use 's' as key (used by start_node)") if @params[:key] == 's' 
    525       out "<%= form_remote_tag(:url => zafu_node_path(#{node_id}), :method => :get, :html => {:id => \"#{dom_id}_f\"}) %><div class='hidden'><input type='hidden' name='t_url' value='#{block.template_url}'/><input type='hidden' name='dom_id' value='#{block.erb_dom_id}'/>#{start_node_input}</div><div class='wrapper'>" 
     528      out "<%= form_remote_tag(:url => zafu_node_path(#{node_id}), :method => :get, :html => {:id => \"#{dom_id}_f\"}) %><div class='hidden'><input type='hidden' name='t_url' value='#{block.template_url}'/><input type='hidden' name='dom_id' value='#{block.erb_dom_id}'/>#{start_node_s_param(:input)}</div><div class='wrapper'>" 
    526529      if @blocks == [] 
    527530        out "<input type='text' name='#{@params[:key] || 'f'}' value='<%= params[#{(@params[:key] || 'f').to_sym.inspect}] %>'/>" 
     
    12371240          next if [:hover, :change, :done].include?(k) 
    12381241          value, static = parse_attributes_in_value(v, :erb => false, :skip_node_attributes => true) 
    1239           url_params << "node[#{k}]=#{CGI.escape(value)}" 
     1242          key = change == 'params' ? "params[#{k}]" : "node[#{k}]" 
     1243          url_params << "#{key}=#{CGI.escape(value)}" 
    12401244        end 
    12411245        return parser_error("missing parameters to set values") if url_params == [] 
    12421246      end 
    12431247     
    1244       url_params << "change=dropped" if change == 'dropped
     1248      url_params << "change=#{change}" if change == 'receiver
    12451249      url_params << "t_url=#{CGI.escape(template_url)}" 
    12461250      url_params << "dom_id=#{erb_dom_id}" 
     1251      url_params << start_node_s_param(:erb) 
    12471252      url_params << "done=#{CGI.escape(@params[:done])}" if @params[:done] 
    12481253     
     
    21742179    def node(klass = self.node_class) 
    21752180      if klass == self.node_class 
    2176         @context[:saved_template] ? "@#{base_class.to_s.underscore}" : (@context[:node] || '@node') 
     2181        (@context[:saved_template] && @context[:main_node]) ? "@#{base_class.to_s.underscore}" : (@context[:node] || '@node') 
    21772182      elsif klass == Node 
    21782183        @context[:previous_node] || '@node' 
     
    23702375    # DOM id for the current context 
    23712376    def dom_id(suffix='') 
    2372       return "\#{dom_id(#{node})}" if @context && @context[:saved_template] 
     2377      return "\#{dom_id(#{node})}" if @context && (@context[:saved_template] && @context[:main_node]) 
    23732378      if @context && scope_node = @context[:scope_node] 
    23742379        res = "#{dom_prefix}_\#{#{scope_node}.zip}" 
     
    23952400     
    23962401    def erb_dom_id(suffix='') 
    2397       return "<%= dom_id(#{node}) %>" if @context && @context[:saved_template] 
     2402      return "<%= dom_id(#{node}) %>" if @context && (@context[:saved_template] && @context[:main_node]) 
    23982403      if @context && scope_node = @context[:scope_node] 
    23992404        res = "#{dom_prefix}_<%= #{scope_node}.zip %>" 
     
    24442449    # use our own scope 
    24452450    def clear_dom_scope 
    2446       @context.delete(:dom_prefix)     # should not propagate 
    24472451      @context.delete(:make_form)      # should not propagate 
    2448       @context.delete(:saved_template) # should not propagate 
     2452      @context.delete(:main_node)      # should not propagate 
    24492453    end 
    24502454     
     
    24522456    def new_dom_scope 
    24532457      clear_dom_scope 
     2458      @context.delete(:saved_template) # should not propagate on fresh template 
     2459      @context.delete(:dom_prefix)     # should not propagate on fresh template 
     2460      @context[:main_node]  = true     # the current context will be rendered with a fresh '@node' 
    24542461      @context[:dom_prefix] = self.dom_prefix 
    24552462    end 
     
    28472854      url_params << "link_id=\#{#{node}.link_id}" if @context[:need_link_id] && node_kind_of?(Node) 
    28482855      url_params << "node[v_status]=#{Zena::Status[:pub]}" if @params[:publish] 
    2849       url_params << start_node_input(false
     2856      url_params << start_node_s_param(:string
    28502857       
    28512858      res = '' 
     
    30833090      return '' if attribute == 'parent_id' # set with 'r_form' 
    30843091       
    3085       if @context[:in_add] 
    3086         value = '' 
    3087       else 
    3088         value = attribute ? "<%= #{node_attribute(attribute)} %>" : "" 
     3092      if @blocks == [] || @blocks == [''] 
     3093        if @context[:in_add] 
     3094          value = '' 
     3095        else 
     3096          value = attribute ? "<%= #{node_attribute(attribute)} %>" : "" 
     3097        end 
     3098      else 
     3099        value = expand_with 
    30893100      end 
    30903101      html_id = @context[:dom_prefix] ? " id='#{erb_dom_id}_#{attribute}'" : '' 
     
    31183129    end 
    31193130     
    3120     def start_node_input(erb = true
    3121       if erb 
     3131    def start_node_s_param(type = :input
     3132      if type == :input 
    31223133        "<input type='hidden' name='s' value='<%= params[:s] || @node[:zip] %>'/>" 
     3134      elsif type == :erb 
     3135        "s=<%= params[:s] || @node[:zip] %>" 
    31233136      else 
    31243137        "s=\#{params[:s] || @node[:zip]}"