Class | Sadmin::EventsController
In: | app/controllers/sadmin/events_controller.rb
Parent: | Sadmin::BaseController

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.

### Methods

calendar change_schedule create delete edit index list mark_for_deletion myfeed new select_schedule set_l_attends show toggle_l_attends update week week2

### Public Instance methods

calendar()

Calendario de los eventos en un mes.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 225
    225:   def calendar
    226:     @t = "events"
    227:
    228:     respond_to do |format|
    229:       format.html do
    230:         render :action => 'index'
    231:       end
    232:       format.js do
    233:         render :update do |page|
    234:           page.replace_html "events_calendar", :partial => "calendar"
    235:         end
    236:       end
    237:       format.xml  { head :ok }
    238:     end
    239:   end

change_schedule()

Cambiar la agenda de un evento.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 266
    266:   def change_schedule
    267:     if s = Schedule.exists?(params[:new_schedule_id])
    268:       s = Schedule.find(params[:new_schedule_id])
    269:       change_schedule_to(s)
    270:     else
    271:       flash[:warning] = t('sadmin.events.no_ha_indicado_la_agenda')
    272:       redirect_to sadmin_event_path(@event)
    273:     end
    274:   end

create()

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.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 136
    136:   def create
    137:     @title = t('sadmin.create_what', :what => Event.human_name)
    138:
    139:     schedule_id = params[:event][:schedule_id].to_i
    140:     if params[:event][:schedule_id] && Schedule.exists?(schedule_id)
    141:       @schedule = Schedule.find(schedule_id)
    142:     end
    143:
    144:     @event = @schedule.nil? ? Event.new(params[:event]) : @schedule.events.new(params[:event])
    145:
    146:     if can_create?(@event.class.to_s.tableize)
    147:       if @event.save
    148:         flash[:notice] = t('sadmin.events.guardado_correctamente', :what => Event.human_name)
    149:         redirect_to @schedule.nil? ? sadmin_event_path(@event.id, :fresh => 1) : sadmin_schedule_event_path(:id => @event.id, :schedule_id => @schedule.id, :fresh => 1)
    150:       else
    151:         render :action => 'new'
    152:       end
    153:     else
    154:       flash[:notice] = t('no_tienes_permiso')
    155:       access_denied
    156:     end
    157:
    158:   end

delete()

Borrar un evento.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 247
    247:   def delete
    248:     @event = Event.find(params[:id])
    249:     clear_event_cache(@event)
    250:
    251:     unless params[:cancel]
    252:       if @event.update_attributes(:deleted => true)
    253:         flash[:notice] = t('sadmin.events.marcado_eliminado')
    254:       else
    255:         flash[:error] = t('sadmin.events.no_marcado_eliminado')
    256:       end
    257:     end
    258:     redirect_to sadmin_event_path(@event)
    259:   end

edit()

Formulario para modificar los datos de un evento.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 180
    180:   def edit
    181:     @title = t('sadmin.modificar_what', :what => Event.human_name)
    182:   end

index()

Calendario de los eventos del mes actual.

[Source]

        # File app/controllers/sadmin/events_controller.rb, line 24
    24:   def index
    25:     respond_to do |format|
    26:       format.html {
    27:         render
    28:       }
    29:       format.ics {
    30:         @events = Event.find(:all, :conditions => ["starts_at >= ?", 3.months.ago])
    31:         render :layout => false
    32:       }
    33:     end
    34:   end

list()

Lista de los eventos de un día.

[Source]

        # File app/controllers/sadmin/events_controller.rb, line 60
    60:   def list
    61:     for_date =  Date.new(@selected_date[:year], @selected_date[:month], @selected_date[:day])
    62:
    63:     conditions = ["(starts_at <= :end_hour) and (ends_at >= :beginning)", {:beginning => for_date.beginning_of_day, :end_hour => for_date.end_of_day}]
    64:
    65:     if session[:l_attends] && current_user.can_see_l_schedule?
    66:       conditions[0] += " AND l_attends='t'"
    67:     end
    68:
    69:     if @show_agenda.include?('agenda')
    70:       @documents = event_finder.find(:all, :conditions => conditions, :order => "starts_at")
    71:     else
    72:       @documents = []
    73:     end
    74:     @documents += get_schedule_events(conditions)
    75:     @documents.sort! {|a,b| a.sort_position <=> b.sort_position}
    76:
    77:
    78:     # @title = t("documents.#{@t.titleize}")
    79:     @subtitle = I18n.localize(for_date, :format => :long)
    80:
    81:     # If there are no events, redirect to the create event form.
    82:     redirect_to new_sadmin_event_path(@selected_date) if @documents.empty?  && !session[:l_attends] && can_create?("events")
    83:   end

mark_for_deletion()

Marcar un evento como ‘borrado’.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 242
    242:   def mark_for_deletion
    243:     @event = Event.find(params[:id])
    244:   end

myfeed()

RSS de los eventos

[Source]

        # File app/controllers/sadmin/events_controller.rb, line 37
    37:   def myfeed
    38:     if params[:u] && params[:p]
    39:       user = User.authenticate_from_url(params[:u], params[:p])
    40:     end
    41:
    42:     if user && user.can_create?("events")
    43:       respond_to do |format|
    44:         format.ics {
    45:           @events = Event.find(:all, :conditions => ["starts_at >= ?", 3.months.ago])
    46:           user.schedules.each do |s|
    47:             @events += s.events.find(:all, :conditions => ["starts_at >= ?", 3.months.ago])
    48:           end
    49:           render :layout => false
    50:         }
    51:       end
    52:     else
    53:       flash[:notice] = t('no_tienes_permiso')
    54:       redirect_to "index"
    55:     end
    56:
    57:   end

new()

Formulario para crear un nuevo evento.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 114
    114:   def new
    115:     @title = t('sadmin.modificar_what', :what => Event.human_name)
    116:
    117:     begin
    118:       default_date = Date.parse("#{@year}-#{@month}-#{@day}")
    119:     rescue ArgumentError
    120:       default_date = Time.now
    121:     end
    122:
    123:     event_params =  { :starts_at => default_date, :ends_at => default_date,
    124:                         :show_in_irekia => can?("create_irekia", "events"), :show_in_agencia => can?("create_agencia", "events"), :is_private => can?("create_private", "events"),
    125:                         :organization_id => current_user.department_id,
    126:                         :has_journalists => false, :has_photographers => false, :confirmed => true}
    127:
    128:     @event = can_create?('events') ? Event.new(event_params) : ScheduleEvent.new(event_params.merge(:schedule_id => current_user.editable_schedules.first.id))
    129:   end

select_schedule()

Elegir una nueva agenda para el evento.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 262
    262:   def select_schedule
    263:   end

set_l_attends()

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.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 303
    303:   def set_l_attends
    304:     if session[:l_attends]
    305:       session[:l_attends] = nil
    306:     else
    307:       if current_user.can_see_l_schedule?
    308:         session[:l_attends] = true
    309:       else
    310:         session[:l_attends] = nil
    311:       end
    312:     end
    313:     redirect_to :back
    314:   end

show()

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

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 161
    161:   def show
    162:     @just_created = params[:fresh].to_i.eql?(1)
    163:     if @just_created
    164:       @selected_date = {}
    165:       [:year, :month, :day].each do |key|
    166:         @selected_date[key] = @event.starts_at.send(key.to_s)
    167:       end
    168:     end
    169:     respond_to do |format|
    170:       format.html {
    171:         render
    172:       }
    173:       format.ics {
    174:         render :layout => false
    175:       }
    176:     end
    177:   end

toggle_l_attends()

Cambiar el valor del campo `l_attends`.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 277
    277:   def toggle_l_attends
    278:     if current_user.can_see_l_schedule?
    279:       @event.toggle!(:l_attends)
    280:       session[:l_attends] = nil
    281:       respond_to do |format|
    282:         format.html do
    283:           render :action => 'show'
    284:         end
    285:         format.js do
    286:           render :update do |page|
    287:             page.replace "l_attends_info_div", :partial => '/sadmin/events/l_attends'
    288:           end
    289:         end
    290:         format.xml  { head :ok }
    291:       end
    292:     else
    293:       flash[:warning] = 'No tiene permiso para cambiar estos datos.'
    294:       redirect_to @schedule.nil? ? sadmin_event_path(@event.id) : sadmin_schedule_event_path(:id => @event.id, :schedule_id => @schedule.id)
    295:     end
    296:
    297:   end

update()

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.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 188
    188:   def update
    189:     new_schedule = params[:event].delete(:schedule_id)
    190:     new_schedule = nil if new_schedule.to_i.eql?(0) || !Schedule.exists?(new_schedule)
    191:
    192:     @event.attributes = params[:event]
    193:     @title = t('sadmin.modificar_what', :what => Event.human_name)
    194:
    195:     clear_event_cache(@event)
    196:
    197:     if event_type_changed?(new_schedule)
    198:       if @event.is_a?(Event)
    199:         if schedule = Schedule.find(new_schedule)
    200:           change_schedule_to(schedule)
    201:         else
    202:           flash[:notice] = 'No puede modificar la agenda'
    203:           render(:action => :edit)
    204:         end
    205:       end
    206:       if @event.is_a?(ScheduleEvent)
    207:         change_schedule_to_agenda
    208:       end
    209:       return
    210:     else
    211:       @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)
    212:       if params[:event][:private_event].nil? && @event.respond_to?('private_event=')
    213:         @event.private_event = 1
    214:       end
    215:       if @event.save
    216:         flash[:notice] = t('sadmin.events.guardado_correctamente', :what => Event.human_name)
    217:         redirect_to @event.schedule_id.nil? ? sadmin_event_path(:id => @event.id) : sadmin_schedule_event_path(:id => @event.id, :schedule_id => @event.schedule_id)
    218:       else
    219:         render :action => params[:return_to] || 'edit'
    220:       end
    221:     end
    222:   end

week()

Lista de los eventos en una semana.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 86
     86:   def week
     87:     for_date =  Date.new(@selected_date[:year], @selected_date[:month], @selected_date[:day])
     88:
     89:     @first_day_of_week = for_date.beginning_of_week
     90:
     91:     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}]
     92:
     93:     if session[:l_attends] && current_user.can_see_l_schedule?
     94:       conditions[0] += " AND l_attends='t'"
     95:     end
     96:
     97:     if @show_agenda.include?('agenda')
     98:       @events = event_finder.find(:all, :conditions => conditions, :order => "starts_at")
     99:     else
    100:       @events = []
    101:     end
    102:     @events += get_schedule_events(conditions)
    103:
    104:     #@title = t("documents.#{@t.titleize}")
    105:     @subtitle = "#{I18n.localize(for_date.beginning_of_week, :format => :long)} - #{I18n.localize(for_date.end_of_week, :format => :long)}"
    106:   end

week2()

Vista alternativa para los eventos de una semana.

[Source]

         # File app/controllers/sadmin/events_controller.rb, line 109
    109:   def week2
    110:     week
    111:   end

[Validate]