Resourcified documents.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8010 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -18,9 +18,9 @@
|
||||
class DocumentsController < ApplicationController
|
||||
default_search_scope :documents
|
||||
model_object Document
|
||||
before_filter :find_project_by_project_id, :only => [:index, :new]
|
||||
before_filter :find_model_object, :except => [:index, :new]
|
||||
before_filter :find_project_from_association, :except => [:index, :new]
|
||||
before_filter :find_project_by_project_id, :only => [:index, :new, :create]
|
||||
before_filter :find_model_object, :except => [:index, :new, :create]
|
||||
before_filter :find_project_from_association, :except => [:index, :new, :create]
|
||||
before_filter :authorize
|
||||
|
||||
helper :attachments
|
||||
@@ -48,24 +48,34 @@ class DocumentsController < ApplicationController
|
||||
|
||||
def new
|
||||
@document = @project.documents.build(params[:document])
|
||||
end
|
||||
|
||||
def create
|
||||
@document = @project.documents.build(params[:document])
|
||||
if request.post? and @document.save
|
||||
attachments = Attachment.attach_files(@document, params[:attachments])
|
||||
render_attachment_warning_if_needed(@document)
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :action => 'index', :project_id => @project
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@categories = DocumentCategory.active #TODO: use it in the views
|
||||
if request.post? and @document.update_attributes(params[:document])
|
||||
end
|
||||
|
||||
def update
|
||||
if request.put? and @document.update_attributes(params[:document])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'show', :id => @document
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@document.destroy
|
||||
@document.destroy if request.delete?
|
||||
redirect_to :controller => 'documents', :action => 'index', :project_id => @project
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<h4><%= link_to h(document.title), :controller => 'documents', :action => 'show', :id => document %></h4>
|
||||
<h4><%= link_to h(document.title), document_path(document) %></h4>
|
||||
<p><em><%= format_time(document.updated_on) %></em></p>
|
||||
|
||||
<div class="wiki">
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<%= error_messages_for 'document' %>
|
||||
<div class="box">
|
||||
<!--[form:document]-->
|
||||
<p><label for="document_category_id"><%=l(:field_category)%></label>
|
||||
<%= select('document', 'category_id', DocumentCategory.active.collect {|c| [c.name, c.id]}) %></p>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<p><label for="document_title"><%=l(:field_title)%> <span class="required">*</span></label>
|
||||
<%= text_field 'document', 'title', :size => 60 %></p>
|
||||
|
||||
<p><label for="document_description"><%=l(:field_description)%></label>
|
||||
<%= text_area 'document', 'description', :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
|
||||
<!--[eoform:document]-->
|
||||
<div class="box tabular">
|
||||
<p><%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %></p>
|
||||
<p><%= f.text_field :title, :required => true, :size => 60 %></p>
|
||||
<p><%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
|
||||
</div>
|
||||
|
||||
<%= wikitoolbar_for 'document_description' %>
|
||||
|
||||
<% if @document.new_record? %>
|
||||
<div class="box tabular">
|
||||
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<h2><%=l(:label_document)%></h2>
|
||||
|
||||
<% form_tag({:action => 'edit', :id => @document}, :class => "tabular") do %>
|
||||
<%= render :partial => 'form' %>
|
||||
<%= submit_tag l(:button_save) %>
|
||||
<% labelled_form_for @document do |f| %>
|
||||
<%= render :partial => 'form', :locals => {:f => f} %>
|
||||
<p><%= submit_tag l(:button_save) %></p>
|
||||
<% end %>
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
<div class="contextual">
|
||||
<%= link_to_if_authorized l(:label_document_new),
|
||||
{:controller => 'documents', :action => 'new', :project_id => @project},
|
||||
:class => 'icon icon-add',
|
||||
:onclick => 'Element.show("add-document"); Form.Element.focus("document_title"); return false;' %>
|
||||
<%= link_to l(:label_document_new), new_project_document_path(@project), :class => 'icon icon-add',
|
||||
:onclick => 'Element.show("add-document"); Form.Element.focus("document_title"); return false;' if User.current.allowed_to?(:manage_documents, @project) %>
|
||||
</div>
|
||||
|
||||
<div id="add-document" style="display:none;">
|
||||
<h2><%=l(:label_document_new)%></h2>
|
||||
<% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :class => "tabular", :multipart => true) do %>
|
||||
<%= render :partial => 'documents/form' %>
|
||||
<div class="box">
|
||||
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
|
||||
</div>
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-document")' %>
|
||||
<% labelled_form_for @document, :url => project_documents_path(@project), :html => {:multipart => true} do |f| %>
|
||||
<%= render :partial => 'form', :locals => {:f => f} %>
|
||||
<p>
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-document")' %>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
<h2><%=l(:label_document_new)%></h2>
|
||||
|
||||
<% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :class => "tabular", :multipart => true) do %>
|
||||
<%= render :partial => 'documents/form' %>
|
||||
|
||||
<div class="box">
|
||||
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
|
||||
</div>
|
||||
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<% labelled_form_for @document, :url => project_documents_path(@project), :html => {:multipart => true} do |f| %>
|
||||
<%= render :partial => 'form', :locals => {:f => f} %>
|
||||
<p><%= submit_tag l(:button_create) %></p>
|
||||
<% end %>
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<div class="contextual">
|
||||
<%= link_to_if_authorized l(:button_edit), {:controller => 'documents', :action => 'edit', :id => @document}, :class => 'icon icon-edit', :accesskey => accesskey(:edit) %>
|
||||
<%= link_to_if_authorized l(:button_delete), {:controller => 'documents', :action => 'destroy', :id => @document}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
|
||||
<% if User.current.allowed_to?(:manage_documents, @project) %>
|
||||
<%= link_to l(:button_edit), edit_document_path(@document), :class => 'icon icon-edit', :accesskey => accesskey(:edit) %>
|
||||
<%= link_to l(:button_delete), document_path(@document), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<h2><%=h @document.title %></h2>
|
||||
|
||||
Reference in New Issue
Block a user