anchor.diff:          }
       });
   
  -    $('a.academic_milestones_generator').click(function() {
  +    $('a.a_academic_milestones_generator').click(function() {
  +        $('#span_error').hide();
           if($("#ivle_token").length && $("#mapping_module").length) {
  -            var DATE_FORMAT = 'YYYY-MM-DDThh:mm:ss';
  -            var milestones = [];
               var key = $("#ivle_api").val(), token = $("#ivle_token").val(), user = ivle.User(key, token);
               user.init().done(function () {
               });
  
positive.code:               <li id="lesson-plan-open-milestone-generator" data-toggle="modal" data-target="#lesson-plan-multi-milestone" >
                  <a href="#">Generate Milestones</a>
                </li>
                <li>
                  <a class="academic_milestones_generator" href="#">Generate NUS Academic Milestones</a>
                </li>
              </ul>
            </div>
  
negative.code:                     .success(function (data) {
                          current_year = data.Results[0].AcadYear;
                          current_semester = data.Results[0].AcadSemester;
                          $("#select-academic-year").empty();
                          $("#select-academic-year").append("<option value='" + current_year + "'>" + current_year + "</option>");
                          next_year = (parseInt(current_year.split('/')[0]) + 1) + '/' + (parseInt(current_year.split('/')[1]) + 1);
                          $("#select-academic-year").append("<option value='" + next_year + "'>" + next_year + "</option>");
                          $("#select-semester").empty();
                          for (i = 1; i <= 4; i++) {
                              $("#select-semester").append("<option value='" + i + "'>" + i + "</option>");
                          }
                          $("#select-semester").val(current_semester);
                      });
          }
      });
  
      $('#btn-generate-nus-calendar-milestone').click(function() {
          $('#span_error').hide();
          var key = $("#ivle_api").val(), token = $("#ivle_token").val(), user = ivle.User(key, token);
          user.init().done(function () {
          });
          var DATE_FORMAT = 'YYYY-MM-DDThh:mm:ss';
          var milestones = [];
          var current_year = $("#select-academic-year").val(), current_semester = $("#select-semester").val();
          if(current_year.length && current_semester.length) {
              user.get("MyOrganizer_AcadSemesterInfo", {AcadYear: current_year, Semester: current_semester})
                      .success(function (data) {
                          if(data.Results.length > 0) {
                              $.each(data.Results, function (ind, val) {
                                  if (val.TypeName != "0" && val.TypeName != "Vacation") {
                                      var date_start = moment(val.WeekTypeStartDate_js, DATE_FORMAT);
                                      var date_end = moment(val.WeekTypeEndDate_js, DATE_FORMAT);
                                      milestones.push({
                                          title: $.isNumeric(val.TypeName) ? ( "Week" + ' ' + val.TypeName) : (val.TypeName + ' ' + "Week"),
                                          start_at: date_start.clone(),
                                          end_at: date_end.clone()
                                      });
                                  }
                              });
                              var upload_milestones = milestones.map(function (milestone) {
                                  return {
                                      title: milestone.title,
                                      description: '',
                                      start_at: milestone.start_at.format(DATE_FORMAT),
                                      end_at: milestone.end_at.format(DATE_FORMAT)
                                  };
                              });
  
                              var promise = $.ajax({
                                  type: 'POST',
                                  url: 'lesson_plan/milestones.json',
                                  data: {
                                      lesson_plan_milestone: upload_milestones
                                  },
                                  dataType: 'json'
                              });
  
                              // Wait for all the requests to come back before closing the dialog.
                              promise.then(function () {
                                  location.reload();
                              }, function () {
                                  alert('An error occurred while processing your request.');
                                  location.reload();
                              });
                          }else{
                              $('#span_error').text("No data for this Year and Semester");
                              $('#span_error').show();
                          }
                          return false;
                      });
          }
      });
  
  
  
  </script>