|
|
@@ -1,21 +1,21 @@
|
|
|
// @require var SYNC_URL
|
|
|
|
|
|
-function zaliczkaFetchData(query, fieldType, resultCallback) {
|
|
|
- console.warn('TODO: zaliczkaFetchData(query, fieldType, resultCallback) query('+query+') fieldType:', fieldType);
|
|
|
+function zaliczkaFetchData(query, args, resultCallback) {
|
|
|
+ console.warn('TODO: zaliczkaFetchData(query, objectNamespace, resultCallback) query('+query+') args:', args);
|
|
|
|
|
|
- // fieldType: Object {"@namespace": "default_db:IN7_DZIENNIK_KORESP", id: "xsd:integer", title: "xsd:string", kategoriaKosztu: "xsd:string"}
|
|
|
- if ('object' !== typeof fieldType) {
|
|
|
- console.log("BUG: Unsupported type '" + fieldType + "'");
|
|
|
+ // objectNamespace: Object {"@namespace": "default_db:IN7_DZIENNIK_KORESP", id: "xsd:integer", title: "xsd:string", kategoriaKosztu: "xsd:string"}
|
|
|
+ if ('object' !== typeof args) {
|
|
|
+ console.log("BUG: Unsupported type '" + args + "'");
|
|
|
return;
|
|
|
}
|
|
|
- if (!fieldType['@namespace'] && !fieldType['xsdType']) {
|
|
|
+ if (!args['@namespace'] && !args['objectNamespace']) {
|
|
|
// TODO: log error
|
|
|
- console.error("BUG: Missing xmlns or xsdType on fieldType");
|
|
|
+ console.error("BUG: Missing namespace in args");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (fieldType['@namespace']) {
|
|
|
- switch (fieldType['@namespace']) {
|
|
|
+ if (args['@namespace']) {
|
|
|
+ switch (args['@namespace']) {
|
|
|
case 'default_db/IN7_MK_BAZA_DYSTRYBUCJI/ZaliczkaProjekt':
|
|
|
case 'default_db/IN7_DZIENNIK_KORESP/ZaliczkaKoresp':
|
|
|
{
|
|
|
@@ -23,7 +23,7 @@ function zaliczkaFetchData(query, fieldType, resultCallback) {
|
|
|
.post(SYNC_URL)
|
|
|
.type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
|
|
|
.send({
|
|
|
- schema: fieldType,
|
|
|
+ schema: args,
|
|
|
query: query
|
|
|
})
|
|
|
.set('Accept', 'application/json')
|
|
|
@@ -40,24 +40,48 @@ function zaliczkaFetchData(query, fieldType, resultCallback) {
|
|
|
}
|
|
|
break;
|
|
|
default: {
|
|
|
- console.log("BUG: Unsupported type namespace '" + fieldType['@namespace'] + "'");
|
|
|
+ console.log("BUG: Unsupported type namespace '" + args['@namespace'] + "'");
|
|
|
}
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (fieldType['xsdType']) {
|
|
|
- switch (fieldType['xsdType']) {
|
|
|
- case 'default_db__x3A__ZALICZKA_POZYCJA:kategoria_kosztuType': {
|
|
|
- var options = [
|
|
|
- 'Koszt-1',
|
|
|
- 'Koszt-2',
|
|
|
- 'Koszt-3',
|
|
|
- ]
|
|
|
- resultCallback({options: options});
|
|
|
+ if ('default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja' == args['objectNamespace']) {
|
|
|
+ switch (args['childName']) {
|
|
|
+ case 'kategoria_kosztu': {
|
|
|
+ fetch(SYNC_URL, {
|
|
|
+ method: 'POST',
|
|
|
+ credentials: 'same-origin',// add cookies
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify({
|
|
|
+ objectNamespace: args['objectNamespace'],
|
|
|
+ childName: args['childName'],
|
|
|
+ query: query
|
|
|
+ })
|
|
|
+ }).then(function (response) {
|
|
|
+ return response.json()
|
|
|
+ }).then(function (data) {
|
|
|
+ if (!data) throw "Empty response";
|
|
|
+ console.log('loadDataAjax:fetch: request finished data:', data);
|
|
|
+ if ('error' === data.type) {
|
|
|
+ p5UI__notifyAjaxCallback(data);
|
|
|
+ console.log('loadDataAjax:fetch: ERR:', e);
|
|
|
+ } else if ('success' === data.type) {
|
|
|
+ resultCallback({options: data.options || []});
|
|
|
+ } else {
|
|
|
+ p5UI__notifyAjaxCallback(data);
|
|
|
+ console.log('loadDataAjax:fetch: ERR:', e);
|
|
|
+ }
|
|
|
+ }).catch(function (e) {
|
|
|
+ p5UI__notifyAjaxCallback({
|
|
|
+ type: 'error',
|
|
|
+ msg: "Request error " + e
|
|
|
+ });
|
|
|
+ console.log('loadDataAjax:fetch: ERR:', e);
|
|
|
+ });
|
|
|
} break;
|
|
|
default: {
|
|
|
- console.warn("BUG: Unsupported xsdType '" + fieldType['xsdType'] + "'");
|
|
|
+ console.warn("BUG: Unsupported namespace '" + args['objectNamespace'] + "'");
|
|
|
}
|
|
|
}
|
|
|
return;
|