activeadmin-selleo-cms 0.0.45 → 0.0.46
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/activeadmin-selleo-cms/forms.storage.js +46 -16
- data/app/controllers/form_answers_controller.rb +19 -0
- data/app/controllers/forms_controller.rb +4 -0
- data/app/models/activeadmin_selleo_cms/form_answer.rb +16 -0
- data/app/models/activeadmin_selleo_cms/form_question.rb +1 -1
- data/app/models/activeadmin_selleo_cms/section.rb +4 -2
- data/app/views/admin/form_questions/_form.html.haml +1 -0
- data/app/views/forms/_form.html.erb +14 -5
- data/app/views/forms/download.pdf.erb +2 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20130708195545_create_activeadmin_selleo_cms_form_answers.rb +12 -0
- data/lib/activeadmin-selleo-cms/version.rb +1 -1
- metadata +4 -1
@@ -1,26 +1,56 @@
|
|
1
|
+
function generateUUID(){
|
2
|
+
var d = new Date().getTime();
|
3
|
+
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
4
|
+
var r = (d + Math.random()*16)%16 | 0;
|
5
|
+
d = Math.floor(d/16);
|
6
|
+
return (c=='x' ? r : (r&0x7|0x8)).toString(16);
|
7
|
+
});
|
8
|
+
return uuid;
|
9
|
+
};
|
10
|
+
|
11
|
+
function submitAnswer(form_id, input, value){
|
12
|
+
$.post('/form_answers', {
|
13
|
+
form_answer: {
|
14
|
+
form_uuid: localStorage[form_id],
|
15
|
+
dom_id: $(input).attr('id'),
|
16
|
+
form_id: $(input).closest('form').data('form-id'),
|
17
|
+
form_question_id: $(input).data('form-question-id'),
|
18
|
+
value: value
|
19
|
+
}
|
20
|
+
})
|
21
|
+
}
|
22
|
+
|
1
23
|
function setupCmsForm(form_id) {
|
2
24
|
$('#'+form_id+' .required fieldset [type="radio"]:first,[type="checkbox"]:first').attr('required','true');
|
3
25
|
$('#'+form_id).validate();
|
4
26
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
27
|
+
if (localStorage[form_id] == undefined) {
|
28
|
+
localStorage[form_id] = generateUUID();
|
29
|
+
}
|
30
|
+
|
31
|
+
$.get('/form_answers.json', {
|
32
|
+
form_uuid: localStorage[form_id]
|
33
|
+
}).success(function(resp){
|
34
|
+
$.each(resp, function(){
|
35
|
+
if (this["value"] != null) {
|
36
|
+
var form_elem = $('#'+this["dom_id"]);
|
37
|
+
if ( ($(form_elem).attr('type') == 'checkbox') || ($(form_elem).attr('type') == 'radio') ) {
|
38
|
+
$(form_elem).attr('checked', true);
|
39
|
+
} else if ($(form_elem).attr('type') == 'file') {
|
40
|
+
// ??
|
41
|
+
} else {
|
42
|
+
$(form_elem).val(this["value"]);
|
43
|
+
}
|
13
44
|
}
|
14
|
-
}
|
45
|
+
})
|
15
46
|
});
|
16
47
|
|
17
48
|
$('#' + form_id + ' input, textarea').change(function(){
|
18
|
-
|
19
|
-
localStorage[$(this).attr('id')] = $(this).is(':checked');
|
20
|
-
} else if ($(this).attr('type') == 'file') {
|
49
|
+
if ($(this).attr('type') == 'file') {
|
21
50
|
// ??
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
51
|
+
} else if ( ($(this).attr('type') == 'checkbox') || ($(this).attr('type') == 'radio') ) {
|
52
|
+
submitAnswer(form_id, this, $(this).is(':checked'))
|
53
|
+
} else {
|
54
|
+
submitAnswer(form_id, this, $(this).val())
|
55
|
+
}});
|
26
56
|
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class FormAnswersController < ApplicationController
|
2
|
+
|
3
|
+
respond_to :html, :json
|
4
|
+
|
5
|
+
def create
|
6
|
+
params[:form_answer] ||= {}
|
7
|
+
if answer = ActiveadminSelleoCms::FormAnswer.where(form_uuid: params[:form_answer][:form_uuid], dom_id: params[:form_answer][:dom_id]).first
|
8
|
+
answer.update_attribute(:value, params[:form_answer][:value])
|
9
|
+
else
|
10
|
+
ActiveadminSelleoCms::FormAnswer.create(params[:form_answer])
|
11
|
+
end
|
12
|
+
render nothing: true
|
13
|
+
end
|
14
|
+
|
15
|
+
def index
|
16
|
+
respond_with ActiveadminSelleoCms::FormAnswer.where(form_uuid: params[:form_uuid])
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActiveadminSelleoCms
|
2
|
+
class FormAnswer < ActiveRecord::Base
|
3
|
+
attr_accessible :form_uuid, :dom_id, :form_id, :form_question_id, :value
|
4
|
+
validates_presence_of :form_uuid, :dom_id
|
5
|
+
|
6
|
+
belongs_to :form
|
7
|
+
belongs_to :form_question
|
8
|
+
|
9
|
+
after_save do
|
10
|
+
if form_question.input_type == :radio_button_tag and !dom_id.match(/_other/)
|
11
|
+
FormAnswer.where(form_uuid: form_uuid, form_question_id: form_question_id).where("id <> ? AND dom_id NOT LIKE '%_other%'", id).destroy_all
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -13,7 +13,7 @@ module ActiveadminSelleoCms
|
|
13
13
|
acts_as_list :scope => :form_id
|
14
14
|
|
15
15
|
attr_accessor :order
|
16
|
-
attr_accessible :title, :question_type, :position, :is_required, :is_multi, :has_other_option, :options_attributes, :order
|
16
|
+
attr_accessible :title, :question_type, :position, :is_required, :is_multi, :has_other_option, :options_attributes, :order, :hint
|
17
17
|
accepts_nested_attributes_for :options, allow_destroy: true
|
18
18
|
|
19
19
|
validates :title, presence: true, uniqueness: {scope: :form_id}
|
@@ -63,8 +63,10 @@ module ActiveadminSelleoCms
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
doc.css('form[data-form-id]').each do |
|
67
|
-
|
66
|
+
doc.css('form[data-form-id]').each do |form_tag|
|
67
|
+
if form = Form.find_by_id(form_tag.attributes["data-form-id"].to_s)
|
68
|
+
form_tag.replace av.render(:file => File.join(ActiveadminSelleoCms::Engine.root, 'app/views/forms/_form'), :layout => nil, :locals => { :form => form })
|
69
|
+
end
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
= semantic_nested_form_for [:admin, @form, @form_question], url: (@form_question.new_record? ? admin_form_form_questions_path(@form.id) : admin_form_form_question_path(@form.id, @form_question.id)), remote: true, html: {id: "form_question_form"} do |form|
|
2
2
|
= form.inputs "Options" do
|
3
3
|
= form.input :title
|
4
|
+
= form.input :hint
|
4
5
|
= form.input :is_required
|
5
6
|
- unless @form_question.is_type?('file')
|
6
7
|
= form.input :is_multi
|
@@ -1,21 +1,30 @@
|
|
1
|
-
<%= form_tag '/forms', multipart: true, id: dom_id(form) do %>
|
1
|
+
<%= form_tag '/forms', multipart: true, id: dom_id(form), data: {form_id: form.id} do %>
|
2
|
+
<ol class="questions">
|
2
3
|
<% form.questions.each do |question| %>
|
4
|
+
<li class="question <%= question.input_type %>">
|
3
5
|
<%= label_tag dom_id(question), question.title %>
|
6
|
+
<% if question.hint.present? %>
|
7
|
+
<p class="hint"><%= question.hint %></p>
|
8
|
+
<% end %>
|
4
9
|
<% if [:check_box_tag].include? question.input_type %>
|
5
10
|
<% question.options.each do |option| %>
|
6
|
-
<%= send(question.input_type, "#{dom_id(question)}[]", option.id, false, required: question.is_required, id: dom_id(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} ) %>
|
7
12
|
<%= label_tag dom_id(option), option.title %>
|
8
13
|
<% end %>
|
9
14
|
<% elsif [:radio_button_tag].include? question.input_type %>
|
10
15
|
<% question.options.each do |option| %>
|
11
|
-
<%= send(question.input_type, dom_id(question), option.id, false, required: question.is_required, id: dom_id(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}) %>
|
12
17
|
<%= label_tag dom_id(option), option.title %>
|
13
18
|
<% end %>
|
19
|
+
<% 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}) %>
|
14
21
|
<% else %>
|
15
|
-
<%= send(question.input_type, dom_id(question), "", required: question.is_required) %>
|
22
|
+
<%= send(question.input_type, dom_id(question), "", required: question.is_required, data: {form_question_id: question.id}) %>
|
16
23
|
<% end %>
|
17
|
-
<%= text_field_tag "#{dom_id(question)}_other" if question.has_other_option %>
|
24
|
+
<%= text_field_tag "#{dom_id(question)}_other", "", data: {form_question_id: question.id} if question.has_other_option %>
|
25
|
+
</li>
|
18
26
|
<% end %>
|
27
|
+
</ol>
|
19
28
|
<% end %>
|
20
29
|
|
21
30
|
<%= button_to_function "Print", "$('##{dom_id(form)}').printElement({printMode:'popup'});" %>
|
@@ -6,6 +6,8 @@
|
|
6
6
|
<%= send(question.input_type, dom_id(question), option.id, Array(params[dom_id(question)]).include?(option.id.to_s)) %>
|
7
7
|
<%= label_tag dom_id(option), option.title %>
|
8
8
|
<% end %>
|
9
|
+
<% elsif [:file_field_tag].include? question.input_type %>
|
10
|
+
<%= send(question.input_type, dom_id(question), required: question.is_required) %>
|
9
11
|
<% else %>
|
10
12
|
<%= send(question.input_type, dom_id(question), params[dom_id(question)]) %>
|
11
13
|
<% end %>
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateActiveadminSelleoCmsFormAnswers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :activeadmin_selleo_cms_form_answers do |t|
|
4
|
+
t.string :form_uuid
|
5
|
+
t.integer :form_id
|
6
|
+
t.integer :form_question_id
|
7
|
+
t.string :dom_id
|
8
|
+
t.string :value
|
9
|
+
t.attachment :data
|
10
|
+
end
|
11
|
+
end
|
12
|
+
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.
|
4
|
+
version: 0.0.46
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -406,6 +406,7 @@ files:
|
|
406
406
|
- app/controllers/forms_controller.rb
|
407
407
|
- app/controllers/cms_controller.rb
|
408
408
|
- app/controllers/locales_controller.rb
|
409
|
+
- app/controllers/form_answers_controller.rb
|
409
410
|
- app/controllers/searches_controller.rb
|
410
411
|
- app/admin/translation.rb
|
411
412
|
- app/admin/active_admin/views_helper.rb
|
@@ -499,6 +500,7 @@ files:
|
|
499
500
|
- app/models/ckeditor/asset.rb
|
500
501
|
- app/models/ckeditor/picture.rb
|
501
502
|
- app/models/ckeditor/attachment_file.rb
|
503
|
+
- app/models/activeadmin_selleo_cms/form_answer.rb
|
502
504
|
- app/models/activeadmin_selleo_cms/section.rb
|
503
505
|
- app/models/activeadmin_selleo_cms/attachment.rb
|
504
506
|
- app/models/activeadmin_selleo_cms/asset.rb
|
@@ -529,6 +531,7 @@ files:
|
|
529
531
|
- db/migrate/20121129160200_create_activeadmin_selleo_cms_locales.rb
|
530
532
|
- db/migrate/20130109132745_add_fields_to_page.rb
|
531
533
|
- db/migrate/20130601141800_add_position_to_related_items.rb
|
534
|
+
- db/migrate/20130708195545_create_activeadmin_selleo_cms_form_answers.rb
|
532
535
|
- db/migrate/20130531154539_add_position_to_assets.rb
|
533
536
|
- db/migrate/20130211151210_create_activeadmin_selleo_cms_related_items.rb
|
534
537
|
- db/migrate/20121221164723_create_activeadmin_selleo_cms_searches.rb
|