app/soc/content/js/duplicate-slots-090825.js
author Daniel Hans <Daniel.M.Hans@gmail.com>
Mon, 02 Nov 2009 23:38:43 +0100
changeset 3074 ebda36efbd61
parent 2804 92397646e5dc
permissions -rw-r--r--
HtmlSanitizer becomes Python 2.6 compatible. The Cleaner class must not have any arguments when calling __init__ function for the object class, because in this case Python 2.6 raises TypeError (while previous versions just ignored them).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
     1
(function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
     2
  var duplicateSlots = window.duplicateSlots = function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
     3
  };
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
  // 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
     5
  // incrementally
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
  var orgs_details = {};
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
  // 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
     8
  // filled incrementally
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
     9
  var assigned_proposals = [];
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    11
  // public function to output actual HTML out of the data (cached or not)
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    12
  duplicateSlots.showDuplicatesHtml =
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    13
    function (orgs_details, student, student_key, proposals) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    14
      /*jslint undef:false */
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    15
      if (html_string === '') {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    16
        jQuery("#div_duplicate_slots").html('');
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    17
        html_string = '<ul>';
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
      }
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    19
      html_string += [
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    20
        '<li>',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    21
        '  Student: ',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    22
        '    <strong>',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    23
        '      <a href="/student/show/', student_key, '">', student.name,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    24
        '</a>',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    25
        '    </strong> ',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    26
        '(<a href="mailto:', student.contact, '">', student.contact, '</a>)'
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    27
      ].join("");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    28
      html_string += '<ul>';
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    29
      jQuery(proposals).each(
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    30
        function (intIndex, proposal) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    31
          html_string += [
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    32
            '<li>',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    33
            '  Organization: ',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    34
            '    <a href="/org/show/', proposal.org_key, '">',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    35
            orgs_details[proposal.org_key].name,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    36
            '</a>, admin: ', orgs_details[proposal.org_key].admin_name,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    37
            ' (<a href="mailto:',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    38
            orgs_details[proposal.org_key].admin_email,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    39
            '">',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    40
            orgs_details[proposal.org_key].admin_email, '</a>)</li>'
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    41
          ].join("");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    42
          html_string += [
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    43
            '<ul>',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    44
            '  <li>',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    45
            'Proposal: ',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    46
            '<a href="/student_proposal/show/', proposal.proposal_key, '">',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    47
            proposal.proposal_title, '</a>',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    48
            '  </li>',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    49
            '</ul>'
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    50
          ].join("");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    51
        }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    52
      );
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    53
      html_string += '</ul></li>';
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    54
      html_string += '</ul>';
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    55
      jQuery("#div_duplicate_slots").html(html_string);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    56
      /*jslint undef:true */
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    57
    };
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    59
  // private function to generate the JSON to send for caching and calling
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    60
  // the actual function that will print the data
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    61
  function printDuplicatesAndSendJSON() {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    62
    // JSON skeleton that need to be sent to the server
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    63
    var to_json = {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    64
      "data": {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    65
        "orgs" : orgs_details,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    66
        "students": {}
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    67
      }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    68
    };
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    69
    // for every student...
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    70
    jQuery.each(assigned_proposals, function (student_key, student) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    71
      var accepted_proposals = student.proposals.length;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    72
      // if accepted proposal are less than 2, then ignore and
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    73
      // continue the iteration
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    74
      if (accepted_proposals < 2) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    75
        return true;
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    76
      }
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    77
      // push this student to the caching JSON
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    78
      to_json.data.students[student_key] = student;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    79
      var proposals = student.proposals;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    80
      // call the function that prints the output html
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    81
      duplicateSlots.showDuplicatesHtml(
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    82
        orgs_details, student, student_key, proposals
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    83
      );
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    84
    });
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    85
    /*jslint undef:false */
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    86
    if (html_string === "") {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    87
    /*jslint undef:true */
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    88
      jQuery("#div_duplicate_slots")
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    89
        .html("<strong>No duplicate slots found</strong>");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    90
    }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    91
    // at the end, send the JSON for caching purposes
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    92
    jQuery.ajax({
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    93
      url: location.href,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    94
      type: 'POST',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    95
      processData: true,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    96
      data: {result: JSON.stringify(to_json)},
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    97
      contentType: 'application/json',
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    98
      dataType: 'json'
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
    99
    });
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
  }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   101
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   102
  // 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
   103
  // private global variables
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   104
  function loadSingleJSONData(data) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   105
    if (data) {
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   106
      // pushing org details
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   107
      jQuery.each(data.data.orgs, function (org_key, organization) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   108
        orgs_details[org_key] = organization;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   109
      });
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   110
      // pushing proposals
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   111
      jQuery(data.data.proposals).each(
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   112
        function (intIndex, proposal) {
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   113
          // if this student_key is not yet present
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   114
          if (assigned_proposals[proposal.student_key] === undefined) {
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   115
            // create the object and insert general info
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   116
            assigned_proposals[proposal.student_key] = {};
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   117
            assigned_proposals[proposal.student_key].name =
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   118
              proposal.student_name;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   119
            assigned_proposals[proposal.student_key].contact =
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   120
              proposal.student_contact;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   121
            assigned_proposals[proposal.student_key].proposals = [];
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
          }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   123
          // anyway, push the accepted proposals
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   124
          assigned_proposals[proposal.student_key].proposals.push(
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
              "org_key" : proposal.org_key,
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   127
              "proposal_key" : proposal.key_name,
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   128
              "proposal_title": proposal.proposal_title
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
        }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   132
      );
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   133
    }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   134
  }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   135
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   136
  function showDuplicates(url_to_query, OFFSET_LENGTH, NUMBER_OF_ORGS) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   137
    var current_offset = 0;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   138
    orgs_details = {};
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   139
    assigned_proposals = [];
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   140
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   141
    // Here Ajax call is handled
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   142
    setTimeout(
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   143
      function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   144
        jQuery.ajax({
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   145
          cache: false,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   146
          mode: "sync",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   147
          type: "GET",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   148
          timeout: 1000000,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   149
          dataType: "json",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   150
          url: [
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   151
            "/program/assigned_proposals/", url_to_query,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   152
            "?limit=", OFFSET_LENGTH,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   153
            "&offset=", current_offset
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   154
          ].join(""),
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   155
          success: function (data, textStatus) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   156
            if (data) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   157
              // Load JSON data
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   158
              loadSingleJSONData(data);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   159
            }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   160
          },
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   161
          error: function (XMLHttpRequest, textStatus, errorThrown) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   162
            // if there is an error return the button and
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   163
            // leave a try again message
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   164
            if (XMLHttpRequest !== undefined) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   165
              jQuery("#id_button_duplicate_slots").fadeIn("slow",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   166
                function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   167
                  jQuery("#description_done").html([
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   168
                    "<strong class='error'> ",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   169
                    "Error encountered, try again",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   170
                    "</strong>"
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   171
                  ].join(""));
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   172
                }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   173
              );
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   174
            }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   175
          }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   176
        });
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   177
        current_offset += OFFSET_LENGTH;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   178
        if (current_offset < NUMBER_OF_ORGS) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   179
          setTimeout(arguments.callee, 1);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   180
        }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   181
      },
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   182
      1
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   183
    );
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   184
    // This prevent page reloading after each ajax call
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   185
    return false;
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   186
  }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   187
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   188
  // public function to begin iterating load of JSONs and then call printing
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   189
  // of duplicates
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   190
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   191
  duplicateSlots.showDuplicatesInit = function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   192
    /*jslint undef:false */
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   193
    html_string = '';
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   194
    // Remember this object for Javascript scoping
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   195
    var this_object = this;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   196
    var NUMBER_OF_ORGS = number_of_orgs;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   197
    var OFFSET_LENGTH = offset_length;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   198
    // Variables to handle progress bar updating
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   199
    var ITERATIONS = (number_of_orgs % offset_length) === 0 ?
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   200
      Math.floor(number_of_orgs / offset_length) :
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   201
      Math.floor(number_of_orgs / offset_length) + 1;
2804
92397646e5dc JSLint comment moved because of new uncompressed JSLint complains.
Mario Ferraro <fadinlight@gmail.com>
parents: 2801
diff changeset
   202
    /*jslint undef:true */
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   203
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   204
    if (ITERATIONS === 0) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   205
      jQuery("#div_duplicate_slots")
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   206
        .html("<strong>No org slots to process</strong>");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   207
      return;
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   208
    }
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   209
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   210
    var successful_calls = 0;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   211
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   212
    jQuery("#id_button_duplicate_slots").fadeOut("slow",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   213
      function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   214
        jQuery("#duplicates_progress_bar").progressBar(0);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   215
        jQuery("#description_done").html("");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   216
        // For every ajax success, bind this function to update user feedback
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   217
        jQuery(this).bind("ajaxSuccess", function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   218
          successful_calls++;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   219
          var percentage = Math.floor(100 * (successful_calls) / (ITERATIONS));
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   220
          jQuery("#duplicates_progress_bar").progressBar(percentage);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   221
          jQuery("#description_progressbar").html([
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   222
            " Processed orgs chunk ", successful_calls, "/", ITERATIONS
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   223
          ].join(""));
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   224
          // If this is the last call, feedback the user and
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   225
          // print the duplicates data
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   226
          if (successful_calls === ITERATIONS) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   227
            jQuery("#applications_progress_bar").fadeOut("slow",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   228
              function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   229
                jQuery("#duplicates_progress_bar").progressBar(0);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   230
                jQuery("#id_button_duplicate_slots").fadeIn("slow");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   231
              }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   232
            );
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   233
            jQuery("#description_progressbar").html("");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   234
            jQuery("#description_done").html("<strong> Done!</strong>");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   235
            jQuery("#duplicates_progress_bar").fadeOut("slow",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   236
              function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   237
                jQuery("#id_button_duplicate_slots").val("Recalculate").fadeIn(
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   238
                  "slow",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   239
                  function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   240
                    // Call printing to HTML function with correct scope
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   241
                    printDuplicatesAndSendJSON.call(this_object);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   242
                  }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   243
                );
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   244
              }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   245
            );
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   246
          }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   247
        });
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   248
        // Call the showDuplicates function for the first time
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   249
        // with correct scope
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   250
        jQuery("#duplicates_progress_bar").fadeIn(
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   251
          "slow",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   252
          showDuplicates.apply(
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   253
            this_object,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   254
            /*jslint undef:false */
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   255
            [url_to_query, OFFSET_LENGTH, NUMBER_OF_ORGS]
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   256
            /*jslint undef:true */
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   257
          )
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   258
        );
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   259
      }
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   260
    );
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   261
  };
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2302
diff changeset
   262
}());