activeadmin-selleo-cms 0.0.46 → 0.0.47

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,16 @@ function submitAnswer(form_id, input, value){
20
20
  })
21
21
  }
22
22
 
23
+ function fileUpload(form_id, dom_id, question_id) {
24
+ $('#popup').html('').load('/form_answers/find_or_create',
25
+ {
26
+ form_uuid: localStorage[form_id],
27
+ dom_id: dom_id,
28
+ form_question_id: question_id
29
+ }
30
+ ).dialog('open');
31
+ }
32
+
23
33
  function setupCmsForm(form_id) {
24
34
  $('#'+form_id+' .required fieldset [type="radio"]:first,[type="checkbox"]:first').attr('required','true');
25
35
  $('#'+form_id).validate();
@@ -28,6 +38,8 @@ function setupCmsForm(form_id) {
28
38
  localStorage[form_id] = generateUUID();
29
39
  }
30
40
 
41
+ $('#'+form_id).data('uuid', localStorage[form_id]);
42
+
31
43
  $.get('/form_answers.json', {
32
44
  form_uuid: localStorage[form_id]
33
45
  }).success(function(resp){
@@ -35,9 +47,11 @@ function setupCmsForm(form_id) {
35
47
  if (this["value"] != null) {
36
48
  var form_elem = $('#'+this["dom_id"]);
37
49
  if ( ($(form_elem).attr('type') == 'checkbox') || ($(form_elem).attr('type') == 'radio') ) {
38
- $(form_elem).attr('checked', true);
50
+ if (this["value"] == "true") {
51
+ $(form_elem).attr('checked', true);
52
+ }
39
53
  } else if ($(form_elem).attr('type') == 'file') {
40
- // ??
54
+ // do nothing
41
55
  } else {
42
56
  $(form_elem).val(this["value"]);
43
57
  }
@@ -47,7 +61,7 @@ function setupCmsForm(form_id) {
47
61
 
48
62
  $('#' + form_id + ' input, textarea').change(function(){
49
63
  if ($(this).attr('type') == 'file') {
50
- // ??
64
+ // do nothing
51
65
  } else if ( ($(this).attr('type') == 'checkbox') || ($(this).attr('type') == 'radio') ) {
52
66
  submitAnswer(form_id, this, $(this).is(':checked'))
53
67
  } else {
@@ -115,7 +115,7 @@
115
115
  });
116
116
  $("textarea", $element).each(function () {
117
117
  //Thanks http://blog.ekini.net/2009/02/24/jquery-getting-the-latest-textvalue-inside-a-textarea/
118
- var value = $(this).attr('value');
118
+ var value = $(this).val();
119
119
  //fix for issue 7 (http://plugins.jquery.com/node/13503 and http://github.com/erikzaadi/jQueryPlugins/issues#issue/7)
120
120
  if ($.browser.mozilla && this.firstChild) {
121
121
  this.firstChild.textContent = value;
@@ -16,4 +16,18 @@ class FormAnswersController < ApplicationController
16
16
  respond_with ActiveadminSelleoCms::FormAnswer.where(form_uuid: params[:form_uuid])
17
17
  end
18
18
 
19
+ def edit
20
+ @form_answer = ActiveadminSelleoCms::FormAnswer.find(params[:id])
21
+ end
22
+
23
+ def update
24
+ @form_answer = ActiveadminSelleoCms::FormAnswer.find(params[:id])
25
+ @form_answer.update_attributes(params[:form_answer])
26
+ end
27
+
28
+ def find_or_create
29
+ @form_answer = ActiveadminSelleoCms::FormAnswer.find_or_create_by_form_uuid_and_dom_id_and_form_question_id(params[:form_uuid], params[:dom_id], params[:form_question_id])
30
+ render action: :edit
31
+ end
32
+
19
33
  end
@@ -6,9 +6,14 @@ class FormsController < ApplicationController
6
6
  end
7
7
 
8
8
  def download
9
+ ActiveadminSelleoCms::FormAnswer.where(form_uuid: params[:form_uuid])
10
+
9
11
  respond_to do |format|
10
12
  format.pdf do
11
- render :pdf => @form.title.parameterize
13
+ render :pdf => @form.title.parameterize, :show_as_html => false
14
+ end
15
+ format.html do
16
+ render :pdf => @form.title.parameterize, :show_as_html => true
12
17
  end
13
18
  end
14
19
  end
@@ -16,21 +21,12 @@ class FormsController < ApplicationController
16
21
  def deliver
17
22
  respond_to do |format|
18
23
  format.html do
19
- pdf = WickedPdf.new.pdf_from_string(
20
- render_to_string('download.pdf.erb')
21
- )
22
- pdf_path = File.join(ActiveadminSelleoCms::Form::PDF_PATH, "#{@form.title.parameterize}-#{Time.now.to_s.parameterize}.pdf")
23
- File.open(pdf_path, 'wb') do |file|
24
- file << pdf
25
- end
26
- ActiveadminSelleoCms::FormMailer.form_submission(pdf_path).deliver
24
+ ActiveadminSelleoCms::FormMailer.form_submission(@form, params[:form_uuid]).deliver
27
25
  flash[:notice] = "Your form has been sent. Thank you."
28
26
  end
29
27
  end
30
28
  end
31
29
 
32
- def answer
33
-
34
- end
30
+ def answer; end
35
31
 
36
32
  end
@@ -2,8 +2,9 @@ module ActiveadminSelleoCms
2
2
  class FormMailer < ActionMailer::Base
3
3
  default from: "web-form@jips.org"
4
4
 
5
- def form_submission(form_filename)
6
- attachments[form_filename] = File.read(form_filename)
5
+ def form_submission(form, form_uuid)
6
+ @form = form
7
+ @form_uuid = form_uuid
7
8
  mail(to: 'aossowski@gmail.com', subject: "New form submission")
8
9
  end
9
10
  end
@@ -1,8 +1,12 @@
1
1
  module ActiveadminSelleoCms
2
2
  class FormAnswer < ActiveRecord::Base
3
- attr_accessible :form_uuid, :dom_id, :form_id, :form_question_id, :value
3
+ attr_accessible :form_uuid, :dom_id, :form_id, :form_question_id, :value, :data
4
4
  validates_presence_of :form_uuid, :dom_id
5
5
 
6
+ has_attached_file :data,
7
+ :url => "/system/cms/form_answers/:id/:style_:basename.:extension",
8
+ :path => ":rails_root/public/system/cms/form_answers/:id/:style_:basename.:extension"
9
+
6
10
  belongs_to :form
7
11
  belongs_to :form_question
8
12
 
@@ -12,5 +16,21 @@ module ActiveadminSelleoCms
12
16
  end
13
17
  end
14
18
 
19
+ def self.value_for(form_uuid, dom_id)
20
+ if answer = self.where(form_uuid: form_uuid, dom_id: dom_id).first
21
+ answer.value
22
+ else
23
+ nil
24
+ end
25
+ end
26
+
27
+ def self.file_for(form_uuid, dom_id)
28
+ if answer = self.where(form_uuid: form_uuid, dom_id: dom_id).first and answer.data.exists?
29
+ answer
30
+ else
31
+ nil
32
+ end
33
+ end
34
+
15
35
  end
16
36
  end
@@ -4,9 +4,9 @@
4
4
  <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
5
5
  </head>
6
6
  <body>
7
- <h3>New form has been submitted.</h3>
7
+ <h3>New form has been submitted!</h3>
8
8
  <p>
9
- Please see the attachmed file.
9
+ <%= link_to "Click here for details.", "/forms/#{@form.id}/download?form_uuid=#{@form_uuid}" %>
10
10
  </p>
11
11
  </body>
12
12
  </html>
@@ -0,0 +1,5 @@
1
+ = semantic_form_for @form_answer, remote: true, html: { multipart: true } do |form|
2
+
3
+ = form.inputs id: 'attachment_fields' do
4
+ = form.input :data, hint: @form_answer.data_file_name
5
+ = form.actions :submit
@@ -0,0 +1 @@
1
+ = render partial: 'form'
@@ -0,0 +1,2 @@
1
+ $('#popup').effect('highlight');
2
+ $('#popup form').html('<%= j render partial: 'form' %>');
@@ -0,0 +1,50 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
+ <%= wicked_pdf_stylesheet_link_tag "components/forms" -%>
7
+ </head>
8
+ <body>
9
+
10
+ <%= form_tag '/forms', multipart: true, id: dom_id(@form), data: {form_id: @form.id} do %>
11
+ <ol class="questions">
12
+ <% @form.questions.each do |question| %>
13
+ <li class="question <%= question.input_type %>">
14
+ <div class="questions_labels">
15
+ <%= label_tag dom_id(question), question.title %>
16
+ <% if question.hint.present? %>
17
+ <p class="hint"><%= question.hint %></p>
18
+ <% end %>
19
+ </div>
20
+ <% if [:check_box_tag].include? question.input_type %>
21
+ <div class="questions_options">
22
+ <% question.options.each do |option| %>
23
+ <%= send(question.input_type, "#{dom_id(question)}[]", option.id, ActiveadminSelleoCms::FormAnswer.value_for(params[:form_uuid], dom_id(option))=="true", required: question.is_required, id: dom_id(option), data: {form_question_id: question.id} ) %>
24
+ <%= label_tag dom_id(option), option.title %>
25
+ <% end %>
26
+ <%= text_field_tag "#{dom_id(question)}_other", ActiveadminSelleoCms::FormAnswer.value_for(params[:form_uuid], "#{dom_id(question)}_other"), data: {form_question_id: question.id} if question.has_other_option %>
27
+ </div>
28
+ <% elsif [:radio_button_tag].include? question.input_type %>
29
+ <div class="questions_options">
30
+ <% question.options.each do |option| %>
31
+ <%= send(question.input_type, dom_id(question), option.id, ActiveadminSelleoCms::FormAnswer.value_for(params[:form_uuid], dom_id(option)), required: question.is_required, id: dom_id(option), data: {form_question_id: question.id}) %>
32
+ <%= label_tag dom_id(option), option.title %>
33
+ <% end %>
34
+ <%= text_field_tag "#{dom_id(question)}_other", ActiveadminSelleoCms::FormAnswer.value_for(params[:form_uuid], "#{dom_id(question)}_other"), data: {form_question_id: question.id} if question.has_other_option %>
35
+ </div>
36
+ <% elsif [:file_field_tag].include? question.input_type %>
37
+ <% if file = ActiveadminSelleoCms::FormAnswer.file_for(params[:form_uuid], dom_id(question)) %>
38
+ <p><%= link_to file.data_file_name, file.data.url %></p>
39
+ <% end %>
40
+ <%#= button_to_function "Select file", "fileUpload('#{dom_id(@form)}', '#{dom_id(question)}', #{question.id})", style: "padding: 5px;" %>
41
+ <% else %>
42
+ <%= send(question.input_type, dom_id(question), ActiveadminSelleoCms::FormAnswer.value_for(params[:form_uuid], dom_id(question)), required: question.is_required, data: {form_question_id: question.id}) %>
43
+ <% end %>
44
+ </li>
45
+ <% end %>
46
+ </ol>
47
+ <% end %>
48
+
49
+ </body>
50
+ </html>
@@ -2,37 +2,59 @@
2
2
  <ol class="questions">
3
3
  <% form.questions.each do |question| %>
4
4
  <li class="question <%= question.input_type %>">
5
- <%= label_tag dom_id(question), question.title %>
6
- <% if question.hint.present? %>
7
- <p class="hint"><%= question.hint %></p>
8
- <% end %>
9
- <% if [:check_box_tag].include? question.input_type %>
10
- <% question.options.each do |option| %>
11
- <%= send(question.input_type, "#{dom_id(question)}[]", option.id, false, required: question.is_required, id: dom_id(option), data: {form_question_id: question.id} ) %>
12
- <%= label_tag dom_id(option), option.title %>
13
- <% end %>
14
- <% elsif [:radio_button_tag].include? question.input_type %>
15
- <% question.options.each do |option| %>
16
- <%= send(question.input_type, dom_id(question), option.id, false, required: question.is_required, id: dom_id(option), data: {form_question_id: question.id}) %>
17
- <%= label_tag dom_id(option), option.title %>
5
+ <div class="questions_labels">
6
+ <%= label_tag dom_id(question), question.title %>
7
+ <% if question.hint.present? %>
8
+ <p class="hint"><%= question.hint %></p>
18
9
  <% end %>
10
+ </div>
11
+ <% if [:check_box_tag].include? question.input_type %>
12
+ <div class="questions_options">
13
+ <% question.options.each do |option| %>
14
+ <%= send(question.input_type, "#{dom_id(question)}[]", option.id, false, required: question.is_required, id: dom_id(option), data: {form_question_id: question.id} ) %>
15
+ <%= label_tag dom_id(option), option.title %>
16
+ <% end %>
17
+ <%= text_field_tag "#{dom_id(question)}_other", "", data: {form_question_id: question.id} if question.has_other_option %>
18
+ </div>
19
+ <% elsif [:radio_button_tag].include? question.input_type %>
20
+ <div class="questions_options">
21
+ <% question.options.each do |option| %>
22
+ <%= send(question.input_type, dom_id(question), option.id, false, required: question.is_required, id: dom_id(option), data: {form_question_id: question.id}) %>
23
+ <%= label_tag dom_id(option), option.title %>
24
+ <% end %>
25
+ <%= text_field_tag "#{dom_id(question)}_other", "", data: {form_question_id: question.id} if question.has_other_option %>
26
+ </div>
19
27
  <% elsif [:file_field_tag].include? question.input_type %>
20
- <%= send(question.input_type, dom_id(question), required: question.is_required, data: {form_question_id: question.id}) %>
28
+ <%= button_to_function "Select file", "fileUpload('#{dom_id(form)}', '#{dom_id(question)}', #{question.id})", style: "padding: 5px;" %>
21
29
  <% else %>
22
30
  <%= send(question.input_type, dom_id(question), "", required: question.is_required, data: {form_question_id: question.id}) %>
23
31
  <% end %>
24
- <%= text_field_tag "#{dom_id(question)}_other", "", data: {form_question_id: question.id} if question.has_other_option %>
25
32
  </li>
26
33
  <% end %>
27
34
  </ol>
28
35
  <% end %>
29
36
 
30
- <%= button_to_function "Print", "$('##{dom_id(form)}').printElement({printMode:'popup'});" %>
31
- <%= button_to_function "Download", "$('##{dom_id(form)}').attr('action', '/forms/#{form.id}/download.pdf').submit();" %>
32
- <%= button_to_function "Send to JIPS", "$('##{dom_id(form)}').attr('action', '/forms/#{form.id}/deliver').submit();" %>
37
+ <%= button_to_function "Print", "$('##{dom_id(form)}').printElement({printMode:'popup'});", class: 'print', title: 'Print' %>
38
+ <%= button_to_function "Download PDF", "downloadPDF(#{form.id}, '#{dom_id(form)}')", class: 'save', title: 'Download PDF' %>
39
+ <%= button_to_function "Download", "download(#{form.id}, '#{dom_id(form)}')", class: 'save', title: 'Download' %>
40
+ <%= button_to_function "Send to JIPS", "deliver(#{form.id}, '#{dom_id(form)}')", class: 'send' %>
33
41
 
34
42
  <script>
35
43
  $(function(){
36
44
  setupCmsForm('<%= dom_id(form) %>');
37
45
  });
46
+
47
+ function downloadPDF(form_id, form_dom_id){
48
+ window.location='/forms/'+form_id+'/download.pdf?form_uuid='+localStorage[form_dom_id];
49
+ }
50
+
51
+ function download(form_id, form_dom_id){
52
+ window.location='/forms/'+form_id+'/download?form_uuid='+localStorage[form_dom_id];
53
+ }
54
+
55
+ function deliver(form_id, form_dom_id) {
56
+ if ($('#'+form_dom_id).valid() == true) {
57
+ window.location='/forms/'+form_id+'/deliver?form_uuid='+localStorage[form_dom_id];
58
+ }
59
+ }
38
60
  </script>
@@ -0,0 +1 @@
1
+ <%= render partial: 'download'%>
@@ -1,16 +1 @@
1
- <%= form_tag '/forms', multipart: true, id: dom_id(@form) do %>
2
- <% @form.questions.each do |question| %>
3
- <%= label_tag dom_id(question), question.title %>
4
- <% if [:check_box_tag, :radio_button_tag].include? question.input_type %>
5
- <% question.options.each do |option| %>
6
- <%= send(question.input_type, dom_id(question), option.id, Array(params[dom_id(question)]).include?(option.id.to_s)) %>
7
- <%= label_tag dom_id(option), option.title %>
8
- <% end %>
9
- <% elsif [:file_field_tag].include? question.input_type %>
10
- <%= send(question.input_type, dom_id(question), required: question.is_required) %>
11
- <% else %>
12
- <%= send(question.input_type, dom_id(question), params[dom_id(question)]) %>
13
- <% end %>
14
- <%= text_field_tag "#{dom_id(question)}_other", params["#{dom_id(question)}_other"] if question.has_other_option %>
15
- <% end %>
16
- <% end %>
1
+ <%= render partial: 'download'%>
data/config/routes.rb CHANGED
@@ -3,12 +3,16 @@ Rails.application.routes.draw do
3
3
 
4
4
  resources :forms, :only => [] do
5
5
  member do
6
- post :download
7
- post :deliver
6
+ get :download
7
+ get :deliver
8
8
  end
9
9
  end
10
10
 
11
- resources :form_answers, :only => [:create, :index]
11
+ resources :form_answers do
12
+ collection do
13
+ post :find_or_create
14
+ end
15
+ end
12
16
 
13
17
  scope ":locale", :locale => /\w{2}/ do
14
18
  scope "search" do
@@ -1,3 +1,3 @@
1
1
  module ActiveadminSelleoCms
2
- VERSION = "0.0.46"
2
+ VERSION = "0.0.47"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-selleo-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.46
4
+ version: 0.0.47
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-08 00:00:00.000000000 Z
12
+ date: 2013-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -441,7 +441,9 @@ files:
441
441
  - app/assets/javascripts/activeadmin-selleo-cms/jquery.browser.js
442
442
  - app/assets/javascripts/activeadmin-selleo-cms/inline-editing.js
443
443
  - app/assets/javascripts/activeadmin-selleo-cms/forms.js
444
+ - app/views/forms/download.html.erb
444
445
  - app/views/forms/deliver.html.erb
446
+ - app/views/forms/_download.erb
445
447
  - app/views/forms/_form.html.erb
446
448
  - app/views/forms/download.pdf.erb
447
449
  - app/views/admin/sections/_form.html.haml
@@ -494,6 +496,9 @@ files:
494
496
  - app/views/searches/show.html.haml
495
497
  - app/views/layouts/activeadmin_selleo_cms/application.html.erb
496
498
  - app/views/active_admin/resource/update.js
499
+ - app/views/form_answers/_form.html.haml
500
+ - app/views/form_answers/update.js.erb
501
+ - app/views/form_answers/edit.html.haml
497
502
  - app/views/activeadmin_selleo_cms/form_mailer/form_submission.html.erb
498
503
  - app/modules/activeadmin_selleo_cms/content_translation.rb
499
504
  - app/models/translation.rb