spina_contact_forms 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 271059450a3277a6d1854e61b063face82479e5f
4
- data.tar.gz: c931c3c6b968bb44bc2e65d211f545bd2e979522
3
+ metadata.gz: e4efda7177e4e030cd9b028cdac12a05f6bda54e
4
+ data.tar.gz: d3366ee2dbe8c832b37639719266ef67dddc2cb3
5
5
  SHA512:
6
- metadata.gz: aaddf19354d3b2449f4d35458ddc9504de6fa49e2765a9c24a6accd33c93727060a5eb8e75530eb8661887b83e537d763806c4e449391b646e756f4c481df2cb
7
- data.tar.gz: a15a718033f06f5a8add9a45bba5f4cbd0d30b1891741870fa92a2538d5d73b1d11182496810907899d3e328a05e5c5c1fc36731f51a1510cf4eb21704bd033c
6
+ metadata.gz: 7049bef23f24e8238c1376dff430c46b06eb38881f11b8f3fd8405551e05a7b80044eebe59b862d367cc67c444548b17a2a506e00098f2cf8d63dfa0f5596e65
7
+ data.tar.gz: 1363a1b9d2f361a485e829367edebd53c39553ea190b73eceffb4b38aac6e90d2a1ea0559cd4e9e5702cee01b810ab11a71b9b906ce2762699ded33e9ce537f8
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # SpinaContactForms
2
- This will add a contact form builder for spina. You can create form elements in the backend that will populate the form in the frontend.
2
+ This will add a contact form builder in spina. You can create form elements in the backend that will populate the form in the frontend.
3
+
4
+ This is a work in progress.
5
+
6
+ Please update to the latest version, anything under '0.1.2' will NOT work.
3
7
 
4
8
  ## Installation
5
9
  Add this line to your application's Gemfile:
@@ -33,7 +37,7 @@ Add the following to your theme's config file (config/initializers/themes/theme_
33
37
  theme.plugins = ['ContactForm']
34
38
  ```
35
39
 
36
- Copy and run the migrations
40
+ Copy and run the migrations, make sure to do this when upgrading as well, since new migragtions could be added.
37
41
  ```bash
38
42
  rake spina_contact_forms_engine:install:migrations
39
43
  rake db:migrate
@@ -43,13 +47,20 @@ rake db:migrate
43
47
  In your view, call `<%= spina_contact_form%>`
44
48
  That's it! Use Mailcatcher for local development, and test it out.
45
49
 
50
+ Contact Forms are scoped to the current_theme, so any changes to the theme name or setting a different theme for the account will cause a separate contact form to be loaded.
51
+
46
52
  ## Contributing
47
53
  Contributions are welcome! It is still in an early stage, and more features are required. Fork it, and create a pull request.
48
54
 
49
55
  ## Roadmap
50
56
  * Currently only text inputs and text areas are supported, select dropdowns, check boxes and radio buttons still needed
57
+ * Required elements do not yet work
58
+ * Use Form Object design pattern (for Active Model validations)
51
59
  * Internationalization needed
52
60
  * Create an install generator, which copies the migrations and view files
53
61
 
62
+ Further updates will be available in may.
63
+
64
+
54
65
  ## License
55
66
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -2,12 +2,16 @@ module Spina
2
2
  module Admin
3
3
  class ContactFormElementsController < AdminController
4
4
  layout 'spina/admin/admin'
5
+ before_action :set_element, only: [:edit, :update, :destroy]
5
6
 
6
7
  def error
7
8
  end
8
9
 
9
10
  def create
10
11
  @contact_form_element = ContactFormElement.new(contact_form_element_params)
12
+ @contact_form_element.theme = current_theme.name
13
+ @contact_form_element.position = Time.now.to_i
14
+
11
15
  respond_to do |format|
12
16
  if @contact_form_element.save
13
17
  format.html {redirect_to admin_contact_forms_path, notice: 'Form Element was successfully created.'}
@@ -18,10 +22,24 @@ module Spina
18
22
  end
19
23
  end
20
24
 
25
+ def sort
26
+ params[:list].each_pair do |parent_pos, parent_node|
27
+ ContactFormElement.find(parent_node[:id]).update(position: parent_pos)
28
+ end
29
+ head :ok
30
+ end
31
+
21
32
  def update
33
+ if @contact_form_element.update_attributes(contact_form_element_params)
34
+ redirect_to admin_contact_forms_path, notice: 'Form element updated.'
35
+ else
36
+ render :error
37
+ end
22
38
  end
23
39
 
24
40
  def destroy
41
+ @contact_form_element.destroy
42
+ redirect_to admin_contact_forms_path, notice: 'Form element deleted.'
25
43
  end
26
44
 
27
45
  private
@@ -30,6 +48,10 @@ module Spina
30
48
  params.require(:contact_form_element).permit(:label, :required, :input_type)
31
49
  end
32
50
 
51
+ def set_element
52
+ @contact_form_element = ContactFormElement.find(params[:id])
53
+ end
54
+
33
55
  end
34
56
  end
35
57
  end
@@ -7,13 +7,13 @@ module Spina
7
7
 
8
8
  def index
9
9
  @contact_form_element = ContactFormElement.new
10
- @contact_form_elements = ContactFormElement.all
10
+ @contact_form_elements = ContactFormElement.by_theme(current_theme)
11
11
  end
12
12
 
13
13
  private
14
14
 
15
15
  def set_breadcrumb
16
- add_breadcrumb t('plugins.ContactForm'), admin_contact_forms_path
16
+ add_breadcrumb t('contact_form.menu_title'), admin_contact_forms_path
17
17
  end
18
18
  end
19
19
  end
@@ -1,7 +1,7 @@
1
1
  module SpinaContactForms
2
2
  module ContactFormsHelper
3
3
  def spina_contact_form
4
- render :partial => 'spina/contact_forms/page', locals: {contact_form_elements: Spina::ContactFormElement.all }
4
+ render :partial => 'spina/contact_forms/page'
5
5
  end
6
6
 
7
7
  def spina_contact_form_input(name, type)
@@ -7,6 +7,9 @@
7
7
  class Spina::ContactFormElement < ApplicationRecord
8
8
  enum input_type: [:text_field, :text_area]
9
9
 
10
+ scope :sorted, -> { order('position') }
11
+ scope :by_theme, ->(theme) { where(theme: theme.name)}
12
+
10
13
  def required?
11
14
  self.required
12
15
  end
@@ -1,4 +1,7 @@
1
- %tr
2
- %td= element.label
3
- %td= element.input_type
4
- %td= element.required?
1
+ %li.dd-item{data: {id: element.id}}
2
+ %div.dd-item-inner
3
+ = link_to element.label, edit_admin_contact_form_element_path(element), remote: true, class: 'button button-link button-small sortable-link'
4
+ %span.pull-right
5
+ = link_to spina.admin_contact_form_element_path(element), method: :delete, data: {confirm: t('spina.delete_confirmation', subject: element.label)}, class: 'button button-small button-link button-danger dd-nodrag' do
6
+ = icon('cross')
7
+ = t('spina.delete')
@@ -0,0 +1,24 @@
1
+ .modal
2
+ = form_for [spina, :admin, @contact_form_element], url: spina.admin_contact_form_element_path do |f|
3
+ %header
4
+ = link_to '#', data: {dismiss: 'modal'} do
5
+ = icon('cross')
6
+
7
+ %h3
8
+ Contact Form Element
9
+
10
+ %section
11
+ .form-label Form Label
12
+ .form-control= f.text_field :label, placeholder: 'Form Label'
13
+ .form-label Required?
14
+ .form-control= f.check_box :required, data: {switch: 'true'}
15
+ .form-label Form Type
16
+ .form-control
17
+ .select-dropdown
18
+ = f.collection_select :input_type, Spina::ContactFormElement.input_types.map{ |el| [el.first, el.first.humanize] }, :first, :second
19
+
20
+ %footer
21
+ = link_to t('spina.cancel'), '#', data: {dismiss: 'modal'}
22
+ %button.primary{type: 'submit'}
23
+ = icon('check')
24
+ =t 'spina.save'
@@ -1,2 +1,2 @@
1
- $('#contact_form_elements').append("<%= j render 'spina/admin/contact_form_elements/contact_form_element', element: @contact_form_element %>");
1
+ $('#form_elements_list ol.dd-list').append("<%= j render 'spina/admin/contact_form_elements/contact_form_element', element: @contact_form_element %>");
2
2
  $('#contact_form_element_label').val('')
@@ -0,0 +1,3 @@
1
+ var modal = $("<%= j render 'edit' %>");
2
+ modal.modal();
3
+ $(document).trigger('page:change');
@@ -1,17 +1,14 @@
1
1
  %header#header
2
2
  = render partial: 'spina/admin/shared/breadcrumbs'
3
+ #header_actions
4
+ = link_to '#form_elements_list', class: 'button sort-switch', data: {change_order: t('spina.pages.change_order'), done_changing_order: t('spina.pages.done_changing_order')} do
5
+ = icon('random')
6
+ = t('spina.pages.change_order')
3
7
 
4
8
  = render 'form'
5
9
 
6
10
  .well
7
- .table-container
8
- %table.table
9
- %thead
10
- %tr
11
- %th Element Label
12
- %th Element Type
13
- %th Required Field?
14
-
15
- %tbody#contact_form_elements
16
- - @contact_form_elements.each do |element|
17
- = render 'spina/admin/contact_form_elements/contact_form_element', element: element
11
+ .dd#form_elements_list{data: {:"sort-url" => spina.sort_admin_contact_form_elements_url }}
12
+ %ol.dd-list
13
+ - @contact_form_elements.sorted.each do |element|
14
+ = render 'spina/admin/contact_form_elements/contact_form_element', element: element
@@ -1,5 +1,6 @@
1
+ - @contact_form_elements = Spina::ContactFormElement.by_theme(current_theme)
1
2
  = form_tag contact_forms_path, remote: true, id: 'spina_contact_form' do
2
- - contact_form_elements.each do |element|
3
+ - @contact_form_elements.each do |element|
3
4
  %label
4
5
  - if element.required?
5
6
  *
data/config/routes.rb CHANGED
@@ -2,9 +2,11 @@ Spina::Engine.routes.draw do
2
2
 
3
3
  namespace :admin, path: Spina.config.backend_path do
4
4
  resources :contact_forms, only: [:index]
5
- resources :contact_form_elements, except: [:show, :index]
5
+ resources :contact_form_elements, except: [:show, :index] do
6
+ post :sort, on: :collection
7
+ end
6
8
  end
7
9
 
8
10
  resources :contact_forms, only: [:create]
9
-
11
+
10
12
  end
@@ -0,0 +1,6 @@
1
+ class AddPositionAndThemeToSpinaContactFormElements < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :spina_contact_form_elements, :theme, :string
4
+ add_column :spina_contact_form_elements, :position, :integer
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module SpinaContactForms
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spina_contact_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-30 00:00:00.000000000 Z
11
+ date: 2017-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -74,7 +74,9 @@ files:
74
74
  - app/views/layouts/mailers/spina_contact_form.html.erb
75
75
  - app/views/layouts/mailers/spina_contact_form.text.erb
76
76
  - app/views/spina/admin/contact_form_elements/_contact_form_element.html.haml
77
+ - app/views/spina/admin/contact_form_elements/_edit.html.haml
77
78
  - app/views/spina/admin/contact_form_elements/create.js.erb
79
+ - app/views/spina/admin/contact_form_elements/edit.js.erb
78
80
  - app/views/spina/admin/contact_form_elements/error.js.erb
79
81
  - app/views/spina/admin/contact_forms/_form.html.haml
80
82
  - app/views/spina/admin/contact_forms/index.html.haml
@@ -87,6 +89,7 @@ files:
87
89
  - config/locales/contact_form_en.yml
88
90
  - config/routes.rb
89
91
  - db/migrate/20170329144025_create_spina_contact_form_elements.rb
92
+ - db/migrate/20170330144159_add_position_and_theme_to_spina_contact_form_elements.rb
90
93
  - lib/spina_contact_forms.rb
91
94
  - lib/spina_contact_forms/engine.rb
92
95
  - lib/spina_contact_forms/version.rb