From 1e6137370e7f6b1b46d825cfcf575a65d1443233 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Sat, 15 Dec 2018 18:12:49 +0100 Subject: [PATCH] Differentiating between user search modes. Small fixes. --- static/mealplanner_script.js | 44 +++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/static/mealplanner_script.js b/static/mealplanner_script.js index 9005f29..d2fb95d 100644 --- a/static/mealplanner_script.js +++ b/static/mealplanner_script.js @@ -5,7 +5,7 @@ $( function() { $(".user-result-container").position({ my: "left top", at: "left bottom", - of: $('#search-user'), // or $("#otherdiv") + of: $('#search-user'), collision: "fit" }); $('.user-result-container').hide(); @@ -34,20 +34,23 @@ function plan_meal() { } function add_user() { + if (eaters.includes($('#search-user').val())) + return; $.ajax({ - url: "/searchusers?q=" + $('#search-user').val() + url: "/searchusers?q=" + $('#search-user').val() + "&s=0" }).done(function(results) { if (results == '[]') { alert('Invalid username'); return; } - names = results.substring(1, results.length-1).split(', '); - if (names.length > 1) { - alert('Please choose one.'); + var meal_date = $('#datepicker').datepicker('getDate'); + if (meal_date == null || $('#spinner-hour').val() == '' || $('#spinner-minute').val() == '') { + alert('Please select a date and a time.'); return; } - eaters.push(names[0].substring(1, names[0].length)); - var meal_date = $('#datepicker').datepicker('getDate'); + names = results.substring(1, results.length - 1).split(', '); + new_eater = names[0].substring(1, names[0].length - 1); + eaters.push(new_eater); var month = (meal_date.getMonth() + 1).toString(); if (month.length == 1) month = '0' + month; @@ -69,7 +72,26 @@ function add_user() { $('#est-cook').attr('src', 'static/' + estkuk + '.png') $('#est-cook').attr('title', estkuk) }); + e = '
\ +
\ + \ + ' + new_eater + '\ +
\ +
\ +
'; + $('#add-user').before(e); + $('.small-round-button').show(); + }); +} + +function remove_user(name) { + eaters = eaters.filter(function(value, index, arr){ + return value != name; }); + $('#for-user-' + name).remove(); + if ($('#eaters-list > div').length == 2) { + $('.small-round-button').hide(); + } } function fill_box(name) { @@ -82,7 +104,7 @@ function user_search() { if ($('#search-user').val() == '') return; $.ajax({ - url: "/searchusers?q=" + $('#search-user').val() + url: "/searchusers?q=" + $('#search-user').val() + "&s=1" }).done(function(results) { // Load results if (results == '[]') @@ -97,6 +119,12 @@ function user_search() { ' $('.user-result-container').append($(e)); }); + // $(".user-result-container").position({ + // my: "left top", + // at: "left bottom", + // of: $('#search-user'), + // collision: "fit" + // }); $('.user-result-container').show(); }); } \ No newline at end of file