aboutsummaryrefslogtreecommitdiff
path: root/data/assets/js/admin/dialogs/post-edit.js
diff options
context:
space:
mode:
Diffstat (limited to 'data/assets/js/admin/dialogs/post-edit.js')
-rw-r--r--data/assets/js/admin/dialogs/post-edit.js88
1 files changed, 69 insertions, 19 deletions
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