defaultPage.php.widget-przypomnij.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. var DBG = DBG || 0;
  2. var DBG1 = true;
  3. if (!NAMESPACE) throw "Missing NAMESPACE";
  4. if (!USER_LOGIN) throw "Missing USER_LOGIN";
  5. if (!HTML_NODE_ID) throw "Missing HTML_NODE_ID";
  6. if (!VIEW_ALL_LINK) throw "Missing VIEW_ALL_LINK";
  7. if (!global.p5VendorJs) throw "Missing vendor.js";
  8. if (!global.p5WFS_GetFeature) throw "Missing p5WFS_GetFeature";
  9. var REQUEST_LIMIT = (REQUEST_LIMIT) ? REQUEST_LIMIT : 10;
  10. var createReactClass = global.p5VendorJs.createReactClass;
  11. var h = global.p5VendorJs.React.createElement;
  12. var ReactDOM = global.p5VendorJs.ReactDOM;
  13. var p5WFS_GetFeature = global.p5WFS_GetFeature;
  14. var P5UI__WidgetPrzypomnij = createReactClass({
  15. getInitialState: function () {
  16. return {
  17. response: [],
  18. isLoading: false,
  19. errorMsg: '',
  20. }
  21. },
  22. componentDidMount: function() {
  23. DBG && console.log('DBG:P5UI__WidgetPrzypomnij:componentDidMount');
  24. this.setState({ isLoading: true })
  25. p5WFS_GetFeature(this.props.namespace, {
  26. sortBy: 'L_APPOITMENT_DATE+A',
  27. maxFeatures: REQUEST_LIMIT,
  28. 'ogc:Filter': '<wfs:Query>' + '\n' +
  29. '<ogc:Filter>' + '\n' +
  30. '<ogc:And>' + '\n' +
  31. '<ogc:PropertyIsEqualTo>' + '\n' +
  32. '<ogc:PropertyName>' + "L_APPOITMENT_USER" + '</ogc:PropertyName>' + "\n" +
  33. '<ogc:Literal>' + this.props.login + '</ogc:Literal>' + "\n" +
  34. '</ogc:PropertyIsEqualTo>' + '\n' +
  35. '</ogc:And>' + '\n' +
  36. '</ogc:Filter>' + '\n' +
  37. '</wfs:Query>',
  38. }).then(this.handleWfsResponse.bind(this))
  39. .catch(this.handleWfsError.bind(this))
  40. },
  41. handleWfsResponse: function (response) {
  42. DBG && console.log('DBG:P5UI__WidgetPrzypomnij:handleWfsResponse', { response });
  43. this.setState({
  44. isLoading: false,
  45. response: response,
  46. })
  47. },
  48. handleWfsError: function (error) {
  49. DBG && console.log('DBG:P5UI__WidgetPrzypomnij:handleWfsError', { error });
  50. this.setState({
  51. isLoading: false,
  52. errorMsg: '' + error,
  53. })
  54. },
  55. renderLoading: function () {
  56. return h('p', {}, "loading...");
  57. },
  58. renderEmpty: function () {
  59. if (this.state.errorMsg) return this.renderErrorMsg();
  60. return h('p', {}, "Brak danych");
  61. },
  62. renderErrorMsg: function () {
  63. return h('div', { className: "alert alert-danger" }, this.state.errorMsg);
  64. },
  65. renderRow: function (row) {
  66. // A_STATUS: "WAITING"
  67. // L_APPOITMENT_DATE: "2013-02-01 00:00:00"
  68. // L_APPOITMENT_INFO: "..."
  69. // L_APPOITMENT_USER: "..."
  70. // PROJECT__ID: "0"
  71. // USER__IS_ACTIVE: "1"
  72. // featureDesc: "Przycisk - Zapisz"
  73. // featureType: "NARZEDZIE"
  74. // feature_id: "CRM_LISTA_ZASOBOW.3954"
  75. // namespace: "default_db/CRM_LISTA_ZASOBOW"
  76. // primaryKey: "3954"
  77. return h('tr', {}, [
  78. h('td', { style: { whiteSpace: "pre" } }, row['L_APPOITMENT_DATE'].substr(0, 10)),
  79. h('td', {}, row['L_APPOITMENT_INFO']),
  80. h('td', {}, [
  81. h('a', {
  82. href: 'index.php?_route=ViewTableAjax&namespace=' + row['namespace'] + '#EDIT/' + row['primaryKey'],
  83. className: "btn btn-xs btn-link"
  84. }, "Edytuj " + row['primaryKey'])
  85. ]),
  86. ]);
  87. },
  88. render: function () {
  89. DBG && console.log('DBG:P5UI__WidgetPrzypomnij:render', { props: this.props, state: this.state });
  90. if (this.state.isLoading) return this.renderLoading();
  91. if (!this.state.response.length) return this.renderEmpty();
  92. return h('table', { className: "table table-condensed table-bordered" }, [
  93. h('thead', {}, [
  94. h('tr', {}, [
  95. h('th', {}, "Termin"),
  96. h('th', {}, "Opis"),
  97. h('th', {}, "Rekord"),
  98. ]),
  99. ]),
  100. h('tfoot', {}, [
  101. h('tr', {}, [
  102. h('td', { colSpan: 3, style: { padding: "12px", textAlign: "center" } }, [
  103. h('a', {
  104. href: VIEW_ALL_LINK,
  105. }, "przeglądaj wszystkie")
  106. ]),
  107. ]),
  108. ]),
  109. h('tbody', {}, this.state.response.map(this.renderRow)),
  110. ]);
  111. }
  112. });
  113. ReactDOM.render(
  114. h(P5UI__WidgetPrzypomnij, {
  115. namespace: NAMESPACE,
  116. login: USER_LOGIN,
  117. }),
  118. document.getElementById(HTML_NODE_ID)
  119. );