solved Using Button Functions

TiG
TiG
@tig
7 years ago
184 posts
Looking for more details than provided by the docs.

Given a custom module (ntTracker) I need to provide a few buttons. The first button would use the hand icon (semantics = cease) and the second button would reuse the trash icon (semantics = discard). So two buttons - no more.

This template code (with, of course, the supporting PHP declarations) ...
{jrCore_item_list_buttons module="ntTracker" item=$item exclude="update"}

... renders the buttons defined in ntTracker but adds update and delete. The exclude does not work. No matter what value (or values) is placed, the extra buttons always appear.

As an alternative, the docs suggest code similar to:
Using {jrCore_item_create_button module="jrAudio" view="create" profile_id=$_profile_id title="Create Audio"}

But this requires that the appropriate function exist in core. There is no 'hand' function (for example).

Likely there is a straightforward (not reinventing the wheel) way to place select icon buttons on a list, but I do not see it. I think I need to buy a vowel from the experts at this point.


--
TiG

updated by @tig: 02/16/18 04:28:07PM
michael
@michael
7 years ago
7,715 posts
Related forum post about how to over-ride icons at skin level
https://www.jamroom.net/the-jamroom-network/forum/using-jamroom/49167/can-i-change-the-icon-for-chat

For your case you have your own module and want to define icons, take a look at jrAction module, it defines its own icons.

It has 2 folders in the img directory
/modules/jrAction/img/icons_black/at.png

Then its used in jrAction_item_index_mentions_button() function.

That will give you something to look at while I go look for why exclude="" isnt working.
michael
@michael
7 years ago
7,715 posts
If this is for a module thats going to be released, I can see you need it done via the module code, but do you know about the item action buttons

Docs: "Item Action Buttons"
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/1508/item-action-buttons
which_buttons.jpg
which_buttons.jpg  •  64KB

options_modify.jpg
options_modify.jpg  •  71KB

TiG
TiG
@tig
7 years ago
184 posts
@michael

I already had the structure in place similar to jrAction. What I did was manually configure the buttons for ntTracker as you suggested to inactivate those I inherited. That allows me to continue, but this is of course not the way we would want to handle this situation. The exclude option is exactly what we need.

Thanks for looking into this and for your advice.


--
TiG

updated by @tig: 11/16/17 05:07:58PM
michael
@michael
7 years ago
7,715 posts
this is what you're after:
{jrCore_item_list_buttons module="xxTrackme" item=$item exclude="jrCore_item_update_button,jrCore_item_delete_button"}
as a template function.

OR you can use a listener to do it for your own module too.

code from the modules include.php file
<?php
/**
 * @copyright 2017 no one
 * @author no one <noone [at] nowhere [dot] com>
 */

// make sure we are not being called directly
defined('APP_DIR') or exit();

/**
 * meta
 */
function xxTrackme_meta(){
    $_tmp = array(
        'name'        => 'Trackme',
        'url'         => 'trackme',
        'version'     => '1.0.1',
        'developer'   => 'Noone, &copy;' . strftime('%Y'),
        'description' => 'Just adds some icons and its own buttons to lists',
        'category'    => 'custom'
    );
    return $_tmp;
}

/**
 * init
 */
function xxTrackme_init(){

    jrCore_register_module_feature('jrCore', 'quota_support', 'xxTrackme', 'on');

    $_tmp = array(
        'title'  => 'Item Halt Button',
        'icon'   => 'halt',
        'active' => 'on'
    );
    jrCore_register_module_feature('jrCore', 'item_list_button', 'xxTrackme', 'xxTrackme_item_halt_button', $_tmp);

    jrCore_register_event_listener('jrCore', 'exclude_item_list_buttons', 'xxTrackme_exclude_item_list_buttons_listener');

    return true;
}

/**
 * the button for lists
 */
function xxTrackme_item_halt_button($module, $_item, $_args, $smarty, $test_only = false){
    if ($test_only) {
        return true;
    }
    $_rt = array(
        'url'     => '#',
        'onclick' => "alert('hello world')",
        'icon'    => 'halt',
        'alt'     => 'the alt text for the halt button here'
    );
    return $_rt;
}

/**
 * listener
 */
function xxTrackme_exclude_item_list_buttons_listener($_data, $_user, $_conf, $_args, $event)
{ // remove the UPDATE button $_data['jrCore_item_update_button'] = true; // remove the DELETE button $_data['jrCore_item_delete_button'] = true; return $_data; }
TiG
TiG
@tig
7 years ago
184 posts
@michael

Since I have a working solution (hoisted by your earlier 'except' workaround) I removed the workaround and included the winning syntax. Now jrCore_item_list_buttons works like a charm. Major thanks.

( Also good to know about the listener trick to implement excludes. )


--
TiG

Tags