Class: EnumerationsController

Inherits:
ApplicationController show all
Defined in:
frontend/app/controllers/enumerations_controller.rb

Instance Method Summary (collapse)

Methods inherited from ApplicationController

can_access?, permission_mappings, set_access_control

Instance Method Details

- (Object) create



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'frontend/app/controllers/enumerations_controller.rb', line 121

def create
  @enumeration = JSONModel(:enumeration).find(params[:id])

  if params[:enumeration].blank? or params[:enumeration][:value].blank?
    flash.now[:error] = "#{I18n.t("enumeration.value")} is required"
    return render_aspace_partial :partial => "new"
  end

  begin
    @enumeration.values += [params[:enumeration][:value]]
    @enumeration.save

    flash[:success] = I18n.t("enumeration._frontend.messages.created")
    render :text => "Success"
  rescue
    flash.now[:error] = I18n.t("enumeration._frontend.messages.create_error")
    render_aspace_partial :partial => "new"
  end

end

- (Object) delete



19
20
21
22
23
24
25
26
27
28
29
# File 'frontend/app/controllers/enumerations_controller.rb', line 19

def delete
  @merge = !params["merge"].blank?
  @enumeration = JSONModel(:enumeration).find(params[:id])
  @value = params[:value]

  if @merge
    render_aspace_partial :partial => "merge"
  else
    render_aspace_partial :partial => "delete"
  end
end

- (Object) destroy



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'frontend/app/controllers/enumerations_controller.rb', line 72

def destroy
  @enumeration = JSONModel(:enumeration).find(params[:id])
  @value = params["enumeration"]["value"]

  begin
    @enumeration.values -= [@value]
    @enumeration.save

    flash[:success] = I18n.t("enumeration._frontend.messages.deleted")
    render :text => "Success"
  rescue ConflictException
    flash.now[:error] = I18n.t("enumeration._frontend.messages.delete_conflict")
    flash.now[:info] = I18n.t("enumeration._frontend.messages.merge_tip")

    render_aspace_partial :partial => "merge"
  rescue
    flash.now[:error] = I18n.t("enumeration._frontend.messages.delete_error")
    render_aspace_partial :partial => "delete"
  end
end

- (Object) index



12
13
14
15
16
# File 'frontend/app/controllers/enumerations_controller.rb', line 12

def index
  # @enumerations = JSONModel(:enumeration).all.select{|enum| enum['editable']}
  @enumerations = JSONModel(:enumeration).all
  @enumeration = JSONModel(:enumeration).find(params[:id]) if params[:id] and not params[:id].blank?
end

- (Object) merge



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'frontend/app/controllers/enumerations_controller.rb', line 94

def merge
  @enumeration = JSONModel(:enumeration).find(params[:id])
  @value = params["enumeration"]["value"]
  @merge = params["merge_into"]

  if @merge.blank?
    flash.now[:error] = "#{I18n.t("enumeration.merge_into")} - is required"
    return render_aspace_partial :partial => "merge"
  elsif @value.blank?
    flash.now[:error] = "#{I18n.t("enumeration.value")} - is required"
    return render_aspace_partial :partial => "merge"
  end

  begin
    request = JSONModel(:enumeration_migration).from_hash(:enum_uri => @enumeration.uri,
                                                          :from => @value,
                                                          :to => @merge)
    request.save

    flash[:success] = I18n.t("enumeration._frontend.messages.merged")
    render :text => "Success"
  rescue
    flash.now[:error] = I18n.t("enumeration._frontend.messages.merge_error")
    render_aspace_partial :partial => "merge"
  end
end

- (Object) new



6
7
8
9
# File 'frontend/app/controllers/enumerations_controller.rb', line 6

def new
  @enumeration = JSONModel(:enumeration).find(params[:id])
  render_aspace_partial :partial => "new"
end

- (Object) set_default



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'frontend/app/controllers/enumerations_controller.rb', line 31

def set_default
  begin
    @enumeration = JSONModel(:enumeration).find(params[:id])
    @enumeration['default_value'] = params[:value]
    @enumeration.save
    flash[:success] = I18n.t("enumeration._frontend.messages.default_set")
  rescue
    flash.now[:error] = I18n.t("enumeration._frontend.messages.default_set_error")
  end
  
  redirect_to(:controller => :enumerations, :action => :index, :id => params[:id])

end

- (Object) update_value

we only update position and suppression here



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'frontend/app/controllers/enumerations_controller.rb', line 47

def update_value
  
    @enumeration_value = JSONModel(:enumeration_value).find( params[:enumeration_value_id])
   
  begin
    
    if params[:suppressed]
      suppress = ( params[:suppressed] == "1" )
      @enumeration_value.set_suppressed(suppress) 
    end
   
    if params[:position]
      JSONModel::HTTP.post_form("#{@enumeration_value.uri}/position", :position => params[:position]) 
    end

    flash[:success] = I18n.t("enumeration._frontend.messages.value_updated")
  rescue
    flash.now[:error] = I18n.t("enumeration._frontend.messages.value_update_error")
  end
  
  redirect_to(:controller => :enumerations, :action => :index, :id => params[:id])

end