Batch actions

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
SSchimkat
Veteran Member
Posts: 31
Joined: 2018-01-04 18:49

Batch actions

Post by SSchimkat » 2019-02-11 15:06

Hi everyone

Playing around with batch actions, and wondering if the are other arguments available than (table_name, ids)?

I would like to use a argument like (table_name, array_of_content_from_column3, array_of_content_from_column6). Would that be possible?

Best regards, Søren

SSchimkat
Veteran Member
Posts: 31
Joined: 2018-01-04 18:49

Re: Batch actions

Post by SSchimkat » 2019-02-12 11:10

I actully got it working, with an Ajax call for retrieving the needed data for the clipboard. It all works just fine .. but only when using Chrome. Other browsers are preventing me from writing to the clipboard - and i'm kinda stuck.

I know this is becomming more of a Javascript question, rather than a AppGini question - but perhaps some Javascript aficionado could share a hint? :-)

Code: Select all

function CopyPackageNames(table_name, ids){

        var query = 'table=' + table_name;
        for(var i = 0; i < ids.length; i++){
                query = query + '&'
                        + encodeURI('ids[]') + '='
                        + encodeURIComponent(ids[i]);
        }

        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {

                if (this.readyState == 4 && this.status == 200) {

                //      navigator.permissions.query({name: "clipboard-write"}).then(result => {
                //              if (result.state == "granted" || result.state == "prompt") {
                //                      navigator.clipboard.writeText(this.responseText).then(function() {
                //                              modal_window({ message: '<div class="alert alert-info">Package names has been copied to the clipboard.</div>', title: "Package names copied"});
                //                      }, function() {
                //                              modal_window({ message: '<div class="alert alert-warning">Error: Package names has not been copied to the clipboard.</div>', title: "Error with accessing the clipboard"});
                //                      });
                //              } else {
                //                      // ...
                //              }
                //      });


                        var TempVar = document.createElement("textarea");
                        document.body.appendChild(TempVar);
                        TempVar.innerHTML = this.responseText;
                        TempVar.select();
                        document.execCommand("copy");
                        document.body.removeChild(TempVar);

                        modal_window({ message: '<div class="alert alert-info">Package names has been copied to the clipboard.</div>', title: "Package names copied"});

                }

        };

        xhttp.open("POST", "GetPackageNames.php", true);
        xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhttp.send(query);

}

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Batch actions

Post by jsetzer » 2019-02-12 11:26

Due to the fact that there is not a single way to implement clipboard-copy, I have done if the following way in one of my ASP.NET projects:
  • Show a modal dialog with a textarea
  • Put the text into the textarea
  • .focus() the textarea
  • .select() the textarea, so the whole text will be selected
  • There is a hint that user's should press [CTRL]+[C] now (or CMD+C)
  • So user copies the text to the clipboard by using the well-known shortcut
  • I'm listening for keystrokes and on keystroke of CTRL+C I close the modal dialog
Different approach, sure, but working in all browsers my customer is using.

Hope this helps!
Regards,
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Batch actions

Post by pbottcher » 2019-02-12 16:17

Hi,
not sure what exactly you try to acheive, but maybe you can try:

Code: Select all

                       var TempVar = document.createElement("textarea");
                        document.body.appendChild(TempVar);
                        TempVar.textcontent = this.responseText;
                        TempVar.focus();
                        TempVar.setSelectionRange(0, target.value.length);
                        document.execCommand("copy");
                        document.body.removeChild(TempVar);
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Batch actions

Post by jsetzer » 2019-02-12 16:43

@pböttcher: this will not work in all browsers, I'm afraid
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

SSchimkat
Veteran Member
Posts: 31
Joined: 2018-01-04 18:49

Re: Batch actions

Post by SSchimkat » 2019-02-12 18:16

It would seem that the problem is all about security. It would work in all (or most) browsers, it if call my function from a click event.

The error message from Firefox ..

document.execCommand(‘cut’/‘copy’) was denied because it was not called from inside a short running user-generated event handler.

.. lead me to this page - kinda explaining the problem: https://developer.mozilla.org/en-US/doc ... _clipboard

This is going to be tricky to get around. :-o

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Batch actions

Post by pbottcher » 2019-02-12 20:21

Hi,

maybe you explain a little bit in detail what you try to acheive, so there might be another solution.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

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

Re: Batch actions

Post by a.gneady » 2019-02-20 14:05

SSchimkat wrote:
2019-02-11 15:06
I would like to use a argument like (table_name, array_of_content_from_column3, array_of_content_from_column6). Would that be possible?
Hmm ... You can retrieve this content knowing the ids by using JavaScript code like this:

Code: Select all

var col6 = [];
for(var i = 0; i < ids.length; i++) {
    col6.push($j('#tablename-fieldname-' + ids[i]).text());
}
Replace tablename and field name above with actual table and field names.
: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.

Post Reply