Changeset 3c682383325a…
Parent 7c7e388ddc6f…
by Adam Wishneusky
Changes to 4 files · Browse files at 3c682383325a Showing diff from parent 7c7e388ddc6f Diff from another changeset...
@@ -1,6 +1,6 @@ -
-Microsoft Visual Studio Solution File, Format Version 10.00
-# Visual Studio 2008
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimeIntervalExample", "TimeIntervalExample\TimeIntervalExample.csproj", "{BAADAECF-22A2-438F-9098-E1E977B1BAF8}"
EndProject
Global
|
@@ -1,4 +1,4 @@ - using System.Reflection;
+using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
|
|
|
- using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Web;
-
-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, IPluginTimeIntervalJoin,
- IPluginJS, IPluginDatabase, IPluginRawPageDisplay
+ using System;
+ using FogCreek.FogBugz;
+ using FogCreek.FogBugz.Database.Entity;
+ using FogCreek.FogBugz.Plugins;
+ using FogCreek.FogBugz.Plugins.Api;
+ using FogCreek.FogBugz.Plugins.Entity;
+ using FogCreek.FogBugz.Plugins.Interfaces;
+
+ public class TimeIntervalExample : Plugin, IPluginTimeIntervalJoin, IPluginJS, IPluginDatabase, IPluginRawPageDisplay
{
- public TimeIntervalExample(CPluginApi api) : base(api) { }
-
- protected const string sPluginId = "Adam+TimeIntervalExample@fogcreek.com";
+ private const string sPluginId = "Adam+TimeIntervalExample@fogcreek.com";
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;
+
+ public TimeIntervalExample(CPluginApi api)
+ : base(api)
+ {
+ }
- #region IPluginTimeIntervalJoin Members
+ #region IPluginTimeIntervalJoin
public string[] TimeIntervalJoinTables()
{
- return new string[] { "TimeIntervalComment" };
+ return new[] { CommentsTable };
}
#endregion
#region IPluginJS Members
- // this js comes down on every page. I put this here instead of in the static js file
- // because we need the pluginprefix for this plugin (which is based on when the plugin is
- // installed. alternatively, we could just set a variable for it in JS-land and put the
- // rest of these functions into the static js file
+ /// <summary>
+ /// Javascript is used to augment the time-tracking UI to display and edit comments
+ /// </summary>
+ /// <returns>new instance configured with list of JScript file references to emit</returns>
public CJSInfo JSInfo()
{
- string fullAjaxPostUrl = api.Url.PluginRawPageUrl() +
- String.Format("&{0}sComment=' + sComment + '&{0}action=postTimeIntervalComment&{0}actionToken={1}&{0}ixInterval=' + ixInterval",
- api.PluginPrefix,
- api.Security.GetActionToken("postTimeIntervalComment"));
- string fullAjaxGetUrl = api.Url.PluginRawPageUrl() +
- String.Format("&{0}action=getTimeIntervalComment&{0}actionToken={1}&{0}ixInterval=' + ixInterval",
- api.PluginPrefix,
- api.Security.GetActionToken("postTimeIntervalComment"));
+ const string trackerObjectFormat = @"
+ var TrackerCommentsPlugIn = {{
+ plugInRawPageUrl: '{0}',
+ pluginPrefix: '{1}',
+ PostTimeFunctionToken: '{2}',
+ UpdateCommentFunctionToken: '{3}',
+ TimeIntervalForeignKeyColumnName: '{4}'
+ }};";
+
+ var jsInfo = new CJSInfo
+ {
+ rgsStaticFiles = new[] {"js/TimeIntervalExample.js"},
+ sInlineJS = string.Format(trackerObjectFormat,
+ api.Url.PluginRawPageUrl(),
+ api.PluginPrefix,
+ api.Security.GetActionToken("saveTimeIntervalComment"),
+ api.Security.GetActionToken("updateCommentText"),
+ IntervalColumn)
+ };
- 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=ixInterval]').val();
- var url = '" + fullAjaxPostUrl + @";
- jQuery.get(url, function(data) { postCallback(data); });
-}
-
-function getTimeIntervalComment(ixInterval)
-{
- var url = '" + fullAjaxGetUrl + @";
- jQuery.get(url, function(data) { getCallback(data); });
-}";
return jsInfo;
}
#endregion
#region IPluginDatabase Members
+ /// <summary>
+ /// Schema Definition
+ /// </summary>
+ /// <returns>
+ /// Array with one element representing the comments table
+ /// </returns>
public CTable[] DatabaseSchema()
{
var timeIntervalComments = api.Database.NewTable(api.Database.PluginTableName(CommentsTable));
timeIntervalComments.sDesc = "Assigns Comments to TimeIntervals";
timeIntervalComments.AddAutoIncrementPrimaryKey("ixTimeIntervalComment");
timeIntervalComments.AddIntColumn(IntervalColumn, true, 0);
timeIntervalComments.AddVarcharColumn(CommentColumn, CommentColumnMaxLength, false);
return new[] { timeIntervalComments };
}
+ /// <summary>
+ /// Returns Database Plugin Schema Version
+ /// </summary>
+ /// <returns>
+ /// Integer with database schema version
+ /// </returns>
public int DatabaseSchemaVersion()
{
return PluginSchemaVer;
}
public void DatabaseUpgradeAfter(int ixVersionFrom, int ixVersionTo, CDatabaseUpgradeApi apiUpgrade)
{
if (ixVersionTo == 1)
{
// No action required. Don't create any data in the tables
}
}
public void DatabaseUpgradeBefore(int ixVersionFrom, int ixVersionTo, CDatabaseUpgradeApi apiUpgrade)
{
- if (ixVersionTo == 1)
+ if (ixVersionTo == 1)
{
// No action required. Don't create any data in the tables
}
}
#endregion
#region IPluginRawPageDisplay Members
+ /// <summary>
+ /// Portion of FogBugz API Interface which generates a completely empty page. In our case, this empty page will never be seen
+ /// by the user. Its only purpose is to provide a URL which AJAX calls can target and the page can then processes these calls.
+ /// </summary>
public string RawPageDisplay()
{
if (api.Request[api.AddPluginPrefix("action")] != null &&
- Convert.ToString(api.Request[api.AddPluginPrefix("action")]) == "postTimeIntervalComment")
+ Convert.ToString(api.Request[api.AddPluginPrefix("action")]) == "saveTimeIntervalComment")
{
// make sure the request includes a valid action token
if ((api.Request[api.AddPluginPrefix("actionToken")] == null) ||
- !api.Security.ValidateActionToken(api.Request[api.AddPluginPrefix("actionToken")],
- "postTimeIntervalComment"))
+ !api.Security.ValidateActionToken(api.Request[api.AddPluginPrefix("actionToken")], "saveTimeIntervalComment"))
{
- return "failure: action token invalid";
+ return "!!Failure!!: action token invalid";
}
else
{
int ixInterval = -1;
string sComment = "";
if (api.Request[api.AddPluginPrefix("ixInterval")] != null &&
Int32.TryParse(Convert.ToString(api.Request[api.AddPluginPrefix("ixInterval")]), out ixInterval))
{
if (api.Request[api.AddPluginPrefix("sComment")] != null)
- sComment = api.Request[api.AddPluginPrefix("sComment")].ToString();
- return PostComment(ixInterval, sComment);
+ {
+ sComment = api.Request[api.AddPluginPrefix("sComment")];
+ }
+
+ //If all error checks pass, post the user's inputted comment to the database.
+ return SaveCommentToDb(ixInterval, sComment);
}
- else return "failure: invalid ixInterval";
+ else
+ {
+ return "!!Failure!!: invalid ixInterval";
+ }
}
}
-
- else if (api.Request[api.AddPluginPrefix("action")] != null &&
- Convert.ToString(api.Request[api.AddPluginPrefix("action")]) == "getTimeIntervalComment")
+ else if (api.Request[api.AddPluginPrefix("action")] != null && Convert.ToString(api.Request[api.AddPluginPrefix("action")]) == "updateCommentText")
{
int ixInterval = -1;
if (api.Request[api.AddPluginPrefix("ixInterval")] != null &&
Int32.TryParse(Convert.ToString(api.Request[api.AddPluginPrefix("ixInterval")]), out ixInterval))
- return GetComment(ixInterval);
+ {
+ //If all error checks pass, retrieve the comment specific to the time interval index.
+ return GetCommentFromDb(ixInterval);
+ }
else
- return "failure: ixInterval invalid";
+ {
+ return "!!Failure!!: ixInterval invalid";
+ }
}
- else return "failure: command not recognized";
+ else
+ {
+ return "!!Failure!!: command not recognized";
+ }
}
+ /// <summary>
+ /// Portion of FogBugz API Interface which sets the permission level of
+ /// the empty pages used by the RawPageDisplay method.
+ /// </summary>
public PermissionLevel RawPageVisibility()
{
return PermissionLevel.Normal;
}
#endregion
- private string PostComment(int ixInterval, string sComment)
+ /// <summary>
+ /// Posts the timeinterval and comment pair into the database
+ /// </summary>
+ /// <returns>
+ /// Returns a string to confirm the the database posting was successful
+ /// </returns>
+ private string SaveCommentToDb (int ixInterval, string sComment)
{
CTimeIntervalQuery query = api.TimeInterval.NewTimeIntervalQuery();
query.AddWhere("TimeInterval.ixInterval = @ixInterval");
query.SetParamInt("@ixInterval", ixInterval);
CTimeInterval[] rgTimeIntervals = query.List();
if (rgTimeIntervals.Length > 0)
{
CTimeInterval interval = rgTimeIntervals[0];
interval.SetPluginField(sPluginId, "sComment", sComment);
interval.Commit();
}
return "success: '" + sComment + "' recorded for interval #" + ixInterval;
}
- private string GetComment(int ixInterval)
+ /// <summary>
+ /// Retrieves the comment for the specified time interval index.
+ /// </summary>
+ /// <returns>
+ /// Returns a string with the comment contained within.
+ /// </returns>
+ private string GetCommentFromDb (int ixInterval)
{
- string sComment = "";
+ string sComment = String.Empty;
CTimeIntervalQuery query = api.TimeInterval.NewTimeIntervalQuery();
query.AddWhere("TimeInterval.ixInterval = @ixInterval");
query.SetParamInt("@ixInterval", ixInterval);
CTimeInterval[] rgTimeIntervals = query.List();
if (rgTimeIntervals.Length > 0)
{
object oComment = rgTimeIntervals[0].GetPluginField(sPluginId, "sComment");
if (oComment != null)
+ {
sComment = oComment.ToString();
+ }
}
return sComment;
}
}
}
|
|
@@ -1,96 +1,276 @@ - // 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(){
+/// <summary>
+/// Capture original functionality of 'Edit Timesheet' button.
+/// Execute it and then append our custom code to add the 'Comment' link.
+/// </summary>
+var oldShow = ClockPopup.show;
+ClockPopup.show = function(){
+ var result = oldShow.apply(ClockPopup, arguments);
+ var commentLinkInserter = new CommentLinkInserter();
+ commentLinkInserter.Insert(true);
+ return result;
+}
+
+/// <summary>
+/// Capture original functionality of 'Previous Date' arrow button.
+/// Execute it and then append our custom code to add the 'Comment' link.
+/// </summary>
+var oldPrevDt = Timesheet.prevDt;
+Timesheet.prevDt = function (){
+ var result = oldPrevDt.apply(Timesheet, arguments);
+ var commentLinkInserter = new CommentLinkInserter();
+ commentLinkInserter.Insert(true);
+ return result;
+}
+
+/// <summary>
+/// Capture original functionality of 'Next Date' arrow button.
+/// Execute it and then append our custom code to add the 'Comment' link.
+/// </summary>
+var oldNextDt = Timesheet.nextDt;
+Timesheet.nextDt = function (){
+ var result = oldNextDt.apply(Timesheet, arguments);
+ var commentLinkInserter = new CommentLinkInserter();
+ commentLinkInserter.Insert(true);
+ return result;
+}
+
+/// <summary>
+/// Capture original functionality of 'Save' button after an interval has been added.
+/// Execute it and then append our custom code to add the 'Comment' links.
+/// </summary>
+var oldCommit = Timesheet.commit;
+Timesheet.commit = function (){
+ var result = oldCommit.apply(Timesheet, arguments);
+ var commentLinkInserter = new CommentLinkInserter();
+ commentLinkInserter.Insert(true);
+ return result;
+}
+
+/// <summary>
+/// Capture original functionality of 'OK' button on pop-up when 'Add Interval' is clicked.
+/// Execute it and then append our custom code to add the 'Comment' link.
+/// </summary>
+var oldSubmitEditor = Timesheet.submitEditor
+Timesheet.submitEditor = function (){
+ var result = oldSubmitEditor.apply(Timesheet, arguments);
+ var commentLinkInserter = new CommentLinkInserter();
+ commentLinkInserter.Insert(false);
+ return result;
+}
+
+/// <summary>
+///Capture original functionality of selecting a date from the TimeSheet calendar.
+///Execute it and then append our custom code to add the 'Comment' links.
+/// </summary>
+var oldCalSetDay = cal.setDay;
+cal.setDay = function (){
+ var result = oldCalSetDay.apply(cal, arguments);
+ var commentLinkInserter = new CommentLinkInserter();
+ commentLinkInserter.Insert(true);
+ return result;
+}
+
+/// <summary>
+//Capture original functionality of selecting a Time Entry Row for deletion.
+//Execute it and then append our custom code to add the 'Comment' links.
+/// </summary>
+var oldTiByIx = Timesheet.tiByIx;
+Timesheet.tiByIx = function () {
+ var result = oldTiByIx.apply(Timesheet, arguments);
+ var commentLinkInserter = new CommentLinkInserter();
+ commentLinkInserter.Insert(false);
+ return result;
+}
+
+/// <summary>
+/// Main function called by 'Edit Timesheet' and the Next/Previous date arrow buttons.
+/// Checks to see if the Timesheet table is present and that the rows in the timesheet are valid.
+/// "Valid" is defined by: The displayed date is not empty of time entries and a comment link isn't already present.
+/// See the insertCommentHtml function for a full description of the 'addFullCommentHtml' parameter
+/// </summary>
+var CommentLinkInserter = function () {
+ var numberOfRetries = 0;
+
+ var insertCommentHtmlLink = function (addFullCommentHtml) {
+ if (numberOfRetries < 50) {
+ if (isTimesheetTableValid() && isTimesheetRowValid()) {
+ insertCommentHtml(addFullCommentHtml);
+ return true;
+ }
+ setTimeout(function () { insertCommentHtmlLink(addFullCommentHtml) }, 200);
+ numberOfRetries++;
+ return false;
+ }
+ }
+
+ /// <summary>
+ ///Check if timesheet table has been generated yet
+ /// </summary>
+ var isTimesheetTableValid = function () {
+ if ($('#idTimesheetTable').length === 0) {
+ return false;
+ }
+ return true;
+ }
+
+ /// <summary>
+ /// Check if timesheet table row is "valid".
+ /// "Valid" is defined by: The displayed date is not empty of time entries and a comment link isn't already present.
+ /// </summary>
+ var isTimesheetRowValid = function () {
+ var isCommentLinkAlreadyPresent = $('.commentButton').length;
+ var isTimeEntryRowValid = $('#idTimesheetTable tr[id^="idTIRow"]').length;
+
+ return (isCommentLinkAlreadyPresent === 0 && isTimeEntryRowValid != 0) ? true : false;
+ }
+
+ /// <summary>
+ /// This method updates the DOM of the timesheet popup to include
+ /// a 'Comment' link for each existing time entry row.
+ /// </summary>
+ var insertCommentHtml = function (addFullCommentHtml) {
+ var comment;
+ var commentHtml;
+ //Add new column for 'Comments'
+ $('<th></th>').insertAfter($('#idTimesheetTable tbody tr th:last-child'));
+ $("#idTimesheetTable tbody tr").each(function (index) {
+ var thisId = $(this).attr("id");
+ //jQuery workaround: thisId returns "" in FogBugz 8.3.4.2, 'undefined' in 8.7.60.
+ thisId = (thisId == undefined) ? "" : thisId;
+ var ixInterval = thisId.substring(thisId.indexOf("_") + 1);
+ if (thisId != "" && $(this).hasClass("row") && ixInterval > 0) {
+ commentHtml = '<td colspan="2" class="commentButton"><a href="#" ixInterval="' + ixInterval + '" onclick="CommentEntryPopUp.showCommentPopUp(this); return false;" style="white-space: nowrap;">' + '[Comment]' + '</a></td>';
+ $(this).append(commentHtml);
+ updateCommentText(ixInterval, '#idTIRow_' + ixInterval + ' .commentButton a', 'text');
+ }
+ else if (thisId != null && $(this).hasClass("row") && ixInterval < 0) {
+ commentHtml = '<td "colspan="2" class="commentButton"></td>';
+ $(this).append(commentHtml);
+ }
+
+ /// Check for jquery versions 1.4 or greater, since they're the ones supporting .last jquery method
+ /// If it's less than 1.4, this plug-in will still work fine except the 'Close' button will be slightly
+ /// misaligned by one table cell.
+ if ($().jquery >= '1.4') {
+ /// The addition of the comment button adds a new td.
+ /// Therefore, all non-time entry rows must span an extra cell now
+ /// or else the cell styling will not look right.
+ var children = $(this).children();
+ var lastchild = children.last();
+ var lastchildcolspan = lastchild.attr("colspan") || 1;
+ lastchild.attr("colspan", parseInt(lastchildcolspan) + 1)
+ }
+ });
+ }
+ return {
+ Insert: insertCommentHtmlLink
+ }
+};
+
+/// <summary>
+/// FogCreek comment: This is the standard fogbugz popup code, managed by the PopupManager object
+/// It also calls updateCommentText to fetch the comment for the interval being shown.
+/// </summary>
+var CommentEntryPopUp = new function () {
var oSelf = this;
-
- this.doPopup = function(elPopupAnchor)
+ this.showCommentPopUp = function(elPopupAnchor)
{
- oSelf.Popup.setHtml(
- '<form id="TimeIntervalExamplePluginForm" onsubmit="TimeIntervalExamplePlugin.Popup.hide(); postTimeIntervalComment(); return false;">\n' +
+ var comment;
+ oSelf.Popup.setHtml(
+ '<form id="CommentEntryPopUpForm" onsubmit="CommentEntryPopUp.Popup.hide(); saveTimeIntervalComment(); return false;">\n' +
'<h1><label for="comment">Comment:</label></h1>' +
'<div>' +
'<input type="hidden" name="ixInterval">' +
- '<input type="text" id="comment" name="comment">' +
+ '<input type="text" style="padding:0px;width:40em;" 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>' +
+ '<br/><nobr style="float:right;margin-bottom:12px;margin-right:3px;"><input type="submit" value="' + FB_OK + '" class="dlgButton"> ' +
+ '<input type="button" onclick="CommentEntryPopUp.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);
+ $("#CommentEntryPopUpForm input[name=ixInterval]").val(elPopupAnchor.attributes.getNamedItem('ixInterval').value);
+ updateCommentText(elPopupAnchor.attributes.getNamedItem('ixInterval').value, '#CommentEntryPopUpForm input[name=comment]','input');
return false;
}
-
+
$(document).ready(function(){
- oSelf.Popup = api.PopupManager.newPopup("TimeIntervalExamplePlugin");
+ oSelf.Popup = api.PopupManager.newPopup("CommentEntryPopUp");
});
}();
-// 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++;
- });
+/// <summary>
+/// Function called after 'Save' is pressed on the Comment Entry pop-up. Saves comment and
+/// updates text in the main timesheet view via the 'SetCommentText...' Callback function
+/// </summary>
+function saveTimeIntervalComment() {
+ var commentText = $('#CommentEntryPopUpForm input[name=comment]').val();
+ var ixInterval = $('#CommentEntryPopUpForm input[name=ixInterval]').val();
+ var targetElement = '#idTIRow_' + ixInterval + ' .commentButton a';
+ var prefix = TrackerCommentsPlugIn.pluginPrefix;
+
+ var url = TrackerCommentsPlugIn.plugInRawPageUrl
+ + '&' + prefix + 'action=saveTimeIntervalComment'
+ + '&' + prefix + 'actionToken=' + TrackerCommentsPlugIn.PostTimeFunctionToken
+ + '&' + prefix + TrackerCommentsPlugIn.TimeIntervalForeignKeyColumnName + '=' + ixInterval
+ + '&' + prefix + 'sComment=' + encodeURIComponent(commentText);
+
+ jQuery.get(url, function () { setCommentTextForElementText(targetElement, commentText); });
}
-// 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();
+
+/// <summary>
+/// Function to update the Comment text that appears after a timesheet entry.
+/// </summary>
+function updateCommentText(ixInterval, targetElement, targetElementType) {
+ var prefix = TrackerCommentsPlugIn.pluginPrefix;
+
+ var url = TrackerCommentsPlugIn.plugInRawPageUrl
+ + '&' + prefix + 'action=updateCommentText'
+ + '&' + prefix + 'actionToken=' + TrackerCommentsPlugIn.UpdateCommentFunctionToken
+ + '&' + prefix + TrackerCommentsPlugIn.TimeIntervalForeignKeyColumnName + '=' + ixInterval;
+
+ url = decodeURIComponent(url);
+
+ switch (targetElementType) {
+ case 'text':
+ $.get(url, function (commentText) { setCommentTextForElementText(targetElement, commentText); });
+ break;
+ case 'input':
+ $.get(url, function (commentText) { setCommentTextForFormInput(targetElement, commentText); });
+ break;
+ default:
+ alert("Problem in updateTargetTextCallback function. Didn't specify a valid 'targetElementType' parameter.");
}
}
-// 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');
+
+/// <summary>
+/// Function used to dynamically rewrite existing comment text in a Form input.
+/// </summary>
+function setCommentTextForFormInput(targetElement, commentText) {
+ if (commentText.substring(0, 11) == '!!Failure!!') {
+ alert('Error: Returned comment was reported as "failed".');
}
- else
- {
- $('form#TimeIntervalExamplePluginForm input[name=comment]').val(data);
+ else {
+ $(targetElement).val(commentText);
}
}
-// runs after the comment is posted for an interval
-function postCallback(data)
-{
- alert(data);
-}
\ No newline at end of file+
+/// <summary>
+/// Function used to dynamically rewrite existing comment text for general HTML elements.
+/// </summary>
+function setCommentTextForElementText(targetElement, commentText) {
+ var truncateLength = 9;
+
+ if (commentText.substring(0, 11) == '!!Failure!!') {
+ alert('Error: Returned comment was reported as "failed".');
+ }
+ else {
+ // If the comment is empty use the default
+ commentText = (commentText != '')
+ ? commentText
+ : '[Comment]';
+ commentText = (commentText.length > truncateLength)
+ ? commentText.substring(0, truncateLength - 3) + '...'
+ : commentText;
+
+ $(targetElement).text(commentText);
+ }
+}
|
Loading...