app/controllers/programme_items_controller.rb
#
# Update a program item based on the inputs
#  
Update a program item based on the inputs
Update a program item based on the inputs
def update
    @extra_item_json = [] if ! @extra_item_json
    startTime = (params[:start_time] && params[:start_time].to_datetime) ? (params[:start_time].to_datetime + zone_delta(params[:start_time].to_datetime)) : nil
    startDay = -1
    startDay = (startTime - Time.zone.parse(SiteConfig.first.start_date.beginning_of_day.to_s).to_datetime).to_i if startTime
    roomId = params[:room_id]
    parent_id = params[:parent_id]
    begin
      ProgrammeItem.transaction do
        @programmeItem = ProgrammeItem.find(params[:id])
        if @programmeItem.parent
          @programmeItem.parent.touch if !@programmeItem.parent.new_record?
          @programmeItem.parent.save
        end
        if @programmeItem.update(permitted_params)
          if (startDay.to_i > -1) && startTime && parent_id.blank?
            room = nil
            room = Room.find(roomId) if roomId.to_i > 0
            addItemToRoomAndTime(@programmeItem, room, startDay, startTime)
          else
            if (@programmeItem.room_item_assignment)
               @programmeItem.room_item_assignment.destroy
            end
          end
          ts = @programmeItem.time_slot
          if (ts)
            ts.end = ts.start + @programmeItem.duration.minutes
            ts.save
          end
        end
        if parent_id
          @programmeItem.parent_id = parent_id
          @programmeItem.save!
          if @programmeItem.parent
            @programmeItem.parent.touch if !@programmeItem.parent.new_record?
            @programmeItem.parent.save
          end
        end
        _after_save(@programmeItem)
      end
    rescue => ex
      Rails.logger.error ex.message if Rails.env.development?
      Rails.logger.error ex.backtrace.join("\n\t") if Rails.env.development?
      render status: :bad_request, text: ex.message
    end
  end
def update @extra_item_json = [ ] if ! @extra_item_json startTime = ( params [ :start_time ] && params [ :start_time ] . to_datetime ) ? ( params [ :start_time ] . to_datetime + zone_delta ( params [ :start_time ] . to_datetime ) ) : nil startDay = - 1 startDay = ( startTime - Time . zone . parse ( SiteConfig . first . start_date . beginning_of_day . to_s ) . to_datetime ) . to_i if startTime roomId = params [ :room_id ] parent_id = params [ :parent_id ] begin ProgrammeItem . transaction do @programmeItem = ProgrammeItem . find ( params [ :id ] ) if @programmeItem . parent @programmeItem . parent . touch if ! @programmeItem . parent . new_record? @programmeItem . parent . save end if @programmeItem . update ( permitted_params ) if ( startDay . to_i > - 1 ) && startTime && parent_id . blank? room = nil room = Room . find ( roomId ) if roomId . to_i > 0 addItemToRoomAndTime ( @programmeItem , room , startDay , startTime ) else if ( @programmeItem . room_item_assignment ) @programmeItem . room_item_assignment . destroy end end ts = @programmeItem . time_slot if ( ts ) ts . end = ts . start + @programmeItem . duration . minutes ts . save end end if parent_id @programmeItem . parent_id = parent_id @programmeItem . save! if @programmeItem . parent @programmeItem . parent . touch if ! @programmeItem . parent . new_record? @programmeItem . parent . save end end _after_save ( @programmeItem ) end rescue => ex Rails . logger . error ex . message if Rails . env . development? Rails . logger . error ex . backtrace . join ( "\n\t" ) if Rails . env . development? render status : :bad_request , text : ex . message end end
Update a program item based on the inputs
Update a program item based on the inputs