Sha256: 05d68ae2511e991c426e3fc8dfbb7bc3535e566255debe9f7cd927940dd4f11b

Contents?: true

Size: 1.62 KB

Versions: 15

Compression:

Stored size: 1.62 KB

Contents

class Admin::MembershipsController < ApplicationController
    
  before_filter :find_reader_and_group
  
  def index
    redirect_to admin_group_url(@group)
  end
  
  def create
    @membership = Membership.find_or_create_by_reader_id_and_group_id(@reader.id, @group.id)
    respond_to do |format|
      format.html { 
        flash[:notice] = "#{@reader.name} added to group #{@group.name}"
        redirect_to admin_group_url(@group) 
      }
      format.js { render :partial => 'reader' }
    end
  end
  
  def destroy
    @membership ||= @group.memberships.find(params[:id])
    @reader = @membership.reader
    @membership.delete if @membership
    respond_to do |format|
      format.html { 
        flash[:notice] = "#{@reader.name} removed from group #{@group.name}" if @membership
        redirect_to admin_group_url(@group) 
      }
      format.js { render :partial => 'reader' }
    end
  end
  
  def toggle
    if @membership = Membership.find_by_reader_id_and_group_id(@reader.id, @group.id)
      destroy
    else
      create
    end
  end
  
  def edit
    @membership = @group.memberships.find(params[:id])
    respond_to do |format|
      format.js { render :partial => 'admin/memberships/role_form' }
    end
  end

  def update
    @membership = @group.memberships.find(params[:id])
    @membership.update_attributes(params[:membership])
    @membership.save!
    respond_to do |format|
      format.js { render :partial => 'admin/memberships/role' }
    end
  end
  
protected

  def find_reader_and_group
    @group = Group.find(params[:group_id])
    @reader = Reader.find(params[:reader_id]) if params[:reader_id]
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
radiant-reader-extension-3.0.20 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.19 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.18 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.17 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.16 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.15 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.14 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.13 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.11 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.10 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.9 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.8 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.7 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.5 app/controllers/admin/memberships_controller.rb
radiant-reader-extension-3.0.4 app/controllers/admin/memberships_controller.rb