Class: Admin::FieldsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::FieldsController
- Defined in:
- app/controllers/admin/fields_controller.rb
Overview
Copyright © 2008-2013 Michael Dvorkin and contributors.
Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php
Instance Method Summary collapse
-
#create ⇒ Object
POST /fields POST /fields.xml AJAX —————————————————————————-.
-
#destroy ⇒ Object
DELETE /fields/1 DELETE /fields/1.xml HTML and AJAX —————————————————————————-.
-
#edit ⇒ Object
GET /fields/1/edit AJAX —————————————————————————-.
-
#index ⇒ Object
GET /fields GET /fields.xml HTML —————————————————————————-.
-
#new ⇒ Object
GET /fields/new GET /fields/new.xml AJAX —————————————————————————-.
-
#show ⇒ Object
GET /fields/1 GET /fields/1.xml HTML —————————————————————————-.
-
#sort ⇒ Object
POST /fields/sort —————————————————————————-.
-
#subform ⇒ Object
GET /fields/subform —————————————————————————-.
-
#update ⇒ Object
PUT /fields/1 PUT /fields/1.xml AJAX —————————————————————————-.
Instance Method Details
#create ⇒ Object
POST /fields POST /fields.xml AJAX
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/admin/fields_controller.rb', line 42 def create as = field_params[:as] @field = if as =~ /pair/ CustomFieldPair.create_pair(params).first elsif as.present? klass = Field.lookup_class(as).classify.constantize klass.create(field_params) else Field.new(field_params).tap(&:valid?) end respond_with(@field) end |
#destroy ⇒ Object
DELETE /fields/1 DELETE /fields/1.xml HTML and AJAX
74 75 76 77 78 79 |
# File 'app/controllers/admin/fields_controller.rb', line 74 def destroy @field = Field.find(params[:id]) @field.destroy respond_with(@field) end |
#edit ⇒ Object
GET /fields/1/edit AJAX
34 35 36 37 |
# File 'app/controllers/admin/fields_controller.rb', line 34 def edit @field = Field.find(params[:id]) respond_with(@field) end |
#index ⇒ Object
GET /fields GET /fields.xml HTML
14 15 |
# File 'app/controllers/admin/fields_controller.rb', line 14 def index end |
#new ⇒ Object
GET /fields/new GET /fields/new.xml AJAX
27 28 29 30 |
# File 'app/controllers/admin/fields_controller.rb', line 27 def new @field = Field.new respond_with(@field) end |
#show ⇒ Object
GET /fields/1 GET /fields/1.xml HTML
20 21 22 |
# File 'app/controllers/admin/fields_controller.rb', line 20 def show respond_with(@field) end |
#sort ⇒ Object
POST /fields/sort
83 84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/admin/fields_controller.rb', line 83 def sort field_group_id = params[:field_group_id].to_i field_ids = params["fields_field_group_#{field_group_id}"] || [] field_ids.each_with_index do |id, index| Field.where(id: id).update_all(position: index + 1, field_group_id: field_group_id) end render nothing: true end |
#subform ⇒ Object
GET /fields/subform
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/controllers/admin/fields_controller.rb', line 96 def subform field = field_params as = field[:as] @field = if (id = field[:id]).present? Field.find(id).tap { |f| f.as = as } else field_group_id = field[:field_group_id] klass = Field.lookup_class(as).classify.constantize klass.new(field_group_id: field_group_id, as: as) end respond_with(@field) do |format| format.html { render partial: 'admin/fields/subform' } end end |
#update ⇒ Object
PUT /fields/1 PUT /fields/1.xml AJAX
60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/admin/fields_controller.rb', line 60 def update if field_params[:as] =~ /pair/ @field = CustomFieldPair.update_pair(params).first else @field = Field.find(params[:id]) @field.update_attributes(field_params) end respond_with(@field) end |