From 42a5de8536377864e814503f88cde2b67e4fa24d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 21 Nov 2009 03:14:30 +0000 Subject: [PATCH] MINOR Removed unused _AJAX_LOADING global from LeftAndMain.js javascript git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92695 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- javascript/CMSMain.js | 88 ++++++++++++++++++++++++++++++++++ javascript/LeftAndMain.js | 3 -- javascript/LeftAndMain_left.js | 3 -- 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/javascript/CMSMain.js b/javascript/CMSMain.js index bd03fc73..1f5811e2 100644 --- a/javascript/CMSMain.js +++ b/javascript/CMSMain.js @@ -138,6 +138,94 @@ var ss_MainLayout; }; }); + /** + * @class Input validation on the URLSegment field + * @name ss.EditForm.URLSegment + */ + $('#Form_EditForm input[name=URLSegment]').concrete('ss', function($){ + return/** @lends ss.EditForm.URLSegment */{ + + FilterRegex: /[^A-Za-z0-9-]+/, + + ValidationMessage: 'URLs can only be made up of letters, digits and hyphens.', + + MaxLength: 50, + + onmatch : function() { + var self = this; + + // intercept change event, do our own writing + this.bind('change', function(e) { + if(!self.validate()) { + jQuery.noticeAdd(self.ValidationMessage()); + } + self.val(self.suggestValue(e.target.value)); + return false; + }); + }, + + /** + * Return a value matching the criteria. + * + * @param {String} val + * @return val + */ + suggestValue: function(val) { + // TODO Do we want to enforce lowercasing in URLs? + return val.substr(0, this.MaxLength()).replace(this.FilterRegex(), '').toLowerCase(); + }, + + validate: function() { + return ( + this.val().length > this.MaxLength() + || this.val().match(this.FilterRegex()) + ); + } + }; + }); + + /** + * @class Input validation on the Title field + * @name ss.EditForm.Title + */ + $('#Form_EditForm input[name=Title]').concrete('ss', function($){ + return/** @lends ss.EditForm.Title */{ + + onmatch : function() { + var self = this; + + this.bind('change', function(e) { + self.updateURLSegment(jQuery('#Form_EditForm input[name=URLSegment]')); + // TODO We should really user-confirm these changes + self.parents('form').find('input[name=MetaTitle], input[name=MenuTitle]').val(self.val()); + }); + }, + + updateURLSegment: function(field) { + if(!field || !field.length) return; + + // TODO language/logic coupling + var isNew = this.val().indexOf("new") == 0; + var suggestion = field.concrete('ss').suggestValue(this.val()); + var confirmMessage = ss.i18n.sprintf( + ss.i18n._t( + 'UPDATEURL.CONFIRM', + 'Would you like me to change the URL to:\n\n' + + '%s/\n\nClick Ok to change the URL, ' + + 'click Cancel to leave it as:\n\n%s' + ), + suggestion, + field.val() + ); + + // don't ask for replacement if record is considered 'new' as defined by its title + if(isNew || (suggestion != field.val() && confirm(confirmMessage))) { + field.val(suggestion); + } + } + }; + }); + /** * @class ParentID field combination - mostly toggling between * the two radiobuttons and setting the hidden "ParentID" field diff --git a/javascript/LeftAndMain.js b/javascript/LeftAndMain.js index b4841afd..f7644bb1 100644 --- a/javascript/LeftAndMain.js +++ b/javascript/LeftAndMain.js @@ -291,9 +291,6 @@ -var _AJAX_LOADING = false; - - // Event.observe(window, 'beforeunload', LeftAndMain_window_unload); /** diff --git a/javascript/LeftAndMain_left.js b/javascript/LeftAndMain_left.js index c215f963..1ea2e691 100755 --- a/javascript/LeftAndMain_left.js +++ b/javascript/LeftAndMain_left.js @@ -201,7 +201,6 @@ TreeNodeAPI.prototype = { selectTreeNode : function() { var url = jQuery(this).find('a').attr('href'); if(url && url != '#') { - _AJAX_LOADING = true; if($('sitetree').notify('SelectionChanged', this)) { this.getPageFromServer(); } @@ -225,8 +224,6 @@ TreeNodeAPI.prototype = { ); if(xmlhttp) this.addNodeClass('loading'); - - _AJAX_LOADING = false; }, ajaxExpansion : function() { this.addNodeClass('loading');