From 698d385886fa342f9879c8d85e7f4290e4fa506f Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Thu, 28 Jul 2016 21:22:52 -0400 Subject: populate themes settings pane --- data/assets/js/admin/tabs/themes.js | 121 ++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 data/assets/js/admin/tabs/themes.js (limited to 'data/assets/js/admin/tabs') diff --git a/data/assets/js/admin/tabs/themes.js b/data/assets/js/admin/tabs/themes.js new file mode 100644 index 0000000..26170b0 --- /dev/null +++ b/data/assets/js/admin/tabs/themes.js @@ -0,0 +1,121 @@ +jQuery(function($) { + "use strict"; + + var TEMPLATES = new LuigiTemplate.Cache({ + theme: [ + "", + "", + " ", + "%{theme_name|h} (%{theme_version|h}, %{theme_date|h})", + "", + ], + + loading: [ + "", + "", + " ", + "Loading...", + "", + ], + + error: [ + "", + "", + " ", + "Error: %{error|h}", + "", + ], + }); + + function filter() { + var qs = $('#themes-q').val().replace(/^\s+|\s+$/g, '').toLowerCase().split(/\s+/); + + if (qs.length > 0) { + // hide all themes + $('#themes .list-group-item').addClass('hidden'); + + // show matching themes + $($.grep($('#themes .list-group-item'), function(el) { + var eq = $(el).data('q'); + + return ($.grep(qs, function(q) { + return eq.indexOf(q) !== -1; + }).length == qs.length); + })).removeClass('hidden'); + } else { + // show all themes + $('#themes .list-group-item').removeClass('hidden'); + } + } + + function reload() { + var btn = $('#themes-reload'), + list = $('#themes'); + + // show loading + btn.toggleClass('disabled').find('.loading').toggleClass('hidden'); + list.html(TEMPLATES.run('loading')); + + send('theme/list').always(function() { + btn.toggleClass('disabled').find('.loading').toggleClass('hidden'); + list.html(''); + }).fail(function(r) { + var error = r.responseText; + + try { + var data = $.parseJSON(r.responseText); + if (data.error) + error = data.error; + } catch (e) {} + + list.html(TEMPLATES.run('error', { + error: error + })); + }).done(function(r) { + list.html($.map(r, function(row) { + var active = (row.is_active == '1'); + + return TEMPLATES.run('theme', $.extend({}, row, { + q: [row.theme_id, row.theme_name, row.theme_version, row.theme_date].join(' ').toLowerCase(), + })); + }).join('')); + + // refresh filters + filter(); + }); + + // stop event + return false; + } + + $('#themes-q').on('search-update', function() { + filter(); + }); + + $('#themes').on('click', 'a.list-group-item', function() { + var theme_id = $(this).data('theme_id'); + + // update highlight + $('#themes .active').removeClass('active'); + $(this).addClass('active'); + + // TODO: show theme details dialog + // $('#theme-edit-dialog').data('theme_id', theme_id).modal('show'); + + // stop event + return false; + }); + + $('#themes-reload').click(reload); + + // load themes + $('#settings-tab-themes').on('show.bs.tab', function() { + reload(); + }); +}); -- cgit v1.2.3