var DBG = DBG || 0;
var DBG1 = true;
var CURRENT_DATE = CURRENT_DATE || '';
if (!STORE_NAME) throw "Store name not defined";
if (!global[STORE_NAME]) throw "Store not defined";
if (!URL_TABLE_POWIAZANIA) throw "Brak URL_TABLE_POWIAZANIA";
if (!BASE_URLS) throw "Brak BASE_URLS"
var RECORD_MORE_FUNCTIONS_OPENED_NODE = null;
if (!FIELD_LIST_PRACOWNICY) throw "Brak FIELD_LIST_PRACOWNICY"
if (!FIELD_LIST_KONTRAHENCI) throw "Brak FIELD_LIST_KONTRAHENCI"
var EXPORT_FIELDS_OD = EXPORT_FIELDS_OD || null;
var EXPORT_FIELDS_DO = EXPORT_FIELDS_DO || null;
var createReactClass = global.p5VendorJs.createReactClass;
var h = global.p5VendorJs.React.createElement;
var ReactDOM = global.p5VendorJs.ReactDOM;
var swal = window.swal;
var globalRaportStore = global[STORE_NAME];
if (!p5UI__clickedOutsideElement) throw "Brak p5UI__clickedOutsideElement"
if (!global.p5VendorJs.Unstated) throw "Brak Unstated"
var Unstated = global.p5VendorJs.Unstated;
var P5UI__BocianHeader = createReactClass({
getStateFromStore: function () {
var storeState = this.props.store.getState();
return {
totalOdPracownicy: storeState.totalOdPracownicy,
totalOdPozostale: storeState.totalOdPozostale,
totalDoKontrahenci: storeState.totalDoKontrahenci,
totalDoPozostale: storeState.totalDoPozostale,
depth: storeState.depth,
onlyTargets: storeState.onlyTargets,
title: storeState.title,
};
},
getInitialState: function() {
return this.getStateFromStore();
},
componentDidMount: function () {
this.unsubscribe = this.props.store.subscribe(this.storeUpdated)
},
componentWillUnmount: function () {
this.unsubscribe()
},
storeUpdated: function () {
DBG && console.log('DBG::P5UI__BocianHeader::storeUpdated ', this.getStateFromStore());
this.setState(this.getStateFromStore())
},
addOdPozostale: function (event) {
// window['createPracownikAjax'](event)
window['addPozostaleOdDo'](event)
},
addDoPozostale: function (event) {
// window['createKontrahentAjax'](event)
window['addPozostaleOdDo'](event)
},
clearPozostaleOd: function (event) {
this.props.store.dispatch({ type: 'CLEAR_POZOSTALE_OD' })
},
clearPozostaleDo: function (event) {
this.props.store.dispatch({ type: 'CLEAR_POZOSTALE_DO' })
},
handleChangeDepth: function (event) {
var store = this.props.store;
var depth = event.target.value;
store.dispatch({ type: 'SET_DEPTH', depth: depth })
},
handleChangeSetOnlyTargetsYes: function () {
this.props.store.dispatch({ type: 'SET_ONLY_TARGETS', onlyTargets: true })
},
handleChangeSetOnlyTargetsNo: function () {
this.props.store.dispatch({ type: 'SET_ONLY_TARGETS', onlyTargets: false })
},
handleChangeTitle: function (event) {
this.props.store.dispatch({ type: 'SET_TITLE', title: event.target.value })
},
handleRaportSubmitForm: function (event) {
event.preventDefault();
var self_store = this.props.store;
var idsPracownicy = getListFromLocalStorage('Bocian.biAuditForm.pracownicyIds');
var idsKontrahenci = getListFromLocalStorage('Bocian.biAuditForm.kontrahenciIds');
var pozostaleOd = getListFromLocalStorage(getSelectedListLocalStorageKey('OD'));
var pozostaleDo = getListFromLocalStorage(getSelectedListLocalStorageKey('DO'));
var allOdLength = idsPracownicy.length + pozostaleOd.length;
var allDoLength = idsKontrahenci.length + pozostaleDo.length;
var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
var smadReaportTitle = getItemLocalStorage('Bocian.biAuditForm.smadReaportTitle');
var analizaOnlyTargets = getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets');
if ( !smadReaportTitle ) {
p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano tytułu raportu' });
return;
}
if ( !depthValue ) {
p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano wartości dla głębokości powiązań' });
return;
}
if ( !analizaOnlyTargets ) {
p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano wartości czy zwracać wyniki tylko z obiektami docelowymi' });
return;
}
if ( !allOdLength ) {
p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano pozycji OD do analizy (pracownicy lub pozostałe bazy)' });
return;
}
if ( !allOdLength && !allDoLength ) {
p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano pozycji do analizy' });
return;
}
// TODO: analizaOnlyTargets = ( 'y' | 'n' ) - allDoLength should depend of analizaOnlyTargets?
// if not choise 'pracownicy' or 'kontrahenci'
if ( !allOdLength || !allDoLength ) {
var messageConfirm = '';
if ( !allDoLength ) {
messageConfirm = 'Nie wybrano podmiotów/kontrahentów! Czas przygotowania raportu może wydłużyć się ze względu na sprawdzenie powiązania ze wszystkimi podmiotami/kontrahentami w systemie. Czy jesteś pewny? ';
}
// show confirm window with message
if (!confirm(messageConfirm)) return;
}
window.fetch(URL_GENERATE_BI_AUDIT_RAPORT_AJAX, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'same-origin',
body: JSON.stringify({
pracownicyIds: idsPracownicy,
kontrahenciIds: idsKontrahenci,
pozostaleOd: pozostaleOd,
pozostaleDo: pozostaleDo,
depthValue: depthValue,
smadReaportTitle: smadReaportTitle,
analizaOnlyTargets: analizaOnlyTargets
})
})
.then(function(response) {
return response.text();
})
.then(function(responseText) {
try {
return JSON.parse(responseText);
} catch (e) {
throw responseText;
}
})
.then(function(result) {
if (result.type == 'success') {
p5UI__notifyAjaxCallback(result);
self_store.dispatch({ type: 'CLEAR_ALL' })
updateTopCounters();
$('#smad-table-PRACOWNICY form').find(':checkbox').prop('checked', false);
$('#smad-table-KONTRAHENCI form').find(':checkbox').prop('checked', false);
$('#count-selected-item-kontrahenci').text('0');
$('#count-selected-item-pracownicy').text('0');
$('.bottom--message-warning-critical-search').text('');
swal({
title: result.msg,
html: 'Przejdź do raportów',
allowOutsideClick: false, // TODO: btn Anuluj na dole?
showCloseButton: true,
confirmButtonText: 'OK',
});
window.setTimeout(function () {
console.warn("URL_TABLE_POWIAZANIA:", URL_TABLE_POWIAZANIA);
}, 100);
window.setTimeout(function () {
window.location.href = URL_TABLE_POWIAZANIA;
}, 6000);
resolve(result.msg);
} else {
if (result.type && result.msg) p5UI__notifyAjaxCallback(result);
reject(result.msg);
}
})
.catch(function(error) {
if(DBG) console.log('request failed', error);
});
},
handleAddByLastReportClick: function (event) {
swal({
title: "dodaj do analizy wg raportu",
input: 'radio',
inputOptions: {
'pracownicy' : "Pracownicy",
'kontrahenci' : "Kontrahenci",
// 'pracownicy_pozostale' : "Pracownicy (pozostałe)",
// 'kontrahenci_pozostale' : "Kontrahenci (pozostałe)",
},
inputValidator: function (value) {
return !value && 'Proszę wybrać typ danych';
}
}).then(function (data) {
handleAddToReportByPreviousReport(data.value);
})
// TODO: like addToReportByPreviousReport but after select report, show counters for pracow., kontr., pozostale od and do with checkbox
// swal({
// title: "TODO: dodaj do analizy wg raportu",
// })
// TODO: https://github.com/sweetalert2/sweetalert2-react-content
// - just pass React element to 'html' ?
},
renderClearPozostaleOdBtn: function () {
return h('i', {
title: "Wyczyść pozostałe",
className: "glyphicon glyphicon-remove",
style: { 'font-size': '14px', 'line-height': '21px', 'margin-left': '3px', 'vertical-align': 'middle', color: "#f00", opacity: "0.5", cursor: "pointer" },
onClick: this.clearPozostaleOd, 'line-height': '20px'
});
},
renderClearPozostaleDoBtn: function () {
return h('i', {
title: "Wyczyść pozostałe",
className: "glyphicon glyphicon-remove",
style: { 'font-size': '14px', 'line-height': '21px', 'margin-left': '3px', 'vertical-align': 'middle', color: "#f00", opacity: "0.5", cursor: "pointer" },
onClick: this.clearPozostaleDo, 'line-height': '20px'
});
},
renderSummaryList: function () {
var totalOd = this.state.totalOdPracownicy + this.state.totalOdPozostale;
var totalDo = this.state.totalDoKontrahenci + this.state.totalDoPozostale;
return h('ul', {}, [
h('li', { style: { marginTop: "6px" } }, [
h('span', {
style: totalOd > 0 ? { color: "#d7142d" } : {}
}, [
" OD ",
h('span', { className: "badge", style: totalOd > 0 ? { 'background-color': "#d7142d" } : {} }, totalOd),
" : ",
]),
h('a', { className: "btn btn-primary btn-xs", href: "#PRACOWNICY" }, [ // .bi-btn-primary
" pracownicy ",
h('span', { className: "badge" }, this.state.totalOdPracownicy),
]),
h('i', { className: "glyphicon glyphicon-plus", style: { 'font-size': "14px", margin: "0 12px" } }),
h('button', { className: "btn btn-primary btn-xs", onClick: this.addOdPozostale }, [ // .bi-btn-primary
" pozostałe ",
h('span', { className: "badge" }, this.state.totalOdPozostale),
]),
(this.state.totalOdPozostale > 0) ? this.renderClearPozostaleOdBtn() : null,
]),
h('li', { style: { marginTop: "6px" } }, [
h('span', {
style: totalDo > 0 ? { color: "#d7142d" } : {}
}, [
" DO ",
h('span', { className: "badge", style: totalDo > 0 ? { 'background-color': "#d7142d" } : {} }, totalDo),
" : ",
]),
h('a', { className: "btn btn-primary btn-xs", href: "#KONTRAHENCI" }, [ // .bi-btn-primary
" kontrahenci ",
h('span', { className: "badge" }, this.state.totalDoKontrahenci),
]),
h('i', { className: "glyphicon glyphicon-plus", style: { 'font-size': "14px", margin: "0 12px" } }),
h('button', { className: "btn btn-primary btn-xs", onClick: this.addOdPozostale }, [ // .bi-btn-primary
" pozostałe ",
h('span', { className: "badge" }, this.state.totalDoPozostale),
]),
(this.state.totalDoPozostale > 0) ? this.renderClearPozostaleDoBtn() : null,
]),
]);
},
renderRaportParamsForm: function () {
var depth = parseInt(this.state.depth);
var isDepthValid = ( !isNaN(depth) && depth >= 1 && depth <= 16 );
var onlyTargets = this.state.onlyTargets;
return h('div', {}, [
h('div', { className: "row" + ( isDepthValid ? "" : " has-error" ), style: { 'margin-bottom': "12px" } }, [
h('div', { className: "form-item col-md-7 col-lg-9 smad-heder-title", style: { 'font-size': "14px", 'text-align': "right", 'padding-top': "5px", 'padding-bottom': "0" } }, [
"głębokość powiązań: ",
]),
h('div', { className: "form-item col-md-5 col-lg-3" }, [
h('input', { type: "number", className: "form-control", placeholder: "1-16", value: this.state.depth, onChange: this.handleChangeDepth, min: 1, max: 16 }),
]),
]),
h('div', { className: "row", style: { 'margin-bottom': "12px" } }, [
h('div', { className: "form-item col-md-7 col-lg-9 smad-heder-title", style: { 'font-size': "14px", 'text-align': "right", 'padding-top': "5px", 'padding-bottom': "0" } }, [
"Czy zwracać wyniki tylko ze znalezionymi obiektami docelowymi (DO)? ",
]),
h('div', { className: "form-item col-md-5 col-lg-3" }, [
h('div', { className: "btn-group" }, [
h('div', { className: "btn btn-default" + ( onlyTargets ? " active" : "" ), style: { padding: "6px 12px" }, onClick: this.handleChangeSetOnlyTargetsYes }, "TAK"),
h('div', { className: "btn btn-default" + ( onlyTargets ? "" : " active" ), style: { padding: "6px 12px" }, onClick: this.handleChangeSetOnlyTargetsNo }, "NIE"),
]),
]),
]),
h('div', { className: "row", style: { 'margin-bottom': "12px" } }, [
h('div', { className: "form-item col-md-3 col-lg-3", style: { 'font-size': "14px", 'text-align': "right", 'padding-top': "5px", 'padding-bottom': "0" } }, [
"Tytuł:",
]),
h('div', { className: "form-item col-md-9 col-lg-9" }, [
h('input', { type: "text", className: "form-control", placeholder: 'Raport bez tytułu z dnia ' + CURRENT_DATE, value: this.state.title, onChange: this.handleChangeTitle }),
]),
]),
]);
},
renderRaportFormSubmitBtn: function () {
var totalOd = this.state.totalOdPracownicy + this.state.totalOdPozostale;
var totalDo = this.state.totalDoKontrahenci + this.state.totalDoPozostale;
var isFormValid = (totalOd || totalDo);
return h('div', { className: "row", style: { padding: "0", 'margin-bottom': "0", 'text-align': "right" } }, [
h('div', { className: "form-item col-md-12 col-lg-12" }, [
h('button', {
type: "button",
className: "btn btn-default" + ( isFormValid ? "" : " disabled" ),
onClick: this.handleRaportSubmitForm,
style: { padding: "18px 42px", 'font-size': "18px", 'font-weight': "900" }
}, "GENERUJ RAPORT POWIĄZAŃ"),
]),
]);
},
renderAddMoreBtns: function () {
return h('div', {
style: { 'padding-top': 6, 'padding-bottom': 20 }
}, [
h('button', { className: "btn btn-success btn-xs", onClick: this.handleAddByLastReportClick }, "dodaj do analizy wg raportu"),
]);
},
render: function () {
DBG && console.log('DBG::P5UI__BocianHeader::render ', { state: this.state });
var totalOd = this.state.totalOdPracownicy + this.state.totalOdPozostale;
var totalDo = this.state.totalDoKontrahenci + this.state.totalDoPozostale;
var depth = this.state.depth;
var errorMsg = (depth > 16) ? "Maksymalna głębokość powiązań to 16!" : "";
var warningMsg = ( ( !totalOd || !totalDo ) && depth > 6 ) ? "Krytyczne wielkości danych do przeszukania. Optymalna głębokość szukania powiaząń to: 6" : "";
return h('div', { className: "container-fluid", style: { backgroundColor: "#efefef" } }, [
h('div', { style: { fontSize: '16px', fontWeight: "normal", color: "#777" } }, [
h('div', { className: "row" }, [
h('div', { className: "col-md-6" }, [
h('h3', { style: { color: "#000" } }, [
h('span', { style: { fontSize: "120%", color: "#d7142d" } }, "|"),
" Tworzenie nowego raportu ",
h('br'),
h('small', {}, [
"(Wybierz elementy do porównania: ",
h('span', { style: { color: "#d7142d" } }, " OD "),
h('i', { className: "glyphicon glyphicon-random", style: { padding: '0 3px', 'font-size': "80%", color: "#000" } }),
h('span', { style: { color: "#d7142d" } }, " DO"),
")",
])
]),
"Wybrano:",
this.renderSummaryList(),
this.renderAddMoreBtns(),
]),
h('div', { className: "col-md-6", style: { 'padding-top': "20px", 'padding-bottom': "20px" } }, [
this.renderRaportParamsForm(),
this.renderRaportFormSubmitBtn(),
]),
]),
h('div', { className: "row" }, [
h('div', { className: "col-md-8 col-md-offset-2 col-xs-12" }, [
errorMsg ? h('div', { className: "alert alert-danger" }, errorMsg) : null,
warningMsg ? h('div', { className: "alert alert-warning" }, warningMsg) : null,
]),
]),
])
])
}
})
function getSelectedListLocalStorageKey(from) { // from: ( OD | DO )
switch (from) {
case 'OD': return 'Bocian.biAuditForm.odFeatureKeys';
case 'DO': return 'Bocian.biAuditForm.doFeatureKeys';
default: throw "Not implemented from selected list '" + from + "' - expected 'OD' or 'DO'";
}
}
function getListFromLocalStorage(key) {
return JSON.parse( localStorage.getItem(key) || '[]' );
}
function getSignedIntFromLocalStorage(key, defaultValue) {
return JSON.parse( localStorage.getItem(key) || defaultValue );
}
function getStringFromLocalStorage(key, defaultValue) {
var value = localStorage.getItem(key);
value = (value) ? JSON.parse(value) : '';
return (value) ? value : defaultValue;
}
// function saveToSelectedListInLocalStorage(from, featureKey) {
// DBG && console.log("DBG::saveToSelectedListInLocalStorage(from, featureKey)", {from, featureKey}, {added: getSelectedListFromLocalStorage(from).concat(featureKey)});
// localStorage.setItem(getSelectedListLocalStorageKey(from), JSON.stringify(
// getSelectedListFromLocalStorage(from).concat(featureKey)
// ))
// }
// function removeFromSelectedListInLocalStorage(from, featureKey) {
// DBG && console.log("DBG::removeFromSelectedListInLocalStorage(from, featureKey)", {from, featureKey});
// localStorage.setItem(getSelectedListLocalStorageKey(from), JSON.stringify(
// getSelectedListFromLocalStorage(from).filter(function (item) {
// return ( item !== featureKey );
// })
// ))
// }
/* DATA FOR READ REAPORT */
function urlFetchKontrahenciPowiazania() {
// Documentation: https://github.com/github/fetch
fetch(URL_FETCH_KONTRAHENCI_POWIAZANIA, {
credentials: 'same-origin'
})
.then(function parseJSON(response) {
return response.json()
})
.then(function(data) {
var reaportItemsKontrahenciPowiazani = null;
data.body.items.forEach (function(row) {
reaportItemsKontrahenciPowiazani += '
'+
'
'+row["ID"]+'
';
});
$( "#body-reaport-kontrahenci-powiazani-tree" ).html(reaportItemsKontrahenciPowiazani);
}).catch(function(error) {
if(DBG) console.log('request failed', error)
});
}
/* FORM DATA FOR GENERATAE REAPORT */
/**
* Załadowanie wybranej pozycji w select czy zwracać wyniki tylko z obiektami docelowymi onlyTarget
*/
function loadCurrentOnlyTargetsSelect() {
var analizaOnlyTargets = getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets');
$('#smad-select-target').val(analizaOnlyTargets).attr("selected", "selected");
$('#smad-select-target-kontrahenci').val(analizaOnlyTargets).attr("selected", "selected");
}
/**
* Załadowanie do storage informacji czy zwracać wyniki tylko z obiektami docelowymi
*/
function updateLocalStorageBiAuditOnlyTargets(idSelect) {
$(idSelect).change(function() {
var newValue = $(idSelect).val();
var responseValue = newValue;
setItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets', responseValue);
$('#smad-select-target').val(newValue).attr("selected", "selected");
$('#smad-select-target-kontrahenci').val(newValue).attr("selected", "selected");
// load in select selected option
loadCurrentOnlyTargetsSelect();
});
}
/**
* Funkcja pozwala na wyświetlenie okienka importu
*/
function showViewUploadFile( event, headerTitle, enumType, showCheckbox, csvFileExample ) {
event.preventDefault();
var enumType = enumType;
if( csvFileExample !== undefined) { // przykład + instrukcja do pobrania
csvFileExample = '