Changeset f320564a9131…
Parent 98193e382721…
by
Changes to 4 files · Browse files at f320564a9131 Showing diff from parent 98193e382721 Diff from another changeset...
@@ -39,5 +39,5 @@ // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.1.0.0")]
-[assembly: AssemblyFileVersion("0.1.0.0")] // adam - Added this cool new FogBugz plugin!
+[assembly: AssemblyVersion("0.1.1.0")]
+[assembly: AssemblyFileVersion("0.1.1.0")]
|
|
|
@@ -6,44 +6,25 @@ using FogCreek.FogBugz;
using FogCreek.FogBugz.Plugins;
using FogCreek.FogBugz.Plugins.Api;
+using FogCreek.FogBugz.Database.Entity;
using FogCreek.FogBugz.Plugins.Entity;
using FogCreek.FogBugz.Plugins.Interfaces;
using FogCreek.FogBugz.UI.Dialog;
namespace TimeIntervalExample
{
- public class TimeIntervalExample : Plugin, IPluginTimeIntervalCommit, IPluginTimeIntervalJoin,
+ public class TimeIntervalExample : Plugin, IPluginTimeIntervalJoin,
IPluginJS, IPluginDatabase, IPluginRawPageDisplay
{
public TimeIntervalExample(CPluginApi api) : base(api) { }
protected const string SPluginId = "Adam+TimeIntervalExample@fogcreek.com";
- string _preCommitComment = "";
private const string CommentsTable = "TimeIntervalComment";
private const string IntervalColumn = "ixInterval";
private const string CommentColumn = "sComment";
public const int CommentColumnMaxLength = 255;
private const int PluginSchemaVer = 1;
- #region IPluginTimeIntervalCommit Members
-
- public void TimeIntervalCommitAfter(CTimeInterval timeinterval)
- {
- throw new NotImplementedException();
- }
-
- public bool TimeIntervalCommitBefore(CTimeInterval timeinterval)
- {
- throw new NotImplementedException();
- }
-
- public void TimeIntervalCommitRollback(CTimeInterval timeinterval)
- {
- throw new NotImplementedException();
- }
-
- #endregion
-
#region IPluginTimeIntervalJoin Members
public string[] TimeIntervalJoinTables()
@@ -57,7 +38,35 @@
public CJSInfo JSInfo()
{
- throw new NotImplementedException();
+ string fullAjaxPostUrl = api.Url.PluginRawPageUrl() +
+ String.Format("&{0}sComment=' + sComment + '&{0}action=postTimeIntervalComment&{0}actionToken={1}",
+ api.PluginPrefix,
+ api.Security.GetActionToken("postTimeIntervalComment"));
+ string fullAjaxGetUrl = api.Url.PluginRawPageUrl() +
+ String.Format("&{0}action=getTimeIntervalComment&{0}actionToken={1}&{0}ixInterval=",
+ api.PluginPrefix,
+ api.Security.GetActionToken("postTimeIntervalComment"));
+
+ CJSInfo jsInfo = new CJSInfo();
+ jsInfo.rgsStaticFiles = new string[] { "js/TimeIntervalExample.js" };
+ jsInfo.sInlineJS = @"
+function postTimeIntervalComment()
+{
+ var sComment = $('form#TimeIntervalExamplePluginForm input[name=comment]').val();
+ var ixInterval = $('form#TimeIntervalExamplePluginForm input[name=]').val();
+ var url = '" + fullAjaxPostUrl + @"';
+ jQuery.get(url, myCallback);
+}
+
+function getTimeIntervalComment(ixInterval)
+{
+ var url = '" + fullAjaxGetUrl + @"' + ixInterval;
+ jQuery.get(url, function() {
+ $('form#TimeIntervalExamplePluginForm input[name=comment]').val(data);
+alert(data);
+});
+}";
+ return jsInfo;
}
#endregion
@@ -103,27 +112,33 @@ public string RawPageDisplay()
{
if (api.Request[api.AddPluginPrefix("action")] != null &&
- Convert.ToString(api.Request[api.AddPluginPrefix("action")]) == "postComment")
+ Convert.ToString(api.Request[api.AddPluginPrefix("action")]) == "postTimeIntervalComment")
{
// make sure the request includes a valid action token
if ((api.Request[api.AddPluginPrefix("actionToken")] == null) ||
!api.Security.ValidateActionToken(api.Request[api.AddPluginPrefix("actionToken")],
- "postComment"))
+ "postTimeIntervalComment"))
{
- return "action token invalid";
+ return "failure: action token invalid";
}
else
{
- PostComment();
+ return PostComment();
}
}
- if (api.Request[api.AddPluginPrefix("data")] == "getComment")
+ else if (api.Request[api.AddPluginPrefix("action")] != null &&
+ Convert.ToString(api.Request[api.AddPluginPrefix("action")]) == "getTimeIntervalComment")
{
- return GetComment();
+ int ixInterval = -1;
+ if (api.Request[api.AddPluginPrefix("action")] != null &&
+ Int32.TryParse(Convert.ToString(api.Request[api.AddPluginPrefix("ixInterval")]), out ixInterval))
+ return GetComment(ixInterval);
+ else
+ return "failure: ixInterval invalid";
}
- else return "command not recognized";
+ else return "failure: command not recognized";
}
public PermissionLevel RawPageVisibility()
@@ -133,14 +148,22 @@
#endregion
- private void PostComment()
+ private string PostComment()
{
-
+ return "success";
}
- private void GetComment()
+ private string GetComment(int ixInterval)
{
- throw new NotImplementedException();
+ CTimeIntervalQuery query = api.TimeInterval.NewTimeIntervalQuery();
+ query.AddWhere("TimeInterval.ixInterval = @ixInterval");
+ query.SetParamInt("@ixInterval", ixInterval);
+
+ CTimeInterval timeInterval = query.List()[0];
+ // check for null
+ string sComment = timeInterval.GetPluginField(SPluginId, "sComment").ToString();
+ // return sComment;
+ return "comment goes here";
}
}
}
|
@@ -50,6 +50,9 @@ <Compile Include="TimeIntervalExample.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
+ <ItemGroup>
+ <Content Include="static\js\TimeIntervalExample.js" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
|
|
@@ -0,0 +1,81 @@ + 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" value="-1">' +
+ '<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>' +
+ '<script type="text/javascript">' +
+
+ '$("form#TimeIntervalExamplePluginForm input[name=ixInterval]").val("' + elPopupAnchor.attributes.getNamedItem("ixInterval").value + '");' +
+ 'getTimeIntervalComment(' + elPopupAnchor.attributes.getNamedItem("ixInterval").value + ');' +
+ '</script>');
+ oSelf.Popup.showPopup(elPopupAnchor);
+ 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> </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++;
+ });
+}
+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 myCallback(sHTML, status)
+{
+ alert(sHTML);
+}
\ No newline at end of file |
Loading...