Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    sendQueue GET/POST problem

    Hi,
    I'm using SmartClient_v82p_2012-09-11_LGPL and copied a code from smartclient wiki to drag/drop order listgrid rows.
    (http://wiki.smartclient.com/display/...rsistent+order)

    My problem is that is my Datasource is defined with postParams
    Everything is fine with all request send with post method except the row ordering queue.

    The queue make a request to "/data?id=2&userOrder=1&_operationType=update&_oldValues=%7B%22userOrder%22%3A%222%22%7D&_componentId=refsList&_dataSource=ds_refs&isc_metaDataPrefix=_&isc_dataFormat=json"

    not just simple to "/data"

    i wanted to make a request with post params only.

    Datasource Code:
    Code:
    isc.RestDataSource.create({
    			ID: 'ds_refs',
    			operationBindings: [{operationType:"fetch", dataProtocol:"postParams"},{operationType:"add", dataProtocol:"postParams"},{operationType:"update", dataProtocol:"postParams"},{operationType:"remove", dataProtocol:"postParams"}],
    			dataFormat: 'json',
    			fetchDataURL: '/data',
    			addDataURL: '/data',
    			removeDataURL: '/data',
    			updateDataURL: '/data',
    
    			fields: [
    				{name: 'id', primaryKey: true},
    				{name: 'name'},
    				{name: 'photo'},
    				{name: 'description'},
    				{name: 'category'},
    				{name: 'public'},
    				{name: 'userOrder'}
    			],
    		});
    recordDrop Code:
    Code:
    recordDrop : function (dropRecords, targetRecord, targetIndex, sourceWidget) {
            if (this == sourceWidget && dropRecords.length != 0) {
                var data = this.data;
                var dropRecordIndices = dropRecords.map(function (record) {
                    return data.findIndex("id", record.id);
                });
    
                var indicesMin = Math.min(dropRecordIndices.min(), targetIndex);
                var indicesMax = Math.max(dropRecordIndices.max(), targetIndex - 1);
    
                var startedQueue = !isc.RPCManager.startQueue();
                var ds = isc.DS.get(this.dataSource); 
                var request = {
                    operation:this.updateOperation,
                    application:this.application,
                    willHandleError:true,
                    oldValues:{ userOrder:0 },
                    componentId:this.ID
                };
    
                // Update the 'userOrder' fields for all records at indices [indicesMin, indicesMax].
                var userOrders = new Array(indicesMax + 1 - indicesMin);
                var i;
                for (i = indicesMin; i <= indicesMax; ++i) {
                    var record = data.get(i);
                    userOrders[i - indicesMin] = record.userOrder;
                }
                var numDropRecordsAfterOrAtTargetIndex = 0;
                for (i = indicesMax; i >= targetIndex; --i) {
                    if (dropRecordIndices.contains(i)) {
                        ++numDropRecordsAfterOrAtTargetIndex;
                    }
                }
                var numDropRecordsBeforeTargetIndex = dropRecords.length - numDropRecordsAfterOrAtTargetIndex;
                var j = 0; // how many drop records have been encountered so far.
                for (i = indicesMin; i < targetIndex; ++i) {
                    var record = data.get(i);
                    request.oldValues.userOrder = record.userOrder;
                    request._originalRecord = isc.shallowClone(record);
    
                    var updates = ds.filterPrimaryKeyFields(record);
                    if (dropRecordIndices.contains(i)) {
                        updates.userOrder = record.userOrder = userOrders[targetIndex - numDropRecordsBeforeTargetIndex + j - indicesMin];
                        ++j;
                    } else {
                        updates.userOrder = record.userOrder = userOrders[i - j - indicesMin];
                    }
                    ds.updateData(updates, null, request);
                }
                j = 0;
                for (i = indicesMax; i >= targetIndex; --i) {
                    var record = data.get(i);
                    request.oldValues.userOrder = record.userOrder;
                    request._originalRecord = isc.shallowClone(record);
    
                    var updates = ds.filterPrimaryKeyFields(record);
                    if (dropRecordIndices.contains(i)) {
                        updates.userOrder = record.userOrder = userOrders[targetIndex + numDropRecordsAfterOrAtTargetIndex - 1 - j - indicesMin];
                        ++j;
                    } else {
                        updates.userOrder = record.userOrder = userOrders[i + j - indicesMin];
                    }
                    ds.updateData(updates, null, request);
                }
    
                // If we're queuing, send the queue now.
                if (startedQueue) {
                    isc.RPCManager.sendQueue(null, null, null, true);
                }
            }
    
            // Call the super implementation of recordDrop() to update the order of rows in the ListGrid.
            this.Super("recordDrop", arguments);
        }
    Thanks
    Last edited by kicsiKAPA; 11 Sep 2012, 09:27. Reason: missing code tag

    #2
    Anybody can help me please?

    I have to make a request with only POST variables, cos the server doesn't accept GET variables. I can't break this wall. Couldn't found anything about this in forum and with google too.

    Listgrid operation(update/delete/add) works fine. I can't understand the example smart order code from wiki why don't make a request passing only POST variables to the server.

    Header information from google chrome when i'm trying to reorder rows
    Code:
    Request URL:http://xxxx.com/data?id=2&userOrder=1&_operationType=update&_oldValues=%7B%22userOrder%22%3A%222%22%7D&_componentId=refsList&_dataSource=ds_refs&isc_metaDataPrefix=_&isc_dataFormat=json
    Request Method:POST
    Status Code:200 OK
    Request Headersview source
    Accept:*/*
    Accept-Charset:ISO-8859-2,utf-8;q=0.7,*;q=0.3
    Accept-Encoding:gzip,deflate,sdch
    Accept-Language:hu-HU,hu;q=0.8,en-US;q=0.6,en;q=0.4
    Connection:keep-alive
    Content-Length:68
    Content-Type:text/xml
    Cookie:PHPSESSID=1c98d7401e88eaff02591e43f8cf3004
    Host:wangogh.com
    Origin:http://xxxx.com
    Referer:http://xxxx.com/admin
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
    Query String Parametersview URL encoded
    id:2
    userOrder:1
    _operationType:update
    _oldValues:{"userOrder":"2"}
    _componentId:refsList
    _dataSource:ds_refs
    isc_metaDataPrefix:_
    isc_dataFormat:json
    Request Payload
    { "transaction": { "transactionNum": 4, "operations": [null, null]}}
    Response Headersview source
    Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Connection:close
    Content-Encoding:gzip
    Content-Length:270
    Content-Type:text/html
    Date:Wed, 12 Sep 2012 09:16:55 GMT
    Expires:Thu, 19 Nov 1981 08:52:00 GMT
    Pragma:no-cache
    Vary:Accept-Encoding
    X-Powered-By:PHP/5.2.14

    And here is a correct one when i'm adding a new record
    Code:
    Request URL:http://xxxx.com/data
    Request Method:POST
    Status Code:200 OK
    Request Headersview source
    Accept:*/*
    Accept-Charset:ISO-8859-2,utf-8;q=0.7,*;q=0.3
    Accept-Encoding:gzip,deflate,sdch
    Accept-Language:hu-HU,hu;q=0.8,en-US;q=0.6,en;q=0.4
    Connection:keep-alive
    Content-Length:168
    Content-Type:application/x-www-form-urlencoded; charset=UTF-8
    Cookie:PHPSESSID=1c98d7401e88eaff02591e43f8cf3004
    Host:wangogh.com
    Origin:http://xxxx.com
    Referer:http://xxxx.com/admin
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
    Form Dataview URL encoded
    name:test
    description:test describe
    category:1
    _operationType:add
    _oldValues:{}
    _componentId:refsForm
    _dataSource:ds_refs
    isc_metaDataPrefix:_
    isc_dataFormat:json
    Response Headersview source
    Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Connection:close
    Content-Length:100
    Content-Type:application/x-json
    Date:Wed, 12 Sep 2012 09:21:50 GMT
    Expires:Thu, 19 Nov 1981 08:52:00 GMT
    Pragma:no-cache
    X-Powered-By:PHP/5.2.14
    If somebody has an idea please help me!

    Many thanks!

    Comment

    Working...
    X