# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2015, Kovid Goyal from ajax import ajax from elementmaker import E from session import UserSessionData, SessionData from book_list.boss import Boss from book_list.globals import set_boss, set_session_data def on_library_loaded(end_type, xhr, ev): p = document.getElementById('page_load_progress') p.parentNode.removeChild(p) if end_type == 'load': interface_data = JSON.parse(xhr.responseText) sd = UserSessionData(interface_data['username'], interface_data['user_session_data']) set_session_data(sd) boss = Boss(interface_data) set_boss(boss) else: document.body.appendChild(E.p(style='color:red', xhr.error_string)) def on_library_load_progress(loaded, total): p = document.querySelector('#page_load_progress > progress') p.max = total p.value = loaded def load_book_list(): temp = SessionData() # So that settings for anonymous users are preserved query = {'library_id':temp.get('library_id'), 'sort':temp.get('sort')} ajax('interface-data/init', on_library_loaded, on_library_load_progress, query=query).send() def on_load(): if window.calibre_entry_point == 'book list': load_book_list() # We wait for all page elements to load, since this is a single page app # with a largely empty starting document, we can use this to preload any resources # we know are going to be needed immediately. window.addEventListener('load', on_load)