FogBugz » TimeIntervalCommentsPlugin http://fogbugz.stackexchange.com/questions/3316
Clone URL:  
TimeIntervalExample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var TimeIntervalExamplePlugin = new function(){ var oSelf = this; this.doPopup = function(elPopupAnchor) { oSelf.Popup.setHtml( '<form id="TimeIntervalExamplePluginForm" onsubmit="TimeIntervalExamplePlugin.Popup.hide(); postTimeIntervalComment(); return false;">\n' + '<h1><label for="comment">Comment:</label></h1>' + '<div>' + '<input type="hidden" name="ixInterval">' + '<input type="text" id="comment" name="comment">' + '</div>' + '<br /><nobr><input type="submit" value="' + FB_OK + '" class="dlgButton"> ' + '<input type="button" onclick="TimeIntervalExamplePlugin.Popup.hide(); return false;" value="' + FB_CANCEL+ '" class="dlgButton"></nobr>' + '</form>'); oSelf.Popup.showPopup(elPopupAnchor); $("form#TimeIntervalExamplePluginForm input[name=ixInterval]").val(elPopupAnchor.attributes.getNamedItem('ixInterval').value); getTimeIntervalComment(elPopupAnchor.attributes.getNamedItem('ixInterval').value); return false; } $(document).ready(function(){ oSelf.Popup = api.PopupManager.newPopup("TimeIntervalExamplePlugin"); }); }(); function doTimesheetMagic(){ // put your jQuery magic here that manipulates the timesheet table // keep in mind that this code will be called each time the timesheet dialog is displayed var i = 0; jQuery("#idTimesheetTable tbody tr").each( function(index) { var thisId = $(this).attr("id"); if (i == 0) { $(this).append("<th>&nbsp;</th>"); } else if (i > 0) { if (thisId.length > 0) { var ixInterval = thisId.substring(thisId.indexOf("_") + 1); $(this).append('<td><a href="#" ixInterval="' + ixInterval + '" onclick="TimeIntervalExamplePlugin.doPopup(this); return false;">' + ixInterval + '</a></td>'); } else { $(this).append("<th>&nbsp;</th>"); i = -2; } } i++; }); } var nWaitCount = 0; function waitForTimesheetReady(){ console.log('lookin for timesheet table...'); if($('#idTimesheetTable').length === 0 && nWaitCount < 10){ console.log('not found, so wait a bit'); nWaitCount++; setTimeout(waitForTimesheetReady, 200); }else{ console.log('found it! now do stuff...'); doTimesheetMagic(); } } var oldShow = ClockPopup.show; ClockPopup.show = function(){ console.log('Calling ClockPopup.show()...'); var result = oldShow.apply(ClockPopup, arguments); nWaitCount = 0; waitForTimesheetReady(); return result; }; function getCallback(data) { if (!data || data.substring(0,7) == 'failure') { alert('error'); } else { $('form#TimeIntervalExamplePluginForm input[name=comment]').val(data); } } function postCallback(data) { alert(data); }