diff --git a/ajax/PointsCenter.php b/ajax/PointsCenter.php index 7a091ca..7564fba 100644 --- a/ajax/PointsCenter.php +++ b/ajax/PointsCenter.php @@ -306,6 +306,17 @@ public function getRecentEvents() ); } + public function eventNameExists($event_name) + { + return count(self::fetchAllQuery( + "SELECT event_name + FROM events + WHERE qtr=:qtr AND event_name=:event_name", + PDO::FETCH_COLUMN, + array(":event_name" => $event_name) + )) > 0; + } + public function getCommitteeEvents($committee) { if ($committee == "Facilities") { @@ -513,11 +524,17 @@ public function getSlivkanBonusPoints($nu_email) $other_points = 0; } - $other_breakdown = array( - array($bonus['other1_name'] | '', $bonus['other1'] | 0), - array($bonus['other2_name'] | '', $bonus['other2'] | 0), - array($bonus['other3_name'] | '', $bonus['other3'] | 0) - ); + $other_breakdown = array(); + + if (!empty($bonus['other1_name'])) { + $other_breakdown[] = array($bonus['other1_name'], $bonus['other1']); + } + if (!empty($bonus['other2_name'])) { + $other_breakdown[] = array($bonus['other2_name'], $bonus['other2']); + } + if (!empty($bonus['other3_name'])) { + $other_breakdown[] = array($bonus['other3_name'], $bonus['other3']); + } return array( "helper" => $helper_points, diff --git a/ajax/eventNameExists.php b/ajax/eventNameExists.php new file mode 100644 index 0000000..eb58a21 --- /dev/null +++ b/ajax/eventNameExists.php @@ -0,0 +1,7 @@ +eventNameExists($_GET['event_name']); + +echo json_encode(array('eventNameExists' => $eventNameExists)); diff --git a/js/points-center/admin.js b/js/points-center/admin.js index a341ba1..05fa37b 100644 --- a/js/points-center/admin.js +++ b/js/points-center/admin.js @@ -239,10 +239,10 @@ module.exports = { utils.appendSlivkanInputs(9); $('#slivkan-entry-tab') - .on('focus', '.slivkan-entry', slivkanTypeahead); - // .on('typeahead:close', '.slivkan-entry', - // { callback: validateSlivkanName }, - // utils.destroyTypeahead); + .on('focus', '.slivkan-entry', slivkanTypeahead) + .on('typeahead:close', '.slivkan-entry', + { callback: validateSlivkanName }, + utils.destroyTypeahead); $('[data-edit-committee]').on('click', function() { var committee = $('#edit-committee').val(); diff --git a/js/points-center/submission.js b/js/points-center/submission.js index 1e096a0..9543527 100644 --- a/js/points-center/submission.js +++ b/js/points-center/submission.js @@ -85,9 +85,7 @@ var validateSlivkanName = function(entry, inBulk) { if (!foundSlivkan) { valid = false; - } - - if (type === 'Committee Only' && $('#committee').val() !== foundSlivkan.committee) { + } else if (type === 'Committee Only' && $('#committee').val() !== foundSlivkan.committee) { valid = false; } @@ -155,10 +153,10 @@ var validateEventName = function() { } else if ((eventName.length <= 32 && eventName.length >= 8) || (type === 'P2P' && eventName === 'P2P')) { eventName += ' ' + $('#date').val(); - $.getJSON(utils.ajaxRoot + '/ajax/getRecentEvents.php', function(events) { + $.getJSON(utils.ajaxRoot + '/ajax/eventNameExists.php', { event_name: eventName }, function(response) { var last; - if (events.length > 0 && _.findIndex(events, { event_name: eventName }) !== -1) { + if (response.eventNameExists) { if (type === 'IM') { last = parseInt(eventEl.val().slice(-1), 10); eventEl.val(eventEl.val().slice(0, -1) + (last + 1).toString()); @@ -709,7 +707,7 @@ module.exports = { .on('typeahead:close', '.slivkan-entry', { callback: validateSlivkanName }, utils.destroyTypeahead) - .on('typeahead:autocomplete', '.slivkan-entry', function() { + .on('typeahead:autocomplete typeahead:select', '.slivkan-entry', function() { $(this).closest('.form-group').next().find('input').focus(); }); @@ -718,7 +716,7 @@ module.exports = { .on('typeahead:close', '.fellow-entry', { callback: validateFellowName }, utils.destroyTypeahead) - .on('typeahead:autocomplete', '.fellow-entry', function() { + .on('typeahead:autocomplete typeahead:select', '.fellow-entry', function() { $(this).closest('.form-group').next().find('input').focus(); }); }); diff --git a/js/points-center/utils.js b/js/points-center/utils.js index c5a35ba..273d86c 100644 --- a/js/points-center/utils.js +++ b/js/points-center/utils.js @@ -86,9 +86,5 @@ module.exports.destroyTypeahead = function(event) { if (target.hasClass('tt-input')) { event.data.callback(target.typeahead('destroy').closest('.form-group')); - - if (TAB_PRESSED) { - target.closest('.form-group').next().find('input').focus(); - } } };