From a0f62e9309fbe05d5f1bd6288679d7ca2d2848f2 Mon Sep 17 00:00:00 2001 From: vfilippov Date: Mon, 1 Feb 2010 13:33:39 +0000 Subject: [PATCH] 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-67ecbb4d7f56 --- Bugzilla/Bug.pm | 8 +++-- js/global.js | 22 ++++++++++++ js/util.js | 36 +++++++++++++++++++ .../en/default/bug/create/create.html.tmpl | 35 +----------------- template/en/default/bug/edit.html.tmpl | 21 +---------- 5 files changed, 65 insertions(+), 57 deletions(-) diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 48c1b4af7..5bcd431ef 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -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 diff --git a/js/global.js b/js/global.js index 776a828f2..e29a9c983 100644 --- a/js/global.js +++ b/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; +} diff --git a/js/util.js b/js/util.js index 666f2666b..9ecc3c7d3 100644 --- a/js/util.js +++ b/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(", "); +} diff --git a/template/en/default/bug/create/create.html.tmpl b/template/en/default/bug/create/create.html.tmpl index 0e06079cf..45c725776 100644 --- a/template/en/default/bug/create/create.html.tmpl +++ b/template/en/default/bug/create/create.html.tmpl @@ -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 diff --git a/template/en/default/bug/edit.html.tmpl b/template/en/default/bug/edit.html.tmpl index 39b79548d..d37370f9b 100644 --- a/template/en/default/bug/edit.html.tmpl +++ b/template/en/default/bug/edit.html.tmpl @@ -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() {