|
172 | 172 | var Griddly = function (element, options) |
173 | 173 | { |
174 | 174 | this.$element = $(element); |
| 175 | + this.$filterModal = $(".griddly-filter-modal", this.$element); |
175 | 176 | this.options = options; |
176 | 177 | this.create(); |
177 | 178 | this.isConstructed = false; |
|
306 | 307 |
|
307 | 308 | }, this); |
308 | 309 |
|
| 310 | + var self = this; |
| 311 | + |
| 312 | + this.$filterModal |
| 313 | + .on("show.bs.modal", function () |
| 314 | + { |
| 315 | + var values = self.getFilterValues(); |
| 316 | + |
| 317 | + $(".griddly-filter-cancel, button.close", this).off("click").on("click", function () |
| 318 | + { |
| 319 | + if (self.$element.triggerHandler("beforeclear.griddly") !== false) |
| 320 | + self.setFilterValues(values, null, true, true); |
| 321 | + }); |
| 322 | + }) |
| 323 | + .on("shown.bs.modal", function () |
| 324 | + { |
| 325 | + $(".modal-body :input:visible:not([disabled]):not([data-griddly-filter-data-type=Date]):first", this).focus(); |
| 326 | + }); |
| 327 | + |
309 | 328 | this.isConstructed = true; |
310 | 329 | }; |
311 | 330 |
|
|
417 | 436 |
|
418 | 437 | $("form", this.$element).on("submit", $.proxy(function (event) |
419 | 438 | { |
420 | | - $(event.currentTarget).closest(".griddly-filter-modal").modal("hide"); |
| 439 | + this.$filterModal.modal("hide"); |
421 | 440 |
|
422 | 441 | this.refresh(true); |
423 | 442 |
|
|
794 | 813 | this.triggerOrQueue(this.$element, "filterchange.griddly", this.$element, event.target); |
795 | 814 | }, this)); |
796 | 815 |
|
| 816 | + // TODO: exclude this if the modal is still in griddly-filters-form? does it dupe? |
| 817 | + $(this.$filterModal).on("change", "input, select", $.proxy(function (event) |
| 818 | + { |
| 819 | + if (!this._isUpdatingFilters) |
| 820 | + this.triggerOrQueue(this.$element, "filterchange.griddly", this.$element, event.target); |
| 821 | + }, this)); |
| 822 | + |
797 | 823 | $(".griddly-filters-inline .filter-content input", this.$element).keyup(function (event) |
798 | 824 | { |
799 | 825 | if (event.which == 13) |
|
1049 | 1075 |
|
1050 | 1076 | invokeFilterModal: function () |
1051 | 1077 | { |
1052 | | - var self = this; |
1053 | | - |
1054 | | - $(".griddly-filter-modal", this.$element) |
1055 | | - .on("show.bs.modal", function () |
1056 | | - { |
1057 | | - var values = self.getFilterValues(); |
1058 | | - |
1059 | | - $(".griddly-filter-cancel", this).off("click").on("click", function () |
1060 | | - { |
1061 | | - if (self.$element.triggerHandler("beforeclear.griddly") !== false) |
1062 | | - self.setFilterValues(values, null, false, true); |
1063 | | - }); |
1064 | | - }) |
1065 | | - .on("shown.bs.modal", function () |
1066 | | - { |
1067 | | - $(".modal-body :input:visible:not([disabled]):first", this).focus(); |
1068 | | - }) |
1069 | | - .modal("show"); |
| 1078 | + this.$filterModal.modal("show"); |
1070 | 1079 | }, |
1071 | 1080 |
|
1072 | 1081 | getAllFilterElements: function () |
|
1079 | 1088 | } |
1080 | 1089 | else |
1081 | 1090 | { |
1082 | | - allFilters = $(".griddly-filters-form input[name], .griddly-filters-form select[name]", this.$element); |
| 1091 | + allFilters = $(".griddly-filters-form input[name], .griddly-filters-form select[name]", this.$element) |
| 1092 | + .add($("input[name], select[name]", this.$filterModal)); |
1083 | 1093 | } |
1084 | 1094 |
|
1085 | 1095 | return allFilters; |
|
1092 | 1102 | if (this.options.filterMode == "Inline") |
1093 | 1103 | return this.$inlineFilters.filter(filter); |
1094 | 1104 | else |
1095 | | - return $(".griddly-filters-form input" + filter + ", .griddly-filters-form select" + filter, this.$element); |
| 1105 | + return $(".griddly-filters-form input" + filter + ", .griddly-filters-form select" + filter, this.$element) |
| 1106 | + .add($("input[name], select[name]", this.$filterModal)); |
1096 | 1107 | }, |
1097 | 1108 |
|
1098 | 1109 | getFilterValues: function () |
|
1199 | 1210 |
|
1200 | 1211 | if (resetNone) |
1201 | 1212 | // clear any none's that were inadvertently reset |
1202 | | - this.$element.find(".griddly-filters-form [data-griddly-filter-isnoneall=true] [multiple] option[value='']").prop("selected", false); |
| 1213 | + this.$element.find(".griddly-filters-form [data-griddly-filter-isnoneall=true] [multiple] option[value='']") |
| 1214 | + .add(this.$filterModal.find("[data-griddly-filter-isnoneall=true] [multiple] option[value='']")) |
| 1215 | + .prop("selected", false); |
1203 | 1216 |
|
1204 | 1217 | this.triggerOrQueue(this.$element, "setfilters.griddly", filters); |
1205 | 1218 |
|
|
0 commit comments