sortable menus, done

v1.18.x
psychobunny 10 years ago
parent 809ed255d1
commit d806cd134f

@ -2,57 +2,44 @@
/* global define, app, ajaxify, socket, templates, bootbox */ /* global define, app, ajaxify, socket, templates, bootbox */
define('admin/general/navigation', function() { define('admin/general/navigation', function() {
var navigation = {}; var navigation = {},
available;
var available;
navigation.init = function() { navigation.init = function() {
available = JSON.parse(ajaxify.variables.get('available')); available = JSON.parse(ajaxify.variables.get('available'));
$('.delete').on('click', function() { $('#save').on('click', save);
$(this).parents('li').remove(); $('.delete').on('click', remove);
}); $('.toggle').on('click', toggle);
$('.toggle').on('click', function() {
var btn = $(this),
disabled = btn.html() === 'Enable';
btn.toggleClass('btn-warning').toggleClass('btn-success').html(!disabled ? 'Enable' : 'Disable');
btn.parents('li').find('[name="enabled"]').val(disabled);
return false;
});
$('#save').on('click', saveNavigation);
$('#enabled') $('#enabled')
.sortable() .sortable()
.droppable({ .droppable({
accept: $('#available li') accept: $('#available li')
}) });
.disableSelection();
$('#available li') $('#available li')
.draggable({ .draggable({
connectToSortable: '#enabled', connectToSortable: '#enabled',
helper: 'clone', helper: 'clone',
distance: 10, distance: 10,
stop: function(ev, ui) { stop: drop
var id = ui.helper.attr('data-id'), });
el = $('#enabled [data-id="' + id + '"]'),
data = id === 'custom' ? {} : available[id];
templates.parse('admin/general/navigation', 'enabled', {enabled: [data]}, function(li) {
li = $(li);
el.after(li);
el.remove();
});
}
})
.disableSelection();
}; };
function saveNavigation() { function drop(ev, ui) {
var id = ui.helper.attr('data-id'),
el = $('#enabled [data-id="' + id + '"]'),
data = id === 'custom' ? {} : available[id];
templates.parse('admin/general/navigation', 'enabled', {enabled: [data]}, function(li) {
li = $(li);
el.after(li);
el.remove();
});
}
function save() {
var nav = []; var nav = [];
$('#enabled li').each(function() { $('#enabled li').each(function() {
@ -81,12 +68,17 @@ define('admin/general/navigation', function() {
}); });
} }
function getDefaultsByRoute(route) { function remove() {
available.forEach(function(item) { $(this).parents('li').remove();
if (item.route.match(route)) { }
return item;
} function toggle() {
}); var btn = $(this),
disabled = btn.html() === 'Enable';
btn.toggleClass('btn-warning').toggleClass('btn-success').html(!disabled ? 'Enable' : 'Disable');
btn.parents('li').find('[name="enabled"]').val(disabled);
return false;
} }
return navigation; return navigation;

@ -9,8 +9,10 @@ var admin = {},
admin.save = function(data, callback) { admin.save = function(data, callback) {
var order = Object.keys(data), var order = Object.keys(data),
items = data.map(function(item) { items = data.map(function(item, idx) {
return JSON.stringify(item); var data = {};
data[idx] = item;
return JSON.stringify(data);
}); });
async.waterfall([ async.waterfall([

@ -8,8 +8,8 @@ var navigation = {},
navigation.get = function(callback) { navigation.get = function(callback) {
db.getSortedSetRange('navigation:enabled', 0, -1, function(err, data) { db.getSortedSetRange('navigation:enabled', 0, -1, function(err, data) {
callback(err, data.map(function(item) { callback(err, data.map(function(item, idx) {
return JSON.parse(item); return JSON.parse(item)[idx];
})); }));
}); });
}; };

@ -21,7 +21,7 @@ var db = require('./database'),
schemaDate, thisSchemaDate, schemaDate, thisSchemaDate,
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
latestSchema = Date.UTC(2015, 1, 25, 2); latestSchema = Date.UTC(2015, 1, 25, 4);
Upgrade.check = function(callback) { Upgrade.check = function(callback) {
db.get('schemaDate', function(err, value) { db.get('schemaDate', function(err, value) {
@ -943,7 +943,7 @@ Upgrade.upgrade = function(callback) {
} }
}, },
function(next) { function(next) {
thisSchemaDate = Date.UTC(2015, 1, 25, 2); thisSchemaDate = Date.UTC(2015, 1, 25, 4);
if (schemaDate < thisSchemaDate) { if (schemaDate < thisSchemaDate) {
updatesMade = true; updatesMade = true;
winston.info('[2015/02/25] Upgrading menu items to dynamic navigation system'); winston.info('[2015/02/25] Upgrading menu items to dynamic navigation system');

Loading…
Cancel
Save