mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
Edit Post Permissions
This commit is contained in:
parent
b59575d26b
commit
59984c2df8
@ -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;
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -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'
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user