Error messages in the UI
This commit is contained in:
parent
87c935ac47
commit
6145a938e3
5 changed files with 51 additions and 11 deletions
|
@ -57,12 +57,20 @@ haste_document.prototype.save = function(data, callback) {
|
|||
_this.locked = true;
|
||||
_this.key = res.key;
|
||||
var high = hljs.highlightAuto(data);
|
||||
callback({
|
||||
callback(null, {
|
||||
value: high.value,
|
||||
key: res.key,
|
||||
language: high.language,
|
||||
lineCount: data.split("\n").length
|
||||
});
|
||||
},
|
||||
error: function(res) {
|
||||
try {
|
||||
callback($.parseJSON(res.responseText));
|
||||
}
|
||||
catch (e) {
|
||||
callback({message: 'Something went wrong!'});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -91,6 +99,15 @@ haste.prototype.setTitle = function(ext) {
|
|||
document.title = title;
|
||||
};
|
||||
|
||||
// Show a message box
|
||||
haste.prototype.showMessage = function(msg, cls) {
|
||||
var msgBox = $('<li class="'+(cls || 'info')+'">'+msg+'</li>');
|
||||
$('#messages').prepend(msgBox);
|
||||
setTimeout(function() {
|
||||
msgBox.slideUp('fast', function() { $(this).remove(); });
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
// Show the light key
|
||||
haste.prototype.lightKey = function() {
|
||||
this.configureKey(['new', 'save']);
|
||||
|
@ -209,8 +226,11 @@ haste.prototype.duplicateDocument = function() {
|
|||
// Lock the current document
|
||||
haste.prototype.lockDocument = function() {
|
||||
var _this = this;
|
||||
this.doc.save(this.$textarea.val(), function(ret) {
|
||||
if (ret) {
|
||||
this.doc.save(this.$textarea.val(), function(err, ret) {
|
||||
if (err) {
|
||||
_this.showMessage(err.message, 'error');
|
||||
}
|
||||
else if (ret) {
|
||||
_this.$code.html(ret.value);
|
||||
_this.setTitle(ret.key);
|
||||
var file = '/' + ret.key;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue