// this is the standard fogbugz popup code, managed by the PopupManager object
// I set the html and added js after oSelf.Popup.setHtml which finds the ixInterval that got added to
// the dialog in doTimesheetMagic to the form here. it also calls getTimeIntervalComment to fetch
// the comment for the interval being shown
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");
});
}();
// this code will be called each time the timesheet dialog is displayed
function doTimesheetMagic(){
var i = 0;
jQuery("#idTimesheetTable tbody tr").each( function(index)
{
var thisId = $(this).attr("id");
if (i == 0)
{
$(this).append("<th> </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> </th>");
i = -2;
}
}
i++;
});
}
// this lets our code run after the dialog is actually done coming down from the server
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();
}
}
// this runs when the timesheet dialog is displayed. it can be changed / added to
// to also run when you click the next and previous arrows in the dialog
var oldShow = ClockPopup.show;
ClockPopup.show = function(){
console.log('Calling ClockPopup.show()...');
var result = oldShow.apply(ClockPopup, arguments);
nWaitCount = 0;
waitForTimesheetReady();
return result;
};
// runs after the comment is fetched for an interval
function getCallback(data)
{
if (data.substring(0,7) == 'failure')
{
alert('error');
}
else
{
$('form#TimeIntervalExamplePluginForm input[name=comment]').val(data);
}
}
// runs after the comment is posted for an interval
function postCallback(data)
{
alert(data);
}
|
Loading...