the API for content_types now allows to change the label_field property of a content type

This commit is contained in:
Didier Lafforgue 2012-02-20 16:16:59 +01:00
parent c5ddabd585
commit 61281db943
3 changed files with 19 additions and 9 deletions

View File

@ -5,6 +5,10 @@ module Locomotive
include Locomotive::Routing::SiteDispatcher include Locomotive::Routing::SiteDispatcher
include Locomotive::ActionController::LocaleHelpers include Locomotive::ActionController::LocaleHelpers
skip_before_filter :verify_authenticity_token
skip_load_and_authorize_resource
before_filter :require_account before_filter :require_account
before_filter :require_site before_filter :require_site
@ -13,10 +17,6 @@ module Locomotive
# before_filter :validate_site_membership # before_filter :validate_site_membership
skip_before_filter :verify_authenticity_token
skip_load_and_authorize_resource
self.responder = Locomotive::ActionController::Responder # custom responder self.responder = Locomotive::ActionController::Responder # custom responder
respond_to :json, :xml respond_to :json, :xml

View File

@ -78,6 +78,12 @@ module Locomotive
self.class.class_name_to_content_type(class_name, self.site) self.class.class_name_to_content_type(class_name, self.site)
end end
def label_field_name=(value)
# mandatory if we allow the API to set the label field name without an id of the field
@new_label_field_name = value unless value.blank?
super(value)
end
# Retrieve from a class name the associated content type within the scope of a site. # Retrieve from a class name the associated content type within the scope of a site.
# If no content type is found, the method returns nil # If no content type is found, the method returns nil
# #
@ -111,7 +117,15 @@ module Locomotive
def set_default_values def set_default_values
self.order_by ||= 'created_at' self.order_by ||= 'created_at'
self.label_field_id = self.entries_custom_fields.first._id if self.label_field_id.blank?
if @new_label_field_name.present?
self.label_field_id = self.entries_custom_fields.detect { |f| f.name == @new_label_field_name.underscore }._id
end
if self.label_field_id.blank?
self.label_field_id = self.entries_custom_fields.first._id
end
field = self.entries_custom_fields.find(self.label_field_id) field = self.entries_custom_fields.find(self.label_field_id)
# the label field should always be required # the label field should always be required

View File

@ -17,10 +17,6 @@ module Locomotive
output = @page.render(locomotive_context) output = @page.render(locomotive_context)
# puts "======================"
# puts output.inspect
# puts "======================"
self.prepare_and_set_response(output) self.prepare_and_set_response(output)
end end
end end