Sha256: 40fa96de7d34b48be82edfbef1d56e88a577dbbae141e6566d18dfb2d4c7011d

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 KB

Contents

module Spontaneous::Rack::Back
  class Content < Base
    put '/:id/?:box_id?' do
      content_for_request(true) do |content, box|
        target = content
        if box
          forbidden! unless box.writable?(user)
          target = box
        end
        update_fields(target, params[:field])
      end
    end

    post '/:id/:box_id/:type_name' do
      content_for_request(true) do |content, box|
        position = (params[:position] || 0).to_i
        type = content_model.schema.to_class(params[:type_name])#.constantize

        forbidden! unless box.writable?(user, type)
        instance = type.new(:created_by => user)
        box.insert(position, instance)
        content.save
        json({
          :position => position,
          :entry => instance.entry.export(user)
        })
      end
    end

    delete '/:id' do
      content_for_request(true) do |content|
        forbidden! unless content.box.writable?(user)
        content.destroy
        json({})
      end
    end

    patch '/:id/toggle' do
      content_for_request(true) do |content|
        forbidden! unless content.box && content.box.writable?(user)
        content.toggle_visibility!
        json({:id => content.id, :hidden => (content.hidden? ? true : false) })
      end
    end

    patch '/:id/position/:position' do
      content_for_request(true) do |content|
        forbidden! unless content.box.writable?(user)
        content.update_position(params[:position].to_i)
        json( {:message => 'OK'} )
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/rack/back/content.rb
spontaneous-0.2.0.beta9 lib/spontaneous/rack/back/content.rb
spontaneous-0.2.0.beta8 lib/spontaneous/rack/back/content.rb
spontaneous-0.2.0.beta7 lib/spontaneous/rack/back/content.rb
spontaneous-0.2.0.beta6 lib/spontaneous/rack/back/content.rb
spontaneous-0.2.0.beta5 lib/spontaneous/rack/back/content.rb
spontaneous-0.2.0.beta4 lib/spontaneous/rack/back/content.rb
spontaneous-0.2.0.beta3 lib/spontaneous/rack/back/content.rb
spontaneous-0.2.0.beta2 lib/spontaneous/rack/back/content.rb