Factor showNotificationBar out into ValidatingView.

When all settings require an explicit save, this functionality will be
shared between each view (with slight changes, e.g. click handlers.)
This commit is contained in:
Peter Fogg
2013-06-24 13:07:09 -04:00
parent 4b59a85dae
commit 164a469e9d
2 changed files with 42 additions and 34 deletions

View File

@@ -57,8 +57,14 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
mode: "application/json", lineNumbers: false, lineWrapping: false,
onChange: function(instance, changeobj) {
// this event's being called even when there's no change :-(
if (instance.getValue() !== oldValue && !self.notificationBarShowing) {
self.showNotificationBar();
if (instance.getValue() !== oldValue) {
var message = gettext("Your changes will not take effect until you save your progress. Take care with key and value formatting, as validation is not implemented.");
self.showNotificationBar(message,
_.bind(self.saveView, self),
_.bind(self.revertView, self));
if(self.saved) {
self.saved.hide();
}
}
},
onFocus : function(mirror) {
@@ -97,38 +103,6 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
}
});
},
showNotificationBar: function() {
var self = this;
var message = gettext("Your changes will not take effect until you save your progress. Take care with key and value formatting, as validation is not implemented.")
var confirm = new CMS.Views.Notification.Warning({
title: gettext("You've Made Some Changes"),
message: message,
actions: {
primary: {
"text": gettext("Save Changes"),
"class": "action-save",
"click": function() {
self.saveView();
confirm.hide();
self.notificationBarShowing = false;
}
},
secondary: [{
"text": gettext("Cancel"),
"class": "action-cancel",
"click": function() {
self.revertView();
confirm.hide();
self.notificationBarShowing = false;
}
}]
}});
this.notificationBarShowing = true;
confirm.show();
if(this.saved) {
this.saved.hide();
}
},
saveView : function() {
// TODO one last verification scan:
// call validateKey on each to ensure proper format

View File

@@ -67,5 +67,39 @@ CMS.Views.ValidatingView = Backbone.View.extend({
// put error on the contained inputs
return $(ele).find(inputElements);
}
},
showNotificationBar: function(message, primaryClick, secondaryClick) {
if(this.notificationBarShowing) {
return;
}
var self = this;
this.confirmation = new CMS.Views.Notification.Warning({
title: gettext("You've made some changes"),
message: message,
actions: {
primary: {
"text": gettext("Save Changes"),
"class": "action-save",
"click": function() {
primaryClick();
self.confirmation.hide();
self.notificationBarShowing = false;
}
},
secondary: [{
"text": gettext("Cancel"),
"class": "action-cancel",
"click": function() {
if(secondaryClick) {
secondaryClick();
}
self.confirmation.hide();
self.notificationBarShowing = false;
}
}]
}});
this.notificationBarShowing = true;
this.confirmation.show();
}
});