var createReactClass = window.p5VendorJs.createReactClass; var h = window.p5VendorJs.React.createElement; var ReactDOM = window.p5VendorJs.ReactDOM; var AsyncTypeahead = window.p5VendorJs.AsyncTypeahead; var swal = window.swal; var STORE_NAME = STORE_NAME || '_anton1RaportStore'; var DBG = DBG || false; var DBG1 = true; function anton1FeatureKey(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 'Anton1.biAuditForm.odFeatureKeys'; case 'DO': return 'Anton1.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) { var _childCache = {}; // fieldName => { pk => child } items.forEach(function (item) { var refFields = Object.keys(item).filter(function (fieldName) { return (-1 !== fieldName.indexOf(':') && item[fieldName]); }); refFields.forEach(function (fieldName) { item[fieldName].forEach(function (child) { if (1 === Object.keys(child).length && 'xlink' in child) { // xlink } else if (Object.keys(child).length > 1) { if ('@primaryKey' in child) { if (!(fieldName in _childCache)) _childCache[fieldName] = {}; _childCache[fieldName][ child['@primaryKey'] ] = child; } } }) }) return item; }); DBG && console.log('DBG convertXlinkToObjects', { _childCache, items }); return items.map(function (item) { var refFields = Object.keys(item).filter(function (fieldName) { return (-1 !== fieldName.indexOf(':') && item[fieldName]); }); refFields.forEach(function (fieldName) { item[fieldName] = item[fieldName].map(function (child) { if (1 === Object.keys(child).length && 'xlink' in child) { var pk = child['xlink'].split('.').pop(); return _childCache[fieldName][pk]; } else if ('p5:links' in child && 'p5:next' in child['p5:links']) { return Object.assign({}, child['p5:links']['p5:next'], { type: 'p5:next' }); // child.value = "https://.../SE/wfs-data.php/?SERVICE=WFS&VERSION=1.0.0&TYPENAME=default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person&REQUEST=GetFeature&backRefNS=default_db/BI_audit_KRS/BI_audit_KRS&backRefPK=1332604&backRefField=default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person&maxFeatures=10&startIndex=10" } return child; }) }) return item; }) } function filterByHelper(option, node) { var text = (node && node.text) ? node.text : ''; var label = option.label.toLowerCase(); var words = ( (text.indexOf(' ') > 0) ? text.split(' ') : [ text ] ).map(function (word) { return word.trim().replace(/^[0]+/g, '').toLowerCase(); }) .filter(function (word) { return word.length > 2; }); var foundWords = words.filter(function (word) { return (label.indexOf(word) > -1); }) return (foundWords.length === words.length); } // function (option, text) { // if (option.ID == 161323) return false; // console.log('TODO: filterBy...', {option, text}); // return true; // }, var P5UI_AddItemToReport_SelectKrsPerson = createReactClass({ // h(SelectKrsPerson, { krs: this.state.selected }) // this.props.krs: { // "@primaryKey": "161323", // "A_kod": "80-299", // "A_kraj": "POLSKA", // "A_miejscowosc": "GDAŃSK", // "A_nrDomu": "54C", // "A_nrLokalu": null, // "A_poczta": "GDAŃSK", // "A_ulica": "BARNIEWICKA", // "ID": "161323", // "S_kraj": "POLSKA", // "S_miejscowosc": "GDAŃSK", // "S_wojewodztwo": "POMORSKIE", // "krs": "0000223476", // "nazwa": "BIALL Sp. z o.o.", // "nip": "6040018535", // "regon": "193106935", // "default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person": [ // { // "@primaryKey": "747004", // "ID": "747004", // "imiona": "ADRIAN RYSZARD", // "nazwisko": "WIECZORKOWSKI", // "pesel": "75040301615" // }, // { // "@primaryKey": "747003", // "ID": "747003", // "imiona": "EWA", // "nazwisko": "WIECZORKOWSKA", // "pesel": "75090401549" // }, // ... // { // "@backRefNS: "default_db/BI_audit_KRS/BI_audit_KRS" // @backRefPK: "1332604" // @maxFeatures: 10 // @startIndex: 10 // @typeName: "default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person" // type: "p5:next" // value: "https://biuro.biall-net.pl/dev-pl/se-projects/anton1/SE/wfs-data.php/?SERVICE=WFS&VERSION=1.0.0&TYPENAME=default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person&REQUEST=GetFeature&backRefNS=default_db/BI_audit_KRS/BI_audit_KRS&backRefPK=1332604&backRefField=default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person&maxFeatures=10&startIndex=10" // } getKrsPersonsFromProps: function () { return (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'] : []; }, handleFetchMore: function () { this.props.fetchMoreKrsPerson(this.props.krs); }, render: function () { var krsPresons = this.getKrsPersonsFromProps(); // var _selectPerson = this.props.selectPerson.bind(this) var selectedBaza = 'default_db/BI_audit_KRS_person/BI_audit_KRS_person'; var handleFetchMore = this.handleFetchMore.bind(this); return (krsPresons.length > 0) ? h('ol', { style: { margin: '22px', textAlign: 'left' } }, krsPresons.map(function (person) { var label = (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || ''); if ('type' in person && "p5:next" == person['type']) { return h('li', {}, [ h('a', { className: "btn btn-link", onClick: handleFetchMore }, "pobierz więcej ...") ]); } return h('li', {}, [ 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; } }); var P5UI_AddItemToReport_SelectMSIGPerson = createReactClass({ render: function () { // BI_audit_MSIG_person var msigPresons = (this.props.msig && 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 selectedBaza = 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person'; return (msigPresons.length > 0) ? h('ol', { style: { margin: '22px', textAlign: 'left' } }, msigPresons.map(function (person) { var label = (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || ''); return h('li', {}, [ 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; } }); var P5UI_AddItemToReport_BazaMenuItem = createReactClass({ // this.props: { key: option.ID, baza: selectedBaza, data: option } render: function () { return h('div', {}, this.props.data.label); } }); 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 = anton1FeatureKey(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__Anton1Header::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({ getInitialState: function () { // var listOd = getSelectedListFromLocalStorage('OD'); // var listDo = getSelectedListFromLocalStorage('DO'); return { baza: null, newItemBaza: null, isSearching: false, selected: null, }; }, _handleSelectBaza: function (baza) { this.setState({ baza: baza, newItemBaza: null, selected: null, isSearching: false }); }, _handleSelectNewItem: function (baza) { this.setState({ baza: null, newItemBaza: baza, selected: null, isSearching: false }); }, _handleSelected: function (selected) { this.setState({ selected: (selected.length > 0) ? selected[0] : null }); }, _fetchMoreKrsPerson: function (krs) { var _addMoreKrsPersons = this._addMoreKrsPersons.bind(this); var pk = krs['@primaryKey'] var krsPersons = (krs && krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person']) ? krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'] : []; var lastPerson = krsPersons[ krsPersons.length - 1 ]; if (lastPerson && 'type' in lastPerson && "p5:next" == lastPerson['type']) { var fetchNextLink = lastPerson['value']; DBG && console.log("DBG: fetchNextLink", { fetchNextLink }); var cols = [ 'ID', 'imiona', 'nazwisko', 'pesel' ]; p5WFS_GetFeature(lastPerson['@typeName'], { 'p5:next': fetchNextLink.replace('&maxFeatures=10', '&maxFeatures=100') + '&' + 'propertyName=' + cols.join(',') }).then(function (results) { DBG && console.log('DBG: _fetchMoreKrsPerson result', { results }); _addMoreKrsPersons(pk, results.map(function (item) { return Object.assign({}, item, { '@primaryKey': item['ID'] }) })); }) } else { DBG && console.log("DBG: missing fetch more link"); return; } }, _addMoreKrsPersons: function (pk, moreKrsPersons) { var newOptions = this.state.options.map(function (item) { if (item['@primaryKey'] === pk) { item['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'].pop() // rm last link node - p5:link/p5:next return Object.assign(item, { 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person': item['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'].concat(moreKrsPersons) }) } return item; }); this.setState({ options: newOptions }) }, _handleSearch: function (query) { this.setState({ isSearching: true }); var _setState = this.setState.bind(this); var baza = this.state.baza; window.fetch(URL_FETCH_FROM_BAZA, { method: 'POST', header: { 'contentType': 'applications/json' }, credentials: 'same-origin', body: JSON.stringify({ baza: baza, query: query, }) }) .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); if (result.body && result.body.items && result.body.items.length > 0) { return result.body.items; } else { p5UI__notifyAjaxCallback({ type: 'warning', msg: "Brak danych pasujących do kryteriów wyszukiwania" }); _setState({ isSearching: false, options: [] }); } } }) .then(function(items) { DBG && console.log('items fetched:', items); _setState({ isSearching: false, options: convertXlinkToObjects(items) }); }) .catch(function(error) { DBG && console.log('request failed', error); }) }, componentWillUnmount: function () { 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 () { 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_person/BI_audit_KRS_person", title: "KRS - Osoby", label: "KRS/p" }); bazaBtns.push({ baza: "default_db/BI_audit_MSIG/BI_audit_MSIG", title: "MSIG - Firmy", label: "MSIG" }); bazaBtns.push({ baza: "default_db/BI_audit_MSIG_person/BI_audit_MSIG_person", title: "MSIG - Osoby", label: "MSIG/p" }); //bazaBtns.push({ baza: "default_db/BI_audit_taxpayer/BI_audit_taxpayer", title: "VAT - Aktywni płatnicy", label: "VATp" }); bazaBtns.push({ baza: "default_db/BI_audit_CEIDG/BI_audit_CEIDG", title: "CEIDG", label: "CEIDG" }); 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" }); function generateBazaBtn(btn, opts) { return h('button', { title: btn.title, className: "btn btn-success" + (opts.selected ? " active" : ""), style: { margin: "3px" }, onClick: function () { opts.onClick(btn.baza) }, }, btn.label) } function generateNewItemBtn(btn, opts) { return h('button', { title: btn.title, className: "btn btn-success" + (opts.selected ? " active" : ""), style: { margin: "3px" }, onClick: function () { opts.onClick(btn.baza) }, }, btn.label) } var handleSelectBaza = this._handleSelectBaza.bind(this); var handleSelectNewItem = this._handleSelectNewItem.bind(this); var selectedBaza = this.state.baza; var selectedNewItemBaza = this.state.newItemBaza; var selectedItem = this.state.selected; var selectedLabel = ''; if (selectedBaza) { var selBazaBtn = bazaBtns.filter(function (btn) { return btn.baza === selectedBaza; }) if (selBazaBtn) { selBazaBtn[0].title } } var handleSearch = this._handleSearch.bind(this); var handleSelected = this._handleSelected.bind(this); var _onSelect = this.props.onSelect; var _fetchMoreKrsPerson = this._fetchMoreKrsPerson.bind(this); DBG && console.log('DBG: render this.state.options', this.state.options); return h('div', {}, [ h('p', { style: { textAlign: "center" } }, "Wybierz bazę"), h('div', { style: { marginBottom: '22px' } }, bazaBtns.map(function (btn) { return generateBazaBtn(btn, { onClick: handleSelectBaza, selected: (selectedBaza === btn.baza), }); }).concat( newItemBtns.map(function (btn) { return generateNewItemBtn(btn, { onClick: handleSelectNewItem, selected: (selectedNewItemBaza === btn.baza), }); }) ) ), ('default_db/BI_audit_KRS/BI_audit_KRS' === selectedBaza) && h(AsyncTypeahead, { isLoading: this.state.isSearching, allowNew: false, multiple: false, options: this.state.options, labelKey: "label", emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania", searchText: "Wyszukiwanie...", // labelKey: function (option) { // return [ // option.nazwa.replace('"', ''), // option.nip, // option.krs, // option.regon, // option.S_miejscowosc, // ].join(' ') // }, minLength: 3, onSearch: handleSearch, placeholder: "Wyszukaj...", onChange: handleSelected, autoFocus: true, filterBy: filterByHelper, renderMenuItemChildren: function (option, props) { return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option }); } }), ('default_db/BI_audit_KRS_person/BI_audit_KRS_person' === selectedBaza) && h(AsyncTypeahead, { isLoading: this.state.isSearching, allowNew: false, multiple: false, options: this.state.options, labelKey: "label", emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania", searchText: "Wyszukiwanie...", // labelKey: function (option) { // return [ // option.nazwa.replace('"', ''), // option.nip, // option.krs, // option.regon, // option.S_miejscowosc, // ].join(' ') // }, minLength: 3, onSearch: handleSearch, placeholder: "Wyszukaj...", onChange: handleSelected, autoFocus: true, filterBy: filterByHelper, renderMenuItemChildren: function (option, props) { return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option }); } }), ('default_db/BI_audit_MSIG/BI_audit_MSIG' === selectedBaza) && h(AsyncTypeahead, { isLoading: this.state.isSearching, allowNew: false, multiple: false, options: this.state.options, labelKey: "label", emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania", searchText: "Wyszukiwanie...", // labelKey: function (option) { // return [ // option.nazwa.replace('"', ''), // option.nip, // option.krs, // option.regon, // option.S_miejscowosc, // ].join(' ') // }, minLength: 3, onSearch: handleSearch, placeholder: "Wyszukaj...", onChange: handleSelected, autoFocus: true, filterBy: filterByHelper, renderMenuItemChildren: function (option, props) { return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option }); } }), ('default_db/BI_audit_MSIG_person/BI_audit_MSIG_person' === selectedBaza) && h(AsyncTypeahead, { isLoading: this.state.isSearching, allowNew: false, multiple: false, options: this.state.options, labelKey: "label", emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania", searchText: "Wyszukiwanie...", // labelKey: function (option) { // return [ // option.nazwa.replace('"', ''), // option.nip, // option.krs, // option.regon, // option.S_miejscowosc, // ].join(' ') // }, minLength: 3, onSearch: handleSearch, placeholder: "Wyszukaj...", onChange: handleSelected, autoFocus: true, filterBy: filterByHelper, renderMenuItemChildren: function (option, props) { return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option }); } }), ('default_db/BI_audit_CEIDG/BI_audit_CEIDG' === selectedBaza) && h(AsyncTypeahead, { isLoading: this.state.isSearching, allowNew: false, multiple: false, options: this.state.options, labelKey: "label", emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania", searchText: "Wyszukiwanie...", // labelKey: function (option) { // return [ // option.nazwa.replace('"', ''), // option.nip, // option.krs, // option.regon, // option.S_miejscowosc, // ].join(' ') // }, minLength: 3, onSearch: handleSearch, placeholder: "Wyszukaj...", onChange: handleSelected, autoFocus: true, filterBy: filterByHelper, renderMenuItemChildren: function (option, props) { return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option }); } }), ("default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY" === selectedNewItemBaza) && h('div', { className: 'form-group' }, [ h('input',{ className:'form-control required', id:'personName', placeholder:'Imię' }), h('input',{ className:'form-control required', id:'personSurname', placeholder:'Nazwisko' }), h('input',{ className:'form-control required', id:'personPesel', placeholder:'Pesel' }), h('input',{ className:'form-control', id:'personNip', placeholder:'NIP' }), h('button', { className: "btn btn-primary", onClick: function () { _onSelect(selectedNewItemBaza, { personName: document.getElementById('personName').value, personSurname: document.getElementById('personSurname').value, personPesel: document.getElementById('personPesel').value, personNip: document.getElementById('personNip').value, }) swal.close(); }.bind(this) }, "Dodaj osobę") ]), ("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI" === selectedNewItemBaza) && h('div', { className: 'form-group' }, [ h('input',{ className:'form-control required', id:'companyName', placeholder:'Nazwa' }), h('input',{ className:'form-control required', id:'companyPesel', placeholder:'Pesel' }), h('input',{ className:'form-control required', id:'companyStreet', placeholder:'Ulica' }), h('input',{ className:'form-control required', id:'companyNumber', placeholder:'Numer budynku' }), h('input',{ className:'form-control required', id:'companyNumberLocal', placeholder:'Numer lokalu' }), h('input',{ className:'form-control required', id:'companyPostCode', placeholder:'Kod pocztowy' }), h('input',{ className:'form-control required', id:'companyCity', placeholder:'Miejscowosc' }), h('input',{ className:'form-control required', id:'companyNip', placeholder:'NIP' }), h('input',{ className:'form-control', id:'companyRegon', placeholder:'REGON' }), h('input',{ className:'form-control', id:'companyKrs', placeholder:'KRS' }), h('button', { className: "btn btn-primary", onClick: function () { _onSelect(selectedNewItemBaza, { companyName: document.getElementById('companyName').value, companyNip: document.getElementById('companyNip').value, companyRegon: document.getElementById('companyRegon').value, companyPesel: document.getElementById('companyPesel').value, companyStreet: document.getElementById('companyStreet').value, companyNumber: document.getElementById('companyNumber').value, companyNumberLocal: document.getElementById('companyNumberLocal').value, companyPostCode: document.getElementById('companyPostCode').value, companyCity: document.getElementById('companyCity').value, companyKrs: document.getElementById('companyKrs').value, }) swal.close(); }.bind(this) }, "Dodaj podmiot") ]), (selectedBaza && selectedItem) && this.renderItemSave(selectedBaza, selectedItem), ('default_db/BI_audit_KRS/BI_audit_KRS' === selectedBaza && selectedItem) && h(P5UI_AddItemToReport_SelectKrsPerson, { krs: selectedItem, selectPerson: function (person) { _onSelect("default_db/BI_audit_KRS_person/BI_audit_KRS_person", person); // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza')); // swal.close() }, fetchMoreKrsPerson: _fetchMoreKrsPerson }), ('default_db/BI_audit_MSIG/BI_audit_MSIG' === selectedBaza && selectedItem) && h(P5UI_AddItemToReport_SelectMSIGPerson, { msig: selectedItem, selectPerson: function (person) { _onSelect("default_db/BI_audit_MSIG_person/BI_audit_MSIG_person", person); // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza')); // swal.close() } }), (DBG && selectedItem) && h('pre', { style: { textAlign: 'left' } }, JSON.stringify(selectedItem, null, 2)), ]) } }); function getWindowWidth() { var w = window, d = document, e = d.documentElement, g = d.getElementsByTagName('body')[0]; return w.innerWidth || e.clientWidth || g.clientWidth; } function addItemToRaport(event) { // default_db/BI_audit_KRS/BI_audit_KRS // default_db/BI_audit_KRS_person/BI_audit_KRS_person // default_db/BI_audit_MSIG/BI_audit_MSIG // default_db/BI_audit_MSIG_person/BI_audit_MSIG_person // default_db/BI_audit_taxpayer/BI_audit_taxpayer // default_db/BI_audit_CEIDG/BI_audit_CEIDG // default_db/BI_audit_ENERGA_RUM_UMOWY/BI_audit_ENERGA_RUM_UMOWY // default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI // default_db/BI_audit_ENERGA_FAKTURY/BI_audit_ENERGA_FAKTURY var valueUrl = global.location.hash; swal({ title: "Dodaj osobę lub podmiot", width: (getWindowWidth() * 0.8), html: '
', animation: false, showConfirmButton: false, showCancelButton: false, showCloseButton: true, allowEnterKey: false, onOpen: function () { ReactDOM.render( h(P5UI_AddItemToReport, { onSelect: function (from, baza, selected) { DBG && console.log('TODO: selected ', { from, baza, selected }); global.fetch(URL_SAVE_TO_DB, { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ from: from, baza: baza, item: selected }) }).then(function(response) { return response.json(); }).then(function(result) { if(result.type === "success"){ if(valueUrl === '#PRACOWNICY'){ urlFetchPracownicy(1); }else{ urlFetchKontrahenci(1); } } p5UI__notifyAjaxCallback(result); }) } }), document.getElementById(FUNCTION_NAME + '__searchBaza') ) } }).catch(function (err) { DBG && console.log('err', err) }) } // global[FUNCTION_NAME] = addItemToRaport; module.exports[FUNCTION_NAME] = addItemToRaport; // module.exports = { // P5UI_AddItemToReport_BazaMenuItem, // P5UI_AddItemToReport, // createPracownikAjax // }