From 4cf03981b72409eb8c3bf9370dd42989fa0be0aa Mon Sep 17 00:00:00 2001 From: re0ne Date: Wed, 2 Sep 2015 14:31:31 +0300 Subject: [PATCH 1/4] Minor changes in file structure --- templates/client/blank.html | 2 +- templates/client/includes/banners/tops.html | 12 ++---------- templates/client/popups/cemat_modal.html | 2 +- .../client/static_client/js/{ => rejs}/banners.js | 13 +++++++++---- templates/client/static_client/js/rejs/tops.js | 8 ++++++++ 5 files changed, 21 insertions(+), 16 deletions(-) rename templates/client/static_client/js/{ => rejs}/banners.js (89%) create mode 100644 templates/client/static_client/js/rejs/tops.js diff --git a/templates/client/blank.html b/templates/client/blank.html index 00219448..1be9b75a 100644 --- a/templates/client/blank.html +++ b/templates/client/blank.html @@ -87,7 +87,7 @@ This template include basic anf main styles and js files, "tag": "{{ tag }}" }; - + diff --git a/templates/client/includes/banners/tops.html b/templates/client/includes/banners/tops.html index 142e63a4..d421696d 100644 --- a/templates/client/includes/banners/tops.html +++ b/templates/client/includes/banners/tops.html @@ -1,13 +1,5 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/templates/client/popups/cemat_modal.html b/templates/client/popups/cemat_modal.html index fb497d72..d6c437d9 100644 --- a/templates/client/popups/cemat_modal.html +++ b/templates/client/popups/cemat_modal.html @@ -16,7 +16,7 @@ - + diff --git a/templates/client/static_client/js/banners.js b/templates/client/static_client/js/rejs/banners.js similarity index 89% rename from templates/client/static_client/js/banners.js rename to templates/client/static_client/js/rejs/banners.js index 1f6126ca..df86bbb0 100644 --- a/templates/client/static_client/js/banners.js +++ b/templates/client/static_client/js/rejs/banners.js @@ -4,10 +4,17 @@ var API_URL_ROOT = "/expo-b/get-banners/"; var getUrl = function () { + var catalog = ""; + + var parts = /^\/([^\/]+)(?:\/|$)/i.exec(location.pathname); + if (parts) { + catalog = parts[1]; + } + var data = window.sendData; if (data instanceof Object) { - var search = []; + var search = ["catalog=" + catalog]; for (var key in data) { if (data.hasOwnProperty(key)) { @@ -23,9 +30,7 @@ } } - if (search.length) { - return API_URL_ROOT + "?" + search.join("&"); - } + return API_URL_ROOT + "?" + search.join("&"); } return API_URL_ROOT; diff --git a/templates/client/static_client/js/rejs/tops.js b/templates/client/static_client/js/rejs/tops.js new file mode 100644 index 00000000..b3fbd8a5 --- /dev/null +++ b/templates/client/static_client/js/rejs/tops.js @@ -0,0 +1,8 @@ +(function () { + "use strict"; + + var API_URL_ROOT = "/expo-b/get-tops/"; + var PARENT_ID = "expo_top_events"; + + console.log("TOPS"); +})(); From 7a757d9cb83cb5b1c7f84e1e4e8976dc5dad7c46 Mon Sep 17 00:00:00 2001 From: re0ne Date: Wed, 2 Sep 2015 15:26:26 +0300 Subject: [PATCH 2/4] Added tops getting --- templates/client/includes/banners/tops.html | 2 + .../client/static_client/js/rejs/tops.js | 64 ++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/templates/client/includes/banners/tops.html b/templates/client/includes/banners/tops.html index d421696d..f1678855 100644 --- a/templates/client/includes/banners/tops.html +++ b/templates/client/includes/banners/tops.html @@ -1,3 +1,5 @@ +{% load static %} +
diff --git a/templates/client/static_client/js/rejs/tops.js b/templates/client/static_client/js/rejs/tops.js index b3fbd8a5..5f99943b 100644 --- a/templates/client/static_client/js/rejs/tops.js +++ b/templates/client/static_client/js/rejs/tops.js @@ -4,5 +4,67 @@ var API_URL_ROOT = "/expo-b/get-tops/"; var PARENT_ID = "expo_top_events"; - console.log("TOPS"); + var getUrl = function () { + var catalog = ""; + + var parts = /^\/([^\/]+)(?:\/|$)/i.exec(location.pathname); + if (parts) { + catalog = parts[1]; + } + + var data = window.sendData; + + if (data instanceof Object) { + var search = ["catalog=" + catalog]; + + 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("&"); + } + + return API_URL_ROOT; + }; + + 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) { + try { + callback(JSON.parse(event.target.responseText)); + } catch (error) { + // do nothing + } + } + } + }; + + xhr.send(); + }; + + var insertTops = function (data) { + console.log(data); + }; + + var main = function () { + console.log("### TOPS ###"); + + getTops(getUrl(), insertTops); + }; + + window.addEventListener("load", main); })(); From 4c179cb3e5262e642de17914432e5e10b4e42b2f Mon Sep 17 00:00:00 2001 From: re0ne Date: Wed, 2 Sep 2015 15:59:25 +0300 Subject: [PATCH 3/4] Top events adding --- templates/client/static_client/js/rejs/tops.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/templates/client/static_client/js/rejs/tops.js b/templates/client/static_client/js/rejs/tops.js index 5f99943b..db87aa6a 100644 --- a/templates/client/static_client/js/rejs/tops.js +++ b/templates/client/static_client/js/rejs/tops.js @@ -45,7 +45,7 @@ if (event.target.readyState === 4) { if (event.target.status === 200) { try { - callback(JSON.parse(event.target.responseText)); + callback(event.target.responseText); } catch (error) { // do nothing } @@ -56,13 +56,15 @@ xhr.send(); }; - var insertTops = function (data) { - console.log(data); + var insertTops = function (text) { + var parent = document.getElementById(PARENT_ID); + + if (parent) { + parent.innerHTML = text; + } }; var main = function () { - console.log("### TOPS ###"); - getTops(getUrl(), insertTops); }; From bc267464c46d547150114a870882afed1b11de8d Mon Sep 17 00:00:00 2001 From: Kotiuk Nazarii Date: Wed, 2 Sep 2015 17:31:34 +0300 Subject: [PATCH 4/4] Popups hardcoded --- expobanner/models.py | 4 +++- expobanner/views.py | 4 ++-- proj/settings.py | 2 ++ templates/client/includes/banners/popup.html | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 templates/client/includes/banners/popup.html diff --git a/expobanner/models.py b/expobanner/models.py index b49c914f..12e1d066 100644 --- a/expobanner/models.py +++ b/expobanner/models.py @@ -95,8 +95,10 @@ class Banner(models.Model, StatMixin): html = models.BooleanField(verbose_name=_('HTML?'), default=False) flash = models.BooleanField(verbose_name=_('Flash?'), default=False) - js = models.BooleanField(verbose_name=_('Javascript?'), default=False) + popup = models.BooleanField(verbose_name=_('Popup?'), default=False) paid = models.BooleanField(verbose_name=_('Is Paid event link?'), default=False) + # for detecting popups + cookie = models.CharField(max_length=30, blank=True, null=True, default=settings.DEFAULT_POPUP_COOKIE) public = models.BooleanField(verbose_name=u'Активный', default=True) created_at = models.DateTimeField(verbose_name=_('Created At'), auto_now_add=True) diff --git a/expobanner/views.py b/expobanner/views.py index 96540cdc..99135b27 100644 --- a/expobanner/views.py +++ b/expobanner/views.py @@ -46,7 +46,7 @@ def get_banners(request): for group, banners in group_banners.iteritems(): banner = get_banner_by_params(banners, good_urls, params) if banner: - if banner.js or banner.html: + if banner.html: text = banner.text img = '' alt = '' @@ -61,7 +61,7 @@ def get_banners(request): 'is_html': banner.html, 'is_flash': banner.flash, 'is_img': is_img, - 'is_js': banner.js, + 'is_popup': banner.popup, 'img': img, 'alt': alt, 'text': text diff --git a/proj/settings.py b/proj/settings.py index c2828869..14caba29 100644 --- a/proj/settings.py +++ b/proj/settings.py @@ -449,6 +449,8 @@ CLIENT_DATE_FORMAT = ["%d.%m.%Y"] # cache pages in random seconds. random in this range CACHE_RANGE = [60, 120] +DEFAULT_POPUP_COOKIE = 'expo_b_default_popup' + try: from local import * except ImportError, e: diff --git a/templates/client/includes/banners/popup.html b/templates/client/includes/banners/popup.html new file mode 100644 index 00000000..51d5d4ad --- /dev/null +++ b/templates/client/includes/banners/popup.html @@ -0,0 +1,2 @@ + \ No newline at end of file