aboutsummaryrefslogtreecommitdiff
path: root/data/assets/js/admin/dialogs
diff options
context:
space:
mode:
Diffstat (limited to 'data/assets/js/admin/dialogs')
-rw-r--r--data/assets/js/admin/dialogs/blog-edit.js20
-rw-r--r--data/assets/js/admin/dialogs/page-edit.js23
-rw-r--r--data/assets/js/admin/dialogs/post-edit.js88
-rw-r--r--data/assets/js/admin/dialogs/project-edit.js21
4 files changed, 127 insertions, 25 deletions
diff --git a/data/assets/js/admin/dialogs/blog-edit.js b/data/assets/js/admin/dialogs/blog-edit.js
index 46a782b..0084028 100644
--- a/data/assets/js/admin/dialogs/blog-edit.js
+++ b/data/assets/js/admin/dialogs/blog-edit.js
@@ -1,7 +1,23 @@
jQuery(function($) {
"use strict";
- $('#blog-edit-dialog').on('post-data-loaded', function(r) {
- console.log(r);
+ var p = '#blog-edit-';
+
+ $(p + 'dialog').on('guff.loaded', function(ev) {
+ var r = ev.post_data;
+ $(p + 'tags').val(r.tags);
+ });
+
+ $(p + 'confirm').click(function() {
+ $(p + 'dialog').trigger({
+ type: 'guff.save',
+
+ post_data: {
+ tags: $(p + 'tags').val(),
+ },
+ });
+
+ // stop event
+ return false;
});
});
diff --git a/data/assets/js/admin/dialogs/page-edit.js b/data/assets/js/admin/dialogs/page-edit.js
index 8af9ec2..05d69a7 100644
--- a/data/assets/js/admin/dialogs/page-edit.js
+++ b/data/assets/js/admin/dialogs/page-edit.js
@@ -1,7 +1,26 @@
jQuery(function($) {
"use strict";
- $('#page-edit-dialog').on('post-data-loaded', function(r) {
- console.log(r);
+ var p = '#page-edit-';
+
+ $(p + 'dialog').on('guff.loaded', function(ev) {
+ var r = ev.post_data;
+
+ $(p + 'layout a').removeClass('btn-primary').addClass('btn-default');
+ $(p + 'layout a[data-val="' + r.layout + '"]')
+ .toggleClass('btn-primary btn-default');
+ });
+
+ $(p + 'confirm').click(function() {
+ $(p + 'dialog').trigger({
+ type: 'guff.save',
+
+ post_data: {
+ layout: $(p + 'layout .btn-primary').data('val'),
+ },
+ });
+
+ // stop event
+ return false;
});
});
diff --git a/data/assets/js/admin/dialogs/post-edit.js b/data/assets/js/admin/dialogs/post-edit.js
index 31b85ee..01baba1 100644
--- a/data/assets/js/admin/dialogs/post-edit.js
+++ b/data/assets/js/admin/dialogs/post-edit.js
@@ -8,7 +8,7 @@ jQuery(function($) {
if (slug.prop('disabled')) {
slug.val(
name.val().toLowerCase()
- .replace(/[^a-z0-9_\.-]+/g, '-')
+ .replace(/[^a-z0-9_-]+/g, '-')
.replace(/^-+|-+$/g, '')
);
}
@@ -17,9 +17,39 @@ jQuery(function($) {
$.each(['blog', 'page', 'project'], function(i, id) {
var p = '#' + id + '-edit-';
- $(p + 'dialog').one('shown.bs.modal', function() {
- // lazy-init editor
- CKEDITOR.replace(id + '-edit-body');
+ $(p + 'dialog').on('guff.loaded', function(ev) {
+ var r = ev.post_data,
+ slug_lock = (r.slug_lock == "1");
+
+ $(p + 'name').val(r.name);
+ $(p + 'slug').val(r.slug)
+ .prop('disabled', slug_lock ? 'disabled' : null);
+
+ $(p + 'slug-lock')
+ .toggleClass('btn-default', slug_lock)
+ .toggleClass('btn-primary', !slug_lock)
+ .find('fa')
+ .toggleClass('fa-lock', slug_lock)
+ .toggleClass('fa-unlock', !slug_lock);
+
+ var editor = CKEDITOR.instances[id + '-edit-body'];
+ if (!editor) {
+ // lazy-init editor
+ editor = CKEDITOR.replace(id + '-edit-body');
+ }
+
+ if (editor.status == 'ready') {
+ // editor is ready, set body data
+ editor.setData(r.body);
+ } else {
+ editor.once('instanceReady', function() {
+ editor.setData(r.body);
+ });
+ }
+
+ $(p + 'state a').removeClass('btn-primary').addClass('btn-default');
+ $(p + 'state a[data-val="' + r.state + '"]')
+ .toggleClass('btn-primary btn-default');
}).on('show.bs.modal', function() {
var me = $(this);
@@ -50,7 +80,7 @@ jQuery(function($) {
me.find('.modal-body.loading-done').removeClass('hidden');
me.trigger({
- type: "post-data-loaded",
+ type: "guff.loaded",
post_data: r,
});
});
@@ -61,21 +91,40 @@ jQuery(function($) {
$(this).data('close-dialog-confirmed') ||
confirm('Close without saving changes?')
);
- }).find('button[data-dismiss="modal"]').click(function() {
- // override close confirmation
- // FIXME: should this only be on save?
- $(p + 'dialog').data('close-dialog-confirmed', true);
- });
+ }).on('guff.save', function(ev) {
+ $(p + 'confirm').addClass('disabled')
+ .find('.loading').toggleClass('hidden');
+
+ send(id + "/set", $.extend({
+ post_id: $(p + 'dialog').data('post_id'),
+ name: $(p + 'name').val(),
+ slug_lock: $(p + 'slug-lock').hasClass('btn-default') ? 't' : 'f',
+ slug: $(p + 'slug').val(),
+ body: CKEDITOR.instances[id + '-edit-body'].getData(),
+ state: $(p + 'state .btn-primary').data('val'),
+ }, ev.post_data)).always(function() {
+ $(p + 'confirm').removeClass('disabled')
+ .find('.loading').toggleClass('hidden');
+ }).fail(function(r) {
+ var error = r.responseText;
- $(p + 'confirm').click(function() {
- if ($(this).hasClass('disabled'))
- return false;
+ try {
+ var data = $.parseJSON(r.responseText);
+ if (data.error)
+ error = data.error;
+ } catch (e) {}
- // TODO: see #user-add-confirm
- alert('TODO: create');
+ alert('Error: ' + error);
+ }).done(function(r) {
+ // reload posts
+ $('#posts-reload').click();
- // stop event
- return false;
+ // dismiss dialog
+ $(p + 'dialog').data('close-dialog-confirmed', true).modal('hide');
+ });
+ }).find('button[data-dismiss="modal"]').click(function() {
+ // override close confirmation dialog
+ $(p + 'dialog').data('close-dialog-confirmed', true);
});
});
@@ -109,8 +158,9 @@ jQuery(function($) {
return false;
});
- $('.state-buttons').on('a', 'click', function() {
- $(this).parent().find('.btn-primary').toggleClass('btn-default btn-primary');
+ $('.state-buttons a').click(function() {
+ $(this).parent().find('.btn-primary')
+ .toggleClass('btn-default btn-primary');
$(this).toggleClass('btn-default btn-primary');
// stop event
diff --git a/data/assets/js/admin/dialogs/project-edit.js b/data/assets/js/admin/dialogs/project-edit.js
index a31abf2..17236f6 100644
--- a/data/assets/js/admin/dialogs/project-edit.js
+++ b/data/assets/js/admin/dialogs/project-edit.js
@@ -1,7 +1,24 @@
jQuery(function($) {
"use strict";
- $('#project-edit-dialog').on('post-data-loaded', function(r) {
- console.log(r);
+ var p = '#project-edit-';
+
+ $(p + 'dialog').on('guff.loaded', function(ev) {
+ var r = ev.post_data;
+
+ $(p + 'repo').val(r.repo_url);
+ });
+
+ $(p + 'confirm').click(function() {
+ $(p + 'dialog').trigger({
+ type: 'guff.save',
+
+ post_data: {
+ repo_url: $(p + 'repo').val(),
+ },
+ });
+
+ // stop event
+ return false;
});
});