Merge pull request #128 from ryanwachtl/silverstripe-cms

---

When page Title field is changed, adds an "Update URL" button. Also updates the panel breadcrumb and tree after the Title field changes.
This commit is contained in:
Ingo Schommer 2012-05-14 14:27:51 +02:00
commit c3735ec666
4 changed files with 88 additions and 21 deletions

View File

@ -26,6 +26,8 @@
.field.urlsegment .prefix { color: #777; }
.field.urlsegment .cancel, .field.urlsegment .update, .field.urlsegment .edit { margin-left: 7px; }
#Form_EditForm #Title .update { margin-left: 7px; }
.cms .AssetAdmin .cms-content-fields { overflow: hidden; }
.cms .AssetAdmin .cms-content-fields .cms-edit-form.AssetAdmin { overflow-y: auto; }
.cms .AssetAdmin .cms-content-fields .cms-content-tools .cms-panel-content { overflow: hidden; }

View File

@ -25,31 +25,92 @@
onmatch : function() {
var self = this;
var URLSegment = $('.cms-edit-form input[name=URLSegment]');
var LiveURLSegment = $('.cms-edit-form input[name=LiveURLSegment]');
var form = self.parents('form');
var url_segment = $('.field.urlsegment', form).find(':text');
var live_url_segment = $('input[name=LiveURLSegment]', form);
self._addActions();
this.bind('change', function(e) {
var title = self.val();
// Criteria for defining a "new" page
if ( (URLSegment.val().indexOf("new") == 0) && LiveURLSegment.val() == "" ) {
self.updatePageTitleHeading();
self.parents('form').find('input[name=MetaTitle], input[name=MenuTitle]').val(self.val());
// update the URLSegment
URLSegment.closest('.field.urlsegment').update(self);
if ( (url_segment.val().indexOf("new") == 0) && live_url_segment.val() == "" ) {
self.updateRelatedFields(title);
self.updateURLSegment(title);
} else {
return;
$('.update', self.parent()).show();
}
self.updatePanelLabels(title);
});
this._super();
},
/**
* Function: updatePageTitleHeading
* Function: updateRelatedFields
*
* Update the page title heading when page title changes
* Update the related fields
* (String) title
*/
updatePageTitleHeading: function() {
$('#page-title-heading').text(this.val());
updateRelatedFields: function(title) {
var form = this.parents('form');
form.find('input[name=MetaTitle], input[name=MenuTitle]').val(title);
},
/**
* Function: updateURLSegment
*
* Update the URLSegment
* (String) title
*/
updateURLSegment: function(title) {
var url_segment_field = $('.field.urlsegment', this.parents('form'));
var updateURLFromTitle = $('.update', this.parent());
url_segment_field.update(title);
if (updateURLFromTitle.is(':visible')) {
updateURLFromTitle.hide();
}
},
/**
* Function: updatePanelLabels
*
* Update the breadcrumb and tree
* (String) title
*/
updatePanelLabels: function(title) {
var pageID = $('.cms-edit-form input[name=ID]').val();
var panelCrumb = $('span.cms-panel-link.crumb');
var treeItem = $('.item', $('.cms-tree').find("[data-id='" + pageID + "']"));
if (title && title != "") {
panelCrumb.text(title);
treeItem.text(title);
}
},
/**
* Function: _addActions
*
* Utility to add update from title action
*
*/
_addActions: function() {
var self = this;
var updateURLFromTitle;
// update button
updateURLFromTitle = $('<button />', {
'class': 'update ss-ui-button-small',
'text': 'Update URL',
'click': function(e) {
e.preventDefault();
self.updateURLSegment(self.val());
}
});
// insert elements
updateURLFromTitle.insertAfter(self);
updateURLFromTitle.hide();
}
});

View File

@ -26,9 +26,9 @@
* Return URLSegemnt val()
*
* Parameters:
* (DOMElement) other (optional)
* (Bool) auto (optional, triggers a second toggle)
*/
edit: function(other) {
edit: function(auto) {
var field = this.find(':text'),
holder = this.find('.preview'),
@ -59,7 +59,7 @@
// field updated from another fields value
// reset to original state
if (other) this.edit();
if (auto) this.edit();
return field.val();
},
@ -68,8 +68,8 @@
* Function: update
*
* Commits the change of the URLSegment to the field
* Optional: pass in another element to use its value
* to update the URLSegment (ex. from Title)
* Optional: pass in (String)
* to update the URLSegment
*/
update: function() {
@ -78,10 +78,10 @@
holder = this.find('.preview'),
currentVal = holder.text(),
updateVal,
other = arguments[0];
title = arguments[0];
if (other && other.val() !== "") {
updateVal = other.val();
if (title && title !== "") {
updateVal = title;
} else {
updateVal = field.val();
}
@ -90,7 +90,7 @@
self.suggest(updateVal, function(data) {
var newVal = decodeURIComponent(data.value);
field.val(newVal);
self.edit(other);
self.edit(title);
});
} else {
self.edit();

View File

@ -114,3 +114,7 @@
margin-left: 7px;
}
}
#Form_EditForm #Title .update {
margin-left: 7px;
}