Better status messages for mascot importing.
This commit is contained in:
parent
eb1b6e39fc
commit
583f154d19
@ -13163,35 +13163,35 @@
|
|||||||
return reader.readAsText(file);
|
return reader.readAsText(file);
|
||||||
},
|
},
|
||||||
load: function(mascots, userMascots) {
|
load: function(mascots, userMascots) {
|
||||||
var len, mascot, message, name, _i, _len;
|
var ilen, imported, len, mascot, message, name, type, _i, _len, _ref;
|
||||||
len = Conf["Deleted Mascots"].length;
|
len = Conf["Deleted Mascots"].length;
|
||||||
|
imported = [];
|
||||||
if (name = mascots["Mascot"]) {
|
if (name = mascots["Mascot"]) {
|
||||||
MascotTools.parse(mascots, userMascots);
|
MascotTools.parse(mascots, userMascots, imported);
|
||||||
message = "" + name + " successfully imported!";
|
|
||||||
} else if (mascots.length) {
|
} else if (mascots.length) {
|
||||||
for (_i = 0, _len = mascots.length; _i < _len; _i++) {
|
for (_i = 0, _len = mascots.length; _i < _len; _i++) {
|
||||||
mascot = mascots[_i];
|
mascot = mascots[_i];
|
||||||
MascotTools.parse(mascot, userMascots);
|
MascotTools.parse(mascot, userMascots, imported);
|
||||||
}
|
}
|
||||||
message = "Mascots imported!";
|
|
||||||
} else {
|
} else {
|
||||||
return new Notice('warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5);
|
return new Notice('warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5);
|
||||||
}
|
}
|
||||||
|
_ref = name && (ilen = imported.length) ? ["" + name + " successfully imported!", 'info'] : ilen ? ["" + ilen + " mascots successfully imported!", 'info'] : ["Failed to import any mascots. ;__;", 'info'], message = _ref[0], type = _ref[1];
|
||||||
$.set('userMascots', userMascots);
|
$.set('userMascots', userMascots);
|
||||||
if (len !== Conf["Deleted Mascots"].length) {
|
if (len !== Conf["Deleted Mascots"].length) {
|
||||||
$.set('Deleted Mascots', Conf['Deleted Mascots']);
|
$.set('Deleted Mascots', Conf['Deleted Mascots']);
|
||||||
}
|
}
|
||||||
new Notice('info', message, 10);
|
new Notice(type, message, 10);
|
||||||
return Settings.openSection.call({
|
return Settings.openSection.call({
|
||||||
open: Settings.mascots,
|
open: Settings.mascots,
|
||||||
hyphenatedTitle: 'mascots'
|
hyphenatedTitle: 'mascots'
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
parse: function(mascot, userMascots) {
|
parse: function(mascot, userMascots, imported) {
|
||||||
var name;
|
var image, message, name;
|
||||||
if (!(name = mascot["Mascot"])) {
|
if (!(name = mascot["Mascot"] && (image = mascot.image))) {
|
||||||
new Notice('warning', "Failed to import a mascot. Mascot has no name.", 5);
|
message = "Failed to import a mascot. File file has no " + (name ? 'image' : image ? 'name' : 'name nor image') + ".";
|
||||||
return;
|
return new Notice('warning', message, 5);
|
||||||
}
|
}
|
||||||
delete mascot["Mascot"];
|
delete mascot["Mascot"];
|
||||||
if (Mascots[name] && !$.remove(Conf["Deleted Mascots"], name)) {
|
if (Mascots[name] && !$.remove(Conf["Deleted Mascots"], name)) {
|
||||||
@ -13199,7 +13199,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return userMascots[name] = Mascots[name] = mascot;
|
return imported.push(userMascots[name] = Mascots[name] = mascot);
|
||||||
},
|
},
|
||||||
position: function(mascot) {
|
position: function(mascot) {
|
||||||
if (!Style.sheets.mascots) {
|
if (!Style.sheets.mascots) {
|
||||||
|
|||||||
@ -13152,35 +13152,35 @@
|
|||||||
return reader.readAsText(file);
|
return reader.readAsText(file);
|
||||||
},
|
},
|
||||||
load: function(mascots, userMascots) {
|
load: function(mascots, userMascots) {
|
||||||
var len, mascot, message, name, _i, _len;
|
var ilen, imported, len, mascot, message, name, type, _i, _len, _ref;
|
||||||
len = Conf["Deleted Mascots"].length;
|
len = Conf["Deleted Mascots"].length;
|
||||||
|
imported = [];
|
||||||
if (name = mascots["Mascot"]) {
|
if (name = mascots["Mascot"]) {
|
||||||
MascotTools.parse(mascots, userMascots);
|
MascotTools.parse(mascots, userMascots, imported);
|
||||||
message = "" + name + " successfully imported!";
|
|
||||||
} else if (mascots.length) {
|
} else if (mascots.length) {
|
||||||
for (_i = 0, _len = mascots.length; _i < _len; _i++) {
|
for (_i = 0, _len = mascots.length; _i < _len; _i++) {
|
||||||
mascot = mascots[_i];
|
mascot = mascots[_i];
|
||||||
MascotTools.parse(mascot, userMascots);
|
MascotTools.parse(mascot, userMascots, imported);
|
||||||
}
|
}
|
||||||
message = "Mascots imported!";
|
|
||||||
} else {
|
} else {
|
||||||
return new Notice('warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5);
|
return new Notice('warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5);
|
||||||
}
|
}
|
||||||
|
_ref = name && (ilen = imported.length) ? ["" + name + " successfully imported!", 'info'] : ilen ? ["" + ilen + " mascots successfully imported!", 'info'] : ["Failed to import any mascots. ;__;", 'info'], message = _ref[0], type = _ref[1];
|
||||||
$.set('userMascots', userMascots);
|
$.set('userMascots', userMascots);
|
||||||
if (len !== Conf["Deleted Mascots"].length) {
|
if (len !== Conf["Deleted Mascots"].length) {
|
||||||
$.set('Deleted Mascots', Conf['Deleted Mascots']);
|
$.set('Deleted Mascots', Conf['Deleted Mascots']);
|
||||||
}
|
}
|
||||||
new Notice('info', message, 10);
|
new Notice(type, message, 10);
|
||||||
return Settings.openSection.call({
|
return Settings.openSection.call({
|
||||||
open: Settings.mascots,
|
open: Settings.mascots,
|
||||||
hyphenatedTitle: 'mascots'
|
hyphenatedTitle: 'mascots'
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
parse: function(mascot, userMascots) {
|
parse: function(mascot, userMascots, imported) {
|
||||||
var name;
|
var image, message, name;
|
||||||
if (!(name = mascot["Mascot"])) {
|
if (!(name = mascot["Mascot"] && (image = mascot.image))) {
|
||||||
new Notice('warning', "Failed to import a mascot. Mascot has no name.", 5);
|
message = "Failed to import a mascot. File file has no " + (name ? 'image' : image ? 'name' : 'name nor image') + ".";
|
||||||
return;
|
return new Notice('warning', message, 5);
|
||||||
}
|
}
|
||||||
delete mascot["Mascot"];
|
delete mascot["Mascot"];
|
||||||
if (Mascots[name] && !$.remove(Conf["Deleted Mascots"], name)) {
|
if (Mascots[name] && !$.remove(Conf["Deleted Mascots"], name)) {
|
||||||
@ -13188,7 +13188,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return userMascots[name] = Mascots[name] = mascot;
|
return imported.push(userMascots[name] = Mascots[name] = mascot);
|
||||||
},
|
},
|
||||||
position: function(mascot) {
|
position: function(mascot) {
|
||||||
if (!Style.sheets.mascots) {
|
if (!Style.sheets.mascots) {
|
||||||
|
|||||||
@ -352,35 +352,48 @@ MascotTools =
|
|||||||
|
|
||||||
load: (mascots, userMascots) ->
|
load: (mascots, userMascots) ->
|
||||||
len = Conf["Deleted Mascots"].length
|
len = Conf["Deleted Mascots"].length
|
||||||
|
imported = []
|
||||||
if name = mascots["Mascot"]
|
if name = mascots["Mascot"]
|
||||||
MascotTools.parse mascots, userMascots
|
MascotTools.parse mascots, userMascots, imported
|
||||||
message = "#{name} successfully imported!"
|
|
||||||
else if mascots.length
|
else if mascots.length
|
||||||
MascotTools.parse mascot, userMascots for mascot in mascots
|
MascotTools.parse mascot, userMascots, imported for mascot in mascots
|
||||||
message = "Mascots imported!"
|
|
||||||
else
|
else
|
||||||
return new Notice 'warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5
|
return new Notice 'warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5
|
||||||
|
|
||||||
|
[message, type] = if name and ilen = imported.length
|
||||||
|
["#{name} successfully imported!", 'info']
|
||||||
|
else if ilen
|
||||||
|
["#{ilen} mascots successfully imported!", 'info']
|
||||||
|
else
|
||||||
|
["Failed to import any mascots. ;__;", 'info']
|
||||||
|
|
||||||
$.set 'userMascots', userMascots
|
$.set 'userMascots', userMascots
|
||||||
$.set 'Deleted Mascots', Conf['Deleted Mascots'] unless len is Conf["Deleted Mascots"].length
|
$.set 'Deleted Mascots', Conf['Deleted Mascots'] unless len is Conf["Deleted Mascots"].length
|
||||||
|
|
||||||
new Notice 'info', message, 10
|
new Notice type, message, 10
|
||||||
|
|
||||||
Settings.openSection.call
|
Settings.openSection.call
|
||||||
open: Settings.mascots
|
open: Settings.mascots
|
||||||
hyphenatedTitle: 'mascots'
|
hyphenatedTitle: 'mascots'
|
||||||
|
|
||||||
parse: (mascot, userMascots) ->
|
parse: (mascot, userMascots, imported) ->
|
||||||
unless name = mascot["Mascot"]
|
unless name = mascot["Mascot"] and image = mascot.image
|
||||||
new Notice 'warning', "Failed to import a mascot. Mascot has no name.", 5
|
message = "Failed to import a mascot. File file has no #{if name
|
||||||
return
|
'image'
|
||||||
|
else if image
|
||||||
|
'name'
|
||||||
|
else
|
||||||
|
'name nor image'}."
|
||||||
|
|
||||||
|
return new Notice 'warning', message, 5
|
||||||
|
|
||||||
|
|
||||||
delete mascot["Mascot"]
|
delete mascot["Mascot"]
|
||||||
|
|
||||||
if Mascots[name] and not $.remove Conf["Deleted Mascots"], name
|
if Mascots[name] and not $.remove Conf["Deleted Mascots"], name
|
||||||
return unless confirm "The mascot #{name} already exists? Would you like to overwrite it?"
|
return unless confirm "The mascot #{name} already exists? Would you like to overwrite it?"
|
||||||
|
|
||||||
userMascots[name] = Mascots[name] = mascot
|
imported.push userMascots[name] = Mascots[name] = mascot
|
||||||
|
|
||||||
position: (mascot) ->
|
position: (mascot) ->
|
||||||
return unless Style.sheets.mascots
|
return unless Style.sheets.mascots
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user