Bug 58021
bzParseTime in bug creation, move some js to util.js and global.js git-svn-id: svn://svn.office.custis.ru/3rdparty/bugzilla.org/trunk@638 6955db30-a419-402b-8a0d-67ecbb4d7f56master
parent
54b8834e3a
commit
a0f62e9309
|
@ -52,6 +52,7 @@ use Storable qw(dclone);
|
|||
use URI;
|
||||
use URI::QueryParam;
|
||||
use Date::Format qw(time2str);
|
||||
use POSIX qw(floor);
|
||||
|
||||
use base qw(Bugzilla::Object Exporter);
|
||||
@Bugzilla::Bug::EXPORT = qw(
|
||||
|
@ -3212,15 +3213,16 @@ sub ValidateTime
|
|||
$time =~ tr/,/./;
|
||||
$time = trim($time) || 0;
|
||||
|
||||
if ($time =~ /^(-?)(?:(\d+):(\d+)(?::(\d+))?)$/so)
|
||||
if ($time =~ /^(-?)(\d+):(\d+)$/so)
|
||||
{
|
||||
# HH:MM[:SS]
|
||||
# HH:MM
|
||||
$time = $1 . ($2 + $3/60 + ($4||0)/3600);
|
||||
$time = floor($time*100+0.5)/100;
|
||||
}
|
||||
elsif ($time =~ /^(-?\d+(?:\.\d+)?)d$/so)
|
||||
{
|
||||
# days
|
||||
$time = $1 * 24;
|
||||
$time = $1 * 8;
|
||||
}
|
||||
|
||||
# regexp verifies one or more digits, optionally followed by a period and
|
||||
|
|
22
js/global.js
22
js/global.js
|
@ -226,3 +226,25 @@ function menuforusers_showmulti(id, wha)
|
|||
sel.style.visibility = show ? '' : 'hidden';
|
||||
btn.src = 'images/dn' + (show ? 'push' : '') + '.gif';
|
||||
}
|
||||
|
||||
/* work time parser: "1,5" or "1:30" (HH:MM) = 1.5, "1.5d" (days) = 12 */
|
||||
function bzParseTime(time)
|
||||
{
|
||||
time = time+"";
|
||||
time = time.replace(',','.');
|
||||
if (m = time.match(/^\s*(-?)(\d+):(\d+)\s*$/))
|
||||
{
|
||||
for (var i = 2; i < 5; i++)
|
||||
{
|
||||
if (!m[i]) m[i] = 0;
|
||||
else m[i] = parseInt(m[i]);
|
||||
}
|
||||
if (!m[1]) m[1] = '';
|
||||
time = Math.floor(parseFloat(m[1] + (m[2] + m[3]/60))*100+0.5)/100;
|
||||
}
|
||||
else if (m = time.match(/^\s*(-?\d+(?:\.\d+)?)d\s*$/))
|
||||
time = parseFloat(m[1])*8;
|
||||
else
|
||||
time = parseFloat(time);
|
||||
return time;
|
||||
}
|
||||
|
|
36
js/util.js
36
js/util.js
|
@ -271,3 +271,39 @@ function bz_toggleClass(anElement, aClass) {
|
|||
YAHOO.util.Dom.addClass(anElement, aClass);
|
||||
}
|
||||
}
|
||||
|
||||
/* map { $_ => 1 } %h */
|
||||
function array_hash(ar)
|
||||
{
|
||||
var h = {};
|
||||
if (ar.length == 1 && ar[0].length == 0)
|
||||
return h;
|
||||
for (i in ar)
|
||||
h[ar[i]] = 1;
|
||||
return h;
|
||||
}
|
||||
|
||||
/* [a,b,c], [d,b] ---> {d:1},{a:1,c:1} */
|
||||
function diff_arrays(a1, a2)
|
||||
{
|
||||
var h1 = array_hash(a1);
|
||||
var h2 = array_hash(a2);
|
||||
var add = {}, rem = {};
|
||||
for (i in a1)
|
||||
if (!h2[a1[i]])
|
||||
rem[a1[i]] = 1;
|
||||
for (i in a2)
|
||||
if (!h1[a2[i]])
|
||||
add[a2[i]] = 1;
|
||||
return [ add, rem ];
|
||||
}
|
||||
|
||||
/* join ",", grep { $h{$_} } keys %h */
|
||||
function hash_join(h)
|
||||
{
|
||||
var a = [];
|
||||
for (i in h)
|
||||
if (h[i])
|
||||
a.push(i);
|
||||
return a.join(", ");
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ var flags = new Array([% product.components.size %]);
|
|||
|
||||
function Create_onsubmit()
|
||||
{
|
||||
wt = parseFloat(document.Create.work_time.value.replace(',','.'));
|
||||
wt = bzParseTime(document.Create.work_time.value);
|
||||
if (wt != wt || wt < 0)
|
||||
wt = 0;
|
||||
else if ([% remind_about_worktime_newbug ? 1 : 0 %] && (!wt || wt == 0))
|
||||
|
@ -101,39 +101,6 @@ function Create_onsubmit()
|
|||
return true;
|
||||
}
|
||||
|
||||
function array_hash(ar)
|
||||
{
|
||||
var h = {};
|
||||
if (ar.length == 1 && ar[0].length == 0)
|
||||
return h;
|
||||
for (i in ar)
|
||||
h[ar[i]] = 1;
|
||||
return h;
|
||||
}
|
||||
|
||||
function diff_arrays(a1, a2)
|
||||
{
|
||||
var h1 = array_hash(a1);
|
||||
var h2 = array_hash(a2);
|
||||
var add = {}, rem = {};
|
||||
for (i in a1)
|
||||
if (!h2[a1[i]])
|
||||
rem[a1[i]] = 1;
|
||||
for (i in a2)
|
||||
if (!h1[a2[i]])
|
||||
add[a2[i]] = 1;
|
||||
return [ add, rem ];
|
||||
}
|
||||
|
||||
function hash_join(h)
|
||||
{
|
||||
var a = [];
|
||||
for (i in h)
|
||||
if (h[i])
|
||||
a.push(i);
|
||||
return a.join(", ");
|
||||
}
|
||||
|
||||
function set_assign_to() {
|
||||
// Based on the selected component, fill the "Assign To:" field
|
||||
// with the default component owner, and the "QA Contact:" field
|
||||
|
|
|
@ -138,24 +138,6 @@
|
|||
|
||||
[% IF user.in_group(Param('timetrackinggroup')) %]
|
||||
var fRemainingTime = [% bug.remaining_time %]; // holds the original value
|
||||
function bzParseTime(time)
|
||||
{
|
||||
time = time+"";
|
||||
time = time.replace(',','.');
|
||||
if (m = time.match(/^\s*(-?)(?:(\d+):(\d+)(?::(\d+))?)\s*$/))
|
||||
{
|
||||
for (var i = 2; i < 5; i++)
|
||||
{
|
||||
if (!m[i]) m[i] = 0;
|
||||
else m[i] = parseInt(m[i]);
|
||||
}
|
||||
if (!m[1]) m[1] = '';
|
||||
time = m[1] + (m[2] + m[3]/60 + m[4]/3600);
|
||||
}
|
||||
else if (m = time.match(/^\s*(-?\d+(?:\.\d+)?)d\s*$/))
|
||||
time = parseFloat(m[1])*24;
|
||||
return parseFloat(time);
|
||||
}
|
||||
function adjustRemainingTime()
|
||||
{
|
||||
// subtracts time spent from remaining time
|
||||
|
@ -176,8 +158,7 @@
|
|||
// prevent negative values if work_time > fRemainingTime
|
||||
new_time = Math.max(fRemainingTime - wt, 0.0);
|
||||
// get upto 2 decimal places
|
||||
document.changeform.remaining_time.value =
|
||||
Math.round(new_time * 100)/100;
|
||||
document.changeform.remaining_time.value = Math.round(new_time * 100)/100;
|
||||
}
|
||||
|
||||
function updateRemainingTime() {
|
||||
|
|
Loading…
Reference in New Issue