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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/admin/fields_controller.rb', line 43 def create as = field_params["as"] klass= Field.lookup_class(as).safe_constantize @field = if as.match?(/pair/) klass.create_pair("pair" => pair_params, "field" => field_params).first elsif as.present? 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
75 76 77 78 79 80 |
# File 'app/controllers/admin/fields_controller.rb', line 75 def destroy @field = Field.find(params["id"]) @field.destroy respond_with(@field) end |
#edit ⇒ Object
GET /fields/1/edit AJAX
35 36 37 38 |
# File 'app/controllers/admin/fields_controller.rb', line 35 def edit @field = Field.find(params["id"]) respond_with(@field) end |
#index ⇒ Object
GET /fields GET /fields.xml HTML
15 16 |
# File 'app/controllers/admin/fields_controller.rb', line 15 def index end |
#new ⇒ Object
GET /fields/new GET /fields/new.xml AJAX
28 29 30 31 |
# File 'app/controllers/admin/fields_controller.rb', line 28 def new @field = Field.new respond_with(@field) end |
#show ⇒ Object
GET /fields/1 GET /fields/1.xml HTML
21 22 23 |
# File 'app/controllers/admin/fields_controller.rb', line 21 def show respond_with(@field) end |
#sort ⇒ Object
POST /fields/sort
84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/admin/fields_controller.rb', line 84 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
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/controllers/admin/fields_controller.rb', line 97 def subform field = field_params as = field_params["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).safe_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
61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/admin/fields_controller.rb', line 61 def update if field_params["as"].match?(/pair/) @field = CustomFieldPair.update_pair("pair" => pair_params, "field" => field_params).first else @field = Field.find(params["id"]) @field.update(field_params) end respond_with(@field) end |