From 417b94800f75523c3699a096c2864006e011c2f5 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 10 Jan 2014 20:32:58 -0800 Subject: [PATCH] CRM-14065 - Activity Form - Fix activityStatus js function --- templates/CRM/Activity/Form/ActivityJs.tpl | 53 +++++----------------- 1 file changed, 12 insertions(+), 41 deletions(-) diff --git a/templates/CRM/Activity/Form/ActivityJs.tpl b/templates/CRM/Activity/Form/ActivityJs.tpl index d47b6cc4b2..8ee7da8284 100644 --- a/templates/CRM/Activity/Form/ActivityJs.tpl +++ b/templates/CRM/Activity/Form/ActivityJs.tpl @@ -73,48 +73,19 @@ * @param element message JSON object. */ function activityStatus(message) { - var d = new Date(), time = [], i; - var currentDateTime = d.getTime() - var activityTime = cj("input#activity_date_time_time").val().replace(":", ""); - - //chunk the time in bunch of 2 (hours,minutes,ampm) - for (i = 0; i < activityTime.length; i += 2) { - time.push(activityTime.slice(i, i + 2)); - } - var activityDate = new Date(cj("input#activity_date_time_hidden").val()); - - d.setFullYear(activityDate.getFullYear()); - d.setMonth(activityDate.getMonth()); - d.setDate(activityDate.getDate()); - var hours = time['0']; - var ampm = time['2']; - - if (ampm == "PM" && hours != 0 && hours != 12) { - // force arithmetic instead of string concatenation - hours = hours * 1 + 12; - } - else { - if (ampm == "AM" && hours == 12) { - hours = 0; + var date = cj("#activity_date_time_display").datepicker('getDate'); + if (date) { + var + now = new Date(), + time = cj("#activity_date_time_time").timeEntry('getTime') || date, + activityStatusId = cj('#status_id').val(), + d = date.toString().split(' '), + activityDate = new Date(d[0] + ' ' + d[1] + ' ' + d[2] + ' ' + d[3] + ' ' + time.toTimeString()); + if (activityStatusId == 2 && now < activityDate) { + return confirm(message.completed); } - } - d.setHours(hours); - d.setMinutes(time['1']); - - var activity_date_time = d.getTime(); - - var activityStatusId = cj('#status_id').val(); - - if (activityStatusId == 2 && currentDateTime < activity_date_time) { - if (!confirm(message.completed)) { - return false; - } - } - else { - if (activity_date_time && activityStatusId == 1 && currentDateTime >= activity_date_time) { - if (!confirm(message.scheduled)) { - return false; - } + else if (activityStatusId == 1 && now >= activityDate) { + return confirm(message.scheduled); } } } -- 2.25.1