app/controllers/week_plan_controller.rb
# Parses and executes a drag-move operation requested by AJAX call
#
Parses and executes a drag-move operation requested by AJAX call
Parses and executes a drag - move operation requested by AJAX call
def parse_drag_move_operation( from_dom, to_dom, dom_xref_hash )
    logger.debug( "\r\n\r\n---[ #{controller_name()}.parse_drag_move_operation ] ---" ) if DEBUG_VERBOSE
    if from_dom =~ /dragapp/ && to_dom =~ /dropapp/
      from_index = dom_xref_hash[ :drag_appointment_doms ].index( from_dom )
      from_id    = dom_xref_hash[ :drag_appointment_ids ][ from_index ]
      to_index   = dom_xref_hash[ :drop_date_schedule_doms ].index( to_dom )
      to_date    = dom_xref_hash[ :drop_date_schedules ][ to_index ]
      appointment = Appointment.find( from_id )
      if appointment                                
        appointment.date_schedule = to_date
        appointment.updated_on = Time.now
        unless appointment.save
          flash[:error] = as_('Save failure.')
          log_error( "ActiveRecord SAVE Failure during parse_drag_move_operation( #{from_dom} |=> #{to_dom} )" )
        end
      else
        flash[:error] = as_('Cannot find the appointment to be moved.')
        log_error( "Cannot find the appointment to be moved! In parse_drag_move_operation( #{from_dom} |=> #{to_dom} )" )
      end
    elsif from_dom =~ /dragapp/ && to_dom =~ /dropslot/
      from_index  = dom_xref_hash[ :drag_appointment_doms ].index( from_dom )
      from_id     = dom_xref_hash[ :drag_appointment_ids ][ from_index ]
      appointment = Appointment.find( from_id )
      if appointment                                
        curr_date_schedule = appointment.date_schedule
        curr_patient_id    = appointment.patient_id
        appointment.destroy if appointment && !appointment.is_receipt_issued?
        schedule = Schedule.new
        schedule.preset_default_values( :date_schedule => curr_date_schedule, :patient_id => curr_patient_id )
        schedule.updated_on = Time.now
        schedule.must_insert = true
        unless schedule.save
          flash[:error] = as_('Save failure.')
          log_error( "ActiveRecord SAVE Failure during parse_drag_move_operation( #{from_dom} |=> #{to_dom} )" )
        end
      else
        flash[:error] = as_('Cannot find the appointment to be moved.')
        log_error( "Cannot find the appointment to be moved! In parse_drag_move_operation( #{from_dom} |=> #{to_dom} )" )
      end
    elsif from_dom =~ /dragslot/ && to_dom =~ /dropapp/
      from_index  = dom_xref_hash[ :drag_schedule_doms ].index( from_dom )
      from_id     = dom_xref_hash[ :drag_schedule_ids ][ from_index ]
      to_index    = dom_xref_hash[ :drop_date_schedule_doms ].index( to_dom )
      to_date     = dom_xref_hash[ :drop_date_schedules ][ to_index ]
      schedule    = Schedule.find( from_id )
      if schedule                                   
        curr_patient_id    = schedule.patient_id
        schedule.is_done   = true
        appointment = Appointment.new
        appointment.preset_default_values( :date_schedule => to_date, :patient_id => curr_patient_id )
        unless appointment.save && schedule.save
          flash[:error] = as_('Save failure.')
          log_error( "ActiveRecord SAVE Failure during parse_drag_move_operation( #{from_dom} |=> #{to_dom} )" )
        end
      else
        flash[:error] = as_('Cannot find the schedule note to be processed.')
        log_error( "Cannot find the schedule note to be processed! In parse_drag_move_operation( #{from_dom} |=> #{to_dom} )" )
      end
    end
  end
def parse_drag_move_operation ( from_dom , to_dom , dom_xref_hash ) logger . debug ( "\r\n\r\n---[ #{controller_name()}.parse_drag_move_operation ] ---" ) if DEBUG_VERBOSE if from_dom =~ / dragapp / && to_dom =~ / dropapp / from_index = dom_xref_hash [ :drag_appointment_doms ] . index ( from_dom ) from_id = dom_xref_hash [ :drag_appointment_ids ] [ from_index ] to_index = dom_xref_hash [ :drop_date_schedule_doms ] . index ( to_dom ) to_date = dom_xref_hash [ :drop_date_schedules ] [ to_index ] appointment = Appointment . find ( from_id ) if appointment appointment . date_schedule = to_date appointment . updated_on = Time . now unless appointment . save flash [ :error ] = as_ ( 'Save failure.' ) log_error ( "ActiveRecord SAVE Failure during parse_drag_move_operation( #{from_dom} |=> #{to_dom} )" ) end else flash [ :error ] = as_ ( 'Cannot find the appointment to be moved.' ) log_error ( "Cannot find the appointment to be moved! In parse_drag_move_operation( #{from_dom} |=> #{to_dom} )" ) end elsif from_dom =~ / dragapp / && to_dom =~ / dropslot / from_index = dom_xref_hash [ :drag_appointment_doms ] . index ( from_dom ) from_id = dom_xref_hash [ :drag_appointment_ids ] [ from_index ] appointment = Appointment . find ( from_id ) if appointment curr_date_schedule = appointment . date_schedule curr_patient_id = appointment . patient_id appointment . destroy if appointment && ! appointment . is_receipt_issued? schedule = Schedule . new schedule . preset_default_values ( :date_schedule => curr_date_schedule , :patient_id => curr_patient_id ) schedule . updated_on = Time . now schedule . must_insert = true unless schedule . save flash [ :error ] = as_ ( 'Save failure.' ) log_error ( "ActiveRecord SAVE Failure during parse_drag_move_operation( #{from_dom} |=> #{to_dom} )" ) end else flash [ :error ] = as_ ( 'Cannot find the appointment to be moved.' ) log_error ( "Cannot find the appointment to be moved! In parse_drag_move_operation( #{from_dom} |=> #{to_dom} )" ) end elsif from_dom =~ / dragslot / && to_dom =~ / dropapp / from_index = dom_xref_hash [ :drag_schedule_doms ] . index ( from_dom ) from_id = dom_xref_hash [ :drag_schedule_ids ] [ from_index ] to_index = dom_xref_hash [ :drop_date_schedule_doms ] . index ( to_dom ) to_date = dom_xref_hash [ :drop_date_schedules ] [ to_index ] schedule = Schedule . find ( from_id ) if schedule curr_patient_id = schedule . patient_id schedule . is_done = true appointment = Appointment . new appointment . preset_default_values ( :date_schedule => to_date , :patient_id => curr_patient_id ) unless appointment . save && schedule . save flash [ :error ] = as_ ( 'Save failure.' ) log_error ( "ActiveRecord SAVE Failure during parse_drag_move_operation( #{from_dom} |=> #{to_dom} )" ) end else flash [ :error ] = as_ ( 'Cannot find the schedule note to be processed.' ) log_error ( "Cannot find the schedule note to be processed! In parse_drag_move_operation( #{from_dom} |=> #{to_dom} )" ) end end end
Parses and executes a drag-move operation requested by AJAX call
Parses and executes a drag - move operation requested by AJAX call
# --- FROM App.id (dragapp)       |==TO==>  empty date (dropapp):  => Update appointment.date_schedule # (The negation of this should never occur) # --- FROM App.id (dragapp)       |==TO==>  empty slot (dropslot): => Create note + Delete appointment # (The negation of this should never occur) # --- FROM Schedule.id (dragslot)  |==TO==>  empty date (dropapp):  => Create appointment with default values + Update note as 'done' # (The negation of this should never occur) # --- FROM Schedule.id (dragslot)  |==TO==>  empty slot (dropslot): => (Do nothing)
from_dom
to_dom
dom_xref_hash