jcm55

Views2 / CiviCRM event check-in js

Sep 19th, 2014
139
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function () {
  2.   $('#scan').focus();
  3. });
  4.  
  5. function handleScan(scandata, e) {
  6.   if (e.keyCode == 13) {
  7.     if (scandata.length) {
  8.       toggleParticipant(scandata, 1);
  9.     }
  10.     return (e.keyCode != 13);
  11.   }
  12. }
  13.  
  14. function updateStatus(message, mtype) {
  15.   $('#actionstatus').removeClass();
  16.   $('#actionstatus').addClass(mtype);
  17.   $('#actionstatus').text(message);
  18.   $('#scan').val('');
  19.   $('#scan').focus();
  20. }
  21.  
  22. function toggleParticipant(partID, scanned) {
  23.   // get participant current status
  24.   selector = '[class*="' + partID + '"]';
  25.   partRow = $(selector);
  26.   if (! partRow.length) {
  27.     updateStatus('Error: Ticket ID ' + partID + ' not found.', 'error');
  28.     return;
  29.   }
  30.   classList = partRow.attr('class').split(/\s+/);
  31.   for (var i = 0; i < classList.length; i++) {
  32.     if (classList[i].indexOf("-strike") >= 0) {
  33.       if (scanned) {
  34.         updateStatus('Error: Ticket ID ' + partID + ' already admitted.', 'error');
  35.         return;
  36.       }
  37.       var currentclass = classList[i];
  38.       var targetclass = classList[i].replace("-strike", "");
  39.       var partNewStatus = 1;
  40.     }
  41.     else if (classList[i].indexOf("table-highlighter") >= 0) {
  42.       var currentclass = classList[i];
  43.       var targetclass = currentclass + "-strike";
  44.       var partNewStatus = 2;
  45.     }
  46.   }
  47.  
  48.   // update participant row
  49.   partRow.removeClass(currentclass);
  50.   partRow.addClass(targetclass);
  51.  
  52.   // update participant with new status
  53.   $().crmAPI('Participant', 'create', {'id':partID, 'participant_status_id':partNewStatus }, { 'ajaxURL':'/civicrm/ajax/rest', success: function(data) {
  54.     if (data['is_error']) {
  55.       updateStatus(data['error_message'], 'error');
  56.       return;
  57.     }
  58.     // update checked in count
  59.     $('.view-filters form').submit();
  60.  
  61.     // update status message
  62.     message = "Ticket ID " + partID;
  63.     if (partNewStatus == 2) {
  64.       message += " accepted.";
  65.       mtype = "accept";
  66.     }
  67.     else {
  68.       message += " cleared.";
  69.       mtype = "normal";
  70.     }
  71.     setTimeout("try{ updateStatus(message, mtype); } catch(error) {}", 1500);
  72.   }});
  73. }
RAW Paste Data