Selectable drop down list with registered users

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
landinialejandro
AppGini Super Hero
AppGini Super Hero
Posts: 126
Joined: 2016-03-06 00:59
Location: Argentina
Contact:

Selectable drop down list with registered users

Post by landinialejandro » 2020-11-07 22:33

Hello, I want to leave you in this opportunity a function that allows you to list all the users of the application.
The first thing they need is that there is a text type field in the destination table, it doesn't need anything special.
Then they need to put the function somewhere where it can be accessed at any time, for example in header-extras.php.

Inside the tablename-dv.js file, place the function call. the only parameters that we pass are the name of the table and the field where the data is to be saved.

I hope you find it useful both to me.

function definition:

Code: Select all

/**
 * Construct a selectable drop down list with registered users.
 * @param {string} f - Field name to replace wit drop-down list.
 * @param {string} t - table name destiny.
 */
function users_dropdown(f, t) {
    var $selectField = $j('#' + f + '').hide();
    var $span = $j('<span/>', { id: 's2_users_' + f });
    $selectField.closest('div').append($span);
    var val = $selectField.val();

    $span.select2({
        width: '100%',
        formatNoMatches: function(term) { return 'No matches found!'; },
        minimumResultsForSearch: 5,
        loadMorePadding: 200,
        escapeMarkup: function(m) { return m; },
        ajax: {
            url: 'admin/getUsers.php',
            dataType: 'json',
            cache: true,
            data: function(term, page) { return { s: term, p: page, t: t }; },
            results: function(resp, page) { return resp; }
        }
    }).on('change', function(e) {
        $j('[name="' + f + '"]').val(e.added.id);
    });
    if (val) {
        $span.select2('data', { text: val, id: val });
    }
}
caller fucntion inside tablename-dv.js

Code: Select all

t = 'contacto';
f = 'user';
users_dropdown(f, t);
The attachment normal_text.gif is no longer available
Attachments
function_list_user_he.png
function_list_user_he.png (73.25 KiB) Viewed 1360 times
function_list_user.png
function_list_user.png (11.89 KiB) Viewed 1360 times
combo.gif
combo.gif (128.67 KiB) Viewed 1360 times
normal_text.gif
normal_text.gif (27.1 KiB) Viewed 1360 times
Alejandro.
AppGini 5.98 - Linux OpenSuse Tumblewweed.

Some of my posts that may interest you:
:arrow: Landini Admin Template: Template for Appgini like AdminLTE
:arrow: Profile image plugin: add and changue image user profile
:arrow: Field editor in table view: Configurable fast edit fields in TV
:idea: my personal page

User avatar
a.gneady
Site Admin
Posts: 1287
Joined: 2012-09-27 14:46
Contact:

Re: Selectable drop down list with registered users

Post by a.gneady » 2020-11-12 11:31

Thanks Landini :)
Just a headsup: this would work only for admin user.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

User avatar
landinialejandro
AppGini Super Hero
AppGini Super Hero
Posts: 126
Joined: 2016-03-06 00:59
Location: Argentina
Contact:

Re: Selectable drop down list with registered users

Post by landinialejandro » 2020-11-12 16:00

a.gneady wrote:
2020-11-12 11:31
Thanks Landini :)
Just a headsup: this would work only for admin user.
Hello! thanks. Yes, I forgot to say it is a condition that only works for the admin. since it should be the only one that assigns a directory to a data record.
Alejandro.
AppGini 5.98 - Linux OpenSuse Tumblewweed.

Some of my posts that may interest you:
:arrow: Landini Admin Template: Template for Appgini like AdminLTE
:arrow: Profile image plugin: add and changue image user profile
:arrow: Field editor in table view: Configurable fast edit fields in TV
:idea: my personal page

Post Reply