lib/scrivito/basic_obj.rb in scrivito_sdk-1.1.1 vs lib/scrivito/basic_obj.rb in scrivito_sdk-1.2.0.rc1

- old
+ new

@@ -662,11 +662,11 @@ end def reload_data id = self.id.to_s update_data -> { - CmsBackend.instance.find_obj_data_by(workspace.revision, :id, [id]).first.first + CmsBackend.find_obj_data_by(workspace.revision, :id, [id]).first.first } end # @api public def last_changed @@ -925,11 +925,11 @@ def find_container_and_attribute_name_for_widget(widget_id) if attribute_name = find_attribute_containing_widget(widget_id) return [self, attribute_name] end - all_widgets_from_pool.each do |container_widget| + contained_widgets.each do |container_widget| if attribute_name = container_widget.find_attribute_containing_widget(widget_id) return [container_widget, attribute_name] end end @@ -946,26 +946,24 @@ def publishable? !has_conflict? end - def all_widgets_from_pool - read_widget_pool.keys.map do |widget_id| - widget_from_pool(widget_id) - end - end - def generate_widget_pool_id 10.times do id = self.class.generate_widget_pool_id return id if widget_data_from_pool(id).nil? end raise ScrivitoError.new('Could not generate a new unused widget id') end + def contained_widgets + read_widget_pool.keys.map(&method(:widget_from_pool)) + end + def parent_path ParentPath.of(path) unless root? end def outdated? @@ -1025,20 +1023,20 @@ target_workspace.api_request(:delete, "/objs/#{id}") end def reset_modifications case - when new? then destroy + when new? then workspace.api_request(:delete, "/objs/#{id}") when deleted? then self.class.restore(id) else revert end end def cms_data_for_revision(revision) return nil unless revision - result = CmsBackend.instance.find_obj_data_by(revision, "id", [id]) + result = CmsBackend.find_obj_data_by(revision, "id", [id]) obj_data = result.first.first if obj_data && obj_data.value_of("_modification") != "deleted" obj_data end @@ -1181,17 +1179,10 @@ api_attributes = serialize_attributes( obj_attributes, widget_pool_attributes, workspace, obj_id ) - if obj - widget_pool = api_attributes['_widget_pool'] - widget_gc = WidgetGarbageCollection.new(obj, - {obj => obj_attributes}.merge(widget_pool_attributes)) - widget_gc.widgets_to_delete.each { |widget| widget_pool[widget.id] = nil } - end - [api_attributes, widget_pool_attributes] end def serialize_attributes(obj_attributes, widget_pool_attributes, workspace, obj_id) serializer = AttributeSerializer.new(obj_attributes['_obj_class'] || name, obj_id) @@ -1208,10 +1199,12 @@ def serialize_widget_pool_attributes(serializer, widget_pool_attributes) {}.tap do |serialized_attributes| widget_pool_attributes.each_pair do |widget, widget_attributes| obj_class = widget_attributes['_obj_class'] - serialized_attributes[widget.id] = serializer.serialize(widget_attributes, + widget_serializer = AttributeSerializer.new(obj_class, serializer.obj_id) + + serialized_attributes[widget.id] = widget_serializer.serialize(widget_attributes, find_attribute_definitions(obj_class, BasicWidget) || widget.attribute_definitions) end end end