app/soc/content/js/bulk-review-090825.js
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 12 Sep 2009 01:19:23 +0200
changeset 2903 bf17c6a843dd
parent 2801 0ee67cc9bd20
permissions -rw-r--r--
Add ValueStoreMiddleware Based on the view decorator.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
     1
jQuery(document).ready(function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
     2
  jQuery("#applications_progress_bar").progressBar({showText: false});
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
});
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
     5
function bulkReview(data) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
     6
  // some global constants
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
     7
  var GLOBAL_LINK = data.link;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
     8
  var TOTAL_APPLICATIONS = data.nr_applications;
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    10
  // some global variables set needed for internal iteration
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    11
  var application_index = 0;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    12
  // number of iteration is not taken from data.nr_applications
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    13
  // to ensure avoidance of array out of bounds errors
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    14
  var total_index = data.applications.length;
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    15
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    16
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    17
  // call immediately the function for review
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    18
  // real iteration is inside
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    19
  setTimeout(
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    20
    function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    21
      var error_happened = false;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    22
      var application = data.applications[application_index];
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    23
      var current_application = application_index + 1;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    24
      // regular expression to find a valid scope path
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    25
      // inside matching parenthesis
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    26
      var re = /\((\w*)\)/;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    27
      var scope_path = GLOBAL_LINK.match(re)[1];
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    28
      // the URL is obtained by using the scope path found
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    29
      // in the matching parenthesis
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    30
      var url_to_call = GLOBAL_LINK.replace(re, application[scope_path]);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    31
      // now we can call the URL found
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    32
      jQuery.ajax({
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    33
        async: false,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    34
        cache: false,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    35
        url: url_to_call,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    36
        timeout: 10000,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    37
        success: function (data) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    38
          if (data) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    39
            // update progress bar percentage and description
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    40
            var percentage =
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    41
              Math.floor(100 * (current_application) / (TOTAL_APPLICATIONS));
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    42
            jQuery("#description_progressbar").html([
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    43
              " Processed application ", application.name,
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    44
              " (", current_application, "/", TOTAL_APPLICATIONS, ")"
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    45
            ].join(""));
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    46
            jQuery("#applications_progress_bar").progressBar(percentage);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    47
          }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    48
        },
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    49
        error: function (XMLHttpRequest, textStatus, errorThrown) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    50
          // if there is an error return the button and
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    51
          // leave a try again message
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    52
          error_happened = true;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    53
          jQuery("[id^=button_bulk_]").fadeIn(
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    54
            "slow",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    55
            function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    56
              jQuery("#description_done").html([
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    57
                "<strong class='error'>",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    58
                "  Error encountered, try again",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    59
                "</strong>"
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    60
              ].join(""));
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    61
            }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    62
          );
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    63
        }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    64
      });
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    65
      // if there were no errors, continue the iteration
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    66
      if (!error_happened) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    67
        // prepare for new iteration and then recall this function
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    68
        application_index++;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    69
        if (application_index < total_index) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    70
          setTimeout(arguments.callee, 0);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    71
        }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    72
        else {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    73
          // all ok, tell the user we are done
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    74
          jQuery("#applications_progress_bar").fadeOut(
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    75
            "slow",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    76
            function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    77
              jQuery("#applications_progress_bar").progressBar(0);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    78
              jQuery("[id^=button_bulk_]").fadeIn("slow");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    79
            }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    80
          );
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    81
          jQuery("#description_progressbar").html("");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    82
          jQuery("#description_done").html("<strong>Done!</strong>");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    83
        }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    84
      }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    85
    },
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    86
    0
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    87
  );
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    88
}
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    89
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    90
function bulkReviewInit(bulk_review_link, button) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    91
  // get the JSON object with details of every application for bulk acceptance
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    92
  jQuery.getJSON(
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    93
    bulk_review_link + "?_=" + (new Date().getTime()),
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    94
    function (data) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    95
      // If there are applications to review...
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    96
      if (data.nr_applications !== 0) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    97
        //...then fade out the button, show the progress bar and call the function for review
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    98
        jQuery("[id^=button_bulk_]").fadeOut(
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
    99
          "slow",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   100
          function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   101
            jQuery("#applications_progress_bar").progressBar(0);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   102
            jQuery("#description_done").html("");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   103
            jQuery("#applications_progress_bar").fadeIn("slow", bulkReview(data));
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   104
          }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   105
        );
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   106
      }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   107
      else {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   108
        var no_organization_text = "No organizations to ";
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   109
        if (jQuery(button).attr("id").indexOf("reject") !== -1) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   110
          no_organization_text += "reject";
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   111
        }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   112
        else {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   113
          no_organization_text += "accept";
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   114
        }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   115
        jQuery("#description_done").html("<strong>" + no_organization_text + "</strong>");
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   116
      }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   117
    }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 1646
diff changeset
   118
  );
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
}