class CourseDiploma

Shows the existing courses and the courses on the server, so that the two can be synchronized.

Public Instance Methods

layout() click to toggle source
# File Views/Course/Diploma.rb, line 10
def layout
  set_data_class :Courses
  @order = 30
  @update = true

  gui_hbox do
    gui_vbox :nogroup do
      show_table :diplomas_t, :headings => [:Name, :Grade, :State, :PDF],
                 :widths => [200, 50, 100], :height => 500,
                 :columns => [0, 0, 0, :html]
    end
    gui_vbox :nogroup do
      gui_fields do
        show_info :status
        show_button :do_diplomas, :abort
      end
      show_print :print
    end
    gui_window :missing_data do
      show_html :missing
      show_button :close
    end
    gui_window :printing do
      show_html :msg_print
      show_button :close
    end
  end
end
rpc_button_abort(session, args) click to toggle source
# File Views/Course/Diploma.rb, line 194
def rpc_button_abort(session, args)
  course_id = args._courses[0]
  course = Entities.Courses.match_by_course_id(course_id)
  course.abort_pdfs
  reply(:unhide, :do_diplomas) +
      reply(:hide, :abort) +
      reply(:auto_update, 0) +
      rpc_list_choice(session, 'courses', args)
end
rpc_button_close(session, args) click to toggle source
# File Views/Course/Diploma.rb, line 137
def rpc_button_close(session, args)
  reply(:window_hide) +
      reply(:empty_selections)
end
rpc_button_do_diplomas(session, args) click to toggle source
# File Views/Course/Diploma.rb, line 61
def rpc_button_do_diplomas(session, args)
  course_id = args._courses[0]
  course = Courses.match_by_course_id(course_id)
  if not course or course.export_check
    if course
      return reply(:window_show, :missing_data) +
          reply(:update, :missing => 'The following fields are not filled in:<br>' +
                           course.export_check.join('<br>'))
    end
  else
    course.prepare_diplomas

    rpc_list_choice(session, :courses, :courses => [course_id.to_s])
  end
end
rpc_button_print(session, args) click to toggle source
# File Views/Course/Diploma.rb, line 142
def rpc_button_print(session, args)
  ret = rpc_print(session, :print, args) +
      reply(:window_hide)
  lp_cmd = cmd_printer(session, :print)
  if (names = args['diplomas_t']).length > 0
    course_id = args['courses'][0]
    course = Courses.match_by_course_id(course_id)
    log_msg :diploma, "Printing #{names.inspect} of #{course.name}"

    files = names.collect { |f|
      file = "#{course.dir_diplomas}/#{f}"
      exts = %w( pdf png )
      while (!File.exists? file) and (exts.length > 0)
        file = "#{course.get_diploma_filename(f, exts.pop)}"
      end
      if !File.exists? file
        file = 'Not found'
      end
      dputs(3) { "Filename is #{file}" }
      name = ((p = Persons.match_by_login_name(f)) and p.full_name) ||
          {'all.zip' => 'All files', '000-4pp.pdf' => '4 on 1 page',
           '000-all.pdf' => 'All diplomas'}[f] || 'Unknown'
      [name, file]
    }
    dputs(2) { "Printing #{files.inspect}" }
    if lp_cmd
      names = []
      files.each { |name, file|
        if File.exists? file
          System.run_bool("#{lp_cmd} #{file}")
          names.push name
        end
      }
      ret += reply(:window_show, :printing) +
          reply(:update, :msg_print => 'Impression de<ul><li>' +
                           "#{names.join('</li><li>')}</li></ul>en cours")
    else
      ret += reply(:window_show, :printing) +
          reply(:update, :msg_print => 'Choisir le pdf:<ul>' +
                           files.collect { |name, file|
                             if File.exists? file
                               FileUtils.cp file, '/tmp'
                               "<li><a target='other' href=\"/tmp/#{File.basename(file)}\">#{name}</a></li>"
                             else
                               "<li>#{name} - not found</li>"
                             end
                           }.join('') + '</ul>')
    end
  end
  ret
end
rpc_list_choice_courses(session, args) click to toggle source
# File Views/Course/Diploma.rb, line 49
def rpc_list_choice_courses(session, args)
  args.to_sym!
  ret = reply(:empty_nonlists, :diplomas_t)
  if args._courses.length > 0
    if course = Courses.match_by_course_id(args._courses.to_a[0])
      course.update_state(true)
      ret += rpc_update_with_values(session, args)
    end
  end
  return ret
end
rpc_show(session) click to toggle source
Calls superclass method
# File Views/Course/Diploma.rb, line 39
def rpc_show(session)
  super(session) +
      reply(:hide, [:abort, :status])
end
rpc_update(session) click to toggle source
Calls superclass method
# File Views/Course/Diploma.rb, line 44
def rpc_update(session)
  super(session) +
      reply_print(session)
end
rpc_update_with_values(session, args) click to toggle source
# File Views/Course/Diploma.rb, line 81
def rpc_update_with_values(session, args)
  #dputs_func

  args.to_sym!
  if true
    (course_id = args._courses[0]) or return []
    #ret = rpc_list_choice( session, "courses", "courses" => course_id.to_s )
    (course = Entities.Courses.match_by_course_id(course_id)) or return []
  else
    return unless course = args._courses
  end

  ret = []

  overall_state = course.make_pdfs_state['0']
  if overall_state == 'done'
    ret += reply(:auto_update, 0) +
        reply(:hide, [:abort, :status]) +
        reply(:unhide, :do_diplomas)
  else
    ret += reply(:auto_update, -5) +
        reply(:unhide, [:abort, :status]) +
        reply(:hide, :do_diplomas) +
        reply(:update, :status => overall_state)
  end
  dputs(3) { "Overall_state is #{overall_state}" }

  states = case course.get_files.select { |f| f =~ /(000-4pp.pdf|zip)$/ }.first
             when /zip$/
               [['all.zip', ['All files', '', '', pdf_link("#{course.name}/all.zip")]]]
             when /pdf$/
               [['000-4pp.pdf', ['4 on 1 page', '', '',
                                 pdf_link("#{course.name}/000-4pp.pdf")]],
                ['000-all.pdf', ['All diplomas', '', '',
                                 pdf_link("#{course.name}/000-all.pdf")]]]
             else
               dputs(3) { course.get_files.inspect }
               []
           end
  dputs(3) { "States is #{states}" }

  states += course.make_pdfs_state.keys.reject { |k| k == '0' }.
      collect { |s|
    st = course.make_pdfs_state[s]
    p = Persons.match_by_login_name(s)
    link = st[1] == 'done' ? pdf_link(st[2]) : '---'
    [s, [p.full_name, st[0], st[1], link]]
  }.sort { |a, b|
    a[1][0] <=> b[1][0]
  }

  return ret +
      reply_print(session) +
      reply(:update, :diplomas_t => states)
end