ENHANCEMENT Update URLSegment from Title (closes #6981)

This commit is contained in:
Ryan Wachtl 2012-05-12 23:55:26 -05:00
parent b77920e2fe
commit f56126470d
4 changed files with 88 additions and 21 deletions

View File

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

View File

@ -25,31 +25,92 @@
onmatch : function() { onmatch : function() {
var self = this; var self = this;
var URLSegment = $('.cms-edit-form input[name=URLSegment]'); var form = self.parents('form');
var LiveURLSegment = $('.cms-edit-form input[name=LiveURLSegment]'); var url_segment = $('.field.urlsegment', form).find(':text');
var live_url_segment = $('input[name=LiveURLSegment]', form);
self._addActions();
this.bind('change', function(e) { this.bind('change', function(e) {
var title = self.val();
// Criteria for defining a "new" page // Criteria for defining a "new" page
if ( (URLSegment.val().indexOf("new") == 0) && LiveURLSegment.val() == "" ) { if ( (url_segment.val().indexOf("new") == 0) && live_url_segment.val() == "" ) {
self.updatePageTitleHeading(); self.updateRelatedFields(title);
self.parents('form').find('input[name=MetaTitle], input[name=MenuTitle]').val(self.val()); self.updateURLSegment(title);
// update the URLSegment
URLSegment.closest('.field.urlsegment').update(self);
} else { } else {
return; $('.update', self.parent()).show();
} }
self.updatePanelLabels(title);
}); });
this._super(); this._super();
}, },
/** /**
* Function: updatePageTitleHeading * Function: updateRelatedFields
* *
* Update the page title heading when page title changes * Update the related fields
* (String) title
*/ */
updatePageTitleHeading: function() { updateRelatedFields: function(title) {
$('#page-title-heading').text(this.val()); 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() * Return URLSegemnt val()
* *
* Parameters: * Parameters:
* (DOMElement) other (optional) * (Bool) auto (optional, triggers a second toggle)
*/ */
edit: function(other) { edit: function(auto) {
var field = this.find(':text'), var field = this.find(':text'),
holder = this.find('.preview'), holder = this.find('.preview'),
@ -59,7 +59,7 @@
// field updated from another fields value // field updated from another fields value
// reset to original state // reset to original state
if (other) this.edit(); if (auto) this.edit();
return field.val(); return field.val();
}, },
@ -68,8 +68,8 @@
* Function: update * Function: update
* *
* Commits the change of the URLSegment to the field * Commits the change of the URLSegment to the field
* Optional: pass in another element to use its value * Optional: pass in (String)
* to update the URLSegment (ex. from Title) * to update the URLSegment
*/ */
update: function() { update: function() {
@ -78,10 +78,10 @@
holder = this.find('.preview'), holder = this.find('.preview'),
currentVal = holder.text(), currentVal = holder.text(),
updateVal, updateVal,
other = arguments[0]; title = arguments[0];
if (other && other.val() !== "") { if (title && title !== "") {
updateVal = other.val(); updateVal = title;
} else { } else {
updateVal = field.val(); updateVal = field.val();
} }
@ -90,7 +90,7 @@
self.suggest(updateVal, function(data) { self.suggest(updateVal, function(data) {
var newVal = decodeURIComponent(data.value); var newVal = decodeURIComponent(data.value);
field.val(newVal); field.val(newVal);
self.edit(other); self.edit(title);
}); });
} else { } else {
self.edit(); self.edit();

View File

@ -113,4 +113,8 @@
.cancel, .update, .edit { .cancel, .update, .edit {
margin-left: 7px; margin-left: 7px;
} }
}
#Form_EditForm #Title .update {
margin-left: 7px;
} }