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 */
define('admin/general/navigation', function() {
var navigation = {};
var available;
var navigation = {},
available;
navigation.init = function() {
available = JSON.parse(ajaxify.variables.get('available'));
$('.delete').on('click', function() {
$(this).parents('li').remove();
});
$('.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);
$('#save').on('click', save);
$('.delete').on('click', remove);
$('.toggle').on('click', toggle);
$('#enabled')
.sortable()
.droppable({
accept: $('#available li')
})
.disableSelection();
});
$('#available li')
.draggable({
connectToSortable: '#enabled',
helper: 'clone',
distance: 10,
stop: function(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();
});
}
})
.disableSelection();
stop: drop
});
};
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 = [];
$('#enabled li').each(function() {
@ -81,12 +68,17 @@ define('admin/general/navigation', function() {
});
}
function getDefaultsByRoute(route) {
available.forEach(function(item) {
if (item.route.match(route)) {
return item;
}
});
function remove() {
$(this).parents('li').remove();
}
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;

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

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

@ -21,7 +21,7 @@ var db = require('./database'),
schemaDate, thisSchemaDate,
// 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) {
db.get('schemaDate', function(err, value) {
@ -943,7 +943,7 @@ Upgrade.upgrade = function(callback) {
}
},
function(next) {
thisSchemaDate = Date.UTC(2015, 1, 25, 2);
thisSchemaDate = Date.UTC(2015, 1, 25, 4);
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.info('[2015/02/25] Upgrading menu items to dynamic navigation system');

Loading…
Cancel
Save