diff --git a/hardware/static/js/hw.js b/hardware/static/js/hw.js index 4eccf90..cb9236f 100644 --- a/hardware/static/js/hw.js +++ b/hardware/static/js/hw.js @@ -48,6 +48,7 @@ let hw = (()=>{ let msg = msg_in || "" let title = title_in || "HackathonAssistant" let closeIn = time || 10000 + var icon = icon || window.location.origin + "/static/favicon.png" let notification = new Notification(title, { body: msg, icon: icon diff --git a/hardware/static/js/hw_list.js b/hardware/static/js/hw_list.js index 8494ef6..9f5a33b 100644 --- a/hardware/static/js/hw_list.js +++ b/hardware/static/js/hw_list.js @@ -26,7 +26,7 @@ let hw_list = ((hw)=>{ element.innerHTML=count } function notifyAvailableItem(item){ - hw.notify("A "+item.name+" has become available! Click the notification to request.", + hw.notify("A "+item.name+" has become available! Click the notification to request (May not work in your browser).", "HackathonAssistant", "", ()=>{ hw.ajax_req({ 'req_item':true, @@ -71,8 +71,6 @@ let hw_list = ((hw)=>{ checkItems.push(itemId) if(!timer){ timer = setInterval(()=>{ - if(!checkItems) - timer = false hw.ajax_req({ 'check_availability': true, 'item_ids': checkItems @@ -80,43 +78,60 @@ let hw_list = ((hw)=>{ for(let item of data.available_items){ obj.stopPool(item.id) notifyAvailableItem(item) + var btn =$("[data-item-id="+item.id+"]")[0] + btn.dataset.action = 'request' + btn.innerHTML = "REQUEST" + btn.classList.remove('active') + } + if(!checkItems.length) + { + clearInterval(timer) + timer = false } }) }, POOLING_TIME) } } obj.initListeners = ()=>{ - $("[data-action='lmk']").on("click", (ev)=>{ - if($(ev.target).hasClass('active')){ - $(ev.target).removeClass('active') - obj.stopPool(ev.target.dataset.itemId) - return + $("[data-action]").on("click", (ev)=>{ + if(ev.currentTarget.dataset.action === 'lmk') + { + if($(ev.target).hasClass('active')) + { + $(ev.target).removeClass('active') + obj.stopPool(ev.target.dataset.itemId) + return + } + if(!hw.canNotify) + { + hw.initNotifications((permission)=>{ + if(permission){ + hw.notify("Notifications enabled!") + $(ev.target).addClass('active') + obj.poolAvailability(ev.target.dataset.itemId) + } + }) + } + else + { + $(ev.target).addClass('active') + obj.poolAvailability(ev.target.dataset.itemId) + } } - if(!hw.canNotify){ - hw.initNotifications((permission)=>{ - if(permission){ - hw.notify("Notifications enabled!") - $(ev.target).addClass('active') - obj.poolAvailability(ev.target.dataset.itemId) + else + { + hw.ajax_req({ + 'req_item':true, + 'item_id': ev.currentTarget.dataset.itemId, + }, (data)=>{ + if(data.ok){ + ev.currentTarget.dataset.targetTime = "00:"+data.minutes+":00" + obj.setTimer(ev.currentTarget) } - }) - } else { - $(ev.target).addClass('active') - obj.poolAvailability(ev.target.dataset.itemId) + }) } }) - $("[data-action='request']").on("click", (ev)=>{ - hw.ajax_req({ - 'req_item':true, - 'item_id': ev.currentTarget.dataset.itemId, - }, (data)=>{ - if(data.ok){ - ev.currentTarget.dataset.targetTime = "00:"+data.minutes+":00" - obj.setTimer(ev.currentTarget) - } - }) - }) $(".hw-toggle").on("click", (ev)=>{ $(ev.currentTarget).toggleClass("open") $(ev.currentTarget).siblings(".hw-toggle-actor").toggleClass("open") diff --git a/hardware/views.py b/hardware/views.py index 713d3d9..b5bef1b 100644 --- a/hardware/views.py +++ b/hardware/views.py @@ -52,6 +52,14 @@ class HardwareBorrowingsView(TabsViewMixin, SingleTableMixin, FilterView): table_pagination = {'per_page': 50} filterset_class = BorrowingFilter + def get_context_data(self, **kwargs): + context = super(HardwareBorrowingsView, self).get_context_data(**kwargs) + if not self.request.user.is_hardware_admin: + context['filter'] = False + context['table'].exclude = ('id', 'user', 'lending_by', 'return_by') + + return context + def get_current_tabs(self): return hardware_tabs(self.request.user)