Skip to content

Commit

Permalink
Add creating of the new documents
Browse files Browse the repository at this point in the history
  • Loading branch information
pepe committed Nov 23, 2012
1 parent 3e25708 commit 7d6e502
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 23 deletions.
23 changes: 22 additions & 1 deletion app/controllers.rb
Expand Up @@ -23,30 +23,51 @@ def current_type
end

def current_type_url
"/#{current_type}"
url(:type, type: current_type)
end

def new_current_type_url
url(:new, type: current_type)
end
end

get :index do
extend Renderer::Html
@documents = columnize(Questionnaire.for_front_page)

render 'index'
end

get :document, with: :id do
extend Renderer::Html
@document = Document.find(params[:id])

render 'document'
end

get :edit, with: :id do
@document = Document.find(params[:id])

render 'edit'
end

post :update do
document = Document.find(params[:id])
document.update_attributes(params[:document])

redirect url(:type, type: document.type)
end

get :new, with: :type do
extend Renderer::Html
@document = Document.new(type: :type)

render 'new'
end

post :create do
document = Document.create(params[:document])

redirect url(:type, type: document.type)
end

Expand Down
2 changes: 2 additions & 0 deletions app/locale/cs.yml
Expand Up @@ -3,13 +3,15 @@ cs:
view: Zobrazit
fill: Vyplnit
edit: Upravit
new_document: Nový dokument
submit: Odeslat
create_pdf: Vytvořit PDF
created_at: Vytvořen
never_filled: Nikdy nevyplněn
last_filled: Vyplněno
back: Zpět na Vaši zeď
editing: Editace
creating: Vytváření nového dokumentu
not_logged_in: Nejste přihlášen/-a. Prosím uděljte tak na eDoktorandovi.
type:
wall: Zeď
Expand Down
2 changes: 2 additions & 0 deletions app/locale/en.yml
Expand Up @@ -3,6 +3,7 @@ en:
view: View
fill: Fill
edit: Edit
new_document: New document
submit: Submit
create_pdf: Create PDF
submited_successfully: Submited successfully
Expand All @@ -12,6 +13,7 @@ en:
back: Back to your wall
not_logged_in: You are not logged in. Please do so from eDoktorand.
editing: Editing
creating: Creating new document
type:
wall: Wall
records: Records
Expand Down
4 changes: 4 additions & 0 deletions app/stylesheets/application.scss
Expand Up @@ -114,3 +114,7 @@ input[type="text"] {
background-color: #22a;
}

.new-doc {
float: right;
margin: 3px 3px 0 0;
}
23 changes: 23 additions & 0 deletions app/views/_form.slim
@@ -0,0 +1,23 @@
fieldset
div.control-group
label.control-label for="name" =t 'document.name'
div.controls
input#name.input-xlarge name='document[name]' type='text' value=@document.name
div.control-group
label.control-label for="desc" =t 'document.desc'
div.controls
input#desc.input-xlarge name='document[desc]' type='text' value=@document.desc
div.control-group
label.control-label for="desc" =t 'document.body'
div.controls
textarea#body name='document[body]' rows='30' = @document.body
div.control-group.pull-right
input.btn.btn-primary type='submit' value=t('save')
div.control-group
label.control-label for="type" =t 'document.type'
div.controls
select#type name='document[type]' selected=@document.type
- %w(expectations plan records analysis).each do |type|
option value=type selected=@document.is_type?(type) =t type, scope: :type
| 

5 changes: 5 additions & 0 deletions app/views/_new_doc.slim
@@ -0,0 +1,5 @@
- if current_account.admin?
div.new-doc
a.btn.btn-primary href=new_current_type_url =t :new_document


23 changes: 1 addition & 22 deletions app/views/edit.slim
Expand Up @@ -7,26 +7,5 @@ ul.breadcrumb

div.span12
form.form-horizontal method='post' action=url(:update, id: @document.id)
fieldset
div.control-group
label.control-label for="name" =t 'document.name'
div.controls
input#name.input-xlarge name='document[name]' type='text' value=@document.name
div.control-group
label.control-label for="desc" =t 'document.desc'
div.controls
input#desc.input-xlarge name='document[desc]' type='text' value=@document.desc
div.control-group
label.control-label for="desc" =t 'document.body'
div.controls
textarea#body name='document[body]' rows='30' = @document.body
div.control-group.pull-right
input.btn.btn-primary type='submit' value=t('save')
div.control-group
label.control-label for="type" =t 'document.type'
div.controls
select#type name='document[type]' selected=@document.type
- %w(expectations plan records analysis).each do |type|
option value=type selected=@document.is_type?(type) =t type, scope: :type
| 
== partial "form"

1 change: 1 addition & 0 deletions app/views/index.slim
@@ -1,6 +1,7 @@
- if flash[:notification]
div.notification
= flash[:notification]

ul.breadcrumb
li.active =t 'wall'

Expand Down
2 changes: 2 additions & 0 deletions app/views/type.slim
@@ -1,3 +1,5 @@
== partial "new_doc"

ul.breadcrumb
li
a href="/" =t 'wall'
Expand Down
7 changes: 7 additions & 0 deletions spec/features/admin_documents_spec.rb
Expand Up @@ -26,4 +26,11 @@
page.should have_content 'Advanced'
end

scenario "creating document" do
click_on 'New document'
page.should have_content('Creating new document')
fill_in 'name', with: 'Advanced'
click_on 'Save'
page.should have_content 'Advanced'
end
end

0 comments on commit 7d6e502

Please sign in to comment.