[rt-users] RTFM WikiText Format Toolbar

2007-12-18 Thread Miguel A. Rivera Rivera

Wanted to integrate a simple way to format the WikiText Custom field in RTFM.



Copy: /opt/rt3/share/html/Elements/EditCustomFieldWikitext to
  /opt/rt3/local/html/Elements/EditCustomFieldWikitext
Edit: /opt/rt3/local/html/Elements/EditCustomFieldWikitext

Add before % while: 

% my $wiki_textarea_value = $NamePrefix .$CustomField-id .'-Values';

% my $wiki_format_toolbar = qq(
% div
% input type=button 
onclick=javascript:lbc(event,'$wiki_textarea_value','bold'); 
style=font-weight: bold; value=B
% input type=button 
onclick=javascript:lbc(event,'$wiki_textarea_value','italic'); 
style=font-weight: bold; value=I
% input type=button 
onclick=javascript:lbc(event,'$wiki_textarea_value','bold_italic'); 
style=font-weight: bold;font-style: italic; value=BI
% input type=button 
onclick=javascript:lbc(event,'$wiki_textarea_value','heading'); value=H1
% input type=button 
onclick=javascript:lbc(event,'$wiki_textarea_value','subheading'); value=H2
% input type=button 
onclick=javascript:lbc(event,'$wiki_textarea_value','subsubheading'); 
value=H3
% input type=button 
onclick=javascript:lbc(event,'$wiki_textarea_value','list'); value=List
% input type=button 
onclick=javascript:lbc(event,'$wiki_textarea_value','link'); value=Link
% /div
% );

% print $wiki_format_toolbar;

Add in both textarea tags:

textarea ... id=%$NamePrefix%%$CustomField-Id%-Values.../textarea



Copy: /opt/rt3/share/html/RTFM/Article/Edit.html to
  /opt/rt3/local/html/RTFM/Article/Edit.html

Add before form:

script type=text/javascript 

function lbc(e, objname, theTag) { 
var el = document.getElementById(objname);

var enclosingTag;
var spaceTag = '\ ';

if(theTag == 'bold'){
startTag = '\'\'\'';
endTag = '\'\'\'';
spaceTag = '';
}
if(theTag == 'italic'){
startTag = '\'\'';
endTag = '\'\'';
spaceTag = '';
}
if(theTag == 'bold_italic'){
startTag = '\'\'\'\'\'';
endTag = '\'\'\'\'\'';
spaceTag = '';
}
if(theTag == 'heading'){
startTag = '=';
endTag = '=';
}
if(theTag == 'subheading'){
startTag = '==';
endTag = '==';
}
if(theTag == 'subsubheading'){
startTag = '=';
endTag = '=';
}
if(theTag == 'link'){
startTag = '[';
endTag = ']';
}
if(theTag == 'list'){
startTag = '\ \ \ \ *\ ';
endTag = '';
}

if (el.setSelectionRange) { 

//Mozilla or FireFox Code 

var st = el.scrollTop; 
var ss = el.selectionStart; 
var se = e.selectionEnd; 
el.value = el.value.substring(0,el.selectionStart) + startTag + 
spaceTag + el.value.substring(el.selectionStart,el.selectionEnd) + spaceTag + 
endTag + el.value.substring(el.selectionEnd,el.value.length); 
el.selectionStart = ss; 
el.selectionEnd = ss; 
el.scrollTop = st; 
} 
else if (document.selection  document.selection.createRange) { 

//Internet Explorer Code 

el.focus(); //Makes sure tags are being added to the textarea 
var range = document.selection.createRange(); 
range.text = startTag + spaceTag + range.text + spaceTag + 
endTag; //Adds beginning and end tags. 
} 
el.focus(); 
} 

/script



Miguel Rivera

___
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

SAVE THOUSANDS OF DOLLARS ON RT SUPPORT:

If you sign up for a new RT support contract before December 31, we'll take
up to 20 percent off the price. This sale won't last long, so get in touch 
today. 
Email us at [EMAIL PROTECTED] or call us at +1 617 812 0745.


Community help: http://wiki.bestpractical.com
Commercial support: [EMAIL PROTECTED]


Discover RT's hidden secrets with RT Essentials from O'Reilly Media. 
Buy a copy at http://rtbook.bestpractical.com

[rt-users] Set TimeWorked automatically

2007-12-13 Thread Miguel A. Rivera Rivera
Hi,

Searching on past threads, I couldn't find how to set the TimeWorked 
automatically when a ticket was resolved, taking into account the Started and 
the Resolved dates. This prompted me to developed the following Scrip, which 
uses Date::Calc to find the date difference and update the TimeWorked field. 
Does RT already provide such an option?

Thanks,

Miguel

Condition: On Resolve
Action: User Defined
Template: Global template: Blank
Stage: TransactionCreate
Custom action preparation code: 1;
Custom action cleanup code:
---
use Date::Calc qw(Delta_DHMS);

my $time_elapsed = 0;

my $date_started_string = $self-TicketObj-Started;
my $date_resolved_string = $self-TicketObj-Resolved;

my (@date_started,@date_resolved);

if ($date_started_string =~ /(\d+)\-(\d+)\-(\d+)\s(\d+)\:(\d+)\:(\d+)/) {
@date_started = ($1, $2, $3, $4, $5, $6);
}

if ($date_resolved_string =~ /(\d+)\-(\d+)\-(\d+)\s(\d+)\:(\d+)\:(\d+)/) {
@date_resolved = ($1, $2, $3, $4, $5, $6);
}

my @diff = Delta_DHMS(@date_started, @date_resolved);

my $day_to_minutes = $diff[0] * 1440;
my $hour_to_minutes = $diff[1] * 60;

my $time_elapsed_sum = $day_to_minutes + $hour_to_minutes + $diff[2];

if($time_elapsed_sum  0){
$time_elapsed = qq($time_elapsed_sum\.$diff[3]);
}

$RT::Logger-debug(Setting TimeWorked to: $time_elapsed);

$self-TicketObj-SetTimeWorked( $time_elapsed );
---

___
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

SAVE THOUSANDS OF DOLLARS ON RT SUPPORT:

If you sign up for a new RT support contract before December 31, we'll take
up to 20 percent off the price. This sale won't last long, so get in touch 
today. 
Email us at [EMAIL PROTECTED] or call us at +1 617 812 0745.


Community help: http://wiki.bestpractical.com
Commercial support: [EMAIL PROTECTED]


Discover RT's hidden secrets with RT Essentials from O'Reilly Media. 
Buy a copy at http://rtbook.bestpractical.com