source: timingandestimationplugin/branches/trac0.12-Permissions/timingandestimationplugin/htdocs/add_hours_from_comment.js

Last change on this file was 12858, checked in by Russ Tyndall, 11 years ago

make add_hours_from_comment work in the face of ajax previews

File size: 1.3 KB
Line 
1(function(){
2var btnTemp = $('<div class="inlinebuttons"><input type="submit" title="add time elapsed since this comment" value="Add Time" class="add-hours-btn"></div>');
3
4function add_buttons(){
5  $(".change .trac-ticket-buttons").each(function(i,e){
6    var ts = timestamp_from_change(this);
7    var el = $(this);
8    // we had a timestamp, but no add hours button
9    if(ts && el.has('.add-hours-btn').length == 0) el.append(btnTemp.clone().click(
10      function(){TandE_onClickOfADateElement(ts);}
11    ));
12  });
13}
14
15function timestamp_from_change(el){
16  el = $(el);
17  if(!el.is(".change")) el = $(el.parents(".change"));
18  var id=el.attr("id"), r = /trac-change-\d+-(\d+)/,
19    m = id && id.match(r),
20    ts = m && m[1];
21  if(ts) return new Date(Math.floor(Number(ts/1000)));
22  return null;
23}
24
25function TandE_onClickOfADateElement(commenttime) {
26  var now = new Date();
27  var minutesDiff = (now - commenttime) / 1000 / 60;
28  var fifteens = Math.floor(minutesDiff / 15);
29  var remainder = minutesDiff % 15;
30  var hours = (fifteens * 0.25) + ((remainder > 5) ? 0.25 : 0.0);
31  $('#field-hours')[0].value = hours;
32  return false;
33}
34
35// when we replace the changelog/timeline add buttons
36$(document).ajaxStop(add_buttons);
37$(document).ready(add_buttons);
38})(); // end of scoping function
Note: See TracBrowser for help on using the repository browser.