Filter on dialog form

20 views
Skip to first unread message

Fabio Lenzarini

unread,
Apr 19, 2024, 9:44:08 AMApr 19
to Jam.py Users Mailing List
hello everyone,
I have a table with the struttira:
project; task; task-of
so I can have:
project 1, task 1
project 1, task 2, task-of 1
project 1, task 3, task-of 1

project 1, task 4
project 1, task 5, task-of 4
project 1, task 6, task-of 4

for various reasons, I need to be able to move groups of tasks from one parent task to another.
jampy_dialog form.png

jampy_dialog form 2.png
i created the function: set task

function set_task_of(item) {
    var copy = item.copy({handlers: false}),
        selections = item.selections;
       
    if (selections.length > 1000) {
        item.alert('Too many records selected.');
    }
    else if (selections.length || item.rec_count) {        
        if (selections.length === 0) {
            selections = [item.id.value];
        }
       
        copy.set_fields(['project', 'task_of']);
        copy.open({open_empty: true});

        copy.edit_options.title = 'Set Task of to ' + selections.length + ' record(s)';
        copy.edit_options.history_button = false;
        copy.edit_options.required = true;
       

        copy.on_edit_form_created = function(c) {

            c.edit_form.find("#item_text").hide();
            c.edit_form.find('#ok-btn').off('click.task').on('click', function() {
                try {
                    c.post();
                    item.server('set_task_of', [c.task_of.value, selections], function(res, error) {
                        if (error) {
                            item.alert_error(error);
                        }
                        if (res) {
                            item.selections = [];
                            item.refresh_page(true);
                            c.cancel_edit();
                            item.alert(selections.length + ' record(s) have been modified.');
                        }
                    });
                }
                finally {
                    c.edit();
                }
            });
        };
        copy.append_record();
    }
}

now, in the lookup that pops up on the task-of, I would like to filter by project....
but i can't do it..

some suggestion?

thanks
Fabio

Danijel Kaurin

unread,
Apr 19, 2024, 1:27:41 PMApr 19
to Fabio Lenzarini, Jam.py Users Mailing List
Hi Fabio.

Please see my code upgrade:

function set_task_of(item) {
    var copy = item.copy({handlers: false}),
        selections = item.selections;
       
    if (selections.length > 1000) {
        item.alert('Too many records selected.');
    }
    else if (selections.length || item.rec_count) {        
        if (selections.length === 0) {
            selections = [item.id.value];
        }
       
        copy.set_fields(['project', 'task_of']);
        copy.open({open_empty: true});

        copy.edit_options.title = 'Set Task of to ' + selections.length + ' record(s)';
        copy.edit_options.history_button = false;
        copy.edit_options.required = true;
       
copy.on_field_select_value = function(field, lookup_item) {
if (field.field_name === 'task_of' && lookup_item) {
lookup_item.set_where({project: copy.project.value});
--
You received this message because you are subscribed to the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jam-py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jam-py/593c2ce7-a006-4a54-81fe-891b73dc4df7n%40googlegroups.com.

Fabio Lenzarini

unread,
Apr 19, 2024, 3:28:00 PMApr 19
to Danijel Kaurin, Jam.py Users Mailing List
Thanks Danjel!

work fine!

ciao e buon weekend!

Fabio Lenzarini

unread,
Apr 19, 2024, 3:47:56 PMApr 19
to Danijel Kaurin, Jam.py Users Mailing List
Would it be possible to complete the project with the values I have in the task table?

I've try some line of code.. but don't work

function set_task_of(item) {
    var copy = item.copy({handlers: false}),
        selections = item.selections;
        
    if (selections.length > 1000) {
        item.alert('Too many records selected.');
    }
    else if (selections.length || item.rec_count) {        
        if (selections.length === 0) {
            selections = [item.id.value];
        }
        
        copy.set_fields(['project', 'task_of']);
        copy.open({open_empty: true});

        copy.edit_options.title = 'Set Task of to ' + selections.length + ' record(s)';
        copy.edit_options.history_button = false;
        copy.edit_options.required = true;

        copy.on_field_select_value = function(field, lookup_item) {

        lookup_item.project.value = item.project.value;

        if (field.field_name === 'task_of' && lookup_item) {
            lookup_item.set_where({project: copy.project.value});
            }
        };        

        copy.on_edit_form_created = function(c) {
            c.edit_form.find("#item_text").hide();
            c.edit_form.find('#ok-btn').off('click.task').on('click', function() {
                try {
                    c.post();
                    item.server('set_task_of', [c.project.value, c.task_of.value, selections], function(res, error) {
                        if (error) {
                            item.alert_error(err

Fabio Lenzarini

unread,
Apr 20, 2024, 10:23:11 AMApr 20
to Danijel Kaurin, Jam.py Users Mailing List
Found:
        copy.on_edit_form_created = function(c) {
            
            c.project.value = item.project.value;
            c.project.lookup_value = item.project.lookup_value;
            
            c.edit_form.find("#item_text").hide();
            c.edit_form.find('#ok-btn').off('click.task').on('click', function() {
                try {
                    c.post();
                    item.server('set_task_of', [c.project.value, c.task_of.value, selections], function(res, error) {
                        if (error) {
                            item.alert_error(error);
                        }
                        if (res) {
                            item.selections = [];
                            item.refresh_page(true);
                            c.cancel_edit();
                            item.alert(selections.length + ' record(s) have been modified.');
                        }
                    });
                }
                finally {
                    c.edit();
                }
            });
        };
Reply all
Reply to author
Forward
0 new messages