Paradigm for variable application parameters

56 views
Skip to first unread message

Manos Pappas

unread,
Sep 7, 2022, 8:23:39 AM9/7/22
to Jam.py Users Mailing List
Hello,

I am writing an application in Jam that uses the paradigms of custom login and multitenancy. I have two questions that I would like some advice on how to do it (a short example code would be appreciated as I am not so proficient in Javascript).

Question 1: The application on the custom users table has extra fields (besides the ones described in the above page) that I would like to have available globally in the app for the logged-on user session. Could the user_info attribute be extended to include more fields that could be populated during the on_login server module of the task object?

Question 2 (more of the same of Q1 due to somehow messed up Javascript variables scopes in my head): I have an item called ItemA (real table) with the following fields: datestart (TEXT), dateend (TEXT), rnvz (INTEGER). From another item (ItemB) client module (inside the on_view_form_created() function), I have the following code:

function on_view_form_created(item) {
    var koskperiod = item.task.itema.copy({handlers: false});
    var koskdatestart = "";
    var koskdateend = "";
    var koskrandevouz = 0;

    koskperiod.open(
        {
            fields: ['datestart','dateend','rnvz'],
            where: {isactive: true}
        },
        function() {                
            koskperiod.each(function(t) {
                koskdatestart = t.datestart.display_text;
                koskdateend = t.dateend.display_text;
                koskrandevouz = t.rnvz.display_text;
            });
        }
    );
    alert(koskrandevouz);

//  more code after here
}

My problem is obvious: the variables (e.g koskrandevouz) are not available on the main body of the on_view_form_created() function and cannot be used from the section after // more code... According to various Javascripts tutorials I've tried, defining the variables within the top of the function would make them available within the on_view_form_created() function, unless I did not understand correctly.

And this comes to my initial question 1: is there some programming paradigm that can be used to create some sort of runtime application "dictionary" that can hold variables to be used within the whole jam.py application scope?

Again, thank you very much in advance for any help and suggestion.

Regards,
Manos

Andrew Yushev

unread,
Sep 7, 2022, 8:32:27 AM9/7/22
to Manos Pappas, Jam.py Users Mailing List
Manos, you can create a dictionary attribute of the task in the on_page_loaded event handler and
initialize it.
For example

function on_page_loaded(task) {
   task.my_app_params = {}
}

ср, 7 сент. 2022 г. в 15:23, Manos Pappas <front...@gmail.com>:
--
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/bb174c87-1c95-4738-9363-70ff2c66c44an%40googlegroups.com.

Manos Pappas

unread,
Sep 7, 2022, 2:01:33 PM9/7/22
to Jam.py Users Mailing List
Hi Andrew,

Thank you very much for your help.
According to your example and the documentation, the event handler on_page_loaded of the task tree can serve as a global namespace for the client part of the jam application, right?

Andrew Yushev

unread,
Sep 8, 2022, 4:20:33 AM9/8/22
to Manos Pappas, Jam.py Users Mailing List
Manos, the task is a global variable on the client side and can be used in any module.

ср, 7 сент. 2022 г. в 21:01, Manos Pappas <front...@gmail.com>:

Manos Pappas

unread,
Sep 9, 2022, 6:36:02 AM9/9/22
to Jam.py Users Mailing List
Thank you Andrew,

Unfortunately, I cannot make it work.

Here is my code.

function on_page_loaded(task) {
    // init some global variables
    task.myemx_userAFM = "noafm";    // AFM of the logged user
    task.myemx_koskdatestart = new Date();
    task.myemx_koskdateend = new Date();
    task.myemx_koskrandevouz = 0;
    task.myemx_koskfromkg = 0;
    task.myemx_kosktokg = 0;
    task.myemx_koskplace = "";
    task.myemx_kosksakperhr = 0;

//rest init code
}

I've initialized my variables there (task.myemx_xxxxx). Next, I want to update some of these on the on_view_form_created() event on a different item.

function on_view_form_created(item) {
    // populate randevouz and date period fields
    var koskperiod = item.task.paramkosk.copy({handlers: false});

    koskperiod.open(
        {
            fields: ['datestart','dateend','randevou','fromkg','tokg'],

            where: {isactive: true}
        },
        function() {                
            koskperiod.each(function(t) {
                task.myemx_koskdatestart = t.datestart;
                task.myemx_koskdateend = t.dateend;
                task.myemx_koskrandevouz = t.randevou;
                task.myemx_koskfromkg = t.fromkg;
                task.myemx_kosktokg = t.tokg;
                $("#kosk_datestart").val(item.task.myemx_koskdatestart.display_text);
                $("#kosk_dateend").val(item.task.myemx_koskdateend.display_text);
                $("#kosk_randevouz").val(item.task.myemx_koskrandevouz.display_text);    // displays '1' which is the correct
            });
        }
    );

    // more code

    item.warning(task.myemx_koskrandevouz);   // displays '0' which is incorrect
}

What I am doing wrong?

Andrew Yushev

unread,
Sep 9, 2022, 10:59:11 AM9/9/22
to Manos Pappas, Jam.py Users Mailing List
Manos, 

In the line

task.myemx_koskrandevouz = t.randevou

you assign the field to the task.myemx_koskrandevouz,
t.datestart is a field.
And in

item.warning(task.myemx_koskrandevouz)

you want to use it as a text parameter.

Maybe the reason is this.
Try to do it this way

task.myemx_koskrandevouz = t.randevou.display_text;
$("#kosk_randevouz").val(task.myemx_koskrandevouz); 
item.warning(task.myemx_koskrandevouz)

пт, 9 сент. 2022 г. в 13:36, Manos Pappas <front...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages