radiant-forms-extension 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/README.md +117 -0
- data/Rakefile +137 -0
- data/VERSION +1 -0
- data/app/controllers/admin/forms_controller.rb +10 -0
- data/app/controllers/forms_controller.rb +35 -0
- data/app/models/form.rb +5 -0
- data/app/models/form_page.rb +7 -0
- data/app/models/response.rb +11 -0
- data/app/views/admin/forms/_fields.html.haml +56 -0
- data/app/views/admin/forms/_filters.html.haml +7 -0
- data/app/views/admin/forms/_form.html.haml +6 -0
- data/app/views/admin/forms/_header.html.haml +3 -0
- data/app/views/admin/forms/edit.html.haml +15 -0
- data/app/views/admin/forms/index.html.haml +20 -0
- data/app/views/admin/forms/new.html.haml +15 -0
- data/app/views/admin/forms/remove.html.haml +20 -0
- data/config/locales/en.yml +3 -0
- data/config/routes.rb +9 -0
- data/cucumber.yml +1 -0
- data/db/migrate/001_create_forms.rb +16 -0
- data/db/migrate/002_create_user_observer.rb +15 -0
- data/db/migrate/003_rename_output_to_content.rb +9 -0
- data/db/migrate/004_create_responses.rb +13 -0
- data/forms_extension.rb +24 -0
- data/lib/forms/admin_ui.rb +23 -0
- data/lib/forms/application_controller_extensions.rb +20 -0
- data/lib/forms/extension_methods.rb +14 -0
- data/lib/forms/page_extensions.rb +6 -0
- data/lib/forms/site_controller_extensions.rb +19 -0
- data/lib/forms/tags.rb +277 -0
- data/lib/tasks/forms_extension_tasks.rake +55 -0
- data/public/images/admin/extensions/form/form.png +0 -0
- data/radiant-forms-extension.gemspec +87 -0
- data/spec/controllers/forms_controller_spec.rb +150 -0
- data/spec/datasets/forms.rb +30 -0
- data/spec/lib/forms/extension_methods_spec.rb +41 -0
- data/spec/lib/forms/tags_spec.rb +122 -0
- data/spec/models/form_spec.rb +40 -0
- data/spec/models/response_spec.rb +31 -0
- data/spec/spec.opts +7 -0
- data/spec/spec_helper.rb +18 -0
- metadata +102 -0
data/.gitignore
ADDED
data/README.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# Radiant Forms Extension
|
2
|
+
|
3
|
+
This extension allows a developer to create forms which can take on multiple tasks
|
4
|
+
|
5
|
+
The idea was taken from the mailer extension, everything mail specific is used in [radiant-forms_mail-extension](http://github.com/squaretalent/radiant-forms_mail-extension)
|
6
|
+
|
7
|
+
Using forms 'DRY's up the process of creating and reusing forms across a site (well I think so at least).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
git clone git://github.com/squaretalent/radiant-forms-extension vendor/extensions/forms
|
12
|
+
rake radiant:extensions:forms:migrate
|
13
|
+
rake radiant:extensions:forms:update
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
A new tab will be present under design, a form has the following properties
|
18
|
+
|
19
|
+
* **title** reference for when you call the form tag (no spaces)
|
20
|
+
* **action** a specification action to submit the form to (posting to external sites etc)
|
21
|
+
* **redirect_to** location to send the redirection to, will go to posting page otherwise
|
22
|
+
* **body** output which will be shown on a radiant page
|
23
|
+
* **content** presentation of data after form is submitted (useful when sending emails)
|
24
|
+
* **config** configuration for the addons which will use that form
|
25
|
+
|
26
|
+
Include the form in a page using a radius tag
|
27
|
+
<r:form name="form_title" />
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Body
|
32
|
+
|
33
|
+
<ol>
|
34
|
+
<li>
|
35
|
+
<r:label for='contact[name]'>
|
36
|
+
<span class='title'>Your Name</span>
|
37
|
+
<r:text name='contact[name]' />
|
38
|
+
</r:label>
|
39
|
+
</li>
|
40
|
+
<li>
|
41
|
+
<r:label for='contact[email]'>
|
42
|
+
<span class='title'>Your Email</span>
|
43
|
+
<r:text name='contact[email]' />
|
44
|
+
</r:label>
|
45
|
+
</li>
|
46
|
+
<li>
|
47
|
+
<r:submit value='Send My Name' />
|
48
|
+
</li>
|
49
|
+
</ol>
|
50
|
+
|
51
|
+
### Content
|
52
|
+
|
53
|
+
<h2>Contact from <r:get name='contact[name]' /></h2>
|
54
|
+
|
55
|
+
<p>You can get back to them on <r:get name='contact[email]' /></p>
|
56
|
+
|
57
|
+
<p>Cheers, <br /> <strong>Cool Mailer</strong></p>
|
58
|
+
|
59
|
+
### Config
|
60
|
+
|
61
|
+
*assuming you have forms_mail installed as well*
|
62
|
+
|
63
|
+
mail:
|
64
|
+
field:
|
65
|
+
from: contact[email]
|
66
|
+
recipients: info@company.com
|
67
|
+
|
68
|
+
### Response
|
69
|
+
|
70
|
+
<html>
|
71
|
+
<head>Some Terribly Designed Radiant Page</head>
|
72
|
+
<body>
|
73
|
+
<r:forms:response>
|
74
|
+
|
75
|
+
<h2>Thank you for contacting us <r:get name='contact[name]' /></h2>
|
76
|
+
|
77
|
+
<!-- We need to clear the response, sort of like flash data -->
|
78
|
+
<r:clear />
|
79
|
+
|
80
|
+
</r:forms:response>
|
81
|
+
</body>
|
82
|
+
</html>
|
83
|
+
|
84
|
+
## Addons
|
85
|
+
|
86
|
+
### The Market
|
87
|
+
|
88
|
+
* [radiant-forms_mail-extension](http://github.com/squaretalent/radiant-forms_mail-extension) -
|
89
|
+
A showcase of how to use addons, allows you to send emails directly from the page
|
90
|
+
|
91
|
+
### Controller
|
92
|
+
|
93
|
+
Must be named **FormsBlahController** and contain an inherited FormsExtensionController of the same name
|
94
|
+
|
95
|
+
class FormsBlahController < FormsExtensionController
|
96
|
+
|
97
|
+
def create
|
98
|
+
# @form = Form which the data comes from
|
99
|
+
# @page = Page which submitted the form (data contains submitted information)
|
100
|
+
|
101
|
+
# return = {
|
102
|
+
# :hash => 'these details will be returned to the result page namespaced under blah'
|
103
|
+
# }
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
Any form configured with a **blah** block will know to call this controllers create method
|
109
|
+
|
110
|
+
blah:
|
111
|
+
key: value
|
112
|
+
another: value
|
113
|
+
|
114
|
+
### Functionality
|
115
|
+
|
116
|
+
I'm going to let you sort that out, you have the create action with input and output
|
117
|
+
from here you can decide how your form addon is going to behave.
|
data/Rakefile
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "radiant-forms-extension"
|
5
|
+
gem.summary = %Q{Forms Extension for Radiant CMS}
|
6
|
+
gem.description = %Q{Send data from a page to a form handler, extendable with addons}
|
7
|
+
gem.email = "dirk.kelly@squaretalent.com"
|
8
|
+
gem.homepage = "http://github.com/squaretalent/radiant-forms-extension"
|
9
|
+
gem.authors = ["dirkkelly"]
|
10
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
11
|
+
end
|
12
|
+
Jeweler::GemcutterTasks.new
|
13
|
+
rescue LoadError
|
14
|
+
puts "Jeweler (or a dependency) not available. This is only required if you plan to package forms as a gem."
|
15
|
+
end
|
16
|
+
|
17
|
+
# In rails 1.2, plugins aren't available in the path until they're loaded.
|
18
|
+
# Check to see if the rspec plugin is installed first and require
|
19
|
+
# it if it is. If not, use the gem version.
|
20
|
+
|
21
|
+
# Determine where the RSpec plugin is by loading the boot
|
22
|
+
unless defined? RADIANT_ROOT
|
23
|
+
ENV["RAILS_ENV"] = "test"
|
24
|
+
case
|
25
|
+
when ENV["RADIANT_ENV_FILE"]
|
26
|
+
require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
|
27
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
28
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
|
29
|
+
else
|
30
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'rake'
|
35
|
+
require 'rake/rdoctask'
|
36
|
+
require 'rake/testtask'
|
37
|
+
|
38
|
+
rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
|
39
|
+
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
|
40
|
+
require 'spec/rake/spectask'
|
41
|
+
require 'cucumber'
|
42
|
+
require 'cucumber/rake/task'
|
43
|
+
|
44
|
+
# Cleanup the RADIANT_ROOT constant so specs will load the environment
|
45
|
+
Object.send(:remove_const, :RADIANT_ROOT)
|
46
|
+
|
47
|
+
extension_root = File.expand_path(File.dirname(__FILE__))
|
48
|
+
|
49
|
+
task :default => :spec
|
50
|
+
task :stats => "spec:statsetup"
|
51
|
+
|
52
|
+
desc "Run all specs in spec directory"
|
53
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
54
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
55
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
56
|
+
end
|
57
|
+
|
58
|
+
task :features => 'spec:integration'
|
59
|
+
|
60
|
+
namespace :spec do
|
61
|
+
desc "Run all specs in spec directory with RCov"
|
62
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
63
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
64
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
65
|
+
t.rcov = true
|
66
|
+
t.rcov_opts = ['--exclude', 'spec', '--rails']
|
67
|
+
end
|
68
|
+
|
69
|
+
desc "Print Specdoc for all specs"
|
70
|
+
Spec::Rake::SpecTask.new(:doc) do |t|
|
71
|
+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
72
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
73
|
+
end
|
74
|
+
|
75
|
+
[:models, :controllers, :views, :helpers].each do |sub|
|
76
|
+
desc "Run the specs under spec/#{sub}"
|
77
|
+
Spec::Rake::SpecTask.new(sub) do |t|
|
78
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
79
|
+
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
desc "Run the Cucumber features"
|
84
|
+
Cucumber::Rake::Task.new(:integration) do |t|
|
85
|
+
t.fork = true
|
86
|
+
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
|
87
|
+
# t.feature_pattern = "#{extension_root}/features/**/*.feature"
|
88
|
+
t.profile = "default"
|
89
|
+
end
|
90
|
+
|
91
|
+
# Setup specs for stats
|
92
|
+
task :statsetup do
|
93
|
+
require 'code_statistics'
|
94
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models)
|
95
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views)
|
96
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
|
97
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
|
98
|
+
::CodeStatistics::TEST_TYPES << "Model specs"
|
99
|
+
::CodeStatistics::TEST_TYPES << "View specs"
|
100
|
+
::CodeStatistics::TEST_TYPES << "Controller specs"
|
101
|
+
::CodeStatistics::TEST_TYPES << "Helper specs"
|
102
|
+
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
|
103
|
+
end
|
104
|
+
|
105
|
+
namespace :db do
|
106
|
+
namespace :fixtures do
|
107
|
+
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
108
|
+
task :load => :environment do
|
109
|
+
require 'active_record/fixtures'
|
110
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
111
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
112
|
+
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
desc 'Generate documentation for the forms extension.'
|
120
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
121
|
+
rdoc.rdoc_dir = 'rdoc'
|
122
|
+
rdoc.title = 'FormsExtension'
|
123
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
124
|
+
rdoc.rdoc_files.include('README')
|
125
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
126
|
+
end
|
127
|
+
|
128
|
+
# For extensions that are in transition
|
129
|
+
desc 'Test the forms extension.'
|
130
|
+
Rake::TestTask.new(:test) do |t|
|
131
|
+
t.libs << 'lib'
|
132
|
+
t.pattern = 'test/**/*_test.rb'
|
133
|
+
t.verbose = true
|
134
|
+
end
|
135
|
+
|
136
|
+
# Load any custom rakefiles for extension
|
137
|
+
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Admin::FormsController < Admin::ResourceController
|
2
|
+
|
3
|
+
skip_before_filter :verify_authenticity_token, :only => :create
|
4
|
+
|
5
|
+
only_allow_access_to :index, :show, :new, :create, :edit, :update, :remove, :destroy,
|
6
|
+
:when => [ :designer, :admin ],
|
7
|
+
:denied_url => { :controller => 'admin/pages', :action => 'index' },
|
8
|
+
:denied_message => 'You must have designer privileges to perform this action.'
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class FormsController < ApplicationController
|
2
|
+
|
3
|
+
no_login_required
|
4
|
+
|
5
|
+
skip_before_filter :verify_authenticity_token
|
6
|
+
|
7
|
+
# POST /forms/1
|
8
|
+
#----------------------------------------------------------------------------
|
9
|
+
def create
|
10
|
+
@page = Page.find(params[:page_id])
|
11
|
+
@form = Form.find(params[:form_id])
|
12
|
+
@page.data = params
|
13
|
+
|
14
|
+
response = current_response
|
15
|
+
response.result = params
|
16
|
+
|
17
|
+
begin
|
18
|
+
@form[:config] = YAML::load("--- !map:HashWithIndifferentAccess\n"+@form[:config]).symbolize_keys
|
19
|
+
rescue
|
20
|
+
raise "Form '#{@form.title}' has not been configured"
|
21
|
+
end
|
22
|
+
|
23
|
+
@form[:config].each do |ext, config|
|
24
|
+
ext_controller = ("Forms#{ext.to_s.capitalize}Controller".constantize).new(@form, @page)
|
25
|
+
response.result = response.result.merge({ "#{ext}_ext" => ext_controller.create })
|
26
|
+
end
|
27
|
+
|
28
|
+
if response.save
|
29
|
+
redirect_to (@form.redirect_to.nil? ? @page.url : @form.redirect_to)
|
30
|
+
else
|
31
|
+
raise "Form '#{@form.name}' could not be submitted. Sorry"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/app/models/form.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
- form_for [:admin, @form], :html => {:onsubmit_status => onsubmit_status(@form)}, :html => { :enctype => 'multipart/form-data' } do |form_form|
|
2
|
+
.form_top
|
3
|
+
- render_region :form_top do |form_top|
|
4
|
+
-# empty
|
5
|
+
|
6
|
+
.form_area
|
7
|
+
- render_region :form do |form|
|
8
|
+
- form.edit_title do
|
9
|
+
%p.title
|
10
|
+
= form_form.label :title, 'Title'
|
11
|
+
= form_form.text_field :title, :class => 'textbox activate', :maxlength => 255
|
12
|
+
|
13
|
+
.drawer
|
14
|
+
.drawer_contents#attributes
|
15
|
+
%table.fieldset
|
16
|
+
%tr
|
17
|
+
%th.label= form_form.label :action, 'Action'
|
18
|
+
%td.field= form_form.text_field :action, :class => 'textbox', :maxlength => 100, :size => 100
|
19
|
+
%tr
|
20
|
+
%th.label= form_form.label :redirect_to, 'Redirect To'
|
21
|
+
%td.field= form_form.text_field :redirect_to, :class => 'textbox', :maxlength => 100, :size => 100
|
22
|
+
.drawer_handle
|
23
|
+
%a.toggle{:href=>'#attributes', :rel=>"toggle[attributes]", :class=>"#{(meta_errors? ? 'less' : 'more')}"}= meta_label
|
24
|
+
|
25
|
+
- form.edit_content do
|
26
|
+
#tab_control
|
27
|
+
#tabs.tabs
|
28
|
+
#parts.pages
|
29
|
+
#form_body.page{'data-caption'=>'body'}
|
30
|
+
= render '/admin/forms/filters'
|
31
|
+
= form_form.text_area :body, :class => 'textarea large', :style => 'width: 100%'
|
32
|
+
#form_content.page{'data-caption'=>'content'}
|
33
|
+
= render '/admin/forms/filters'
|
34
|
+
= form_form.text_area :content, :class => 'textarea large', :style => 'width: 100%'
|
35
|
+
#form_config.page{'data-caption'=>'config'}
|
36
|
+
%p
|
37
|
+
%span.reference_links
|
38
|
+
Available
|
39
|
+
= form_form.text_area :config, :class => 'textarea large', :style => 'width: 100%'
|
40
|
+
|
41
|
+
.form_bottom
|
42
|
+
- render_region :form_bottom do |form_bottom|
|
43
|
+
- form_bottom.edit_buttons do
|
44
|
+
%p.buttons{:style=>"clear: left"}
|
45
|
+
= save_model_button(@form)
|
46
|
+
= save_model_and_continue_editing_button(@form)
|
47
|
+
or
|
48
|
+
= link_to t('cancel'), admin_forms_url
|
49
|
+
- form_bottom.edit_timestamp do
|
50
|
+
%p.updated_line
|
51
|
+
= updated_stamp @form
|
52
|
+
|
53
|
+
- content_for :page_css do
|
54
|
+
:sass
|
55
|
+
th.label
|
56
|
+
:width 75px !important
|
@@ -0,0 +1,7 @@
|
|
1
|
+
%p
|
2
|
+
%span.reference_links
|
3
|
+
= t('reference')
|
4
|
+
%span#filter_reference_link_body
|
5
|
+
= link_to t('filter'), '/admin/reference/filters?filter_name=Textile', :class => 'popup'
|
6
|
+
%span#tag_reference_link_body
|
7
|
+
= link_to t('available_tags'), '/admin/reference/tags', :class => 'popup'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
- body_classes << "reversed"
|
2
|
+
|
3
|
+
- render_region :main do |main|
|
4
|
+
- main.edit_header do
|
5
|
+
%h1= "Edit Form"
|
6
|
+
|
7
|
+
- main.edit_form do
|
8
|
+
= render :partial => 'fields'
|
9
|
+
= hidden_field_tag 'page_part_index_field'
|
10
|
+
|
11
|
+
- content_for :page_css do
|
12
|
+
:sass
|
13
|
+
.tab
|
14
|
+
.close
|
15
|
+
:display none
|
@@ -0,0 +1,20 @@
|
|
1
|
+
- @page_title = 'Forms - ' + default_page_title
|
2
|
+
|
3
|
+
.outset
|
4
|
+
= render 'header'
|
5
|
+
#forms_table
|
6
|
+
%table.index
|
7
|
+
%thead
|
8
|
+
%tr
|
9
|
+
%th.form Form
|
10
|
+
%th.modify Modify
|
11
|
+
%tbody#forms_table_body
|
12
|
+
- if @forms.size != 0
|
13
|
+
= render :partial => 'form', :collection => @forms
|
14
|
+
-else
|
15
|
+
%tr
|
16
|
+
%td.empty{:colspan => 2} No Forms
|
17
|
+
|
18
|
+
#actions
|
19
|
+
%ul
|
20
|
+
%li= link_to "New Form", new_admin_form_path
|
@@ -0,0 +1,15 @@
|
|
1
|
+
- body_classes << "reversed"
|
2
|
+
|
3
|
+
- render_region :main do |main|
|
4
|
+
- main.edit_header do
|
5
|
+
%h1= "New Form"
|
6
|
+
|
7
|
+
- main.edit_form do
|
8
|
+
= render :partial => 'fields'
|
9
|
+
= hidden_field_tag 'page_part_index_field'
|
10
|
+
|
11
|
+
- content_for :page_css do
|
12
|
+
:sass
|
13
|
+
.tab
|
14
|
+
.close
|
15
|
+
:display none
|
@@ -0,0 +1,20 @@
|
|
1
|
+
%h1 Remove Form
|
2
|
+
|
3
|
+
%p
|
4
|
+
Are you sure you want to
|
5
|
+
%strong.warning permanently remove
|
6
|
+
the following form?
|
7
|
+
|
8
|
+
%table.index#form{ :cellpadding => "0", :cellspacing => "0", :border => "0" }
|
9
|
+
%tbody
|
10
|
+
%tr.node.level-1{ :onmouseover => "Element.addClassName(this, 'highlight');", :onmouseout => "Element.removeClassName(this, 'highlight');" }
|
11
|
+
%td.asset
|
12
|
+
= image('form.png', :alt => '')
|
13
|
+
= @form.title
|
14
|
+
|
15
|
+
|
16
|
+
- form_for [:admin, @form], :html => { :method => 'delete', :onsubmit_status => "Removing Form…" } do
|
17
|
+
%p.buttons
|
18
|
+
%input.button{ :type => "submit", :value => "Delete Form" }
|
19
|
+
or
|
20
|
+
= link_to 'Cancel', admin_forms_path
|
data/config/routes.rb
ADDED
data/cucumber.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
default: --format progress features --tags ~@proposed,~@in_progress
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateForms < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :forms do |t|
|
4
|
+
t.string :title
|
5
|
+
t.string :action
|
6
|
+
t.string :redirect_to
|
7
|
+
t.text :body
|
8
|
+
t.text :output
|
9
|
+
t.text :config
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :forms
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateUserObserver < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :forms, :created_by, :integer
|
4
|
+
add_column :forms, :updated_by, :integer
|
5
|
+
add_column :forms, :created_at, :datetime
|
6
|
+
add_column :forms, :updated_at, :datetime
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.down
|
10
|
+
remove_column :forms, :created_by
|
11
|
+
remove_column :forms, :updated_by
|
12
|
+
remove_column :forms, :created_at
|
13
|
+
remove_column :forms, :updated_at
|
14
|
+
end
|
15
|
+
end
|
data/forms_extension.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class FormsExtension < Radiant::Extension
|
2
|
+
version '2.0'
|
3
|
+
description 'Radiant Form extension. Site wide, useful form management'
|
4
|
+
url 'http://github.com/squaretalent/radiant-forms-extension'
|
5
|
+
|
6
|
+
extension_config do |config|
|
7
|
+
if RAILS_ENV == :test
|
8
|
+
config.gem 'rr', :version => '0.10.11'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def activate
|
13
|
+
Radiant::AdminUI.send(:include, Forms::AdminUI) unless defined? admin.form
|
14
|
+
admin.form = Radiant::AdminUI.load_default_form_regions
|
15
|
+
|
16
|
+
Page.class_eval { include Forms::Tags, Forms::PageExtensions }
|
17
|
+
ApplicationController.send(:include, Forms::ApplicationControllerExtensions)
|
18
|
+
SiteController.send(:include, Forms::SiteControllerExtensions)
|
19
|
+
|
20
|
+
tab 'Design' do
|
21
|
+
add_item 'Forms', '/admin/forms', :after => 'Snippets'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Forms
|
2
|
+
module AdminUI
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
attr_accessor :form
|
7
|
+
alias_method :forms, :form
|
8
|
+
protected
|
9
|
+
def load_default_form_regions
|
10
|
+
returning OpenStruct.new do |form|
|
11
|
+
form.edit = Radiant::AdminUI::RegionSet.new do |edit|
|
12
|
+
edit.main.concat %w{edit_header edit_form}
|
13
|
+
edit.form.concat %w{edit_title edit_content}
|
14
|
+
edit.form_bottom.concat %w{edit_buttons edit_timestamp}
|
15
|
+
end
|
16
|
+
form.new = form.edit
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Forms
|
2
|
+
module ApplicationControllerExtensions
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval {
|
5
|
+
helper_method :current_response
|
6
|
+
|
7
|
+
def current_response
|
8
|
+
if request.session[:form_response]
|
9
|
+
@response = Response.find(request.session[:form_response])
|
10
|
+
else
|
11
|
+
@response = Response.create
|
12
|
+
request.session = @response.id
|
13
|
+
end
|
14
|
+
|
15
|
+
@response
|
16
|
+
end
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|