source: timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/htdocs/ticket.js

Last change on this file was 4261, checked in by Russ Tyndall, 15 years ago

finished the ticket permissions
Commented out the javascript that hid the hours in the header now that I can do that from python
(based on additions to blackmagic plugin: http://trac-hacks.org/wiki/BlackMagicTicketTweaksPlugin)

File size: 4.0 KB
Line 
1(function(){
2   function teAddEventListener(elem, evt, func, capture)
3   {
4      capture = capture || false;
5      if (elem.addEventListener) elem.addEventListener(evt, func, capture);
6      else elem.attachEvent('on'+evt, func);
7      return func;
8   }
9   
10// Function from: http://www.robertnyman.com/index.php?p=256
11   function getElementsByClassName(className, tag, elm)
12   {
13      var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
14      var tag = tag || "*";
15      var elm = elm || document;
16      var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
17      var returnElements = [];
18      var current;
19      var length = elements.length;
20      for (var i=0; i<length; i++)
21      {
22     current = elements[i];
23     if(testClass.test(current.className))
24     {
25        returnElements.push(current);
26     }
27      }
28      return returnElements;
29   }
30   
31
32   function FloatToHoursMins(hours)
33   {
34      if (0 == hours) return hours;
35      var neg = false;
36      if(hours < 0){
37     neg = true;
38     hours *= -1;
39      }
40      mins = Math.floor((hours - Math.floor(hours)) * 60);
41      str = neg ? '-' : '';
42      if (hours) str += Math.floor(hours) + 'h';
43      if (mins)  str += ' ' + mins + 'm';
44      return str;
45   }
46   
47   function IntToYesNo(boolflag)
48   {
49      if (boolflag == '1')
50     return 'Yes';
51     
52      if (boolflag == '0')
53     return 'No';
54     
55      return boolflag;
56   }
57   
58   
59   InitBilling = function(){
60      /*  // Convert totalhours field to non-editable
61      try
62      {
63     var x = document.getElementById('totalhours');
64     x = x || document.getElementById('field-totalhours');
65     if (x)
66     {
67        var p = x.parentNode;
68        var n = document.createElement('span')
69           n.id = x.id;
70        n.appendChild(document.createTextNode(x.value));
71        p.removeChild(x);
72        p.appendChild(n);
73     }
74      }
75      catch (er) {}
76      */
77
78      // Display yes/no in the summary
79      // if we fail, then no harm done.
80      try
81      {
82     var b = document.getElementById('h_billable');
83     do{ b = b.nextSibling; }while(b.nodeName != "TD");
84     b.innerHTML = IntToYesNo(b.innerHTML);
85      }
86      catch (er) {}
87 
88      /*
89      // Hide the Add Hours in the title table
90      // if we fail, then no harm done.
91      try
92      {
93     var b = document.getElementById('h_hours');
94     b.innerHTML = '';
95     do{ b = b.nextSibling; }while(b.nodeName != "TD");
96     b.innerHTML = '';
97      }
98      catch (er) {}
99      */
100     
101      // Convert hours from float to hours minutes seconds
102      // if we fail, then no harm done.
103      try
104      {
105     fields = Array('estimatedhours', 'totalhours');
106     for (var i=0; i < 2; ++i) 
107     {
108        var b = document.getElementById('h_' + fields[i]);
109        while (b)
110        {
111           if (!b.nextSibling) break;
112           b = b.nextSibling;
113           if (b.nodeName == 'TD')
114           {
115          b.innerHTML = FloatToHoursMins(b.innerHTML);
116          break;
117           }
118        }
119     }
120      }
121      catch (er) {}
122     
123      // Convert all relevent ticket changes to hours/minutes
124      // if we fail, then no harm done.
125      try {
126     changes = getElementsByClassName('changes', 'ul', document.getElementById('changelog'));
127     var change, li;
128     for (var i=0; change = changes[i]; i++) {
129        for (var j=0, li = change.childNodes[j]; li = change.childNodes[j]; j++) {
130           handleChangeRow(li); 
131        }
132     }
133      }
134      catch (er) {}
135   }
136
137   handleChangeRow = function(li){
138      var child, val, vals =[];
139      if (li.nodeName != 'LI') return;
140      // We look for a STRONG childNode
141      // We also need to find any em's following the STRONG
142      for(var i=0 ; child = li.childNodes[i] ; i++){
143     if (child.nodeName == 'STRONG'){
144        field = child.firstChild.nodeValue;
145        if(!(field == 'hours'
146         || field == 'estimatedhours'
147         || field == 'totalhours'))
148           return;
149     }
150     if (child.nodeName == 'EM'){
151        vals.push([child, child.firstChild.nodeValue])
152     } 
153      }
154      for(var i=0; val = vals[i] ; i++){
155     out = FloatToHoursMins(Number(val[1]))
156     //print(val[0]+'|'+ val[1] )
157     //print("#"+ out)
158     val[0].innerHTML = out
159      }
160      return vals;
161   }
162
163   teAddEventListener(window, 'load', InitBilling)
164})()
165
Note: See TracBrowser for help on using the repository browser.