From f56126470d0e7b301f97b860347abef885c0e392 Mon Sep 17 00:00:00 2001 From: Ryan Wachtl Date: Sat, 12 May 2012 23:55:26 -0500 Subject: [PATCH] ENHANCEMENT Update URLSegment from Title (closes #6981) --- css/screen.css | 2 + javascript/CMSMain.EditForm.js | 85 +++++++++++++++++++++++---- javascript/SiteTreeURLSegmentField.js | 18 +++--- scss/_CMSMain.scss | 4 ++ 4 files changed, 88 insertions(+), 21 deletions(-) diff --git a/css/screen.css b/css/screen.css index 2f3b2473..c594834a 100644 --- a/css/screen.css +++ b/css/screen.css @@ -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; } diff --git a/javascript/CMSMain.EditForm.js b/javascript/CMSMain.EditForm.js index 8868ef12..fef61b79 100644 --- a/javascript/CMSMain.EditForm.js +++ b/javascript/CMSMain.EditForm.js @@ -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 = $('