app/helpers/week_plan_helper.rb
def table_row_for_week( curr_date, start_time, offset_min, schedule, appointments_cache, dom_xref_hash )
    current_user = LeUser.find(session[:le_user_id])
    curr_tot_min = start_time.hour * 60 + start_time.min + offset_min
    curr_hour_digit = curr_tot_min / 60
    curr_min_digit = curr_tot_min % 60
    sTemp = "" << start_time.year.to_s << "-" << "%02u" % start_time.month.to_s << "-" << 
            "%02u" % start_time.day.to_s << " " <<
            "%02u" % curr_hour_digit.to_s << ":" << "%02u" % curr_min_digit.to_s << ":00"
    curr_hour = DateTime.parse(sTemp)

    sOut = "\r\n"                                   # (Add CR+LF for each table row to improve generated source readibility)
    dt_start = Schedule.get_week_start( curr_date )

                                                    # -- DAY CELL SLOT: add a table cell to the row for each working day:
    dt_start.step(dt_start+5, 1) { |d|
      curr_name = ""
      curr_updated_on = nil
      curr_id = 0
      curr_is_receipt_issued = false
      s_target_datetime = Schedule.format_datetime_coordinates_for_mysql_param( d, curr_hour )

      for app in appointments_cache
        if s_target_datetime == Schedule.format_datetime_for_mysql_param( app.date_schedule )
          curr_name = app.get_full_name
          curr_id = app.id
          curr_updated_on = app.updated_on
          curr_is_payed = app.is_payed?
          curr_is_receipt_issued = app.is_receipt_issued
          curr_is_receipt_delivered = app.is_receipt_delivered
          break
        end
      end
                                                    # Build-up basic link to insert into the cell:
      table_data = ( curr_is_payed ? content_tag(:div, '', :class => 'schedule-payed-img') : '' ) +
                   link_to_unless(
                            ( current_user.nil? ||
                              !( curr_name.blank? ? current_user.can_do(:appointments, :create) :
                                                    current_user.can_do(:appointments, :show)
                               )
                            ),
                            "%02u" % curr_hour_digit.to_s << ":" << "%02u" % curr_min_digit.to_s,
                            ( curr_name.blank? ? edit_appointments_path( :id => curr_id, :curr_time => s_target_datetime ) :
                                                 show_appointments_path( :id => curr_id, :curr_time => s_target_datetime )
                            )
                    ) +
                    "<br/>" + h( curr_name )
                                                    # Make table cell data draggable or droppable, if we can:
      if  curr_name.blank?                          # 'DROP'-appointment type:
        div_id = get_unique_dom_id( 'dropapp', s_target_datetime )
        table_data = content_tag( :div, table_data, :id => div_id ) + "\r\n"
        if DRAG_N_DROP_GLOBAL_SWITCH && current_user && current_user.can_do(:appointments, :update)
          table_data << content_tag( :script, get_droppable_script(div_id), :type => "text/javascript" ) + "\r\n"
          dom_xref_hash[:drop_date_schedules]     << s_target_datetime
          dom_xref_hash[:drop_date_schedule_doms] << div_id
        end
                                                    # 'DRAG'-appointment type:
      elsif ! curr_is_receipt_issued
        div_id = get_unique_dom_id( 'dragapp', s_target_datetime )
        table_data = content_tag( :div, table_data, :id => div_id, :style => "width:100%; height:4em; background-color:inherit;" ) + "\r\n"
        if DRAG_N_DROP_GLOBAL_SWITCH && current_user && current_user.can_do(:appointments, :update)
          table_data << content_tag( :script, get_draggable_script(div_id) + get_highlight_script_if_recently_updated(div_id, curr_updated_on), :type => "text/javascript" ) + "\r\n"
          dom_xref_hash[:drag_appointment_ids]  << curr_id
          dom_xref_hash[:drag_appointment_doms] << div_id
        end
                                                    # 'FIXED'-appointment type:
      else
        div_id = get_unique_dom_id( 'app', s_target_datetime )
        script_text = get_highlight_script_if_recently_updated( div_id, curr_updated_on )
        table_data = content_tag( :div, table_data, :id => div_id ) + "\r\n"
        unless script_text.blank?
          table_data << content_tag( :script, script_text, :type => "text/javascript" ) + "\r\n"
        end
      end
                                                    # Encapsulate data in table cell:
      sOut << "    #{content_tag( :td, table_data, :class => get_schedule_cell_style(d, curr_is_receipt_issued, curr_is_receipt_delivered) )}\r\n" 
    }

                                                    # -- SCHEDULE NOTES SLOT: add another table cell at the end of the row:
    s_target_datetime = Schedule.format_datetime_coordinates_for_mysql_param( dt_start+6, curr_hour )
    schedule_notes_slot = ''

    if schedule.nil?                                # 'DROP'-slot type:
        div_id = get_unique_dom_id( 'dropslot', s_target_datetime )
        schedule_notes_slot = content_tag( :div, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', :id => div_id ) + "\r\n"
        if DRAG_N_DROP_GLOBAL_SWITCH && current_user && current_user.can_do(:appointments, :update)
          schedule_notes_slot << content_tag( :script, get_droppable_script(div_id), :type => "text/javascript" ) + "\r\n"
          dom_xref_hash[:drop_date_schedules]     << ''       # leave schedule date blank for empty side slots that are drop targets
          dom_xref_hash[:drop_date_schedule_doms] << div_id
      end
                                                    # 'DRAG'-slot type:
    elsif schedule.must_insert? and (! schedule.is_done?)
        div_id = get_unique_dom_id( 'dragslot', s_target_datetime )
        schedule_notes_slot = content_tag( :div, schedule.get_full_description(), :id => div_id, :style => "width:100%; height:4em; background-color:inherit;" ) + "\r\n"
        if DRAG_N_DROP_GLOBAL_SWITCH && current_user && current_user.can_do(:appointments, :update)
          schedule_notes_slot << content_tag( :script, get_draggable_script(div_id) + get_highlight_script_if_recently_updated(div_id, schedule.updated_on), :type => "text/javascript" ) + "\r\n"
          dom_xref_hash[:drag_schedule_ids]  << schedule.id
          dom_xref_hash[:drag_schedule_doms] << div_id
        end
                                                    # 'FIXED'-slot type:
    else
      div_id = get_unique_dom_id( 'slot', s_target_datetime )
      schedule_notes_slot = content_tag( :div, schedule.get_full_description(), :id => div_id ) + "\r\n"
      script_text = get_highlight_script_if_recently_updated( div_id, schedule.updated_on )
      unless script_text.blank?
        schedule_notes_slot << content_tag( :script, script_text, :type => "text/javascript" ) + "\r\n" 
      end
    end
    sOut << "    #{content_tag( :td, schedule_notes_slot, :class => 'schedule-notes' )}\r\n"

    return content_tag( :tr, sOut, :class => 'schedule-row' )
  end
# Builds a single HTML table row for displaying a single appointments line in 
# current week's schedule, computing the week range with the same algorithm used
# in table_header_for_week.
#
# Each table cell will be built with both drag'n'drop functionality (if enabled)
# and with a link to either show or edit the cell contents - but only if the current user
# stored in the session can actually carry out the action involved.
#
# curr_date : Date instance for extracting current week
# start_time : DateTime instance representing work shift starting time
# offset_min : Integer offset in minutes from starting time
# schedule  : schedule instance; it can be nil if the "schedule notes slot" is assumed to be empty for this row.
# appointments_cache : a collection of all the Appointment instances of the current week.
# dom_xref_hash : Hash containing all the lookup tables for DOM IDs, Appointment IDs, and empty-date place-holders' IDs.
#                The hash will be filled during the construction of the table with several arrays, one for each cross-reference needed. 
#
Builds a single HTML table row for displaying a single appointments line in
current week's schedule, computing the week range with the same algorithm used
in table_header_for_week.

Each table cell will be built with both drag'n'drop functionality (if enabled)
and with a link to either show or edit the cell contents - but only if the current user
stored in the session can actually carry out the action involved.

curr_date : Date instance for extracting current week
start_time : DateTime instance representing work shift starting time
offset_min : Integer offset in minutes from starting time
schedule  : schedule instance; it can be nil if the "schedule notes slot" is assumed to be empty for this row.
appointments_cache : a collection of all the Appointment instances of the current week.
dom_xref_hash : Hash containing all the lookup tables for DOM IDs, Appointment IDs, and empty-date place-holders' IDs.
The hash will be filled during the construction of the table with several arrays, one for each cross-reference needed.
Builds a single HTML table row for displaying a single appointments line in current week ' s schedule computing the week range with the same algorithm used in table_header_for_week . Each table cell will be built with both drag ' n ' drop functionality ( if enabled ) and with a link to either show or edit the cell contents - but only if the current user stored in the session can actually carry out the action involved . curr_date : Date instance for extracting current week start_time : DateTime instance representing work shift starting time offset_min : Integer offset in minutes from starting time schedule : schedule instance ; it can be nil if the " schedule notes slot " is assumed to be empty for this row . appointments_cache : a collection of all the Appointment instances of the current week . dom_xref_hash : Hash containing all the lookup tables for DOM IDs Appointment IDs and empty - date place - holders ' IDs . The hash will be filled during the construction of the table with several arrays one for each cross - reference needed .
def table_row_for_week( curr_date, start_time, offset_min, schedule, appointments_cache, dom_xref_hash )
    current_user = LeUser.find(session[:le_user_id])
    curr_tot_min = start_time.hour * 60 + start_time.min + offset_min
    curr_hour_digit = curr_tot_min / 60
    curr_min_digit = curr_tot_min % 60
    sTemp = "" << start_time.year.to_s << "-" << "%02u" % start_time.month.to_s << "-" << 
            "%02u" % start_time.day.to_s << " " <<
            "%02u" % curr_hour_digit.to_s << ":" << "%02u" % curr_min_digit.to_s << ":00"
    curr_hour = DateTime.parse(sTemp)
    sOut = "\r\n"                                   
    dt_start = Schedule.get_week_start( curr_date )
    dt_start.step(dt_start+5, 1) { |d|
      curr_name = ""
      curr_updated_on = nil
      curr_id = 0
      curr_is_receipt_issued = false
      s_target_datetime = Schedule.format_datetime_coordinates_for_mysql_param( d, curr_hour )
      for app in appointments_cache
        if s_target_datetime == Schedule.format_datetime_for_mysql_param( app.date_schedule )
          curr_name = app.get_full_name
          curr_id = app.id
          curr_updated_on = app.updated_on
          curr_is_payed = app.is_payed?
          curr_is_receipt_issued = app.is_receipt_issued
          curr_is_receipt_delivered = app.is_receipt_delivered
          break
        end
      end
      table_data = ( curr_is_payed ? content_tag(:div, '', :class => 'schedule-payed-img') : '' ) +
                   link_to_unless(
                            ( current_user.nil? ||
                              !( curr_name.blank? ? current_user.can_do(:appointments, :create) :
                                                    current_user.can_do(:appointments, :show)
                               )
                            ),
                            "%02u" % curr_hour_digit.to_s << ":" << "%02u" % curr_min_digit.to_s,
                            ( curr_name.blank? ? edit_appointments_path( :id => curr_id, :curr_time => s_target_datetime ) :
                                                 show_appointments_path( :id => curr_id, :curr_time => s_target_datetime )
                            )
                    ) +
                    "<br/>" + h( curr_name )
      if  curr_name.blank?                          
        div_id = get_unique_dom_id( 'dropapp', s_target_datetime )
        table_data = content_tag( :div, table_data, :id => div_id ) + "\r\n"
        if DRAG_N_DROP_GLOBAL_SWITCH && current_user && current_user.can_do(:appointments, :update)
          table_data << content_tag( :script, get_droppable_script(div_id), :type => "text/javascript" ) + "\r\n"
          dom_xref_hash[:drop_date_schedules]     << s_target_datetime
          dom_xref_hash[:drop_date_schedule_doms] << div_id
        end
      elsif ! curr_is_receipt_issued
        div_id = get_unique_dom_id( 'dragapp', s_target_datetime )
        table_data = content_tag( :div, table_data, :id => div_id, :style => "width:100%; height:4em; background-color:inherit;" ) + "\r\n"
        if DRAG_N_DROP_GLOBAL_SWITCH && current_user && current_user.can_do(:appointments, :update)
          table_data << content_tag( :script, get_draggable_script(div_id) + get_highlight_script_if_recently_updated(div_id, curr_updated_on), :type => "text/javascript" ) + "\r\n"
          dom_xref_hash[:drag_appointment_ids]  << curr_id
          dom_xref_hash[:drag_appointment_doms] << div_id
        end
      else
        div_id = get_unique_dom_id( 'app', s_target_datetime )
        script_text = get_highlight_script_if_recently_updated( div_id, curr_updated_on )
        table_data = content_tag( :div, table_data, :id => div_id ) + "\r\n"
        unless script_text.blank?
          table_data << content_tag( :script, script_text, :type => "text/javascript" ) + "\r\n"
        end
      end
      sOut << "    #{content_tag( :td, table_data, :class => get_schedule_cell_style(d, curr_is_receipt_issued, curr_is_receipt_delivered) )}\r\n" 
    }
    s_target_datetime = Schedule.format_datetime_coordinates_for_mysql_param( dt_start+6, curr_hour )
    schedule_notes_slot = ''
    if schedule.nil?                                
        div_id = get_unique_dom_id( 'dropslot', s_target_datetime )
        schedule_notes_slot = content_tag( :div, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', :id => div_id ) + "\r\n"
        if DRAG_N_DROP_GLOBAL_SWITCH && current_user && current_user.can_do(:appointments, :update)
          schedule_notes_slot << content_tag( :script, get_droppable_script(div_id), :type => "text/javascript" ) + "\r\n"
          dom_xref_hash[:drop_date_schedules]     << ''       
          dom_xref_hash[:drop_date_schedule_doms] << div_id
      end
    elsif schedule.must_insert? and (! schedule.is_done?)
        div_id = get_unique_dom_id( 'dragslot', s_target_datetime )
        schedule_notes_slot = content_tag( :div, schedule.get_full_description(), :id => div_id, :style => "width:100%; height:4em; background-color:inherit;" ) + "\r\n"
        if DRAG_N_DROP_GLOBAL_SWITCH && current_user && current_user.can_do(:appointments, :update)
          schedule_notes_slot << content_tag( :script, get_draggable_script(div_id) + get_highlight_script_if_recently_updated(div_id, schedule.updated_on), :type => "text/javascript" ) + "\r\n"
          dom_xref_hash[:drag_schedule_ids]  << schedule.id
          dom_xref_hash[:drag_schedule_doms] << div_id
        end
    else
      div_id = get_unique_dom_id( 'slot', s_target_datetime )
      schedule_notes_slot = content_tag( :div, schedule.get_full_description(), :id => div_id ) + "\r\n"
      script_text = get_highlight_script_if_recently_updated( div_id, schedule.updated_on )
      unless script_text.blank?
        schedule_notes_slot << content_tag( :script, script_text, :type => "text/javascript" ) + "\r\n" 
      end
    end
    sOut << "    #{content_tag( :td, schedule_notes_slot, :class => 'schedule-notes' )}\r\n"
    return content_tag( :tr, sOut, :class => 'schedule-row' )
  end
def table_row_for_week ( curr_date , start_time , offset_min , schedule , appointments_cache , dom_xref_hash ) current_user = LeUser . find ( session [ :le_user_id ] ) curr_tot_min = start_time . hour * 60 + start_time . min + offset_min curr_hour_digit = curr_tot_min / 60 curr_min_digit = curr_tot_min % 60 sTemp = "" << start_time . year . to_s << "-" << "%02u" % start_time . month . to_s << "-" << "%02u" % start_time . day . to_s << " " << "%02u" % curr_hour_digit . to_s << ":" << "%02u" % curr_min_digit . to_s << ":00" curr_hour = DateTime . parse ( sTemp ) sOut = "\r\n" dt_start = Schedule . get_week_start ( curr_date ) dt_start . step ( dt_start + 5 , 1 ) { | d | curr_name = "" curr_updated_on = nil curr_id = 0 curr_is_receipt_issued = false s_target_datetime = Schedule . format_datetime_coordinates_for_mysql_param ( d , curr_hour ) for app in appointments_cache if s_target_datetime == Schedule . format_datetime_for_mysql_param ( app . date_schedule ) curr_name = app . get_full_name curr_id = app . id curr_updated_on = app . updated_on curr_is_payed = app . is_payed? curr_is_receipt_issued = app . is_receipt_issued curr_is_receipt_delivered = app . is_receipt_delivered break end end table_data = ( curr_is_payed ? content_tag ( :div , '' , :class => 'schedule-payed-img' ) : '' ) + link_to_unless ( ( current_user . nil? || ! ( curr_name . blank? ? current_user . can_do ( :appointments , :create ) : current_user . can_do ( :appointments , :show ) ) ) , "%02u" % curr_hour_digit . to_s << ":" << "%02u" % curr_min_digit . to_s , ( curr_name . blank? ? edit_appointments_path ( :id => curr_id , :curr_time => s_target_datetime ) : show_appointments_path ( :id => curr_id , :curr_time => s_target_datetime ) ) ) + "<br/>" + h ( curr_name ) if curr_name . blank? div_id = get_unique_dom_id ( 'dropapp' , s_target_datetime ) table_data = content_tag ( :div , table_data , :id => div_id ) + "\r\n" if DRAG_N_DROP_GLOBAL_SWITCH && current_user && current_user . can_do ( :appointments , :update ) table_data << content_tag ( :script , get_droppable_script ( div_id ) , :type => "text/javascript" ) + "\r\n" dom_xref_hash [ :drop_date_schedules ] << s_target_datetime dom_xref_hash [ :drop_date_schedule_doms ] << div_id end elsif ! curr_is_receipt_issued div_id = get_unique_dom_id ( 'dragapp' , s_target_datetime ) table_data = content_tag ( :div , table_data , :id => div_id , :style => "width:100%; height:4em; background-color:inherit;" ) + "\r\n" if DRAG_N_DROP_GLOBAL_SWITCH && current_user && current_user . can_do ( :appointments , :update ) table_data << content_tag ( :script , get_draggable_script ( div_id ) + get_highlight_script_if_recently_updated ( div_id , curr_updated_on ) , :type => "text/javascript" ) + "\r\n" dom_xref_hash [ :drag_appointment_ids ] << curr_id dom_xref_hash [ :drag_appointment_doms ] << div_id end else div_id = get_unique_dom_id ( 'app' , s_target_datetime ) script_text = get_highlight_script_if_recently_updated ( div_id , curr_updated_on ) table_data = content_tag ( :div , table_data , :id => div_id ) + "\r\n" unless script_text . blank? table_data << content_tag ( :script , script_text , :type => "text/javascript" ) + "\r\n" end end sOut << "    #{content_tag( :td, table_data, :class => get_schedule_cell_style(d, curr_is_receipt_issued, curr_is_receipt_delivered) )}\r\n" } s_target_datetime = Schedule . format_datetime_coordinates_for_mysql_param ( dt_start + 6 , curr_hour ) schedule_notes_slot = '' if schedule . nil? div_id = get_unique_dom_id ( 'dropslot' , s_target_datetime ) schedule_notes_slot = content_tag ( :div , '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' , :id => div_id ) + "\r\n" if DRAG_N_DROP_GLOBAL_SWITCH && current_user && current_user . can_do ( :appointments , :update ) schedule_notes_slot << content_tag ( :script , get_droppable_script ( div_id ) , :type => "text/javascript" ) + "\r\n" dom_xref_hash [ :drop_date_schedules ] << '' dom_xref_hash [ :drop_date_schedule_doms ] << div_id end elsif schedule . must_insert? and ( ! schedule . is_done? ) div_id = get_unique_dom_id ( 'dragslot' , s_target_datetime ) schedule_notes_slot = content_tag ( :div , schedule . get_full_description ( ) , :id => div_id , :style => "width:100%; height:4em; background-color:inherit;" ) + "\r\n" if DRAG_N_DROP_GLOBAL_SWITCH && current_user && current_user . can_do ( :appointments , :update ) schedule_notes_slot << content_tag ( :script , get_draggable_script ( div_id ) + get_highlight_script_if_recently_updated ( div_id , schedule . updated_on ) , :type => "text/javascript" ) + "\r\n" dom_xref_hash [ :drag_schedule_ids ] << schedule . id dom_xref_hash [ :drag_schedule_doms ] << div_id end else div_id = get_unique_dom_id ( 'slot' , s_target_datetime ) schedule_notes_slot = content_tag ( :div , schedule . get_full_description ( ) , :id => div_id ) + "\r\n" script_text = get_highlight_script_if_recently_updated ( div_id , schedule . updated_on ) unless script_text . blank? schedule_notes_slot << content_tag ( :script , script_text , :type => "text/javascript" ) + "\r\n" end end sOut << "    #{content_tag( :td, schedule_notes_slot, :class => 'schedule-notes' )}\r\n" return content_tag ( :tr , sOut , :class => 'schedule-row' ) end
Builds a single HTML table row for displaying a single appointments line in
current week's schedule, computing the week range with the same algorithm used
in table_header_for_week.
Builds a single HTML table row for displaying a single appointments line in current week ' s schedule computing the week range with the same algorithm used in table_header_for_week .
# (Add CR+LF for each table row to improve generated source readibility) # -- DAY CELL SLOT: add a table cell to the row for each working day: # Build-up basic link to insert into the cell: # Make table cell data draggable or droppable, if we can: # 'DROP'-appointment type: # 'DRAG'-appointment type: # 'FIXED'-appointment type: # Encapsulate data in table cell: # -- SCHEDULE NOTES SLOT: add another table cell at the end of the row: # 'DROP'-slot type: # leave schedule date blank for empty side slots that are drop targets # 'DRAG'-slot type: # 'FIXED'-slot type:
curr_date
start_time
offset_min
schedule
appointments_cache
dom_xref_hash