Giving Calls and Meetings Full 60-Minute Options

sugarcrmdevelopers —  June 18, 2012

A frustrating facet for some SugarCRM users is the limitation of the Calls and Meetings modules to set the minutes-value of their date/time fields to a quarter-hour mark. Some would like a full set of minutes options (i.e. 00,01,02,03…57,58,59). Due to the complexity of date/time formatting, there isn’t a single drop-down that holds the values that these Datetimecombo fields, but the customization can be done. We’ll just need to customize the Datetimecombo field definitions.

Begin by copying these files:

  1. jssource/src_files/include/SugarFields/Fields/Datetimecombo/Datetimecombo.js to custom/include/SugarFields/Fields/Datetimecombo/Datetimecombo.js
  2. /include/SugarFields/Fields/Datetimecombo/EditView.tpl to /custom/include/SugarFields/Fields/Datetimecombo/EditView.tpl
  3. create an empty file at /custom/include/SugarFields/Fields/Datetimecombo/SugarFieldDatetimecombo.php

Modify the javascript file you copied first, look at functions in Datetimecombo.prototype.html and find the lines generating the minutes options. Transform this:

	text += 'n<option value="00" ' + (this.mins == 0 ? "SELECTED" : "") + '>00</option>';
	text += 'n<option value="15" ' + (this.mins == 15 ? "SELECTED" : "") + '>15</option>';
	text += 'n<option value="30" ' + (this.mins == 30 ? "SELECTED" : "") + '>30</option>';
	text += 'n<option value="45" ' + (this.mins == 45 ? "SELECTED" : "") + '>45</option>';
	text += 'n</select>';

to something like this…

	text += 'n<option value="00" ' + (this.mins == 0 ? "SELECTED" : "") + '>00</option>';
	text += 'n<option value="01" ' + (this.mins == 01 ? "SELECTED" : "") + '>01</option>';
	text += 'n<option value="02" ' + (this.mins == 02 ? "SELECTED" : "") + '>02</option>';
	text += 'n<option value="03" ' + (this.mins == 03 ? "SELECTED" : "") + '>03</option>';
	text += 'n<option value="04" ' + (this.mins == 04 ? "SELECTED" : "") + '>04</option>';
	text += 'n<option value="05" ' + (this.mins == 05 ? "SELECTED" : "") + '>05</option>';
	text += 'n<option value="06" ' + (this.mins == 06 ? "SELECTED" : "") + '>06</option>';
	text += 'n<option value="07" ' + (this.mins == 07 ? "SELECTED" : "") + '>07</option>';
	text += 'n<option value="08" ' + (this.mins == 08 ? "SELECTED" : "") + '>08</option>';
...
	text += 'n<option value="59" ' + (this.mins == 59 ? "SELECTED" : "") + '>59</option>';
	text += 'n</select>';

Now scroll up in the same file and look for the function Datetimecombo. This function contains a code block that rounds the value of the minutes field to one of a quarter-marker in the hour. Just comment this section out:

    //A safety scan to make sure hrs and minutes are formatted correctly
//	if (this.mins > 0 && this.mins < 15) {
//		this.mins = 15;
//	} else if (this.mins > 15 && this.mins < 30) {
//		this.mins = 30;
//	} else if (this.mins > 30 && this.mins < 45) {
//		this.mins = 45;
//	} else if (this.mins > 45) {
//		this.hrs += 1;
//		this.mins = 0;
//	} //if-else

Now move into the Smarty template file you put at /custom/include/SugarFields/Fields/Datetimecombo/EditView.tpl. The only piece that needs to be modified here is the reference to the old javascript. Append the prefix custom/ to the javascript src attribute.

<script type="text/javascript" src="custom/include/SugarFields/Fields/Datetimecombo/Datetimecombo.js"></script>

To root these customizations, we’ll just extend the existing Datetimecombo class and have it use our bits-and-pieces of customization.

<?php
require_once('include/SugarFields/Fields/Datetimecombo/SugarFieldDatetimecombo.php');
class CustomSugarFieldDatetimecombo extends SugarFieldDatetimecombo {
}

You may need to do a repair & rebuild (or just test this with Developer Mode enabled). This code will be sufficient to get things started. Looking back, there are more places we’ll need to roll this customization into, such as

  • Calls and Meetings Quick Create
  • Searchable Datetimecombo fields
  • Range search
  • Wireless views

Feel free to contribute code and suggestions in the comments.