Page 1 of 1

Batch actions

Posted: 2019-02-11 15:06
by SSchimkat
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

Re: Batch actions

Posted: 2019-02-12 11:10
by SSchimkat
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);

}

Re: Batch actions

Posted: 2019-02-12 11:26
by jsetzer
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

Re: Batch actions

Posted: 2019-02-12 16:17
by pbottcher
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);

Re: Batch actions

Posted: 2019-02-12 16:43
by jsetzer
@pböttcher: this will not work in all browsers, I'm afraid

Re: Batch actions

Posted: 2019-02-12 18:16
by SSchimkat
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

Re: Batch actions

Posted: 2019-02-12 20:21
by pbottcher
Hi,

maybe you explain a little bit in detail what you try to acheive, so there might be another solution.

Re: Batch actions

Posted: 2019-02-20 14:05
by a.gneady
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.