app/soc/content/js/duplicate-slots-090331.js
author Sverre Rabbelier <sverre@rabbelier.nl>
Thu, 30 Apr 2009 23:33:04 +0200
changeset 2287 f668847ebb75
parent 2044 3aa6123be2a7
child 2301 fd14daa4b45a
permissions -rw-r--r--
Make dev_appserver error out when python version >2.5 is used Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
var duplicateSlots = new function() {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
  // this variable will contain all the org details, and filled
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
  // incrementally
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
  var orgs_details = {};
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
  // this variable will contain all student/proposal data details,
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
  // filled incrementally
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
  var assigned_proposals = new Array();
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
  // public function to begin iterating load of JSONs and then call printing
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
  // of duplicates
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
  this.showDuplicatesInit = function() {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
    // Remember this object for Javascript scoping
2034
59de158c936d Fixed the duplicate slots view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2033
diff changeset
    15
    html_string = '';
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
    var this_object = this;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
    var NUMBER_OF_ORGS = number_of_orgs;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
    var OFFSET_LENGTH = offset_length;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
    // Variables to handle progress bar updating
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
    var ITERATIONS = (number_of_orgs % offset_length)==0 ? Math.floor(number_of_orgs/offset_length) : Math.floor(number_of_orgs/offset_length)+1;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
    var successful_calls = 0;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
    $("#id_button_duplicate_slots").fadeOut("slow",
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
      function() {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
        $("#duplicates_progress_bar").progressBar(0);
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
        $("#description_done").html("");
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
        // For every ajax success, bind this function to update user feedback
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
        $(this).bind("ajaxSuccess", function() {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
          successful_calls++;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
          var percentage = Math.floor(100 * (successful_calls) / (ITERATIONS));
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
          $("#duplicates_progress_bar").progressBar(percentage);
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
          $("#description_progressbar").html(" Processed orgs chunk " + (successful_calls) + "/" + ITERATIONS);
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
          // If this is the last call, feedback the user and print the duplicates data
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
          if (successful_calls==ITERATIONS) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
            $("#applications_progress_bar").fadeOut("slow",
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
              function() {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
                $("#duplicates_progress_bar").progressBar(0);
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
                $("#id_button_duplicate_slots").fadeIn("slow");
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
              }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
            );
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
            $("#description_progressbar").html("");
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
            $("#description_done").html("<strong> Done!</strong>");
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
            $("#duplicates_progress_bar").fadeOut("slow",
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
              function() {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
                $("#id_button_duplicate_slots").val("Recalculate").fadeIn("slow",
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
                  function() {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
                    // Call printing to HTML function with correct scope
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
                    printDuplicatesAndSendJSON.call(this_object);
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
                  }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
                );
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
              }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
            );
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
          }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
        });
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
        // Call the showDuplicates function for the first time with correct scope
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
        $("#duplicates_progress_bar").fadeIn("slow", showDuplicates.apply(this_object,[url_to_query,OFFSET_LENGTH,NUMBER_OF_ORGS]));
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
      }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
    );
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
  }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
  function showDuplicates(url_to_query,OFFSET_LENGTH,NUMBER_OF_ORGS) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
    var current_offset = 0;
2034
59de158c936d Fixed the duplicate slots view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2033
diff changeset
    63
    orgs_details = {};
59de158c936d Fixed the duplicate slots view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2033
diff changeset
    64
    assigned_proposals = new Array();
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
    // Here Ajax call is handled
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
    setTimeout(function() {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
      $.ajax({
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    69
        cache:false,
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
        mode: "sync",
2044
3aa6123be2a7 Now using GET request for getting the data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2042
diff changeset
    71
        type: "GET",
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
        timeout: 1000000,
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
        dataType: "json",
2044
3aa6123be2a7 Now using GET request for getting the data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2042
diff changeset
    74
        url: "/program/assigned_proposals/"+url_to_query+"?limit="+OFFSET_LENGTH+"&offset="+current_offset,
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    75
        success: function (data, textStatus) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    76
          if (data) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    77
            // Load JSON data
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    78
            loadSingleJSONData(data);
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    79
          }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    80
        },
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    81
        error: function(XMLHttpRequest, textStatus, errorThrown) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    82
          // if there is an error return the button and leave a try again message
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    83
          if (XMLHttpRequest!=undefined) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    84
            $("#id_button_duplicate_slots").fadeIn("slow", function() {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    85
	      $("#description_done").html("<strong class='error'> Error encountered, try again</strong>");
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
            });
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    87
          }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    88
       }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    89
      });
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
      current_offset+=OFFSET_LENGTH;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
      if (current_offset<NUMBER_OF_ORGS) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
        setTimeout(arguments.callee,1);
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
      }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    94
    },1);
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    95
    // This prevent page reloading after each ajax call
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    96
    return false;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    97
  }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    98
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    99
  // private function to load a JSON and pushing the data to the
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
  // private global variables
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   101
  function loadSingleJSONData(data) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   102
    if (data) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   103
      // pushing org details
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   104
      for (var org_key in data.data.orgs) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   105
        orgs_details[org_key] = data.data.orgs[org_key];
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   106
      }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   107
      // pushing proposals
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   108
      $(data.data.proposals).each(
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   109
        function(intIndex, proposal) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   110
          // if this student_key is not yet present
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   111
          if (assigned_proposals[proposal.student_key]==undefined) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   112
            // create the object and insert general info
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   113
            assigned_proposals[proposal.student_key] = {};
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   114
            assigned_proposals[proposal.student_key].name = proposal.student_name;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   115
            assigned_proposals[proposal.student_key].contact = proposal.student_contact;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   116
            assigned_proposals[proposal.student_key].proposals = new Array();
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   117
          }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   118
          // anyway, push the accepted proposals
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
          assigned_proposals[proposal.student_key].proposals.push(
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
            {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   121
              "org_key" : proposal.org_key,
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
              "proposal_key" : proposal.key_name,
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   123
              "proposal_title": proposal.proposal_title
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   124
            }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   125
          );
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   126
        }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   127
      );
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   128
    }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   129
  }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   130
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   131
  // private function to generate the JSON to send for caching and calling
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   132
  // the actual function that will print the data
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   133
  function printDuplicatesAndSendJSON() {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   134
    // JSON skeleton that need to be sent to the server
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   135
    var to_json = {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   136
      "data": {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   137
        "orgs" : orgs_details,
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   138
        "students": {}
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   139
      }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   140
    }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   141
    // for every student...
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   142
    for (var student_key in assigned_proposals) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   143
      var accepted_proposals = assigned_proposals[student_key].proposals.length;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   144
      // if accepted proposal are less than 2, then ignore and continue the iteration
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   145
      if (accepted_proposals<2) continue;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   146
      var student = assigned_proposals[student_key];
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   147
      // push this student to the caching JSON
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   148
      to_json.data.students[student_key] = student;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   149
      var proposals = student.proposals;
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   150
      // call the function that prints the output html
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   151
      this.showDuplicatesHtml(orgs_details,student,student_key,proposals);
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   152
    }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   153
    if (html_string=="") {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   154
      $("#div_duplicate_slots").html("<strong>No duplicate slots found</strong>");
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   155
    }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   156
    // at the end, send the JSON for caching purposes
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   157
    $.ajax({
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   158
      url: location.href,
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   159
      type: 'POST',
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   160
      processData: true,
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   161
      data: {result: JSON.stringify(to_json)},
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   162
      contentType: 'application/json',
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   163
      dataType: 'json',
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   164
    });
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   165
  }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   166
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   167
  // public function to output actual HTML out of the data (cached or not)
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   168
  this.showDuplicatesHtml = function(orgs_details,student,student_key,proposals) {
2034
59de158c936d Fixed the duplicate slots view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2033
diff changeset
   169
    if (html_string == '') {
59de158c936d Fixed the duplicate slots view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2033
diff changeset
   170
      $("#div_duplicate_slots").html('');
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   171
      html_string='<ul>';
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   172
    }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   173
    html_string+= '<li>Student: <strong><a href="/student/show/'+student_key+'">'+student.name+'</a></strong> (<a href="mailto:'+student.contact+'">'+student.contact+'</a>)';
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   174
    html_string+='<ul>';
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   175
    $(proposals).each(
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   176
      function (intIndex, proposal) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   177
        html_string+='<li>Organization: <a href="/org/show/'+proposal.org_key+'">'+orgs_details[proposal.org_key].name+'</a>, admin: '+orgs_details[proposal.org_key].admin_name+' (<a href="mailto:'+orgs_details[proposal.org_key].admin_email+'">'+orgs_details[proposal.org_key].admin_email+'</a>)</li>';
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   178
        html_string+='<ul><li>Proposal: <a href="/student_proposal/show/'+proposal.proposal_key+'">'+proposal.proposal_title+'</a></li></ul>';
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   179
      }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   180
    );
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   181
    html_string+='</ul></li>';
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   182
    html_string+='</ul>';
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   183
    $("#div_duplicate_slots").html(html_string);
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   184
  }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   185
}