mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 03:44:29 +03:00
Minor update to notification frontend api
- motivation was an error message on the settings screen - now requires slightly less code to add a notification
This commit is contained in:
parent
4bc3af4039
commit
559edb10a6
@ -22,6 +22,11 @@
|
||||
|
||||
Ghost.init = function () {
|
||||
Ghost.router = new Ghost.Router();
|
||||
|
||||
// This is needed so Backbone recognizes elements already rendered server side
|
||||
// as valid views, and events are bound
|
||||
Ghost.notifications = new Ghost.Views.NotificationCollection({model: []});
|
||||
|
||||
Backbone.history.start({
|
||||
pushState: true,
|
||||
hashChange: false,
|
||||
|
@ -129,6 +129,10 @@
|
||||
var itemView = new Ghost.Views.Notification({ model: item });
|
||||
this.$el.html(itemView.render().el);
|
||||
},
|
||||
addItem: function (item) {
|
||||
this.model.push(item);
|
||||
this.renderItem(item);
|
||||
},
|
||||
removeItem: function (e) {
|
||||
e.preventDefault();
|
||||
var self = e.currentTarget;
|
||||
@ -162,11 +166,6 @@
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// This is needed so Backbone recognizes elements already rendered server side
|
||||
// as valid views, and events are bound
|
||||
window.notColl = new Ghost.Views.NotificationCollection();
|
||||
|
||||
/**
|
||||
* This is the view to generate the markup for the individual
|
||||
* modal. Will be included into #modals.
|
||||
|
@ -153,21 +153,17 @@
|
||||
self.model.destroy({
|
||||
wait: true
|
||||
}).then(function () {
|
||||
self.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'success',
|
||||
message: 'Your post: ' + title + ' has been deleted',
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'success',
|
||||
message: 'Your post: ' + title + ' has been deleted',
|
||||
status: 'passive'
|
||||
});
|
||||
}, function () {
|
||||
self.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'error',
|
||||
message: 'Your post: ' + title + ' has not been deleted.',
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'error',
|
||||
message: 'Your post: ' + title + ' has not been deleted.',
|
||||
status: 'passive'
|
||||
});
|
||||
});
|
||||
},
|
||||
text: "Yes"
|
||||
|
@ -102,21 +102,17 @@
|
||||
this.savePost({
|
||||
status: keys[newIndex]
|
||||
}).then(function () {
|
||||
this.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'success',
|
||||
message: 'Your post: ' + model.get('title') + ' has been ' + keys[newIndex],
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'success',
|
||||
message: 'Your post: ' + model.get('title') + ' has been ' + keys[newIndex],
|
||||
status: 'passive'
|
||||
});
|
||||
}, function () {
|
||||
this.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'error',
|
||||
message: 'Your post: ' + model.get('title') + ' has not been ' + keys[newIndex],
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'error',
|
||||
message: 'Your post: ' + model.get('title') + ' has not been ' + keys[newIndex],
|
||||
status: 'passive'
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@ -127,42 +123,34 @@
|
||||
self = this;
|
||||
|
||||
if (status === 'publish-on') {
|
||||
this.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'alert',
|
||||
message: 'Scheduled publishing not supported yet.',
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'alert',
|
||||
message: 'Scheduled publishing not supported yet.',
|
||||
status: 'passive'
|
||||
});
|
||||
}
|
||||
if (status === 'queue') {
|
||||
this.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'alert',
|
||||
message: 'Scheduled publishing not supported yet.',
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'alert',
|
||||
message: 'Scheduled publishing not supported yet.',
|
||||
status: 'passive'
|
||||
});
|
||||
}
|
||||
|
||||
this.savePost({
|
||||
status: status
|
||||
}).then(function () {
|
||||
self.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'success',
|
||||
message: 'Your post: ' + model.get('title') + ' has been ' + status,
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'success',
|
||||
message: 'Your post: ' + model.get('title') + ' has been ' + status,
|
||||
status: 'passive'
|
||||
});
|
||||
}, function () {
|
||||
self.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'error',
|
||||
message: 'Your post: ' + model.get('title') + ' has not been ' + status,
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'error',
|
||||
message: 'Your post: ' + model.get('title') + ' has not been ' + status,
|
||||
status: 'passive'
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@ -173,21 +161,17 @@
|
||||
var model = this.model,
|
||||
self = this;
|
||||
this.savePost().then(function () {
|
||||
self.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'success',
|
||||
message: 'Your post was saved as ' + model.get('status'),
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'success',
|
||||
message: 'Your post was saved as ' + model.get('status'),
|
||||
status: 'passive'
|
||||
});
|
||||
}, function () {
|
||||
self.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'error',
|
||||
message: model.validationError,
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'error',
|
||||
message: model.validationError,
|
||||
status: 'passive'
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -59,13 +59,11 @@
|
||||
window.location.href = msg.redirect;
|
||||
},
|
||||
error: function (obj, string, status) {
|
||||
self.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'error',
|
||||
message: 'Invalid username or password',
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'error',
|
||||
message: 'Invalid username or password',
|
||||
status: 'passive'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -97,15 +95,13 @@
|
||||
},
|
||||
error: function (obj, string, status) {
|
||||
var msgobj = $.parseJSON(obj.responseText);
|
||||
self.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'error',
|
||||
message: msgobj.message,
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'error',
|
||||
message: msgobj.message,
|
||||
status: 'passive'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}());
|
||||
}());
|
@ -95,23 +95,19 @@
|
||||
this.$el.addClass('active');
|
||||
},
|
||||
saveSuccess: function () {
|
||||
this.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'success',
|
||||
message: 'Saved',
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'success',
|
||||
message: 'Saved',
|
||||
status: 'passive'
|
||||
});
|
||||
|
||||
},
|
||||
saveError: function () {
|
||||
this.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'error',
|
||||
message: 'Something went wrong, not saved :(',
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
Ghost.notifications.addItem({
|
||||
type: 'error',
|
||||
message: 'Something went wrong, not saved :(',
|
||||
status: 'passive'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user