2015-08-03 12:55:00 -07:00
|
|
|
var getState = function(){
|
2015-08-21 11:43:53 -07:00
|
|
|
var loadValues = [],
|
|
|
|
|
ignoreNames = ['page-filter', 'page-search'];
|
2015-08-03 12:55:00 -07:00
|
|
|
$('input, select, textarea').each(function(index, element){
|
|
|
|
|
var name = $(element).prop('name'),
|
|
|
|
|
value = $(element).val();
|
|
|
|
|
|
2015-08-21 11:43:53 -07:00
|
|
|
if (name && !~ignoreNames.indexOf(name)) loadValues.push(name + '|' + value);
|
2015-08-03 12:55:00 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return loadValues.toString();
|
|
|
|
|
};
|
|
|
|
|
|
2015-08-07 13:31:15 -07:00
|
|
|
var bytesToSize = function(bytes) {
|
|
|
|
|
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
|
|
|
if (bytes == 0) return '0 Byte';
|
|
|
|
|
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
|
|
|
|
|
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-07 13:44:12 -07:00
|
|
|
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
|
|
|
|
|
2015-09-14 15:58:34 +02:00
|
|
|
var keepAlive = function keepAlive() {
|
|
|
|
|
$.post(GravAdmin.config.base_url_relative + '/task' + GravAdmin.config.param_sep + 'keepAlive');
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-07 17:01:40 -07:00
|
|
|
$(function () {
|
|
|
|
|
jQuery.substitute = function(str, sub) {
|
|
|
|
|
return str.replace(/\{(.+?)\}/g, function($0, $1) {
|
|
|
|
|
return $1 in sub ? sub[$1] : $0;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-01 21:22:56 +02:00
|
|
|
// // selectize
|
|
|
|
|
// $('select.fancy:not(.create)').selectize({
|
|
|
|
|
// createOnBlur: true,
|
|
|
|
|
// });
|
2015-05-13 15:17:02 +02:00
|
|
|
|
2015-06-01 21:22:56 +02:00
|
|
|
// // selectize with create
|
|
|
|
|
// $('select.fancy.create').selectize({
|
|
|
|
|
// createOnBlur: true,
|
|
|
|
|
// persist: false,
|
|
|
|
|
// create: function (input) {
|
|
|
|
|
// return {
|
|
|
|
|
// value: input,
|
|
|
|
|
// text: input
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// });
|
2014-09-18 17:58:47 -06:00
|
|
|
|
2015-06-01 21:22:56 +02:00
|
|
|
// $('input.fancy').selectize({
|
|
|
|
|
// delimiter: ',',
|
|
|
|
|
// persist: false,
|
|
|
|
|
// create: function (input) {
|
|
|
|
|
// return {
|
|
|
|
|
// value: input,
|
|
|
|
|
// text: input
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// });
|
2014-10-07 17:01:40 -07:00
|
|
|
|
2014-12-11 19:57:57 -07:00
|
|
|
// Set Toastr defaults
|
|
|
|
|
toastr.options = {
|
|
|
|
|
"positionClass": "toast-top-right"
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 16:25:36 -08:00
|
|
|
// dashboard
|
|
|
|
|
var chart = $('.updates-chart'), UpdatesChart;
|
|
|
|
|
if (chart.length) {
|
|
|
|
|
var data = {
|
|
|
|
|
series: [100, 0]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
|
donut: true,
|
|
|
|
|
donutWidth: 10,
|
|
|
|
|
startAngle: 0,
|
|
|
|
|
total: 100,
|
|
|
|
|
showLabel: false,
|
2015-09-07 13:44:12 -07:00
|
|
|
height: 150,
|
|
|
|
|
chartPadding: !isFirefox ? 5 : 10
|
2014-12-19 16:25:36 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UpdatesChart = Chartist.Pie('.updates-chart .ct-chart', data, options);
|
|
|
|
|
UpdatesChart.on('draw', function(data){
|
|
|
|
|
if (data.index) { return; }
|
|
|
|
|
chart.find('.numeric span').text(Math.round(data.value) + '%');
|
2015-08-28 17:31:45 +02:00
|
|
|
|
|
|
|
|
var text = translations.PLUGIN_ADMIN.UPDATES_AVAILABLE;
|
|
|
|
|
if (data.value == 100) {
|
|
|
|
|
text = translations.PLUGIN_ADMIN.FULLY_UPDATED;
|
|
|
|
|
}
|
|
|
|
|
$('.js__updates-available-description').html(text)
|
|
|
|
|
$('.updates-chart .hidden').removeClass('hidden');
|
2014-12-19 16:25:36 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-11 19:57:57 -07:00
|
|
|
// Cache Clear
|
|
|
|
|
$('[data-clear-cache]').on('click', function(e) {
|
|
|
|
|
|
|
|
|
|
$(this).attr('disabled','disabled').find('> .fa').removeClass('fa-trash').addClass('fa-refresh fa-spin');
|
|
|
|
|
var url = $(this).data('clearCache');
|
2015-04-04 22:34:34 +02:00
|
|
|
|
2015-04-20 20:39:53 +02:00
|
|
|
GravAjax({
|
2015-04-04 22:34:34 +02:00
|
|
|
dataType: "json",
|
|
|
|
|
url: url,
|
2015-05-11 16:37:43 +02:00
|
|
|
toastErrors: true,
|
2015-04-04 22:34:34 +02:00
|
|
|
success: function(result, status) {
|
2015-05-11 16:37:43 +02:00
|
|
|
toastr.success(result.message);
|
2014-12-11 19:57:57 -07:00
|
|
|
}
|
2015-05-11 16:37:43 +02:00
|
|
|
}).always(function() {
|
2014-12-11 19:57:57 -07:00
|
|
|
$('[data-clear-cache]').removeAttr('disabled').find('> .fa').removeClass('fa-refresh fa-spin').addClass('fa-trash');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-07-28 14:36:19 -07:00
|
|
|
// Plugins list details sliders
|
|
|
|
|
$('.gpm-name, .gpm-actions').on('click', function(e){
|
|
|
|
|
var target = $(e.target);
|
|
|
|
|
|
|
|
|
|
if (target.prop('tagName') == 'A' || target.parent('a').length) { return true; }
|
|
|
|
|
|
|
|
|
|
var wrapper = $(this).siblings('.gpm-details').find('.table-wrapper');
|
|
|
|
|
wrapper.slideToggle({
|
|
|
|
|
duration: 350,
|
|
|
|
|
complete: function(){
|
|
|
|
|
var isVisible = wrapper.is(':visible');
|
|
|
|
|
wrapper
|
|
|
|
|
.closest('tr')
|
|
|
|
|
.find('.gpm-details-expand i')
|
|
|
|
|
.removeClass('fa-chevron-' + (isVisible ? 'down' : 'up'))
|
|
|
|
|
.addClass('fa-chevron-' + (isVisible ? 'up' : 'down'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-04-20 16:41:53 +02:00
|
|
|
// Update plugins/themes
|
2015-08-06 09:34:55 +02:00
|
|
|
$(document).on('click', '[data-maintenance-update]', function(e) {
|
2014-10-07 17:01:40 -07:00
|
|
|
|
2015-04-13 21:37:12 +02:00
|
|
|
$(this).attr('disabled','disabled').find('> .fa').removeClass('fa-cloud-download').addClass('fa-refresh fa-spin');
|
|
|
|
|
var url = $(this).data('maintenanceUpdate');
|
2015-08-08 17:41:53 +02:00
|
|
|
var task = 'task' + GravAdmin.config.param_sep;
|
2014-10-07 17:01:40 -07:00
|
|
|
|
2015-04-20 20:39:53 +02:00
|
|
|
GravAjax({
|
2015-04-13 21:37:12 +02:00
|
|
|
dataType: "json",
|
|
|
|
|
url: url,
|
2015-05-11 16:37:43 +02:00
|
|
|
toastErrors: true,
|
2015-04-13 21:37:12 +02:00
|
|
|
success: function(result, status) {
|
2015-08-08 17:41:53 +02:00
|
|
|
if (url.indexOf(task + 'updategrav') !== -1) {
|
2015-08-06 17:23:08 +02:00
|
|
|
if (result.status == 'success') {
|
|
|
|
|
$('[data-gpm-grav]').remove();
|
|
|
|
|
toastr.success(result.message + window.grav_available_version);
|
|
|
|
|
$('#footer .grav-version').html(window.grav_available_version);
|
2015-08-07 13:30:29 -07:00
|
|
|
|
|
|
|
|
/*// hide the update button after successfull update and update the badges
|
|
|
|
|
$('[data-maintenance-update]').fadeOut();
|
|
|
|
|
$('.badges.with-updates').removeClass('with-updates').find('.badge.updates').remove();*/
|
2015-08-06 17:23:08 +02:00
|
|
|
} else {
|
|
|
|
|
toastr.success(result.message);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
toastr.success(result.message);
|
2015-08-06 15:15:59 +02:00
|
|
|
}
|
2015-04-13 21:37:12 +02:00
|
|
|
}
|
2015-05-11 16:37:43 +02:00
|
|
|
}).always(function() {
|
2015-04-13 21:37:12 +02:00
|
|
|
GPMRefresh();
|
|
|
|
|
$('[data-maintenance-update]').removeAttr('disabled').find('> .fa').removeClass('fa-refresh fa-spin').addClass('fa-cloud-download');
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-10-07 17:01:40 -07:00
|
|
|
|
2015-04-27 13:37:22 +02:00
|
|
|
// Update plugins/themes
|
|
|
|
|
$('[data-ajax]').on('click', function(e) {
|
|
|
|
|
|
|
|
|
|
var button = $(this),
|
|
|
|
|
icon = button.find('> .fa'),
|
|
|
|
|
url = button.data('ajax');
|
|
|
|
|
|
|
|
|
|
var iconClasses = [],
|
|
|
|
|
helperClasses = [ 'fa-lg', 'fa-2x', 'fa-3x', 'fa-4x', 'fa-5x',
|
|
|
|
|
'fa-fw', 'fa-ul', 'fa-li', 'fa-border',
|
|
|
|
|
'fa-rotate-90', 'fa-rotate-180', 'fa-rotate-270',
|
|
|
|
|
'fa-flip-horizontal', 'fa-flip-vertical' ];
|
|
|
|
|
|
|
|
|
|
// Disable button
|
|
|
|
|
button.attr('disabled','disabled');
|
|
|
|
|
|
|
|
|
|
// Swap fontawesome icon to loader
|
|
|
|
|
$.each(icon.attr('class').split(/\s+/), function (i, classname) {
|
|
|
|
|
if (classname.indexOf('fa-') === 0 && $.inArray(classname, helperClasses) === -1) {
|
|
|
|
|
iconClasses.push(classname);
|
|
|
|
|
icon.removeClass(classname);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
icon.addClass('fa-refresh fa-spin');
|
|
|
|
|
|
|
|
|
|
GravAjax({
|
|
|
|
|
dataType: "json",
|
|
|
|
|
url: url,
|
2015-05-11 16:37:43 +02:00
|
|
|
toastErrors: true,
|
2015-04-27 13:37:22 +02:00
|
|
|
success: function(result, status) {
|
2015-08-08 17:41:53 +02:00
|
|
|
var task = 'task' + GravAdmin.config.param_sep;
|
2015-04-27 13:37:22 +02:00
|
|
|
|
|
|
|
|
var toastrBackup = {};
|
|
|
|
|
if (result.toastr) {
|
|
|
|
|
for (var setting in result.toastr) { if (result.toastr.hasOwnProperty(setting)) {
|
|
|
|
|
toastrBackup[setting] = toastr.options[setting];
|
|
|
|
|
toastr.options[setting] = result.toastr[setting];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-24 18:49:27 +02:00
|
|
|
toastr.success(result.message || translations.PLUGIN_ADMIN.TASK_COMPLETED);
|
2015-04-27 13:37:22 +02:00
|
|
|
|
|
|
|
|
for (var setting in toastrBackup) { if (toastrBackup.hasOwnProperty(setting)) {
|
|
|
|
|
toastr.options[setting] = toastrBackup[setting];
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-29 14:50:38 +02:00
|
|
|
|
2015-08-08 17:41:53 +02:00
|
|
|
if (url.indexOf(task + 'backup') !== -1) {
|
2015-07-29 14:50:38 +02:00
|
|
|
//Reset backup days count
|
2015-08-24 18:49:27 +02:00
|
|
|
$('.backups-chart .numeric').html("0 <em>" + translations.PLUGIN_ADMIN.DAYS + "</em>");
|
2015-07-29 15:10:07 +02:00
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
|
series: [0,100]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
|
donut: true,
|
|
|
|
|
donutWidth: 10,
|
|
|
|
|
startAngle: 0,
|
|
|
|
|
total: 100,
|
|
|
|
|
showLabel: false,
|
|
|
|
|
height: 150
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Chartist.Pie('.backups-chart .ct-chart', data, options);
|
2015-07-29 14:50:38 +02:00
|
|
|
}
|
2015-04-27 13:37:22 +02:00
|
|
|
}
|
2015-05-11 16:37:43 +02:00
|
|
|
}).always(function() {
|
2015-04-27 13:37:22 +02:00
|
|
|
// Restore button
|
|
|
|
|
button.removeAttr('disabled');
|
|
|
|
|
icon.removeClass('fa-refresh fa-spin').addClass(iconClasses.join(' '));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-08-07 14:08:12 -07:00
|
|
|
$('[data-gpm-checkupdates]').on('click', function(){
|
|
|
|
|
var element = $(this);
|
|
|
|
|
element.find('i').addClass('fa-spin');
|
|
|
|
|
GPMRefresh({
|
|
|
|
|
flush: true,
|
2015-08-12 12:45:12 -07:00
|
|
|
callback: function(response) {
|
|
|
|
|
var payload = response.status == 'success' ? response.payload : false;
|
2015-08-07 14:08:12 -07:00
|
|
|
element.find('i').removeClass('fa-spin');
|
2015-08-12 12:45:12 -07:00
|
|
|
|
|
|
|
|
if (payload) {
|
|
|
|
|
if (!payload.grav.isUpdatable && !payload.resources.total) {
|
2015-08-24 18:49:27 +02:00
|
|
|
toastr.success(translations.PLUGIN_ADMIN.EVERYTHING_UP_TO_DATE);
|
2015-08-12 12:45:12 -07:00
|
|
|
} else {
|
2015-08-24 18:49:27 +02:00
|
|
|
var grav = payload.grav.isUpdatable ? 'Grav v' + payload.grav.available : '';
|
|
|
|
|
var resources = payload.resources.total ? payload.resources.total + ' ' + translations.PLUGIN_ADMIN.UPDATES_ARE_AVAILABLE: '';
|
2015-08-12 12:45:12 -07:00
|
|
|
|
2015-08-24 18:49:27 +02:00
|
|
|
if (!resources) { grav += ' ' + translations.PLUGIN_ADMIN.IS_AVAILABLE_FOR_UPDATE }
|
|
|
|
|
toastr.info(grav + (grav && resources ? ' ' + translations.PLUGIN_ADMIN.AND + ' ' : '') + resources);
|
2015-08-12 12:45:12 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-08-07 14:08:12 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var GPMRefresh = function (options) {
|
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
|
task: 'GPM',
|
|
|
|
|
action: 'getUpdates'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (options.flush) { data.flush = true; }
|
|
|
|
|
|
2015-04-20 20:39:53 +02:00
|
|
|
GravAjax({
|
2015-04-13 21:37:12 +02:00
|
|
|
dataType: "JSON",
|
|
|
|
|
url: window.location.href,
|
|
|
|
|
method: "POST",
|
2015-08-07 14:08:12 -07:00
|
|
|
data: data,
|
2015-05-11 16:37:43 +02:00
|
|
|
toastErrors: true,
|
2015-04-13 21:37:12 +02:00
|
|
|
success: function (response) {
|
|
|
|
|
var grav = response.payload.grav,
|
|
|
|
|
installed = response.payload.installed,
|
2015-08-08 17:41:53 +02:00
|
|
|
resources = response.payload.resources,
|
|
|
|
|
task = 'task' + GravAdmin.config.param_sep;
|
2014-12-19 16:25:36 -08:00
|
|
|
|
2015-04-13 21:37:12 +02:00
|
|
|
// grav updatable
|
|
|
|
|
if (grav.isUpdatable) {
|
|
|
|
|
var icon = '<i class="fa fa-bullhorn"></i> ';
|
2015-08-24 18:49:27 +02:00
|
|
|
content = 'Grav <b>v{available}</b> ' + translations.PLUGIN_ADMIN.IS_NOW_AVAILABLE + '! <span class="less">(' + translations.PLUGIN_ADMIN.CURRENT + ': v{version})</span> ',
|
|
|
|
|
button = '<button data-maintenance-update="' + GravAdmin.config.base_url_relative + '/update.json/' + task + 'updategrav" class="button button-small secondary" id="grav-update-button">' + translations.PLUGIN_ADMIN.UPDATE_GRAV_NOW + '</button>';
|
2014-12-19 14:05:10 -08:00
|
|
|
|
2015-08-07 13:31:15 -07:00
|
|
|
if (grav.isSymlink) {
|
2015-08-24 18:49:27 +02:00
|
|
|
button = '<span class="hint--left" style="float: right;" data-hint="' + translations.PLUGIN_ADMIN.GRAV_SYMBOLICALLY_LINKED + '"><i class="fa fa-fw fa-link"></i></span>';
|
2015-08-07 13:31:15 -07:00
|
|
|
}
|
|
|
|
|
|
2015-04-13 21:37:12 +02:00
|
|
|
content = jQuery.substitute(content, {available: grav.available, version: grav.version});
|
|
|
|
|
$('[data-gpm-grav]').addClass('grav').html('<p>' + icon + content + button + '</p>');
|
2015-08-06 17:23:08 +02:00
|
|
|
window.grav_available_version = grav.available;
|
2015-04-13 21:37:12 +02:00
|
|
|
}
|
2015-04-04 22:34:34 +02:00
|
|
|
|
2015-08-06 15:15:59 +02:00
|
|
|
$('#grav-update-button').on('click', function() {
|
2015-08-24 18:49:27 +02:00
|
|
|
$(this).html(translations.PLUGIN_ADMIN.UPDATING_PLEASE_WAIT + ' ' + bytesToSize(grav.assets['grav-update'].size) + '..');
|
2015-08-06 15:15:59 +02:00
|
|
|
});
|
|
|
|
|
|
2015-04-13 21:37:12 +02:00
|
|
|
// dashboard
|
|
|
|
|
if ($('.updates-chart').length) {
|
|
|
|
|
var missing = (resources.total + (grav.isUpdatable ? 1 : 0)) * 100 / (installed + (grav.isUpdatable ? 1 : 0)),
|
|
|
|
|
updated = 100 - missing;
|
|
|
|
|
UpdatesChart.update({series: [updated, missing]});
|
2015-08-07 14:08:12 -07:00
|
|
|
if (resources.total) {
|
|
|
|
|
$('#updates [data-maintenance-update]').fadeIn();
|
|
|
|
|
}
|
2014-12-19 14:05:10 -08:00
|
|
|
}
|
2014-10-07 17:01:40 -07:00
|
|
|
|
2015-08-07 13:30:29 -07:00
|
|
|
if (!resources.total) {
|
|
|
|
|
$('#updates [data-maintenance-update]').fadeOut();
|
|
|
|
|
$('.badges.with-updates').removeClass('with-updates').find('.badge.updates').remove();
|
|
|
|
|
} else {
|
2015-04-13 21:37:12 +02:00
|
|
|
var length,
|
|
|
|
|
icon = '<i class="fa fa-bullhorn"></i>',
|
2015-08-24 18:49:27 +02:00
|
|
|
content = '{updates} ' + translations.PLUGIN_ADMIN.OF_YOUR + ' {type} ' + translations.PLUGIN_ADMIN.HAVE_AN_UPDATE_AVAILABLE,
|
|
|
|
|
button = '<a href="{location}/' + task + 'update" class="button button-small secondary">' + translations.PLUGIN_ADMIN.UPDATE + ' {Type}</a>',
|
2015-04-13 21:37:12 +02:00
|
|
|
plugins = $('.grav-update.plugins'),
|
|
|
|
|
themes = $('.grav-update.themes'),
|
|
|
|
|
sidebar = {plugins: $('#admin-menu a[href$="/plugins"]'), themes: $('#admin-menu a[href$="/themes"]')};
|
|
|
|
|
|
|
|
|
|
// sidebar
|
|
|
|
|
if (sidebar.plugins.length || sidebar.themes.length) {
|
|
|
|
|
var length, badges;
|
|
|
|
|
if (sidebar.plugins.length && (length = Object.keys(resources.plugins).length)) {
|
|
|
|
|
badges = sidebar.plugins.find('.badges');
|
|
|
|
|
badges.addClass('with-updates');
|
|
|
|
|
badges.find('.badge.updates').text(length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sidebar.themes.length && (length = Object.keys(resources.themes).length)) {
|
|
|
|
|
badges = sidebar.themes.find('.badges');
|
|
|
|
|
badges.addClass('with-updates');
|
|
|
|
|
badges.find('.badge.updates').text(length);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-07 17:01:40 -07:00
|
|
|
|
2015-04-13 21:37:12 +02:00
|
|
|
// list page
|
|
|
|
|
if (plugins[0] && (length = Object.keys(resources.plugins).length)) {
|
|
|
|
|
content = jQuery.substitute(content, {updates: length, type: 'plugins'});
|
|
|
|
|
button = jQuery.substitute(button, {Type: 'All Plugins', location: GravAdmin.config.base_url_relative + '/plugins'});
|
|
|
|
|
plugins.html('<p>' + icon + content + button + '</p>');
|
2014-10-07 17:01:40 -07:00
|
|
|
|
2015-04-13 21:37:12 +02:00
|
|
|
var plugin, url;
|
|
|
|
|
$.each(resources.plugins, function (key, value) {
|
|
|
|
|
plugin = $('[data-gpm-plugin="' + key + '"] .gpm-name');
|
|
|
|
|
url = plugin.find('a');
|
2015-08-07 14:08:12 -07:00
|
|
|
if (!plugin.find('.badge.update').length) {
|
2015-08-26 20:16:50 -04:00
|
|
|
plugin.append('<a class="plugin-update-button" href="' + url.attr('href') + '"><span class="badge update">' + translations.PLUGIN_ADMIN.UPDATE_AVAILABLE + '!</span></a>');
|
2015-08-07 14:08:12 -07:00
|
|
|
}
|
2014-10-07 17:01:40 -07:00
|
|
|
|
2015-04-13 21:37:12 +02:00
|
|
|
});
|
|
|
|
|
}
|
2014-10-07 17:01:40 -07:00
|
|
|
|
2015-04-13 21:37:12 +02:00
|
|
|
if (themes[0] && (length = Object.keys(resources.themes).length)) {
|
|
|
|
|
content = jQuery.substitute(content, {updates: length, type: 'themes'});
|
|
|
|
|
button = jQuery.substitute(button, {Type: 'All Themes', location: GravAdmin.config.base_url_relative + '/themes'});
|
|
|
|
|
themes.html('<p>' + icon + content + button + '</p>');
|
|
|
|
|
|
|
|
|
|
var theme, url;
|
|
|
|
|
$.each(resources.themes, function (key, value) {
|
|
|
|
|
theme = $('[data-gpm-theme="' + key + '"]');
|
|
|
|
|
url = theme.find('.gpm-name a');
|
2015-08-24 18:49:27 +02:00
|
|
|
theme.append('<div class="gpm-ribbon"><a href="' + url.attr('href') + '">' + translations.PLUGIN_ADMIN.UPDATE.toUpperCase() + '</a></div>');
|
2015-04-13 21:37:12 +02:00
|
|
|
});
|
|
|
|
|
}
|
2014-10-07 17:01:40 -07:00
|
|
|
|
2015-04-13 21:37:12 +02:00
|
|
|
// details page
|
|
|
|
|
var type = 'plugin',
|
|
|
|
|
details = $('.grav-update.plugin')[0];
|
|
|
|
|
|
|
|
|
|
if (!details) {
|
|
|
|
|
details = $('.grav-update.theme')[0];
|
|
|
|
|
type = 'theme';
|
|
|
|
|
}
|
2014-10-07 17:01:40 -07:00
|
|
|
|
2015-04-13 21:37:12 +02:00
|
|
|
if (details){
|
|
|
|
|
var slug = $('[data-gpm-' + type + ']').data('gpm-' + type),
|
2015-07-28 11:51:50 -07:00
|
|
|
Type = type.charAt(0).toUpperCase() + type.substring(1),
|
|
|
|
|
resource = resources[type + 's'][slug];
|
|
|
|
|
|
|
|
|
|
if (resource) {
|
2015-08-24 18:49:27 +02:00
|
|
|
content = '<strong>v{available}</strong> ' + translations.PLUGIN_ADMIN.OF_THIS + ' ' + type + ' ' + translations.PLUGIN_ADMIN.IS_NOW_AVAILABLE + '!';
|
2015-07-28 11:51:50 -07:00
|
|
|
content = jQuery.substitute(content, { available: resource.available });
|
|
|
|
|
button = jQuery.substitute(button, {
|
|
|
|
|
Type: Type,
|
|
|
|
|
location: GravAdmin.config.base_url_relative + '/' + type + 's/' + slug
|
|
|
|
|
});
|
|
|
|
|
$(details).html('<p>' + icon + content + button + '</p>');
|
|
|
|
|
}
|
2015-04-13 21:37:12 +02:00
|
|
|
}
|
2015-04-04 22:34:34 +02:00
|
|
|
}
|
2015-08-07 14:08:12 -07:00
|
|
|
|
2015-08-12 12:45:12 -07:00
|
|
|
if (options.callback && typeof options.callback == 'function') options.callback(response);
|
2014-10-07 17:01:40 -07:00
|
|
|
}
|
2015-04-13 21:37:12 +02:00
|
|
|
});
|
|
|
|
|
};
|
2015-08-07 14:08:12 -07:00
|
|
|
|
2015-09-09 17:33:19 +02:00
|
|
|
if (GravAdmin.config.enable_auto_updates_check === '1') {
|
|
|
|
|
GPMRefresh();
|
|
|
|
|
}
|
2015-05-20 17:17:41 +02:00
|
|
|
|
|
|
|
|
function reIndex (collection) {
|
|
|
|
|
var holder = collection.find('[data-collection-holder]'),
|
|
|
|
|
addBtn = collection.find('[data-action="add"]'),
|
|
|
|
|
prefix = holder.data('collection-holder'),
|
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
|
|
holder.find('[data-collection-item]').each(function () {
|
|
|
|
|
var item = $(this),
|
|
|
|
|
currentIndex = item.attr('data-collection-key');
|
|
|
|
|
|
|
|
|
|
if (index != currentIndex) {
|
|
|
|
|
var r = new RegExp('^' + prefix.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + '[\.\[]' + currentIndex);
|
|
|
|
|
|
|
|
|
|
item.attr('data-collection-item', item.attr('data-collection-item').replace(r, prefix + '.' + index));
|
|
|
|
|
item.attr('data-collection-key', index);
|
|
|
|
|
item.find('[name]').each(function () {
|
|
|
|
|
$(this).attr('name', $(this).attr('name').replace(r, prefix + '[' + index));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addBtn.data('key-index', index);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-06 12:48:42 -07:00
|
|
|
// Collections
|
2015-05-20 17:17:41 +02:00
|
|
|
$('[data-type="collection"]').each(function () {
|
|
|
|
|
var el = $(this),
|
|
|
|
|
holder = el.find('[data-collection-holder]'),
|
|
|
|
|
config = el.find('[data-collection-config]'),
|
|
|
|
|
isArray = config.data('collection-array'),
|
|
|
|
|
template = el.find('[data-collection-template="new"]').html();
|
|
|
|
|
|
|
|
|
|
// make sortable
|
2015-09-07 13:07:33 -07:00
|
|
|
new Sortable(holder[0], {
|
|
|
|
|
filter: '.form-input-wrapper',
|
|
|
|
|
onUpdate: function () {
|
|
|
|
|
if (isArray)
|
|
|
|
|
reIndex(el);
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-05-20 17:17:41 +02:00
|
|
|
|
|
|
|
|
// hook up delete
|
|
|
|
|
el.on('click', '[data-action="delete"]', function (e) {
|
|
|
|
|
$(this).closest('[data-collection-item]').remove();
|
|
|
|
|
if (isArray)
|
|
|
|
|
reIndex(el);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// hook up add
|
|
|
|
|
el.find('[data-action="add"]').on('click', function (e) {
|
|
|
|
|
var button = $(this),
|
|
|
|
|
key = button.data('key-index'),
|
|
|
|
|
newItem = $(template);
|
|
|
|
|
|
|
|
|
|
newItem.attr('data-collection-item', newItem.attr('data-collection-item').replace('*', key));
|
|
|
|
|
newItem.attr('data-collection-key', key);
|
|
|
|
|
newItem.find('[name]').each(function () {
|
|
|
|
|
$(this).attr('name', $(this).attr('name').replace('*', key));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
holder.append(newItem);
|
|
|
|
|
button.data('key-index', ++key);
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-08-04 19:28:42 +02:00
|
|
|
|
|
|
|
|
// enable the toggleable checkbox when typing in the corresponding textarea/input element
|
2015-08-07 18:25:04 +02:00
|
|
|
jQuery(document).on('input propertychange click', '.form-data textarea, .form-data input, .form-data label, .form-data .selectize-input', function() {
|
2015-08-04 19:28:42 +02:00
|
|
|
var item = this;
|
|
|
|
|
|
|
|
|
|
var checkbox = $(item).parents('.form-field').find('.toggleable input[type="checkbox"]');
|
|
|
|
|
|
|
|
|
|
if (checkbox.length > 0) {
|
|
|
|
|
checkbox.prop('checked', true);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-05 17:55:41 +02:00
|
|
|
$(this).css('opacity', 1);
|
|
|
|
|
$(this).parents('.form-data').css('opacity', 1);
|
|
|
|
|
checkbox.css('opacity', 1);
|
|
|
|
|
checkbox.prop('checked', true);
|
|
|
|
|
checkbox.prop('value', 1);
|
|
|
|
|
checkbox.siblings('label').css('opacity', 1);
|
2015-08-04 19:28:42 +02:00
|
|
|
checkbox.parent().siblings('label').css('opacity', 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// when clicking the label, click the corresponding checkbox automatically
|
|
|
|
|
jQuery(document).on('click', 'label.toggleable', function() {
|
|
|
|
|
var input = $(this).siblings('.checkboxes.toggleable').find('input');
|
|
|
|
|
var on = !input.is(':checked');
|
|
|
|
|
|
|
|
|
|
input.prop('checked', on);
|
|
|
|
|
input.prop('value', on ? 1 : 0);
|
|
|
|
|
$(this).css('opacity', on ? 1 : 0.7);
|
2015-08-17 20:41:09 +02:00
|
|
|
input.siblings('label').css('opacity', on ? 1 : 0.7);
|
|
|
|
|
$(this).parents('.form-label').siblings('.form-data').css('opacity', on ? 1 : 0.7);
|
|
|
|
|
|
2015-08-04 19:28:42 +02:00
|
|
|
});
|
|
|
|
|
|
2015-08-11 10:48:33 +02:00
|
|
|
// Themes Switcher Warning
|
2015-08-06 12:48:42 -07:00
|
|
|
$(document).on('mousedown', '[data-remodal-target="theme-switch-warn"]', function(e){
|
|
|
|
|
var name = $(e.target).closest('[data-gpm-theme]').find('.gpm-name a').text(),
|
|
|
|
|
remodal = $('.remodal.theme-switcher');
|
|
|
|
|
|
|
|
|
|
remodal.find('strong').text(name);
|
|
|
|
|
remodal.find('.button.continue').attr('href', $(e.target).attr('href'));
|
|
|
|
|
});
|
2015-09-14 15:58:34 +02:00
|
|
|
|
|
|
|
|
// Keep-alive
|
|
|
|
|
setInterval(function() {
|
|
|
|
|
keepAlive();
|
2015-09-14 16:25:03 +02:00
|
|
|
}, (GravAdmin.config.admin_timeout/2)*1000); //Call keepAlive() 60s before the admin session timeouts
|
2015-09-14 15:58:34 +02:00
|
|
|
|
2014-09-18 17:58:47 -06:00
|
|
|
});
|