[Rt-commit] r4456 - in rt/branches/CHALDEA-EXPERIMENTAL:
html/Admin/CustomFields html/Elements html/NoAuth lib/RT
jesse at bestpractical.com
jesse at bestpractical.com
Tue Jan 31 20:16:39 EST 2006
Author: jesse
Date: Tue Jan 31 20:16:39 2006
New Revision: 4456
Added:
rt/branches/CHALDEA-EXPERIMENTAL/html/NoAuth/ahah.js
Modified:
rt/branches/CHALDEA-EXPERIMENTAL/ (props changed)
rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/CustomFields/Modify.html
rt/branches/CHALDEA-EXPERIMENTAL/html/Elements/Header
rt/branches/CHALDEA-EXPERIMENTAL/html/Elements/ShowCustomFields
rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm
rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/ObjectCustomFieldValue_Overlay.pm
Log:
r23030 at truegrounds: jesse | 2006-01-31 18:51:02 -0500
* Added the ability to make custom fields link to and include content from other systems.
Modified: rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/CustomFields/Modify.html
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/CustomFields/Modify.html (original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/CustomFields/Modify.html Tue Jan 31 20:16:39 2006
@@ -98,6 +98,31 @@
<INPUT TYPE=CHECKBOX NAME="Enabled" VALUE="1" <%$EnabledChecked%>> <&|/l&>Enabled (Unchecking this box disables this custom field)</&>
</td>
</tr>
+<tr>
+<td class="label"><&|/l&>Link values to</&></td>
+</td>
+<td><input size="60" name="LinkValueTo" value="<%$CustomFieldObj->LinkValueTo%>" />
+<div class="hints">
+<&|/l&>RT can make this custom field's values into hyperlinks to another service.</&>
+<&|/l&>Fill in this field with a URL.</&>
+<&|/l&>RT will replace <tt>__id__</tt> and <tt>__CustomField__</tt> with the record id and custom field value, respectively</&>
+</div>
+</td>
+</tr>
+<tr>
+<td class="label"><&|/l&>Include page</&></td>
+</td>
+<td><input size="60" name="IncludeContentForValue" value="<%$CustomFieldObj->IncludeContentForValue%>" />
+<div class="hints">
+<&|/l&>RT can include content from another web service when showing this custom field.</&>
+<&|/l&>Fill in this field with a URL.</&>
+<&|/l&>RT will replace <tt>__id__</tt> and <tt>__CustomField__</tt> with the record id and custom field value, respectively</&>
+</div>
+</td>
+</tr>
+
+
+
</table>
<BR>
% if ($CustomFieldObj->Id && $CustomFieldObj->IsSelectionType) {
@@ -140,7 +165,7 @@
$CustomFieldObj->Load($id) || $m->comp("/Elements/Error", Why => loc('No CustomField') );
$title = loc( 'Editing CustomField [_1]', $CustomFieldObj->Name() );
- my @attribs = qw( Pattern Name TypeComposite LookupType Description);
+ my @attribs = qw( Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue);
my @aresults = UpdateRecordObject( AttributesRef => \@attribs,
Object => $CustomFieldObj,
ARGSRef => \%ARGS );
Modified: rt/branches/CHALDEA-EXPERIMENTAL/html/Elements/Header
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/html/Elements/Header (original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/html/Elements/Header Tue Jan 31 20:16:39 2006
@@ -56,6 +56,7 @@
<link media="print" rel="stylesheet" href="<%$RT::WebPath%>/NoAuth/printrt.css" type="text/css" />
<script type="text/javascript" src="<%$RT::WebPath%>/rt.js"></script>
+<script type="text/javascript" src="<%$RT::WebPath%>/NoAuth/ahah.js"></script>
<& /Elements/Callback, _CallbackName => 'Head', %ARGS &>
</HEAD>
<BODY BGCOLOR="<%$BgColor%>"
Modified: rt/branches/CHALDEA-EXPERIMENTAL/html/Elements/ShowCustomFields
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/html/Elements/ShowCustomFields (original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/html/Elements/ShowCustomFields Tue Jan 31 20:16:39 2006
@@ -53,12 +53,33 @@
<ul>
% while (my $Value = $Values->Next()) {
<li>
+% if ($CustomField->LinkValueTo) {
+<a href="<%$Value->LinkValueTo|n%>">
+% }
% my $comp = "ShowCustomField".$CustomField->Type;
% if ($m->comp_exists($comp)) {
<& $comp, Object => $Value &>
% } else {
<%$Value->Content%>
% }
+% if ($CustomField->LinkValueTo) {
+</a>
+% }
+
+%# This section automatically populates a div with the "IncludeContentForValue" for this custom
+%# field if it's been defined
+% if ($CustomField->IncludeContentForValue) {
+<div
+ class="object_cf_value_include"
+ id="object_cf_value_<%$Value->id%>"
+ >
+<&|/l, '<a href="'.$Value->IncludeContentForValue.'">' . $Value->IncludeContentForValue."</a>"&>See also: [_1]</&>
+</div>
+
+<script><!--
+ ahah('<%$Value->IncludeContentForValue%>', 'object_cf_value_<%$Value->id%>');
+ --></script>
+% }
</li>
% }
% unless ($Values->Count()) {
Added: rt/branches/CHALDEA-EXPERIMENTAL/html/NoAuth/ahah.js
==============================================================================
--- (empty file)
+++ rt/branches/CHALDEA-EXPERIMENTAL/html/NoAuth/ahah.js Tue Jan 31 20:16:39 2006
@@ -0,0 +1,31 @@
+% $r->content_type('application/x-javascript');
+// Fetching http://www.opendarwin.org/~drernie/src/ahah.js
+function ahah(url, target, delay) {
+ document.getElementById(target).innerHTML = 'Loading <a href="'+url+'">'+url +'</a>...';
+ if (window.XMLHttpRequest) {
+ req = new XMLHttpRequest();
+ } else if (window.ActiveXObject) {
+ req = new ActiveXObject("Microsoft.XMLHTTP");
+ }
+ if (req != undefined) {
+ req.onreadystatechange = function() {ahahDone(url, target, delay);};
+ req.open("GET", url, true);
+ req.send("");
+ }
+}
+
+function ahahDone(url, target, delay) {
+ if (req.readyState == 4) { // only if req is "loaded"
+ if (req.status == 200) { // only if "OK"
+ document.getElementById(target).innerHTML = req.responseText;
+ } else {
+ document.getElementById(target).innerHTML="Error loading '"+url+"':\n"+req.statusText;
+ }
+ if (delay != undefined) {
+ setTimeout("ahah(url,target,delay)", delay); // resubmit after delay
+ //server should ALSO delay before responding
+ }
+ }
+}
+
+% $m->abort();
Modified: rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm (original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm Tue Jan 31 20:16:39 2006
@@ -1219,6 +1219,77 @@
}
-# }}}
+=head2 IncludeContentForValue [VALUE] (and SetIncludeContentForValue)
+
+Gets or sets the C<IncludeContentForValue> for this custom field. RT
+uses this field to automatically include content into the user's browser
+as they display records with custom fields in RT.
+
+=cut
+
+sub SetIncludeContentForValue {
+ shift->IncludeContentForValue(@_);
+}
+sub IncludeContentForValue{
+ my $self = shift;
+ $self->_URLTemplate('IncludeContentForValue', @_);
+}
+
+
+
+=head2 LinkValueTo [VALUE] (and SetLinkValueTo)
+
+Gets or sets the C<LinkValueTo> for this custom field. RT
+uses this field to make custom field values into hyperlinks in the user's
+browser as they display records with custom fields in RT.
+
+=cut
+
+
+sub SetLinkValueTo {
+ shift->LinkValueTo(@_);
+}
+
+sub LinkValueTo {
+ my $self = shift;
+ $self->_URLTemplate('LinkValueTo', @_);
+
+}
+
+
+=head2 _URLTemplate NAME [VALUE]
+
+With one argument, returns the _URLTemplate named C<NAME>, but only if
+the current user has the right to see this custom field.
+
+With two arguments, attemptes to set the relevant template value.
+
+=cut
+
+
+
+sub _URLTemplate {
+ my $self = shift;
+ my $template_name = shift;
+ if (@_) {
+
+ my $value = shift;
+ unless ( $self->CurrentUserHasRight('AdminCustomField') ) {
+ return ( 0, $self->loc('Permission Denied') );
+ }
+ $self->SetAttribute( Name => $template_name, Content => $value );
+ return ( 1, $self->loc('Updated') );
+ } else {
+ unless ( $self->id && $self->CurrentUserHasRight('SeeCustomField') ) {
+ return (undef);
+ }
+
+ my @attr = $self->Attributes->Named($template_name);
+ my $attr = shift @attr;
+
+ if ($attr) { return $attr->Content }
+
+ }
+}
1;
Modified: rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/ObjectCustomFieldValue_Overlay.pm
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/ObjectCustomFieldValue_Overlay.pm (original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/ObjectCustomFieldValue_Overlay.pm Tue Jan 31 20:16:39 2006
@@ -166,6 +166,12 @@
}
+=head2 Object
+
+Returns the object this value applies to
+
+=cut
+
sub Object {
my $self = shift;
my $Object = $self->__Value('ObjectType')->new($self->CurrentUser);
@@ -173,9 +179,82 @@
return($Object);
}
+
+=head2 Delete
+
+Disable this value. Used to remove "current" values from records while leaving them in the history.
+
+=cut
+
+
sub Delete {
my $self = shift;
$self->SetDisabled(1);
}
+=head2 _FillInTemplateURL URL
+
+Takes a URL containing placeholders and returns the URL as filled in for this
+ObjectCustomFieldValue.
+
+Available placeholders:
+
+=over
+
+=item __id__
+
+The id of the object in question.
+
+=item __CustomField__
+
+The value of this custom field for the object in question.
+
+=back
+
+=cut
+
+sub _FillInTemplateURL {
+
+ my $self = shift;
+
+ my $url = shift;
+
+ $url =~ s/__id__/@{[$self->ObjectId]}/g;
+ $url =~ s/__CustomField_/@{[$self->Content]}/g;
+
+ return $url;
+}
+
+
+=head2 ValueLinkURL
+
+Returns a filled in URL template for this ObjectCustomFieldValue, suitable for
+constructing a hyperlink in RT's webui. Returns undef if this custom field doesn't have
+a LinkValueTo
+
+=cut
+
+sub LinkValueTo {
+ my $self = shift;
+ return $self->_FillInTemplateURL($self->CustomFieldObj->LinkValueTo);
+}
+
+
+
+=head2 ValueIncludeURL
+
+Returns a filled in URL template for this ObjectCustomFieldValue, suitable for
+constructing a hyperlink in RT's webui. Returns undef if this custom field doesn't have
+a IncludeContentForValue
+
+=cut
+
+sub IncludeContentForValue {
+ my $self = shift;
+ return $self->_FillInTemplateURL($self->CustomFieldObj->IncludeContentForValue);
+}
+
+
+
+
1;
More information about the Rt-commit
mailing list