activeadmin-selleo-cms 0.0.52 → 0.0.54

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,8 +50,6 @@ function setupCmsForm(form_id) {
50
50
  if (this["value"] == "true") {
51
51
  $(form_elem).attr('checked', true);
52
52
  }
53
- } else if ($(form_elem).attr('type') == 'file') {
54
- // do nothing
55
53
  } else {
56
54
  $(form_elem).val(this["value"]);
57
55
  }
@@ -67,4 +65,8 @@ function setupCmsForm(form_id) {
67
65
  } else {
68
66
  submitAnswer(form_id, this, $(this).val())
69
67
  }});
68
+
69
+ $.each($('.file_upload'), function(){
70
+ $(this).find('.files').load('/form_answers/attachments?form_uuid='+localStorage[form_id]+'&form_question_id='+$(this).data('question-id'));
71
+ });
70
72
  }
@@ -30,4 +30,9 @@ class FormAnswersController < ApplicationController
30
30
  render action: :edit
31
31
  end
32
32
 
33
+ def attachments
34
+ @form_answer = ActiveadminSelleoCms::FormAnswer.where(form_uuid: params[:form_uuid], form_question_id: params[:form_question_id]).first
35
+ render partial: 'attachments'
36
+ end
37
+
33
38
  end
@@ -3,7 +3,10 @@ module ActiveadminSelleoCms
3
3
  def form_submission(form, form_uuid)
4
4
  @form = form
5
5
  @form_uuid = form_uuid
6
- mail(subject: "New form submission")
6
+ mail(
7
+ to: @form.delivery_emails(@form_uuid),
8
+ subject: I18n.t("active_admin.cms.forms.email_subject")
9
+ )
7
10
  end
8
11
  end
9
12
  end
@@ -3,9 +3,18 @@ module ActiveadminSelleoCms
3
3
  PDF_PATH = Rails.root.join('public','system','pdf')
4
4
 
5
5
  has_many :questions, class_name: "FormQuestion", :order => "position"
6
+ has_many :answers, through: :questions
6
7
 
7
8
  validates :title, presence: true
9
+ validates :email, presence: true
8
10
 
9
11
  attr_protected :id
12
+
13
+ def delivery_emails(form_uuid)
14
+ [(email || ActionMailer::Base.default[:to])] +
15
+ answers.joins(:form_question).
16
+ where(:activeadmin_selleo_cms_form_questions => {:question_type => FormQuestion::TYPE_EMAIL}).
17
+ where("value IS NOT NULL AND value <> ''").where(:form_uuid => form_uuid).map(&:value)
18
+ end
10
19
  end
11
20
  end
@@ -1,14 +1,13 @@
1
1
  module ActiveadminSelleoCms
2
2
  class FormAnswer < ActiveRecord::Base
3
- attr_accessible :form_uuid, :dom_id, :form_id, :form_question_id, :value, :data
3
+ attr_accessible :form_uuid, :dom_id, :form_id, :form_question_id, :value, :form_answer_attachments_attributes
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
-
10
6
  belongs_to :form
11
7
  belongs_to :form_question
8
+ has_many :form_answer_attachments
9
+
10
+ accepts_nested_attributes_for :form_answer_attachments
12
11
 
13
12
  after_save do
14
13
  if form_question.input_type == :radio_button_tag and !dom_id.match(/_other/)
@@ -24,11 +23,11 @@ module ActiveadminSelleoCms
24
23
  end
25
24
  end
26
25
 
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
26
+ def self.files_for(form_uuid, dom_id)
27
+ if answer = self.where(form_uuid: form_uuid, dom_id: dom_id).first
28
+ answer.form_answer_attachments
30
29
  else
31
- nil
30
+ []
32
31
  end
33
32
  end
34
33
 
@@ -0,0 +1,11 @@
1
+ module ActiveadminSelleoCms
2
+ class ActiveadminSelleoCms::FormAnswerAttachment < ActiveRecord::Base
3
+ attr_accessible :form_answer_id, :data
4
+
5
+ has_attached_file :data,
6
+ :url => "/system/cms/form_answer_attachments/:id/:style_:basename.:extension",
7
+ :path => ":rails_root/public/system/cms/form_answer_attachments/:id/:style_:basename.:extension"
8
+
9
+ belongs_to :form_answer
10
+ end
11
+ end
@@ -5,11 +5,13 @@ module ActiveadminSelleoCms
5
5
  TYPE_SELECT = 1
6
6
  TYPE_FILE = 2
7
7
  TYPE_LABEL = 3
8
- TYPES = [TYPE_TEXT, TYPE_SELECT, TYPE_FILE, TYPE_LABEL]
9
- TYPE_NAMES = ["text question", "select question", "file upload", "label"]
8
+ TYPE_EMAIL = 4
9
+ TYPES = [TYPE_TEXT, TYPE_SELECT, TYPE_FILE, TYPE_LABEL, TYPE_EMAIL]
10
+ TYPE_NAMES = ["text question", "select question", "file upload", "label", "email"]
10
11
 
11
12
  belongs_to :form
12
13
  has_many :options, class_name: "FormQuestionOption", :order => "position"
14
+ has_many :answers, class_name: "FormAnswer"
13
15
 
14
16
  acts_as_list :scope => :form_id
15
17
 
@@ -26,7 +28,7 @@ module ActiveadminSelleoCms
26
28
  end
27
29
 
28
30
  def question_type_dictionary(int)
29
- ["text question", "select question", "file upload", "label"][int]
31
+ TYPE_NAMES[int]
30
32
  end
31
33
 
32
34
  end
@@ -60,6 +62,8 @@ module ActiveadminSelleoCms
60
62
  :file_field_tag
61
63
  elsif question_type == TYPE_LABEL
62
64
  :legend
65
+ elsif question_type == TYPE_EMAIL
66
+ :email_field_tag
63
67
  end
64
68
  end
65
69
 
@@ -5,7 +5,7 @@
5
5
  - unless @form_question.is_type?('label')
6
6
  = form.input :hint
7
7
  = form.input :is_required
8
- - unless @form_question.is_type?('file')
8
+ - unless @form_question.is_type?('file') or @form_question.is_type?('email')
9
9
  = form.input :is_multi
10
10
  - if @form_question.is_type?('select')
11
11
  = form.input :has_other_option
@@ -1,6 +1,7 @@
1
1
  = semantic_form_for [:admin, @form], url: admin_form_path(@form) do |form|
2
2
  = form.inputs "General options" do
3
3
  = form.input :title
4
+ = form.input :email, label: t("active_admin.cms.forms.email")
4
5
 
5
6
  %ol.draggable_questions_container
6
7
  - ActiveadminSelleoCms::FormQuestion::TYPES.each do |qtype|
@@ -0,0 +1,3 @@
1
+ %ol
2
+ - @form_answer.form_answer_attachments.each do |att|
3
+ %li= att.data_file_name
@@ -1,5 +1,7 @@
1
+ %legend= t("active_admin.cms.forms.upload_new_file")
1
2
  = semantic_form_for @form_answer, remote: true, html: { multipart: true } do |form|
2
3
 
3
- = form.inputs id: 'attachment_fields' do
4
- = form.input :data, hint: @form_answer.data_file_name
5
- = form.actions :submit
4
+ = form.semantic_fields_for :form_answer_attachments, form.object.form_answer_attachments.build do |attachment_form|
5
+ = attachment_form.input :data, hint: @form_answer.data_file_name
6
+
7
+ = form.action :submit, label: t("active_admin.cms.forms.upload_file"), as: :button
@@ -1,2 +1,2 @@
1
- $('#popup').effect('highlight');
2
- $('#popup form').html('<%= j render partial: 'form' %>');
1
+ $('#popup').dialog('close');
2
+ $('[data-question-id="<%= @form_answer.form_question.id %>"] .files').html('<%= j render partial: 'attachments' %>');
@@ -34,10 +34,15 @@
34
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
35
  </div>
36
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;" %>
37
+ <div class="file_upload">
38
+ <ol>
39
+ <% ActiveadminSelleoCms::FormAnswer.files_for(params[:form_uuid], dom_id(question)).each do |file| %>
40
+ <li><%= file.data_file_name %></li>
41
+ <% end %>
42
+ </ol>
43
+ </div>
44
+ <% elsif question.input_type == :legend %>
45
+ <legend><%= question.label %></legend>
41
46
  <% else %>
42
47
  <%= 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
48
  <% end %>
@@ -33,8 +33,8 @@
33
33
  </div>
34
34
  <% elsif [:file_field_tag].include? question.input_type %>
35
35
  <div class="file_upload" data-question-id="<%= question.id %>">
36
- <p></p>
37
- <%= button_to_function t("active_admin.cms.forms.select_file"), "fileUpload('#{dom_id(form)}', '#{dom_id(question)}', #{question.id})", style: "padding: 5px;" %>
36
+ <div class="files"></div>
37
+ <%= button_to_function t("active_admin.cms.forms.upload_new_file"), "fileUpload('#{dom_id(form)}', '#{dom_id(question)}', #{question.id})", style: "padding: 5px;" %>
38
38
  </div>
39
39
  <% elsif question.input_type == :legend %>
40
40
  <legend><%= question.label %></legend>
@@ -39,6 +39,10 @@ en:
39
39
  submit: "Submit form"
40
40
  print: "Print"
41
41
  pdf: "Download PDF"
42
- select_file: "Select file"
43
42
  other: "Other"
44
- required: "&nbsp;(required)"
43
+ required: "&nbsp;(required)"
44
+ email: "Delivery email"
45
+ email_subject: "New form has been submitted"
46
+ upload: "Upload"
47
+ upload_new_file: "Upload new file"
48
+ uploaded_files: "Uploaded files"
data/config/routes.rb CHANGED
@@ -11,6 +11,7 @@ Rails.application.routes.draw do
11
11
  resources :form_answers do
12
12
  collection do
13
13
  post :find_or_create
14
+ get :attachments
14
15
  end
15
16
  end
16
17
 
@@ -0,0 +1,5 @@
1
+ class AddEmailToForms < ActiveRecord::Migration
2
+ def change
3
+ add_column :activeadmin_selleo_cms_forms, :email, :string
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class CreateActiveadminSelleoCmsFormAnswerAttachments < ActiveRecord::Migration
2
+ def change
3
+ create_table :activeadmin_selleo_cms_form_answer_attachments do |t|
4
+ t.belongs_to :form_answer
5
+ t.attachment :data
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveadminSelleoCms
2
- VERSION = "0.0.52"
2
+ VERSION = "0.0.54"
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.52
4
+ version: 0.0.54
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -447,6 +447,7 @@ files:
447
447
  - app/assets/images/admin/remove.png
448
448
  - app/assets/images/admin/question_3.png
449
449
  - app/assets/images/admin/question_1.png
450
+ - app/assets/images/admin/question_4.png
450
451
  - app/assets/images/activeadmin-selleo-cms/Jcrop.gif
451
452
  - app/assets/javascripts/active_admin.js
452
453
  - app/assets/javascripts/ckeditor/config.js
@@ -525,6 +526,7 @@ files:
525
526
  - app/views/form_answers/_form.html.haml
526
527
  - app/views/form_answers/update.js.erb
527
528
  - app/views/form_answers/edit.html.haml
529
+ - app/views/form_answers/_attachments.html.haml
528
530
  - app/views/activeadmin_selleo_cms/form_mailer/form_submission.html.erb
529
531
  - app/modules/activeadmin_selleo_cms/content_translation.rb
530
532
  - app/models/translation.rb
@@ -543,6 +545,7 @@ files:
543
545
  - app/models/activeadmin_selleo_cms/form_question.rb
544
546
  - app/models/activeadmin_selleo_cms/form_question_option.rb
545
547
  - app/models/activeadmin_selleo_cms/image.rb
548
+ - app/models/activeadmin_selleo_cms/form_answer_attachment.rb
546
549
  - app/models/activeadmin_selleo_cms/related_item.rb
547
550
  - config/routes.rb
548
551
  - config/locales/cms.pl.yml
@@ -558,6 +561,7 @@ files:
558
561
  - db/migrate/20130207213528_change_activeadmin_selleo_cms_assets.rb
559
562
  - db/migrate/20130625104333_create_activeadmin_selleo_cms_forms.rb
560
563
  - db/migrate/20121204112326_create_ckeditor_assets.rb
564
+ - db/migrate/20130814151821_add_email_to_forms.rb
561
565
  - db/migrate/20130102113712_create_activeadmin_selleo_cms_assets.rb
562
566
  - db/migrate/20130206173233_change_activeadmin_selleo_cms_searches.rb
563
567
  - db/migrate/20121129160200_create_activeadmin_selleo_cms_locales.rb
@@ -568,6 +572,7 @@ files:
568
572
  - db/migrate/20130211151210_create_activeadmin_selleo_cms_related_items.rb
569
573
  - db/migrate/20121221164723_create_activeadmin_selleo_cms_searches.rb
570
574
  - db/migrate/20130108153415_add_redirect_to_first_sub_page.rb
575
+ - db/migrate/20130814184227_create_activeadmin_selleo_cms_form_answer_attachments.rb
571
576
  - db/migrate/20121206231053_create_activeadmin_selleo_cms_sections.rb
572
577
  - db/migrate/20130625104459_create_activeadmin_selleo_cms_form_question_options.rb
573
578
  - db/migrate/20121227222912_create_translations.rb