From 791ff06b8b4b2c62ec7e494698280478f9c6da25 Mon Sep 17 00:00:00 2001 From: okhin Date: Mon, 13 Feb 2017 13:49:23 +0100 Subject: [PATCH] Better management of json data --- static/css/piphone.css | 4 ++++ templates/contactslist.html | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/static/css/piphone.css b/static/css/piphone.css index dc08b04..f73ddcf 100644 --- a/static/css/piphone.css +++ b/static/css/piphone.css @@ -31,3 +31,7 @@ main { height: 48px; width: 48px; } + +.json-data { + display: none; +} diff --git a/templates/contactslist.html b/templates/contactslist.html index 3a16388..4f43821 100644 --- a/templates/contactslist.html +++ b/templates/contactslist.html @@ -19,7 +19,10 @@ -
+
+ {{ json_encode(@contacts) }} +
+
@@ -37,7 +40,6 @@ $(document).ready(function() { $('select.filter').change(function() { var filter_group = $(this).val(); - var contacts = JSON.parse(wrapper.attr('data-json')); contacts = contacts.filter(function(contact) { var keep = false contact['groups'].forEach(function(group) { @@ -47,11 +49,10 @@ $(document).ready(function() { }); return keep; }); - list_meps(contacts, $('.contact .wrapper')); + list_meps(contacts, wrapper); }); $('#search').change(function() { - var contacts = JSON.parse(wrapper.attr('data-json')); contacts = contacts.filter(function(contact) { return contact['full_name'].startsWith($('#search').val()); }); @@ -59,7 +60,8 @@ $(document).ready(function() { }); var wrapper = $('.contact .wrapper'); - var contacts = JSON.parse(wrapper.attr('data-json')); + var contacts_json = $('.contact .json-data').text() + var contacts = JSON.parse(contacts_json); list_meps(contacts, wrapper); var random = Math.floor((Math.random() * $('.collection-item').length)); -- GitLab