Skip to content

Commit

Permalink
add eventNameExists to fix issue with event name checking, other bug …
Browse files Browse the repository at this point in the history
…fixes
  • Loading branch information
benthemonkey committed Oct 11, 2015
1 parent 28a786a commit de1b179
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
27 changes: 22 additions & 5 deletions ajax/PointsCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions ajax/eventNameExists.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
header('Content-type: text/html; charset=utf-8');
require_once "./PointsCenter.php";
$points_center = new \Slivka\PointsCenter();
$eventNameExists = $points_center->eventNameExists($_GET['event_name']);

echo json_encode(array('eventNameExists' => $eventNameExists));
8 changes: 4 additions & 4 deletions js/points-center/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 5 additions & 7 deletions js/points-center/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
});

Expand All @@ -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();
});
});
Expand Down
4 changes: 0 additions & 4 deletions js/points-center/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

This comment has been minimized.

Copy link
@benthemonkey

benthemonkey Mar 6, 2016

Author Owner

Note to self: I moved this functionality over to the specific callbacks related to the submission form. I think it was messing up the inputs on the admin page.

}
};

0 comments on commit de1b179

Please sign in to comment.