                                    (:lessonType moduleInfo)
                                    (:lessonGroup moduleInfo)
                                    bgColorCssClass
-                                   true
-                                   ModulesMap))
+                                   true))
 
         ; Update URL hash with newly added module
         (update-document-location-hash-with-new-module!

    $divElem))

(defn- add-module-lesson!
  "Adds a single lesson of a module (obtained from the `ModulesMap` global) to
   the timetable.
   Returns a `ModulesSelectedLessonInfo` object augmented with the `:divElem`,
   `:moduleCode`, `:lessonType` and `:lessonGroup` keys."
  [moduleCode moduleName lessonType lessonLabel modulesMapLesson bgColorCssClass


   Returns a sequence of `ModulesSelectedLessonInfo` objects each augmented
   with the `:divElem`, `:moduleCode`, `:lessonType`, `:lessonGroup` keys."
  [moduleCode lessonType lessonLabel bgColorCssClass isActuallySelected?]
  (if (module-has-lesson-group? moduleCode lessonType lessonLabel)
      (let [moduleName          (get-module-name-from-module-code moduleCode)
            modulesMapLessonSeq (get-ModulesMapLesson-seq moduleCode lessonType
                                                          lessonLabel)

            augLessonInfoSeq
            (doall (map (fn [modulesMapLesson]
                          (add-module-lesson! moduleCode moduleName
                                                         lessonType
                                                         lessonLabel
                                                         modulesMapLesson
                                                         bgColorCssClass
                                                         isActuallySelected?))
                        modulesMapLessonSeq))

            lessonInfoSeq       (map #(dissoc %1 :divElem :moduleCode
                                              :lessonType :lessonGroup)
                                     augLessonInfoSeq)
            $divElemSeq         (map #(:divElem %1) augLessonInfoSeq)]
        (if isActuallySelected?
            (do
              ; Update ModulesSelected with the lesson group
              (set! ModulesSelected
                    (assoc-in ModulesSelected [moduleCode lessonType]
                              {:label lessonLabel, :info lessonInfoSeq}))

              ; Add to ModulesSelectedOrder
              (if (not-any? #{moduleCode} ModulesSelectedOrder)
                  (do
                    (set! ModulesSelectedOrder
                          (conj ModulesSelectedOrder moduleCode))
                    ; Update select2 box.
                    ; NOTE: This does a quadratic amount of work but I do not
                    ;       have a workaround.
                    (select2/select2-box-set-val
                      select2/$Select2-Box
                      (get-selected-module-codes-as-js-array))))

              ; Only lesson types with more than 1 option of lesson group
              ; will be draggable
              (if (module-lesson-type-has-multiple-choices? moduleCode
                                                            lessonType)
                  (make-added-lessons-draggable $divElemSeq moduleCode
                                                lessonType lessonLabel
                                                bgColorCssClass)))

            ; lesson was added due to draggable <div>
            ; Make it droppable
            (make-fake-lessons-droppable augLessonInfoSeq))
        augLessonInfoSeq)))

(defn add-module!
  "Adds a module to the timetable.
