Skip to content

Commit

Permalink
# This is a combination of 9 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

Fix salesagility#10364 - Adding now option in Datetime fields

# This is the commit message #2:

Fix salesagility#10364 - Adding now option in Datetime fields

# This is the commit message #3:

Fix salesagility#10364 - Adding now option in Datetime fields

# This is the commit message #4:

Fix salesagility#10364 - Adding now option in Datetime fields

# This is the commit message #5:

Fix salesagility#10364 - Adding now option in Datetime fields

# This is the commit message #6:

Fix salesagility#10364 - Adding now option in Datetime fields

# This is the commit message #7:

Fix salesagility#10364 - Adding now option in Datetime fields

# This is the commit message #8:

Fix salesagility#10364 - Adding now option in Datetime fields

# This is the commit message #9:

Fix salesagility#10364 - Adding now option in Datetime fields
  • Loading branch information
SinergiaCRM committed Feb 26, 2024
1 parent b39d961 commit d298e16
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 41 deletions.
6 changes: 3 additions & 3 deletions include/MassUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public function getMassUpdateForm(
break;
case "datetimecombo":
$even = !$even;
$newhtml .= $this->addDatetime($displayname, $field["name"]);
$newhtml .= $this->addDatetime($displayname, $field["name"],$field["display_default"]);
break;
case "datetime":
case "date":
Expand Down Expand Up @@ -1296,7 +1296,7 @@ public function addRadioenum($displayname, $varname, $options)
* @param displayname Name to display in the popup window
* @param varname name of the variable
*/
public function addDatetime($displayname, $varname)
public function addDatetime($displayname, $varname, $fieldtimeformat)
{
global $timedate, $app_strings, $app_list_strings, $theme, $current_user;
$userformat = $timedate->get_user_time_format();
Expand All @@ -1318,7 +1318,7 @@ public function addDatetime($displayname, $varname)
<input type="hidden" id="{$varname}" name="{$varname}">
$dtscript
<script type="text/javascript">
var combo_{$varname} = new Datetimecombo(" ", "$varname", "$userformat", '','','',1);
var combo_{$varname} = new Datetimecombo(" ", "$varname", "$userformat", '','','',1,"$fieldtimeformat");
//Render the remaining widget fields
text = combo_{$varname}.html('');
document.getElementById('{$varname}_time_section').innerHTML = text;
Expand Down
2 changes: 1 addition & 1 deletion include/SugarFields/Fields/Datetimecombo/EditView.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function set_{{$idname}}_values(form) {ldelim}
{{/if}}
<script type="text/javascript" src="{sugar_getjspath file="include/SugarFields/Fields/Datetimecombo/Datetimecombo.js"}"></script>
<script type="text/javascript">
var combo_{{$idname}} = new Datetimecombo("{$fields[{{sugarvar key='name' stringFormat=true}}].value}", "{{$idname}}", "{$TIME_FORMAT}", "{{$tabindex}}", '{{$displayParams.showNoneCheckbox}}', false, true);
var combo_{{$idname}} = new Datetimecombo("{$fields[{{sugarvar key='name' stringFormat=true}}].value}", "{{$idname}}", "{$TIME_FORMAT}", "{{$tabindex}}", '{{$displayParams.showNoneCheckbox}}', false, true, "{$fields[{{sugarvar key='name' stringFormat=true}}].display_default}");
//Render the remaining widget fields
text = combo_{{$idname}}.html('{{$displayParams.updateCallback}}');
document.getElementById('{{$idname}}_time_section').innerHTML = text;
Expand Down
6 changes: 5 additions & 1 deletion include/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,11 @@ function get_sugar_config_defaults(): array
'legacy_email_behaviour' => false,
'valid_imap_ports' => [
'110', '143', '993', '995'
]
],
'datetime_combo_minute_interval' => 15,
'js_available' => array(
0 => 'datetime_combo_minute_interval',
)
];

if (!is_object($locale)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
* @param tabindex
* @allowEmptyHM - if this param was set true , the hour and minute select field will has an empty option.
*/
function Datetimecombo (datetime, field, timeformat, tabindex, showCheckbox, checked, allowEmptyHM) {
function Datetimecombo (datetime, field, timeformat, tabindex, showCheckbox, checked, allowEmptyHM, defaultValue = "") {
this.defaultValue = defaultValue;
this.datetime = datetime;
this.allowEmptyHM = allowEmptyHM;
if(typeof this.datetime == "undefined" || datetime == '' || trim(datetime).length < 10) {
Expand Down Expand Up @@ -93,36 +94,6 @@ function Datetimecombo (datetime, field, timeformat, tabindex, showCheckbox, che
this.checked = parseInt(checked);
YAHOO.util.Selector.query('input#' + this.fieldname + '_date')[0].value = this.datetime;

//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(this.hasMeridiem && this.hrs == 12) {
if(this.meridiem == "pm" || this.meridiem == "am") {
if(this.meridiem == "pm") {
this.meridiem = "am";
} else {
this.meridiem = "pm";
}
} else {
if(this.meridiem == "PM") {
this.meridiem = "AM";
} else {
this.meridiem = "PM";
}
}
}
if (this.hasMeridiem && this.hrs > 12) {
this.hrs = this.hrs - 12;
}
} //if-else

}

/**
Expand Down Expand Up @@ -185,10 +156,17 @@ Datetimecombo.prototype.html = function(callback) {
if(this.allowEmptyHM){
text += '\n<option></option>';
}
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>';
var minuteSteps = 15;

if (typeof SUGAR.config.datetime_combo_minute_interval !== 'undefined') {
minuteSteps = parseInt(SUGAR.config.datetime_combo_minute_interval);
}
if (this.defaultValue.includes('now')) {
minuteSteps = 1;
}
for (i = 0; i < 60; i += minuteSteps) {
text += '\n<option value="' + (i < 10 ? '0' : '') + i + '" ' + (this.mins == i ? "SELECTED" : "") + '>' + (i < 10 ? '0' : '') + i + '</option>';
}
text += '\n</select>';

if(this.hasMeridiem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function get_body(&$ss, $vardef)
}
}
$ss->assign('default_date', $date);
} elseif($vardef['display_default'] == 'now') {
$ss->assign('default_date', $vardef['display_default']);
}
$ss->assign('default_hours', $hours);
$ss->assign('default_minutes', $minitues);
Expand Down
24 changes: 24 additions & 0 deletions modules/DynamicFields/templates/Fields/Forms/datetimecombo.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,29 @@
addToValidateBinaryDependency('popup_form',"defaultDate_date", 'alpha', false, "{$APP.ERR_MISSING_REQUIRED_FIELDS} {$APP.LBL_DATE} {$APP.LBL_OR} {$APP.LBL_HOURS}" ,"defaultTime_hours");
addToValidateBinaryDependency('popup_form',"defaultTime_hours", 'alpha', false, "{$APP.ERR_MISSING_REQUIRED_FIELDS} {$APP.LBL_HOURS} {$APP.LBL_OR} {$APP.LBL_MINUTES}" ,"defaultTime_minutes");
addToValidateBinaryDependency('popup_form', "defaultTime_minutes", 'alpha', false, "{$APP.ERR_MISSING_REQUIRED_FIELDS} {$APP.LBL_MINUTES} {$APP.LBL_OR} {$APP.LBL_MERIDIEM}","defaultTime_meridiem");
{literal}
toggleDateValidation();
$('#defaultDate_date', 'form').on("change", function() {
toggleDateValidation();
});
function toggleDateValidation() {
if ($('#defaultDate_date', 'form').val() == 'now' || $('#defaultDate_date', 'form').val() == '') {
removeFromValidate('popup_form', "defaultDate_date");
$('#defaultTime_hours').parent().closest('tr').hide();
$('#defaultTime_hours').val('');
$('#defaultTime_minutes').val('');
$('#defaultTime').val('');
} else {
$('#defaultTime_hours').parent().closest('tr').show();
{/literal}
addToValidateBinaryDependency('popup_form',"defaultDate_date", 'alpha', false, "{$APP.ERR_MISSING_REQUIRED_FIELDS} {$APP.LBL_DATE} {$APP.LBL_OR} {$APP.LBL_HOURS}" ,"defaultTime_hours");
addToValidateBinaryDependency('popup_form',"defaultTime_hours", 'alpha', false, "{$APP.ERR_MISSING_REQUIRED_FIELDS} {$APP.LBL_HOURS} {$APP.LBL_OR} {$APP.LBL_MINUTES}" ,"defaultTime_minutes");
addToValidateBinaryDependency('popup_form', "defaultTime_minutes", 'alpha', false, "{$APP.ERR_MISSING_REQUIRED_FIELDS} {$APP.LBL_MINUTES} {$APP.LBL_OR} {$APP.LBL_MERIDIEM}","defaultTime_meridiem");
{literal}
}
}
{/literal}
</script>
{include file="modules/DynamicFields/templates/Fields/Forms/coreBottom.tpl"}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class TemplateDatetimecombo extends TemplateRange
public $len = '';
public $dateStrings = array(
'-none-' => '',
'today'=>'now',
'now' => 'now',
'today'=> 'today',
'yesterday'=> '-1 day',
'tomorrow'=>'+1 day',
'next week'=> '+1 week',
Expand Down Expand Up @@ -167,6 +168,8 @@ public function populateFromPost()
//lets format the string to make sure the leading 0's are added back in for hours and minutes
$_REQUEST['default'] = $_REQUEST['defaultDate'] . '&' . sprintf('%02d:%02d%s', $hours, $minutes, $meridiem);
}
} elseif ($_REQUEST['defaultDate'] == 'now') {
$_REQUEST['default'] = 'now';
} else {
$_REQUEST['default'] = '';
}
Expand Down

0 comments on commit d298e16

Please sign in to comment.