| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- // @require var SYNC_URL
- function zaliczkaFetchData(query, args, resultCallback) {
- console.warn('TODO: zaliczkaFetchData(query, objectNamespace, resultCallback) query('+query+') args:', args);
- // 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 (!args['@namespace'] && !args['objectNamespace']) {
- // TODO: log error
- console.error("BUG: Missing namespace in args");
- return;
- }
- if (args['@namespace']) {
- switch (args['@namespace']) {
- case 'default_db/IN7_MK_BAZA_DYSTRYBUCJI/ZaliczkaProjekt':
- case 'default_db/IN7_DZIENNIK_KORESP/ZaliczkaKoresp':
- {
- superagent
- .post(SYNC_URL)
- .type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
- .send({
- schema: args,
- query: query
- })
- .set('Accept', 'application/json')
- .end(function(err, res) {
- var payload = (err || !res.ok || 'application/json' !== res.type)
- ? {type: 'warning', msg: (res.body && res.body.msg) ? res.body.msg : 'Request error', body: res.body}
- : {type: 'success', msg: res.body.msg || '', body: res.body}
- jQuery(document).trigger('DBG:notify', payload)
- console.log('F.fetchDataAjax res.body', res.body)
- console.log('F.fetchDataAjax payload', payload)
- jQuery.notify(payload.msg, payload.type)
- resultCallback(payload.body)
- });
- }
- break;
- default: {
- console.log("BUG: Unsupported type namespace '" + args['@namespace'] + "'");
- }
- }
- return;
- }
- if ('default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja' == args['objectNamespace']) {
- switch (args['childName']) {
- case 'typ_dokumentu':
- 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 namespace '" + args['objectNamespace'] + "'");
- }
- }
- return;
- }
- }
- global.zaliczkaFetchData = zaliczkaFetchData
|