aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
Diffstat (limited to 'data')
-rw-r--r--data/assets/js/admin/tabs/sites.js125
-rw-r--r--data/init.yaml75
2 files changed, 182 insertions, 18 deletions
diff --git a/data/assets/js/admin/tabs/sites.js b/data/assets/js/admin/tabs/sites.js
new file mode 100644
index 0000000..9ef9564
--- /dev/null
+++ b/data/assets/js/admin/tabs/sites.js
@@ -0,0 +1,125 @@
+jQuery(function($) {
+ "use strict";
+
+ var TEMPLATES = new LuigiTemplate.Cache({
+ site: [
+ "<a ",
+ "href='#' ",
+ "class='list-group-item %{css|h}' ",
+ "title='Edit site \"%{name|h}\".' ",
+ "data-site_id='%{site_id|h}' ",
+ "data-q='%{q|h}' ",
+ ">",
+ "%{name|h}",
+
+ "<span class='%{badge_css} badge pull-right'>",
+ "default",
+ "</span>",
+ "</a>",
+ ],
+
+ loading: [
+ "<span class='list-group-item disabled'>",
+ "<i class='fa fa-spinner fa-spin'></i>",
+ " ",
+ "Loading...",
+ "</span>",
+ ],
+
+ error: [
+ "<span class='list-group-item list-group-item-danger disabled'>",
+ "<i class='fa fa-exclamation-triangle'></i>",
+ " ",
+ "Error: %{error|h}",
+ "</span>",
+ ],
+ });
+
+ function filter() {
+ var qs = $('#sites-q').val().replace(/^\s+|\s+$/g, '').toLowerCase().split(/\s+/);
+
+ if (qs.length > 0) {
+ // hide all sites
+ $('#sites .list-group-item').addClass('hidden');
+
+ // show matching sites
+ $($.grep($('#sites .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 sites
+ $('#sites .list-group-item').removeClass('hidden');
+ }
+ }
+
+ function reload() {
+ var btn = $('#sites-reload'),
+ list = $('#sites');
+
+ // show loading
+ btn.toggleClass('disabled').find('.loading').toggleClass('hidden');
+ list.html(TEMPLATES.run('loading'));
+
+ send('site/get_sites').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('site', $.extend({}, row, {
+ q: [row.site_id, row.slug, row.name, row.body].join(' ').toLowerCase(),
+ badge_css: row.is_default ? '' : 'hidden',
+ }));
+ }).join(''));
+
+ // refresh filters
+ filter();
+ });
+
+ // stop event
+ return false;
+ }
+
+ $('#sites-q').on('search-update', function() {
+ filter();
+ });
+
+ $('#sites').on('click', 'a.list-group-item', function() {
+ var site_id = $(this).data('site_id');
+
+ // update highlight
+ $('#sites .active').removeClass('active');
+ $(this).addClass('active');
+
+ // TODO
+ // $('#site-edit-dialog').data('site_id', site_id).modal('show');
+ alert('TODO: edit site ' + site_id);
+
+ // stop event
+ return false;
+ });
+
+ $('#sites-reload').click(reload);
+
+ // load sites
+ $('#settings-tab-sites').on('show.bs.tab', function() {
+ reload();
+ });
+});
diff --git a/data/init.yaml b/data/init.yaml
index 34a0595..f9a8ac1 100644
--- a/data/init.yaml
+++ b/data/init.yaml
@@ -41,7 +41,7 @@ init_sql:
password TEXT NOT NULL DEFAULT '',
- is_active BOOLEAN NOT NULL DEFAULT false
+ is_active BOOLEAN NOT NULL DEFAULT 0
)
- |
@@ -88,7 +88,7 @@ init_sql:
-- is this a system theme?
-- note: system themes are located in system_dir/themes/<slug>/
- is_system BOOLEAN NOT NULL DEFAULT false
+ is_system BOOLEAN NOT NULL DEFAULT 0
)
- |
@@ -188,32 +188,67 @@ init_sql:
- |
CREATE TABLE sites (
- site_id INTEGER PRIMARY KEY,
+ site_id INTEGER PRIMARY KEY,
+
+ -- make sure slug is lowercase, does not begin with a dot, and
+ -- does not contain slashes
+ slug TEXT UNIQUE NOT NULL CHECK (
+ LENGTH(slug) > 0 AND
+ slug = LOWER(slug) AND
+ slug NOT LIKE '.%' AND
+ slug NOT LIKE '%/%'
+ ),
- -- make sure name does not begin with a dot or
+ -- make sure slug does not begin with a dot or
-- contain slashes
- name TEXT UNIQUE NOT NULL CHECK (
- LENGTH(name) > 0 AND
- name NOT LIKE '.%' AND
- name NOT LIKE '%/%'
- ),
+ name TEXT UNIQUE NOT NULL
+ CHECK (LENGTH(name) > 0),
+
+ -- site description
+ body TEXT NOT NULL DEFAULT '',
+
+ -- site description
+ lang TEXT NOT NULL DEFAULT 'en-US' CHECK (
+ -- e.g. 'en' or 'en-US'
+ (LENGTH(lang) = 2 OR LENGTH(lang) = 5) AND
+ (lang LIKE '__' OR lang LIKE '__-__')
+ ),
-- date that site was created
- created_at TIMESTAMP WITH TIME ZONE NOT NULL
- DEFAULT CURRENT_TIMESTAMP,
+ created_at TIMESTAMP WITH TIME ZONE NOT NULL
+ DEFAULT CURRENT_TIMESTAMP,
-- theme for this site
- theme_id INTEGER NOT NULL
- REFERENCES themes(theme_id),
+ theme_id INTEGER NOT NULL
+ REFERENCES themes(theme_id),
+
+ -- disabled: too fucking complicated with "is_default"
+ -- is this site active
+ -- is_active BOOLEAN NOT NULL DEFAULT 0,
- is_active BOOLEAN NOT NULL DEFAULT false,
+ -- is this the default site
+ is_default BOOLEAN NOT NULL DEFAULT 0,
- is_default BOOLEAN NOT NULL DEFAULT false
+ -- use full body for rss and atom feeds
+ is_full_feed BOOLEAN NOT NULL DEFAULT 1
)
- |
- INSERT INTO sites(site_id, name, theme_id, is_active, is_default) VALUES
- (1, 'default', 1, 1, 1)
+ INSERT INTO sites (
+ site_id,
+ slug,
+ name,
+ body,
+ theme_id,
+ is_default
+ ) VALUES (
+ 1,
+ 'default',
+ 'Default',
+ 'True guff stuff.',
+ 1,
+ 1
+ )
- |
CREATE TABLE site_domains (
@@ -224,7 +259,11 @@ init_sql:
LENGTH(domain) > 0 AND
domain = LOWER(domain) AND
domain NOT LIKE '% %'
- )
+ ),
+
+ sort_order INTEGER NOT NULL,
+
+ PRIMARY KEY (site_id, domain)
)
- |