Alright, all things aside. I am looking for opinions and tips on this small
piece of code.
This might seem like alot of code, but thats because of the comments.
I wanted a simple method of recording time-punches. I first designed this
as an inline script,
but thought that it should only need one line of code so a macro seemed
like the answer, but after actually
coding that I thought of all the parameters that are passed and the extra
code needed to make it into a
macro seemed like unnecessary overhead.
The solution I figured was to put the script in a sepperate tiddler, and
used the <<tiddler>> macro
(i.e. <<tiddler TimePunch>>) to transclude the script on-the-fly.
This wouldn't work for a script which needs parameters or more context to
function, but for this it works.
The coments seem excessive, but I used a process which I call LBL'ing
(el-bee-el-ing) which simply
means commenting the code 'Line by Line.'
If anyone has any opinions on the transclusion of inline scripts, or maybe
a better way to format the
comments within the tiddlyWiki context they would be greatly appreciated.
/%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Author: Clifford Bressette
IV
%
% Purpose: _This is like a macro except that it is designed to be
transcluded into a seperate %
% tiddler. This will put an inline script with a label of
"TimePunch" which when clicked %
% will append a table entry to the TimeSheet tiddler
recording the userName and %
% current time. These entries will be used later for various
purposes._ %
% Usage: _You must simply put <<tiddler TimePunch>> wherever you would
like the clickable %
% label to
appear._
%
% Date: _November 11,
2012
%
% Version:
1.0
%
% Last Modified: _November 11,
2012
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%/
<script label="TimePunch">
// _____________________________________________
// | Create the variable now which I then use to store a
// | snapshot of the current date/time using the global
// | Date() function
// |______________________________________________
var now=Date();
// _________________________________________________________________
// | Check to see if the user meant to enter a timepunch using a
// | system confirm dialog. append our 'now' variable to the end of the
// | confirmation message so the user can double check that the time
// | is correct. This is in an if(){}; statement so that if the user
clicks 'cancel'
// | then nothing happens.
// |_________________________________________________________________
if (confirm("Please confirm TimePunch for \n" + now)){
// _______________________________________________________________
// |Grab the TimeSheet tiddler and store it in the local object
// |TimeSheet. From here we can read/write to the local object without
// |any permanent changes to the tiddler. Later we will use
store.saveTiddler
// |to write the changes to the tiddler.
// |_______________________________________________________________
var TimeSheet=store.fetchTiddler("TimeSheet");
// _______________________________________________________________
// | Here we will use our local TimeSheet object to store our information.
// | The TimeSheet.text property currently holds the body of the TimeSheet
// | tiddler. We use this to append our txtUserName and our date/time
snapshot
// | to the end of the body. The '|' or 'pipe' symbols are used by
tiddlyWiki
// | to format this information into a table
// |_______________________________________________________________
TimeSheet.text += "|" + config.options.txtUserName + "|" + now + "|\n";
// _______________________________________________________________
// | Remember earlier when I said that we would use the store.saveTiddler
// | method to write the changes to the actual tiddler. Well, here goes.
// |_______________________________________________________________
store.saveTiddler(TimeSheet);
};
</script>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/tiddlywiki/-/a27mDTIaOIMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/tiddlywiki?hl=en.