diff --git a/apps/expobanner/views.py b/apps/expobanner/views.py index 624e9a74..598bf436 100644 --- a/apps/expobanner/views.py +++ b/apps/expobanner/views.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import json import re +from datetime import date from django.http import HttpResponse from django.shortcuts import redirect, get_object_or_404, render @@ -100,8 +101,8 @@ def get_top(request): 'catalog': catalog, 'month': request.GET.get('month')} - tops = Top.cached.all() - events = get_top_events(tops, params, request) + tops = Top.cached.filter(fr__lte=date.today(), to__gte=date.today()).order_by('?') + events = get_top_events(tops, params, request)[:3] ctx = {'objects': events} if not events: diff --git a/static/client/js/rejs/tops.js b/static/client/js/rejs/tops.js index 565cc5cd..31b97704 100644 --- a/static/client/js/rejs/tops.js +++ b/static/client/js/rejs/tops.js @@ -79,9 +79,9 @@ if (parent) { parent.innerHTML = text; - $(document).ready(function () { - removeDublicates(); - }); + // $(document).ready(function () { + // removeDublicates(); + // }); } }; diff --git a/static/client/js/scripts.js b/static/client/js/scripts.js index 31656c5a..174c13b3 100644 --- a/static/client/js/scripts.js +++ b/static/client/js/scripts.js @@ -88,6 +88,7 @@ function build_filters_period () { function submit_search_form () { var $form = $('.filter_form'), params = $form.serialize(), + paramsForTop = $form.serializeArray(), filters_url = $form.data('formurl'), results_url = $form.data('resultsurl'), $loader = $('#wait-ajax'); @@ -101,7 +102,7 @@ function submit_search_form () { $.getJSON(results_url, params, function(data) { if (data.success) { - $('.page-body').html(data.results); + $('.page-body').html(data.results).prepend('
'); build_sidebar(); $loader.hide(); } @@ -115,6 +116,105 @@ function submit_search_form () { build_filters_period(); } }) + + var API_URL_ROOT = "/expo-b/get-tops/"; + var PARENT_ID = "expo_top_events"; + + var getUrl = function () { + var search = []; + + var parts = /^\/([^\/]+)(?:\/|$)/i.exec(location.pathname); + if (parts) { + search.push("catalog=" + encodeURIComponent(parts[1])); + } else { + search.push("catalog="); + } + + var data = window.sendData, theme = []; + $.each(paramsForTop, function(i,val){ + if(val.name === 'theme') { + theme.push(parseInt(val.value)); + } + }); + data.theme = theme; + console.log('NEW:',data); + if (data instanceof Object) { + for (var key in data) { + if (data.hasOwnProperty(key)) { + var value = data[key]; + + if (value instanceof Array) { + for (var i = 0, l = value.length; i < l; i++) { + search.push(encodeURIComponent(key) + "=" + encodeURIComponent(value[i])); + } + } else { + search.push(encodeURIComponent(key) + "=" + encodeURIComponent(value)); + } + } + } + } + + return API_URL_ROOT + "?" + search.join("&"); + }; + + var runCallback = function (callback, arg) { + try { + callback(arg); + } catch (error) { + // do nothing + } + // console.info('callback Done'); + }; + + var getTops = function (url, callback) { + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, true); + + xhr.onreadystatechange = function (event) { + if (event.target.readyState === 4) { + if (event.target.status === 200) { + if (document.readyState === "loading" && !window.marker_DOMtopjsElementInserted) { + // console.info('setting DOMContentLoaded event listener'); + // console.info('setting DOMtopjsElementInserted event listener'); + // document.addEventListener("DOMContentLoaded", function() { + + document.addEventListener("DOMtopjsElementInserted", function() { + runCallback(callback, event.target.responseText); + }); + } else { + runCallback(callback, event.target.responseText); + } + } + } + }; + + xhr.send(); + }; + + var removeDublicates = function () { + $('div#' + PARENT_ID + ' ul li.cl-item').each(function(index, el) { + $('div.page-body ul.cat-list li.cl-item[data-slug=\'' + $(el).data('slug') + '\']').not(el).remove(); + }); + }; + + var insertTops = function (text) { + var parent = document.getElementById(PARENT_ID); + + if (parent) { + parent.innerHTML = text; + // $(document).ready(function () { + // removeDublicates(); + // }); + } + }; + + var main = function () { + getTops(getUrl(), insertTops); + }; + // main(); + // window.addEventListener("load", main); + // document.addEventListener("DOMContentLoaded", main); + main(); } $(document).ready(function () { diff --git a/static/client/js/vendor.js b/static/client/js/vendor.js index dbc723ff..3f29bca6 100644 --- a/static/client/js/vendor.js +++ b/static/client/js/vendor.js @@ -4947,6 +4947,7 @@ function build_filters_period () { function submit_search_form () { var $form = $('.filter_form'), params = $form.serialize(), + paramsForTop = $form.serializeArray(), filters_url = $form.data('formurl'), results_url = $form.data('resultsurl'), $loader = $('#wait-ajax'); @@ -4960,7 +4961,7 @@ function submit_search_form () { $.getJSON(results_url, params, function(data) { if (data.success) { - $('.page-body').html(data.results); + $('.page-body').html(data.results).prepend(''); build_sidebar(); $loader.hide(); } @@ -4974,6 +4975,105 @@ function submit_search_form () { build_filters_period(); } }) + + var API_URL_ROOT = "/expo-b/get-tops/"; + var PARENT_ID = "expo_top_events"; + + var getUrl = function () { + var search = []; + + var parts = /^\/([^\/]+)(?:\/|$)/i.exec(location.pathname); + if (parts) { + search.push("catalog=" + encodeURIComponent(parts[1])); + } else { + search.push("catalog="); + } + + var data = window.sendData, theme = []; + $.each(paramsForTop, function(i,val){ + if(val.name === 'theme') { + theme.push(parseInt(val.value)); + } + }); + data.theme = theme; + console.log('NEW:',data); + if (data instanceof Object) { + for (var key in data) { + if (data.hasOwnProperty(key)) { + var value = data[key]; + + if (value instanceof Array) { + for (var i = 0, l = value.length; i < l; i++) { + search.push(encodeURIComponent(key) + "=" + encodeURIComponent(value[i])); + } + } else { + search.push(encodeURIComponent(key) + "=" + encodeURIComponent(value)); + } + } + } + } + + return API_URL_ROOT + "?" + search.join("&"); + }; + + var runCallback = function (callback, arg) { + try { + callback(arg); + } catch (error) { + // do nothing + } + // console.info('callback Done'); + }; + + var getTops = function (url, callback) { + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, true); + + xhr.onreadystatechange = function (event) { + if (event.target.readyState === 4) { + if (event.target.status === 200) { + if (document.readyState === "loading" && !window.marker_DOMtopjsElementInserted) { + // console.info('setting DOMContentLoaded event listener'); + // console.info('setting DOMtopjsElementInserted event listener'); + // document.addEventListener("DOMContentLoaded", function() { + + document.addEventListener("DOMtopjsElementInserted", function() { + runCallback(callback, event.target.responseText); + }); + } else { + runCallback(callback, event.target.responseText); + } + } + } + }; + + xhr.send(); + }; + + var removeDublicates = function () { + $('div#' + PARENT_ID + ' ul li.cl-item').each(function(index, el) { + $('div.page-body ul.cat-list li.cl-item[data-slug=\'' + $(el).data('slug') + '\']').not(el).remove(); + }); + }; + + var insertTops = function (text) { + var parent = document.getElementById(PARENT_ID); + + if (parent) { + parent.innerHTML = text; + // $(document).ready(function () { + // removeDublicates(); + // }); + } + }; + + var main = function () { + getTops(getUrl(), insertTops); + }; + // main(); + // window.addEventListener("load", main); + // document.addEventListener("DOMContentLoaded", main); + main(); } $(document).ready(function () { diff --git a/static/client/js_min/vendor.min.js b/static/client/js_min/vendor.min.js index d07c29a3..2a09dc12 100644 --- a/static/client/js_min/vendor.min.js +++ b/static/client/js_min/vendor.min.js @@ -1,8 +1,8 @@ -function mapInit(){var e=document.getElementById("map-canvas"),t=e.getAttribute("data-coords"),i=t.indexOf(","),n=parseFloat(t.substring(0,i)),a=parseFloat(t.substring(i+1,t.length)),o=new google.maps.LatLng(n,a),s={zoom:15,center:o,scrollwheel:!1};map=new google.maps.Map(e,s);new google.maps.Marker({position:o,map:map})}function addError(e,t){var i=$("#reg_form "+e),n=$("
'),$.each(window.sendData,function(e,i){var n=e;if(i.length){if("array"==$.type(i))for(var a=0;aThe requested content cannot be loaded.
Please try again later.