Class: Admin::FormFieldTypesController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/form_field_types_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/admin/form_field_types_controller.rb', line 35

def create
  add_sid(:form_field_type)
  @form_field_type = FormFieldType.new(params[:form_field_type])
  @form_field_type.has_asset = ["file", "image"].include?(@form_field_type.field_type) ? 1 : 0
  if @form_field_type.save
    Activity.add(_sid, "Form field type '#{@form_field_type.name}' added", current_user, "Form")
    redirect_to "/admin/form_field_types/#{@form_field_type.id}", :notice => "Created new field type"
  else
    render :action => 'new'
  end
end

#destroyObject



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

def destroy
  @form_field_type = FormFieldType.find_sys_id(_sid, params[:id])
  if @form_field_type.form_fields.size>0
    redirect_to "/admin/form_field_types/#{@form_field_type.id}", :notice=>"Cannot delete because form fields are using this type" and return
  end

  Activity.add(_sid, "Form field type '#{@form_field_type.name}' deleted", current_user, "Form")
  @form_field_type.destroy
  redirect_to "/admin/form_field_types", :notice=>"Deleted field type"
end

#editObject



47
48
49
# File 'app/controllers/admin/form_field_types_controller.rb', line 47

def edit
  @form_field_type = FormFieldType.find_sys_id(_sid, params[:id])
end

#editoptionsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/admin/form_field_types_controller.rb', line 3

def editoptions
  @form_field_type = FormFieldType.find_sys_id(_sid, params[:id])
  redirect_to "/admin/form_field_types" and return unless @form_field_type

  @referer = params[:referer] || request.referer 
  if request.put?
    options = params[:form_field_type][:options]

    if params[:text_options].not_blank?
      options += "|" if options.not_blank?
      options += params[:text_options].split("\n").collect { |s| s.is_blank? ? nil : s.strip }.compact.join('|')
    end
    if @form_field_type.update_attributes(:options=>options)
      redirect_to params[:referer], :notice=>"Options saved"
      return
    end
  end
end

#indexObject



22
23
24
# File 'app/controllers/admin/form_field_types_controller.rb', line 22

def index
  @form_field_types = FormFieldType.sys(_sid).all
end

#newObject



30
31
32
33
# File 'app/controllers/admin/form_field_types_controller.rb', line 30

def new
  @form_field_type = FormFieldType.new
  @form_field_type.allow_blank = 1
end

#showObject



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

def show
  @form_field_type = FormFieldType.find_sys_id(_sid, params[:id])
end

#updateObject



51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/admin/form_field_types_controller.rb', line 51

def update
  @form_field_type = FormFieldType.find_sys_id(_sid, params[:id])
  @form_field_type.has_asset = 1 if ["file", "image"].include?(@form_field_type.field_type)
  if @form_field_type.update_attributes(params[:form_field_type])
    Activity.add(_sid, "Form field type '#{@form_field_type.name}' updated", current_user, "Form")
    redirect_to "/admin/form_field_types/#{@form_field_type.id}", :notice=>"Updated field type"
  else
    render :action => 'edit'
  end
end