Toolbar module for customer portal

English! place to talk about development, programming and coding
Post Reply
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Toolbar module for customer portal

Post by Gunjan »

Hi,

I want to develop toolbar module for customer portal. How can I do this?

Thanks & Regards,
Gunjan
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Toolbar module for customer portal

Post by reneeb »

Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Re: Toolbar module for customer portal

Post by Gunjan »

Hi,

i tried to understand the concept but couldn't understand it. can you please tell me some other way or clarify it?

Thanks & Regards,
Gunjan
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Toolbar module for customer portal

Post by reneeb »

Sorry, I was referring to NavigationBar, not ToolBar.

If you want to create a ToolBar for the customer portal, you need to:

* Create SysConfig options like the ones in Frontend::Agent::ToolBarModule
* Add handling of those options in the method CustomerHeader in Kernel::Output::HTML::Layout like it was done for the Agent interface (see https://github.com/OTRS/otrs/blob/rel-3 ... t.pm#L1516)
* Add ToolBar block in CustomerHeader.dtl like the one in the Agent interface (see https://github.com/OTRS/otrs/blob/maste ... er.dtl#L27)
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Re: Toolbar module for customer portal

Post by Gunjan »

Hi,

I have done 1 & 3 point but in the 2nd point, I am facing some issue. inhttps://github.com/OTRS/otrs/blob/rel-3 ... t.pm#L1516
I have added the given code and changed according to our needs, but at line 1518, I don't know what is the issue. I am not able to use this code in sub customerheader(). Please enlighten me !

Thanks
Gunjan
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Toolbar module for customer portal

Post by reneeb »

What did you try? What error messages do you get?

Instead of UserType -> "Agent" it has to be UserType -> "Customer".
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Re: Toolbar module for customer portal

Post by Gunjan »

ya I changed 'User' to 'customer' and 'Frontend::ToolBarModule' to 'CustomerFrontend::ToolBarModule', but don't know what is the prob. when I run this code after changes made, I got internal server error everytime. Do I need to make changes somewhere else?
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Re: Toolbar module for customer portal

Post by Gunjan »

Hi,

I made a module 'ToolBarCustomerSearchProfile' like 'ToolBarTicketSearchProfile', what changes should be done in this file?

Thanks in Advance
Gunjan
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Re: Toolbar module for customer portal

Post by Gunjan »

Hello,

I found some problem in the created file 'ToolBarCustomerSearchProfile'. Please have a look in the following code:

Code: Select all

sub Run {
    my ( $Self, %Param ) = @_;

    # get user data
   [b] my %User = $Self->{UserObject}->GetUserData([/b]
        UserID => $Self->{UserID},
    );
the issue is in the bold line. Please tell me what should I write instead of this line?
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Toolbar module for customer portal

Post by reneeb »

You have to create a CustomerUserObject and use the Method CustomerUserDataGet (see http://otrs.perl-services.de/docs/otrs/ ... ruser.html )
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Re: Toolbar module for customer portal

Post by Gunjan »

I have done this. but I am not able to get customerdata in CustomerUserObject. i am using external backend for Customer User data.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Toolbar module for customer portal

Post by reneeb »

Please show more code...

Maybe you should hire a professional developer.
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Re: Toolbar module for customer portal

Post by Gunjan »

Config:

Code: Select all

<ConfigItem Name="CustomerFrontend::ToolBarModule###1-Ticket::TicketSearchProfile" Required="0" Valid="0">
        <Description Translatable="1">customer interface module to access search profiles </Description>
        <Group>Ticket</Group>
        <SubGroup>Frontend::Customer::ToolBarModule</SubGroup>
        <Setting>
            <Hash>
                <Item Key="Module">Kernel::Output::HTML::ToolBarCustomerSearchProfile</Item>
                <Item Key="Description">Search-Template</Item>
                <Item Key="Name">Search-Template</Item>
                <Item Key="Block">ToolBarSearchProfile</Item>
                <Item Key="MaxWidth">40</Item>
                <Item Key="Priority">1990010</Item>
            </Hash>
        </Setting>
    </ConfigItem>
   
ToolBarCustomerSearchProfile.pm:

Code: Select all

package Kernel::Output::HTML::ToolBarCustomerSearchProfile;

use strict;
use warnings;

use Kernel::System::SearchProfile;

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless( $Self, $Type );

    # get needed objects
    for (qw(ConfigObject LogObject DBObject TicketObject LayoutObject UserID UserObject)) {
        $Self->{$_} = $Param{$_} || die "Got no $_!";
    }

    $Self->{SearchProfileObject} = Kernel::System::SearchProfile->new(%Param);

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;

    # get user data
    my %User = $Self->{UserObject}->CustomerUserDataGet(
        UserLogin => $Self->{UserID},
    );
	
    # create search profiles string
    my $ProfilesStrg = $Self->{LayoutObject}->BuildSelection(
        Data => {
            '', '-',
            $Self->{SearchProfileObject}->SearchProfileList(
                Base      => 'TicketSearch',
                UserLogin => $User{UserLogin},
            ),
        },
        Name       => 'Profile',
        ID         => 'ToolBarSearchProfile',
        Title      => $Self->{LayoutObject}->{LanguageObject}->Get('Search template'),
        SelectedID => '',
        Max        => $Param{Config}->{MaxWidth},
    );

    my $Priority = $Param{Config}->{'Priority'};
    my %Return   = ();
    $Return{ $Priority++ } = {
        Block       => $Param{Config}->{Block},
        Description => $Param{Config}->{Description},
        Name        => $Param{Config}->{Name},
        Image       => '',
        Link        => $ProfilesStrg,
        AccessKey   => '',
    };
$Self->{LogObject}->Log(
                	Priority => 'error',
                	Message =>"@{[%Return]}\n"
                	);

    return %Return;
}

1;
code in customerHeader.dtl:

Code: Select all

<!-- dtl:block:ToolBar -->
        <ul id="ToolBar">
<!-- dtl:block:ToolBarItem -->
            <li class="$QData{"Class"}"><a href="$Data{"Link"}" accesskey="$QData{"AccessKey"}" title="$Text{"$Data{"Description"}"}: $QData{"Count"}$QData{"AccessKeyReference"}">$Text{"$Data{"Description"}"} <i class="icon-small icon-time icon-show-reached"></i> <i class="icon-small icon-star icon-show-new"></i><i class="$QData{"Icon"}"></i> <span class="Counter">$QData{"Count"}</span> </a></li>
<!-- dtl:block:ToolBarItem -->
<!-- dtl:block:ToolBarSearchProfile-->
            <li class="Extended SearchProfile">
                <form action="$Env{"CGIHandle"}" method="post" name="SearchProfile">
                    <input type="hidden" name="Action" value="CustomerTicketSearch"/>
                    <input type="hidden" name="Subaction" value="LoadProfile"/>
                    <input type="hidden" name="SearchTemplate" value="$Text{"Search"}"/>
                    $Data{"Link"}
#                    <a href="#" id="ToolbarProfileSearch" title="$Text{"$Data{"Description"}"}  ($QData{"AccessKey"})" accesskey="$QData{"AccessKey"}" $Data{"LinkOption"}>$Text{"$Data{"Name"}"}</a>
                </form>
            </li>
<!-- dtl:js_on_document_complete -->
            <script type="text/javascript">//<![CDATA[
                $('#ToolBarSearchProfile').bind('change', function (Event) {
                    $(Event.target).closest('form').submit();
                    Event.preventDefault();
                    Event.stopPropagation();
                    return false;
                });
            //]]></script>
<!-- dtl:js_on_document_complete -->
<!-- dtl:block:ToolBarSearchProfile-->
        </ul>
<!-- dtl:block:ToolBar -->

Code in Layout.pm:

Code: Select all

# run tool bar item modules
   	if ( $Self->{UserID} && $Self->{UserType} eq 'Customer' ) {

        	my $ToolBarModule = $Self->{ConfigObject}->Get('CustomerFrontend::ToolBarModule');
        	if ( $Param{ShowToolbarItems} && ref $ToolBarModule eq 'HASH' ) {

            		my %Modules;
            		my %Jobs = %{$ToolBarModule};

            		for my $Job (sort keys %Jobs ) {
                		# load and run module
                		next if !$Self->{MainObject}->Require( $Jobs{$Job}->{Module} );
                		my $Object = $Jobs{$Job}->{Module}->new( %{$Self},LayoutObject => $Self );
                		next if !$Object;
                		%Modules = ( $Object->Run( %Param, Config => $Jobs{$Job} ), %Modules );				
            		}

            		# show tool bar items
            		my $ToolBarShown = 0;
            		for my $Key ( sort keys %Modules ) {
               	next if !%{ $Modules{$Key} };

                	# show tool bar wrapper
                	if ( !$ToolBarShown ) {
                    		$ToolBarShown = 1;
                    		$Self->Block(
                        		Name => 'ToolBar',
                        		Data => \%Param,
                    		);
                	}
                	$Self->Block(
                    		Name => $Modules{$Key}->{Block},
                    		Data => {
                        		%{ $Modules{$Key} },
                        		AccessKeyReference => $Modules{$Key}->{AccessKey}
                        		? " ($Modules{$Key}->{AccessKey})"
                        		: '',
                    		},
                	);

		}

   	 	# show logged in notice
        	if ( $Param{ShowPrefLink} ) {
            		$Self->Block(
                	Name => 'Login',
                	Data => \%Param,
            		);
        	}
        	else {
            		$Self->Block(
                		Name => 'LoginWithoutLink',
                		Data => \%Param,
            		);
        	}

        	# show logout button (if registered)
        	if (
            		$Param{ShowLogoutButton}
            		&& $Self->{ConfigObject}->Get('Frontend::Module')->{Logout}
            	   )
        	{
            		$Self->Block(
                		Name => 'Logout',
                		Data => \%Param,
            		);
        	}

	}
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Toolbar module for customer portal

Post by reneeb »

(Changes to your code marked with "# <-----"

ToolBarCustomerSearchProfile.pm:

Code: Select all

[...]
sub Run {
    my ( $Self, %Param ) = @_;

    # get user data
    my %User = $Self->{UserObject}->CustomerUserDataGet(
        User => $Self->{UserID},                                                         # <-----
    );
	
    # create search profiles string
    my $ProfilesStrg = $Self->{LayoutObject}->BuildSelection(
        Data => {
            '', '-',
            $Self->{SearchProfileObject}->SearchProfileList(
                Base      => 'CustomerTicketSearch',                                         # <-----
                UserLogin => $User{UserLogin},
            ),
        },[...]
Code in Layout.pm:

Code: Select all

# run tool bar item modules
        if ( !$Param{ShowToolbarItems} ) {                                                               # <-----
            $Param{ShowToolbarItems} = 1;                                         # <-----
        }                                                                                                 # <-----

   	if ( $Self->{UserID} && $Self->{UserType} eq 'Customer' ) {

[...]
You can remove this code

Code: Select all

   	 	# show logged in notice
        	if ( $Param{ShowPrefLink} ) {
            		$Self->Block(
                	Name => 'Login',
                	Data => \%Param,
            		);
        	}
        	else {
            		$Self->Block(
                		Name => 'LoginWithoutLink',
                		Data => \%Param,
            		);
        	}

        	# show logout button (if registered)
        	if (
            		$Param{ShowLogoutButton}
            		&& $Self->{ConfigObject}->Get('Frontend::Module')->{Logout}
            	   )
        	{
            		$Self->Block(
                		Name => 'Logout',
                		Data => \%Param,
            		);
        	}

	}
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Re: Toolbar module for customer portal

Post by Gunjan »

SearchProfile dropdown is still not visible on customer interface. Did I put the right code in CustomerHeader.dtl file? can you tell me the right place where I should put this code?
Thanks
Gunjan
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Toolbar module for customer portal

Post by reneeb »

You should put the .dtl code here

Code: Select all

<!-- dtl:block:DebugRTLButton -->
# <----
    </div>
Did you add those three lines in Layout.pm to activate "ShowToolbarItems"?
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Re: Toolbar module for customer portal

Post by Gunjan »

i have put all the code. but the problem is when I put the code in 'layout.pm', I got internal server error everytime.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Toolbar module for customer portal

Post by reneeb »

Gunjan wrote:i have put all the code. but the problem is when I put the code in 'layout.pm', I got internal server error everytime.
What do the logs say (OTRS log, webserver log)?
Can you post the complete code of Layout.pm that fails?

Sometimes it is really hard to help you as you do not post all information! If something fails, please post the error messages, the log messages, the code and what you have tried to debug the error...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Re: Toolbar module for customer portal

Post by Gunjan »

Hi,

Thanks for your support :) Field is visible now and working fine.

Regards,
Gunjan
kalyana1315
Znuny expert
Posts: 171
Joined: 24 Apr 2013, 12:29
Znuny Version: OTRS3.3
Real Name: kalyanachakravarthy M P
Company: TATA Technologies
Location: Pune,India
Contact:

Re: Toolbar module for customer portal

Post by kalyana1315 »

Gunjan wrote:Hi,

Thanks for your support :) Field is visible now and working fine.

Regards,
Gunjan

Hi Gujan

please once update working code
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Re: Toolbar module for customer portal

Post by Gunjan »

Hi kalyana,

working Code in Layout.pm :

Code: Select all

# run tool bar item modules
	if ( !$Param{ShowToolbarItems} ) {                                                              
        	$Param{ShowToolbarItems} = 1;                                         
	}  
		
    	if ( $Self->{UserID} && $Self->{UserType} eq 'Customer' ) {
        	my $ToolBarModule = $Self->{ConfigObject}->Get('CustomerFrontend::ToolBarModule');
        	if ( $Param{ShowToolbarItems} && ref $ToolBarModule eq 'HASH' ) {
            		my %Modules;
            		my %Jobs = %{$ToolBarModule};
            		for my $Job ( sort keys %Jobs ) {

                		# load and run module
                		next if !$Self->{MainObject}->Require( $Jobs{$Job}->{Module} );
                		my $Object = $Jobs{$Job}->{Module}->new(
                    			%{$Self},
                    			LayoutObject => $Self,
                		);
                		next if !$Object;
                		%Modules = ( $Object->Run( %Param, Config => $Jobs{$Job} ), %Modules );
            		}

            		# show tool bar items
            		my $ToolBarShown = 0;
            		for my $Key ( sort keys %Modules ) {
                		next if !%{ $Modules{$Key} };

                		# show tool bar wrapper
                		if ( !$ToolBarShown ) {
                    			$ToolBarShown = 1;
                    			$Self->Block(
                        			Name => 'ToolBar',
                        			Data => \%Param,
                    			);
                		}
                		$Self->Block(
                    			Name => $Modules{$Key}->{Block},
                    			Data => {
                        			%{ $Modules{$Key} },
                        			AccessKeyReference => $Modules{$Key}->{AccessKey}
                        			? " ($Modules{$Key}->{AccessKey})"
                        			: '',
                    			},
                		);
            		}
        	}
	}	
rest code is mentioned in the earlier posts.
kalyana1315
Znuny expert
Posts: 171
Joined: 24 Apr 2013, 12:29
Znuny Version: OTRS3.3
Real Name: kalyanachakravarthy M P
Company: TATA Technologies
Location: Pune,India
Contact:

Re: Toolbar module for customer portal

Post by kalyana1315 »

Thank you Very much Gunjan :D :D
Gunjan
Znuny expert
Posts: 228
Joined: 09 Dec 2013, 06:37
Znuny Version: 3.3.x

Re: Toolbar module for customer portal

Post by Gunjan »

Hi,

I also want to show this 'search profile' dropdown on 'ActionRow' of customer interface. I wrote the below code but not working

Code: Select all

<ConfigItem Name="CustomerFrontend::Module###ToolBarModule" Required="0" Valid="1">
        <Description Translatable="1">Frontend module registration for the agent interface.</Description>
        <Group>Ticket</Group>
        <SubGroup>Frontend::Customer::ModuleRegistration</SubGroup>
        <Setting>
            <FrontendModuleReg>
                <Description>ToolBar Module for customer interface</Description>
                <Title>Customer ToolBar Module </Title>
                <NavBarName>Ticket</NavBarName>
		  <NavBar>
			 
                    <Description Translatable="1">Search-Template</Description>
     			<Name Translatable="1">Search-Template</Name>
			<Link>Action=ToolBarCustomerSearchProfile</Link>
                    <LinkOption></LinkOption>
			<Block>ToolBarSearchProfile</Block>
                     <Type>Menu</Type>
			<Prio>900</Prio>
                </NavBar>				
            </FrontendModuleReg>
        </Setting>
</ConfigItem>
what should I add in this code??
Post Reply