Added page-preview feature to wiki module.
This commit is contained in:
parent
0fb8ee214f
commit
7de45543c4
7 changed files with 36 additions and 21 deletions
|
@ -18,10 +18,8 @@ class PagesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /pages/new
|
|
||||||
# GET /pages/new.xml
|
|
||||||
def new
|
def new
|
||||||
@page = Page.new(:title => params[:title])
|
@page = Page.new(:title => params[:title].capitalize.gsub("-", " "))
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # new.html.erb
|
format.html # new.html.erb
|
||||||
|
@ -29,47 +27,46 @@ class PagesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /pages/1/edit
|
|
||||||
def edit
|
def edit
|
||||||
@page = Page.find(params[:id])
|
@page = Page.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /pages
|
|
||||||
# POST /pages.xml
|
|
||||||
def create
|
def create
|
||||||
@page = current_user.pages.build(params[:page])
|
@page = current_user.pages.build(params[:page])
|
||||||
|
|
||||||
respond_to do |format|
|
if params[:preview]
|
||||||
|
render :action => 'new'
|
||||||
|
else
|
||||||
if @page.save
|
if @page.save
|
||||||
flash[:notice] = 'Seite wurde angelegt.'
|
flash[:notice] = 'Seite wurde angelegt.'
|
||||||
format.html { redirect_to(wiki_page_path(@page.permalink)) }
|
redirect_to(wiki_page_path(@page.permalink))
|
||||||
format.xml { render :xml => @page, :status => :created, :location => @page }
|
|
||||||
else
|
else
|
||||||
format.html { render :action => "new" }
|
render :action => "new"
|
||||||
format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# PUT /pages/1
|
|
||||||
# PUT /pages/1.xml
|
|
||||||
def update
|
def update
|
||||||
@page = Page.find(params[:id])
|
@page = Page.find(params[:id])
|
||||||
|
@page.attributes = params[:page].merge({:user => current_user})
|
||||||
|
|
||||||
if @page.update_attributes(params[:page].merge({:user => current_user}))
|
if params[:preview]
|
||||||
|
@page.attributes = params[:page]
|
||||||
|
render :action => 'edit'
|
||||||
|
else
|
||||||
|
if @page.save
|
||||||
flash[:notice] = 'Seite wurde aktualisiert.'
|
flash[:notice] = 'Seite wurde aktualisiert.'
|
||||||
redirect_to wiki_page_path(@page.permalink)
|
redirect_to wiki_page_path(@page.permalink)
|
||||||
else
|
else
|
||||||
render :action => "edit"
|
render :action => "edit"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
rescue ActiveRecord::StaleObjectError
|
rescue ActiveRecord::StaleObjectError
|
||||||
flash[:error] = "Achtung, die Seite wurde gerade von jemand anderes bearbeitet. Bitte versuche es erneut."
|
flash[:error] = "Achtung, die Seite wurde gerade von jemand anderes bearbeitet. Bitte versuche es erneut."
|
||||||
redirect_to wiki_page_path(@page.permalink)
|
redirect_to wiki_page_path(@page.permalink)
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /pages/1
|
|
||||||
# DELETE /pages/1.xml
|
|
||||||
def destroy
|
def destroy
|
||||||
@page = Page.find(params[:id])
|
@page = Page.find(params[:id])
|
||||||
@page.destroy
|
@page.destroy
|
||||||
|
|
1
app/views/pages/_body.html.haml
Normal file
1
app/views/pages/_body.html.haml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
= wikified_body @page.body
|
|
@ -1,3 +1,7 @@
|
||||||
|
- if params[:preview]
|
||||||
|
%h2 Vorschau
|
||||||
|
#preview= render :partial => 'body'
|
||||||
|
|
||||||
#wiki-syntax-help{:style => "float:right"}
|
#wiki-syntax-help{:style => "float:right"}
|
||||||
%p
|
%p
|
||||||
%b Schnelle Formatierungshilfe
|
%b Schnelle Formatierungshilfe
|
||||||
|
@ -25,6 +29,8 @@
|
||||||
%br/
|
%br/
|
||||||
= f.text_area :body, :size => "60x30"
|
= f.text_area :body, :size => "60x30"
|
||||||
%p
|
%p
|
||||||
|
= f.submit "Vorschau", :name => 'preview'
|
||||||
|
|
|
||||||
= f.submit "Speichern"
|
= f.submit "Speichern"
|
||||||
|
|
|
|
||||||
= link_to "Abbrechen", :back
|
= link_to "Abbrechen", :back
|
|
@ -11,7 +11,7 @@
|
||||||
= "(#{User.find(version.updated_by).nick})"
|
= "(#{User.find(version.updated_by).nick})"
|
||||||
|
|
||||||
|
|
||||||
= wikified_body @page.body
|
= render :partial => 'body'
|
||||||
|
|
||||||
%hr.clear/
|
%hr.clear/
|
||||||
%p
|
%p
|
||||||
|
|
|
@ -440,3 +440,7 @@ ul.autocomplete .informal {
|
||||||
|
|
||||||
a.new_wiki_link {
|
a.new_wiki_link {
|
||||||
color: grey; }
|
color: grey; }
|
||||||
|
|
||||||
|
#preview {
|
||||||
|
border: 1px dotted grey;
|
||||||
|
padding: 0 1em; }
|
||||||
|
|
|
@ -441,6 +441,10 @@ ul.autocomplete .informal {
|
||||||
a.new_wiki_link {
|
a.new_wiki_link {
|
||||||
color: grey; }
|
color: grey; }
|
||||||
|
|
||||||
|
#preview {
|
||||||
|
border: 1px dotted grey;
|
||||||
|
padding: 0 1em; }
|
||||||
|
|
||||||
#logininfo, #header, #footer {
|
#logininfo, #header, #footer {
|
||||||
display: none; }
|
display: none; }
|
||||||
|
|
||||||
|
|
|
@ -488,3 +488,6 @@ ul.autocomplete
|
||||||
// *** wiki
|
// *** wiki
|
||||||
a.new_wiki_link
|
a.new_wiki_link
|
||||||
color: grey
|
color: grey
|
||||||
|
#preview
|
||||||
|
border: 1px dotted grey
|
||||||
|
padding: 0 1em
|
Loading…
Reference in a new issue