class Sadmin::EventsController

Controlador para el acceso a las agendas desde la parte de administración de la web.

Sólo los usuarios que tienen permiso para ver las agendas pueden acceder a este controlador.

Public Instance Methods

auto_complete_for_event_place() click to toggle source

Autocomplete para el nombre del sitio

# File app/controllers/sadmin/events_controller.rb, line 367
def auto_complete_for_event_place
  places = EventLocation.find(:all, :conditions => ["tildes(place) ilike ?", "%"+params[:event][:place].tildes+"%"])
  render :partial => 'event_locations', :object => places
end
auto_complete_for_event_politicians_tag_list() click to toggle source

Autocomplete para la lista de políticos

# File app/controllers/sadmin/events_controller.rb, line 383
def auto_complete_for_event_politicians_tag_list
  auto_complete_for_document_politicians_tag_list(params[:event][:politicians_tag_list])
end
calendar() click to toggle source

Calendario de los eventos en un mes.

# File app/controllers/sadmin/events_controller.rb, line 254
def calendar
  @t = "events"
  
  respond_to do |format|
    format.html do
      render :action => 'index'
    end
    format.js do
      render :update do |page|
        page.replace_html "events_calendar", :partial => "calendar"
      end
    end
    format.xml  { head :ok }
  end
end
change_schedule() click to toggle source

Cambiar la agenda de un evento.

# File app/controllers/sadmin/events_controller.rb, line 294
def change_schedule
  if s = Schedule.exists?(params[:new_schedule_id])
    s = Schedule.find(params[:new_schedule_id])
    change_schedule_to(s)
  else
    flash[:warning] = t('sadmin.events.no_ha_indicado_la_agenda')
    redirect_to sadmin_event_path(@event)
  end  
end
create() click to toggle source

Crear un evento nuevo.

Si los datos son correctos el evento se crea y se muestra la página del evento nuevo. Si algún dato no es válido, se muestra de nuevo el formulario con explicación sobre los datos que no son válidos.

# File app/controllers/sadmin/events_controller.rb, line 165
def create
  @title = t('sadmin.create_what', :what => Event.human_name)
  
  schedule_id = params[:event][:schedule_id].to_i
  if params[:event][:schedule_id] && Schedule.exists?(schedule_id)
    @schedule = Schedule.find(schedule_id)
  end
  
  @event = @schedule.nil? ? Event.new(params[:event]) : @schedule.events.new(params[:event])
  if can_create?(@event.class.to_s.tableize)
    if @event.save
      flash[:notice] = t('sadmin.events.guardado_correctamente', :what => Event.human_name)
      redirect_to @schedule.nil? ? sadmin_event_path(@event.id, :fresh => 1) : sadmin_schedule_event_path(:id => @event.id, :schedule_id => @schedule.id, :fresh => 1)
    else
      render :action => 'new'
    end
  else
    flash[:notice] = t('no_tienes_permiso')
    access_denied
  end    
  
end
delete() click to toggle source

Borrar un evento.

# File app/controllers/sadmin/events_controller.rb, line 276
def delete
  @event = Event.find(params[:id])
  
  unless params[:cancel]
    if @event.update_attributes(:deleted => true)
      flash[:notice] = t('sadmin.events.marcado_eliminado')
    else
      flash[:error] = t('sadmin.events.no_marcado_eliminado')
    end
  end
  redirect_to sadmin_event_path(@event)
end
edit() click to toggle source

Formulario para modificar los datos de un evento.

# File app/controllers/sadmin/events_controller.rb, line 208
def edit
  @title = t('sadmin.modificar_what', :what => Event.human_name)
end
index() click to toggle source

Calendario de los eventos del mes actual.

# File app/controllers/sadmin/events_controller.rb, line 51
def index
  respond_to do |format|
    format.html {
      render
    }
    format.ics {
      @events = Event.find(:all, :conditions => ["starts_at >= ?", 3.months.ago])
      render :layout => false
    }
  end
end
list() click to toggle source

Lista de los eventos de un día.

# File app/controllers/sadmin/events_controller.rb, line 88
def list
  for_date =  Date.new(@selected_date[:year], @selected_date[:month], @selected_date[:day])
  
  conditions = ["(starts_at <= :end_hour) and (ends_at >= :beginning)", {:beginning => for_date.beginning_of_day, :end_hour => for_date.end_of_day}]
  
  if session[:l_attends] && current_user.can_see_l_schedule?
    conditions[0] += " AND l_attends='t'"
  end
  
  if @show_agenda.include?('agenda')
    @documents = event_finder.find(:all, :conditions => conditions, :order => "starts_at")
  else
    @documents = []
  end
  @documents += get_schedule_events(conditions)
  @documents.sort! {|a,b| a.sort_position <=> b.sort_position}
  
  
  # @title = t("documents.#{@t.titleize}")
  @subtitle = I18n.localize(for_date, :format => :long)
  @prev_day = for_date - 1.day
  @next_day = for_date + 1.day    

  # If there are no events, redirect to the create event form.  
  redirect_to new_sadmin_event_path(@selected_date) if @documents.empty?  && !session[:l_attends] && can_create?("events")
end
mark_for_deletion() click to toggle source

Marcar un evento como ‘borrado’.

# File app/controllers/sadmin/events_controller.rb, line 271
def mark_for_deletion
  @event = Event.find(params[:id])
end
myfeed() click to toggle source

RSS de todos los eventos

# File app/controllers/sadmin/events_controller.rb, line 64
def myfeed
  if params[:u] && params[:p]
    user = User.authenticate_from_url(params[:u], params[:p])
  end
  
  if user && user.can_access?("events")
    respond_to do |format|
      format.ics {
        # Eventos públicos o privados que ven todos los usuarios con acceso a la agenda.
        @events = Event.find(:all, :conditions => ["starts_at >= ?", 3.months.ago])
        # Eventos de las agendas privadas de los departamentos a los que el usuario tiene acceso.
        user.schedules.each do |s|
          @events += s.events.find(:all, :conditions => ["starts_at >= ?", 3.months.ago])
        end
        render :layout => false
      }
    end        
  else
    flash[:notice] = t('no_tienes_permiso')
    redirect_to "index"
  end    
end
new() click to toggle source

Formulario para crear un nuevo evento.

# File app/controllers/sadmin/events_controller.rb, line 144
def new
  @title = t('sadmin.create_what', :what => Event.human_name)
  
  begin
    default_date = Date.parse("#{@year}-#{@month}-#{@day}") 
  rescue ArgumentError
    default_date = Time.now
  end
  
  event_params =  { :starts_at => default_date, :ends_at => default_date, 
                    :organization_id => current_user.department_id,
                    :has_journalists => false, :has_photographers => false}
                      
  @event = can_create?('events') ? Event.new(event_params) : ScheduleEvent.new(event_params.merge(:schedule_id => current_user.editable_schedules.first.id))
end
select_schedule() click to toggle source

Elegir una nueva agenda para el evento.

# File app/controllers/sadmin/events_controller.rb, line 290
def select_schedule
end
set_l_attends() click to toggle source

Asignar un valor nuevo a session[:l_attends].

El valor de session[:l_attends] indica si en la vista de los eventos salen sólo los eventos a los que asiste el Lehendakari o todos los eventos.

# File app/controllers/sadmin/events_controller.rb, line 331
def set_l_attends
  if session[:l_attends]
    session[:l_attends] = nil
  else
    if current_user.can_see_l_schedule?
      session[:l_attends] = true
    else
      session[:l_attends] = nil
    end
  end    
  redirect_to :back
end
show() click to toggle source

Página de un evento. Se muestran todos los datos del evento.

# File app/controllers/sadmin/events_controller.rb, line 189
def show
  @just_created = params[:fresh].to_i.eql?(1)
  if @just_created
    @selected_date = {}
    [:year, :month, :day].each do |key|
      @selected_date[key] = @event.starts_at.send(key.to_s)
    end
  end    
  respond_to do |format|
    format.html {
      render
    }
    format.ics {
      render :layout => false
    }
  end
end
toggle_l_attends() click to toggle source

Cambiar el valor del campo l_attends.

# File app/controllers/sadmin/events_controller.rb, line 305
def toggle_l_attends
  if current_user.can_see_l_schedule?
    @event.toggle!(:l_attends)
    session[:l_attends] = nil
    respond_to do |format|
      format.html do
        render :action => 'show'
      end
      format.js do
        render :update do |page|
          page.replace "l_attends_info_div", :partial => '/sadmin/events/l_attends'
        end
      end
      format.xml  { head :ok }
    end
  else
    flash[:warning] = 'No tiene permiso para cambiar estos datos.'
    redirect_to @schedule.nil? ? sadmin_event_path(@event.id) : sadmin_schedule_event_path(:id => @event.id, :schedule_id => @schedule.id)
  end
  
end
unrelate() click to toggle source
# File app/controllers/sadmin/events_controller.rb, line 344
def unrelate
  if rel = @event.related_items.find_by_eventable_id(params[:related_item_id])
    rel.destroy
  end
  redirect_to sadmin_event_path(:id => @event.id)
end
update() click to toggle source

Modificar los datos de un evento.

Si los datos son válidos, estos se guardan en la base de datos y se muestra el evento. Si los datos no son válidos se muestra el formulario con los mensajes de error correspondientes.

# File app/controllers/sadmin/events_controller.rb, line 216
def update
  new_schedule = params[:event].delete(:schedule_id)
  #new_schedule = nil if new_schedule.to_i.eql?(0) || !Schedule.exists?(new_schedule)
  
  @event.attributes = params[:event]
  @title = t('sadmin.modificar_what', :what => Event.human_name)
  
  if event_type_changed?(new_schedule)
    if @event.is_a?(Event)
      if schedule = Schedule.find(new_schedule)
        change_schedule_to(schedule)
      else
        flash[:notice] = 'No puede modificar la agenda'
        render(:action => :edit)
      end   
    end
    if @event.is_a?(ScheduleEvent)
      change_schedule_to_agenda
    end
    return
  else
    if (new_schedule.to_i <= 0)
      # cambio entre público y privado
      @event.schedule_id = new_schedule if @event.is_a?(Event)
    else
      # cambio entre agendas privadas
      @event.schedule_id = new_schedule if @event.is_a?(ScheduleEvent) && current_user.can_change_schedule?(@event.schedule_id) && current_user.can_change_schedule?(new_schedule)
    end
    if @event.save
      flash[:notice] = t('sadmin.events.guardado_correctamente', :what => Event.human_name)
      redirect_to @event.is_a?(Event) ? sadmin_event_path(:id => @event.id) : sadmin_schedule_event_path(:id => @event.id, :schedule_id => @event.schedule_id)
    else
      render :action => params[:return_to] || 'edit'
    end
  end
end
week() click to toggle source

Lista de los eventos en una semana.

# File app/controllers/sadmin/events_controller.rb, line 116
def week
  for_date =  Date.new(@selected_date[:year], @selected_date[:month], @selected_date[:day])
  
  @first_day_of_week = for_date.beginning_of_week
  
  conditions = ["(starts_at <= :end_hour) and (ends_at >= :beginning)", {:beginning => for_date.beginning_of_week.to_time, :end_hour => for_date.end_of_week.to_time.end_of_day}]
  
  if session[:l_attends] && current_user.can_see_l_schedule?
    conditions[0] += " AND l_attends='t'"
  end
  
  if @show_agenda.include?('agenda')
    @events = event_finder.find(:all, :conditions => conditions, :order => "starts_at")
  else
    @events = []
  end
  @events += get_schedule_events(conditions)
  
  #@title = t("documents.#{@t.titleize}")
  @subtitle = "#{I18n.localize(for_date.beginning_of_week, :format => :long)} - #{I18n.localize(for_date.end_of_week, :format => :long)}"
end
week2() click to toggle source

Vista alternativa para los eventos de una semana.

# File app/controllers/sadmin/events_controller.rb, line 139
def week2
  week
end