Bocian.php.addItemToRaport.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. const createReactClass = window.p5VendorJs.createReactClass;
  2. const h = window.p5VendorJs.React.createElement;
  3. const ReactDOM = window.p5VendorJs.ReactDOM;
  4. const AsyncTypeahead = window.p5VendorJs.AsyncTypeahead;
  5. const swal = window.swal;
  6. const DBG = 1;
  7. var P5UI_AddItemToReport_BazaMenuItem = createReactClass({
  8. // this.props: { key: option.ID, baza: selectedBaza, data: option }
  9. render: function () {
  10. return h('div', {}, this.props.data.label);
  11. }
  12. })
  13. var P5UI_AddItemToReport = createReactClass({
  14. getInitialState: function () {
  15. return {
  16. baza: null,
  17. newItemBaza: null,
  18. isSearching: false,
  19. selected: null,
  20. };
  21. },
  22. _handleSelectBaza: function (baza) {
  23. this.setState({ baza: baza, newItemBaza: null });
  24. },
  25. _handleSelectNewItem: function (baza) {
  26. this.setState({ baza: null, newItemBaza: baza });
  27. },
  28. _handleSelected: function (selected) {
  29. this.setState({ selected: (selected.length > 0) ? selected[0] : null });
  30. },
  31. _handleSearch: function (query) {
  32. this.setState({ isSearching: true });
  33. setTimeout(function () {
  34. var options = [];
  35. options.push({
  36. ID: 601900,
  37. nazwa: "ADEGROUP SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ SPÓŁKA KOMANDYTOWA",
  38. krs: "0000721712", nip: "5862328735", regon: "369609850",
  39. S_kraj: "POLSKA", S_miejscowosc: "GDYNIA", A_kod: "81-310", A_ulica: "ŚLĄSKA", A_nrDomu: "35/37",
  40. searchLabel: "ADEGROUP SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ SPÓŁKA KOMANDYTOWA, ŚLĄSKA 35/37, 81-310 GDYNIA, krs: 0000721712, nip: 5862328735, regon: 369609850",
  41. label: "ADEGROUP SPÓŁKA ..., ŚLĄSKA 35/37, 81-310 GDYNIA"
  42. })
  43. options.push({
  44. ID: 601900,
  45. nazwa: "BIZNESLIMIT.PL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ",
  46. krs: "0000721708", nip: "9452218050", regon: "369608402",
  47. S_kraj: "POLSKA", S_miejscowosc: "KRAKÓW", A_kod: "31-315", A_ulica: "ELIASZA RADZIKOWSKIEGO", A_nrLokalu: "16", A_nrDomu: "74",
  48. searchLabel: "BIZNESLIMIT.PL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ ELIASZA RADZIKOWSKIEGO 74/16, 31-315 KRAKÓW 0000721708 9452218050 369608402",
  49. label: "BIZNESLIMIT.PL ..., ELIASZA RADZIKOWSKIEGO 74/16, 31-315 KRAKÓW"
  50. })
  51. this.setState({ isSearching: true, options: options });
  52. }.bind(this), 1000);
  53. // makeAndHandleRequest(query)
  54. // .then(({ options }) => {
  55. // this.setState({
  56. // isLoading: false,
  57. // options,
  58. // });
  59. // });
  60. },
  61. componentWillUnmount: function () {
  62. DBG && console.log("DBG: conponentDidUnmount...");
  63. },
  64. render: function () {
  65. // '<div>' +
  66. // '<p style="text-align:center">' + 'Wybierz bazę' + '</p>' +
  67. // '<div>' + .join(' ') + '</div>' +
  68. // +
  69. // '</div>',
  70. var bazaBtns = [];
  71. bazaBtns.push({ baza: "default_db/BI_audit_KRS/BI_audit_KRS", title: "KRS - Firmy", label: "KRS" });
  72. bazaBtns.push({ baza: "default_db/BI_audit_KRS_person/BI_audit_KRS_person", title: "KRS - Osoby", label: "KRS/p" });
  73. bazaBtns.push({ baza: "default_db/BI_audit_MSIG/BI_audit_MSIG", title: "MSIG - Firmy", label: "MSIG" });
  74. bazaBtns.push({ baza: "default_db/BI_audit_MSIG_person/BI_audit_MSIG_person", title: "KRS - Osoby", label: "MSIG/p" });
  75. bazaBtns.push({ baza: "default_db/BI_audit_taxpayer/BI_audit_taxpayer", title: "VAT - Aktywni płatnicy", label: "VATp" });
  76. bazaBtns.push({ baza: "default_db/BI_audit_CEIDG/BI_audit_CEIDG", title: "CEIDG", label: "CEIDG" });
  77. // bazaBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_UMOWY/BI_audit_ENERGA_RUM_UMOWY", title: "RUM Umowy", label: "RUM/u" });
  78. // bazaBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI", title: "RUM Kontrahenci", label: "RUM/k" });
  79. // bazaBtns.push({ baza: "default_db/BI_audit_ENERGA_FAKTURY/BI_audit_ENERGA_FAKTURY", title: "Faktury - do imoportowania", label: "Faktury" });
  80. var newItemBtns = [];
  81. newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY", title: "Nowa osoba", label: "Nowa osoba" });
  82. newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI", title: "Nowy podmiot", label: "Nowy podmiot" });
  83. function generateBazaBtn(btn, opts) {
  84. return h('button', {
  85. title: btn.title,
  86. className: "btn btn-success" + (opts.selected ? " active" : ""),
  87. style: { margin: "3px" },
  88. onClick: function () {
  89. opts.onClick(btn.baza)
  90. },
  91. }, btn.label)
  92. }
  93. function generateNewItemBtn(btn, opts) {
  94. return h('button', {
  95. title: btn.title,
  96. className: "btn btn-success" + (opts.selected ? " active" : ""),
  97. style: { margin: "3px" },
  98. onClick: function () {
  99. opts.onClick(btn.baza)
  100. },
  101. }, btn.label)
  102. }
  103. var handleSelectBaza = this._handleSelectBaza.bind(this);
  104. var handleSelectNewItem = this._handleSelectNewItem.bind(this);
  105. var selectedBaza = this.state.baza;
  106. var selectedNewItem = this.state.newItemBaza;
  107. var selectedLabel = '';
  108. if (selectedBaza) {
  109. var selBazaBtn = bazaBtns.filter(function (btn) { return btn.baza === selectedBaza; })
  110. if (selBazaBtn) {
  111. selBazaBtn[0].title
  112. }
  113. }
  114. var handleSearch = this._handleSearch.bind(this);
  115. var handleSelected = this._handleSelected.bind(this);
  116. return h('div', {}, [
  117. h('p', { style: { textAlign: "center" } }, "Wybierz bazę"),
  118. h('div', { style: { marginBottom: '22px' } },
  119. bazaBtns.map(function (btn) {
  120. return generateBazaBtn(btn, {
  121. onClick: handleSelectBaza,
  122. selected: (selectedBaza === btn.baza),
  123. });
  124. }).concat(
  125. newItemBtns.map(function (btn) {
  126. return generateNewItemBtn(btn, {
  127. onClick: handleSelectNewItem,
  128. selected: (selectedNewItem === btn.baza),
  129. });
  130. })
  131. )
  132. ),
  133. selectedBaza && h(AsyncTypeahead, {
  134. isLoading: this.state.isSearching,
  135. allowNew: false,
  136. multiple: false,
  137. options: this.state.options,
  138. labelKey: "searchLabel",
  139. minLength: 2,
  140. onSearch: handleSearch,
  141. placeholder: "Wyszukaj...",
  142. onChange: handleSelected,
  143. autoFocus: true,
  144. // filterBy: function (option, text) {
  145. // console.log('TODO: filterBy...', {option, text});
  146. // return true;
  147. // },
  148. renderMenuItemChildren: function (option, props) {
  149. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  150. }
  151. }),
  152. selectedNewItem && h('p', {}, "Dodaj nowy ... " + selectedNewItem),
  153. // '' === selectedNewItem && h
  154. (selectedBaza && this.state.selected) && h('div', { style: { marginTop: '22px' } }, [
  155. h('button', {
  156. className: "btn btn-success active",
  157. onClick: function () {
  158. ReactDOM.unmountComponentAtNode(document.getElementById('createPracownikAjax__searchBaza'));
  159. swal.close()
  160. }
  161. }, "Dodaj")
  162. ])
  163. ])
  164. }
  165. })
  166. function getWindowWidth() {
  167. var w = window, d = document,
  168. e = d.documentElement,
  169. g = d.getElementsByTagName('body')[0];
  170. return w.innerWidth || e.clientWidth || g.clientWidth;
  171. }
  172. function createPracownikAjax(event) {
  173. // default_db/BI_audit_KRS/BI_audit_KRS
  174. // default_db/BI_audit_KRS_person/BI_audit_KRS_person
  175. // default_db/BI_audit_MSIG/BI_audit_MSIG
  176. // default_db/BI_audit_MSIG_person/BI_audit_MSIG_person
  177. // default_db/BI_audit_taxpayer/BI_audit_taxpayer
  178. // default_db/BI_audit_CEIDG/BI_audit_CEIDG
  179. // default_db/BI_audit_ENERGA_RUM_UMOWY/BI_audit_ENERGA_RUM_UMOWY
  180. // default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI
  181. // default_db/BI_audit_ENERGA_FAKTURY/BI_audit_ENERGA_FAKTURY
  182. swal({
  183. title: "Dodaj osobę lub podmiot",
  184. width: (getWindowWidth() * 0.8),
  185. html: '<div id="createPracownikAjax__searchBaza" style="padding:0 24px 24px 24px"></div>',
  186. animation: false,
  187. showConfirmButton: false,
  188. showCancelButton: false,
  189. showCloseButton: true,
  190. onOpen: function () {
  191. ReactDOM.render(
  192. h(P5UI_AddItemToReport, {
  193. onSelect: function (baza, selected) {
  194. console.log('TODO: selected ', { baza, selected });
  195. }
  196. }),
  197. document.getElementById('createPracownikAjax__searchBaza')
  198. )
  199. }
  200. }).catch(function (err) {
  201. DBG && console.log('err', err)
  202. })
  203. }
  204. global.createPracownikAjax = createPracownikAjax;
  205. // module.exports = {
  206. // P5UI_AddItemToReport_BazaMenuItem,
  207. // P5UI_AddItemToReport,
  208. // createPracownikAjax
  209. // }