lib/pairing_matrix/server/public/index.js in pairing_matrix-2.0 vs lib/pairing_matrix/server/public/index.js in pairing_matrix-2.1

- old
+ new

@@ -1,25 +1,26 @@ $(document).ready(function () { var playground = new PlayGround(".area"); var pairingData = []; - var renderMatrix = function (days) { - $('#no_of_days').text(days); + var renderMatrix = function () { + var days = $('#days').val(); hideMatrix(); showLoader(); - $.get('/data/' + days).done(function (data) { + $.get('/data/' + days + "?cache_enabled=" + isCachingEnabled()).done(function (data) { pairingData = JSON.parse(data); playground.load(pairingData); hideLoader(); showMatrix(); }).fail(function () { - alert('error occurred!'); + alert('Error fetching data from server!'); hideLoader(); showMatrix(); }); }; var hideMatrix = function () { + $(".authors_container").hide(); $('.viz_container').hide(); }; var showMatrix = function () { $('.viz_container').show(); @@ -33,11 +34,11 @@ if (a > b) return 1; if (b > a) return -1; return 0; }); _.each(sortedNames, function (name) { - $('.authors').append("<input type='checkbox' checked='true' name='" + name + "'><label for='" + name + "'>" + name + "</label></br>"); + $('.authors').append("<input type='checkbox' class='author' checked='true' name='" + name + "'><label for='" + name + "'>" + name + "</label></br>"); }); $(".authors_container").show(); }; @@ -47,25 +48,55 @@ var showLoader = function () { $('.loaderContainer').show(); }; + var enableCaching = function () { + $('.cache-toggle').bootstrapToggle('on'); + }; + + var isCachingEnabled = function () { + return $('.cache-toggle').prop('checked'); + }; + + var updateDays = function(days) { + var $days = $('#days'); + $days.val(days); + }; + $('#visualize').on('click', function () { - $(".authors_container").hide(); - renderMatrix($('#days').val()) + renderMatrix() }); - renderMatrix($('#days').val()); + $('#a_week').on('click', function () { + updateDays('7'); + renderMatrix() + }); + $('#two_weeks').on('click', function () { + updateDays('14'); + renderMatrix() + }); + + $('#a_month').on('click', function () { + updateDays('30'); + renderMatrix() + }); + + $('#two_months').on('click', function () { + updateDays('60'); + renderMatrix() + }); + $('#reset').click(function () { - _.each($('input[type="checkbox"]'), function (e) { + _.each($('.author'), function (e) { e.checked = false; }); }); $('#render').click(function (e) { - var checked = _.filter($('input[type="checkbox"]'), function (e) { + var checked = _.filter($('.author'), function (e) { return e.checked }); var names = _.map(checked, function (checkbox) { return checkbox.name }); @@ -74,6 +105,9 @@ return _.include(names, data[0]) || _.include(names, data[1]) }); playground.load(filteredPairingData); }); + + enableCaching(); + renderMatrix(); });