mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
Merge pull request #151 from sminnee/trac-7507
BUG: Update MenuTitle whenever Title is changed and the value of Title used to be. Bubble the change to update LHS tree. (Trac #7507)
This commit is contained in:
commit
3cb77d8853
@ -25,6 +25,8 @@
|
|||||||
onmatch : function() {
|
onmatch : function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
self.data('OrigVal', self.val());
|
||||||
|
|
||||||
var form = self.parents('form');
|
var form = self.parents('form');
|
||||||
var url_segment = $('.field.urlsegment', form).find(':text');
|
var url_segment = $('.field.urlsegment', form).find(':text');
|
||||||
var live_url_segment = $('input[name=LiveURLSegment]', form);
|
var live_url_segment = $('input[name=LiveURLSegment]', form);
|
||||||
@ -33,14 +35,18 @@
|
|||||||
|
|
||||||
if(url_segment.length > 0) {
|
if(url_segment.length > 0) {
|
||||||
this.bind('change', function(e) {
|
this.bind('change', function(e) {
|
||||||
|
var origTitle = self.data('OrigVal');
|
||||||
var title = self.val();
|
var title = self.val();
|
||||||
|
self.data('OrigVal', title);
|
||||||
|
|
||||||
// Criteria for defining a "new" page
|
// Criteria for defining a "new" page
|
||||||
if ((url_segment.val().indexOf('new') == 0) && live_url_segment.val() == '') {
|
if ((url_segment.val().indexOf('new') == 0) && live_url_segment.val() == '') {
|
||||||
self.updateRelatedFields(title);
|
|
||||||
self.updateURLSegment(title);
|
self.updateURLSegment(title);
|
||||||
} else {
|
} else {
|
||||||
$('.update', self.parent()).show();
|
$('.update', self.parent()).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.updateRelatedFields(title, origTitle);
|
||||||
self.updateBreadcrumbLabel(title);
|
self.updateBreadcrumbLabel(title);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -54,12 +60,20 @@
|
|||||||
/**
|
/**
|
||||||
* Function: updateRelatedFields
|
* Function: updateRelatedFields
|
||||||
*
|
*
|
||||||
* Update the related fields
|
* Update the related fields if appropriate
|
||||||
* (String) title
|
* (String) title The new title
|
||||||
|
* (Stirng) origTitle The original title
|
||||||
*/
|
*/
|
||||||
updateRelatedFields: function(title) {
|
updateRelatedFields: function(title, origTitle) {
|
||||||
var form = this.parents('form');
|
// Update these fields only if their value was originally the same as the title
|
||||||
form.find('input[name=MetaTitle], input[name=MenuTitle]').val(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({
|
$('.cms-edit-form input[name=MenuTitle]').entwine({
|
||||||
onchange: function() {
|
onchange: function() {
|
||||||
|
this.updatedRelatedFields();
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as the onchange handler but callable as a method
|
||||||
|
*/
|
||||||
|
updatedRelatedFields: function() {
|
||||||
var menuTitle = this.val();
|
var menuTitle = this.val();
|
||||||
this.updateTreeLabel(menuTitle);
|
this.updateTreeLabel(menuTitle);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user