From a040bec0048a7f2d1ef61d69aba033bcbb8d6e35 Mon Sep 17 00:00:00 2001 From: Alexandr Nesterenko Date: Tue, 25 Jul 2017 14:09:00 -0700 Subject: [PATCH] xpath autosave --- .../frontend/assets/js/setup-tool-ext.js | 79 +++++++++++++++---- .../frontend/templates/frontend/setup.html | 4 + 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/frontend/frontend/static/frontend/assets/js/setup-tool-ext.js b/frontend/frontend/static/frontend/assets/js/setup-tool-ext.js index 601c461..f9fc532 100644 --- a/frontend/frontend/static/frontend/assets/js/setup-tool-ext.js +++ b/frontend/frontend/static/frontend/assets/js/setup-tool-ext.js @@ -4,29 +4,65 @@ if (!document.location.href.match('https?://[^/]+/[^/]+/setup\?.+')) return; +function save(key, obj) { + if (typeof(localStorage) !== "undefined") { + var tm = new Date().getTime(); + var v = {time: tm, value: obj} + localStorage.setItem(key, JSON.stringify(v)); + } +} +function read(key) { + var day = 24 * 60 * 60 * 1000; + + if (typeof(localStorage) !== "undefined") { + var v = localStorage.getItem(key); + if (v) { + var tm = new Date().getTime(); + var v = JSON.parse(v); + if (tm - v.time < day) { + return v.value; + } + } + } +} + +window.save = save; +window.read = read; + function init_tool(pathes) { } function check_pathes(pathes) { } -var _config = null; +var _config = ['', {}]; var _active = false; function updateUI(config) { - console.log(config); - _config = config; + console.log(config); + _config = config; - $('#ste-parent').val(config[0]); - ['title', 'description', 'link'].forEach(function(name){ - $('#ste-'+ name).val(name in config[1] ? config[1][name] : ''); - }); + $('#ste-parent').val(config[0]); + ['title', 'description', 'link'].forEach(function(name){ + $('#ste-'+ name).val(name in config[1] ? config[1][name] : ''); + }); } function showIcon(show) { $("#st-ext-trigger")[0].style.display = show ? "inline-block" : "none"; } +function getUIConfig() { + var cfg = [ + $('#ste-parent').val(), + {} + ]; + ['title', 'description', 'link'].forEach(function(name){ + cfg[1][name] = $('#ste-'+ name).val(); + }); + return cfg; +} + function changed() { var ch = false; if (_config[0] != $('#ste-parent').val()) @@ -57,24 +93,37 @@ window.ET = { }; function show_ext(show) { - if (show && changed() && !confirm($("#st-clicker-trigger").attr('confirm-text'))) - return; - $("#st-ext-trigger")[0].style.display = show ? "inline-block" : "none"; - $("#st-clicker-trigger")[0].style.display = !show ? "inline-block" : "none"; - $("#st-extended")[0].style.display = !show ? "block" : "none"; - $("#st-clicker")[0].style.display = show ? "block" : "none"; + $("#st-ext-trigger")[0].style.display = !show ? "inline-block" : "none"; + $("#st-clicker-trigger")[0].style.display = show ? "inline-block" : "none"; + $("#st-extended")[0].style.display = show ? "block" : "none"; + $("#st-clicker")[0].style.display = !show ? "block" : "none"; _active = show; } $(document).ready(function(){ $("#st-ext-trigger").click(function(){ - show_ext(false); + show_ext(true); + return true; }); $("#st-clicker-trigger").click(function(){ - show_ext(true); + var ch = changed(); + if (!ch || confirm($("#st-clicker-trigger").attr('confirm-text'))) + show_ext(false); + return true; }); + /*var cfg = read('xpathes') + if (cfg) { + updateUI(cfg); + show_ext(true); + $("#restored-alert")[0].style.display = 'block'; + }*/ + + /*$("#ste-parent, #ste-title, #ste-description, #ste-link").change(function(){ + save('xpathes', getUIConfig()); + return true; + });*/ }); diff --git a/frontend/frontend/templates/frontend/setup.html b/frontend/frontend/templates/frontend/setup.html index fc38f15..f03c56b 100644 --- a/frontend/frontend/templates/frontend/setup.html +++ b/frontend/frontend/templates/frontend/setup.html @@ -44,6 +44,10 @@ }
+

{% trans 'setup.you_are_creating_feed_with' %}