Changeset 599

Show
Ignore:
Timestamp:
2007-06-03 23:01:47 (2 years ago)
Author:
gaspard
Message:

Fixing the way zafu forms work. This will resolve many bugs related to values being loaded from the wrong context. Still some work to be done with r_add and it will be sane.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/TODO

    r583 r599  
    99  * image 
    1010  * template 
     11 
     12****** FIXME: visitor.lang should never be empty or bad. set 'lang' in participation ? 
    1113 
    1214* if mksite fails (password too short, etc): rollback ! 
  • trunk/app/controllers/application.rb

    r586 r599  
    234234        raise Zena::AccessViolation.new("'template_url' contains illegal characters : #{template_url.inspect}") 
    235235      end 
    236      
     236       
    237237      template_url = template_url[1..-1].split('/') 
    238       path = "/#{template_url[0]}/#{template_url[1]}/#{visitor.lang}/#{template_url[2..-1].join('/')}" 
     238      path = "/#{template_url[0]}/#{template_url[1]}/#{session[:dev] ? 'dev' : lang}/#{template_url[2..-1].join('/')}" 
    239239 
    240240      "#{SITES_ROOT}/#{current_site.host}/zafu#{path}" 
  • trunk/app/controllers/nodes_controller.rb

    r587 r599  
    4646        :join   => "INNER JOIN versions ON versions.node_id = nodes.id", 
    4747        :conditions => match, 
    48         :order  => "score DESC" } 
     48        :order  => "score DESC", 
     49        :group  => "nodes.id" } 
    4950    elsif params[:id] 
    5051      query = { 
  • trunk/app/helpers/application_helper.rb

    r591 r599  
    471471       
    472472      # get list of notes in this scope 
    473       notes = source.send(method, :conditions=>["#{using} >= ? AND #{using} <= ?", start_date, end_date], :order=>"#{using} ASC") || [] 
     473      notes = source.relation(method, :conditions=>["#{using} >= ? AND #{using} <= ?", start_date, end_date], :order=>"#{using} ASC") || [] 
    474474       
    475475      # build event hash 
  • trunk/app/models/contact.rb

    r561 r599  
    88  link :favorites,   :class_name=>'Node' 
    99  link :collaborator_for, :class_name=>'Project', :as=>'collaborator' 
     10   
     11  # TODO: test 
     12  def self.version_class 
     13    ContactVersion 
     14  end 
    1015   
    1116  def user 
     
    2126  end 
    2227   
    23   private 
    24     # TODO: test 
    25     def version_class 
    26       ContactVersion 
    27     end 
    2828end 
  • trunk/app/models/contact_version.rb

    r569 r599  
    99  before_validation_on_create :contact_version_before_validation_on_create 
    1010   
    11   def content_class 
     11  def self.content_class 
    1212    ContactContent 
    1313  end 
  • trunk/app/models/document.rb

    r576 r599  
    4141    def parent_class 
    4242      Node 
     43    end 
     44     
     45    def version_class 
     46      DocumentVersion 
    4347    end 
    4448     
     
    101105  private 
    102106   
    103   # Set name from filename 
    104   def document_before_validation 
    105     content = version.content 
    106     if new_record? 
    107       if ! self[:name].blank? 
    108         # name set 
    109         base = self[:name] 
    110       elsif file = content.instance_variable_get(:@file) 
    111         # set with filename 
    112         base = file.original_filename 
     107    # Set name from filename 
     108    def document_before_validation 
     109      content = version.content 
     110      if new_record? 
     111        if ! self[:name].blank? 
     112          # name set 
     113          base = self[:name] 
     114        elsif file = content.instance_variable_get(:@file) 
     115          # set with filename 
     116          base = file.original_filename 
     117        else 
     118          # set with title 
     119          base = version.title 
     120        end 
     121        if base =~ /(.*)\.(\w+)$/ 
     122          self[:name] = $1 
     123          ext         = $2 
     124        else 
     125          self[:name] = base 
     126          ext         = nil 
     127        end 
     128       
     129        content[:name] = self[:name].sub(/\.*$/,'') # remove trailing dots 
     130        content.ext    = ext 
    113131      else 
    114         # set with title 
    115         base = version.title 
    116       end 
    117       if base =~ /(.*)\.(\w+)$/ 
    118         self[:name] = $1 
    119         ext         = $2 
    120       else 
    121         self[:name] = base 
    122         ext         = nil 
    123       end 
    124        
    125       content[:name] = self[:name].sub(/\.*$/,'') # remove trailing dots 
    126       content.ext    = ext 
    127     else 
    128       # we cannot use 'old' here as this record is not secured when spreading inheritance 
    129       if self[:name] != self.class.find(self[:id])[:name] && self[:name] && self[:name] != '' 
    130         # FIXME: name is not important (just used to find file in case db crash: do not sync.) 
    131         # update all content names : 
    132         versions.each do |v| 
    133           if v[:id] == @version[:id] 
    134             v = @version # make sure modifications are made to our loaded version/content 
    135           else 
    136             v.node = self # preload so the relation to 'self' is kept 
     132        # we cannot use 'old' here as this record is not secured when spreading inheritance 
     133        if self[:name] != self.class.find(self[:id])[:name] && self[:name] && self[:name] != '' 
     134          # FIXME: name is not important (just used to find file in case db crash: do not sync.) 
     135          # update all content names : 
     136          versions.each do |v| 
     137            if v[:id] == @version[:id] 
     138              v = @version # make sure modifications are made to our loaded version/content 
     139            else 
     140              v.node = self # preload so the relation to 'self' is kept 
     141            end 
     142            content = v.content 
     143            content.name = self[:name].sub(/\.*$/,'') # remove trailing dots 
     144            content.save 
    137145          end 
    138           content = v.content 
    139           content.name = self[:name].sub(/\.*$/,'') # remove trailing dots 
    140           content.save 
    141146        end 
    142147      end 
    143148    end 
    144   end 
    145  
    146   # This is a callback from acts_as_multiversioned 
    147   def version_class 
    148     DocumentVersion 
    149   end 
    150149end 
  • trunk/app/models/document_version.rb

    r375 r599  
    88class DocumentVersion < Version 
    99  validates_presence_of       :content 
    10   def content_class 
     10  def self.content_class 
    1111    DocumentContent 
    1212  end 
  • trunk/app/models/image.rb

    r582 r599  
    6060      ImageBuilder.image_content_type?(content_type) 
    6161    end 
     62     
     63    # This is a callback from acts_as_multiversioned 
     64    def version_class 
     65      ImageVersion 
     66    end 
    6267  end 
    6368  # Crop the image using the 'crop' hash with the top left corner position (:x, :y) and the width and height (:width, :heigt). Example: 
     
    8691    version.filesize(format) 
    8792  end 
    88    
    89   private 
    90     # This is a callback from acts_as_multiversioned 
    91     def version_class 
    92       ImageVersion 
    93     end 
    9493end 
  • trunk/app/models/image_version.rb

    r542 r599  
    99  before_create :set_image_text 
    1010   
    11   def content_class 
     11  def self.content_class 
    1212    ImageContent 
    1313  end 
  • trunk/app/models/node.rb

    r598 r599  
    550550  def relation(methods, opts={}) 
    551551    res = nil 
    552     try_list = methods.split(',') 
     552    try_list = methods.to_s.split(',') 
    553553    plural = Zena::Acts::Linkable::plural_method?(try_list[0]) 
    554554    if !plural 
     
    738738    c = klass.new(opts) 
    739739    c.parent_id  = self[:id] 
     740    c.instance_variable_set(:@parent, self) 
     741     
    740742    c.visitor    = visitor 
    741743     
     
    795797  def user_zip; self[:user_id]; end 
    796798   
    797   # More reflection needed before implementation. 
     799   
     800  def klass=(new_class) 
     801    if new_class.kind_of?(String) 
     802      klass = Module.const_get(new_class) 
     803    else 
     804      klass = new_class 
     805    end 
     806    raise NameError if !klass.ancestors.include?(Node) || klass.version_class != self.class.content_class 
     807     
     808     
     809     
     810  rescue NameError 
     811    errors.add('klass', 'invalid') 
     812  end 
    798813   
    799814  # transform an Node into another Object. This is a two step operation : 
  • trunk/app/models/template.rb

    r598 r599  
    55    def accept_content_type?(content_type) 
    66      content_type =~ /text\/(html|xml)/ 
     7    end 
     8     
     9    def version_class 
     10      TemplateVersion 
    711    end 
    812  end 
     
    4347    end 
    4448     
    45     def version_class 
    46       TemplateVersion 
    47     end 
    4849end 
  • trunk/app/models/template_version.rb

    r587 r599  
    88class TemplateVersion < Version 
    99  validates_presence_of       :content 
     10   
     11   
     12  # TODO: test 
     13  def self.content_class 
     14    TemplateContent 
     15  end 
    1016   
    1117  # TODO: test 
     
    2935  end 
    3036   
    31   # TODO: test 
    32   def content_class 
    33     TemplateContent 
    34   end 
    3537end 
  • trunk/app/models/text_document.rb

    r588 r599  
    1515    def accept_content_type?(content_type) 
    1616      content_type =~ /^(text)/ 
     17    end 
     18     
     19    def version_class 
     20      TextDocumentVersion 
    1721    end 
    1822  end 
     
    5660      content[:ext]  ||= 'txt' 
    5761    end   
    58     # This is a callback from acts_as_multiversioned 
    59     def version_class 
    60       TextDocumentVersion 
    61     end 
    6262end 
  • trunk/app/models/text_document_version.rb

    r368 r599  
    33=end 
    44class TextDocumentVersion < DocumentVersion 
    5   def content_class 
     5  def self.content_class 
    66    TextDocumentContent 
    77  end 
  • trunk/app/models/version.rb

    r587 r599  
    4343  before_create         :set_number 
    4444  uses_dynamic_attributes 
     45   
     46  class << self 
     47    # Some #Version sub-classes need to have more specific content than just 'text' and 'summary'. 
     48    # this content is stored in a delegate 'content' object found with the 'content_class' class method 
     49    def content_class 
     50      nil 
     51    end 
     52  end 
    4553   
    4654  def author 
     
    123131  end 
    124132   
    125   # Some #Version sub-classes need to have more specific content than just 'text' and 'summary'. 
    126   # this content is stored in a delegate 'content' object found with the 'content_class' class method 
    127   def content_class 
    128     nil 
    129   end 
    130    
    131133  def clone 
    132134    obj = super 
     
    137139   
    138140  private 
     141    def content_class 
     142      self.class.content_class 
     143    end 
     144   
    139145    def can_update_content 
    140146      if @redaction_content && Version.find_all_by_content_id(self[:id]).size > 0 
  • trunk/app/views/calendar/_tiny.rhtml

    r585 r599  
    1 <table cellspacing="0" id="tinycal"
     1<table cellspacing="0" class='tinycal'
    22  <tr class="head"><td class="button"> 
    33    <%= link_to_remote( '<img src="/images/control_rewind.png"/>' , :update=>'tinycal', :url=>{:controller=>'calendar', :action=>'show', :date=>(date << 1), :id=>source[:id], :size=>size, :find=>method, :rnd=>rnd } ) %> 
  • trunk/app/views/nodes/create.rjs

    r471 r599  
    66  ref = params[:reference] || "#{params[:template_url]}_add" 
    77  page.insert_html pos.to_sym, ref, :file => fullpath_from_template_url + ".erb" 
    8   @node    = Node.new 
     8  @node = @node.parent.new_child(:class => @node.class) 
    99  page.replace "#{params[:template_url]}_form", :file => fullpath_from_template_url + "_form.erb" 
    1010  page.toggle "#{params[:template_url]}_form", "#{params[:template_url]}_add" 
  • trunk/db/init/base/help.yml

    r589 r599  
    11class: Page 
    2 v_title: Skins (layout themes) 
     2v_title: Help 
    33v_summary: | 
    44  |_. markup |_. result | 
  • trunk/db/init/base/skins/default/layout.html

    r584 r599  
    7777            <ol> 
    7878              <li do='each' set_class='li_s[v_status]' do='link'/> 
    79               <r:add before='self' tag='li'/> 
    80               <r:form> 
    81                 <li class='inline_form'> 
    82                   <form> 
    83                     <p class='hidden'>      <input type='hidden' name='node[parent_id]' value='' do='void' set_value='[id]'/></p> 
    84                     <p class='node_klass'>  <r:input type='select' attr='klass' options='Page,Section,Skin,Project'/></p> 
    85                     <p class='node_v_title'><input type='text' name='node[v_title]' value=''/></p> 
    86                     <p class='btn_validate'><input type="submit" value='validate' do='void' tset_value='validate'/></p> 
    87                   </form> 
    88                 </li> 
    89               </r:form> 
     79              <li do='add' before='self'/> 
     80              <li class='inline_form' do='form'> 
     81                <p class='node_klass'>  <input type='select' name='klass' options='Page,Section,Skin,Project'/></p> 
     82                <p class='node_v_title'><input type='text' name='v_title' value=''/></p> 
     83                <p class='btn_validate'><input type="submit" value='validate' tset_value='validate'/></p> 
     84              </li> 
    9085            </ol> 
    9186          </r:if> 
  • trunk/db/init/base/skins/default/notes.html

    r584 r599  
    11<div id='notes' do='notes_all' limit='10' order='log_at DESC'> 
    22  <ul class='note_list'> 
    3     <r:add after='self' tag='li'/> 
    4     <r:form><li class='inline_form'><form
    5         <p class='hidden'>      <input type='hidden' name='node[parent_id]' value='' do='void' set_value='[id]'/></p
    6         <p class='node_klass'>  <r:input type='select' attr='klass' options='Post,Letter'/></p> 
    7         <p class='node_log_at'> <r:input type='date_box' attr='log_at'/></p> 
    8         <p class='node_v_title'><input type='text' name='node[v_title]' do='void' set_value='[v_title]' size='25'/></p> 
     3    <li do='add' after='self'/> 
     4    <li class='inline_form' do='form'
     5      <form
     6        <p class='node_klass'>  <input type='select' name='klass' options='Post,Letter'/></p> 
     7        <p class='node_log_at'> <input type='date_box' name='log_at'/></p> 
     8        <p class='node_v_title'><input type='text' name='v_title' size='25'/></p> 
    99        <p class='validate'>    <input type="submit" value='validate' do='void' tset_value='validate'/></p> 
    10       </form></li> 
    11     </r:form
     10      </form> 
     11    </li
    1212    <li class='note' do='each'> 
    1313      <div class='header'> 
  • trunk/db/schema.rb

    r589 r599  
    157157    t.column "public_group_id", :integer 
    158158    t.column "site_group_id",   :integer 
     159    t.column "trans_group_id",  :integer 
    159160    t.column "name",            :string 
    160161    t.column "authentication",  :boolean 
     
    174175    t.column "klass",     :string 
    175176    t.column "mode",      :string 
    176   end 
    177  
    178   create_table "tmp", :id => false, :force => true do |t| 
    179     t.column "a", :string, :limit => 50 
    180     t.column "b", :string, :limit => 50 
    181177  end 
    182178 
  • trunk/lib/multiversion.rb

    r589 r599  
    566566         
    567567        def version_class 
    568           Version 
     568          self.class.version_class 
    569569        end 
    570570         
     
    587587          # PUT YOUR CLASS METHODS HERE 
    588588           
     589          # This is a callback from acts_as_multiversioned 
     590          def version_class 
     591            Version 
     592          end 
     593           
    589594          # Find a node based on a version id 
    590595          def version(version_id) 
  • trunk/lib/parser/lib/rules/zafu.rb

    r592 r599  
    6868      return text if @html_tag_done 
    6969      if @html_tag 
    70         if text.blank? && ['meta'].include?(@html_tag) 
     70        if text.blank? && ['meta','input'].include?(@html_tag) 
    7171          res = "<#{@html_tag}#{params_to_html(@html_tag_params || {})}#{append.join('')}/>" 
    7272        else 
     
    109109      end 
    110110       
     111      res   = "<#{@html_tag}#{params_to_html(@params)}" 
     112      @html_tag_done = true 
     113      inner = expand_with 
     114      if inner == '' 
     115        res + "/>" 
     116      else 
     117        res + ">#{inner}" 
     118      end 
     119    end 
     120     
     121    def r_form 
     122      res   = "<#{@html_tag}#{params_to_html(@params)}" 
     123      @html_tag_done = true 
     124      inner = expand_with 
     125      if inner == '' 
     126        res + "/>" 
     127      else 
     128        res + ">#{inner}" 
     129      end 
     130    end 
     131     
     132    def r_input 
     133      res   = "<#{@html_tag}#{params_to_html(@params)}" 
     134      @html_tag_done = true 
     135      inner = expand_with 
     136      if inner == '' 
     137        res + "/>" 
     138      else 
     139        res + ">#{inner}" 
     140      end 
     141    end 
     142     
     143    def r_textarea 
    111144      res   = "<#{@html_tag}#{params_to_html(@params)}" 
    112145      @html_tag_done = true 
     
    127160      @html_tag = @options[:html_tag] 
    128161      @options.delete(:html_tag) 
    129       @html_tag_params = parse_params(@options[:html_tag_params]
     162      @html_tag_params = parse_params(@options.delete(:html_tag_params)
    130163      @options.delete(:html_tag_params) 
    131164       
    132165      # end_tag 
    133       @end_tag = @html_tag || @options.delete(:end_do) || "r:#{@method}" 
     166      @end_tag = @html_tag || @options.delete(:end_do) || @options.delete(:end_tag) || "r:#{@method}" 
    134167      @end_tag_count  = 1 
    135168       
     
    137170      @space_before = @options[:space_before] 
    138171      @options.delete(:space_before) 
     172       
     173      # form capture (input, textarea, form) 
     174      @options[:form] ||= true if @method == 'form' 
    139175       
    140176      # puts "[#{@space_before}(#{@method})#{@space_after}]" 
     
    267303        # puts "HTML:[#{$&}]" # html 
    268304        make(:asset) 
     305      elsif @options[:form] && @text =~ /\A<(input|textarea|form)([^>]*?)(\/?)>/ 
     306        eat $& 
     307        method = $1 == 'form' ? 'form_tag' : $1 # <form> ==> r_form_tag, <r:form> ==> r_form 
     308        opts.merge!(:method=>method, :params=>$2) 
     309        opts.merge!(:text=>'') if $3 != '' 
     310        opts.merge!(:end_tag=>'form') if method == 'form_tag' 
     311        make(:void, opts) 
    269312      elsif @text =~ /\A[^>]*?>/ 
    270313        # html tag 
  • trunk/lib/parser/lib/rules/zena.rb

    r592 r599  
    7272      # some 'id' information can be set during rendering and should merge into tag_params 
    7373      @html_tag_params_bak = @html_tag_params 
    74       @html_tag_params     = @html_tag_params.merge(@context[:html_tag_params] || {}) 
     74      @html_tag_params     = @html_tag_params.merge(@context.delete(:html_tag_params) || {}) 
    7575      unless @context[:preflight] 
    7676        if store = @params.delete(:store) 
     
    330330     
    331331    def r_edit 
    332       @pass[:edit] = self 
    333332      if @context[:preflight] 
     333        @pass[:edit] = self 
    334334        # preprocessing 
    335335        return "" 
     
    345345    end 
    346346     
    347     # FIXME: implement all inputs correctly ! 
    348     # change ALL inputs/textarea,form etc from within a z:form ? 
    349347    def r_input 
     348      return '' if @context[:preflight] 
    350349      case @params[:type] 
    351350      when 'select' 
     351        return "<span class='parser_error'>select without name</span>"   unless   name = @params[:name] 
    352352        klasses = @params[:options] || "Page,Note" 
    353         "<%= select('node', '#{@params[:attr]}', #{klasses.split(',').map(&:strip).inspect}) %>" 
     353        "<%= select('node', #{name.inspect}, #{klasses.split(',').map(&:strip).inspect}) %>" 
    354354      when 'date_box' 
    355         "<%= date_box 'node', '#{@params[:attr]}', :size=>15 %>" 
    356       end 
     355        return "<span class='parser_error'>date_box without name</span>"   unless   name = @params[:name] 
     356        "<%= date_box 'node', #{name.inspect}, :size=>15#{@context[:in_add] ? ", :value=>''" : ''} %>" 
     357      else 
     358        @html_tag = 'input' 
     359        @html_tag_params.merge!(@params) 
     360        if name = @html_tag_params[:name] 
     361          if name =~ /\Anode\[(.*?)\]/ 
     362            name = $1 
     363          else 
     364            @html_tag_params[:name] = "node[#{name}]" 
     365          end 
     366          return '' if name == 'node[parent_id]' # set with 'r_form' 
     367        end 
     368        if @context[:in_add] 
     369          value = @html_tag_params[:value] ? '' : " value=''" 
     370        else 
     371          value = name ? " value='<%= #{node_attribute(name, :node=>'@node')} %>'" : '' 
     372        end 
     373        out render_html_tag(nil, value) 
     374      end 
     375    end 
     376     
     377    def r_form_tag 
     378      if @context[:preflight] 
     379        @pass[:form_tag] = self 
     380        # preprocessing 
     381        return "" 
     382      end 
     383      # replace <form> with constructed form 
     384      "#{@context[:form_tag]}#{expand_with(:form_tag => nil)}</form>" 
    357385    end 
    358386     
     
    361389    # FIXME: use <r:form href='self'> or <r:form action='...'> 
    362390    def r_form 
    363       @pass[:form] = self 
    364391      if @context[:preflight] 
     392        @pass[:form] = self 
    365393        # preprocessing 
    366394        return "" 
    367395      end 
    368396       
    369        
    370397      if template_url = @context[:template_url] 
    371398        # ajax 
    372         # TODO: use remote_form_for :#{node_class.to_s.downcase}, :url ... and replace all input/select/... 
    373399 
    374400        if @context[:in_add] 
    375           @html_tag_params.merge!(:id=>"#{template_url}_form") 
    376           form =  "<p class='btn_x'><a href='#' onclick='[\"#{template_url}_add\", \"#{template_url}_form\"].each(Element.toggle);return false;'>#{_('btn_x')}</a></p>\n" 
    377           form << "<%= form_remote_tag(:url => #{node_class.to_s.downcase.pluralize}_path) %>\n" 
    378         else 
    379           # saved form 
     401          # inline form used to create new elements: set values to '' and 'parent_id' from context 
     402          @html_tag_params.merge!(:id=>"#{template_url}_form", :style=>"display:none;") 
     403          start =  "<p class='btn_x'><a href='#' onclick='[\"#{template_url}_add\", \"#{template_url}_form\"].each(Element.toggle);return false;'>#{_('btn_x')}</a></p>\n" 
     404          form  =  "<%= form_remote_tag(:url => #{node_class.to_s.downcase.pluralize}_path) %>\n" 
     405        else 
     406          # saved form used to edit: set values and 'parent_id' from @node 
    380407          @html_tag_params.merge!(:id=>"#{template_url}<%= @node.new_record? ? '_form' : @node[:zip] %>") 
     408          # new_record? = edit/create failed, rendering form with errors 
     409          # else        = edit 
     410          start =<<-END_TXT 
     411<% if @node.new_record? -%> 
     412  <p class='btn_x'><a href='#' onclick='[\"#{template_url}_add\", \"#{template_url}_form\"].each(Element.toggle);return false;'>#{_('btn_x')}</a></p> 
     413<% else -%> 
     414  <p class='btn_x'><%= link_to_remote(#{_('btn_x').inspect}, :url => #{node_class.to_s.downcase}_path(#{node}[:zip]) + '?template_url=#{CGI.escape(template_url)}', :method => :get) %></a></p> 
     415<% end -%> 
     416END_TXT 
    381417          form =<<-END_TXT 
    382418<% if @node.new_record? -%> 
    383   <p class='btn_x'><a href='#' onclick='[\"#{template_url}_add\", \"#{template_url}_form\"].each(Element.toggle);return false;'>#{_('btn_x')}</a></p> 
    384   <%= form_remote_tag(:url => #{node_class.to_s.downcase.pluralize}_path) %> 
     419<%= form_remote_tag(:url => #{node_class.to_s.downcase.pluralize}_path) %> 
    385420<% else -%> 
    386   <p class='btn_x'><%= link_to_remote(#{_('btn_x').inspect}, :url => #{node_class.to_s.downcase}_path(#{node}[:zip]) + '?template_url=#{CGI.escape(template_url)}', :method => :get) %></a></p> 
    387   <%= form_remote_tag(:url => #{node_class.to_s.downcase}_path(#{node}[:zip]), :method => :put) %> 
     421<%= form_remote_tag(:url => #{node_class.to_s.downcase}_path(#{node}[:zip]), :method => :put) %> 
    388422<% end -%> 
    389423END_TXT 
     
    391425        form << "<div class='hidden'>" 
    392426        form << "<input type='hidden' name='template_url' value='#{template_url}'/>\n" 
     427        form << "<input type='hidden' name='node[parent_id]' value='<%= #{@context[:in_add] ? '@node[:zip]' : node + '.parent_zip'} %>'/>\n" 
    393428         
    394         if @params[:klass] 
    395           # FIXME: add the 'klass' attribute to node_class if no input for klass 
     429        if @params[:klass] && @context[:in_add] 
    396430          form << "<input type='hidden' name='node[klass]' value='#{@params[:klass]}'/>\n" 
    397431        end 
     
    410444        form = "FORM WITHOUT AJAX TODO\n" 
    411445      end 
    412       exp = expand_with 
    413        
    414       exp.gsub!(/<form[^>]*>/,form) 
    415       if @html_tag 
    416         out render_html_tag(exp) 
    417       elsif exp =~ /\A([^<]*)<(\w+)([^>]*)>(.*)<\/\2>(.*)/m 
    418         out $1 
    419         tag   = $2 
    420         inner = $4 
    421         after = $5 
    422         if @html_tag_params 
    423           start_tag  = add_params("<#{$2}#{$3}>", @html_tag_params) 
    424         else 
    425           start_tag = "<#{$2}#{$3}>" 
    426         end 
    427         out "#{start_tag}#{inner}</#{tag}>#{after}" 
    428         @html_tag_done = true 
    429       else 
    430         out exp 
    431       end 
     446      if @pass[:form_tag] 
     447        res = start + expand_with(:form_tag => form) 
     448      else 
     449        res = start + form + expand_with + '</form>' 
     450      end 
     451      out render_html_tag(res) 
    432452    end 
    433453     
     
    463483    # TODO: test 
    464484    def r_add 
    465       @pass[:add] = self 
    466485      if @context[:preflight] 
     486        @pass[:add] = self 
    467487        # preprocessing 
    468488        return "" 
     
    493513        end 
    494514         
    495         form_opts = { :node=>"@#{node_class.to_s.downcase}", :html_tag_params=>{:id=>"#{prefix}_form", :style=>"display:none;"}, :no_form => false, :in_add => true } 
     515         
     516        # FIXME: :after, :before, :top, :bottom should move to 'r_form' during preflight 
     517        #        :node => .. should be removed. 
     518        #        just leave ':in_add' 
     519         
     520        form_opts = { :node=>"@#{node_class.to_s.downcase}", :no_form => false, :in_add => true } 
    496521         
    497522        [:after, :before, :top, :bottom].each do |sym| 
     
    869894    # TODO: test 
    870895    def r_calendar 
    871       from   = 'project'.inspect 
     896      from   = 'project' 
    872897      date   = 'main_date' 
    873       find   = (@params[:find  ] || 'news'   ).to_sym.inspect 
    874       size   = (@params[:size  ] || 'tiny'    ).to_sym.inspect 
    875       using  = (@params[:using ] || 'event_at').gsub(/[^a-z_]/,'').to_sym.inspect # SQL injection security 
    876       "<%= calendar(:node=>#{node}, :from=>#{from}, :date=>#{date}, :find=>#{find}, :size=>#{size}, :using=>#{using}) %>" 
     898      find   = (@params[:find  ] || 'news'   ).to_sym 
     899      size   = (@params[:size  ] || 'tiny'    ).to_sym 
     900      using  = (@params[:using ] || 'event_at').gsub(/[^a-z_]/,'').to_sym # SQL injection security 
     901      "<div id='#{size}cal'><%= calendar(:node=>#{node}, :from=>#{from.inspect}, :date=>#{date}, :find=>#{find.inspect}, :size=>#{size.inspect}, :using=>#{using.inspect}) %></div>" 
    877902    end 
    878903     
     
    12971322        end 
    12981323      end 
    1299       @html_tag = 'div' if !@html_tag && set_params != {} 
    1300        
    1301       @html_tag_params ||= {} 
     1324 
     1325      @html_tag = 'div' if !@html_tag && (set_params != {} || @html_tag_params != {}) 
     1326       
    13021327      bak = @html_tag_params.dup 
    13031328      res_params = {} 
  • trunk/lib/parser/test/parser_test.rb

    r591 r599  
    3636      "nothing missing" 
    3737    end 
     38     
     39    def r_textarea 
     40      res   = "<#{@html_tag}#{params_to_html(@params)}" 
     41      @html_tag_done = true 
     42      inner = expand_with 
     43      if inner == '' 
     44        res + "/>" 
     45      else 
     46        res + ">#{inner}" 
     47      end 
     48    end 
     49     
    3850    def r_test 
    3951      self.inspect 
     
    4456  testfile :zafu, :zafu_asset, :zafu_insight, :zazen 
    4557  def test_single 
    46     do_test('zafu', 'ignore_do_empty') 
     58    do_test('zafu', 'form') 
    4759  end 
    4860   
  • trunk/lib/parser/test/zafu.yml

    r591 r599  
    290290  src: "<r:void class='test' tag='p'>blah</r:void>" 
    291291  res: "<p class='test'>blah</p>" 
     292   
     293static_form: 
     294  src: "<r:test><form action='hello'><p><input type='text' name='hoy' value='hili'/></p></form></r:test>" 
     295  res: "[test]<form action='hello'><p><input type='text' name='hoy' value='hili'/></p></form>[/test]" 
     296   
     297form: 
     298  src: "<r:test><p do='form'><form action='hello'><p><input type='text' name='hoy' value='hili'/></p></form></p></r:test>" 
     299  res: "[test][form]<p>[form_tag {= :action=>'hello'}]<p>[input {= :name=>'hoy', :type=>'text', :value=>'hili'}/]</p>[/form_tag]</p>[/form][/test]" 
  • trunk/lib/parser/test/zazen.yml

    r496 r599  
    66  src: "some @strange < code@" 
    77  res: "<p>some <code>strange &lt; code</code></p>" 
     8   
     9at_code_again: 
     10  src: "We changed the syntax from @zafu|<z:link/>@ to @zafu|<r:link/>@ to better reflect the fact that we want to *render* a link." 
     11  res: "/code class='zafu'.*/" 
    812   
    913at_code_ruby: 
  • trunk/lib/tasks/zena.rake

    r597 r599  
    116116            #        OR we could symlink /var/zena/current/... 
    117117            ['calendar', 'images', 'javascripts', 'stylesheets'].each do |dir| 
     118              # FIXME: 'RAILS_ROOT' should be '/var/zena/current' and not '/var/zena/releases/20070632030330' !!! 
    118119              FileUtils.ln_s("#{RAILS_ROOT}/public/#{dir}", "#{host_path}/public/#{dir}") 
    119120            end 
  • trunk/public/stylesheets/calendars.css

    </
    r585 r599  
    11/* small calendar */ 
    22 
    3 #small_calendar { height: 9em; margin-bottom:0.8em; } 
    4 #tinycal { font-size:0.7em; margin:auto; cursor:pointer; } 
    5 #tinycal table { border: 1px solid #CAD4DA; background:#F5F8F9; } 
    6 #tinycal td { text-align:center; color:#333; } 
    7 #tinycal a { color:inherit; } 
    8 #tinycal em { border-bottom:2px solid orange; } 
    9 #tinycal .head td { font-weight:bold; padding: 2px; line-height:1.5; font-size:0.9em; color:#655; padding:2px; text-align:center; } 
    10 #tinycal .head td.button a { border:0; text-decoration:none; color:#568BB9;} 
    11 #tinycal .body td { height:1.8em; } 
    12 #tinycal .body #tiny_today p { background:#CFD6DA; } 
    13 #tinycal .body td.other, #tinycal .body td.other a { color:#ccc; } 
    14 #tinycal .body td.sat, #tinycal .body td.sat a { color:#35950B; } 
    15 #tinycal .body td.satother, #tinycal .body td.satother a { color:#C8DEC1; } 
    16 #tinycal .body td.sun, #tinycal .body td.sun a { color:#35950B; } 
    17 #tinycal .body td.sunother, #tinycal .body td.sunother a { color:#C8DEC1; } 
     3#tinycal { height: 9em; margin-bottom:0.8em; }