2014-09-18 17:58:47 -06:00
|
|
|
var getState = function(){
|
|
|
|
|
var loadValues = [];
|
|
|
|
|
$('input, select, textarea').each(function(index, element){
|
|
|
|
|
var name = $(element).prop('name'),
|
|
|
|
|
value = $(element).val();
|
|
|
|
|
|
|
|
|
|
if (name) loadValues.push(name + '|' + value);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return loadValues.toString();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$(function(){
|
|
|
|
|
|
|
|
|
|
// selectize
|
|
|
|
|
$('input.page-filter').selectize({
|
2015-04-20 20:41:34 +02:00
|
|
|
maxItems: null,
|
|
|
|
|
valueField: 'flag',
|
|
|
|
|
labelField: 'flag',
|
|
|
|
|
searchField: ['flag'],
|
|
|
|
|
options: [
|
|
|
|
|
{flag: 'Modular'},
|
|
|
|
|
{flag: 'Visible'},
|
|
|
|
|
{flag: 'Routable'}
|
2015-07-27 14:32:31 -07:00
|
|
|
]
|
2014-09-18 17:58:47 -06:00
|
|
|
});
|
|
|
|
|
|
2015-07-27 14:32:31 -07:00
|
|
|
|
|
|
|
|
var childrenToggles = $('[data-toggle="children"]'),
|
|
|
|
|
storage = sessionStorage.getItem('grav:admin:pages'),
|
|
|
|
|
collapseAll = function(store) {
|
|
|
|
|
childrenToggles.each(function(i, element){
|
|
|
|
|
var icon = $(element).find('.page-icon'),
|
|
|
|
|
open = icon.hasClass('children-open'),
|
|
|
|
|
key = $(element).closest('[data-nav-id]').data('nav-id'),
|
|
|
|
|
children = $(element).closest('li.page-item').find('ul:first');
|
|
|
|
|
|
|
|
|
|
if (open) {
|
|
|
|
|
children.hide();
|
|
|
|
|
if (store) delete storage[key];
|
|
|
|
|
icon.removeClass('children-open').addClass('children-closed');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (store) sessionStorage.setItem('grav:admin:pages', JSON.stringify(storage));
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
expandAll = function(store) {
|
|
|
|
|
childrenToggles.each(function(i, element){
|
|
|
|
|
var icon = $(element).find('.page-icon'),
|
|
|
|
|
open = icon.hasClass('children-open'),
|
|
|
|
|
key = $(element).closest('[data-nav-id]').data('nav-id'),
|
|
|
|
|
children = $(element).closest('li.page-item').find('ul:first');
|
|
|
|
|
|
|
|
|
|
if (!open) {
|
|
|
|
|
children.show();
|
|
|
|
|
if (store) storage[key] = 1;
|
|
|
|
|
icon.removeClass('children-closed').addClass('children-open');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (store) sessionStorage.setItem('grav:admin:pages', JSON.stringify(storage));
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
restoreStates = function() {
|
|
|
|
|
collapseAll();
|
|
|
|
|
for (var key in storage) {
|
|
|
|
|
var element = $('[data-nav-id="' + key + '"]'),
|
|
|
|
|
icon = element.find('.page-icon').first(),
|
|
|
|
|
open = icon.hasClass('children-open'),
|
|
|
|
|
children = element.closest('li.page-item').find('ul:first');
|
|
|
|
|
|
|
|
|
|
children.show();
|
|
|
|
|
icon.removeClass('children-closed').addClass('children-open');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!storage) {
|
|
|
|
|
sessionStorage.setItem('grav:admin:pages', (storage = '{}'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
storage = JSON.parse(storage);
|
|
|
|
|
|
2015-04-20 20:41:34 +02:00
|
|
|
var startFilterPages = function () {
|
|
|
|
|
|
|
|
|
|
$('input[name="page-search"]').focus();
|
|
|
|
|
var flags = $('input[name="page-filter"]').val(),
|
|
|
|
|
query = $('input[name="page-search"]').val();
|
|
|
|
|
|
|
|
|
|
if (!flags.length && !query.length) {
|
2015-07-27 14:32:31 -07:00
|
|
|
GravAjax.jqxhr.abort();
|
2015-04-20 20:41:34 +02:00
|
|
|
return finishFilterPages([], true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GravAjax({
|
|
|
|
|
dataType: 'json',
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: GravAdmin.config.base_url_relative + '/pages-filter.json/task:filterPages',
|
|
|
|
|
data: {
|
|
|
|
|
flags: flags,
|
|
|
|
|
query: query
|
|
|
|
|
},
|
2015-05-11 16:37:43 +02:00
|
|
|
toastErrors: true,
|
2015-04-20 20:41:34 +02:00
|
|
|
success: function (result, status) {
|
|
|
|
|
finishFilterPages(result.results);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var finishFilterPages = function (pages, reset) {
|
|
|
|
|
var items = $('[data-nav-id]');
|
|
|
|
|
|
|
|
|
|
items.removeClass('search-match');
|
|
|
|
|
|
|
|
|
|
if (reset) {
|
|
|
|
|
items.addClass('search-match');
|
2015-07-27 14:32:31 -07:00
|
|
|
restoreStates();
|
2015-04-20 20:41:34 +02:00
|
|
|
} else {
|
|
|
|
|
pages.forEach(function (id) {
|
2015-07-27 14:32:31 -07:00
|
|
|
var match = items.filter('[data-nav-id="' + id + '"]'),
|
|
|
|
|
parents = match.parents('[data-nav-id]');
|
2015-04-20 20:41:34 +02:00
|
|
|
match.addClass('search-match');
|
|
|
|
|
match.find('[data-nav-id]').addClass('search-match');
|
2015-07-27 14:32:31 -07:00
|
|
|
parents.addClass('search-match');
|
|
|
|
|
parents.find('[data-toggle="children"]').each(function(index, element){
|
|
|
|
|
var icon = $(this).find('.page-icon'),
|
|
|
|
|
open = icon.hasClass('children-open'),
|
|
|
|
|
children = $(this).closest('li.page-item').find('ul:first');
|
|
|
|
|
|
|
|
|
|
if (!open) {
|
|
|
|
|
children.show();
|
|
|
|
|
icon.removeClass('children-closed').addClass('children-open');
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-04-20 20:41:34 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
items.each(function (key, item) {
|
|
|
|
|
if ($(item).hasClass('search-match')) {
|
|
|
|
|
$(item).show();
|
|
|
|
|
} else {
|
|
|
|
|
$(item).hide();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// selectize
|
|
|
|
|
$('input[name="page-search"]').on('input', startFilterPages);
|
|
|
|
|
$('input[name="page-filter"]').on('change', startFilterPages);
|
|
|
|
|
|
|
|
|
|
|
2014-09-18 17:58:47 -06:00
|
|
|
// auto generate folder based on title
|
|
|
|
|
// on user input on folder, autogeneration stops
|
|
|
|
|
// if user empties the folder, autogeneration restarts
|
|
|
|
|
$('input[name="folder"]').on('input', function(){
|
|
|
|
|
$(this).data('user-custom-folder', true);
|
|
|
|
|
if (!$(this).val()) $(this).data('user-custom-folder', false);
|
2015-07-27 14:32:31 -07:00
|
|
|
});
|
|
|
|
|
|
2014-09-18 17:58:47 -06:00
|
|
|
$('input[name="title"]').on('input', function(e){
|
|
|
|
|
if (!$('input[name="folder"]').data('user-custom-folder')) {
|
2014-09-26 10:55:00 -07:00
|
|
|
folder = $(this).val().toLowerCase().replace(/\s/g, '-').replace(/[^a-z0-9_\-]/g, '');
|
2014-09-18 17:58:47 -06:00
|
|
|
$('input[name="folder"]').val(folder);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-09-26 10:58:44 -07:00
|
|
|
$('input[name="folder"]').on('input', function(e){
|
|
|
|
|
value = $(this).val().toLowerCase().replace(/\s/g, '-').replace(/[^a-z0-9_\-]/g, '');
|
|
|
|
|
$(this).val(value);
|
|
|
|
|
});
|
|
|
|
|
|
2015-07-27 14:32:31 -07:00
|
|
|
childrenToggles.on('click', function () {
|
2015-04-20 16:43:30 +02:00
|
|
|
var icon = $(this).find('.page-icon'),
|
|
|
|
|
open = icon.hasClass('children-open'),
|
2015-07-27 14:32:31 -07:00
|
|
|
key = $(this).closest('[data-nav-id]').data('nav-id'),
|
2015-04-20 16:43:30 +02:00
|
|
|
children = $(this).closest('li.page-item').find('ul:first');
|
|
|
|
|
|
|
|
|
|
if (open) {
|
|
|
|
|
children.hide();
|
2015-07-27 14:32:31 -07:00
|
|
|
delete storage[key];
|
2015-04-20 16:43:30 +02:00
|
|
|
icon.removeClass('children-open').addClass('children-closed');
|
|
|
|
|
} else {
|
|
|
|
|
children.show();
|
2015-07-27 14:32:31 -07:00
|
|
|
storage[key] = true;
|
2015-04-20 16:43:30 +02:00
|
|
|
icon.removeClass('children-closed').addClass('children-open');
|
|
|
|
|
}
|
2015-07-27 14:32:31 -07:00
|
|
|
|
|
|
|
|
sessionStorage.setItem('grav:admin:pages', JSON.stringify(storage));
|
2015-04-20 16:43:30 +02:00
|
|
|
});
|
|
|
|
|
|
2014-09-18 17:58:47 -06:00
|
|
|
var currentValues = getState(),
|
|
|
|
|
clickedLink;
|
|
|
|
|
|
|
|
|
|
$('#admin-main button').on('click', function(){
|
|
|
|
|
$(window).off('beforeunload');
|
|
|
|
|
});
|
|
|
|
|
|
2014-09-18 17:32:58 -07:00
|
|
|
$('[data-remodal-id] form').on('submit', function(){
|
|
|
|
|
$(window).off('beforeunload');
|
|
|
|
|
});
|
|
|
|
|
|
2014-09-18 17:58:47 -06:00
|
|
|
$("#admin-mode-toggle input[name=mode-switch]").on('change', function(e){
|
2014-09-18 17:35:05 -07:00
|
|
|
var value = $(this).val(),
|
|
|
|
|
uri = $(this).data('leave-url');
|
2014-09-18 17:58:47 -06:00
|
|
|
|
|
|
|
|
if (currentValues == getState()) {
|
|
|
|
|
setTimeout(function(){
|
2014-09-18 17:35:05 -07:00
|
|
|
window.location.href = uri;
|
2014-09-18 17:58:47 -06:00
|
|
|
}, 200)
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
var confirm = $.remodal.lookup[$('[data-remodal-id=changes]').data('remodal')],
|
|
|
|
|
buttons = $('[data-remodal-id=changes] a.button'),
|
|
|
|
|
action;
|
|
|
|
|
|
|
|
|
|
buttons.on('click', function(e){
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
action = $(this).data('leave-action');
|
|
|
|
|
|
|
|
|
|
buttons.off('click');
|
|
|
|
|
confirm.close();
|
|
|
|
|
|
|
|
|
|
if (action == 'continue') {
|
|
|
|
|
$(window).off('beforeunload');
|
2014-09-21 18:27:12 -07:00
|
|
|
window.location.href = $("#admin-mode-toggle input[name=mode-switch]:checked").data('leave-url');
|
2014-09-18 17:58:47 -06:00
|
|
|
} else {
|
|
|
|
|
$('input[name=mode-switch][checked]').prop('checked', true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
confirm.open();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('a[href]:not([href^=#])').on('click', function(e){
|
|
|
|
|
if (currentValues != getState()){
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
clickedLink = $(this).attr('href');
|
|
|
|
|
|
|
|
|
|
var confirm = $.remodal.lookup[$('[data-remodal-id=changes]').data('remodal')],
|
|
|
|
|
buttons = $('[data-remodal-id=changes] a.button'),
|
|
|
|
|
action;
|
|
|
|
|
|
|
|
|
|
buttons.on('click', function(e){
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
action = $(this).data('leave-action');
|
|
|
|
|
|
|
|
|
|
buttons.off('click');
|
|
|
|
|
confirm.close();
|
|
|
|
|
|
|
|
|
|
if (action == 'continue') {
|
|
|
|
|
$(window).off('beforeunload');
|
|
|
|
|
window.location.href = clickedLink;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
confirm.open();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-09-30 15:49:28 -07:00
|
|
|
// deletion
|
|
|
|
|
$('[data-remodal-target="delete"]').on('click', function(){
|
|
|
|
|
var okdelete = $('[data-remodal-id=delete] a.button');
|
|
|
|
|
|
|
|
|
|
okdelete.data('delete-action', $(this).data('delete-url'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('[data-delete-action]').on('click', function(){
|
|
|
|
|
var confirm = $.remodal.lookup[$('[data-remodal-id=delete]').data('remodal')],
|
|
|
|
|
okdelete = $(this).data('delete-action');
|
|
|
|
|
|
|
|
|
|
window.location.href = okdelete;
|
|
|
|
|
confirm.close();
|
|
|
|
|
});
|
|
|
|
|
|
2014-09-18 17:58:47 -06:00
|
|
|
$(window).on('beforeunload', function(){
|
|
|
|
|
if (currentValues != getState()){
|
|
|
|
|
return "You have made changes on this page that you have not yet confirmed. If you navigate away from this page you will lose your unsaved changes";
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|