footable.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. (function (global, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define("/tables/footable", ["jquery", "Site"], factory);
  4. } else if (typeof exports !== "undefined") {
  5. factory(require("jquery"), require("Site"));
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory(global.jQuery, global.Site);
  11. global.tablesFootable = mod.exports;
  12. }
  13. })(this, function (_jquery, _Site) {
  14. "use strict";
  15. _jquery = babelHelpers.interopRequireDefault(_jquery);
  16. (0, _jquery.default)(document).ready(function ($$$1) {
  17. (0, _Site.run)();
  18. }); // Example Row Toggler
  19. // -------------------
  20. (function () {
  21. (0, _jquery.default)('#exampleRowToggler').footable({
  22. "toggleColumn": "first",
  23. "showToggle": true,
  24. "expandFirst": true
  25. });
  26. })(); // Accordion
  27. // ---------
  28. (function () {
  29. (0, _jquery.default)('#exampleFooAccordion').footable();
  30. })(); // Collapse
  31. // --------------------------
  32. (function () {
  33. (0, _jquery.default)('#exampleFooCollapse').footable();
  34. })(); // NO HEADERS
  35. // ----------
  36. (function () {
  37. (0, _jquery.default)('#exampleNoHeaders').footable();
  38. })(); // Pagination
  39. // ----------
  40. (function () {
  41. (0, _jquery.default)('#examplePagination').footable();
  42. (0, _jquery.default)('#exampleShow [data-page-size]').on('click', function (e) {
  43. e.preventDefault();
  44. var pagesize = (0, _jquery.default)(this).data('pageSize');
  45. FooTable.get('#examplePagination').pageSize(pagesize);
  46. });
  47. })(); // Custom filter UI
  48. // ----------
  49. (function () {
  50. (0, _jquery.default)('#exampleCustomFilter').footable();
  51. (0, _jquery.default)('.filter-ui-status').on('change', function () {
  52. var filtering = FooTable.get('#exampleCustomFilter').use(FooTable.Filtering),
  53. // get the filtering component for the table
  54. filter = (0, _jquery.default)(this).val(); // get the value to filter by
  55. if (filter === 'none') {
  56. // if the value is "none" remove the filter
  57. filtering.removeFilter('status');
  58. } else {
  59. // otherwise add/update the filter.
  60. filtering.addFilter('status', filter, ['status']);
  61. }
  62. filtering.filter();
  63. });
  64. })(); // Modal
  65. // ----------
  66. (function () {
  67. (0, _jquery.default)('#exampleModal').footable({
  68. "useParentWidth": true
  69. });
  70. })(); // Loading Rows
  71. // ----------
  72. (function () {
  73. (0, _jquery.default)('#exampleLoading').footable();
  74. var loading = FooTable.get('#exampleLoading');
  75. (0, _jquery.default)('.append-rows').on('click', function (e) {
  76. e.preventDefault(); // get the url to load off the button
  77. var url = (0, _jquery.default)(this).data('url'); // ajax fetch the rows
  78. _jquery.default.get(url).then(function (rows) {
  79. // and then load them using either
  80. loading.rows.load(rows); // or
  81. // ft.loadRows(rows);
  82. });
  83. });
  84. })(); // Filtering
  85. // ---------
  86. (function () {
  87. FooTable.MyFiltering = FooTable.Filtering.extend({
  88. construct: function construct(instance) {
  89. this._super(instance);
  90. this.statuses = ['Active', 'Disabled', 'Suspended'];
  91. this.def = 'Any Status';
  92. this.$status = null;
  93. },
  94. $create: function $create() {
  95. this._super();
  96. var self = this,
  97. $form_grp = (0, _jquery.default)('<div/>', {
  98. 'class': 'form-group'
  99. }).append((0, _jquery.default)('<label/>', {
  100. 'class': 'sr-only',
  101. text: 'Status'
  102. })).prependTo(self.$form);
  103. self.$status = (0, _jquery.default)('<select/>', {
  104. 'class': 'form-control'
  105. }).on('change', {
  106. self: self
  107. }, self._onStatusDropdownChanged).append((0, _jquery.default)('<option/>', {
  108. text: self.def
  109. })).appendTo($form_grp);
  110. _jquery.default.each(self.statuses, function (i, status) {
  111. self.$status.append((0, _jquery.default)('<option/>').text(status));
  112. });
  113. },
  114. _onStatusDropdownChanged: function _onStatusDropdownChanged(e) {
  115. var self = e.data.self,
  116. selected = (0, _jquery.default)(this).val();
  117. if (selected !== self.def) {
  118. self.addFilter('status', selected, ['status']);
  119. } else {
  120. self.removeFilter('status');
  121. }
  122. self.filter();
  123. },
  124. draw: function draw() {
  125. this._super();
  126. var status = this.find('status');
  127. if (status instanceof FooTable.Filter) {
  128. this.$status.val(status.query.val());
  129. } else {
  130. this.$status.val(this.def);
  131. }
  132. }
  133. });
  134. FooTable.components.register('filtering', FooTable.MyFiltering);
  135. var filtering = (0, _jquery.default)('#exampleFootableFiltering');
  136. filtering.footable();
  137. })(); // Editing Row
  138. // ----------------
  139. (function () {
  140. var $modal = (0, _jquery.default)('#editor-modal'),
  141. $editor = (0, _jquery.default)('#editor'),
  142. $editorTitle = (0, _jquery.default)('#editor-title'),
  143. ft = FooTable.init('#exampleFooEditing', {
  144. editing: {
  145. enabled: true,
  146. addRow: function addRow() {
  147. $modal.removeData('row');
  148. $editor[0].reset();
  149. $editorTitle.text('Add a new row');
  150. $modal.modal('show');
  151. },
  152. editRow: function editRow(row) {
  153. var values = row.val();
  154. $editor.find('#id').val(values.id);
  155. $editor.find('#firstName').val(values.firstName);
  156. $editor.find('#lastName').val(values.lastName);
  157. $editor.find('#jobTitle').val(values.jobTitle);
  158. $editor.find('#startedOn').val(values.startedOn.format('YYYY-MM-DD'));
  159. $editor.find('#dob').val(values.dob.format('YYYY-MM-DD'));
  160. $modal.data('row', row); // set the row data value for use later
  161. $editorTitle.text('Edit row #' + values.id); // set the modal title
  162. $modal.modal('show'); // display the modal
  163. },
  164. deleteRow: function deleteRow(row) {
  165. if (confirm('Are you sure you want to delete the row?')) {
  166. row.delete();
  167. }
  168. },
  169. $buttonShow: function $buttonShow() {
  170. return '<button type="button" class="btn btn-primary mr-10 footable-show">' + this.showText + "</button>";
  171. },
  172. $buttonHide: function $buttonHide() {
  173. return '<button type="button" class="btn btn-default footable-hide">' + this.hideText + "</button>";
  174. },
  175. $buttonAdd: function $buttonAdd() {
  176. return '<button type="button" class="btn btn-primary mr-15 footable-add">' + this.addText + "</button> ";
  177. }
  178. }
  179. }),
  180. uid = 10;
  181. $editor.on('submit', function (e) {
  182. if (this.checkValidity && !this.checkValidity()) return;
  183. e.preventDefault();
  184. var row = $modal.data('row'),
  185. values = {
  186. id: $editor.find('#id').val(),
  187. firstName: $editor.find('#firstName').val(),
  188. lastName: $editor.find('#lastName').val(),
  189. jobTitle: $editor.find('#jobTitle').val(),
  190. startedOn: moment($editor.find('#startedOn').val(), 'YYYY-MM-DD'),
  191. dob: moment($editor.find('#dob').val(), 'YYYY-MM-DD')
  192. };
  193. if (row instanceof FooTable.Row) {
  194. row.val(values);
  195. } else {
  196. values.id = uid++;
  197. ft.rows.add(values);
  198. }
  199. $modal.modal('hide');
  200. });
  201. })();
  202. });