Просмотр исходного кода

Adds a helper for preview links.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10031 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/2.1.0
Jean-Philippe Lang 12 лет назад
Родитель
Сommit
ff68fff80e

+ 8
- 0
app/helpers/application_helper.rb Просмотреть файл

@@ -995,6 +995,14 @@ module ApplicationHelper
link_to l(:button_delete), url, options
end

def preview_link(url, form, target='preview', options={})
content_tag 'a', l(:label_preview), {
:href => "#",
:onclick => %|submitPreview("#{escape_javascript url_for(url)}", "#{escape_javascript form}", "#{escape_javascript target}"); return false;|,
:accesskey => accesskey(:preview)
}.merge(options)
end

def back_url_hidden_field_tag
back_url = params[:back_url] || request.env['HTTP_REFERER']
back_url = CGI.unescape(back_url.to_s)

+ 1
- 7
app/views/boards/show.html.erb Просмотреть файл

@@ -14,13 +14,7 @@
<%= form_for @message, :url => {:controller => 'messages', :action => 'new', :board_id => @board}, :html => {:multipart => true, :id => 'message-form'} do |f| %>
<%= render :partial => 'messages/form', :locals => {:f => f} %>
<p><%= submit_tag l(:button_create) %>
<%= link_to_remote l(:label_preview),
{ :url => { :controller => 'messages', :action => 'preview', :board_id => @board },
:method => 'post',
:update => 'preview',
:with => "Form.serialize('message-form')",
:complete => "Element.scrollTo('preview')"
}, :accesskey => accesskey(:preview) %> |
<%= preview_link({:controller => 'messages', :action => 'preview', :board_id => @board}, 'message-form') %> |
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-message")' %></p>
<% end %>
<div id="preview" class="wiki"></div>

+ 1
- 7
app/views/issues/_edit.html.erb Просмотреть файл

@@ -38,13 +38,7 @@
<%= f.hidden_field :lock_version %>
<%= hidden_field_tag 'last_journal_id', params[:last_journal_id] || @issue.last_journal_id %>
<%= submit_tag l(:button_submit) %>
<%= link_to_remote l(:label_preview),
{ :url => preview_edit_issue_path(:project_id => @project, :id => @issue),
:method => 'post',
:update => 'preview',
:with => 'Form.serialize("issue-form")',
:complete => "Element.scrollTo('preview')"
}, :accesskey => accesskey(:preview) %>
<%= preview_link preview_edit_issue_path(:project_id => @project, :id => @issue), 'issue-form' %>
<% end %>

<div id="preview" class="wiki"></div>

+ 1
- 7
app/views/issues/new.html.erb Просмотреть файл

@@ -36,13 +36,7 @@

<%= submit_tag l(:button_create) %>
<%= submit_tag l(:button_create_and_continue), :name => 'continue' %>
<%= link_to_remote l(:label_preview),
{ :url => preview_new_issue_path(:project_id => @project),
:method => 'post',
:update => 'preview',
:with => "Form.serialize('issue-form')",
:complete => "Element.scrollTo('preview')"
}, :accesskey => accesskey(:preview) %>
<%= preview_link preview_new_issue_path(:project_id => @project), 'issue-form' %>

<%= javascript_tag "Form.Element.focus('issue_subject');" %>
<% end %>

+ 3
- 8
app/views/journals/_notes_form.html.erb Просмотреть файл

@@ -6,14 +6,9 @@
:rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min) %>
<%= call_hook(:view_journals_notes_form_after_notes, { :journal => @journal}) %>
<p><%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
{ :url => preview_edit_issue_path(:project_id => @project, :id => @journal.issue),
:method => 'post',
:update => "journal_#{@journal.id}_preview",
:with => "Form.serialize('journal-#{@journal.id}-form')",
:complete => "Element.scrollTo('journal_#{@journal.id}_preview')"
}, :accesskey => accesskey(:preview) %>
|
<%= preview_link preview_edit_issue_path(:project_id => @project, :id => @journal.issue),
"journal-#{@journal.id}-form",
"journal_#{@journal.id}_preview" %> |
<%= link_to l(:button_cancel), '#', :onclick => "Element.remove('journal-#{@journal.id}-form'); " +
"Element.show('journal-#{@journal.id}-notes'); return false;" %></p>


+ 1
- 8
app/views/messages/edit.html.erb Просмотреть файл

@@ -12,14 +12,7 @@
<%= render :partial => 'form',
:locals => {:f => f, :replying => !@message.parent.nil?} %>
<%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
{ :url => { :controller => 'messages',
:action => 'preview', :board_id => @board, :id => @message },
:method => 'post',
:update => 'preview',
:with => "Form.serialize('message-form')",
:complete => "Element.scrollTo('preview')"
}, :accesskey => accesskey(:preview) %>
<%= preview_link({:controller => 'messages', :action => 'preview', :board_id => @board, :id => @message}, 'message-form') %>
<% end %>
<div id="preview" class="wiki"></div>


+ 1
- 7
app/views/messages/new.html.erb Просмотреть файл

@@ -3,13 +3,7 @@
<%= form_for @message, :url => {:action => 'new'}, :html => {:multipart => true, :id => 'message-form'} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<%= submit_tag l(:button_create) %>
<%= link_to_remote l(:label_preview),
{ :url => { :controller => 'messages', :action => 'preview', :board_id => @board },
:method => 'post',
:update => 'preview',
:with => "Form.serialize('message-form')",
:complete => "Element.scrollTo('preview')"
}, :accesskey => accesskey(:preview) %>
<%= preview_link({:controller => 'messages', :action => 'preview', :board_id => @board}, 'message-form') %>
<% end %>

<div id="preview" class="wiki"></div>

+ 1
- 7
app/views/messages/show.html.erb Просмотреть файл

@@ -75,13 +75,7 @@
<%= form_for @reply, :as => :reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true, :id => 'message-form'} do |f| %>
<%= render :partial => 'form', :locals => {:f => f, :replying => true} %>
<%= submit_tag l(:button_submit) %>
<%= link_to_remote l(:label_preview),
{ :url => { :controller => 'messages', :action => 'preview', :board_id => @board },
:method => 'post',
:update => 'preview',
:with => "Form.serialize('message-form')",
:complete => "Element.scrollTo('preview')"
}, :accesskey => accesskey(:preview) %>
<%= preview_link({:controller => 'messages', :action => 'preview', :board_id => @board}, 'message-form') %>
<% end %>
<div id="preview" class="wiki"></div>
</div>

+ 1
- 6
app/views/news/edit.html.erb Просмотреть файл

@@ -3,12 +3,7 @@
<%= labelled_form_for @news, :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
{ :url => preview_news_path(:project_id => @project),
:method => 'get',
:update => 'preview',
:with => "Form.serialize('news-form')"
}, :accesskey => accesskey(:preview) %>
<%= preview_link preview_news_path(:project_id => @project), 'news-form' %>
<% end %>
<div id="preview" class="wiki"></div>


+ 1
- 6
app/views/news/index.html.erb Просмотреть файл

@@ -11,12 +11,7 @@
:html => { :id => 'news-form', :multipart => true } do |f| %>
<%= render :partial => 'news/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= link_to_remote l(:label_preview),
{ :url => preview_news_path(:project_id => @project),
:method => 'get',
:update => 'preview',
:with => "Form.serialize('news-form')"
}, :accesskey => accesskey(:preview) %> |
<%= preview_link preview_news_path(:project_id => @project), 'news-form' %> |
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %>
<% end if @project %>
<div id="preview" class="wiki"></div>

+ 1
- 6
app/views/news/new.html.erb Просмотреть файл

@@ -4,11 +4,6 @@
:html => { :id => 'news-form', :multipart => true } do |f| %>
<%= render :partial => 'news/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= link_to_remote l(:label_preview),
{ :url => preview_news_path(:project_id => @project),
:method => 'get',
:update => 'preview',
:with => "Form.serialize('news-form')"
}, :accesskey => accesskey(:preview) %>
<%= preview_link preview_news_path(:project_id => @project), 'news-form' %>
<% end %>
<div id="preview" class="wiki"></div>

+ 1
- 6
app/views/news/show.html.erb Просмотреть файл

@@ -16,12 +16,7 @@
:html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
{ :url => preview_news_path(:project_id => @project),
:method => 'get',
:update => 'preview',
:with => "Form.serialize('news-form')"
}, :accesskey => accesskey(:preview) %> |
<%= preview_link preview_news_path(:project_id => @project), 'news-form' %> |
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("edit-news"); return false;' %>
<% end %>
<div id="preview" class="wiki"></div>

+ 1
- 8
app/views/wiki/edit.html.erb Просмотреть файл

@@ -33,14 +33,7 @@
</div>

<p><%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
{ :url => { :controller => 'wiki', :action => 'preview',
:project_id => @project, :id => @page.title },
:method => :post,
:update => 'preview',
:with => "Form.serialize('wiki_form')",
:complete => "Element.scrollTo('preview')"
}, :accesskey => accesskey(:preview) %></p>
<%= preview_link({:controller => 'wiki', :action => 'preview', :project_id => @project, :id => @page.title }, 'wiki_form') %></p>
<%= wikitoolbar_for 'content_text' %>
<% end %>


+ 10
- 0
public/javascripts/application.js Просмотреть файл

@@ -337,6 +337,16 @@ function hideModal(el) {
}
}

function submitPreview(url, form, target) {
new Ajax.Updater(target, url, {
asynchronous:true,
evalScripts:true,
method:'post',
onComplete:function(request){Element.scrollTo(target)},
parameters:Form.serialize(form)
});
}

function collapseScmEntry(id) {
var els = document.getElementsByClassName(id, 'browser');
for (var i = 0; i < els.length; i++) {

Загрузка…
Отмена
Сохранить