ActionRow in .tt file

English! place to talk about development, programming and coding
Post Reply
EXG133
Znuny expert
Posts: 217
Joined: 06 Aug 2012, 18:12
Znuny Version: 3.1.7 & 4.04

ActionRow in .tt file

Post by EXG133 »

In a WorkOrder you have the ActionRow. I'm trying to understand how it's built up (what controls the buttons shown) and the part in red confuses me:

[% RenderBlockStart("Menu") %]
[% RenderBlockStart("MenuItem") %]
<li>
<a href="[% Env("Baselink") %][% Data.Link | Interpolate %]" id="Menu[% Data.MenuID | html %]" class="[% Data.MenuClass | html %]" title="[% Translate(Data.Description) | html %]">[% Translate(Data.Name) | html %]</a>
</li>

[% RenderBlockStart("ShowConfirmationDialog") %]
[% WRAPPER JSOnDocumentComplete %]
<script type="text/javascript">//<![CDATA[
/*global ITSM: true */
ITSM.Agent.ConfirmationDialog.BindConfirmationDialog({
ElementID: 'Menu[% Data.MenuID %]',
ElementSelector: '[% Data.ElementSelector | Interpolate %]',
DialogContentQueryString: '[% Data.DialogContentQueryString | Interpolate %]',
ConfirmedActionQueryString: '[% Data.ConfirmedActionQueryString | Interpolate %]',
DialogTitle: '[% Data.DialogTitle | Interpolate %]',
TranslatedText: {
Yes: [% Translate("Yes") | JSON %],
No: [% Translate("No") | JSON %],
Ok: [% Translate("Ok") | JSON %]
}
});
//]]></script>
[% END %]
[% RenderBlockEnd("ShowConfirmationDialog") %]

[% RenderBlockEnd("MenuItem") %]
[% RenderBlockEnd("Menu") %]
</ul>
</div>

I can see the result is something like this:

<a href="/otrs/index.pl?Action=AgentITSMChangeEdit;ChangeID=1121" id="Menu030-Edit" class="AsPopup" title="Edit the change">Edit</a>

I've been reading all the docs on the tt website and it just doesn't click where I can find what defines the content of [% Env("Baselink") %][% Data.Link | Interpolate %] . Are we telling tt to interpolate the value of the variable Link ?
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: ActionRow in .tt file

Post by RStraub »

Hello there and welcome to the broad field of modding OTRS :)

The syntax Env("NameOfAVariable") tells the file that produces HTML pages and parses OTRS-specific code (let's call it template generator) to take the value of an enviroment variable and just write that value down. In this case, it's the Baselink, which resolves to something like "Full-Qualified-Domain-Name/otrs/index.pl?".

The second part is different, as it is not the value of an enviroment variable, but a local variable used by your module. There are always (well most of the time) two files that generate html content:
- The Perl Module (.pm) which gathers data and aggregates it
- The Template File (.dtl or .tt) which tells the template generator how the html page will be arranged like

So, if you would take a look into the according .pm file, you'd see that somewhere in there, the hash "Data" will contain a key called "Link". The value assigned by the perl file then is used instead of [% Data.Link | Interpolate %].

Does this clarify things for you :) ?
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
EXG133
Znuny expert
Posts: 217
Joined: 06 Aug 2012, 18:12
Znuny Version: 3.1.7 & 4.04

Re: ActionRow in .tt file

Post by EXG133 »

I checked the /opt/otrs/Kernel/Modules/AgentITSMWorkOrderZoom.pm but couldn't find where %Data is defined.

So I suspect the magic is hiding in this part?

# start template output
$Output .= $Self->{LayoutObject}->Output(
TemplateFile => 'AgentITSMWorkOrderZoom',
Data => {
%{$Change},
%{$WorkOrder},
},
);

The templatefile in every pm file seems to be called through /Kernel/Output/HTML/LayoutTemplate.pm so it seems plausible. Except I still don't see where Link is coming from if I look at the sub Output.. All I can find about Link is related to LinkObject which I don't think is what I'm looking for.

I don't know if it's just me but I find following ITSM stuff more complicated than the tickets :o
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: ActionRow in .tt file

Post by RStraub »

https://github.com/OTRS/ITSMChangeManag ... om.pm#L447

Thath's where the entry for the template file is generated and the hash called "Data" gets it's Key/Value pair "Link"
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
EXG133
Znuny expert
Posts: 217
Joined: 06 Aug 2012, 18:12
Znuny Version: 3.1.7 & 4.04

Re: ActionRow in .tt file

Post by EXG133 »

There goes what little confidence I had in Perl! :(

I think what confused me is the comments about Dynamic Fields around that area, I will read through it and hopefully figure it out.
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: ActionRow in .tt file

Post by RStraub »

Well, sorry. Read your Question too generic, as there was so much text :)

You are looking for the building of a menu item. What I linked you are dynamic fields, you are very correct.

The menu is build in:
ITSMWorkOrderMenuGeneric.pm

In the template file you can read

Code: Select all

[% RenderBlockStart("MenuItem") %]
So if you look in the perl module for the Block that is called MenuItem, you'll find that the link has to be created here:
https://github.com/OTRS/ITSMChangeManag ... ric.pm#L91

Sorry again, was too lazy :(

EDIT:

Then again, there you won't find info about the Link. I suggest that you dump the $Param{WorkOrder} hashref and see what it contains.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
EXG133
Znuny expert
Posts: 217
Joined: 06 Aug 2012, 18:12
Znuny Version: 3.1.7 & 4.04

Re: ActionRow in .tt file

Post by EXG133 »

Anything that improves my understanding is welcome! :)
I will post again if I find how it works, thanks a lot for the assistance.
EXG133
Znuny expert
Posts: 217
Joined: 06 Aug 2012, 18:12
Znuny Version: 3.1.7 & 4.04

Re: ActionRow in .tt file

Post by EXG133 »

This seems to work:

AgentITSMWorkOrderEdit.pm

Code: Select all

# check permissions
    my $Access = $Self->{ChangeObject}->Permission(
        Type        => $Self->{Config}->{Permission},
        Action      => $Self->{Action},
        ChangeID    => $WorkOrder->{ChangeID},
        WorkOrderID => $WorkOrderID,
        UserID      => $Self->{UserID},
    );

    # CUSTOM - force provide access to edit button if the active agent is the workorder agent (WorkOrderAgentID = UserID) #
    if ( !$Access ) {
        if ( $Param{WorkOrder}{WorkOrderAgentID} = $Self->{UserID} ) {
            $Access = 1;
        }
    }
ITSMWorkOrderMenuWithPermissionFromChange.pm

Code: Select all

   if ( !$RequiredPriv ) {

        # Display the menu-link, when no privilege is required
        $Access = 1;
    }
    # CUSTOM - show the editmenu if the active user is the workorderagent (WorkOrderAgentID = UserID) #
    elsif (     ($Param{WorkOrder}{WorkOrderAgentID} = $Self->{UserID})
           and ($Param{MenuID} eq "030-Edit") ){
        $Access = 1;
    }
 
Post Reply