Permalink
Browse files

BUG: Update MenuTitle whenever Title is changed and the value of Titl…

…e used to be. Bubble the change to update LHS tree. (Trac #7507)

We had to use .data() to track OrigVal manually, but this means that the MenuTitle can be updated much more reliably.  In addition, we trigger the change-handler for MenuTitle that updates the LHS tree.  Unfortunately, we couldn't simply use .trigger('change') because it broken in IE8 due to an entwine bug.
  • Loading branch information...
1 parent 211ce61 commit 6be86022955cf37d09014648e800ce37c7faabda @sminnee sminnee committed Jun 22, 2012
Showing with 27 additions and 6 deletions.
  1. +27 −6 javascript/CMSMain.EditForm.js
@@ -24,6 +24,8 @@
// Constructor: onmatch
onmatch : function() {
var self = this;
+
+ self.data('OrigVal', self.val());
var form = self.parents('form');
var url_segment = $('.field.urlsegment', form).find(':text');
@@ -33,14 +35,18 @@
if(url_segment.length > 0) {
this.bind('change', function(e) {
+ var origTitle = self.data('OrigVal');
var title = self.val();
+ self.data('OrigVal', title);
+
// Criteria for defining a "new" page
if ((url_segment.val().indexOf('new') == 0) && live_url_segment.val() == '') {
- self.updateRelatedFields(title);
self.updateURLSegment(title);
} else {
$('.update', self.parent()).show();
}
+
+ self.updateRelatedFields(title, origTitle);
self.updateBreadcrumbLabel(title);
});
}
@@ -54,12 +60,20 @@
/**
* Function: updateRelatedFields
*
- * Update the related fields
- * (String) title
+ * Update the related fields if appropriate
+ * (String) title The new title
+ * (Stirng) origTitle The original title
*/
- updateRelatedFields: function(title) {
- var form = this.parents('form');
- form.find('input[name=MetaTitle], input[name=MenuTitle]').val(title);
+ updateRelatedFields: function(title, origTitle) {
+ // Update these fields only if their value was originally the same as the title
+ this.parents('form').find('input[name=MetaTitle], input[name=MenuTitle]').each(function() {
+ var $this = $(this);
+ if($this.val() == origTitle) {
+ $this.val(title);
+ // Onchange bubbling didn't work in IE8, so .trigger('change') couldn't be used
+ if($this.updatedRelatedFields) $this.updatedRelatedFields();
+ }
+ });
},
/**
@@ -122,6 +136,13 @@
*/
$('.cms-edit-form input[name=MenuTitle]').entwine({
onchange: function() {
+ this.updatedRelatedFields();
+ },
+
+ /**
+ * Same as the onchange handler but callable as a method
+ */
+ updatedRelatedFields: function() {
var menuTitle = this.val();
this.updateTreeLabel(menuTitle);
},

0 comments on commit 6be8602

Please sign in to comment.