FogBugz » TimeIntervalCommentsPlugin http://fogbugz.stackexchange.com/questions/3316
Clone URL:  
Pushed to one repository · View In Graph Contained in version_0-2-0-0, version_0-2-0-1, and tip

in progress. much javascript kinda sorta working

Changeset f320564a9131

Parent 98193e382721

by Adam Wishneusky

Changes to 4 files · Browse files at f320564a9131 Showing diff from parent 98193e382721 Diff from another changeset...

 
39
40
41
42
43
 
 
 
39
40
41
 
 
42
43
@@ -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
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
 
57
58
59
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
62
63
 
103
104
105
106
 
107
108
109
110
111
 
112
113
 
114
115
116
117
 
118
119
120
121
122
 
 
123
124
 
 
 
 
 
 
125
126
 
127
128
129
 
133
134
135
136
 
137
138
 
139
140
141
 
142
143
 
 
 
 
 
 
 
 
 
144
145
146
 
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
 
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
 
112
113
114
 
115
116
117
118
119
 
120
121
 
122
123
124
125
 
126
127
128
129
130
 
131
132
133
 
134
135
136
137
138
139
140
 
141
142
143
144
 
148
149
150
 
151
152
 
153
154
155
 
156
157
 
158
159
160
161
162
163
164
165
166
167
168
169
@@ -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
51
52
 
 
 
53
54
55
 
50
51
52
53
54
55
56
57
58
@@ -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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -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>&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 myCallback(sHTML, status) +{ + alert(sHTML); +} \ No newline at end of file