diff --git a/app/controllers.rb b/app/controllers.rb index f6f7e15..561951d 100644 --- a/app/controllers.rb +++ b/app/controllers.rb @@ -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 diff --git a/app/locale/cs.yml b/app/locale/cs.yml index f22bf22..e08da48 100644 --- a/app/locale/cs.yml +++ b/app/locale/cs.yml @@ -3,6 +3,7 @@ cs: view: Zobrazit fill: Vyplnit edit: Upravit + new_document: Nový dokument submit: Odeslat create_pdf: Vytvořit PDF created_at: Vytvořen @@ -10,6 +11,7 @@ cs: 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ď diff --git a/app/locale/en.yml b/app/locale/en.yml index 6cdc229..0799756 100644 --- a/app/locale/en.yml +++ b/app/locale/en.yml @@ -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 @@ -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 diff --git a/app/stylesheets/application.scss b/app/stylesheets/application.scss index 858d61f..aa370ed 100644 --- a/app/stylesheets/application.scss +++ b/app/stylesheets/application.scss @@ -114,3 +114,7 @@ input[type="text"] { background-color: #22a; } +.new-doc { + float: right; + margin: 3px 3px 0 0; +} diff --git a/app/views/_form.slim b/app/views/_form.slim new file mode 100644 index 0000000..6e6309d --- /dev/null +++ b/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 + |  + diff --git a/app/views/_new_doc.slim b/app/views/_new_doc.slim new file mode 100644 index 0000000..85eb73b --- /dev/null +++ b/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 + + diff --git a/app/views/edit.slim b/app/views/edit.slim index adf8381..5c89450 100644 --- a/app/views/edit.slim +++ b/app/views/edit.slim @@ -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" diff --git a/app/views/index.slim b/app/views/index.slim index e2f4103..fdb55cf 100644 --- a/app/views/index.slim +++ b/app/views/index.slim @@ -1,6 +1,7 @@ - if flash[:notification] div.notification = flash[:notification] + ul.breadcrumb li.active =t 'wall' diff --git a/app/views/type.slim b/app/views/type.slim index e025d2e..1356d34 100644 --- a/app/views/type.slim +++ b/app/views/type.slim @@ -1,3 +1,5 @@ +== partial "new_doc" + ul.breadcrumb li a href="/" =t 'wall' diff --git a/spec/features/admin_documents_spec.rb b/spec/features/admin_documents_spec.rb index 3eb1459..2a946de 100644 --- a/spec/features/admin_documents_spec.rb +++ b/spec/features/admin_documents_spec.rb @@ -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