|
@@ -3,7 +3,46 @@ var h = window.p5VendorJs.React.createElement;
|
|
var ReactDOM = window.p5VendorJs.ReactDOM;
|
|
var ReactDOM = window.p5VendorJs.ReactDOM;
|
|
var AsyncTypeahead = window.p5VendorJs.AsyncTypeahead;
|
|
var AsyncTypeahead = window.p5VendorJs.AsyncTypeahead;
|
|
var swal = window.swal;
|
|
var swal = window.swal;
|
|
|
|
+var STORE_NAME = STORE_NAME || '_bocianRaportStore';
|
|
var DBG = DBG || false;
|
|
var DBG = DBG || false;
|
|
|
|
+var DBG1 = true;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function bocianFeatureKey(ns, pk) {
|
|
|
|
+ switch (ns) {
|
|
|
|
+ case 'default_db/BI_audit_KRS/BI_audit_KRS': return 'KRS.' + pk;
|
|
|
|
+ case 'default_db/BI_audit_KRS_person/BI_audit_KRS_person': return 'KRS/p.' + pk;
|
|
|
|
+ case 'default_db/BI_audit_MSIG/BI_audit_MSIG': return 'MSIG.' + pk;
|
|
|
|
+ case 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person': return 'MSIG/p.' + pk;
|
|
|
|
+ case 'default_db/BI_audit_CEIDG/BI_audit_CEIDG': return 'CEIDG.' + pk;
|
|
|
|
+ default: throw "Not implemented feature key for ns '" + ns + "'";
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+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 getSelectedListFromLocalStorage(from) {
|
|
|
|
+ return JSON.parse( localStorage.getItem(getSelectedListLocalStorageKey(from)) || '[]' );
|
|
|
|
+}
|
|
|
|
+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 );
|
|
|
|
+ })
|
|
|
|
+ ))
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
function convertXlinkToObjects(items) {
|
|
function convertXlinkToObjects(items) {
|
|
@@ -101,17 +140,21 @@ var P5UI_AddItemToReport_SelectKrsPerson = createReactClass({
|
|
var krsPresons = (this.props.krs && this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'])
|
|
var krsPresons = (this.props.krs && this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'])
|
|
? this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person']
|
|
? this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person']
|
|
: [];
|
|
: [];
|
|
- var _selectPerson = this.props.selectPerson.bind(this)
|
|
|
|
|
|
+ // var _selectPerson = this.props.selectPerson.bind(this)
|
|
|
|
+ var selectedBaza = 'default_db/BI_audit_KRS_person/BI_audit_KRS_person';
|
|
|
|
|
|
return (krsPresons.length > 0)
|
|
return (krsPresons.length > 0)
|
|
? h('ol', { style: { margin: '22px', textAlign: 'left' } }, krsPresons.map(function (person) {
|
|
? h('ol', { style: { margin: '22px', textAlign: 'left' } }, krsPresons.map(function (person) {
|
|
|
|
+ var label = (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || '');
|
|
return h('li', {}, [
|
|
return h('li', {}, [
|
|
- (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || ''),
|
|
|
|
- h('button', {
|
|
|
|
- className: "btn btn-primary",
|
|
|
|
- style: { marginLeft: "8px", padding: "4px 8px", fontSize: "small" },
|
|
|
|
- onClick: function () { _selectPerson(person) }
|
|
|
|
- }, "Dodaj osobę")
|
|
|
|
|
|
+ h(P5UI_AddItemToReport_Checkbox, { from: 'OD', selectedBaza: selectedBaza, selectedItem: person }),
|
|
|
|
+ h(P5UI_AddItemToReport_Checkbox, { from: 'DO', selectedBaza: selectedBaza, selectedItem: person }),
|
|
|
|
+ h('span', { style: { 'margin-left': "6px" } }, label),
|
|
|
|
+ // h('button', {
|
|
|
|
+ // className: "btn btn-primary",
|
|
|
|
+ // style: { marginLeft: "8px", padding: "4px 8px", fontSize: "small" },
|
|
|
|
+ // onClick: function () { _selectPerson(person) }
|
|
|
|
+ // }, "Dodaj osobę")
|
|
]);
|
|
]);
|
|
}))
|
|
}))
|
|
: null;
|
|
: null;
|
|
@@ -124,16 +167,20 @@ var P5UI_AddItemToReport_SelectMSIGPerson = createReactClass({
|
|
? this.props.msig['default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person']
|
|
? this.props.msig['default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person']
|
|
: [];
|
|
: [];
|
|
var _selectPerson = this.props.selectPerson.bind(this)
|
|
var _selectPerson = this.props.selectPerson.bind(this)
|
|
|
|
+ var selectedBaza = 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person';
|
|
|
|
|
|
return (msigPresons.length > 0)
|
|
return (msigPresons.length > 0)
|
|
? h('ol', { style: { margin: '22px', textAlign: 'left' } }, msigPresons.map(function (person) {
|
|
? h('ol', { style: { margin: '22px', textAlign: 'left' } }, msigPresons.map(function (person) {
|
|
|
|
+ var label = (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || '');
|
|
return h('li', {}, [
|
|
return h('li', {}, [
|
|
- (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || ''),
|
|
|
|
- h('button', {
|
|
|
|
- className: "btn btn-primary",
|
|
|
|
- style: { marginLeft: "8px", padding: "4px 8px", fontSize: "small" },
|
|
|
|
- onClick: function () { _selectPerson(person) }
|
|
|
|
- }, "Dodaj osobę")
|
|
|
|
|
|
+ h(P5UI_AddItemToReport_Checkbox, { from: 'OD', selectedBaza: selectedBaza, selectedItem: person }),
|
|
|
|
+ h(P5UI_AddItemToReport_Checkbox, { from: 'DO', selectedBaza: selectedBaza, selectedItem: person }),
|
|
|
|
+ h('span', { style: { 'margin-left': "6px" } }, label),
|
|
|
|
+ // h('button', {
|
|
|
|
+ // className: "btn btn-primary",
|
|
|
|
+ // style: { marginLeft: "8px", padding: "4px 8px", fontSize: "small" },
|
|
|
|
+ // onClick: function () { _selectPerson(person) }
|
|
|
|
+ // }, "Dodaj osobę")
|
|
]);
|
|
]);
|
|
}))
|
|
}))
|
|
: null;
|
|
: null;
|
|
@@ -147,8 +194,81 @@ var P5UI_AddItemToReport_BazaMenuItem = createReactClass({
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+var P5UI_AddItemToReport_Checkbox = createReactClass({
|
|
|
|
+ _getStore: function () {
|
|
|
|
+ DBG && console.warn('DBG:: window[STORE_NAME]', { store: window[STORE_NAME], STORE_NAME: STORE_NAME})
|
|
|
|
+ return window[STORE_NAME] || null;
|
|
|
|
+ },
|
|
|
|
+ getStateFromStore: function () {
|
|
|
|
+ var featureKey = bocianFeatureKey(this.props.selectedBaza, this.props.selectedItem['@primaryKey']);
|
|
|
|
+ var storeState = this._getStore().getState();
|
|
|
|
+ return {
|
|
|
|
+ featureKey: featureKey,
|
|
|
|
+ isSelected: (-1 !== this.getStoreList(this.props.from).indexOf(featureKey)),
|
|
|
|
+ // totalOdPracownicy: storeState.totalOdPracownicy,
|
|
|
|
+ // totalOdPozostale: storeState.totalOdPozostale,
|
|
|
|
+ // totalDoKontrahenci: storeState.totalDoKontrahenci,
|
|
|
|
+ // totalDoPozostale: storeState.totalDoPozostale,
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ getStoreList: function (from) {
|
|
|
|
+ var storeState = this._getStore().getState();
|
|
|
|
+ switch (from) {
|
|
|
|
+ case 'OD': return storeState.pozostaleOd;
|
|
|
|
+ case 'DO': return storeState.pozostaleDo;
|
|
|
|
+ default: throw "Not imeplemented store list from = '" + from + "'";
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ getInitialState: function () {
|
|
|
|
+ return this.getStateFromStore();
|
|
|
|
+ },
|
|
|
|
+ componentDidMount: function () {
|
|
|
|
+ var store = this._getStore()
|
|
|
|
+ this._unsubscribe = store ? store.subscribe(this.storeUpdated) : function () {};
|
|
|
|
+ },
|
|
|
|
+ componentWillUnmount: function () {
|
|
|
|
+ this._unsubscribe();
|
|
|
|
+ },
|
|
|
|
+ storeUpdated: function () {
|
|
|
|
+ DBG && console.log('DBG::P5UI__BocianHeader::storeUpdated ', this.getStateFromStore());
|
|
|
|
+ this.setState(this.getStateFromStore())
|
|
|
|
+ },
|
|
|
|
+ _handleClick: function () {
|
|
|
|
+ this.state.isSelected ? this.removeItem() : this.saveItem();
|
|
|
|
+ // _onSelect(from, selectedBaza, selectedItem);
|
|
|
|
+ },
|
|
|
|
+ removeItem: function () {
|
|
|
|
+ this._getStore().dispatch({ type: 'RM_' + this.props.from, featureKey: this.state.featureKey })
|
|
|
|
+ // removeFromSelectedListInLocalStorage(this.props.from, this.state.featureKey);
|
|
|
|
+ // this.setState({ isSelected: false });
|
|
|
|
+ },
|
|
|
|
+ saveItem: function () {
|
|
|
|
+ this._getStore().dispatch({ type: 'ADD_' + this.props.from, featureKey: this.state.featureKey })
|
|
|
|
+ // saveToSelectedListInLocalStorage(this.props.from, this.state.featureKey);
|
|
|
|
+ // this.setState({ isSelected: true });
|
|
|
|
+ },
|
|
|
|
+ render: function () {
|
|
|
|
+ var handleClick = this._handleClick.bind(this);
|
|
|
|
+ // var _onSelect = this.props.onSelect;
|
|
|
|
+ var isSelected = this.state.isSelected;
|
|
|
|
+ return h('div', { className: "checkbox", style: { display: "inline-block", 'margin-left': "6px" } }, [
|
|
|
|
+ h('label', { style: { border: "1px solid " + ( isSelected ? "red" : "#ccc" ), 'border-radius': "4px", padding: "2px 6px 0 6px", 'font-size': "12px" } }, [
|
|
|
|
+ h('input', {
|
|
|
|
+ style: { margin: "0 6px 0 0", position: "relative" },
|
|
|
|
+ type: "checkbox",
|
|
|
|
+ checked: isSelected,
|
|
|
|
+ onClick: handleClick,
|
|
|
|
+ }),
|
|
|
|
+ h('span', { style: { 'line-height': "20px" } }, this.props.from),
|
|
|
|
+ ])
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
var P5UI_AddItemToReport = createReactClass({
|
|
var P5UI_AddItemToReport = createReactClass({
|
|
getInitialState: function () {
|
|
getInitialState: function () {
|
|
|
|
+ // var listOd = getSelectedListFromLocalStorage('OD');
|
|
|
|
+ // var listDo = getSelectedListFromLocalStorage('DO');
|
|
return {
|
|
return {
|
|
baza: null,
|
|
baza: null,
|
|
newItemBaza: null,
|
|
newItemBaza: null,
|
|
@@ -213,6 +333,32 @@ var P5UI_AddItemToReport = createReactClass({
|
|
componentWillUnmount: function () {
|
|
componentWillUnmount: function () {
|
|
DBG && console.log("DBG: conponentDidUnmount...");
|
|
DBG && console.log("DBG: conponentDidUnmount...");
|
|
},
|
|
},
|
|
|
|
+ renderItemSave__OLD(selectedBaza, selectedItem) {
|
|
|
|
+ var _onSelect = this.props.onSelect;
|
|
|
|
+ return h('div', { style: { margin: '22px' } }, [
|
|
|
|
+ h('button', {
|
|
|
|
+ className: "btn btn-primary",
|
|
|
|
+ onClick: function () {
|
|
|
|
+ _onSelect(selectedBaza, selectedItem);
|
|
|
|
+ // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza'));
|
|
|
|
+ // swal.close()
|
|
|
|
+ }
|
|
|
|
+ }, "XXX Dodaj " + (
|
|
|
|
+ ( ('default_db/BI_audit_KRS_person/BI_audit_KRS_person' === selectedBaza)
|
|
|
|
+ || ('default_db/BI_audit_MSIG_person/BI_audit_MSIG_person' === selectedBaza)
|
|
|
|
+ )
|
|
|
|
+ ? "osobę"
|
|
|
|
+ : "firmę"
|
|
|
|
+ )) // TODO: |> KRS -> firmę, |> KRS Person -> osobę, ....
|
|
|
|
+ ]);
|
|
|
|
+ },
|
|
|
|
+ renderItemSave(selectedBaza, selectedItem) {
|
|
|
|
+ return h('div', { style: { margin: '22px', 'font-size': "16px" } }, [
|
|
|
|
+ "Dodaj jako: ",
|
|
|
|
+ h(P5UI_AddItemToReport_Checkbox, { from: 'OD', selectedBaza: selectedBaza, selectedItem: selectedItem }),
|
|
|
|
+ h(P5UI_AddItemToReport_Checkbox, { from: 'DO', selectedBaza: selectedBaza, selectedItem: selectedItem }),
|
|
|
|
+ ]);
|
|
|
|
+ },
|
|
render: function () {
|
|
render: function () {
|
|
var bazaBtns = [];
|
|
var bazaBtns = [];
|
|
bazaBtns.push({ baza: "default_db/BI_audit_KRS/BI_audit_KRS", title: "KRS - Firmy", label: "KRS" });
|
|
bazaBtns.push({ baza: "default_db/BI_audit_KRS/BI_audit_KRS", title: "KRS - Firmy", label: "KRS" });
|
|
@@ -223,8 +369,8 @@ var P5UI_AddItemToReport = createReactClass({
|
|
bazaBtns.push({ baza: "default_db/BI_audit_CEIDG/BI_audit_CEIDG", title: "CEIDG", label: "CEIDG" });
|
|
bazaBtns.push({ baza: "default_db/BI_audit_CEIDG/BI_audit_CEIDG", title: "CEIDG", label: "CEIDG" });
|
|
|
|
|
|
var newItemBtns = [];
|
|
var newItemBtns = [];
|
|
- newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY", title: "Nowa osoba", label: "Nowa osoba" });
|
|
|
|
- newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI", title: "Nowy podmiot", label: "Nowy podmiot" });
|
|
|
|
|
|
+ // newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY", title: "Nowa osoba", label: "Nowa osoba" });
|
|
|
|
+ // newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI", title: "Nowy podmiot", label: "Nowy podmiot" });
|
|
|
|
|
|
function generateBazaBtn(btn, opts) {
|
|
function generateBazaBtn(btn, opts) {
|
|
return h('button', {
|
|
return h('button', {
|
|
@@ -416,7 +562,7 @@ var P5UI_AddItemToReport = createReactClass({
|
|
return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
|
|
return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
|
|
}
|
|
}
|
|
}),
|
|
}),
|
|
- (selectedNewItemBaza === "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY") && h('div', { className: 'form-group' }, [
|
|
|
|
|
|
+ ("default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY" === selectedNewItemBaza) && h('div', { className: 'form-group' }, [
|
|
h('input',{
|
|
h('input',{
|
|
className:'form-control required',
|
|
className:'form-control required',
|
|
id:'personName',
|
|
id:'personName',
|
|
@@ -447,7 +593,7 @@ var P5UI_AddItemToReport = createReactClass({
|
|
swal.close();
|
|
swal.close();
|
|
}.bind(this) }, "Dodaj osobę")
|
|
}.bind(this) }, "Dodaj osobę")
|
|
]),
|
|
]),
|
|
- (selectedNewItemBaza === "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI") && h('div', { className: 'form-group' }, [
|
|
|
|
|
|
+ ("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI" === selectedNewItemBaza) && h('div', { className: 'form-group' }, [
|
|
h('input',{
|
|
h('input',{
|
|
className:'form-control required',
|
|
className:'form-control required',
|
|
id:'companyName',
|
|
id:'companyName',
|
|
@@ -514,22 +660,7 @@ var P5UI_AddItemToReport = createReactClass({
|
|
swal.close();
|
|
swal.close();
|
|
}.bind(this) }, "Dodaj podmiot")
|
|
}.bind(this) }, "Dodaj podmiot")
|
|
]),
|
|
]),
|
|
- (selectedBaza && selectedItem) && h('div', { style: { margin: '22px' } }, [
|
|
|
|
- h('button', {
|
|
|
|
- className: "btn btn-primary",
|
|
|
|
- onClick: function () {
|
|
|
|
- _onSelect(selectedBaza, selectedItem);
|
|
|
|
- // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza'));
|
|
|
|
- // swal.close()
|
|
|
|
- }
|
|
|
|
- }, "Dodaj " + (
|
|
|
|
- ( ('default_db/BI_audit_KRS_person/BI_audit_KRS_person' === selectedBaza)
|
|
|
|
- || ('default_db/BI_audit_MSIG_person/BI_audit_MSIG_person' === selectedBaza)
|
|
|
|
- )
|
|
|
|
- ? "osobę"
|
|
|
|
- : "firmę"
|
|
|
|
- )) // TODO: |> KRS -> firmę, |> KRS Person -> osobę, ....
|
|
|
|
- ]),
|
|
|
|
|
|
+ (selectedBaza && selectedItem) && this.renderItemSave(selectedBaza, selectedItem),
|
|
('default_db/BI_audit_KRS/BI_audit_KRS' === selectedBaza && selectedItem) && h(P5UI_AddItemToReport_SelectKrsPerson, {
|
|
('default_db/BI_audit_KRS/BI_audit_KRS' === selectedBaza && selectedItem) && h(P5UI_AddItemToReport_SelectKrsPerson, {
|
|
krs: selectedItem,
|
|
krs: selectedItem,
|
|
selectPerson: function (person) {
|
|
selectPerson: function (person) {
|
|
@@ -581,13 +712,14 @@ function addItemToRaport(event) {
|
|
onOpen: function () {
|
|
onOpen: function () {
|
|
ReactDOM.render(
|
|
ReactDOM.render(
|
|
h(P5UI_AddItemToReport, {
|
|
h(P5UI_AddItemToReport, {
|
|
- onSelect: function (baza, selected) {
|
|
|
|
- DBG && console.log('TODO: selected ', { baza, selected });
|
|
|
|
|
|
+ onSelect: function (from, baza, selected) {
|
|
|
|
+ DBG && console.log('TODO: selected ', { from, baza, selected });
|
|
global.fetch(URL_SAVE_TO_DB, {
|
|
global.fetch(URL_SAVE_TO_DB, {
|
|
method: 'POST',
|
|
method: 'POST',
|
|
credentials: 'same-origin',
|
|
credentials: 'same-origin',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
body: JSON.stringify({
|
|
|
|
+ from: from,
|
|
baza: baza,
|
|
baza: baza,
|
|
item: selected
|
|
item: selected
|
|
})
|
|
})
|