r47462 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47461‎ | r47462 | r47463 >
Date:19:35, 18 February 2009
Author:tparscal
Status:deferred
Tags:
Comment:
Initial import.
Modified paths:
  • /civicrm/utilities/scripts/ceanup.user.js (added) (history)

Diff [purge]

Index: civicrm/utilities/scripts/ceanup.user.js
@@ -0,0 +1,106 @@
 2+/* Configuration */
 3+
 4+// Creates list of fields to process
 5+var fields = {
 6+ titleCase : [
 7+ 'first_name',
 8+ 'middle_name',
 9+ 'last_name',
 10+ 'job_title',
 11+ 'current_employer',
 12+ 'location_1_address_city',
 13+ 'location_1_address_street_address',
 14+ 'location_1_address_supplemental_address_1',
 15+ 'location_1_address_supplemental_address_2',
 16+ ],
 17+ lowerCase : [
 18+ 'location_1_email_1_email'
 19+ ],
 20+ upperCase : []
 21+};
 22+
 23+/* Functions */
 24+
 25+// Function to convert string to title case
 26+function toTitleCase( string ) {
 27+ // Creates lower case version
 28+ var lowerCase = String( string ).toLowerCase();
 29+ // Creates upper case version
 30+ var upperCase = String( string ).toUpperCase();
 31+ // Creates empty var for title case version
 32+ var titleCase = '';
 33+ // Creates indicator that previous character was not a casable character
 34+ var previousCasable = false;
 35+ for( var i = 0; i < lowerCase.length; i++ ) {
 36+ // Gets lower case version of current character
 37+ var character = lowerCase.charAt( i );
 38+ // Checks if the previous character was NOT casable
 39+ if ( !previousCasable ) {
 40+ // Changes character to upper case version
 41+ character = upperCase.charAt( i );
 42+ }
 43+ // Append character to title case version
 44+ titleCase += character;
 45+ // Remember if current character is NOT casable for next loop
 46+ previousCasable = ( lowerCase.charAt( i ) != upperCase.charAt( i ) );
 47+ }
 48+ // Returns converted version
 49+ return titleCase;
 50+}
 51+// Add event handler to object
 52+function addHandler( element, attach, handler ) { + if( window.addEventListener ) { + element.addEventListener( attach, handler, false ); + } else if( window.attachEvent ) { + element.attachEvent( 'on' + attach, handler ); + } +}
 53+
 54+/* Run Operations */
 55+
 56+// Converts each title case field
 57+for ( var i = 0; i < fields['titleCase'].length; i++ ) {
 58+ var field = document.getElementById( fields['titleCase'][i] );
 59+ field.value = toTitleCase( field.value );
 60+}
 61+// Converts each lowercase feild
 62+for ( var i = 0; i < fields['lowerCase'].length; i++ ) {
 63+ var field = document.getElementById( fields['lowerCase'][i] );
 64+ field.value = String( field.value ).toLowerCase();
 65+}
 66+// Converts each uppercase feild
 67+for ( var i = 0; i < fields['upperCase'].length; i++ ) {
 68+ var field = document.getElementById( fields['upperCase'][i] );
 69+ field.value = String( field.value ).toUpperCase();
 70+}
 71+// Adds handler to prefix select box that updates gender ID
 72+addHandler(
 73+ document.getElementById( 'prefix_id' ),
 74+ 'change',
 75+ function() {
 76+ var editForm = document.getElementById( 'Edit' );
 77+ var genderFieldNames = [ 'none', 'female', 'male', 'trans' ];
 78+ var genderFields = {};
 79+ for ( var i = 0; i < editForm.elements.length; i++ ) {
 80+ if ( editForm.elements[i].name == 'gender_id' ) {
 81+ genderFields[genderFieldNames[editForm.elements[i].value]] =
 82+ editForm.elements[i];
 83+ }
 84+ }
 85+ switch ( this.options[this.selectedIndex].value ) {
 86+ case '1':
 87+ case '2':
 88+ genderFields.female.checked = true;
 89+ break;
 90+ case '3':
 91+ genderFields.male.checked = true;
 92+ break;
 93+ }
 94+ }
 95+);
 96+// Hides the Tags and Groups show button
 97+groupShowDiv = document.getElementById( 'group_show' );
 98+groupShowDiv.style.display = 'none';
 99+// Shows the Tags and Groups box
 100+groupDiv = document.getElementById( 'group' );
 101+groupDiv.style.display = 'block';

Status & tagging log