Changeset 1082
- Timestamp:
- 2008-07-01 01:22:27 (6 months ago)
- Files:
-
- trunk/app/controllers/application.rb (modified) (3 diffs)
- trunk/app/controllers/data_entries_controller.rb (modified) (1 diff)
- trunk/app/controllers/nodes_controller.rb (modified) (4 diffs)
- trunk/app/helpers/application_helper.rb (modified) (2 diffs)
- trunk/app/views/data_entries/create.rjs (modified) (1 diff)
- trunk/app/views/data_entries/destroy.rjs (modified) (1 diff)
- trunk/app/views/data_entries/edit.rjs (modified) (1 diff)
- trunk/app/views/data_entries/show.rjs (modified) (1 diff)
- trunk/app/views/data_entries/update.rjs (modified) (1 diff)
- trunk/app/views/links/destroy.rjs (modified) (1 diff)
- trunk/app/views/nodes/_edit_attribute.rhtml (modified) (1 diff)
- trunk/app/views/nodes/drop.rjs (modified) (1 diff)
- trunk/app/views/nodes/edit.rjs (modified) (1 diff)
- trunk/app/views/nodes/show.rjs (modified) (1 diff)
- trunk/app/views/nodes/update.rjs (modified) (1 diff)
- trunk/lib/parser/lib/parser.rb (modified) (2 diffs)
- trunk/lib/parser/lib/rules/zena.rb (modified) (36 diffs)
- trunk/lib/parser/test/parser/zafu.yml (modified) (1 diff)
- trunk/lib/parser/test/parser_test.rb (modified) (1 diff)
- trunk/public/stylesheets/zena.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/application.rb
r1081 r1082 250 250 path 251 251 end 252 252 253 253 # Find the best template for the current node's skin, node's class, format and mode. The template 254 254 # files are searched first into 'sites/shared/views/templates/fixed'. If the templates are not found … … 431 431 "" 432 432 end 433 434 # TODO: test 435 def fullpath_from_template_url(template_url=params[:t emplate_url])433 434 # TODO: test 435 def fullpath_from_template_url(template_url=params[:t_url]) 436 436 if template_url =~ /\A\.|[^\w\*\._\-\/]/ 437 437 raise Zena::AccessViolation.new("'template_url' contains illegal characters : #{template_url.inspect}") … … 444 444 end 445 445 446 def eval_parameters_from_template_url(template_url=params[:template_url])447 return {} unless template_url448 path = fullpath_from_template_url(template_url) + '.erb'449 if File.exists?(path)450 eval File.read(path)451 else452 nil453 end454 end455 446 # Require a login for authenticated navigation (with '/oo' prefix) or for any content if the site's 'authorize' 456 447 # attribute is true. trunk/app/controllers/data_entries_controller.rb
r998 r1082 30 30 def zafu 31 31 respond_to do |format| 32 format.js { @template_file = fullpath_from_template_url(params[:template_url]) 33 render :action => 'show' } 32 format.js { render :action => 'show' } 34 33 end 35 34 end trunk/app/controllers/nodes_controller.rb
r1081 r1082 62 62 def zafu 63 63 respond_to do |format| 64 format.js { @template_file = fullpath_from_template_url(params[:template_url]) 65 render :action => 'show' } 64 format.js { render :action => 'show' } 66 65 end 67 66 end … … 74 73 75 74 if attributes = params[:node] 76 if params[:target] == 'receiver' 75 if params[:node][:id] == '[id]' 76 # swap (a way to preview content by drag & drop) 77 @node = other 78 elsif params[:change] == 'receiver' 77 79 attributes[:copy] = other 78 80 @node.update_attributes_with_transformation(attributes) … … 89 91 end 90 92 91 #if set == 'parent' 92 # unless other.update_attributes(:parent_id => @node[:id]) 93 # @errors = other.errors 94 # end 95 #elsif set =~ /\Ad_/ 96 # other.update_attributes(set => (@params[:value] || @node.v_title)) 97 #elsif other.class.zafu_readable?(set) 98 # other.update_attributes(set => (@params[:value] || @node.v_title)) 99 #else 100 # other.add_link(set, @node[:id]) 101 # unless other.save 102 # @errors = other.errors 103 # end 104 #end 105 respond_to do |format| 106 format.js { @template_file = fullpath_from_template_url(params[:template_url]) } 93 respond_to do |format| 94 format.js 107 95 end 108 96 end … … 224 212 end 225 213 226 if params[:template_url]227 # edit from inline form in zafu228 @update = 'zafu'229 elsif params[:identifier]230 @update = 'attribute'231 elsif ['parent', 'dates', 'groups', 'links'].include? params[:drive]232 # drive editing233 @update = params[:drive]234 else235 @update = 'edit'236 end237 238 214 respond_to do |format| 239 215 format.html do trunk/app/helpers/application_helper.rb
r1081 r1082 5 5 module ApplicationHelper 6 6 include Zena::Acts::Secure 7 8 9 def dom_id(node) 10 if node.new_record? 11 "#{params[:dom_id]}_form" 12 elsif params[:action] == 'create' && !params[:udom_id] 13 "#{params[:dom_id]}_#{node.zip}" 14 else 15 params[:udom_id] || params[:dom_id] 16 end 17 end 18 19 # RJS to update a page after create/update/destroy 20 def update_page_content(page, obj) 21 base_class = obj.kind_of?(Node) ? Node : obj.class 22 23 if obj.new_record? 24 # A. could not create object: show form with errors 25 page.replace "#{params[:dom_id]}_form", :file => fullpath_from_template_url + "_form.erb" 26 elsif @errors || !obj.errors.empty? 27 # B. could not update/delete: show errors 28 case params[:action] 29 when 'destroy', 'drop' 30 page.insert_html :top, params[:dom_id], :inline => render_errors 31 else 32 page.replace "#{params[:dom_id]}_form", :file => fullpath_from_template_url + "_form.erb" 33 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) }) 42 end 43 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 end 50 else 51 # D. normal update 52 case params[:action] 53 when 'edit' 54 page.replace params[:dom_id], :file => fullpath_from_template_url + "_form.erb" 55 page << "$('#{params[:dom_id]}_form_t').focusFirstElement();" 56 when 'create' 57 pos = params[:position] || :before 58 ref = params[:reference] || "#{params[:dom_id]}_add" 59 page.insert_html pos.to_sym, ref, :file => fullpath_from_template_url + ".erb" 60 instance_variable_set("@#{base_class.to_s.underscore}", obj.clone) 61 page.replace "#{params[:dom_id]}_form", :file => fullpath_from_template_url + "_form.erb" 62 if params[:done] 63 page << params[:done] 64 else 65 page.toggle "#{params[:dom_id]}_form", "#{params[:dom_id]}_add" 66 end 67 when 'update' 68 page.replace params[:dom_id], :file => fullpath_from_template_url + ".erb" 69 when 'destroy' 70 page.visual_effect :highlight, params[:dom_id], :duration => 0.3 71 page.visual_effect :fade, params[:dom_id], :duration => 0.3 72 else 73 page.replace params[:dom_id], :file => fullpath_from_template_url + ".erb" 74 end 75 end 76 end 7 77 8 78 # translation of static text using gettext … … 74 144 res = "<a href='#{url}' onclick=\"new Ajax.Request('#{url}', {asynchronous:true, evalScripts:true, method:'#{options[:method] || 'get'}'}); return false;\"" 75 145 html_options.each do |k,v| 76 next unless [:class, :id, :style ].include?(k)146 next unless [:class, :id, :style, :rel, :onclick].include?(k) 77 147 res << " #{k}='#{v}'" 78 148 end trunk/app/views/data_entries/create.rjs
r1069 r1082 1 if @data_entry.new_record? 2 page.replace "#{params[:dom_id]}_form", :file => fullpath_from_template_url + "_form.erb" 3 elsif params[:upd_id] 4 page.replace "#{params[:upd_id]}_#{@node.zip}", :file => fullpath_from_template_url(params[:upd_url]) + ".erb" 5 else 6 pos = params[:position] || :before 7 ref = params[:reference] || "#{params[:dom_id]}_add" 8 page.insert_html pos.to_sym, ref, :file => fullpath_from_template_url + ".erb" 9 @data_entry = @data_entry.clone 10 page.replace "#{params[:dom_id]}_form", :file => fullpath_from_template_url + "_form.erb" 11 if params[:done] 12 page << params[:done] 13 else 14 page.toggle "#{params[:dom_id]}_form", "#{params[:dom_id]}_add" 15 end 16 end 1 update_page_content(page, @data_entry) trunk/app/views/data_entries/destroy.rjs
r1069 r1082 1 if @errors || !@data_entry.errors.empty? 2 # FIXME 3 else 4 page.visual_effect :highlight, "#{params[:dom_id]}_#{@data_entry.zip}", :duration => 0.3 5 page.visual_effect :fade, "#{params[:dom_id]}_#{@data_entry.zip}", :duration => 0.3 6 7 if params[:upd_url] 8 page.replace "#{params[:dom_id]}_#{@node.zip}", :file => fullpath_from_template_url(params[:upd_url]) + ".erb" 9 end 10 end 1 update_page_content(page, @data_entry) trunk/app/views/data_entries/edit.rjs
r1067 r1082 1 page.replace "#{params[:dom_id]}_#{@data_entry.zip}", :file => fullpath_from_template_url + "_form.erb" 2 page << "$('#{params[:dom_id]}_form_t').focusFirstElement();" 1 update_page_content(page, @data_entry) trunk/app/views/data_entries/show.rjs
r1069 r1082 1 page.replace "#{params[:dom_id]}_#{@data_entry.zip}", :file => fullpath_from_template_url + ".erb" 1 update_page_content(page, @data_entry) trunk/app/views/data_entries/update.rjs
r1069 r1082 1 if params[:upd_id] 2 page.replace "#{params[:upd_id]}_#{@node.zip}", :file => fullpath_from_template_url(params[:upd_url]) + ".erb" 3 else 4 page.replace "#{params[:dom_id]}_#{@data_entry.zip}", :file => fullpath_from_template_url + ".erb" 5 end 1 update_page_content(page, @data_entry) trunk/app/views/links/destroy.rjs
r1067 r1082 1 1 if params[:dom_id] 2 # zafu remove dom_id 3 if @errors || !@node.errors.empty? 4 # FIXME 5 else 6 page.visual_effect :highlight, "#{params[:dom_id]}_#{@node.zip}", :duration => 0.3 7 page.visual_effect :fade, "#{params[:dom_id]}_#{@node.zip}", :duration => 0.3 8 end 2 update_page_content(page, @node) 9 3 else 10 4 if @errors || !@node.errors.empty? trunk/app/views/nodes/_edit_attribute.rhtml
r918 r1082 1 1 <% if params[:zazen] == 'true' -%> 2 <% remote_form_for(:node, @node, :url => node_path(@node[:zip]), :method => :put) do |f| -%> 3 <input type='hidden' class='hidden' name='identifier' value='<%= params[:identifier] %>'/> 4 <input type='hidden' class='hidden' name='zazen' value='true'/> 5 <%= f.text_area(params[:attribute], :cols => nil, :rows => nil, :class=>'ajax_edit') %> 6 <input type='submit' text='<%= _('validate') %>'/> 2 <% remote_form_for(:node, @node, :url => node_path(@node[:zip]), :html => {:method => :put, :class => 'ajax_edit'}) do |f| -%> 3 <div class='hidden'> 4 <input type='hidden' class='hidden' name='dom_id' value='<%= params[:dom_id] %>'/> 5 <input type='hidden' class='hidden' name='zazen' value='true'/> 6 <% if params[:publish] == 'true' -%><input type='hidden' name='node[v_status]' value='<%= Zena::Status[:pub] %>'/><% end -%> 7 </div> 8 <div class='wrapper'> 9 <%= f.text_area(params[:attribute], :cols => nil, :rows => nil, :class=>'ajax_edit') %> 10 <input type='submit' text='<%= _('validate') %>'/> 11 </div> 7 12 <% end -%> 8 <% else -%> 9 <% remote_form_for(:node, @node, :url => node_path(@node[:zip]), :method => :put) do |f| -%> 10 <input type='hidden' class='hidden' name='identifier' value='<%= params[:identifier] %>'/> 11 <%= f.text_field(params[:attribute], :class=>'ajax_edit') %> 12 <% end -%> 13 <% else 14 value = Node.zafu_attribute(@node, params[:attribute]) -%> 15 <%= form_remote_tag(:url => node_path(@node[:zip]), :method => :put, :html => {:class => 'ajax_edit'}) %> 16 <div class='hidden'> 17 <input type='hidden' name='dom_id' value='<%= params[:dom_id] %>'/> 18 <% if params[:publish] == 'true' -%><input type='hidden' name='node[v_status]' value='<%= Zena::Status[:pub] %>'/><% end -%> 19 </div> 20 <div class='wrapper'><input type='text' id='<%= params[:dom_id] %>_' name='node[<%= params[:attribute] %>]' value='<%= value %>' size='<%= value.size %>'/></div> 21 </form> 13 22 <% end -%> trunk/app/views/nodes/drop.rjs
r1067 r1082 1 page.replace_html params[:dom_id], :file => fullpath_from_template_url + ".erb" 2 if @errors 3 page.insert_html :top, params[:dom_id], :inline => render_errors 4 end 1 update_page_content(page, @node) trunk/app/views/nodes/edit.rjs
r1067 r1082 1 1 if params[:attribute] 2 page.replace_html params[: identifier], :partial => 'edit_attribute'3 page << "$(' node_#{params[:attribute]}').focus();"4 page << "$(' node_#{params[:attribute]}').select();"2 page.replace_html params[:dom_id], :partial => 'edit_attribute' 3 page << "$('#{params[:dom_id]}_').focus();" 4 page << "$('#{params[:dom_id]}_').select();" 5 5 else 6 page.replace "#{params[:dom_id]}_#{@node.zip}", :file => fullpath_from_template_url + "_form.erb" 7 page << "$('#{params[:dom_id]}_form_t').focusFirstElement();" 6 update_page_content(page, @node) 8 7 end trunk/app/views/nodes/show.rjs
r1067 r1082 1 page.replace "#{params[:dom_id]}_#{@node.zip}", :file => fullpath_from_template_url + ".erb" 1 update_page_content(page, @node) trunk/app/views/nodes/update.rjs
r1067 r1082 1 if @errors || !@node.errors.empty? 2 if @update == 'zafu' 3 page.replace "#{params[:dom_id]}_#{@node.new_record? ? 'form' : @node.zip}", :file => fullpath_from_template_url + "_form.erb" 1 if params[:dom_id] && !params[:t_url] 2 attribute = params[:node].keys[0] 3 if params[:zazen] == 'true' 4 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]}&zazen=true", :method => :get) + "</span>" + zazen(params[:node][attribute]) 4 5 else 5 # TODO: is this used ? how ? when ? 6 page.replace_html "#{@update}_errors", :inline => @errors ? render_errors : error_messages_for(@node) 6 page.replace_html params[:dom_id], link_to_remote(params[:node][attribute], :url => edit_node_path(@node[:zip]) + "?attribute=#{attribute}&dom_id=#{params[:dom_id]}", :method => :get) 7 7 end 8 else 9 if @update == 'zafu' 10 page.replace "#{params[:dom_id]}_#{@node.zip}", :file => fullpath_from_template_url + ".erb" 11 elsif @update == 'attribute' 12 attribute = params[:node].keys[0] 13 if params[:zazen] == 'true' 14 page.replace_html params[:identifier], "<span class='zazen_edit'>" + link_to_remote(_('edit'), :url => edit_node_path(@node[:zip]) + "?attribute=#{attribute}&identifier=#{CGI.escape(params[:identifier])}&zazen=true", :method => :get) + "</span>" + zazen(params[:node][attribute]) 8 elsif upd = params[:drive] 9 if ['parent', 'dates', 'groups', 'links'].include?(upd) 10 if @errors || !@node.errors.empty? 11 page.replace_html "#{upd}_errors", :inline => @errors ? render_errors : error_messages_for(@node) 15 12 else 16 page.replace_html params[:identifier], link_to_remote(params[:node][attribute], :url => edit_node_path(@node[:zip]) + "?attribute=#{attribute}&identifier=#{CGI.escape(params[:identifier])}", :method => :get) 13 page.replace upd, :partial => upd 14 page.replace 'messages', :inline => flash_messages 15 page.visual_effect :highlight, upd 16 page.visual_effect :fade, 'notice', :duration => 3 17 17 end 18 elsif @update == 'edit' 18 else 19 flash['error'] = "unknown 'drive' parameter #{upd.inspect}" 19 20 page.replace 'messages', :inline => flash_messages 20 page << "opener.location.href = '/redirect?url=' + escape(opener.location.pathname);" # Safari bug21 page << "self.close();"22 else23 page.replace @update, :partial => @update24 page.replace 'messages', :inline => flash_messages25 page.visual_effect :highlight, @update26 page.visual_effect :fade, 'notice', :duration => 327 21 end 22 else 23 update_page_content(page, @node) 28 24 end trunk/lib/parser/lib/parser.rb
r1055 r1082 139 139 140 140 def render(context={}) 141 return '' if context["no_#{@method}".to_sym]142 141 if @name 143 142 # we pass the name as 'context' in the children tags … … 513 512 only = acontext[:only] 514 513 new_context = @context.merge(acontext) 514 515 if ignore = acontext[:ignore] 516 ignore = (@context[:ignore] || []) + (acontext[:ignore] || []) 517 ignore.uniq! 518 if acontext[:no_ignore] 519 ignore = ignore - acontext[:no_ignore] 520 end 521 new_context[:ignore] = ignore 522 end 523 515 524 blocks.each do |b| 516 525 if b.kind_of?(String) 517 if !only || only.include?(:string)526 if (!only || only.include?(:string)) && (!ignore || !ignore.include?(:string)) 518 527 res << b 519 528 end 520 elsif !only || only.include?(b.method)529 elsif (!only || only.include?(b.method)) && (!ignore || !ignore.include?(b.method)) 521 530 res << b.render(new_context.dup) 522 531 if pass = b.pass trunk/lib/parser/lib/rules/zena.rb
r1081 r1082 361 361 if @params[:edit] == 'true' && !['url','path'].include?(attribute) 362 362 name = unique_name + '_' + attribute 363 "<% if #{node}.can_write? -%><span class='show_edit' id='#{ name}.#{erb_node_id}'>#{actions}<%= link_to_remote(#{attribute_method}, :url => edit_node_path(#{node_id}) + \"?attribute=#{attribute}&identifier=#{CGI.escape(name)}.\#{#{node_id}}\", :method => :get) %></span><% else -%>#{actions}<%= #{attribute_method} %><% end -%>"363 "<% if #{node}.can_write? -%><span class='show_edit' id='#{erb_dom_id("#{attribute}_")}'>#{actions}<%= link_to_remote(#{attribute_method}, :url => edit_node_path(#{node_id}) + \"?attribute=#{attribute}&dom_id=#{dom_id("#{attribute}_")}#{@params[:publish] == 'true' ? '&publish=true' : ''}\", :method => :get) %></span><% else -%>#{actions}<%= #{attribute_method} %><% end -%>" 364 364 else 365 365 "#{actions}<%= #{attribute_method} %>" … … 389 389 390 390 if @params[:edit] == 'true' && !['url','path'].include?(attribute) 391 name = unique_name + '_' + attribute392 391 edit_text = _('edit') 393 @html_tag_params[:id] = ["'#{name}.#{erb_node_id}'"]394 res = "<% if #{node}.can_write? -%><span class='zazen_edit'><%= link_to_remote(#{edit_text.inspect}, :url => edit_node_path(#{node_id}) + \"?attribute=#{attribute}& identifier=#{CGI.escape(name)}.\#{#{node_id}}&zazen=true\", :method => :get) %></span><% end -%>#{res}"392 @html_tag_params[:id] = erb_dom_id("#{attribute}_") 393 res = "<% if #{node}.can_write? -%><span class='zazen_edit'><%= link_to_remote(#{edit_text.inspect}, :url => edit_node_path(#{node_id}) + \"?attribute=#{attribute}&dom_id=#{dom_id("#{attribute}_")}#{@params[:publish] == 'true' ? '&publish=true' : ''}&zazen=true\", :method => :get) %></span><% end -%>#{res}" 395 394 else 396 395 res … … 432 431 end 433 432 @html_tag_done = false 434 @html_tag_params.merge!(:id=> "#{@context[:erb_dom_id]}_#{erb_node_id}")433 @html_tag_params.merge!(:id=>erb_dom_id) 435 434 out expand_with 436 else 437 @context[:dom_id] = "#{self.dom_id}_\#{#{node_id}}" 438 @context[:erb_dom_id] = "#{self.dom_id}_#{erb_node_id}" 439 template_url = @context[:template_url] = get_template_url 440 form_url = template_url + '_form' 441 442 @html_tag ||= 'div' 443 444 unless @context[:make_form] 445 # STORE TEMPLATE ======== 446 template_node = "@#{base_class.to_s.underscore}" 447 erb_dom_id = "<%= params[:dom_id] %>" 448 dom_id = "\#{params[:dom_id]}" 449 context_bak = @context.dup # avoid side effects when rendering the same block 450 template = expand_block(self, :block=>self, :list=>false, :node=>template_node, :template_url=>template_url, :dom_id => dom_id, :erb_dom_id => erb_dom_id, :form=>false, :no_form => true) 451 @context = context_bak 452 @result = '' 453 out helper.save_erb_to_url(template, template_url) 435 if @method == 'drop' && !@context[:make_form] 436 out drop_javascript 437 end 438 else 439 440 if parent.method == 'each' && @method == parent.single_child_method 441 # use parent as block 442 # FIXME: will not work with block as distant target... 443 # do nothing 444 else 445 @html_tag ||= 'div' 446 new_dom_scope 454 447 455 # STORE FORM ============ 456 if descendant('edit') 457 if form = descendant('form') 458 # USE BLOCK FORM ======== 459 form_text = expand_block(form, @context.merge(:node => template_node, :template_url=>template_url, :dom_id => dom_id, :erb_dom_id => erb_dom_id)) 460 else 461 # MAKE A FORM FROM BLOCK ======== 462 form = self.dup 463 form.method = 'form' 464 form_text = expand_block(form, @context.merge(:make_form => true, :list => false, :node => template_node, :template_url=>template_url, :dom_id => dom_id, :erb_dom_id => erb_dom_id)) 448 unless @context[:make_form] 449 # STORE TEMPLATE ======== 450 451 context_bak = @context.dup # avoid side effects when rendering the same block 452 template = expand_block(self, :block=>self, :list=>false, :saved_template=>true, :ignore =>['form']) 453 @context = context_bak 454 @result = '' 455 out helper.save_erb_to_url(template, template_url) 456 457 # STORE FORM ============ 458 if edit = descendant('edit') 459 publish_after_save = (edit.params[:publish] == 'true') 460 if form = descendant('form') 461 # USE BLOCK FORM ======== 462 form_text = expand_block(form, :saved_template=>true, :publish_after_save => publish_after_save) 463 else 464 # MAKE A FORM FROM BLOCK ======== 465 form = self.dup 466 form.method = 'form' 467 form_text = expand_block(form, :make_form => true, :list => false, :saved_template => true, :publish_after_save => publish_after_save) 468 end 469 out helper.save_erb_to_url(form_text, form_url) 465 470 end 466 out helper.save_erb_to_url(form_text, form_url) 467 end 468 end 469 470 @html_tag_done = false 471 @html_tag_params.merge!(:id=>"#{@context[:erb_dom_id]}_#{erb_node_id}") 472 # RENDER 473 out expand_with(:template_url => template_url) 471 end 472 473 # RENDER 474 @html_tag_done = false 475 @html_tag_params.merge!(:id=>erb_dom_id) 476 end 477 478 out expand_with 479 if @method == 'drop' && !@context[:make_form] 480 out drop_javascript 481 end 474 482 end 475 483 end … … 477 485 # TODO: test 478 486 def r_filter 479 return parser_error("missing 'block' in same parent") unless parent && block = parent.descendant('block') 480 dom_id = "#{block.dom_id(@context)}_\#{#{node_id}}" 481 erb_dom_id = "#{block.dom_id(@context)}_#{erb_node_id}" 482 template_url = block.get_template_url(@context) 483 out "<%= form_remote_tag(:url => zafu_node_path(#{node_id}), :method => :get, :html => {:id => \"#{dom_id}_f\"}) %><div class='hidden'><input type='hidden' name='template_url' value='#{template_url}'/><input type='hidden' name='dom_id' value='#{erb_dom_id}'/></div><div class='wrapper'>" 487 if upd = @params[:update] 488 return unless block = find_target(upd) 489 else 490 return parser_error("missing 'block' in same parent") unless parent && block = parent.descendant('block') 491 end 492 493 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}'/></div><div class='wrapper'>" 484 494 if @blocks == [] 485 495 out "<input type='text' name='#{@params[:key] || 'f'}' value='<%= params[#{(@params[:key] || 'f').to_sym.inspect}] %>'/>" … … 505 515 states = ((@params[:states] || 'todo, done') + ' ').split(',').map(&:strip) 506 516 507 action = "?template_url=#{CGI.escape(block.get_template_url(@context))}" 508 action << "&node[v_status]=#{Zena::Status[:pub]}" if @params[:publish] 509 action << "&dom_id=#{@context[:dom_id]}" 510 action << "&node[#{@params[:attr]}]=\#{#{states.inspect}[ ((#{states.inspect}.index(#{node_attribute(@params[:attr])}.to_s) || 0)+1) % #{states.size}]}" 511 512 out "<% if #{node}.can_write? %>" 513 out "<%= tag_to_remote({:url => node_path(#{node_id}) + \"#{action}\", :method => :put}) %>" 514 if @blocks != [] 515 inner = expand_with 516 else 517 inner = get_text_for_erb 518 end 519 out inner 520 out "</a>" 521 out "<% else -%>" 522 out inner 523 out "<% end -%>" 517 url_params = "node[#{@params[:attr]}]=\#{#{states.inspect}[ ((#{states.inspect}.index(#{node_attribute(@params[:attr])}.to_s) || 0)+1) % #{states.size}]}" 518 519 out link_to_update(block, :url_params => url_params, :method => :put, :html_params => get_html_params(@params)) 524 520 end 525 521 … … 728 724 def r_edit 729 725 text = get_text_for_erb 730 if template_url = @context[:template_url]726 if @context[:dom_prefix] 731 727 # ajax 732 728 if @context[:in_form] 733 734 729 # cancel button 735 730 @context[:form_cancel] || '' 736 731 else 737 732 # edit button 738 739 action = "?template_url=#{CGI.escape(template_url)}"740 action << "&dom_id=#{@context[:dom_id]}"741 action << "&link_id=\#{#{node}.link_id}" if @context[:need_link_id]742 733 743 if block = ancestor('block')744 action << "&upd_id=#{block.context[:dom_id]}"745 end746 734 # TODO: show 'reply' instead of 'edit' in comments if visitor != author 747 out "<% if #{node}.can_write? -%>" 748 out "<%= tag_to_remote({:url => edit_#{base_class.to_s.underscore}_path(#{node_id}) + \"#{action}\", :method => :get}#{params_to_erb(@params)}) %>" 749 if @blocks != [] 750 out expand_with 751 else 752 out get_text_for_erb || _('edit') 753 end 754 out "</a><% end -%>" 735 out link_to_update(self, :url => "\#{edit_#{base_class.to_s.underscore}_path(#{node_id})}", :html_params => get_html_params(@params), :method => :get, :else => :void) 755 736 end 756 737 else … … 857 838 set_fields << "#{var_name}[#{tag.params[:name]}]" 858 839 end 859 if template_url = @context[:template_url]840 if @context[:dom_prefix] 860 841 # ajax 861 862 863 842 if @context[:in_add] 843 # inline form used to create new elements: set values to '' and 'parent_id' from context 844 id_hash = {:id => "#{erb_dom_id}_form", :style => "display:none;"} 864 845 865 if block = ancestor('block')866 hidden_fields['upd_url'] = block.context[:template_url]867 hidden_fields['upd_id'] = block.context[:erb_dom_id]868 end869 870 erb_dom_id = @context[:erb_dom_id]871 dom_id = @context[:dom_id]872 873 # inline form used to create new elements: set values to '' and 'parent_id' from context874 @html_tag_params.merge!(:id=>"#{erb_dom_id}_form", :style=>"display:none;")875 846 cancel = "<p class='btn_x'><a href='#' onclick='[\"#{erb_dom_id}_add\", \"#{erb_dom_id}_form\"].each(Element.toggle);return false;'>#{_('btn_x')}</a></p>\n" 876 847 form = "<%= form_remote_tag(:url => #{base_class.to_s.underscore.pluralize}_path, :html => {:id => \"#{dom_id}_form_t\"}) %>\n" 877 848 else 878 erb_dom_id = "<%= params[:dom_id] %>" 879 dom_id = "\#{params[:dom_id]}" 849 # saved form 880 850 881 if block = ancestor('block') 882 hidden_fields['upd_url'] = block.context[:template_url] 883 hidden_fields['upd_id'] = "<%= params[:upd_id] %>" 884 end 851 id_hash = {:id => "#{erb_dom_id}"} 885 852 886 # saved form used to edit/create: set values and 'parent_id' from @node887 @html_tag_params.merge!(:id=>"#{erb_dom_id}_<%= #{node}.new_record? ? 'form' : #{node}.zip %>") unless @method == 'block' # called from r_block888 # new_record? = edit/create failed, rendering form with errors889 # else = edit890 # FIXME: remove '/zafu?' when nodes_controller's method 'zafu' is no longer needed.891 853 cancel = <<-END_TXT 892 854 <% if #{node}.new_record? -%> 893 <p class='btn_x'><a href='#' onclick='[\" #{erb_dom_id}_add\", \"#{erb_dom_id}_form\"].each(Element.toggle);return false;'>#{_('btn_x')}</a></p>855 <p class='btn_x'><a href='#' onclick='[\"<%= params[:dom_id] %>_add\", \"<%= params[:dom_id] %>_form\"].each(Element.toggle);return false;'>#{_('btn_x')}</a></p> 894 856 <% else -%> 895 <p class='btn_x'><%= link_to_remote(#{_('btn_x').inspect}, :url => #{base_class.to_s.underscore}_path(#{node_id}) + \"/zafu?t emplate_url=#{CGI.escape(template_url)}&dom_id=\#{params[:dom_id]}#{@context[:need_link_id] ? "&link_id=\#{#{node}.link_id}" : ''}\", :method => :get) %></p>857 <p class='btn_x'><%= link_to_remote(#{_('btn_x').inspect}, :url => #{base_class.to_s.underscore}_path(#{node_id}) + \"/zafu?t_url=#{CGI.escape(template_url)}&dom_id=\#{params[:dom_id]}#{@context[:need_link_id] ? "&link_id=\#{#{node}.link_id}" : ''}\", :method => :get) %></p> 896 858 <% end -%> 897 859 END_TXT 898 860 form =<<-END_TXT 899 861 <% if #{node}.new_record? -%> 900 <%= form_remote_tag(:url => #{base_class.to_s.underscore.pluralize}_path, :html => {:id => \" #{dom_id}_form_t\"}) %>862 <%= form_remote_tag(:url => #{base_class.to_s.underscore.pluralize}_path, :html => {:id => \"\#{params[:dom_id]}_form_t\"}) %> 901 863 <% else -%> 902 864 <%= form_remote_tag(:url => #{base_class.to_s.underscore}_path(#{node_id}), :method => :put, :html => {:id => \"#{dom_id}_form_t\"}) %> … … 909 871 910 872 hidden_fields['link_id'] = "<%= #{node}.link_id %>" if @context[:need_link_id] 911 hidden_fields['template_url'] = template_url 912 hidden_fields['dom_id'] = erb_dom_id 873 874 if block = ancestor('block') 875 # set update template url 876 hidden_fields['u_url'] = block.template_url 877 hidden_fields['udom_id'] = block.erb_dom_id 878 end 879 880 hidden_fields['t_url'] = template_url 881 882 if @context[:saved_template] 883 hidden_fields['dom_id'] = "<%= params[:dom_id] %>" 884 else 885 hidden_fields['dom_id'] = erb_dom_id 886 end 887 913 888 914 889 if node_kind_of?(Node) … … 939 914 end 940 915 if params[:done] == 'focus' 941 if @params[:focus] 942 hidden_fields['done'] = "$(\"#{erb_dom_id}_#{@params[:focus]}\").focus();" 916 erb_dom_id = @context[:saved_template] ? '<%= params[:dom_id] %>' : self.erb_dom_id 917 if params[:focus] 918 hidden_fields['done'] = "'$(\"#{erb_dom_id}_#{@params[:focus]}\").focus();'" 943 919 else 944 hidden_fields['done'] = " $(\"#{erb_dom_id}_form_t\").focusFirstElement();"920 hidden_fields['done'] = "'$(\"#{erb_dom_id}_form_t\").focusFirstElement();'" 945 921 end 946 922 elsif params[:done] … … 950 926 else 951 927 # no ajax 928 id_hash = {} 952 929 # FIXME 953 930 cancel = "" # link to normal node ? 954 931 form = "<form method='post' action='/nodes/#{erb_node_id}'><div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div>" 955 932 end 956 hidden_fields['node[klass]'] = @params[:klass] || @context[:klass] || 'Page' 933 hidden_fields['node[klass]'] = @params[:klass] || @context[:klass] || 'Page' if node_kind_of?(Node) 957 934 hidden_fields['node[v_status]'] = Zena::Status[:pub] if @context[:publish_after_save] || (@params[:publish] == 'true') 958 935 … … 960 937 hidden_fields.each do |k,v| 961 938 next if set_fields.include?(k) 962 v = " \"#{v}\"" unless v.kind_of?(String) && ['"', "'"].include?(v[0..0])939 v = "'#{v}'" unless v.kind_of?(String) && ['"', "'"].include?(v[0..0]) 963 940 form << "<input type='hidden' name='#{k}' value=#{v}/>\n" 964 941 end … … 987 964 end 988 965 @blocks = blocks_bak 966 @html_tag_done = false 967 @html_tag_params.merge!(id_hash) 989 968 out render_html_tag(res) 990 969 end … … 1045 1024 out "<% if #{node}.can_write? -%>" 1046 1025 end 1026 1047 1027 unless descendant('add_btn') 1048 1028 # add a descendant between self and blocks. … … 1054 1034 end 1055 1035 1056 if @context[:form] && @context[: template_url]1036 if @context[:form] && @context[:dom_prefix] 1057 1037 # ajax add 1058 1059 erb_dom_id = @context[:erb_dom_id]1060 1038 1061 1039 @html_tag_params.merge!(:id => "#{erb_dom_id}_add") … … 1077 1055 out "<% if #{var}_new = #{node_class}.new -%>" 1078 1056 end 1057 1079 1058 if @context[:form].method == 'form' 1080 out expand_block(@context[:form], :in_add => true, :no_ form => false, :add=>self, :node => "#{var}_new", :parent_node => node, :klass => klass, :publish_after_save => (@params[:publish] == 'true'))1059 out expand_block(@context[:form], :in_add => true, :no_ignore => ['form'], :add=>self, :node => "#{var}_new", :parent_node => node, :klass => klass, :publish_after_save => (@params[:publish] == 'true')) 1081 1060 else 1082 1061 # build form from 'each' 1083 out expand_block(@context[:form], :in_add => true, :no_ form => false, :add=>self, :make_form => true, :node => "#{var}_new", :parent_node => node, :klass => klass, :publish_after_save => (@params[:publish] == 'true'))1062 out expand_block(@context[:form], :in_add => true, :no_ignore => ['form'], :add=>self, :make_form => true, :node => "#{var}_new", :parent_node => node, :klass => klass, :publish_after_save => (@params[:publish] == 'true')) 1084 1063 end 1085 1064 out "<% end -%>" … … 1123 1102 # end 1124 1103 #end 1104 1125 1105 def r_drop 1126 hover = @params.delete(:hover) 1127 target = @params.delete(:target) 1128 1106 r_block 1107 end 1108 1109 def drop_javascript 1110 hover = @params[:hover] 1111 change = @params[:change] 1112 1129 1113 if role = @params[:set] || @params[:add] 1130 action = "node[#{role}_id]=[id]"1131 else 1132 actions = []1114 url_params = ["node[#{role}_id]=[id]"] 1115 else 1116 url_params = [] 1133 1117 # set='icon_for=[id], v_status='50', v_title='[v_title]' 1134 1118 @params.each do |k, v| 1119 next if [:hover, :change].include?(k) 1135 1120 value, static = parse_attributes_in_value(v, :erb => false, :skip_node_attributes => true) 1136 if k =~ /\Acomment_(\w+)/ 1137 actions << "comment[#{$1}]=#{CGI.escape(value)}" 1138 else 1139 actions << "node[#{k}]=#{CGI.escape(value)}" 1140 end 1141 end 1142 return parser_error("missing parameters to set values") if actions == [] 1143 action = actions.join('&') 1144 end 1145 1146 @html_tag ||= 'div' 1147 template_url = get_template_url 1148 @html_tag_params ||= {} 1149 dom_id = parent.method == 'each' ? @context[:erb_dom_id] : unique_name 1150 @html_tag_params[:id] = "#{dom_id}_#{erb_node_id}" 1151 @html_tag_params[:class] ||= 'drop' 1152 1153 action << "&target=receiver" if target == 'receiver' 1154 action << "&template_url=#{CGI.escape(template_url)}" 1155 action << "&dom_id=#{@html_tag_params[:id]}" 1156 out render_html_tag(expand_with) 1157 # out "<%= drop_receiving_element('#{@html_tag_params[:id]}', :url => drop_node_path(#{node}.zip) + #{action.inspect}, :method => :put, :revert=>true) %>" 1158 # BUG WITH &. USING RAW JS BELOW. 1159 out "<script type='text/javascript'> 1121 url_params << "node[#{k}]=#{CGI.escape(value)}" 1122 end 1123 return parser_error("missing parameters to set values") if url_params == [] 1124 end 1125 1126 url_params << "&change=receiver" if change == 'receiver' 1127 url_params << "&t_url=#{CGI.escape(template_url)}" 1128 url_params << "&dom_id=#{erb_dom_id}" 1129 1130 "<script type='text/javascript'> 1160 1131 //<![CDATA[ 1161 Droppables.add('#{ @html_tag_params[:id]}', {hoverclass:'#{hover || 'drop_hover'}', onDrop:function(element){new Ajax.Request('/nodes/#{erb_node_id}/drop?#{action}', {asynchronous:true, evalScripts:true, method:'put', parameters:'drop=' + encodeURIComponent(element.id)})}})1132 Droppables.add('#{erb_dom_id}', {hoverclass:'#{hover || 'drop_hover'}', onDrop:function(element){new Ajax.Request('/nodes/#{erb_node_id}/drop?#{url_params.join('&')}', {asynchronous:true, evalScripts:true, method:'put', parameters:'drop=' + encodeURIComponent(element.id)})}}) 1162 1133 //]]> 1163 1134 </script>" 1164 1165 # TEMPLATE ========1166 template_node = "@#{base_class.to_s.underscore}"1167 template = expand_with(:node=>template_node, :template_url=>template_url)1168 out helper.save_erb_to_url(template, template_url)1169 1135 end 1170 1136 … … 1173 1139 @html_tag_params ||= {} 1174 1140 dom_id = unique_name 1175 @html_tag_params[:id] = "#{dom_id}_#{erb_node_id}"1141 @html_tag_params[:id] = erb_dom_id 1176 1142 case @params[:revert] 1177 1143 when 'move' … … 1192 1158 1193 1159 def r_unlink 1194 #dom_id = "#{@context[:dom_id]}.\#{#{node_id}}" 1195 1196 if block = ancestor('block') 1197 upd_url = "&upd_url=#{CGI.escape(block.context[:template_url])}" 1198 erb_dom_id = block.context[:erb_dom_id] 1199 dom_id = block.context[:dom_id] 1200 else 1201 template_url = "" 1202 erb_dom_id = @context[:erb_dom_id] 1203 dom_id = @context[:dom_id] 1160 opts = {} 1161 1162 unless target = ancestor('block') 1163 target = self 1204 1164 end 1205 1165 1206 1166 if node_kind_of?(Node) 1207 out "<% if #{node}.link_id -%>" 1208
