summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/enumerations_controller.rb19
-rw-r--r--app/models/enumeration.rb1
-rw-r--r--app/views/enumerations/index.api.rsb9
3 files changed, 26 insertions, 3 deletions
diff --git a/app/controllers/enumerations_controller.rb b/app/controllers/enumerations_controller.rb
index 73a6ebd79..6eddff738 100644
--- a/app/controllers/enumerations_controller.rb
+++ b/app/controllers/enumerations_controller.rb
@@ -18,13 +18,26 @@
class EnumerationsController < ApplicationController
layout 'admin'
- before_filter :require_admin
+ before_filter :require_admin, :except => :index
+ before_filter :require_admin_or_api_request, :only => :index
before_filter :build_new_enumeration, :only => [:new, :create]
before_filter :find_enumeration, :only => [:edit, :update, :destroy]
+ accept_api_auth :index
helper :custom_fields
def index
+ respond_to do |format|
+ format.html
+ format.api {
+ @klass = Enumeration.get_subclass(params[:type])
+ if @klass
+ @enumerations = @klass.shared.sorted.all
+ else
+ render_404
+ end
+ }
+ end
end
def new
@@ -33,7 +46,7 @@ class EnumerationsController < ApplicationController
def create
if request.post? && @enumeration.save
flash[:notice] = l(:notice_successful_create)
- redirect_to :action => 'index', :type => @enumeration.type
+ redirect_to :action => 'index'
else
render :action => 'new'
end
@@ -45,7 +58,7 @@ class EnumerationsController < ApplicationController
def update
if request.put? && @enumeration.update_attributes(params[:enumeration])
flash[:notice] = l(:notice_successful_update)
- redirect_to :action => 'index', :type => @enumeration.type
+ redirect_to :action => 'index'
else
render :action => 'edit'
end
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index d4564a036..d3454021f 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -36,6 +36,7 @@ class Enumeration < ActiveRecord::Base
validates_length_of :name, :maximum => 30
scope :shared, where(:project_id => nil)
+ scope :sorted, order("#{table_name}.position ASC")
scope :active, where(:active => true)
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
diff --git a/app/views/enumerations/index.api.rsb b/app/views/enumerations/index.api.rsb
new file mode 100644
index 000000000..2fc70b987
--- /dev/null
+++ b/app/views/enumerations/index.api.rsb
@@ -0,0 +1,9 @@
+api.array @klass.name.underscore.pluralize do
+ @enumerations.each do |enumeration|
+ api.__send__ @klass.name.underscore do
+ api.id enumeration.id
+ api.name enumeration.name
+ api.is_default enumeration.is_default
+ end
+ end
+end