diff --git a/src/interface/static/js/pyshelf_ux.js b/src/interface/static/js/pyshelf_ux.js index f23e013..8d68491 100755 --- a/src/interface/static/js/pyshelf_ux.js +++ b/src/interface/static/js/pyshelf_ux.js @@ -18,7 +18,7 @@ $(document).ready(function(){ var max_height = win_height - (hdr_height + ftr_height) - (scr_height - win_height); // Set our available height var u_string = "Username"; var p_string = "Password"; - var s_string = "search by Title, Author, Tags, or Collections" + var s_string = "search by Title, Author, Tags, or Collections"; customlog([cmp_height]); $(".search_submit").click(function(){ var query = $('.nav_search').val(); @@ -35,8 +35,8 @@ $(document).ready(function(){ }); $('.nav_link').on('mouseover', function (e){ var popover_str = $(this).attr('alt'); - x = $(this).offset().left - y = $(this).offset().top + x = $(this).offset().left; + y = $(this).offset().to; $('.popover').html(popover_str); $('.popover').css('left', x+nav_width); $('.popover').css('top', y); @@ -44,15 +44,15 @@ $(document).ready(function(){ }); $('.nav_link').on('mouseout', function (e){ var popover_str = $(this).attr('alt'); - x = $(this).offset().left - y = $(this).offset().top + x = $(this).offset().left; + y = $(this).offset().top; $('.popover').html(popover_str); $('.popover').css('left', x); $('.popover').css('top', y); $('.popover').css('display','none'); }); $('#btn_collections').on('click', function (e){ - $('.hidden.vert-nav.collections').toggle() + $('.hidden.vert-nav.collections').toggle(); }); $('.input_box').on('click', function(){ $(this).attr("value",""); @@ -78,16 +78,16 @@ $(document).ready(function(){ var optionSelected = $(this).find("option:selected"); var valueSelected = optionSelected.val(); var textSelected = optionSelected.text(); - window.location.href="/"+valueSelected + window.location.href="/"+valueSelected; }); $('#btn-home').on("click", function(){ _location = $(this).attr('data-location'); window.location.href=_location; }); $('#flip_sort').on("click", function(){ - window.location.href="/flip_sort/"+$("#_order").val() + window.location.href="/flip_sort/"+$("#_order").val(); }); - $('#search_string').html(" "+$('#_search').val().substr(0,15)+"") + $('#search_string').html(" "+$('#_search').val().substr(0,15)+""); $('#pop_over_0').dialog({ autoOpen: false }); resize_search(); @@ -97,10 +97,10 @@ $(document).ready(function(){ window.location.href = '/show_collection/'+$(this).attr('data'); }); $('#btn_login').on('click', function() { - var isopen = $('#pop_over_0').dialog("isOpen") + var isopen = $('#pop_over_0').dialog("isOpen"); if (isopen) { $('#pop_over_0').dialog("close"); - return + return; } customlog(['Login Clicked']); $.ajax({ @@ -138,10 +138,10 @@ $(document).ready(function(){ window.location.href = '/logout'; }); $('#coll_button').on('click', function(){ - var isopen = $('#pop_over_0').dialog("isOpen") + var isopen = $('#pop_over_0').dialog("isOpen"); if (isopen){ $('#pop_over_0').dialog("close"); - return + return; } customlog(['Collections Clicked']); $.ajax({ @@ -171,7 +171,43 @@ $(document).ready(function(){ error: function(response){ customlog(["Failure", response]); } - }) + }); + }); + $('.info-button').on('click', function(){ + var isopen = $('#pop_over_0').dialog("isOpen"); + if (isopen){ + $('#pop_over_0').dialog("close"); + return; + } + customlog(['Book Details Clicked', $(this).attr('data')]); + $.ajax({ + type: "GET", url: "/live", data: {hook: 'details', pk:$(this).attr('data')}, + success: function(response){ + // Set the dialog title + $('#pop_over_0').dialog({ + title: "Collections", + maxHeight: (win_height-100), + minWidth: $("#horiz_nav_main").width(), + hide: { effect: "blind", duration: 1000 }, + show: { effect: "blind", duration: 1000 }, + position: { my: "top", at: "bottom", of: $("#horiz_nav_main") + } + }); + // clear and create a new container + $('#pop_over_0').html('
'); + // Populate the container from response.data + $.each(response.data, function(index, value){ + $('#collections').append("
"+value+"
"); + }); + // Close the container + $('#pop_over').append('
'); + // Now open this dialog + $('#pop_over_0').dialog("open"); + }, + error: function(response){ + customlog(["Failure", response]); + } + }); }); }); function resize_search(win_width){ diff --git a/src/interface/templates/index.html b/src/interface/templates/index.html index 60bafe3..731e7ab 100755 --- a/src/interface/templates/index.html +++ b/src/interface/templates/index.html @@ -120,8 +120,8 @@ - - + + diff --git a/src/interface/views.py b/src/interface/views.py index 449bc58..e15276a 100755 --- a/src/interface/views.py +++ b/src/interface/views.py @@ -1,22 +1,22 @@ +import json import os from base64 import b64decode, b64encode from pathlib import Path from backend.lib.config import Config +from django.conf import settings +from django.contrib import auth +from django.contrib.auth import authenticate, get_user_model, login, logout +from django.contrib.auth.models import User from django.db import models from django.http import JsonResponse -from django.shortcuts import HttpResponse, render, redirect # render_to_response -from django.utils.text import slugify -from django.contrib.auth import login, authenticate, logout -from django.contrib import auth -from django.contrib.auth.models import User -from django.conf import settings -from django.contrib.auth import get_user_model -from django.utils.datastructures import MultiValueDictKeyError -import json -from .forms import SignUpForm, UserLoginForm -from .models import Books, Collections, Navigation, Favorites, User +from django.shortcuts import HttpResponse, redirect, render # render_to_response from django.template.loader import render_to_string +from django.utils.datastructures import MultiValueDictKeyError +from django.utils.text import slugify + +from .forms import SignUpForm, UserLoginForm +from .models import Books, Collections, Favorites, Navigation, User config = Config(Path("../")) @@ -380,6 +380,12 @@ def collections_list(): def live(request, **kwargs): + """ + Respond to live requests. Primarily used as a response object for Ajax calls + :param GET['hook']: collection_listing, book_details, register + :param kwargs['pk']: Primary key of requested object + :return: JsonResponse Object, status response code + """ err_txt = {"err": "There is no responder for your request"} try: hook = request.GET['hook'] except MultiValueDictKeyError as e: return JsonResponse(err_txt, status=404) @@ -445,10 +451,10 @@ def payload(request, query, _set, _limit, _order, **kwargs): _r, _r_len = \ _results.order_by(_order)[_set_min:_set_max],\ _results.count() - else: + else: # No new query was passed try: query = request.session['cached_query'] # Is there a cached query? - if query == None: raise KeyError + if query == None: raise KeyError # No cached query exists jump to KeyError if request.session['ascending']: _results = Books().generic_search(query) else: _results = Books().generic_search(query).reverse() @@ -464,7 +470,7 @@ def payload(request, query, _set, _limit, _order, **kwargs): _bookstats = Books.objects.all().count() if (_r_len): _btotal = str(_r_len) else: _btotal = str(_bookstats) - + # Format the payload and return it to the view return { "Books": _r, "Set": str(_set), @@ -479,4 +485,3 @@ def payload(request, query, _set, _limit, _order, **kwargs): "SearchLen": _r_len, "Order": _order, } -