diff --git a/.eslintrc b/.eslintrc
index 0b5174a..13d996c 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -79,7 +79,7 @@ rules:
no-use-before-define: 2
# Stylistic Rules
- brace-style: [1, "1tbs"]
+ brace-style: [1, "1tbs", {"allowSingleLine": true}]
camelcase: [1, {"properties": "never"}]
comma-spacing: 1
comma-style: [2, "last"]
diff --git a/css/points-center.css b/css/points-center.css
index 3a53afb..74f4106 100644
--- a/css/points-center.css
+++ b/css/points-center.css
@@ -10,22 +10,26 @@ legend{
margin: 50px 20px 15px;
}
-.slivkan-suggestion{
- min-height: 30px;
+.tt-suggestion{
+ min-height: 30px!important;
+ height: auto!important;
}
-.slivkan-suggestion img{
+.tt-menu {
+ min-width: 260px!important;
+}
+
+.tt-suggestion img{
display: inline-block;
- position: absolute;
- right: 4px;
height: 30px;
+ float: right;
transition-duration: 0.2s;
-webkit-transition-duration: 0.2s;
-moz-transition-duration: 0.2s;
-o-transition-duration: 0.2s;
}
-.slivkan-suggestion img:hover{
+.tt-suggestion img:hover{
z-index: 100;
-webkit-transform: translate(0,60px) scale(5);
-moz-transform: translate(0,60px) scale(5);
@@ -34,7 +38,7 @@ legend{
transform: translate(0,60px) scale(5);
}
-.slivkan-dupe{
+.tt-suggestion.dupe{
color: #999999;
font-style: italic;
}
@@ -51,10 +55,6 @@ legend{
margin-left: 5px;
}
-.tt-dropdown-menu{
- min-width: 260px;
-}
-
/* committee colors
.Exec td { background-color: #2f7ed8!important; }
.Academic td { background-color: #0d233a!important; color: white; }
diff --git a/css/typeahead.js-bootstrap.css b/css/typeahead.js-bootstrap.css
index 9992504..5eab8a6 100644
--- a/css/typeahead.js-bootstrap.css
+++ b/css/typeahead.js-bootstrap.css
@@ -1,80 +1,54 @@
-.twitter-typeahead {
- width: 100%;
- position: relative;
-}
-
-.twitter-typeahead .tt-input,
-.twitter-typeahead .tt-hint {
- margin-bottom: 0;
- width: 100%;
- height: 34px;
- position: absolute;
- top: 0;
- left: 0;
-}
-
-.twitter-typeahead .tt-hint {
- color: #a1a1a1;
- z-index: 1;
- padding: 4px; /*6px 12px;*/
- border: 1px solid transparent;
-}
-
-.twitter-typeahead .tt-input {
- z-index: 2;
- border-radius: 4px;
-}
-
-.input-group-addon + .twitter-typeahead > .tt-input {
- border-radius: 0!important;
-}
-
-.input-group-appended > .twitter-typeahead > .tt-input {
- border-top-right-radius: 0!important;
- border-bottom-right-radius: 0!important;
-}
-
-.tt-menu {
- min-width: 160px;
- margin-top: 2px;
- padding: 5px 0;
- background-color: #fff;
- border: 1px solid #ccc;
- border: 1px solid rgba(0, 0, 0, .2);
- *border-right-width: 2px;
- *border-bottom-width: 2px;
- -webkit-border-radius: 6px;
- -moz-border-radius: 6px;
- border-radius: 6px;
- -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
- -moz-box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
- box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
- -webkit-background-clip: padding-box;
- -moz-background-clip: padding;
- background-clip: padding-box;
-}
-
-.tt-suggestion {
- display: block;
- padding: 4px;/*3px 20px;*/
-}
-
-.tt-suggestion.tt-cursor {
- color: #fff;
- background-color: #0081c2;
- background-image: -moz-linear-gradient(top, #0088cc, #0077b3);
- background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0077b3));
- background-image: -webkit-linear-gradient(top, #0088cc, #0077b3);
- background-image: -o-linear-gradient(top, #0088cc, #0077b3);
- background-image: linear-gradient(to bottom, #0088cc, #0077b3);
- background-repeat: repeat-x;
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0077b3', GradientType=0)
-}
-
-.tt-suggestion.tt-cursor a {
- color: #fff;
-}
-
-.tt-suggestion p {
- margin: 0;
+span.twitter-typeahead .tt-menu,
+span.twitter-typeahead .tt-dropdown-menu {
+ position: absolute;
+ top: 100%;
+ left: 0;
+ z-index: 1000;
+ display: none;
+ float: left;
+ min-width: 160px;
+ padding: 5px 0;
+ margin: 2px 0 0;
+ list-style: none;
+ font-size: 14px;
+ text-align: left;
+ background-color: #ffffff;
+ border: 1px solid #cccccc;
+ border: 1px solid rgba(0, 0, 0, 0.15);
+ border-radius: 4px;
+ -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
+ box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
+ background-clip: padding-box;
+}
+span.twitter-typeahead .tt-suggestion {
+ display: block;
+ padding: 3px 20px;
+ clear: both;
+ font-weight: normal;
+ line-height: 1.42857143;
+ color: #333333;
+ white-space: nowrap;
+}
+span.twitter-typeahead .tt-suggestion:hover,
+span.twitter-typeahead .tt-suggestion:focus,
+span.twitter-typeahead .tt-suggestion.tt-cursor {
+ color: #ffffff;
+ text-decoration: none;
+ outline: 0;
+ background-color: #337ab7;
+}
+span.twitter-typeahead {
+ width: 100%;
+}
+.input-group span.twitter-typeahead {
+ display: block !important;
+}
+.input-group span.twitter-typeahead .tt-menu {
+ top: 32px !important;
+}
+.input-group.input-group-lg span.twitter-typeahead .tt-menu {
+ top: 44px !important;
+}
+.input-group.input-group-sm span.twitter-typeahead .tt-menu {
+ top: 28px !important;
}
diff --git a/js/points-center/admin.js b/js/points-center/admin.js
index 5f60f48..a341ba1 100644
--- a/js/points-center/admin.js
+++ b/js/points-center/admin.js
@@ -1,5 +1,9 @@
'use strict';
+var _ = {
+ find: require('lodash/collection/find'),
+ forEach: require('lodash/collection/forEach')
+};
var utils = require('./utils');
var slivkans, nicknames;
var submitConfigOrQuarterInfo = function(name, value, confirmMessage) {
@@ -24,8 +28,8 @@ var slivkanTypeahead = function() {
utils.appendSlivkanInputs(1);
}
}
- if (!target.hasClass('tt-query')) {
- target.typeahead(utils.typeaheadOpts('slivkans', slivkans)).focus();
+ if (!target.hasClass('tt-input')) {
+ target.typeahead(null, utils.typeaheadOpts('slivkans', slivkans)).focus();
}
return false;
@@ -39,15 +43,14 @@ var validateSlivkanName = function(entry) {
// clear duplicates
$('#slivkan-entry-tab').find('.slivkan-entry').each(function() {
- var $self = $(this);
+ var _name = $(this).val();
- if ($self.val().length > 0) {
- if (nameArray.indexOf($self.val()) === -1) {
- nameArray.push($self.val());
+ if (_name.length > 0) {
+ if (nameArray.indexOf(_name) === -1) {
+ nameArray.push(_name);
} else {
- $self.val('');
+ $(this).val('');
$('#duplicate-alert').show();
- submission.validateSlivkanName(self.parent(), true);
}
}
});
@@ -58,7 +61,7 @@ var validateSlivkanName = function(entry) {
}
if (name.length > 0) {
- if (slivkans.indexOfKey('full_name', name) === -1) {
+ if (!utils.findSlivkan(slivkans, name)) {
valid = false;
}
utils.updateValidity(entry, valid);
@@ -70,30 +73,28 @@ var validateSlivkanName = function(entry) {
};
var addSlivkans = function(data) {
- var i, entry, name;
- var entries = $('.slivkan-entry-control', '#slivkan-entry-tab');
+ var $entries = $('.slivkan-entry-control', '#slivkan-entry-tab');
var len = data.length;
- entries.find('.slivkan-entry').val('');
+ $entries.find('.slivkan-entry').val('').each(function(i, el) {
+ utils.updateValidity($(el), null);
+ });
- if (entries.length <= len) {
- utils.appendSlivkanInputs(len - entries.length + 1);
- entries = $('.slivkan-entry-control', '#slivkan-entry-tab');
+ if ($entries.length <= len) {
+ utils.appendSlivkanInputs(len - $entries.length + 1);
+ $entries = $('.slivkan-entry-control', '#slivkan-entry-tab');
}
- for (i = 0; i < len; i++) {
- entry = entries.eq(i);
- name = slivkans[slivkans.indexOfKey('nu_email', data[i].nu_email)].full_name;
- entry.find('.slivkan-entry').val(name);
- if (data[i].points) {
- entry.find('.committee-points').val(data[i].points);
- }
- validateSlivkanName(entry);
- }
+ _.forEach(data, function(slivkan, i) {
+ var $entry = $entries.eq(i);
+ var name = _.find(slivkans, { nu_email: slivkan.nu_email }).full_name;
- for (i; i < entries.length; i++) {
- validateSlivkanName(entries.eq(i));
- }
+ $entry.find('.slivkan-entry').val(name);
+
+ if (slivkan.points) {
+ $entry.find('.committee-points').val(slivkan.points);
+ }
+ });
};
module.exports = {
@@ -238,10 +239,10 @@ module.exports = {
utils.appendSlivkanInputs(9);
$('#slivkan-entry-tab')
- .on('focus', '.slivkan-entry', slivkanTypeahead)
- .on('typeahead:closed', '.slivkan-entry.tt-query',
- { 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();
@@ -290,7 +291,7 @@ module.exports = {
for (i = 0; i < entries.length; i++) {
name = entries.eq(i).val();
if (name.length > 0) {
- nuEmailArray.push(slivkans[slivkans.indexOfKey('full_name', name)].nu_email);
+ nuEmailArray.push(utils.findSlivkan(slivkans, name).nu_email);
}
if (isCommittee) {
@@ -311,6 +312,7 @@ module.exports = {
slivkans: nuEmailArray
};
}
+
$.post(
utils.ajaxRoot + '/ajax/submitCommitteeOrSuite.php',
formData,
diff --git a/js/points-center/breakdown.js b/js/points-center/breakdown.js
index 1962f15..62214b0 100644
--- a/js/points-center/breakdown.js
+++ b/js/points-center/breakdown.js
@@ -1,173 +1,154 @@
'use strict';
+var _ = {
+ forEach: require('lodash/collection/forEach'),
+ template: require('lodash/string/template')
+};
var highcharts = require('highcharts-browserify');
var ajaxRoot = require('./utils').ajaxRoot;
var slivkans, qtrs;
-var drawChart = function(tableData, titleIn, id) {
- setTimeout(function() {
- $('#' + id).highcharts({
- credits: {
- enabled: false
- },
- plotOptions: id !== 'eventsChart' ? {} : {
- pie: {
- allowPointSelect: true,
- cursor: 'pointer',
- dataLabels: {
- enabled: true
- },
- point: {
- events: {
- select: function() {
- $('.' + this.name).css({
- 'background-color': this.color,
- 'color': 'white'
- });
- },
- unselect: function() {
- $('.' + this.name).removeAttr('style');
- }
+var eventsTemplate = _.template($('#eventsTemplate').html(), { imports: { forEach: _.forEach } });
+var otherPointsTableTemplate = _.template($('#otherPointsTableTemplate').html(), { imports: { forEach: _.forEach } });
+
+var $breakdown = $('.breakdown');
+var $attendedEvents = $('#attendedEvents');
+var $unattendedEvents = $('#unattendedEvents');
+var $otherPointsTable = $('#otherPointsTable');
+
+var $eventsChart = $('#eventsChart');
+var $imsChart = $('#imsChart');
+
+var drawChart = function($el, tableData, titleIn, width) {
+ $el.highcharts({
+ chart: {
+ width: width
+ },
+ credits: {
+ enabled: false
+ },
+ plotOptions: $el[0].id !== 'eventsChart' ? {} : {
+ pie: {
+ allowPointSelect: true,
+ cursor: 'pointer',
+ dataLabels: {
+ enabled: true
+ },
+ point: {
+ events: {
+ select: function() {
+ $('.' + this.name).css({
+ 'background-color': this.color,
+ 'color': 'white'
+ });
+ },
+ unselect: function() {
+ $('.' + this.name).removeAttr('style');
}
}
}
- },
- title: {
- text: titleIn,
- style: {
- 'font-size': '8pt'
- }
- },
- tooltip: {
- pointFormat: '{series.name}: {point.y}, {point.percentage:.1f}% '
- },
- series: [{
- type: 'pie',
- name: 'Events',
- data: tableData
- }]
- });
- }, 500);
+ }
+ },
+ title: {
+ text: titleIn,
+ style: {
+ 'font-size': '8pt'
+ }
+ },
+ tooltip: {
+ pointFormat: '{series.name}: {point.y}, {point.percentage:.1f}% '
+ },
+ series: [{
+ type: 'pie',
+ name: 'Events',
+ data: tableData
+ }]
+ });
};
var getSlivkanPoints = function() {
var nuEmail = $('#slivkan').val();
var qtr = localStorage.spc_brk_qtr || qtrs[0].qtr;
- var attendedEventsEl = $('#attendedEvents');
- var unattendedEventsEl = $('#unattendedEvents');
+ var width = $eventsChart.width();
+
+ // fix height of breakdown so there is no flash of background
+ $breakdown.parent().css('min-height', $breakdown.parent().height());
if (nuEmail.length > 0) {
localStorage.spc_brk_slivkan = nuEmail;
- $('.breakdown').fadeOut(function() {
- attendedEventsEl.empty();
- unattendedEventsEl.empty();
- $('#otherPointsTableBody').empty();
-
- $.getJSON(ajaxRoot + '/ajax/getPointsBreakdown.php', { nu_email: nuEmail, qtr: qtr }, function(data) {
- var i;
- var eventData = [];
- var imData = [];
- var eventTotal = 0;
- var imTotal = 0;
- var imExtra = 0;
- var hasOther = false;
-
- if (data.events.attended.length > 0) {
- for (i = data.events.attended.length - 1; i >= 0; i--) {
- attendedEventsEl
- .append($('
')
- .append($(' ')
- .addClass(data.events.attended[i].committee)
- .text(data.events.attended[i].event_name)));
- }
- } else {
- attendedEventsEl
- .append($(' ')
- .append($(' ').text('None :(')));
- }
+ $.when(
+ $.getJSON(ajaxRoot + '/ajax/getPointsBreakdown.php', { nu_email: nuEmail, qtr: qtr }),
+ $breakdown.fadeOut()
+ ).then(function(data) {
+ var eventData = [];
+ var imData = [];
+ var eventTotal = 0;
+ var imTotal = 0;
+ var imExtra = 0;
- if (data.events.unattended.length > 0) {
- for (i = data.events.unattended.length - 1; i >= 0; i--) {
- unattendedEventsEl
- .append($(' ')
- .append($(' ')
- .addClass(data.events.unattended[i].committee)
- .text(data.events.unattended[i].event_name)));
- }
- } else {
- unattendedEventsEl
- .append($(' ')
- .append($(' ').text('None :)')));
- }
+ data = data[0]; // only care about first entry
- for (i = 0; i < data.other_breakdown.length; i++) {
- if (data.other_breakdown[i][0]) {
- $('#otherPointsTableBody')
- .append($(' ')
- .append($(' ').text(data.other_breakdown[i][0]))
- .append($(' ').text(data.other_breakdown[i][1])));
+ $eventsChart.empty();
+ $imsChart.empty();
- hasOther = true;
- }
- }
-
- if (hasOther) {
- $('#otherPointsTable').show();
- } else {
- $('#otherPointsTable').hide();
- }
+ $attendedEvents.html(eventsTemplate({ events: data.events.attended.reverse() }));
+ $unattendedEvents.html(eventsTemplate({ events: data.events.unattended.reverse() }));
+ $otherPointsTable.html(otherPointsTableTemplate(data));
- for (i = 0; i < data.events.counts.length; i++) {
- eventData.push([data.events.counts[i].committee, parseInt(data.events.counts[i].count, 10)]);
-
- eventTotal += parseInt(data.events.counts[i].count, 10);
- }
+ _.forEach(data.events.counts, function(count) {
+ var int = parseInt(count.count, 10);
- $('.eventPoints').text(eventTotal);
- drawChart(eventData, 'Event Points (' + eventTotal + ' Total)', 'eventsChart');
+ eventData.push([count.committee, int]);
+ eventTotal += int;
+ });
- if (data.ims.length > 0) {
- $('#imsChart').show();
- for (i = 0; i < data.ims.length; i++) {
- data.ims[i].count = parseInt(data.ims[i].count, 10);
+ $('.eventPoints').text(eventTotal);
+ drawChart($eventsChart, eventData, 'Event Points (' + eventTotal + ' Total)', width);
- imData.push([data.ims[i].sport, data.ims[i].count]);
+ if (data.ims.length > 0) {
+ $imsChart.show();
+ _.forEach(data.ims, function(im) {
+ im.count = parseInt(im.count, 10);
- if (data.ims[i].count >= 3) {
- imTotal += data.ims[i].count;
- } else {
- imExtra += data.ims[i].count;
- }
- }
+ imData.push([im.sport, im.count]);
- if (imTotal > 15) {
- imExtra += imTotal - 15;
- imTotal = 15;
+ if (im.count >= 3) {
+ imTotal += im.count;
+ } else {
+ imExtra += im.count;
}
+ });
- drawChart(
- imData,
- ['IMs (', imTotal, ' Points, ', imExtra,
- (imExtra === 1 ? ' Doesn\'t' : ' Don\'t'), ' Count)'].join(''),
- 'imsChart'
- );
- } else {
- $('#imsChart').hide();
+ if (imTotal > 15) {
+ imExtra += imTotal - 15;
+ imTotal = 15;
}
- $('.imPoints').text(imTotal);
- $('.helperPoints').text(data.helper);
- $('.committeePoints').text(data.committee);
- $('.otherPoints').text(data.other);
+ drawChart(
+ $imsChart,
+ imData,
+ ['IMs (', imTotal, ' Points, ', imExtra,
+ (imExtra === 1 ? ' Doesn\'t' : ' Don\'t'), ' Count)'].join(''),
+ width
+ );
+ } else {
+ $imsChart.hide();
+ }
+
+ $('.imPoints').text(imTotal);
+ $('.helperPoints').text(data.helper);
+ $('.committeePoints').text(data.committee);
+ $('.otherPoints').text(data.other);
- $('.totalPoints').text(
- [eventTotal, imTotal, data.helper, data.committee, data.other].map(function(n) {
- return parseInt(n, 10);
- }).reduce(function(a, b) {
- return a + b;
- }));
+ $('.totalPoints').text(
+ [eventTotal, imTotal, data.helper, data.committee, data.other].map(function(n) {
+ return parseInt(n, 10);
+ }).reduce(function(a, b) {
+ return a + b;
+ }));
- $('.breakdown').fadeIn();
+ $breakdown.fadeIn(function() {
+ $breakdown.parent().css('min-height', '');
});
});
}
diff --git a/js/points-center/correction.js b/js/points-center/correction.js
index 62a059d..dbc1169 100644
--- a/js/points-center/correction.js
+++ b/js/points-center/correction.js
@@ -15,14 +15,14 @@ var resetForm = function() {
};
var validateFilledBy = function() {
- return utils.updateValidity($('.filled-by-control'), utils.slivkanNameExists(slivkans, $('#filled-by').val()));
+ return utils.updateValidity($('.filled-by-control'), utils.findSlivkan(slivkans, $('#filled-by').val()));
};
var submitPointsCorrection = function() {
var data = {
event_name: $('#event-name').val(),
name: $('#filled-by').val(),
- sender_email: slivkans[slivkans.indexOfKey('full_name', $('#filled-by').val())].nu_email,
+ sender_email: utils.findSlivkan(slivkans, $('#filled-by').val()).nu_email,
comments: $('#comments').val()
};
diff --git a/js/points-center/submission.js b/js/points-center/submission.js
index 6869dea..1e096a0 100644
--- a/js/points-center/submission.js
+++ b/js/points-center/submission.js
@@ -2,10 +2,14 @@
var moment = require('moment');
var _ = {
- cloneDeep: require('lodash/lang/cloneDeep')
+ findIndex: require('lodash/array/findIndex'),
+ forEach: require('lodash/collection/forEach'),
+ cloneDeep: require('lodash/lang/cloneDeep'),
+ template: require('lodash/string/template')
};
var utils = require('./utils');
var type, slivkans, fellows;
+var typeaheadUniqueIndex = 0;
var VALID_EVENT_NAME = false;
var appendFellowInputs = function(n) {
@@ -40,7 +44,7 @@ var saveSlivkans = function() {
};
var validateSlivkanName = function(entry, inBulk) {
- var ind, committee;
+ var foundSlivkan;
var valid = true;
var slivkanEntry = entry.find('.slivkan-entry');
var name = slivkanEntry.val();
@@ -51,14 +55,15 @@ var validateSlivkanName = function(entry, inBulk) {
// clear duplicates
$('#slivkan-entry-tab').find('.slivkan-entry').each(function() {
var $self = $(this);
+ var _name = $self.val();
- if ($self.val().length > 0) {
- if (nameArray.indexOf($self.val()) === -1) {
- nameArray.push($self.val());
+ if (_name.length > 0) {
+ if (nameArray.indexOf(_name) === -1) {
+ nameArray.push(_name);
} else {
$self.val('');
$('#duplicate-alert').slideDown();
- validateSlivkanName(self.parent(), true);
+ validateSlivkanName($self.parent(), true);
}
}
});
@@ -76,14 +81,14 @@ var validateSlivkanName = function(entry, inBulk) {
}
if (name.length > 0) {
- ind = slivkans.indexOfKey('full_name', name);
+ foundSlivkan = utils.findSlivkan(slivkans, name);
- valid &= ind !== -1;
-
- if (type === 'Committee Only') {
- committee = $('#committee').val();
+ if (!foundSlivkan) {
+ valid = false;
+ }
- valid &= committee === slivkans[ind].committee;
+ if (type === 'Committee Only' && $('#committee').val() !== foundSlivkan.committee) {
+ valid = false;
}
utils.updateValidity(entry, valid);
@@ -119,7 +124,7 @@ var validateFellowName = function(entry) {
entry.removeClass('has-warning');
if (name.length > 0) {
- valid = fellows.indexOfKey('full_name', name) !== -1;
+ valid = _.findIndex({ full_name: name }) !== -1;
utils.updateValidity(entry, valid);
} else {
entry.removeClass('has-success has-error');
@@ -153,7 +158,7 @@ var validateEventName = function() {
$.getJSON(utils.ajaxRoot + '/ajax/getRecentEvents.php', function(events) {
var last;
- if (events.length > 0 && events.indexOfKey('event_name', eventName) !== -1) {
+ if (events.length > 0 && _.findIndex(events, { event_name: eventName }) !== -1) {
if (type === 'IM') {
last = parseInt(eventEl.val().slice(-1), 10);
eventEl.val(eventEl.val().slice(0, -1) + (last + 1).toString());
@@ -226,7 +231,6 @@ var validateDescription = function() {
};
var validateFilledBy = function() {
- var valid = true;
var name = $('#filled-by').val();
$('.filled-by-control').removeClass('has-warning');
@@ -238,10 +242,7 @@ var validateFilledBy = function() {
// store value
localStorage.spc_sub_filledby = name;
- valid = slivkans.indexOfKey('full_name', name) !== -1;
- utils.updateValidity($('.filled-by-control'), valid);
-
- return valid;
+ return utils.updateValidity($('.filled-by-control'), utils.findSlivkan(slivkans, name));
};
var toggleType = function(event) {
@@ -355,7 +356,7 @@ var addBulkNames = function() {
name = nameArray[i];
// check if wildcard
- wildcardInd = slivkans.indexOfKey('wildcard', name);
+ wildcardInd = _.findIndex(slivkans, { wildcard: name });
if (wildcardInd !== -1) {
name = slivkans[wildcardInd].full_name;
}
@@ -446,14 +447,15 @@ var resetForm = function(force) {
};
var submitPointsForm = function() {
- var name, nuEmail, val, ind, obj, realSubmit;
+ var $realSubmit = $('#real-submit');
+ var resultsTemplate = _.template($('#resultsTemplate').html(), { imports: { forEach: _.forEach } });
var data = {
date: $('#date').val(),
type: type.toLowerCase().replace(' ', '_'),
committee: $('#committee').val(),
event_name: $('#event').val(),
description: $('#description').val(),
- filled_by: slivkans[slivkans.indexOfKey('full_name', $('#filled-by').val())].nu_email,
+ filled_by: utils.findSlivkan(slivkans, $('#filled-by').val()).nu_email,
comments: $('#comments').val(),
attendees: [],
committee_members: [],
@@ -461,23 +463,19 @@ var submitPointsForm = function() {
};
$('#slivkan-entry-tab').find('.slivkan-entry').each(function() {
- name = $(this).val();
- if (name.length > 0) {
- ind = slivkans.indexOfKey('full_name', name);
- nuEmail = slivkans[ind].nu_email;
-
- data.attendees.push(nuEmail);
- if (slivkans[ind].committee === data.committee &&
- data.committee !== 'Exec' &&
- type !== 'p2p' &&
- type !== 'im') {
- data.committee_members.push(nuEmail);
+ var slivkan = utils.findSlivkan(slivkans, $(this).val());
+
+ if (slivkan) {
+ data.attendees.push(slivkan.nu_email);
+
+ if (slivkan.committee === data.committee && data.committee !== 'Exec' && type !== 'p2p' && type !== 'im') {
+ data.committee_members.push(slivkan.nu_email);
}
}
});
$('.fellow-entry').each(function() {
- name = $(this).val();
+ var name = $(this).val();
if (name.length > 0) {
data.fellows.push(name);
@@ -485,38 +483,16 @@ var submitPointsForm = function() {
});
// clear receipt:
- $('#receipt').empty();
-
- for (obj in data) {
- if (data.hasOwnProperty(obj)) {
- if (obj === 'attendees' || obj === 'committee_members' || obj === 'fellows') {
- val = data[obj].join(', ');
- } else {
- val = data[obj];
- }
-
- $(' ').append(
- $(' ').text(obj)
- ).append(
- $(' ').text(val)
- ).appendTo('#receipt');
- }
- }
-
- $(' ').append($('Status '))
- .append($('Unsubmitted '))
- .appendTo('#receipt');
+ $('#receipt').html(resultsTemplate({ data: data }));
$('#submit-results').modal('show');
- realSubmit = $('#real-submit');
-
- realSubmit.off('click');
- realSubmit.on('click', function() {
- realSubmit.button('loading');
+ $realSubmit.off('click');
+ $realSubmit.on('click', function() {
+ $realSubmit.button('loading');
$.post(utils.ajaxRoot + '/ajax/submitPointsForm.php', data, function(dataIn) {
- realSubmit.button('reset');
+ $realSubmit.button('reset');
$('#results-status').parent().removeClass('has-warning');
if (dataIn.error) {
$('#results-status').text('Error in Step ' + dataIn.step)
@@ -601,57 +577,54 @@ var validatePointsForm = function() {
return valid;
};
-var handlers = {
- addClassWarning: function() {
- $(this).closest('.form-group').addClass('has-warning');
- },
- slivkanTypeahead: function() {
- var ind, committee, numInputs;
- var target = $(this);
- var slivkansTmp = _.cloneDeep(slivkans);
-
- if (localStorage.spc_sub_attendees) {
- localStorage.spc_sub_attendees.split(', ').forEach(function(el) {
- ind = slivkansTmp.indexOfKey('full_name', el);
- if (ind !== -1) {
- slivkansTmp[ind].dupe = true;
- }
- });
- }
+var slivkanTypeahead = function() {
+ var ind, committee, numInputs;
+ var target = $(this);
+ var slivkansTmp = _.cloneDeep(slivkans);
- if (type === 'Committee Only') {
- committee = $('#committee').val();
+ if (localStorage.spc_sub_attendees) {
+ localStorage.spc_sub_attendees.split(', ').forEach(function(el) {
+ ind = _.findIndex(slivkansTmp, { full_name: el });
+ if (ind !== -1) {
+ slivkansTmp[ind].dupe = true;
+ }
+ });
+ }
- slivkansTmp = slivkansTmp.filter(function(item) {
- return item.committee === committee;
- });
- }
+ if (type === 'Committee Only') {
+ committee = $('#committee').val();
- if (target.closest('.slivkan-entry-control').addClass('has-warning').is(':last-child')) {
- numInputs = $('#slivkan-entry-tab').find('.slivkan-entry').length;
- if (numInputs < 120) {
- utils.appendSlivkanInputs(1);
- }
- }
+ slivkansTmp = slivkansTmp.filter(function(item) {
+ return item.committee === committee;
+ });
+ }
- if (!target.hasClass('tt-input')) {
- target.typeahead(null, utils.typeaheadOpts('slivkans' + Math.random(), slivkansTmp)).focus();
- }
- },
- fellowTypeahead: function() {
- var numInputs;
- var target = $(this);
-
- if (target.closest('.fellow-entry-control').addClass('has-warning').is(':last-child')) {
- numInputs = $('#fellow-entry-tab').find('.fellow-entry').length;
- if (numInputs < 20) {
- appendFellowInputs(1);
- }
+ if (target.closest('.slivkan-entry-control').addClass('has-warning').is(':last-child')) {
+ numInputs = $('#slivkan-entry-tab').find('.slivkan-entry').length;
+ if (numInputs < 120) {
+ utils.appendSlivkanInputs(1);
}
- if (!target.hasClass('tt-input')) {
- target.typeahead(null, utils.typeaheadOpts('fellows', fellows)).focus();
+ }
+
+ if (!target.hasClass('tt-input')) {
+ typeaheadUniqueIndex++;
+ target.typeahead(null, utils.typeaheadOpts('slivkans' + typeaheadUniqueIndex, slivkansTmp)).focus();
+ }
+};
+
+var fellowTypeahead = function() {
+ var numInputs;
+ var target = $(this);
+
+ if (target.closest('.fellow-entry-control').addClass('has-warning').is(':last-child')) {
+ numInputs = $('#fellow-entry-tab').find('.fellow-entry').length;
+ if (numInputs < 20) {
+ appendFellowInputs(1);
}
}
+ if (!target.hasClass('tt-input')) {
+ target.typeahead(null, utils.typeaheadOpts('fellows', fellows)).focus();
+ }
};
module.exports = {
@@ -732,20 +705,20 @@ module.exports = {
$('#filled-by').typeahead(null, utils.typeaheadOpts('slivkans', slivkans));
$('#slivkan-entry-tab')
- .on('focus', '.slivkan-entry', handlers.slivkanTypeahead)
- .on('typeahead:closed', '.slivkan-entry.tt-input',
+ .on('focus', '.slivkan-entry', slivkanTypeahead)
+ .on('typeahead:close', '.slivkan-entry',
{ callback: validateSlivkanName },
utils.destroyTypeahead)
- .on('typeahead:selected', '.slivkan-entry.tt-input', function() {
+ .on('typeahead:autocomplete', '.slivkan-entry', function() {
$(this).closest('.form-group').next().find('input').focus();
});
$('#fellow-entry-tab')
- .on('focus', '.fellow-entry', handlers.fellowTypeahead)
- .on('typeahead:closed', '.fellow-entry.tt-input',
+ .on('focus', '.fellow-entry', fellowTypeahead)
+ .on('typeahead:close', '.fellow-entry',
{ callback: validateFellowName },
utils.destroyTypeahead)
- .on('typeahead:selected', '.fellow-entry.tt-input', function() {
+ .on('typeahead:autocomplete', '.fellow-entry', function() {
$(this).closest('.form-group').next().find('input').focus();
});
});
@@ -757,10 +730,10 @@ module.exports = {
}
// event handlers for inputs
- $('#filled-by') .on('focus', handlers.addClassWarning)
+ $('#filled-by') .on('focus', function() { $(this).closest('.form-group').addClass('has-warning'); })
.on('focusout', validateFilledBy);
$('#type') .on('click', toggleType);
- $('#event') .on('focus', handlers.addClassWarning)
+ $('#event') .on('focus', function() { $(this).closest('.form-group').addClass('has-warning'); })
.on('focusout', validateEventName);
$('#date') .on('change', function() {
localStorage.spc_sub_date = $(this).val();
@@ -769,15 +742,9 @@ module.exports = {
$('#im-team') .on('change', validateIMTeam);
$('#committee') .on('change', validateCommittee);
$('#description') .on('focusout', validateDescription);
- $('#comments') .on('focusout', function() {
- localStorage.spc_sub_comments = $(this).val();
- });
- $('#close-sort-alert') .on('click', function() {
- $('#sort-alert').slideUp();
- });
- $('#close-dupe-alert') .on('click', function() {
- $('#duplicate-alert').slideUp();
- });
+ $('#comments') .on('focusout', function() { localStorage.spc_sub_comments = $(this).val(); });
+ $('#close-sort-alert') .on('click', function() { $('#sort-alert').slideUp(); });
+ $('#close-dupe-alert') .on('click', function() { $('#duplicate-alert').slideUp(); });
$('#sort-entries') .on('click', sortEntries);
$('#submit') .on('click', validatePointsForm);
$('#reset') .on('click', resetForm);
diff --git a/js/points-center/utils.js b/js/points-center/utils.js
index eb503ca..c5a35ba 100644
--- a/js/points-center/utils.js
+++ b/js/points-center/utils.js
@@ -1,7 +1,7 @@
'use strict';
var _ = {
- findIndex: require('lodash/array/findIndex'),
+ find: require('lodash/collection/find'),
template: require('lodash/string/template')
};
var Bloodhound = require('typeahead.js/dist/bloodhound');
@@ -34,7 +34,8 @@ module.exports.appendSlivkanInputs = function(n) {
}
};
-module.exports.slivkanNameExists = function(slivkans, name) {
+// searches slivkans collection for either nu_email or full_name
+module.exports.findSlivkan = function(slivkans, name) {
var find = {};
if (name.length === 0) {
@@ -42,7 +43,7 @@ module.exports.slivkanNameExists = function(slivkans, name) {
} else {
find[name.indexOf(' ') !== -1 ? 'full_name' : 'nu_email'] = name;
- return _.findIndex(slivkans, find) !== -1;
+ return _.find(slivkans, find);
}
};
@@ -74,9 +75,8 @@ module.exports.typeaheadOpts = function(name, slivkans) {
displayKey: 'full_name',
source: tmp.ttAdapter(),
templates: {
- suggestion: _.template(['">',
- '<%= full_name %>
'].join(''))
+ suggestion: _.template([' class="dupe"<% } %>><%= full_name %>',
+ '
'].join(''))
}
};
};
@@ -85,13 +85,10 @@ module.exports.destroyTypeahead = function(event) {
var target = $(this);
if (target.hasClass('tt-input')) {
- // needs a delay because typeahead.js seems to not like destroying on focusout
- setTimeout(function(_target) {
- event.data.callback(target.typeahead('destroy').closest('.form-group'));
-
- if (TAB_PRESSED) {
- _target.closest('.form-group').next().find('input').focus();
- }
- }, 1, target);
+ event.data.callback(target.typeahead('destroy').closest('.form-group'));
+
+ if (TAB_PRESSED) {
+ target.closest('.form-group').next().find('input').focus();
+ }
}
};
diff --git a/package.json b/package.json
index 94b6f63..2530206 100644
--- a/package.json
+++ b/package.json
@@ -33,7 +33,8 @@
"watchify": "3.4.0"
},
"scripts": {
- "watch": "./node_modules/gulp/bin/gulp.js watch"
+ "watch": "./node_modules/gulp/bin/gulp.js watch",
+ "build": "./node_modules/gulp/bin/gulp.js build"
},
"repository": {
"type": "git",
diff --git a/spc-admin.php b/spc-admin.php
index 70a591a..f23960c 100644
--- a/spc-admin.php
+++ b/spc-admin.php
@@ -46,6 +46,12 @@ function getSlivkanName($slivkans, $nu_email)
padding: 6px 8px;
width: 35px;
}
+
+ .table td:nth-child(2) {
+ overflow-wrap: break-word;
+ word-wrap: break-word;
+ word-break: break-word;
+ }
Admin Dashboard
diff --git a/spc-breakdown.php b/spc-breakdown.php
index 6ab638a..1a7054d 100644
--- a/spc-breakdown.php
+++ b/spc-breakdown.php
@@ -85,17 +85,9 @@
-
+
-
-
-
- Other Points Breakdown
- Pts
-
-
-
-
+
@@ -123,3 +115,38 @@
+
+
+
+
diff --git a/spc-committee-headquarters.php b/spc-committee-headquarters.php
index 3d65238..778d0a0 100644
--- a/spc-committee-headquarters.php
+++ b/spc-committee-headquarters.php
@@ -22,13 +22,12 @@ function getFullName($slivkans, $nu_email)
}
?>
-
@@ -47,37 +46,38 @@ function getFullName($slivkans, $nu_email)
Committee Headquarters
-
-
-
Click to edit values.
+
+
+
+
Click to edit values.
+
+
+
+
Colors:
+
+
+ Attendee
+ Point Taker
+ Other Points
+ None
+
+
+
+
+
-
-
Colors:
-
-
- Attendee
- Point Taker
- Other Points
- None
-
-
-
-
-
-
-
+
-
+ Name
-
diff --git a/spc-submission.php b/spc-submission.php
index 54d02ba..397924b 100644
--- a/spc-submission.php
+++ b/spc-submission.php
@@ -203,3 +203,17 @@
+
+