Class: Admin::FieldsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/fields_controller.rb

Overview

Fat Free CRM Copyright © 2008-2011 by Michael Dvorkin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.


Instance Method Summary collapse

Instance Method Details

#createObject

POST /fields POST /fields.xml AJAX




77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/admin/fields_controller.rb', line 77

def create
  @field = CustomField.new(params[:field])

  respond_to do |format|
    if @field.save
      format.js   # create.js.rjs
      format.xml  { render :xml => @field, :status => :created, :location => @field }
    else
      format.js   # create.js.rjs
      format.xml  { render :xml => @field.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /fields/1 DELETE /fields/1.xml HTML and AJAX




114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/controllers/admin/fields_controller.rb', line 114

def destroy
  @field = CustomField.find(params[:id])

  respond_to do |format|
    if @field.destroy
      format.js   # destroy.js.rjs
      format.xml  { head :ok }
    else
      format.js   # destroy.js.rjs
      format.xml  { render :xml => @field.errors, :status => :unprocessable_entity }
    end
  end

rescue ActiveRecord::RecordNotFound
  respond_to_not_found(:html, :js, :xml)
end

#editObject

GET /fields/1/edit AJAX




62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/admin/fields_controller.rb', line 62

def edit
  @field = Field.find(params[:id])

  if params[:previous].to_s =~ /(\d+)\z/
    @previous = Field.find($1)
  end

rescue ActiveRecord::RecordNotFound
  @previous ||= $1.to_i
  respond_to_not_found(:js)
end

#indexObject

GET /fields GET /fields.xml HTML




27
28
# File 'app/controllers/admin/fields_controller.rb', line 27

def index
end

#newObject

GET /fields/new GET /fields/new.xml AJAX




48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/admin/fields_controller.rb', line 48

def new
  @field = CustomField.new(:field_group_id => params[:field_group_id])

  respond_to do |format|
    format.js   # new.js.rjs
    format.xml  { render :xml => @field }
  end

rescue ActiveRecord::RecordNotFound # Kicks in if related asset was not found.
  respond_to_not_found(:html, :xml)
end

#showObject

GET /fields/1 GET /fields/1.xml HTML




33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/admin/fields_controller.rb', line 33

def show
  @custom_field = Field.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @custom_field }
  end

rescue ActiveRecord::RecordNotFound
  respond_to_not_found(:html, :xml)
end

#sortObject

POST /fields/sort




133
134
135
136
137
138
139
140
141
142
# File 'app/controllers/admin/fields_controller.rb', line 133

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.update_all({:position => index+1, :field_group_id => field_group_id}, {:id => id})
  end

  render :nothing => true
end

#updateObject

PUT /fields/1 PUT /fields/1.xml AJAX




94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/admin/fields_controller.rb', line 94

def update
  @field = Field.find(params[:id])

  respond_to do |format|
    if @field.update_attributes(params[:field])
      format.js
      format.xml  { head :ok }
    else
      format.js
      format.xml  { render :xml => @field.errors, :status => :unprocessable_entity }
    end
  end

rescue ActiveRecord::RecordNotFound
  respond_to_not_found(:js, :xml)
end