Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest w2grid pass 'cmd' to remote data source, php, problem #1837

Closed
Rimokas opened this issue Jun 13, 2019 · 8 comments
Closed

Latest w2grid pass 'cmd' to remote data source, php, problem #1837

Rimokas opened this issue Jun 13, 2019 · 8 comments

Comments

@Rimokas
Copy link

Rimokas commented Jun 13, 2019

*I'm submitting a ...
[x] bug report

  • What is the current behavior?
    Not working as expected.

  • What is the expected behavior?

Older source of w2grid:

    request: function (cmd, add_params, url, callBack) {
            if (add_params == null) add_params = {};
            if (url == '' || url == null) url = this.url;
            if (url == '' || url == null) return;
            // build parameters list
            var params = {};
            if (!w2utils.isInt(this.offset)) this.offset = 0;
            if (!w2utils.isInt(this.last.xhr_offset)) this.last.xhr_offset = 0;
            // add list params
            params['cmd']         = cmd;
            params['selected']    = this.getSelection();
            params['limit']       = this.limit;
            params['offset']      = parseInt(this.offset) + parseInt(this.last.xhr_offset);
            params['search']      = this.searchData;
            params['searchLogic'] = this.last.logic;
            params['sort']        = this.sortData;
    

As you can see, "params[ 'cmd' ]" exist.

Now in the latest w2grid :

    request: function (cmd, add_params, url, callBack) {
            if (add_params == null) add_params = {};
            if (url == '' || url == null) url = this.url;
            if (url == '' || url == null) return;
            // build parameters list
            if (!w2utils.isInt(this.offset)) this.offset = 0;
            if (!w2utils.isInt(this.last.xhr_offset)) this.last.xhr_offset = 0;
            // add list params
            var params = {
                limit       : this.limit,
                offset      : parseInt(this.offset) + parseInt(this.last.xhr_offset),
                searchLogic : this.last.logic,
                search: this.searchData.map(function (search) {
                        var _search = $.extend({}, search);
                        if (this.searchMap && this.searchMap[_search.field]) _search.field = this.searchMap[_search.field];
                        return _search;
                    }.bind(this)),
                sort: this.sortData.map(function (sort) {
                        var _sort = $.extend({}, sort);
                        if (this.sortMap && this.sortMap[_sort.field]) _sort.field = this.sortMap[_sort.field];
                        return _sort;
                    }.bind(this))
            }
            if (this.searchData.length === 0) {
                delete params['search'];
                delete params['searchLogic'];
            }
            if (this.sortData.length === 0) {
                delete params['sort'];
            }
            // append other params
            $.extend(params, this.postData);
            $.extend(params, add_params);
            // event before
            if (cmd == 'get') {
                var edata = this.trigger({ phase: 'before', type: 'request', target: this.name, url: url, postData: params, httpHeaders: this.httpHeaders });
                if (edata.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return; }
            } else {
                var edata = { url: url, postData: params, httpHeaders: this.httpHeaders };
            }
            // call server to get data
    

I can't to find in which place parameter of "cmd" will be send to php file ... :(

Php :

        $prm     = $_REQUEST[ 'request' ];
    $rqs     = json_decode( $prm, true );
    $cmd     = $rqs[ 'cmd' ];
    

It return an error, that not exist "cmd" ...

How to work with the latest w2ui and remote data source through php ? Or it's bug here ?

Thanks in advance ...

@mpf82
Copy link
Collaborator

mpf82 commented Jun 13, 2019

Looks like a bug, especially since params.cmd is accessed later in the code: https://github.com/vitmalina/w2ui/blob/master/src/w2grid.js#L2459

This change has been introduced during this PR: 5f7e598#diff-8b4d4a6961edfba8a65c282e9645abb3L2376

Seems that selected is also gone from params.

Maybe @mrg2001 can explain the reason behind this change.

@Rimokas
Copy link
Author

Rimokas commented Jun 14, 2019

Hi,

Thanks for the answer ...
How to draw his attention to this problem ?

@vitmalina
Copy link
Owner

Guys, cmd parameter is no longer being passed to the server because it is redundant. In the code mentioned by @mpf82, it looks like it is a variable in that function, not something that is passed to the server. The reason it is removed is because now you can specify different urls for different commands, for example for get data you can set a url

url: {
   get: 'some_url?cmd=get',
   save: 'same_url?cmd=save',
   remove: 'some_url?cmd=remove'
}

However, if url is the same and defined as a string, you still on the server side can figure out the function by method it sends. It will sent GET, PUT, DELETE methods as defined by dataType. See http://w2ui.com/web/docs/1.5/w2utils.settings

@vitmalina
Copy link
Owner

In addition, you can also use postData that are additional params to be send to the server. Also you can overwrite methods for all grids and introduce your own processing, see http://w2ui.com/web/docs/1.5/utils

@Rimokas
Copy link
Author

Rimokas commented Jun 22, 2019

Thanks, Vitali
Understand, now after some small changes it's working ...
I'm check in out for "selected" - how to pass them ?

@vitmalina
Copy link
Owner

vitmalina commented Jun 22, 2019

there is an event onRequest, you can add/modify params that will be sent there :)

@Rimokas
Copy link
Author

Rimokas commented Jun 23, 2019 via email

@mpf82
Copy link
Collaborator

mpf82 commented Jun 24, 2019

@vitmalina I don't think removing cmd from the parameters was a good idea. For JSON dataType, the methos ist always POST - you can no longer figure out what the original command is on the server side if you have a single server URL that handles all the AJAX communication - that's actually the case in our application.

We cannot even add the command to postData in the before phase, because the event trigger

a) only is executed for command get
b) does not receive the original command as a parameter

Please add the cmd parameter back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants