Edit Post Permissions

This commit is contained in:
Jacob Gable 2013-08-15 18:22:08 -05:00
parent b59575d26b
commit 59984c2df8
2 changed files with 37 additions and 7 deletions

View File

@ -54,13 +54,14 @@
// by `addSubview`, which will in-turn remove any
// children of those views, and so on.
removeSubviews: function () {
var i, l, children = this.subviews;
var children = this.subviews;
if (!children) {
return this;
}
for (i = 0, l = children.length; i < l; i += 1) {
children[i].remove();
}
_(children).invoke("remove");
this.subviews = [];
return this;
},
@ -72,6 +73,32 @@
this.removeSubviews();
}
return Backbone.View.prototype.remove.apply(this, arguments);
},
// Used in API request fail handlers to parse a standard api error
// response json for the message to display
getRequestErrorMessage: function (request) {
var message;
// Can't really continue without a request
if (!request) {
return null;
}
// Seems like a sensible default
message = request.statusText;
// If a non 200 response
if (request.status !== 200) {
try {
// Try to parse out the error, or default to "Unknown"
message = request.responseJSON.error || "Unknown Error";
} catch (e) {
message = "The server returned an error (" + (request.status || "?") + ").";
}
}
return message;
}
});

View File

@ -157,17 +157,20 @@
if (e) {
e.preventDefault();
}
var model = this.model;
var view = this,
model = this.model;
this.savePost().then(function () {
Ghost.notifications.addItem({
type: 'success',
message: 'Your post was saved as ' + model.get('status'),
status: 'passive'
});
}, function () {
}, function (request) {
var message = view.getRequestErrorMessage(request) || model.validationError;
Ghost.notifications.addItem({
type: 'error',
message: model.validationError,
message: message,
status: 'passive'
});
});