Jump to content

Make "Active" view selected by default when viewing "My Products & Services" from client area


akust0m

Recommended Posts

Hello :)

 

When navigating to either one of the following client area pages, all services are shown regardless of whether they are active, terminated, cancelled etc..

 

https://example.com/clientarea.php?action=services

https://example.com/clientarea.php?action=domains

 

You can filter the results by clicking on one of the "View" buttons on the left.

 

However, is there a way to have "Active" set by default?

 

Thanks!

Link to comment
Share on other sites

  • 3 years later...

Same question, is there a an easy way to have "Active" set by default? So that the users do not have to click it manually?
 

The user should be able to display the expired and other services if needed (so we cannot use a hook to remove the expired services).

Edited by dandju
Link to comment
Share on other sites

Given that my jQuery skills are poor, I'd simply trigger the "click" event on the sidebar on document ready like follows.

<script type="text/javascript">
    jQuery(document).ready( function ()
    {
        var table = jQuery('#tableServicesList').removeClass('hidden').DataTable();
        {if $orderby == 'product'}
            table.order([0, '{$sort}'], [3, 'asc']);
        {elseif $orderby == 'amount' || $orderby == 'billingcycle'}
            table.order(1, '{$sort}');
        {elseif $orderby == 'nextduedate'}
            table.order(2, '{$sort}');
        {elseif $orderby == 'domainstatus'}
            table.order(3, '{$sort}');
        {/if}
        table.draw();
        jQuery('#tableLoading').addClass('hidden');

         // I'M HERE! I TRIGGER THE CLICK EVENT ON THE SIDEBAR TO FILTER ACTIVE SERVICES
        $("a#Primary_Sidebar-My_Services_Status_Filter-Active").trigger("click");
    });
</script>

 

Link to comment
Share on other sites

Hi @Kian

Thanks for the suggestion. Was thinking of something similar, but was not sure how to "trigger" the click in Javascript.

I have tried it using the suggested method but still nothing happens - furthermore it seems that the filter no longer works when adding the "trigger" method.

Do you have another idea?

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

I checked this one more time and can confirm that @Kian's solution is working:

$("#Primary_Sidebar-My_Services_Status_Filter-Active").trigger("click");

The only "problem" is that the click is triggered on every page load, of course --> When the filter is set to active and the page is reloaded, the filter is removed because of the triggered click.

Is there a way to get the current filter status which can be used to prevent the click in case it is active already?

Link to comment
Share on other sites

Change it like follows:

if ($( "div[menuitemname='My Services Status Filter'] a[class='list-group-item active']").attr('menuitemname') != 'Active')
{
	$("a#Primary_Sidebar-My_Services_Status_Filter-Active").trigger("click");
}

 

Link to comment
Share on other sites

Thank you, @Kian.

Exactly what I was looking for. Just had to remove the "a" from the trigger line, everything working as expected:

if ($( "div[menuitemname='My Services Status Filter'] a[class='list-group-item active']").attr('menuitemname') != 'Active')
{
	$("#Primary_Sidebar-My_Services_Status_Filter-Active").trigger("click");
}

 

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

Hi guys, sure this is the a hook doing this job for you.

Its tested on WHMCS 8.1 and later versions.

<?php

add_hook('ClientAreaFooterOutput', 1, function ($vars) {
    if ($vars['filename'] === 'clientarea') {
        return <<<HTML
<script>
    function selectActiveService() {
        if (window.location.href.indexOf("clientarea.php?action=services") > -1) {
            var activeServiceLink = document.getElementById("Primary_Sidebar-My_Services_Status_Filter-Active");
            if (activeServiceLink && !activeServiceLink.classList.contains("active")) {
                activeServiceLink.click();
            } else {
                return true;
            }
        }
        return false;
    }

    function keepTryingToSelectActiveService() {
        var intervalId = setInterval(function() {
            if (selectActiveService()) {
                clearInterval(intervalId);
            }
        }, 100);
    }

    document.addEventListener("DOMContentLoaded", function() {
        keepTryingToSelectActiveService();
    });
</script>
HTML;
    }
});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated