Skip to content
Snippets Groups Projects
Commit b8d5a7ea authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update direct protocol (proxy, store and filter).

parent cbde9810
No related branches found
No related tags found
2 merge requests!27Release 0.9.1,!268 extjs 6
......@@ -716,10 +716,7 @@ def to_jsonstore(table, **kwargs):
extraParams=base_params,
model=tablename,
pageParam=NOPAGE,
rootProperty=ROOT,
successProperty=SUCCESS,
storeId=get_store_id(tablename),
totalProperty=TOTAL)
storeId=get_store_id(tablename))
for field in table:
fieldname = field.name
......
......@@ -7,20 +7,6 @@
*
* It also provide a set of method to filter the store passing by the server.
*
* **Note**: this class inherits of the config options from:
*
* - **{@link Ext.data.proxy.Direct proxy}**
*
* - **{@link Ext.data.proxy.Direct#extraParams extraParams}**
* - **{@link Ext.data.proxy.Direct#pageParam pageParam}**
*
* - **{@link Ext.data.reader.Json JsonReader}**
*
* - **{@link Ext.data.reader.Json#cfg-root rootProperty}**
* - **{@link Ext.data.reader.Json#idProperty idProperty}**
* - **{@link Ext.data.reader.Json#successProperty successProperty}**
* - **{@link Ext.data.reader.Json#totalProperty totalProperty}**
*/
Ext.define('Dbui.data.DirectStore', {
......@@ -52,15 +38,7 @@ Ext.define('Dbui.data.DirectStore', {
type: 'xdirect'
};
Ext.copyTo(proxy, config, [
'extraParams',
'idProperty',
'pageParam',
'rootProperty',
'successProperty',
'totalProperty'
]);
Ext.copyTo(proxy, config, ['extraParams', 'pageParam']);
config.proxy = proxy;
}
......@@ -125,17 +103,17 @@ Ext.define('Dbui.data.DirectStore', {
conditions = [],
i;
if (me.extraParams.where) {
if (me.proxy.extraParams.where) {
if (me.initialWhere) {
for (i = 0; i < me.initialWhere.length; i += 1) {
conditions.push(me.initialWhere[i]);
}
me.getProxy().setExtraParam('where', conditions);
me.proxy.setExtraParam('where', conditions);
} else {
delete me.getProxy().extraParams.where;
delete me.proxy.extraParams.where;
}
}
}
......
/**
* Implement the server protocol.
*
* **Note**: this class inherits of the config options from the JsonReader:
*
* - **{@link Ext.data.reader.Json JsonReader}**
*
* - **{@link Ext.data.reader.Json#cfg-root rootProperty}**
* - **{@link Ext.data.reader.Json#idProperty idProperty}**
* - **{@link Ext.data.reader.Json#successProperty successProperty}**
* - **{@link Ext.data.reader.Json#totalProperty totalProperty}**
* Direct proxy implementing the DbSvc protocol.
*
* * **Note**: each operation contains at least 3 parameters:
*
......@@ -35,6 +26,21 @@ Ext.define('Dbui.data.proxy.Direct', {
extend: 'Ext.data.proxy.Direct',
alias: 'proxy.xdirect',
// predefined JSON reader adapted to the DbSvc service
reader: {
type: 'json',
rootProperty: 'records',
successProperty: 'success',
totalProperty: 'count'
},
// predeined JSON writer adapted to the DbSvc service
writer: {
type: 'json',
allowSingle: false,
writeAllFields: false
},
// jshint strict: false
/**
......@@ -42,8 +48,7 @@ Ext.define('Dbui.data.proxy.Direct', {
*/
constructor: function (config) {
var me = this,
reader;
var me = this;
// the direct API tu run with the DbSvc service
if (!config.api) {
......@@ -55,24 +60,6 @@ Ext.define('Dbui.data.proxy.Direct', {
};
}
// the JSON reader
if (!config.reader) {
reader = {
type: 'json'
};
Ext.copyTo(reader, config, 'rootProperty,idProperty,successProperty,totalProperty');
config.reader = reader;
}
// the JSOn writer
if (!config.writer) {
config.writer = {
type: 'json',
allowSingle: false,
writeAllFields: false
};
}
// initialise the base class
me.callParent(arguments);
},
......@@ -91,81 +78,99 @@ Ext.define('Dbui.data.proxy.Direct', {
* @param {Object} scope
*
*/
doRequest: function (operation, callback, scope) {
doRequest: function (operation) {
"use strict";
var me = this,
writer = me.getWriter(),
request = me.buildRequest(operation),
params = request.params,
args = [],
i,
fieldId = Dbui.encodeField(operation.params.tableName, 'id'),
fn,
method,
records;
action, api, args, data, fieldId, i, fn, params, records,
request, writer;
if (!me.methodsResolved) {
me.resolveMethods();
}
fn = me.api[request.action] || me.directFn;
request = me.buildRequest(operation);
action = request.getAction();
api = me.getApi();
if (api) {
fn = api[action];
}
fn = fn || me.getDirectFn();
writer = me.getWriter();
if (operation.allowWrite()) {
if (writer && operation.allowWrite()) {
request = writer.write(request);
}
switch (operation.action) {
// DvSvc Protocol ....................................................
params = request.getParams();
switch (action) {
case 'read':
method = fn.directCfg.method;
args = method.getArgs(params, me.paramOrder, me.paramsAsHash);
break;
case 'create':
params.records = request.jsonData;
args.push(params);
break;
case 'update':
params.records = request.jsonData;
fieldId = Dbui.encodeField(params.tableName, 'id');
params.records = [];
records = request.getRecords();
// abandon the update if the proxy is not yet ready
for (i = 0; i < params.records; i += 1) {
if (!params.records[fieldId]) {
return;
}
for (i = 0; i < records.length; i += 1) {
data = records[i].getData();
delete data[fieldId];
params.records.push(data);
}
args.push(params);
break;
case 'destroy':
// build the list of id to be destroy
case 'update':
params.records = [];
records = request.getRecords();
records = operation.getRecords();
for (i = 0; i < records.length; i += 1) {
params.records.push(records[i].get(fieldId));
data = records[i].getData();
params.records.push(data);
}
break;
// abandon the transaction if the proxy is not yet ready
if (records === null || params.records.length === 0) {
return;
}
case 'destroy':
fieldId = Dbui.encodeField(params.tableName, 'id');
params.records = [];
records = request.getRecords();
args.push(params);
for (i = 0; i < records.length; i += 1) {
data = records[i].getData();
params.records.push(data[fieldId]);
}
break;
}
Ext.apply(request, {
//....................................................................
request.setParams(params);
args = fn.directCfg.method.getArgs({
params: params,
paramOrder: me.getParamOrder(),
paramsAsHash: me.getParamsAsHash(),
metadata: me.getMetadata(),
callback: me.createRequestCallback(request, operation),
scope: me
});
request.setConfig({
args: args,
directFn: fn
});
args.push(me.createRequestCallback(request, operation, callback, scope), me);
fn.apply(window, args);
// Store expects us to return something to indicate that the request
// is pending; not doing so will make a buffered Store repeat the
// requests over and over. See https://sencha.jira.com/browse/EXTJSIV-11757
return request;
}
});
......@@ -339,7 +339,7 @@ Ext.define('Dbui.grid.Filter', {
// push new condition in the where clause of the store
if (conditions.length) {
store.extraParams.where = conditions;
store.proxy.extraParams.where = conditions;
// go back to the initial where setting when conditions are empty
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment