Ability to remove saves

This commit is contained in:
Victor 2015-12-11 23:20:57 +02:00
parent d5ceb0afec
commit 539151e3ac

View File

@ -393,6 +393,9 @@ Views.prototype.showMainMenu = function () {
this.addMainMenuItem("Загрузить…", function() { this.addMainMenuItem("Загрузить…", function() {
views.showLoadStateMenu(); views.showLoadStateMenu();
}); });
this.addMainMenuItem("Удалить…", function() {
views.showRemoveStateMenu();
});
} }
this.addMainMenuItem("Закрыть", function() { this.addMainMenuItem("Закрыть", function() {
$('#menu').hide(); $('#menu').hide();
@ -609,3 +612,29 @@ Views.prototype.createLoadStateClickFunction = function (index, save) {
$('#menu').hide(); $('#menu').hide();
}; };
}; };
Views.prototype.showRemoveStateMenu = function () {
var saves = JSON.parse(localStorage.saves || null) || {};
var items = saves[rpyscript] || [];
$('#menuTitle').text('Удалить');
$('#menuChoose').empty();
this.addMainMenuItem("Закрыть", function() {
$('#menu').hide();
});
for(var i = items.length - 1; i >= 0; i--) {
var li = $('<li>', {text: items[i].time});
li.click(this.createRemoveStateClickFunction(i));
li.appendTo($('#menuChoose'));
}
$('#menu').show();
};
Views.prototype.createRemoveStateClickFunction = function (index) {
var views = this;
return function () {
var saves = JSON.parse(localStorage.saves || null) || {};
saves[rpyscript].splice(index, 1);
localStorage.saves = JSON.stringify(saves);
views.showRemoveStateMenu();
};
};