Commit 98920e7e by cahrens

Switch to new notification/Save/Cancel mechanism (attached to bottom of viewport).

parent 24781782
...@@ -10,14 +10,13 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({ ...@@ -10,14 +10,13 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
// Model class is CMS.Models.Settings.Advanced // Model class is CMS.Models.Settings.Advanced
events : { events : {
'click .delete-button' : "deleteEntry", 'click .delete-button' : "deleteEntry",
'click .save-button' : "saveView", // 'click .save-button' : "saveView", TODO: put back once Advanced is not in tab view
'click .cancel-button' : "revertView", // 'click .cancel-button' : "revertView", with current code, must attach listener in initialize method
'click .new-button' : "addEntry", 'click .new-button' : "addEntry",
// update model on changes // update model on changes
'change #course-advanced-policy-key' : "updateKey", 'change #course-advanced-policy-key' : "updateKey",
'keydown #course-advanced-policy-key' : "enableSaveCancelButtons" 'keydown #course-advanced-policy-key' : "showSaveCancelButtons"
// TODO enable/disable save based on validation (currently enabled whenever there are changes) // TODO enable/disable save based on validation (currently enabled whenever there are changes)
// TODO enable/disable new button?
}, },
initialize : function() { initialize : function() {
var self = this; var self = this;
...@@ -29,6 +28,8 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({ ...@@ -29,6 +28,8 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
self.render(); self.render();
} }
); );
$('.save-button').on('click', this, this.saveView);
$('.cancel-button').on('click', this, this.revertView);
this.model.on('error', this.handleValidationError, this); this.model.on('error', this.handleValidationError, this);
}, },
render: function() { render: function() {
...@@ -58,7 +59,7 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({ ...@@ -58,7 +59,7 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
CodeMirror.fromTextArea(textarea, { CodeMirror.fromTextArea(textarea, {
mode: "application/json", lineNumbers: false, lineWrapping: true, mode: "application/json", lineNumbers: false, lineWrapping: true,
onChange: function() { onChange: function() {
self.enableSaveCancelButtons(); self.showSaveCancelButtons();
}, },
onBlur: function (mirror) { onBlur: function (mirror) {
var key = $(mirror.getWrapperElement()).closest('.row').children('.key').attr('id'); var key = $(mirror.getWrapperElement()).closest('.row').children('.key').attr('id');
...@@ -78,31 +79,29 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({ ...@@ -78,31 +79,29 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
this.$el.find(".message-status.error").addClass("is-shown"); this.$el.find(".message-status.error").addClass("is-shown");
} }
else if (type === this.unsaved_changes) { else if (type === this.unsaved_changes) {
this.$el.find(".message-status.warning").addClass("is-shown"); $('.wrapper-notification').addClass('is-shown');
} }
else if (type === this.successful_changes) { else if (type === this.successful_changes) {
this.$el.find(".message-status.confirm").addClass("is-shown"); this.$el.find(".message-status.confirm").addClass("is-shown");
this.disableSaveCancelButtons(); this.hideSaveCancelButtons();
} }
} }
else { else {
// This is the case of the page first rendering. // This is the case of the page first rendering.
this.disableSaveCancelButtons(); this.hideSaveCancelButtons();
} }
}, },
enableSaveCancelButtons: function() { showSaveCancelButtons: function() {
if (!this.buttonsEnabled) { if (!this.buttonsVisible) {
this.$el.find(".save-button").removeClass('disabled'); $('.wrapper-notification').addClass('is-shown');
this.$el.find(".cancel-button").show(); this.buttonsVisible = true;
this.buttonsEnabled = true;
} }
}, },
disableSaveCancelButtons: function() { hideSaveCancelButtons: function() {
this.$el.find(".save-button").addClass('disabled'); $('.wrapper-notification').removeClass('is-shown');
this.$el.find(".cancel-button").hide(); this.buttonsVisible = false;
this.buttonsEnabled = false;
}, },
toggleNewButton: function (enable) { toggleNewButton: function (enable) {
...@@ -134,8 +133,8 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({ ...@@ -134,8 +133,8 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
// TODO one last verification scan: // TODO one last verification scan:
// call validateKey on each to ensure proper format // call validateKey on each to ensure proper format
// check for dupes // check for dupes
var self = this; var self = event.data;
this.model.save({}, self.model.save({},
{ {
success : function() { success : function() {
self.render(); self.render();
...@@ -145,10 +144,10 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({ ...@@ -145,10 +144,10 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
}); });
}, },
revertView : function(event) { revertView : function(event) {
this.model.deleteKeys = []; var self = event.data;
var self = this; self.model.deleteKeys = [];
this.model.clear({silent : true}); self.model.clear({silent : true});
this.model.fetch({ self.model.fetch({
success : function() { self.render(); }, success : function() { self.render(); },
error : CMS.ServerError error : CMS.ServerError
}); });
......
...@@ -28,12 +28,6 @@ from contentstore import utils ...@@ -28,12 +28,6 @@ from contentstore import utils
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function(){ $(document).ready(function(){
// to show/hide the alert, just toggle the "is-shown" class with JS - CSS handles the rest
$('.test-notification').click(function(e){
e.preventDefault();
$('.wrapper-notification').toggleClass('is-shown');
});
// proactively populate advanced b/c it has the filtered list and doesn't really follow the model pattern // proactively populate advanced b/c it has the filtered list and doesn't really follow the model pattern
var advancedModel = new CMS.Models.Settings.Advanced(${advanced_dict | n}, {parse:true}); var advancedModel = new CMS.Models.Settings.Advanced(${advanced_dict | n}, {parse:true});
advancedModel.blacklistKeys = ${advanced_blacklist | n}; advancedModel.blacklistKeys = ${advanced_blacklist | n};
...@@ -59,8 +53,7 @@ from contentstore import utils ...@@ -59,8 +53,7 @@ from contentstore import utils
<%block name="content"> <%block name="content">
<!-- --> <!-- -->
<div class="main-wrapper"> <div class="main-wrapper">
<div class="inner-wrapper"> <div class="inner-wrapper">
<a href="#" class="test-notification">Test Notification (for testing purposes)!</a>
<h1>Settings</h1> <h1>Settings</h1>
...@@ -753,10 +746,6 @@ from contentstore import utils ...@@ -753,10 +746,6 @@ from contentstore import utils
There was an error saving your information. Please see below. There was an error saving your information. Please see below.
</div> </div>
<div class="message message-status warning is-shown">
Your changes will not take effect until you press "Save" on the bottom of the page.
</div>
<section class="settings-advanced-policies"> <section class="settings-advanced-policies">
<header> <header>
<h3>Manual Policy Definition</h3> <h3>Manual Policy Definition</h3>
...@@ -774,8 +763,6 @@ from contentstore import utils ...@@ -774,8 +763,6 @@ from contentstore import utils
<!-- advanced policy actions --> <!-- advanced policy actions -->
<div class="actions actions-advanced-policies"> <div class="actions actions-advanced-policies">
<a href="#" class="save-button">Save</a>
<a href="#" class="cancel-button">Cancel</a>
<a href="#" class="new-button new-advanced-policy-item add-policy-data"> <a href="#" class="new-button new-advanced-policy-item add-policy-data">
<span class="plus-icon white"></span>New Manual Policy <span class="plus-icon white"></span>New Manual Policy
</a> </a>
...@@ -795,7 +782,7 @@ from contentstore import utils ...@@ -795,7 +782,7 @@ from contentstore import utils
<div class="notification warning"> <div class="notification warning">
<div class="copy"> <div class="copy">
<i class="ss-icon ss-symbolicons-block icon icon-warning">&#x26A0;</i> <i class="ss-icon ss-symbolicons-block icon icon-warning">&#x26A0;</i>
<p><strong>Note: </strong>Your changes will not take effect until you <strong>save your progress</strong>.</p> <p><strong>Note: </strong>Your changes will not take effect until you <strong>save your progress</strong>.</p>
</div> </div>
<div class="actions"> <div class="actions">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment