// @require var ID_STORAGE // @require var TABLE_NAME // @require var FETCH_URL // @require var ADD_ACTION_URL function Storage__tableStruct__addAction() { fetch(FETCH_URL, { method: 'POST', credentials: 'same-origin',// add cookies headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ idStorage: ID_STORAGE, table: TABLE_NAME }) }).then(function (response) { if ('application/json' !== response.headers.get('Content-Type').substr(0, 16)) { throw 'Wrong response type: ' + response.headers.get('Content-Type') } 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 data:', data); } else if ('success' === data.type) { if (!data.options) throw 'Missing options' if (!data.options.length) throw 'Brak akcji do wyboru' Storage__tableStruct__fetchedAddAction(data.options); } else { p5UI__notifyAjaxCallback(data); console.log('loadDataAjax:fetch: ERR data:', data); } }).catch(function (e) { p5UI__notifyAjaxCallback({ type: 'error', msg: 'Request error: ' + e }); console.log('fetchActionList: ERR:', e); }); } function Storage__tableStruct__fetchedAddAction(options) { var optionsList = {}; options.forEach(function (option) { optionsList[option.ID] = '[' + option.ID + '] ' + option.DESC }) swal({ title: 'Dodaj Akcję', input: 'radio', inputOptions: optionsList, showCancelButton: true, showCloseButton: true, inputClass: 'p5-swal-radio-as-list', inputValidator: function (result) { return new Promise(function (resolve, reject) { if (result) { resolve() } else { reject('Wybierz akcję') } }) } }).then(function (result) { fetch(ADD_ACTION_URL, { method: 'POST', credentials: 'same-origin',// add cookies headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ idStorage: ID_STORAGE, table: TABLE_NAME, idAction: result }) }).then(function (response) { if ('application/json' !== response.headers.get('Content-Type').substr(0, 16)) { throw 'Wrong response type: ' + response.headers.get('Content-Type') } return response.json() }).then(function (data) { if (!data) throw 'Empty response'; console.log('ADD_ACTION_URL:fetch: request finished data:', data); if ('error' === data.type) { p5UI__notifyAjaxCallback(data); console.log('ADD_ACTION_URL:fetch: ERR data:', data); } else if ('success' === data.type) { p5UI__notifyAjaxCallback(data); } else { p5UI__notifyAjaxCallback(data); console.log('ADD_ACTION_URL:fetch: ERR data:', data); } }).catch(function (e) { p5UI__notifyAjaxCallback({ type: 'error', msg: 'Request error: ' + e }); console.log('fetchActionList: ERR:', e); }); console.log('TODO: result', result); }).catch(function (e) { if ('close' === e || 'cancel' === e || 'overlay' === e) { } else throw e }) } function Storage__tableStruct__editActionLabel(n, idAction) { console.log('F.Storage__tableStruct__editActionLabel idAction('+idAction+')', n) swal('TODO', 'Edytuj nazwę akcji', 'warning') } function Storage__tableStruct__addParamAction(n, idAction, flatDefArgs) { var defArgs = (flatDefArgs || '').split(';').map(function (flatArg) { var arg = flatArg.split('=') return { ID: arg[0], DESC: arg[1]} }) console.log('F.Storage__tableStruct__addParamAction idAction('+idAction+')', defArgs, n) swal('TODO', '