Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

dataTables.searchBuilder.js 155KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494
  1. /*! SearchBuilder 1.0.1
  2. * ©2020 SpryMedia Ltd - datatables.net/license/mit
  3. */
  4. (function () {
  5. 'use strict';
  6. var $$2;
  7. var dataTable$2;
  8. var moment = window.moment;
  9. var luxon = window.luxon;
  10. /**
  11. * Sets the value of jQuery for use in the file
  12. *
  13. * @param jq the instance of jQuery to be set
  14. */
  15. function setJQuery$2(jq) {
  16. $$2 = jq;
  17. dataTable$2 = jq.fn.dataTable;
  18. }
  19. /**
  20. * The Criteria class is used within SearchBuilder to represent a search criteria
  21. */
  22. var Criteria = /** @class */ (function () {
  23. function Criteria(table, opts, topGroup, index, depth) {
  24. var _this = this;
  25. if (index === void 0) { index = 0; }
  26. if (depth === void 0) { depth = 1; }
  27. // Check that the required version of DataTables is included
  28. if (!dataTable$2 || !dataTable$2.versionCheck || !dataTable$2.versionCheck('1.10.0')) {
  29. throw new Error('SearchPane requires DataTables 1.10 or newer');
  30. }
  31. this.classes = $$2.extend(true, {}, Criteria.classes);
  32. // Get options from user and any extra conditions/column types defined by plug-ins
  33. this.c = $$2.extend(true, {}, Criteria.defaults, $$2.fn.dataTable.ext.searchBuilder, opts);
  34. var i18n = this.c.i18n;
  35. this.s = {
  36. condition: undefined,
  37. conditions: {},
  38. data: undefined,
  39. dataIdx: -1,
  40. dataPoints: [],
  41. dateFormat: false,
  42. depth: depth,
  43. dt: table,
  44. filled: false,
  45. index: index,
  46. topGroup: topGroup,
  47. type: '',
  48. value: []
  49. };
  50. this.dom = {
  51. buttons: $$2('<div/>')
  52. .addClass(this.classes.buttonContainer),
  53. condition: $$2('<select disabled/>')
  54. .addClass(this.classes.condition)
  55. .addClass(this.classes.dropDown)
  56. .addClass(this.classes.italic)
  57. .attr('autocomplete', 'hacking'),
  58. conditionTitle: $$2('<option value="" disabled selected hidden/>')
  59. .text(this.s.dt.i18n('searchBuilder.condition', i18n.condition)),
  60. container: $$2('<div/>')
  61. .addClass(this.classes.container),
  62. data: $$2('<select/>')
  63. .addClass(this.classes.data)
  64. .addClass(this.classes.dropDown)
  65. .addClass(this.classes.italic),
  66. dataTitle: $$2('<option value="" disabled selected hidden/>')
  67. .text(this.s.dt.i18n('searchBuilder.data', i18n.data)),
  68. defaultValue: $$2('<select disabled/>')
  69. .addClass(this.classes.value)
  70. .addClass(this.classes.dropDown)
  71. .addClass(this.classes.select),
  72. "delete": $$2('<button>&times</button>')
  73. .addClass(this.classes["delete"])
  74. .addClass(this.classes.button)
  75. .attr('title', this.s.dt.i18n('searchBuilder.deleteTitle', i18n.deleteTitle))
  76. .attr('type', 'button'),
  77. // eslint-disable-next-line no-useless-escape
  78. left: $$2('<button>\<</button>')
  79. .addClass(this.classes.left)
  80. .addClass(this.classes.button)
  81. .attr('title', this.s.dt.i18n('searchBuilder.leftTitle', i18n.leftTitle))
  82. .attr('type', 'button'),
  83. // eslint-disable-next-line no-useless-escape
  84. right: $$2('<button>\></button>')
  85. .addClass(this.classes.right)
  86. .addClass(this.classes.button)
  87. .attr('title', this.s.dt.i18n('searchBuilder.rightTitle', i18n.rightTitle))
  88. .attr('type', 'button'),
  89. value: [
  90. $$2('<select disabled/>')
  91. .addClass(this.classes.value)
  92. .addClass(this.classes.dropDown)
  93. .addClass(this.classes.italic)
  94. .addClass(this.classes.select)
  95. ],
  96. valueTitle: $$2('<option value="--valueTitle--" selected/>')
  97. .text(this.s.dt.i18n('searchBuilder.value', i18n.value))
  98. };
  99. // If the greyscale option is selected then add the class to add the grey colour to SearchBuilder
  100. if (this.c.greyscale) {
  101. $$2(this.dom.data).addClass(this.classes.greyscale);
  102. $$2(this.dom.condition).addClass(this.classes.greyscale);
  103. $$2(this.dom.defaultValue).addClass(this.classes.greyscale);
  104. for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
  105. var val = _a[_i];
  106. $$2(val).addClass(this.classes.greyscale);
  107. }
  108. }
  109. // For responsive design, adjust the criterias properties on the following events
  110. this.s.dt.on('draw.dtsp', function () {
  111. _this._adjustCriteria();
  112. });
  113. this.s.dt.on('buttons-action', function () {
  114. _this._adjustCriteria();
  115. });
  116. $$2(window).on('resize.dtsp', dataTable$2.util.throttle(function () {
  117. _this._adjustCriteria();
  118. }));
  119. this._buildCriteria();
  120. return this;
  121. }
  122. /**
  123. * Adds the left button to the criteria
  124. */
  125. Criteria.prototype.updateArrows = function (hasSiblings, redraw) {
  126. if (hasSiblings === void 0) { hasSiblings = false; }
  127. if (redraw === void 0) { redraw = true; }
  128. // Empty the container and append all of the elements in the correct order
  129. $$2(this.dom.container)
  130. .empty()
  131. .append(this.dom.data)
  132. .append(this.dom.condition)
  133. .append(this.dom.value[0]);
  134. this.setListeners();
  135. // Trigger the inserted events for the value elements as they are inserted
  136. $$2(this.dom.value[0]).trigger('dtsb-inserted');
  137. for (var i = 1; i < this.dom.value.length; i++) {
  138. $$2(this.dom.container).append(this.dom.value[i]);
  139. $$2(this.dom.value[i]).trigger('dtsb-inserted');
  140. }
  141. // If this is a top level criteria then don't let it move left
  142. if (this.s.depth > 1) {
  143. $$2(this.dom.buttons).append(this.dom.left);
  144. }
  145. // If the depthLimit of the query has been hit then don't add the right button
  146. if ((this.c.depthLimit === false || this.s.depth < this.c.depthLimit) && hasSiblings) {
  147. $$2(this.dom.buttons).append(this.dom.right);
  148. }
  149. else {
  150. $$2(this.dom.right).remove();
  151. }
  152. $$2(this.dom.buttons).append(this.dom["delete"]);
  153. $$2(this.dom.container).append(this.dom.buttons);
  154. if (redraw) {
  155. // A different combination of arrows and selectors may lead to a need for responsive to be triggered
  156. this._adjustCriteria();
  157. }
  158. };
  159. /**
  160. * Destroys the criteria, removing listeners and container from the dom
  161. */
  162. Criteria.prototype.destroy = function () {
  163. // Turn off listeners
  164. $$2(this.dom.data).off('.dtsb');
  165. $$2(this.dom.condition).off('.dtsb');
  166. $$2(this.dom["delete"]).off('.dtsb');
  167. for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
  168. var val = _a[_i];
  169. $$2(val).off('.dtsb');
  170. }
  171. // Remove container from the dom
  172. $$2(this.dom.container).remove();
  173. };
  174. /**
  175. * Passes in the data for the row and compares it against this single criteria
  176. *
  177. * @param rowData The data for the row to be compared
  178. * @returns boolean Whether the criteria has passed
  179. */
  180. Criteria.prototype.search = function (rowData, rowIdx) {
  181. var condition = this.s.conditions[this.s.condition];
  182. if (this.s.condition !== undefined && condition !== undefined) {
  183. var filter = rowData[this.s.dataIdx];
  184. // This check is in place for if a custom decimal character is in place
  185. if (this.s.type.indexOf('num') !== -1 &&
  186. (this.s.dt.settings()[0].oLanguage.sDecimal !== '' ||
  187. this.s.dt.settings()[0].oLanguage.sThousands !== '')) {
  188. var splitRD = [rowData[this.s.dataIdx]];
  189. if (this.s.dt.settings()[0].oLanguage.sDecimal !== '') {
  190. splitRD = rowData[this.s.dataIdx].split(this.s.dt.settings()[0].oLanguage.sDecimal);
  191. }
  192. if (this.s.dt.settings()[0].oLanguage.sThousands !== '') {
  193. for (var i = 0; i < splitRD.length; i++) {
  194. splitRD[i] = splitRD[i].replace(this.s.dt.settings()[0].oLanguage.sThousands, ',');
  195. }
  196. }
  197. filter = splitRD.join('.');
  198. }
  199. // If orthogonal data is in place we need to get it's values for searching
  200. if (this.c.orthogonal.search !== 'filter') {
  201. var settings = this.s.dt.settings()[0];
  202. filter = settings.oApi._fnGetCellData(settings, rowIdx, this.s.dataIdx, typeof this.c.orthogonal === 'string' ?
  203. this.c.orthogonal :
  204. this.c.orthogonal.search);
  205. }
  206. if (this.s.type === 'array') {
  207. // Make sure we are working with an array
  208. if (!Array.isArray(filter)) {
  209. filter = [filter];
  210. }
  211. filter.sort();
  212. for (var _i = 0, filter_1 = filter; _i < filter_1.length; _i++) {
  213. var filt = filter_1[_i];
  214. if (filt) {
  215. filt = filt.replace(/[\r\n\u2028]/g, ' ');
  216. }
  217. }
  218. }
  219. else if (filter !== null) {
  220. filter = filter.replace(/[\r\n\u2028]/g, ' ');
  221. }
  222. if (this.s.type.indexOf('html') !== -1) {
  223. filter = filter.replace(/(<([^>]+)>)/ig, '');
  224. }
  225. // Not ideal, but jqueries .val() returns an empty string even
  226. // when the value set is null, so we shall assume the two are equal
  227. if (filter === null) {
  228. filter = '';
  229. }
  230. return condition.search(filter, this.s.value, this);
  231. }
  232. };
  233. /**
  234. * Gets the details required to rebuild the criteria
  235. */
  236. Criteria.prototype.getDetails = function () {
  237. var value = this.s.value;
  238. // This check is in place for if a custom decimal character is in place
  239. if (this.s.type.indexOf('num') !== -1 &&
  240. (this.s.dt.settings()[0].oLanguage.sDecimal !== '' || this.s.dt.settings()[0].oLanguage.sThousands !== '')) {
  241. for (var i = 0; i < this.s.value.length; i++) {
  242. var splitRD = [this.s.value[i].toString()];
  243. if (this.s.dt.settings()[0].oLanguage.sDecimal !== '') {
  244. splitRD = this.s.value[i].split(this.s.dt.settings()[0].oLanguage.sDecimal);
  245. }
  246. if (this.s.dt.settings()[0].oLanguage.sThousands !== '') {
  247. for (var j = 0; j < splitRD.length; j++) {
  248. splitRD[j] = splitRD[j].replace(this.s.dt.settings()[0].oLanguage.sThousands, ',');
  249. }
  250. }
  251. this.s.value[i] = splitRD.join('.');
  252. }
  253. }
  254. return {
  255. condition: this.s.condition,
  256. data: this.s.data,
  257. value: value
  258. };
  259. };
  260. /**
  261. * Getter for the node for the container of the criteria
  262. *
  263. * @returns JQuery<HTMLElement> the node for the container
  264. */
  265. Criteria.prototype.getNode = function () {
  266. return this.dom.container;
  267. };
  268. /**
  269. * Populates the criteria data, condition and value(s) as far as has been selected
  270. */
  271. Criteria.prototype.populate = function () {
  272. this._populateData();
  273. // If the column index has been found attempt to select a condition
  274. if (this.s.dataIdx !== -1) {
  275. this._populateCondition();
  276. // If the condittion has been found attempt to select the values
  277. if (this.s.condition !== undefined) {
  278. this._populateValue();
  279. }
  280. }
  281. };
  282. /**
  283. * Rebuilds the criteria based upon the details passed in
  284. *
  285. * @param loadedCriteria the details required to rebuild the criteria
  286. */
  287. Criteria.prototype.rebuild = function (loadedCriteria) {
  288. // Check to see if the previously selected data exists, if so select it
  289. var foundData = false;
  290. var dataIdx;
  291. this._populateData();
  292. // If a data selection has previously been made attempt to find and select it
  293. if (loadedCriteria.data !== undefined) {
  294. var italic_1 = this.classes.italic;
  295. var data_1 = this.dom.data;
  296. $$2(this.dom.data).children('option').each(function () {
  297. if ($$2(this).text() === loadedCriteria.data) {
  298. $$2(this).attr('selected', true);
  299. $$2(data_1).removeClass(italic_1);
  300. foundData = true;
  301. dataIdx = $$2(this).val();
  302. }
  303. });
  304. }
  305. // If the data has been found and selected then the condition can be populated and searched
  306. if (foundData) {
  307. this.s.data = loadedCriteria.data;
  308. this.s.dataIdx = dataIdx;
  309. this.c.orthogonal = this._getOptions().orthogonal;
  310. $$2(this.dom.dataTitle).remove();
  311. this._populateCondition();
  312. $$2(this.dom.conditionTitle).remove();
  313. var condition_1;
  314. // Check to see if the previously selected condition exists, if so select it
  315. $$2(this.dom.condition).children('option').each(function () {
  316. if ((loadedCriteria.condition !== undefined &&
  317. $$2(this).val() === loadedCriteria.condition &&
  318. typeof loadedCriteria.condition === 'string')) {
  319. $$2(this).attr('selected', true);
  320. condition_1 = $$2(this).val();
  321. }
  322. });
  323. this.s.condition = condition_1;
  324. // If the condition has been found and selected then the value can be populated and searched
  325. if (this.s.condition !== undefined) {
  326. $$2(this.dom.conditionTitle).remove();
  327. $$2(this.dom.condition).removeClass(this.classes.italic);
  328. this._populateValue(loadedCriteria);
  329. }
  330. else {
  331. $$2(this.dom.conditionTitle).prependTo(this.dom.condition).attr('selected', true);
  332. }
  333. }
  334. };
  335. /**
  336. * Sets the listeners for the criteria
  337. */
  338. Criteria.prototype.setListeners = function () {
  339. var _this = this;
  340. $$2(this.dom.data)
  341. .unbind('input change')
  342. .on('input change', function () {
  343. $$2(_this.dom.dataTitle).attr('selected', false);
  344. $$2(_this.dom.data).removeClass(_this.classes.italic);
  345. _this.s.dataIdx = $$2(_this.dom.data).children('option:selected').val();
  346. _this.s.data = $$2(_this.dom.data).children('option:selected').text();
  347. _this.c.orthogonal = _this._getOptions().orthogonal;
  348. // When the data is changed, the values in condition and value may also change so need to renew them
  349. _this._clearCondition();
  350. _this._clearValue();
  351. _this._populateCondition();
  352. // If this criteria was previously active in the search then
  353. // remove it from the search and trigger a new search
  354. if (_this.s.filled) {
  355. _this.s.filled = false;
  356. _this.s.dt.draw();
  357. _this.setListeners();
  358. }
  359. _this.s.dt.state.save();
  360. });
  361. $$2(this.dom.condition)
  362. .unbind('input change')
  363. .on('input change', function () {
  364. $$2(_this.dom.conditionTitle).attr('selected', false);
  365. $$2(_this.dom.condition).removeClass(_this.classes.italic);
  366. var condDisp = $$2(_this.dom.condition).children('option:selected').val();
  367. // Find the condition that has been selected and store it internally
  368. for (var _i = 0, _a = Object.keys(_this.s.conditions); _i < _a.length; _i++) {
  369. var cond = _a[_i];
  370. if (cond === condDisp) {
  371. _this.s.condition = condDisp;
  372. break;
  373. }
  374. }
  375. // When the condition is changed, the value selector may switch between
  376. // a select element and an input element
  377. _this._clearValue();
  378. _this._populateValue();
  379. for (var _b = 0, _c = _this.dom.value; _b < _c.length; _b++) {
  380. var val = _c[_b];
  381. // If this criteria was previously active in the search then remove
  382. // it from the search and trigger a new search
  383. if (_this.s.filled && $$2(_this.dom.container).has(val).length !== 0) {
  384. _this.s.filled = false;
  385. _this.s.dt.draw();
  386. _this.setListeners();
  387. }
  388. }
  389. _this.s.dt.draw();
  390. });
  391. };
  392. /**
  393. * Adjusts the criteria to make SearchBuilder responsive
  394. */
  395. Criteria.prototype._adjustCriteria = function () {
  396. // If this criteria is not present then don't bother adjusting it
  397. if ($$2(document).has(this.dom.container).length === 0) {
  398. return;
  399. }
  400. var valRight;
  401. var valWidth;
  402. var outmostval = this.dom.value[this.dom.value.length - 1];
  403. // Calculate the width and right value of the outmost value element
  404. if ($$2(this.dom.container).has(outmostval).length !== 0) {
  405. valWidth = $$2(outmostval).outerWidth(true);
  406. valRight = $$2(outmostval).offset().left + valWidth;
  407. }
  408. else {
  409. return;
  410. }
  411. var leftOffset = $$2(this.dom.left).offset();
  412. var rightOffset = $$2(this.dom.right).offset();
  413. var clearOffset = $$2(this.dom["delete"]).offset();
  414. var hasLeft = $$2(this.dom.container).has(this.dom.left).length !== 0;
  415. var hasRight = $$2(this.dom.container).has(this.dom.right).length !== 0;
  416. var buttonsLeft = hasLeft ?
  417. leftOffset.left :
  418. hasRight ?
  419. rightOffset.left :
  420. clearOffset.left;
  421. // Perform the responsive calculations and redraw where necessary
  422. if ((buttonsLeft - valRight < 15 ||
  423. (hasLeft && leftOffset.top !== clearOffset.top) ||
  424. (hasRight && rightOffset.top !== clearOffset.top)) &&
  425. !$$2(this.dom.container).parent().hasClass(this.classes.vertical)) {
  426. $$2(this.dom.container).parent().addClass(this.classes.vertical);
  427. $$2(this.s.topGroup).trigger('dtsb-redrawContents');
  428. }
  429. else if (buttonsLeft -
  430. ($$2(this.dom.data).offset().left +
  431. $$2(this.dom.data).outerWidth(true) +
  432. $$2(this.dom.condition).outerWidth(true) +
  433. valWidth) > 15
  434. && $$2(this.dom.container).parent().hasClass(this.classes.vertical)) {
  435. $$2(this.dom.container).parent().removeClass(this.classes.vertical);
  436. $$2(this.s.topGroup).trigger('dtsb-redrawContents');
  437. }
  438. };
  439. /**
  440. * Builds the elements of the dom together
  441. */
  442. Criteria.prototype._buildCriteria = function () {
  443. // Append Titles for select elements
  444. $$2(this.dom.data).append(this.dom.dataTitle);
  445. $$2(this.dom.condition).append(this.dom.conditionTitle);
  446. // Add elements to container
  447. $$2(this.dom.container)
  448. .append(this.dom.data)
  449. .append(this.dom.condition);
  450. for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
  451. var val = _a[_i];
  452. $$2(val).append(this.dom.valueTitle);
  453. $$2(this.dom.container).append(val);
  454. }
  455. // Add buttons to container
  456. $$2(this.dom.container)
  457. .append(this.dom["delete"])
  458. .append(this.dom.right);
  459. this.setListeners();
  460. };
  461. /**
  462. * Clears the condition select element
  463. */
  464. Criteria.prototype._clearCondition = function () {
  465. $$2(this.dom.condition).empty();
  466. $$2(this.dom.conditionTitle).attr('selected', true).attr('disabled', true);
  467. $$2(this.dom.condition).prepend(this.dom.conditionTitle).prop('selectedIndex', 0);
  468. this.s.conditions = {};
  469. this.s.condition = undefined;
  470. };
  471. /**
  472. * Clears the value elements
  473. */
  474. Criteria.prototype._clearValue = function () {
  475. if (this.s.condition !== undefined) {
  476. var _loop_1 = function (val) {
  477. // Timeout is annoying but because of IOS
  478. setTimeout(function () {
  479. $$2(val).remove();
  480. }, 50);
  481. };
  482. // Remove all of the value elements
  483. for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
  484. var val = _a[_i];
  485. _loop_1(val);
  486. }
  487. // Call the init function to get the value elements for this condition
  488. this.dom.value = [].concat(this.s.conditions[this.s.condition].init(this, Criteria.updateListener));
  489. $$2(this.dom.value[0]).insertAfter(this.dom.condition).trigger('dtsb-inserted');
  490. // Insert all of the value elements
  491. for (var i = 1; i < this.dom.value.length; i++) {
  492. $$2(this.dom.value[i]).insertAfter(this.dom.value[i - 1]).trigger('dtsb-inserted');
  493. }
  494. }
  495. else {
  496. var _loop_2 = function (val) {
  497. // Timeout is annoying but because of IOS
  498. setTimeout(function () {
  499. $$2(val).remove();
  500. }, 50);
  501. };
  502. // Remove all of the value elements
  503. for (var _b = 0, _c = this.dom.value; _b < _c.length; _b++) {
  504. var val = _c[_b];
  505. _loop_2(val);
  506. }
  507. // Append the default valueTitle to the default select element
  508. $$2(this.dom.valueTitle)
  509. .attr('selected', true);
  510. $$2(this.dom.defaultValue)
  511. .append(this.dom.valueTitle)
  512. .insertAfter(this.dom.condition);
  513. }
  514. this.s.value = [];
  515. this.dom.value = [
  516. $$2('<select disabled/>')
  517. .addClass(this.classes.value)
  518. .addClass(this.classes.dropDown)
  519. .addClass(this.classes.italic)
  520. .addClass(this.classes.select)
  521. .append($$2(this.dom.valueTitle).clone())
  522. ];
  523. };
  524. /**
  525. * Gets the options for the column
  526. *
  527. * @returns {object} The options for the column
  528. */
  529. Criteria.prototype._getOptions = function () {
  530. var table = this.s.dt;
  531. return $$2.extend(true, {}, Criteria.defaults, table.settings()[0].aoColumns[this.s.dataIdx].searchBuilder);
  532. };
  533. /**
  534. * Populates the condition dropdown
  535. */
  536. Criteria.prototype._populateCondition = function () {
  537. var conditionOpts = [];
  538. var conditionsLength = Object.keys(this.s.conditions).length;
  539. // If there are no conditions stored then we need to get them from the appropriate type
  540. if (conditionsLength === 0) {
  541. var column = $$2(this.dom.data).children('option:selected').val();
  542. this.s.type = this.s.dt.columns().type().toArray()[column];
  543. // If the column type is unknown, call a draw to try reading it again
  544. if (this.s.type === null) {
  545. this.s.dt.draw();
  546. this.setListeners();
  547. this.s.type = this.s.dt.columns().type().toArray()[column];
  548. }
  549. // Enable the condition element
  550. $$2(this.dom.condition)
  551. .attr('disabled', false)
  552. .empty()
  553. .append(this.dom.conditionTitle)
  554. .addClass(this.classes.italic);
  555. $$2(this.dom.conditionTitle)
  556. .attr('selected', true);
  557. var decimal = this.s.dt.settings()[0].oLanguage.sDecimal;
  558. // This check is in place for if a custom decimal character is in place
  559. if (decimal !== '' && this.s.type.indexOf(decimal) === this.s.type.length - decimal.length) {
  560. if (this.s.type.indexOf('num-fmt') !== -1) {
  561. this.s.type = this.s.type.replace(decimal, '');
  562. }
  563. else if (this.s.type.indexOf('num') !== -1) {
  564. this.s.type = this.s.type.replace(decimal, '');
  565. }
  566. }
  567. // Select which conditions are going to be used based on the column type
  568. var conditionObj = this.c.conditions[this.s.type] !== undefined ?
  569. this.c.conditions[this.s.type] :
  570. this.s.type.indexOf('moment') !== -1 ?
  571. this.c.conditions.moment :
  572. this.s.type.indexOf('luxon') !== -1 ?
  573. this.c.conditions.luxon :
  574. this.c.conditions.string;
  575. // If it is a moment format then extract the date format
  576. if (this.s.type.indexOf('moment') !== -1) {
  577. this.s.dateFormat = this.s.type.replace(/moment-/g, '');
  578. }
  579. else if (this.s.type.indexOf('luxon') !== -1) {
  580. this.s.dateFormat = this.s.type.replace(/luxon-/g, '');
  581. }
  582. // Add all of the conditions to the select element
  583. for (var _i = 0, _a = Object.keys(conditionObj); _i < _a.length; _i++) {
  584. var condition = _a[_i];
  585. if (conditionObj[condition] !== null) {
  586. this.s.conditions[condition] = conditionObj[condition];
  587. var condName = conditionObj[condition].conditionName;
  588. if (typeof condName === 'function') {
  589. condName = condName(this.s.dt, this.c.i18n);
  590. }
  591. conditionOpts.push($$2('<option>', {
  592. text: condName,
  593. value: condition
  594. })
  595. .addClass(this.classes.option)
  596. .addClass(this.classes.notItalic));
  597. }
  598. }
  599. }
  600. // Otherwise we can just load them in
  601. else if (conditionsLength > 0) {
  602. $$2(this.dom.condition).empty().attr('disabled', false).addClass(this.classes.italic);
  603. for (var _b = 0, _c = Object.keys(this.s.conditions); _b < _c.length; _b++) {
  604. var condition = _c[_b];
  605. var condName = this.s.conditions[condition].conditionName;
  606. if (typeof condName === 'function') {
  607. condName = condName(this.s.dt, this.c.i18n);
  608. }
  609. var newOpt = $$2('<option>', {
  610. text: condName,
  611. value: condition
  612. })
  613. .addClass(this.classes.option)
  614. .addClass(this.classes.notItalic);
  615. if (this.s.condition !== undefined && this.s.condition === condName) {
  616. $$2(newOpt).attr('selected', true);
  617. $$2(this.dom.condition).removeClass(this.classes.italic);
  618. }
  619. conditionOpts.push(newOpt);
  620. }
  621. }
  622. else {
  623. $$2(this.dom.condition)
  624. .attr('disabled', true)
  625. .addClass(this.classes.italic);
  626. return;
  627. }
  628. for (var _d = 0, conditionOpts_1 = conditionOpts; _d < conditionOpts_1.length; _d++) {
  629. var opt = conditionOpts_1[_d];
  630. $$2(this.dom.condition).append(opt);
  631. }
  632. $$2(this.dom.condition).prop('selectedIndex', 0);
  633. };
  634. /**
  635. * Populates the data select element
  636. */
  637. Criteria.prototype._populateData = function () {
  638. var _this = this;
  639. $$2(this.dom.data).empty().append(this.dom.dataTitle);
  640. // If there are no datas stored then we need to get them from the table
  641. if (this.s.dataPoints.length === 0) {
  642. this.s.dt.columns().every(function (index) {
  643. // Need to check that the column can be filtered on before adding it
  644. if (_this.c.columns === true ||
  645. (_this.s.dt.columns(_this.c.columns).indexes().toArray().indexOf(index) !== -1)) {
  646. var found = false;
  647. for (var _i = 0, _a = _this.s.dataPoints; _i < _a.length; _i++) {
  648. var val = _a[_i];
  649. if (val.index === index) {
  650. found = true;
  651. break;
  652. }
  653. }
  654. if (!found) {
  655. var col = _this.s.dt.settings()[0].aoColumns[index];
  656. var opt = {
  657. index: index,
  658. text: (col.searchBuilderTitle === undefined ?
  659. col.sTitle :
  660. col.searchBuilderTitle).replace(/(<([^>]+)>)/ig, '')
  661. };
  662. _this.s.dataPoints.push(opt);
  663. $$2(_this.dom.data).append($$2('<option>', {
  664. text: opt.text,
  665. value: opt.index
  666. })
  667. .addClass(_this.classes.option)
  668. .addClass(_this.classes.notItalic));
  669. }
  670. }
  671. });
  672. }
  673. // Otherwise we can just load them in
  674. else {
  675. var _loop_3 = function (data) {
  676. this_1.s.dt.columns().every(function (index) {
  677. var col = _this.s.dt.settings()[0].aoColumns[index];
  678. if ((col.searchBuilderTitle === undefined ?
  679. col.sTitle :
  680. col.searchBuilderTitle).replace(/(<([^>]+)>)/ig, '') === data.text) {
  681. data.index = index;
  682. }
  683. });
  684. var newOpt = $$2('<option>', {
  685. text: data.text.replace(/(<([^>]+)>)/ig, ''),
  686. value: data.index
  687. })
  688. .addClass(this_1.classes.option)
  689. .addClass(this_1.classes.notItalic);
  690. if (this_1.s.data === data.text) {
  691. this_1.s.dataIdx = data.index;
  692. $$2(newOpt).attr('selected', true);
  693. $$2(this_1.dom.data).removeClass(this_1.classes.italic);
  694. }
  695. $$2(this_1.dom.data).append(newOpt);
  696. };
  697. var this_1 = this;
  698. for (var _i = 0, _a = this.s.dataPoints; _i < _a.length; _i++) {
  699. var data = _a[_i];
  700. _loop_3(data);
  701. }
  702. }
  703. };
  704. /**
  705. * Populates the Value select element
  706. *
  707. * @param loadedCriteria optional, used to reload criteria from predefined filters
  708. */
  709. Criteria.prototype._populateValue = function (loadedCriteria) {
  710. var _this = this;
  711. var prevFilled = this.s.filled;
  712. this.s.filled = false;
  713. // Remove any previous value elements
  714. // Timeout is annoying but because of IOS
  715. setTimeout(function () {
  716. $$2(_this.dom.defaultValue).remove();
  717. }, 50);
  718. var _loop_4 = function (val) {
  719. // Timeout is annoying but because of IOS
  720. setTimeout(function () {
  721. $$2(val).remove();
  722. }, 50);
  723. };
  724. for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
  725. var val = _a[_i];
  726. _loop_4(val);
  727. }
  728. var children = $$2(this.dom.container).children();
  729. if (children.length > 3) {
  730. for (var i = 2; i < children.length - 1; i++) {
  731. $$2(children[i]).remove();
  732. }
  733. }
  734. // Find the column with the title matching the data for the criteria and take note of the index
  735. if (loadedCriteria !== undefined) {
  736. this.s.dt.columns().every(function (index) {
  737. if (_this.s.dt.settings()[0].aoColumns[index].sTitle === loadedCriteria.data) {
  738. _this.s.dataIdx = index;
  739. }
  740. });
  741. }
  742. // Initialise the value elements based on the condition
  743. this.dom.value = [].concat(this.s.conditions[this.s.condition].init(this, Criteria.updateListener, loadedCriteria !== undefined ? loadedCriteria.value : undefined));
  744. if (loadedCriteria !== undefined && loadedCriteria.value !== undefined) {
  745. this.s.value = loadedCriteria.value;
  746. }
  747. // Insert value elements and trigger the inserted event
  748. $$2(this.dom.value[0])
  749. .insertAfter(this.dom.condition)
  750. .trigger('dtsb-inserted');
  751. for (var i = 1; i < this.dom.value.length; i++) {
  752. $$2(this.dom.value[i])
  753. .insertAfter(this.dom.value[i - 1])
  754. .trigger('dtsb-inserted');
  755. }
  756. // Check if the criteria can be used in a search
  757. this.s.filled = this.s.conditions[this.s.condition].isInputValid(this.dom.value, this);
  758. this.setListeners();
  759. // If it can and this is different to before then trigger a draw
  760. if (prevFilled !== this.s.filled) {
  761. this.s.dt.draw();
  762. this.setListeners();
  763. }
  764. };
  765. Criteria.version = '1.1.0';
  766. Criteria.classes = {
  767. button: 'dtsb-button',
  768. buttonContainer: 'dtsb-buttonContainer',
  769. condition: 'dtsb-condition',
  770. container: 'dtsb-criteria',
  771. data: 'dtsb-data',
  772. "delete": 'dtsb-delete',
  773. dropDown: 'dtsb-dropDown',
  774. greyscale: 'dtsb-greyscale',
  775. input: 'dtsb-input',
  776. italic: 'dtsb-italic',
  777. joiner: 'dtsp-joiner',
  778. left: 'dtsb-left',
  779. notItalic: 'dtsb-notItalic',
  780. option: 'dtsb-option',
  781. right: 'dtsb-right',
  782. select: 'dtsb-select',
  783. value: 'dtsb-value',
  784. vertical: 'dtsb-vertical'
  785. };
  786. /**
  787. * Default initialisation function for select conditions
  788. */
  789. Criteria.initSelect = function (that, fn, preDefined, array) {
  790. if (preDefined === void 0) { preDefined = null; }
  791. if (array === void 0) { array = false; }
  792. var column = $$2(that.dom.data).children('option:selected').val();
  793. var indexArray = that.s.dt.rows().indexes().toArray();
  794. var settings = that.s.dt.settings()[0];
  795. // Declare select element to be used with all of the default classes and listeners.
  796. var el = $$2('<select/>')
  797. .addClass(Criteria.classes.value)
  798. .addClass(Criteria.classes.dropDown)
  799. .addClass(Criteria.classes.italic)
  800. .addClass(Criteria.classes.select)
  801. .append(that.dom.valueTitle)
  802. .on('input change', function () {
  803. $$2(this).removeClass(Criteria.classes.italic);
  804. fn(that, this);
  805. });
  806. if (that.c.greyscale) {
  807. $$2(el).addClass(Criteria.classes.greyscale);
  808. }
  809. var added = [];
  810. var options = [];
  811. // Add all of the options from the table to the select element.
  812. // Only add one option for each possible value
  813. for (var _i = 0, indexArray_1 = indexArray; _i < indexArray_1.length; _i++) {
  814. var index = indexArray_1[_i];
  815. var filter = settings.oApi._fnGetCellData(settings, index, column, typeof that.c.orthogonal === 'string' ?
  816. that.c.orthogonal :
  817. that.c.orthogonal.search);
  818. var value = {
  819. filter: typeof filter === 'string' ?
  820. filter.replace(/[\r\n\u2028]/g, ' ') : // Need to replace certain characters to match search values
  821. filter,
  822. index: index,
  823. text: settings.oApi._fnGetCellData(settings, index, column, typeof that.c.orthogonal === 'string' ?
  824. that.c.orthogonal :
  825. that.c.orthogonal.display)
  826. };
  827. // If we are dealing with an array type, either make sure we are working with arrays, or sort them
  828. if (that.s.type === 'array') {
  829. value.filter = !Array.isArray(value.filter) ?
  830. [value.filter] :
  831. value.filter = value.filter.sort();
  832. value.text = !Array.isArray(value.text) ?
  833. [value.text] :
  834. value.text = value.text.sort();
  835. }
  836. // Function to add an option to the select element
  837. var addOption = function (filt, text) {
  838. // Add text and value, stripping out any html if that is the column type
  839. var opt = $$2('<option>', {
  840. type: Array.isArray(filt) ? 'Array' : 'String',
  841. value: that.s.type.indexOf('html') !== -1 && filt !== null && typeof filt === 'string' ?
  842. filt.replace(/(<([^>]+)>)/ig, '') :
  843. filt
  844. })
  845. .addClass(that.classes.option)
  846. .addClass(that.classes.notItalic)
  847. // Have to add the text this way so that special html characters are not escaped - &amp; etc.
  848. .html(typeof text === 'string' ?
  849. text.replace(/(<([^>]+)>)/ig, '') :
  850. text);
  851. var val = $$2(opt).val();
  852. // Check that this value has not already been added
  853. if (added.indexOf(val) === -1) {
  854. added.push(val);
  855. options.push(opt);
  856. if (preDefined !== null && Array.isArray(preDefined[0])) {
  857. preDefined[0] = preDefined[0].sort().join(',');
  858. }
  859. // If this value was previously selected as indicated by preDefined, then select it again
  860. if (preDefined !== null && opt.val() === preDefined[0]) {
  861. opt.attr('selected', true);
  862. $$2(el).removeClass(Criteria.classes.italic);
  863. }
  864. }
  865. };
  866. // If this is to add the individual values within the array we need to loop over the array
  867. if (array) {
  868. for (var i = 0; i < value.filter.length; i++) {
  869. addOption(value.filter[i], value.text[i]);
  870. }
  871. }
  872. // Otherwise the value that is in the cell is to be added
  873. else {
  874. addOption(value.filter, value.text);
  875. }
  876. }
  877. options.sort(function (a, b) {
  878. if (that.s.type === 'array' ||
  879. that.s.type === 'string' ||
  880. that.s.type === 'num' ||
  881. that.s.type === 'html' ||
  882. that.s.type === 'html-num') {
  883. if ($$2(a).val() < $$2(b).val()) {
  884. return -1;
  885. }
  886. else if ($$2(a).val() > $$2(b).val()) {
  887. return 1;
  888. }
  889. else {
  890. return 0;
  891. }
  892. }
  893. else if (that.s.type === 'num-fmt' || that.s.type === 'html-num-fmt') {
  894. if (+$$2(a).val().replace(/[^0-9.]/g, '') < +$$2(b).val().replace(/[^0-9.]/g, '')) {
  895. return -1;
  896. }
  897. else if (+$$2(a).val().replace(/[^0-9.]/g, '') > +$$2(b).val().replace(/[^0-9.]/g, '')) {
  898. return 1;
  899. }
  900. else {
  901. return 0;
  902. }
  903. }
  904. });
  905. for (var _a = 0, options_1 = options; _a < options_1.length; _a++) {
  906. var opt = options_1[_a];
  907. $$2(el).append(opt);
  908. }
  909. return el;
  910. };
  911. /**
  912. * Default initialisation function for select array conditions
  913. *
  914. * This exists because there needs to be different select functionality for contains/without and equals/not
  915. */
  916. Criteria.initSelectArray = function (that, fn, preDefined) {
  917. if (preDefined === void 0) { preDefined = null; }
  918. return Criteria.initSelect(that, fn, preDefined, true);
  919. };
  920. /**
  921. * Default initialisation function for input conditions
  922. */
  923. Criteria.initInput = function (that, fn, preDefined) {
  924. var _this = this;
  925. if (preDefined === void 0) { preDefined = null; }
  926. // Declare the input element
  927. var searchDelay = that.s.dt.settings()[0].searchDelay;
  928. var el = $$2('<input/>')
  929. .addClass(Criteria.classes.value)
  930. .addClass(Criteria.classes.input)
  931. .on('input keypress', !that.c.enterSearch || searchDelay !== null ?
  932. that.s.dt.settings()[0].oApi._fnThrottle(function () {
  933. return fn(that, this);
  934. }, searchDelay) :
  935. that.c.enterSearch ?
  936. function (e) {
  937. var code = e.keyCode || e.which;
  938. if (code === 13) {
  939. fn(that, _this);
  940. }
  941. } :
  942. function () {
  943. fn(that, _this);
  944. });
  945. if (that.c.greyscale) {
  946. $$2(el).addClass(Criteria.classes.greyscale);
  947. }
  948. // If there is a preDefined value then add it
  949. if (preDefined !== null) {
  950. $$2(el).val(preDefined[0]);
  951. }
  952. // This is add responsive functionality to the logic button without redrawing everything else
  953. that.s.dt.one('draw', function () {
  954. $$2(that.s.topGroup).trigger('dtsb-redrawLogic');
  955. });
  956. return el;
  957. };
  958. /**
  959. * Default initialisation function for conditions requiring 2 inputs
  960. */
  961. Criteria.init2Input = function (that, fn, preDefined) {
  962. var _this = this;
  963. if (preDefined === void 0) { preDefined = null; }
  964. // Declare all of the necessary jQuery elements
  965. var searchDelay = that.s.dt.settings()[0].searchDelay;
  966. var els = [
  967. $$2('<input/>')
  968. .addClass(Criteria.classes.value)
  969. .addClass(Criteria.classes.input)
  970. .on('input keypress', searchDelay !== null ?
  971. that.s.dt.settings()[0].oApi._fnThrottle(function () {
  972. return fn(that, this);
  973. }, searchDelay) :
  974. that.c.enterSearch ?
  975. function (e) {
  976. var code = e.keyCode || e.which;
  977. if (code === 13) {
  978. fn(that, _this);
  979. }
  980. } :
  981. function () {
  982. fn(that, _this);
  983. }),
  984. $$2('<span>')
  985. .addClass(that.classes.joiner)
  986. .text(that.s.dt.i18n('searchBuilder.valueJoiner', that.c.i18n.valueJoiner)),
  987. $$2('<input/>')
  988. .addClass(Criteria.classes.value)
  989. .addClass(Criteria.classes.input)
  990. .on('input keypress', searchDelay !== null ?
  991. that.s.dt.settings()[0].oApi._fnThrottle(function () {
  992. return fn(that, this);
  993. }, searchDelay) :
  994. that.c.enterSearch ?
  995. function (e) {
  996. var code = e.keyCode || e.which;
  997. if (code === 13) {
  998. fn(that, _this);
  999. }
  1000. } :
  1001. function () {
  1002. fn(that, _this);
  1003. })
  1004. ];
  1005. if (that.c.greyscale) {
  1006. $$2(els[0]).addClass(Criteria.classes.greyscale);
  1007. $$2(els[2]).addClass(Criteria.classes.greyscale);
  1008. }
  1009. // If there is a preDefined value then add it
  1010. if (preDefined !== null) {
  1011. $$2(els[0]).val(preDefined[0]);
  1012. $$2(els[2]).val(preDefined[1]);
  1013. }
  1014. // This is add responsive functionality to the logic button without redrawing everything else
  1015. that.s.dt.one('draw', function () {
  1016. $$2(that.s.topGroup).trigger('dtsb-redrawLogic');
  1017. });
  1018. return els;
  1019. };
  1020. /**
  1021. * Default initialisation function for date conditions
  1022. */
  1023. Criteria.initDate = function (that, fn, preDefined) {
  1024. var _this = this;
  1025. if (preDefined === void 0) { preDefined = null; }
  1026. var searchDelay = that.s.dt.settings()[0].searchDelay;
  1027. // Declare date element using DataTables dateTime plugin
  1028. var el = $$2('<input/>')
  1029. .addClass(Criteria.classes.value)
  1030. .addClass(Criteria.classes.input)
  1031. .dtDateTime({
  1032. attachTo: 'input',
  1033. format: that.s.dateFormat ? that.s.dateFormat : undefined
  1034. })
  1035. .on('change', searchDelay !== null ?
  1036. that.s.dt.settings()[0].oApi._fnThrottle(function () {
  1037. return fn(that, this);
  1038. }, searchDelay) :
  1039. function () {
  1040. fn(that, _this);
  1041. })
  1042. .on('input keypress', !that.c.enterSearch && searchDelay !== null ?
  1043. that.s.dt.settings()[0].oApi._fnThrottle(function () {
  1044. return fn(that, this);
  1045. }, searchDelay) :
  1046. that.c.enterSearch ?
  1047. function (e) {
  1048. var code = e.keyCode || e.which;
  1049. if (code === 13) {
  1050. fn(that, _this);
  1051. }
  1052. } :
  1053. function () {
  1054. fn(that, _this);
  1055. });
  1056. if (that.c.greyscale) {
  1057. $$2(el).addClass(Criteria.classes.greyscale);
  1058. }
  1059. // If there is a preDefined value then add it
  1060. if (preDefined !== null) {
  1061. $$2(el).val(preDefined[0]);
  1062. }
  1063. // This is add responsive functionality to the logic button without redrawing everything else
  1064. that.s.dt.one('draw', function () {
  1065. $$2(that.s.topGroup).trigger('dtsb-redrawLogic');
  1066. });
  1067. return el;
  1068. };
  1069. Criteria.initNoValue = function (that) {
  1070. // This is add responsive functionality to the logic button without redrawing everything else
  1071. that.s.dt.one('draw', function () {
  1072. $$2(that.s.topGroup).trigger('dtsb-redrawLogic');
  1073. });
  1074. };
  1075. Criteria.init2Date = function (that, fn, preDefined) {
  1076. var _this = this;
  1077. if (preDefined === void 0) { preDefined = null; }
  1078. var searchDelay = that.s.dt.settings()[0].searchDelay;
  1079. // Declare all of the date elements that are required using DataTables dateTime plugin
  1080. var els = [
  1081. $$2('<input/>')
  1082. .addClass(Criteria.classes.value)
  1083. .addClass(Criteria.classes.input)
  1084. .dtDateTime({
  1085. attachTo: 'input',
  1086. format: that.s.dateFormat ? that.s.dateFormat : undefined
  1087. })
  1088. .on('change', searchDelay !== null ?
  1089. that.s.dt.settings()[0].oApi._fnThrottle(function () {
  1090. return fn(that, this);
  1091. }, searchDelay) :
  1092. function () {
  1093. fn(that, _this);
  1094. })
  1095. .on('input keypress', !that.c.enterSearch && searchDelay !== null ?
  1096. that.s.dt.settings()[0].oApi._fnThrottle(function () {
  1097. return fn(that, this);
  1098. }, searchDelay) :
  1099. that.c.enterSearch ?
  1100. function (e) {
  1101. var code = e.keyCode || e.which;
  1102. if (code === 13) {
  1103. fn(that, _this);
  1104. }
  1105. } :
  1106. function () {
  1107. fn(that, _this);
  1108. }),
  1109. $$2('<span>')
  1110. .addClass(that.classes.joiner)
  1111. .text(that.s.dt.i18n('searchBuilder.valueJoiner', that.c.i18n.valueJoiner)),
  1112. $$2('<input/>')
  1113. .addClass(Criteria.classes.value)
  1114. .addClass(Criteria.classes.input)
  1115. .dtDateTime({
  1116. attachTo: 'input',
  1117. format: that.s.dateFormat ? that.s.dateFormat : undefined
  1118. })
  1119. .on('change', searchDelay !== null ?
  1120. that.s.dt.settings()[0].oApi._fnThrottle(function () {
  1121. return fn(that, this);
  1122. }, searchDelay) :
  1123. function () {
  1124. fn(that, _this);
  1125. })
  1126. .on('input keypress', !that.c.enterSearch && searchDelay !== null ?
  1127. that.s.dt.settings()[0].oApi._fnThrottle(function () {
  1128. return fn(that, this);
  1129. }, searchDelay) :
  1130. that.c.enterSearch ?
  1131. function (e) {
  1132. var code = e.keyCode || e.which;
  1133. if (code === 13) {
  1134. fn(that, _this);
  1135. }
  1136. } :
  1137. function () {
  1138. fn(that, _this);
  1139. })
  1140. ];
  1141. if (that.c.greyscale) {
  1142. $$2(els[0]).addClass(Criteria.classes.greyscale);
  1143. $$2(els[2]).addClass(Criteria.classes.greyscale);
  1144. }
  1145. // If there are and preDefined values then add them
  1146. if (preDefined !== null && preDefined.length > 0) {
  1147. $$2(els[0]).val(preDefined[0]);
  1148. $$2(els[2]).val(preDefined[1]);
  1149. }
  1150. // This is add responsive functionality to the logic button without redrawing everything else
  1151. that.s.dt.one('draw', function () {
  1152. $$2(that.s.topGroup).trigger('dtsb-redrawLogic');
  1153. });
  1154. return els;
  1155. };
  1156. /**
  1157. * Default function for select elements to validate condition
  1158. */
  1159. Criteria.isInputValidSelect = function (el) {
  1160. var allFilled = true;
  1161. // Check each element to make sure that the selections are valid
  1162. for (var _i = 0, el_1 = el; _i < el_1.length; _i++) {
  1163. var element = el_1[_i];
  1164. if (($$2(element).children('option:selected').length ===
  1165. $$2(element).children('option').length -
  1166. $$2(element).children('option.' + Criteria.classes.notItalic).length) &&
  1167. $$2(element).children('option:selected').length === 1 &&
  1168. $$2(element).children('option:selected')[0] === $$2(element).children('option:hidden')[0]) {
  1169. allFilled = false;
  1170. }
  1171. }
  1172. return allFilled;
  1173. };
  1174. /**
  1175. * Default function for input and date elements to validate condition
  1176. */
  1177. Criteria.isInputValidInput = function (el) {
  1178. var allFilled = true;
  1179. // Check each element to make sure that the inputs are valid
  1180. for (var _i = 0, el_2 = el; _i < el_2.length; _i++) {
  1181. var element = el_2[_i];
  1182. if ($$2(element).is('input') && $$2(element).val().length === 0) {
  1183. allFilled = false;
  1184. }
  1185. }
  1186. return allFilled;
  1187. };
  1188. /**
  1189. * Default function for getting select conditions
  1190. */
  1191. Criteria.inputValueSelect = function (el) {
  1192. var values = [];
  1193. // Go through the select elements and push each selected option to the return array
  1194. for (var _i = 0, el_3 = el; _i < el_3.length; _i++) {
  1195. var element = el_3[_i];
  1196. if ($$2(element).is('select')) {
  1197. var val = $$2(element).children('option:selected').val();
  1198. // If the type of the option is an array we need to split it up and sort it
  1199. values.push($$2(element).children('option:selected').attr('type') === 'Array' ?
  1200. val.split(',').sort() :
  1201. val);
  1202. }
  1203. }
  1204. return values;
  1205. };
  1206. /**
  1207. * Default function for getting input conditions
  1208. */
  1209. Criteria.inputValueInput = function (el) {
  1210. var values = [];
  1211. // Go through the input elements and push each value to the return array
  1212. for (var _i = 0, el_4 = el; _i < el_4.length; _i++) {
  1213. var element = el_4[_i];
  1214. if ($$2(element).is('input')) {
  1215. values.push($$2(element).val());
  1216. }
  1217. }
  1218. return values;
  1219. };
  1220. /**
  1221. * Function that is run on each element as a call back when a search should be triggered
  1222. */
  1223. Criteria.updateListener = function (that, el) {
  1224. // When the value is changed the criteria is now complete so can be included in searches
  1225. // Get the condition from the map based on the key that has been selected for the condition
  1226. var condition = that.s.conditions[that.s.condition];
  1227. that.s.filled = condition.isInputValid(that.dom.value, that);
  1228. that.s.value = condition.inputValue(that.dom.value, that);
  1229. if (!Array.isArray(that.s.value)) {
  1230. that.s.value = [that.s.value];
  1231. }
  1232. for (var i = 0; i < that.s.value.length; i++) {
  1233. // If the value is an array we need to sort it
  1234. if (Array.isArray(that.s.value[i])) {
  1235. that.s.value[i].sort();
  1236. }
  1237. // Otherwise replace the decimal place character for i18n
  1238. else if (that.s.type.indexOf('num') !== -1 &&
  1239. (that.s.dt.settings()[0].oLanguage.sDecimal !== '' ||
  1240. that.s.dt.settings()[0].oLanguage.sThousands !== '')) {
  1241. var splitRD = [that.s.value[i].toString()];
  1242. if (that.s.dt.settings()[0].oLanguage.sDecimal !== '') {
  1243. splitRD = that.s.value[i].split(that.s.dt.settings()[0].oLanguage.sDecimal);
  1244. }
  1245. if (that.s.dt.settings()[0].oLanguage.sThousands !== '') {
  1246. for (var j = 0; j < splitRD.length; j++) {
  1247. splitRD[j] = splitRD[j].replace(that.s.dt.settings()[0].oLanguage.sThousands, ',');
  1248. }
  1249. }
  1250. that.s.value[i] = splitRD.join('.');
  1251. }
  1252. }
  1253. // Take note of the cursor position so that we can refocus there later
  1254. var idx = null;
  1255. var cursorPos = null;
  1256. for (var i = 0; i < that.dom.value.length; i++) {
  1257. if (el === that.dom.value[i][0]) {
  1258. idx = i;
  1259. if (el.selectionStart !== undefined) {
  1260. cursorPos = el.selectionStart;
  1261. }
  1262. }
  1263. }
  1264. // Trigger a search
  1265. that.s.dt.draw();
  1266. // Refocus the element and set the correct cursor position
  1267. if (idx !== null) {
  1268. $$2(that.dom.value[idx]).removeClass(that.classes.italic);
  1269. $$2(that.dom.value[idx]).focus();
  1270. if (cursorPos !== null) {
  1271. $$2(that.dom.value[idx])[0].setSelectionRange(cursorPos, cursorPos);
  1272. }
  1273. }
  1274. };
  1275. // The order of the conditions will make eslint sad :(
  1276. // Has to be in this order so that they are displayed correctly in select elements
  1277. // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
  1278. // eslint-disable-next-line @typescript-eslint/member-ordering
  1279. Criteria.dateConditions = {
  1280. '=': {
  1281. conditionName: function (dt, i18n) {
  1282. return dt.i18n('searchBuilder.conditions.date.equals', i18n.conditions.date.equals);
  1283. },
  1284. init: Criteria.initDate,
  1285. inputValue: Criteria.inputValueInput,
  1286. isInputValid: Criteria.isInputValidInput,
  1287. search: function (value, comparison) {
  1288. value = value.replace(/(\/|-|,)/g, '-');
  1289. return value === comparison[0];
  1290. }
  1291. },
  1292. // eslint-disable-next-line sort-keys
  1293. '!=': {
  1294. conditionName: function (dt, i18n) {
  1295. return dt.i18n('searchBuilder.conditions.date.not', i18n.conditions.date.not);
  1296. },
  1297. init: Criteria.initDate,
  1298. inputValue: Criteria.inputValueInput,
  1299. isInputValid: Criteria.isInputValidInput,
  1300. search: function (value, comparison) {
  1301. value = value.replace(/(\/|-|,)/g, '-');
  1302. return value !== comparison[0];
  1303. }
  1304. },
  1305. '<': {
  1306. conditionName: function (dt, i18n) {
  1307. return dt.i18n('searchBuilder.conditions.date.before', i18n.conditions.date.before);
  1308. },
  1309. init: Criteria.initDate,
  1310. inputValue: Criteria.inputValueInput,
  1311. isInputValid: Criteria.isInputValidInput,
  1312. search: function (value, comparison) {
  1313. value = value.replace(/(\/|-|,)/g, '-');
  1314. return value < comparison[0];
  1315. }
  1316. },
  1317. '>': {
  1318. conditionName: function (dt, i18n) {
  1319. return dt.i18n('searchBuilder.conditions.date.after', i18n.conditions.date.after);
  1320. },
  1321. init: Criteria.initDate,
  1322. inputValue: Criteria.inputValueInput,
  1323. isInputValid: Criteria.isInputValidInput,
  1324. search: function (value, comparison) {
  1325. value = value.replace(/(\/|-|,)/g, '-');
  1326. return value > comparison[0];
  1327. }
  1328. },
  1329. 'between': {
  1330. conditionName: function (dt, i18n) {
  1331. return dt.i18n('searchBuilder.conditions.date.between', i18n.conditions.date.between);
  1332. },
  1333. init: Criteria.init2Date,
  1334. inputValue: Criteria.inputValueInput,
  1335. isInputValid: Criteria.isInputValidInput,
  1336. search: function (value, comparison) {
  1337. value = value.replace(/(\/|-|,)/g, '-');
  1338. if (comparison[0] < comparison[1]) {
  1339. return comparison[0] <= value && value <= comparison[1];
  1340. }
  1341. else {
  1342. return comparison[1] <= value && value <= comparison[0];
  1343. }
  1344. }
  1345. },
  1346. // eslint-disable-next-line sort-keys
  1347. '!between': {
  1348. conditionName: function (dt, i18n) {
  1349. return dt.i18n('searchBuilder.conditions.date.notBetween', i18n.conditions.date.notBetween);
  1350. },
  1351. init: Criteria.init2Date,
  1352. inputValue: Criteria.inputValueInput,
  1353. isInputValid: Criteria.isInputValidInput,
  1354. search: function (value, comparison) {
  1355. value = value.replace(/(\/|-|,)/g, '-');
  1356. if (comparison[0] < comparison[1]) {
  1357. return !(comparison[0] <= value && value <= comparison[1]);
  1358. }
  1359. else {
  1360. return !(comparison[1] <= value && value <= comparison[0]);
  1361. }
  1362. }
  1363. },
  1364. 'null': {
  1365. conditionName: function (dt, i18n) {
  1366. return dt.i18n('searchBuilder.conditions.date.empty', i18n.conditions.date.empty);
  1367. },
  1368. init: Criteria.initNoValue,
  1369. inputValue: function () {
  1370. return;
  1371. },
  1372. isInputValid: function () {
  1373. return true;
  1374. },
  1375. search: function (value) {
  1376. return (value === null || value === undefined || value.length === 0);
  1377. }
  1378. },
  1379. // eslint-disable-next-line sort-keys
  1380. '!null': {
  1381. conditionName: function (dt, i18n) {
  1382. return dt.i18n('searchBuilder.conditions.date.notEmpty', i18n.conditions.date.notEmpty);
  1383. },
  1384. init: Criteria.initNoValue,
  1385. inputValue: function () {
  1386. return;
  1387. },
  1388. isInputValid: function () {
  1389. return true;
  1390. },
  1391. search: function (value) {
  1392. return !(value === null || value === undefined || value.length === 0);
  1393. }
  1394. }
  1395. };
  1396. // The order of the conditions will make eslint sad :(
  1397. // Has to be in this order so that they are displayed correctly in select elements
  1398. // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
  1399. // eslint-disable-next-line @typescript-eslint/member-ordering
  1400. Criteria.momentDateConditions = {
  1401. '=': {
  1402. conditionName: function (dt, i18n) {
  1403. return dt.i18n('searchBuilder.conditions.date.equals', i18n.conditions.date.equals);
  1404. },
  1405. init: Criteria.initDate,
  1406. inputValue: Criteria.inputValueInput,
  1407. isInputValid: Criteria.isInputValidInput,
  1408. search: function (value, comparison, that) {
  1409. return moment(value, that.s.dateFormat).valueOf() ===
  1410. moment(comparison[0], that.s.dateFormat).valueOf();
  1411. }
  1412. },
  1413. // eslint-disable-next-line sort-keys
  1414. '!=': {
  1415. conditionName: function (dt, i18n) {
  1416. return dt.i18n('searchBuilder.conditions.date.not', i18n.conditions.date.not);
  1417. },
  1418. init: Criteria.initDate,
  1419. inputValue: Criteria.inputValueInput,
  1420. isInputValid: Criteria.isInputValidInput,
  1421. search: function (value, comparison, that) {
  1422. return moment(value, that.s.dateFormat).valueOf() !==
  1423. moment(comparison[0], that.s.dateFormat).valueOf();
  1424. }
  1425. },
  1426. '<': {
  1427. conditionName: function (dt, i18n) {
  1428. return dt.i18n('searchBuilder.conditions.date.before', i18n.conditions.date.before);
  1429. },
  1430. init: Criteria.initDate,
  1431. inputValue: Criteria.inputValueInput,
  1432. isInputValid: Criteria.isInputValidInput,
  1433. search: function (value, comparison, that) {
  1434. return moment(value, that.s.dateFormat).valueOf() < moment(comparison[0], that.s.dateFormat).valueOf();
  1435. }
  1436. },
  1437. '>': {
  1438. conditionName: function (dt, i18n) {
  1439. return dt.i18n('searchBuilder.conditions.date.after', i18n.conditions.date.after);
  1440. },
  1441. init: Criteria.initDate,
  1442. inputValue: Criteria.inputValueInput,
  1443. isInputValid: Criteria.isInputValidInput,
  1444. search: function (value, comparison, that) {
  1445. return moment(value, that.s.dateFormat).valueOf() > moment(comparison[0], that.s.dateFormat).valueOf();
  1446. }
  1447. },
  1448. 'between': {
  1449. conditionName: function (dt, i18n) {
  1450. return dt.i18n('searchBuilder.conditions.date.between', i18n.conditions.date.between);
  1451. },
  1452. init: Criteria.init2Date,
  1453. inputValue: Criteria.inputValueInput,
  1454. isInputValid: Criteria.isInputValidInput,
  1455. search: function (value, comparison, that) {
  1456. var val = moment(value, that.s.dateFormat).valueOf();
  1457. var comp0 = moment(comparison[0], that.s.dateFormat).valueOf();
  1458. var comp1 = moment(comparison[1], that.s.dateFormat).valueOf();
  1459. if (comp0 < comp1) {
  1460. return comp0 <= val && val <= comp1;
  1461. }
  1462. else {
  1463. return comp1 <= val && val <= comp0;
  1464. }
  1465. }
  1466. },
  1467. // eslint-disable-next-line sort-keys
  1468. '!between': {
  1469. conditionName: function (dt, i18n) {
  1470. return dt.i18n('searchBuilder.conditions.date.notBetween', i18n.conditions.date.notBetween);
  1471. },
  1472. init: Criteria.init2Date,
  1473. inputValue: Criteria.inputValueInput,
  1474. isInputValid: Criteria.isInputValidInput,
  1475. search: function (value, comparison, that) {
  1476. var val = moment(value, that.s.dateFormat).valueOf();
  1477. var comp0 = moment(comparison[0], that.s.dateFormat).valueOf();
  1478. var comp1 = moment(comparison[1], that.s.dateFormat).valueOf();
  1479. if (comp0 < comp1) {
  1480. return !(+comp0 <= +val && +val <= +comp1);
  1481. }
  1482. else {
  1483. return !(+comp1 <= +val && +val <= +comp0);
  1484. }
  1485. }
  1486. },
  1487. 'null': {
  1488. conditionName: function (dt, i18n) {
  1489. return dt.i18n('searchBuilder.conditions.date.empty', i18n.conditions.date.empty);
  1490. },
  1491. init: Criteria.initNoValue,
  1492. inputValue: function () {
  1493. return;
  1494. },
  1495. isInputValid: function () {
  1496. return true;
  1497. },
  1498. search: function (value) {
  1499. return (value === null || value === undefined || value.length === 0);
  1500. }
  1501. },
  1502. // eslint-disable-next-line sort-keys
  1503. '!null': {
  1504. conditionName: function (dt, i18n) {
  1505. return dt.i18n('searchBuilder.conditions.date.notEmpty', i18n.conditions.date.notEmpty);
  1506. },
  1507. init: Criteria.initNoValue,
  1508. inputValue: function () {
  1509. return;
  1510. },
  1511. isInputValid: function () {
  1512. return true;
  1513. },
  1514. search: function (value) {
  1515. return !(value === null || value === undefined || value.length === 0);
  1516. }
  1517. }
  1518. };
  1519. // The order of the conditions will make eslint sad :(
  1520. // Has to be in this order so that they are displayed correctly in select elements
  1521. // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
  1522. // eslint-disable-next-line @typescript-eslint/member-ordering
  1523. Criteria.luxonDateConditions = {
  1524. '=': {
  1525. conditionName: function (dt, i18n) {
  1526. return dt.i18n('searchBuilder.conditions.date.equals', i18n.conditions.date.equals);
  1527. },
  1528. init: Criteria.initDate,
  1529. inputValue: Criteria.inputValueInput,
  1530. isInputValid: Criteria.isInputValidInput,
  1531. search: function (value, comparison, that) {
  1532. return luxon.DateTime.fromFormat(value, that.s.dateFormat).ts
  1533. === luxon.DateTime.fromFormat(comparison[0], that.s.dateFormat).ts;
  1534. }
  1535. },
  1536. // eslint-disable-next-line sort-keys
  1537. '!=': {
  1538. conditionName: function (dt, i18n) {
  1539. return dt.i18n('searchBuilder.conditions.date.not', i18n.conditions.date.not);
  1540. },
  1541. init: Criteria.initDate,
  1542. inputValue: Criteria.inputValueInput,
  1543. isInputValid: Criteria.isInputValidInput,
  1544. search: function (value, comparison, that) {
  1545. return luxon.DateTime.fromFormat(value, that.s.dateFormat).ts
  1546. !== luxon.DateTime.fromFormat(comparison[0], that.s.dateFormat).ts;
  1547. }
  1548. },
  1549. '<': {
  1550. conditionName: function (dt, i18n) {
  1551. return dt.i18n('searchBuilder.conditions.date.before', i18n.conditions.date.before);
  1552. },
  1553. init: Criteria.initDate,
  1554. inputValue: Criteria.inputValueInput,
  1555. isInputValid: Criteria.isInputValidInput,
  1556. search: function (value, comparison, that) {
  1557. return luxon.DateTime.fromFormat(value, that.s.dateFormat).ts
  1558. < luxon.DateTime.fromFormat(comparison[0], that.s.dateFormat).ts;
  1559. }
  1560. },
  1561. '>': {
  1562. conditionName: function (dt, i18n) {
  1563. return dt.i18n('searchBuilder.conditions.date.after', i18n.conditions.date.after);
  1564. },
  1565. init: Criteria.initDate,
  1566. inputValue: Criteria.inputValueInput,
  1567. isInputValid: Criteria.isInputValidInput,
  1568. search: function (value, comparison, that) {
  1569. return luxon.DateTime.fromFormat(value, that.s.dateFormat).ts
  1570. > luxon.DateTime.fromFormat(comparison[0], that.s.dateFormat).ts;
  1571. }
  1572. },
  1573. 'between': {
  1574. conditionName: function (dt, i18n) {
  1575. return dt.i18n('searchBuilder.conditions.date.between', i18n.conditions.date.between);
  1576. },
  1577. init: Criteria.init2Date,
  1578. inputValue: Criteria.inputValueInput,
  1579. isInputValid: Criteria.isInputValidInput,
  1580. search: function (value, comparison, that) {
  1581. var val = luxon.DateTime.fromFormat(value, that.s.dateFormat).ts;
  1582. var comp0 = luxon.DateTime.fromFormat(comparison[0], that.s.dateFormat).ts;
  1583. var comp1 = luxon.DateTime.fromFormat(comparison[1], that.s.dateFormat).ts;
  1584. if (comp0 < comp1) {
  1585. return comp0 <= val && val <= comp1;
  1586. }
  1587. else {
  1588. return comp1 <= val && val <= comp0;
  1589. }
  1590. }
  1591. },
  1592. // eslint-disable-next-line sort-keys
  1593. '!between': {
  1594. conditionName: function (dt, i18n) {
  1595. return dt.i18n('searchBuilder.conditions.date.notBetween', i18n.conditions.date.notBetween);
  1596. },
  1597. init: Criteria.init2Date,
  1598. inputValue: Criteria.inputValueInput,
  1599. isInputValid: Criteria.isInputValidInput,
  1600. search: function (value, comparison, that) {
  1601. var val = luxon.DateTime.fromFormat(value, that.s.dateFormat).ts;
  1602. var comp0 = luxon.DateTime.fromFormat(comparison[0], that.s.dateFormat).ts;
  1603. var comp1 = luxon.DateTime.fromFormat(comparison[1], that.s.dateFormat).ts;
  1604. if (comp0 < comp1) {
  1605. return !(+comp0 <= +val && +val <= +comp1);
  1606. }
  1607. else {
  1608. return !(+comp1 <= +val && +val <= +comp0);
  1609. }
  1610. }
  1611. },
  1612. 'null': {
  1613. conditionName: function (dt, i18n) {
  1614. return dt.i18n('searchBuilder.conditions.date.empty', i18n.conditions.date.empty);
  1615. },
  1616. init: Criteria.initNoValue,
  1617. inputValue: function () {
  1618. return;
  1619. },
  1620. isInputValid: function () {
  1621. return true;
  1622. },
  1623. search: function (value) {
  1624. return (value === null || value === undefined || value.length === 0);
  1625. }
  1626. },
  1627. // eslint-disable-next-line sort-keys
  1628. '!null': {
  1629. conditionName: function (dt, i18n) {
  1630. return dt.i18n('searchBuilder.conditions.date.notEmpty', i18n.conditions.date.notEmpty);
  1631. },
  1632. init: Criteria.initNoValue,
  1633. inputValue: function () {
  1634. return;
  1635. },
  1636. isInputValid: function () {
  1637. return true;
  1638. },
  1639. search: function (value) {
  1640. return !(value === null || value === undefined || value.length === 0);
  1641. }
  1642. }
  1643. };
  1644. // The order of the conditions will make eslint sad :(
  1645. // Has to be in this order so that they are displayed correctly in select elements
  1646. // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
  1647. // eslint-disable-next-line @typescript-eslint/member-ordering
  1648. Criteria.numConditions = {
  1649. '=': {
  1650. conditionName: function (dt, i18n) {
  1651. return dt.i18n('searchBuilder.conditions.number.equals', i18n.conditions.number.equals);
  1652. },
  1653. init: Criteria.initSelect,
  1654. inputValue: Criteria.inputValueSelect,
  1655. isInputValid: Criteria.isInputValidSelect,
  1656. search: function (value, comparison) {
  1657. return +value === +comparison[0];
  1658. }
  1659. },
  1660. // eslint-disable-next-line sort-keys
  1661. '!=': {
  1662. conditionName: function (dt, i18n) {
  1663. return dt.i18n('searchBuilder.conditions.number.not', i18n.conditions.number.not);
  1664. },
  1665. init: Criteria.initSelect,
  1666. inputValue: Criteria.inputValueSelect,
  1667. isInputValid: Criteria.isInputValidSelect,
  1668. search: function (value, comparison) {
  1669. return +value !== +comparison[0];
  1670. }
  1671. },
  1672. '<': {
  1673. conditionName: function (dt, i18n) {
  1674. return dt.i18n('searchBuilder.conditions.number.lt', i18n.conditions.number.lt);
  1675. },
  1676. init: Criteria.initInput,
  1677. inputValue: Criteria.inputValueInput,
  1678. isInputValid: Criteria.isInputValidInput,
  1679. search: function (value, comparison) {
  1680. return +value < +comparison[0];
  1681. }
  1682. },
  1683. '<=': {
  1684. conditionName: function (dt, i18n) {
  1685. return dt.i18n('searchBuilder.conditions.number.lte', i18n.conditions.number.lte);
  1686. },
  1687. init: Criteria.initInput,
  1688. inputValue: Criteria.inputValueInput,
  1689. isInputValid: Criteria.isInputValidInput,
  1690. search: function (value, comparison) {
  1691. return +value <= +comparison[0];
  1692. }
  1693. },
  1694. '>=': {
  1695. conditionName: function (dt, i18n) {
  1696. return dt.i18n('searchBuilder.conditions.number.gte', i18n.conditions.number.gte);
  1697. },
  1698. init: Criteria.initInput,
  1699. inputValue: Criteria.inputValueInput,
  1700. isInputValid: Criteria.isInputValidInput,
  1701. search: function (value, comparison) {
  1702. return +value >= +comparison[0];
  1703. }
  1704. },
  1705. // eslint-disable-next-line sort-keys
  1706. '>': {
  1707. conditionName: function (dt, i18n) {
  1708. return dt.i18n('searchBuilder.conditions.number.gt', i18n.conditions.number.gt);
  1709. },
  1710. init: Criteria.initInput,
  1711. inputValue: Criteria.inputValueInput,
  1712. isInputValid: Criteria.isInputValidInput,
  1713. search: function (value, comparison) {
  1714. return +value > +comparison[0];
  1715. }
  1716. },
  1717. 'between': {
  1718. conditionName: function (dt, i18n) {
  1719. return dt.i18n('searchBuilder.conditions.number.between', i18n.conditions.number.between);
  1720. },
  1721. init: Criteria.init2Input,
  1722. inputValue: Criteria.inputValueInput,
  1723. isInputValid: Criteria.isInputValidInput,
  1724. search: function (value, comparison) {
  1725. if (+comparison[0] < +comparison[1]) {
  1726. return +comparison[0] <= +value && +value <= +comparison[1];
  1727. }
  1728. else {
  1729. return +comparison[1] <= +value && +value <= +comparison[0];
  1730. }
  1731. }
  1732. },
  1733. // eslint-disable-next-line sort-keys
  1734. '!between': {
  1735. conditionName: function (dt, i18n) {
  1736. return dt.i18n('searchBuilder.conditions.number.notBetween', i18n.conditions.number.notBetween);
  1737. },
  1738. init: Criteria.init2Input,
  1739. inputValue: Criteria.inputValueInput,
  1740. isInputValid: Criteria.isInputValidInput,
  1741. search: function (value, comparison) {
  1742. if (+comparison[0] < +comparison[1]) {
  1743. return !(+comparison[0] <= +value && +value <= +comparison[1]);
  1744. }
  1745. else {
  1746. return !(+comparison[1] <= +value && +value <= +comparison[0]);
  1747. }
  1748. }
  1749. },
  1750. 'null': {
  1751. conditionName: function (dt, i18n) {
  1752. return dt.i18n('searchBuilder.conditions.number.empty', i18n.conditions.number.empty);
  1753. },
  1754. init: Criteria.initNoValue,
  1755. inputValue: function () {
  1756. return;
  1757. },
  1758. isInputValid: function () {
  1759. return true;
  1760. },
  1761. search: function (value) {
  1762. return (value === null || value === undefined || value.length === 0);
  1763. }
  1764. },
  1765. // eslint-disable-next-line sort-keys
  1766. '!null': {
  1767. conditionName: function (dt, i18n) {
  1768. return dt.i18n('searchBuilder.conditions.number.notEmpty', i18n.conditions.number.notEmpty);
  1769. },
  1770. init: Criteria.initNoValue,
  1771. inputValue: function () {
  1772. return;
  1773. },
  1774. isInputValid: function () {
  1775. return true;
  1776. },
  1777. search: function (value) {
  1778. return !(value === null || value === undefined || value.length === 0);
  1779. }
  1780. }
  1781. };
  1782. // The order of the conditions will make eslint sad :(
  1783. // Has to be in this order so that they are displayed correctly in select elements
  1784. // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
  1785. // eslint-disable-next-line @typescript-eslint/member-ordering
  1786. Criteria.numFmtConditions = {
  1787. '=': {
  1788. conditionName: function (dt, i18n) {
  1789. return dt.i18n('searchBuilder.conditions.number.equals', i18n.conditions.number.equals);
  1790. },
  1791. init: Criteria.initSelect,
  1792. inputValue: Criteria.inputValueSelect,
  1793. isInputValid: Criteria.isInputValidSelect,
  1794. search: function (value, comparison) {
  1795. var val = value.indexOf('-') === 0 ?
  1796. '-' + value.replace(/[^0-9.]/g, '') :
  1797. value.replace(/[^0-9.]/g, '');
  1798. var comp = comparison[0].indexOf('-') === 0 ?
  1799. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  1800. comparison[0].replace(/[^0-9.]/g, '');
  1801. return +val === +comp;
  1802. }
  1803. },
  1804. // eslint-disable-next-line sort-keys
  1805. '!=': {
  1806. conditionName: function (dt, i18n) {
  1807. return dt.i18n('searchBuilder.conditions.number.not', i18n.conditions.number.not);
  1808. },
  1809. init: Criteria.initSelect,
  1810. inputValue: Criteria.inputValueSelect,
  1811. isInputValid: Criteria.isInputValidSelect,
  1812. search: function (value, comparison) {
  1813. var val = value.indexOf('-') === 0 ?
  1814. '-' + value.replace(/[^0-9.]/g, '') :
  1815. value.replace(/[^0-9.]/g, '');
  1816. var comp = comparison[0].indexOf('-') === 0 ?
  1817. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  1818. comparison[0].replace(/[^0-9.]/g, '');
  1819. return +val !== +comp;
  1820. }
  1821. },
  1822. '<': {
  1823. conditionName: function (dt, i18n) {
  1824. return dt.i18n('searchBuilder.conditions.number.lt', i18n.conditions.number.lt);
  1825. },
  1826. init: Criteria.initInput,
  1827. inputValue: Criteria.inputValueInput,
  1828. isInputValid: Criteria.isInputValidInput,
  1829. search: function (value, comparison) {
  1830. var val = value.indexOf('-') === 0 ?
  1831. '-' + value.replace(/[^0-9.]/g, '') :
  1832. value.replace(/[^0-9.]/g, '');
  1833. var comp = comparison[0].indexOf('-') === 0 ?
  1834. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  1835. comparison[0].replace(/[^0-9.]/g, '');
  1836. return +val < +comp;
  1837. }
  1838. },
  1839. '<=': {
  1840. conditionName: function (dt, i18n) {
  1841. return dt.i18n('searchBuilder.conditions.number.lte', i18n.conditions.number.lte);
  1842. },
  1843. init: Criteria.initInput,
  1844. inputValue: Criteria.inputValueInput,
  1845. isInputValid: Criteria.isInputValidInput,
  1846. search: function (value, comparison) {
  1847. var val = value.indexOf('-') === 0 ?
  1848. '-' + value.replace(/[^0-9.]/g, '') :
  1849. value.replace(/[^0-9.]/g, '');
  1850. var comp = comparison[0].indexOf('-') === 0 ?
  1851. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  1852. comparison[0].replace(/[^0-9.]/g, '');
  1853. return +val <= +comp;
  1854. }
  1855. },
  1856. '>=': {
  1857. conditionName: function (dt, i18n) {
  1858. return dt.i18n('searchBuilder.conditions.number.gte', i18n.conditions.number.gte);
  1859. },
  1860. init: Criteria.initInput,
  1861. inputValue: Criteria.inputValueInput,
  1862. isInputValid: Criteria.isInputValidInput,
  1863. search: function (value, comparison) {
  1864. var val = value.indexOf('-') === 0 ?
  1865. '-' + value.replace(/[^0-9.]/g, '') :
  1866. value.replace(/[^0-9.]/g, '');
  1867. var comp = comparison[0].indexOf('-') === 0 ?
  1868. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  1869. comparison[0].replace(/[^0-9.]/g, '');
  1870. return +val >= +comp;
  1871. }
  1872. },
  1873. // eslint-disable-next-line sort-keys
  1874. '>': {
  1875. conditionName: function (dt, i18n) {
  1876. return dt.i18n('searchBuilder.conditions.number.gt', i18n.conditions.number.gt);
  1877. },
  1878. init: Criteria.initInput,
  1879. inputValue: Criteria.inputValueInput,
  1880. isInputValid: Criteria.isInputValidInput,
  1881. search: function (value, comparison) {
  1882. var val = value.indexOf('-') === 0 ?
  1883. '-' + value.replace(/[^0-9.]/g, '') :
  1884. value.replace(/[^0-9.]/g, '');
  1885. var comp = comparison[0].indexOf('-') === 0 ?
  1886. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  1887. comparison[0].replace(/[^0-9.]/g, '');
  1888. return +val > +comp;
  1889. }
  1890. },
  1891. 'between': {
  1892. conditionName: function (dt, i18n) {
  1893. return dt.i18n('searchBuilder.conditions.number.between', i18n.conditions.number.between);
  1894. },
  1895. init: Criteria.init2Input,
  1896. inputValue: Criteria.inputValueInput,
  1897. isInputValid: Criteria.isInputValidInput,
  1898. search: function (value, comparison) {
  1899. var val = value.indexOf('-') === 0 ?
  1900. '-' + value.replace(/[^0-9.]/g, '') :
  1901. value.replace(/[^0-9.]/g, '');
  1902. var comp0 = comparison[0].indexOf('-') === 0 ?
  1903. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  1904. comparison[0].replace(/[^0-9.]/g, '');
  1905. var comp1 = comparison[1].indexOf('-') === 0 ?
  1906. '-' + comparison[1].replace(/[^0-9.]/g, '') :
  1907. comparison[1].replace(/[^0-9.]/g, '');
  1908. if (+comp0 < +comp1) {
  1909. return +comp0 <= +val && +val <= +comp1;
  1910. }
  1911. else {
  1912. return +comp1 <= +val && +val <= +comp0;
  1913. }
  1914. }
  1915. },
  1916. // eslint-disable-next-line sort-keys
  1917. '!between': {
  1918. conditionName: function (dt, i18n) {
  1919. return dt.i18n('searchBuilder.conditions.number.notBetween', i18n.conditions.number.notBetween);
  1920. },
  1921. init: Criteria.init2Input,
  1922. inputValue: Criteria.inputValueInput,
  1923. isInputValid: Criteria.isInputValidInput,
  1924. search: function (value, comparison) {
  1925. var val = value.indexOf('-') === 0 ?
  1926. '-' + value.replace(/[^0-9.]/g, '') :
  1927. value.replace(/[^0-9.]/g, '');
  1928. var comp0 = comparison[0].indexOf('-') === 0 ?
  1929. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  1930. comparison[0].replace(/[^0-9.]/g, '');
  1931. var comp1 = comparison[1].indexOf('-') === 0 ?
  1932. '-' + comparison[1].replace(/[^0-9.]/g, '') :
  1933. comparison[1].replace(/[^0-9.]/g, '');
  1934. if (+comp0 < +comp1) {
  1935. return !(+comp0 <= +val && +val <= +comp1);
  1936. }
  1937. else {
  1938. return !(+comp1 <= +val && +val <= +comp0);
  1939. }
  1940. }
  1941. },
  1942. 'null': {
  1943. conditionName: function (dt, i18n) {
  1944. return dt.i18n('searchBuilder.conditions.number.empty', i18n.conditions.number.empty);
  1945. },
  1946. init: Criteria.initNoValue,
  1947. inputValue: function () {
  1948. return;
  1949. },
  1950. isInputValid: function () {
  1951. return true;
  1952. },
  1953. search: function (value) {
  1954. return (value === null || value === undefined || value.length === 0);
  1955. }
  1956. },
  1957. // eslint-disable-next-line sort-keys
  1958. '!null': {
  1959. conditionName: function (dt, i18n) {
  1960. return dt.i18n('searchBuilder.conditions.number.notEmpty', i18n.conditions.number.notEmpty);
  1961. },
  1962. init: Criteria.initNoValue,
  1963. inputValue: function () {
  1964. return;
  1965. },
  1966. isInputValid: function () {
  1967. return true;
  1968. },
  1969. search: function (value) {
  1970. return !(value === null || value === undefined || value.length === 0);
  1971. }
  1972. }
  1973. };
  1974. // The order of the conditions will make eslint sad :(
  1975. // Has to be in this order so that they are displayed correctly in select elements
  1976. // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
  1977. // eslint-disable-next-line @typescript-eslint/member-ordering
  1978. Criteria.stringConditions = {
  1979. '=': {
  1980. conditionName: function (dt, i18n) {
  1981. return dt.i18n('searchBuilder.conditions.string.equals', i18n.conditions.string.equals);
  1982. },
  1983. init: Criteria.initSelect,
  1984. inputValue: Criteria.inputValueSelect,
  1985. isInputValid: Criteria.isInputValidSelect,
  1986. search: function (value, comparison) {
  1987. return value === comparison[0];
  1988. }
  1989. },
  1990. // eslint-disable-next-line sort-keys
  1991. '!=': {
  1992. conditionName: function (dt, i18n) {
  1993. return dt.i18n('searchBuilder.conditions.string.not', i18n.conditions.string.not);
  1994. },
  1995. init: Criteria.initSelect,
  1996. inputValue: Criteria.inputValueSelect,
  1997. isInputValid: Criteria.isInputValidInput,
  1998. search: function (value, comparison) {
  1999. return value !== comparison[0];
  2000. }
  2001. },
  2002. 'starts': {
  2003. conditionName: function (dt, i18n) {
  2004. return dt.i18n('searchBuilder.conditions.string.startsWith', i18n.conditions.string.startsWith);
  2005. },
  2006. init: Criteria.initInput,
  2007. inputValue: Criteria.inputValueInput,
  2008. isInputValid: Criteria.isInputValidInput,
  2009. search: function (value, comparison) {
  2010. return value.toLowerCase().indexOf(comparison[0].toLowerCase()) === 0;
  2011. }
  2012. },
  2013. // eslint-disable-next-line sort-keys
  2014. 'contains': {
  2015. conditionName: function (dt, i18n) {
  2016. return dt.i18n('searchBuilder.conditions.string.contains', i18n.conditions.string.contains);
  2017. },
  2018. init: Criteria.initInput,
  2019. inputValue: Criteria.inputValueInput,
  2020. isInputValid: Criteria.isInputValidInput,
  2021. search: function (value, comparison) {
  2022. return value.toLowerCase().indexOf(comparison[0].toLowerCase()) !== -1;
  2023. }
  2024. },
  2025. 'ends': {
  2026. conditionName: function (dt, i18n) {
  2027. return dt.i18n('searchBuilder.conditions.string.endsWith', i18n.conditions.string.endsWith);
  2028. },
  2029. init: Criteria.initInput,
  2030. inputValue: Criteria.inputValueInput,
  2031. isInputValid: Criteria.isInputValidInput,
  2032. search: function (value, comparison) {
  2033. return value.toLowerCase().endsWith(comparison[0].toLowerCase());
  2034. }
  2035. },
  2036. 'null': {
  2037. conditionName: function (dt, i18n) {
  2038. return dt.i18n('searchBuilder.conditions.string.empty', i18n.conditions.string.empty);
  2039. },
  2040. init: Criteria.initNoValue,
  2041. inputValue: function () {
  2042. return;
  2043. },
  2044. isInputValid: function () {
  2045. return true;
  2046. },
  2047. search: function (value) {
  2048. return (value === null || value === undefined || value.length === 0);
  2049. }
  2050. },
  2051. // eslint-disable-next-line sort-keys
  2052. '!null': {
  2053. conditionName: function (dt, i18n) {
  2054. return dt.i18n('searchBuilder.conditions.string.notEmpty', i18n.conditions.string.notEmpty);
  2055. },
  2056. init: Criteria.initNoValue,
  2057. inputValue: function () {
  2058. return;
  2059. },
  2060. isInputValid: function () {
  2061. return true;
  2062. },
  2063. search: function (value) {
  2064. return !(value === null || value === undefined || value.length === 0);
  2065. }
  2066. }
  2067. };
  2068. // The order of the conditions will make eslint sad :(
  2069. // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
  2070. // eslint-disable-next-line @typescript-eslint/member-ordering
  2071. Criteria.arrayConditions = {
  2072. 'contains': {
  2073. conditionName: function (dt, i18n) {
  2074. return dt.i18n('searchBuilder.conditions.array.contains', i18n.conditions.array.contains);
  2075. },
  2076. init: Criteria.initSelectArray,
  2077. inputValue: Criteria.inputValueSelect,
  2078. isInputValid: Criteria.isInputValidSelect,
  2079. search: function (value, comparison) {
  2080. return value.indexOf(comparison[0]) !== -1;
  2081. }
  2082. },
  2083. 'without': {
  2084. conditionName: function (dt, i18n) {
  2085. return dt.i18n('searchBuilder.conditions.array.without', i18n.conditions.array.without);
  2086. },
  2087. init: Criteria.initSelectArray,
  2088. inputValue: Criteria.inputValueSelect,
  2089. isInputValid: Criteria.isInputValidSelect,
  2090. search: function (value, comparison) {
  2091. return value.indexOf(comparison[0]) === -1;
  2092. }
  2093. },
  2094. // eslint-disable-next-line sort-keys
  2095. '=': {
  2096. conditionName: function (dt, i18n) {
  2097. return dt.i18n('searchBuilder.conditions.array.equals', i18n.conditions.array.equals);
  2098. },
  2099. init: Criteria.initSelect,
  2100. inputValue: Criteria.inputValueSelect,
  2101. isInputValid: Criteria.isInputValidSelect,
  2102. search: function (value, comparison) {
  2103. if (value.length === comparison[0].length) {
  2104. for (var i = 0; i < value.length; i++) {
  2105. if (value[i] !== comparison[0][i]) {
  2106. return false;
  2107. }
  2108. }
  2109. return true;
  2110. }
  2111. return false;
  2112. }
  2113. },
  2114. // eslint-disable-next-line sort-keys
  2115. '!=': {
  2116. conditionName: function (dt, i18n) {
  2117. return dt.i18n('searchBuilder.conditions.array.not', i18n.conditions.array.not);
  2118. },
  2119. init: Criteria.initSelect,
  2120. inputValue: Criteria.inputValueSelect,
  2121. isInputValid: Criteria.isInputValidSelect,
  2122. search: function (value, comparison) {
  2123. if (value.length === comparison[0].length) {
  2124. for (var i = 0; i < value.length; i++) {
  2125. if (value[i] !== comparison[0][i]) {
  2126. return true;
  2127. }
  2128. }
  2129. return false;
  2130. }
  2131. return true;
  2132. }
  2133. },
  2134. 'null': {
  2135. conditionName: function (dt, i18n) {
  2136. return dt.i18n('searchBuilder.conditions.array.empty', i18n.conditions.array.empty);
  2137. },
  2138. init: Criteria.initNoValue,
  2139. inputValue: function () {
  2140. return;
  2141. },
  2142. isInputValid: function () {
  2143. return true;
  2144. },
  2145. search: function (value) {
  2146. return (value === null || value === undefined || value.length === 0);
  2147. }
  2148. },
  2149. // eslint-disable-next-line sort-keys
  2150. '!null': {
  2151. conditionName: function (dt, i18n) {
  2152. return dt.i18n('searchBuilder.conditions.array.notEmpty', i18n.conditions.array.notEmpty);
  2153. },
  2154. init: Criteria.initNoValue,
  2155. inputValue: function () {
  2156. return;
  2157. },
  2158. isInputValid: function () {
  2159. return true;
  2160. },
  2161. search: function (value) {
  2162. return (value !== null && value !== undefined && value.length !== 0);
  2163. }
  2164. }
  2165. };
  2166. // eslint will be sad because we have to disable member ordering for this as the
  2167. // private static properties used are not yet declared otherwise
  2168. // eslint-disable-next-line @typescript-eslint/member-ordering
  2169. Criteria.defaults = {
  2170. columns: true,
  2171. conditions: {
  2172. 'array': Criteria.arrayConditions,
  2173. 'date': Criteria.dateConditions,
  2174. 'html': Criteria.stringConditions,
  2175. 'html-num': Criteria.numConditions,
  2176. 'html-num-fmt': Criteria.numFmtConditions,
  2177. 'luxon': Criteria.luxonDateConditions,
  2178. 'moment': Criteria.momentDateConditions,
  2179. 'num': Criteria.numConditions,
  2180. 'num-fmt': Criteria.numFmtConditions,
  2181. 'string': Criteria.stringConditions
  2182. },
  2183. depthLimit: false,
  2184. enterSearch: false,
  2185. filterChanged: undefined,
  2186. greyscale: false,
  2187. i18n: {
  2188. add: 'Add Condition',
  2189. button: {
  2190. 0: 'Search Builder',
  2191. _: 'Search Builder (%d)'
  2192. },
  2193. clearAll: 'Clear All',
  2194. condition: 'Condition',
  2195. data: 'Data',
  2196. deleteTitle: 'Delete filtering rule',
  2197. leftTitle: 'Outdent criteria',
  2198. logicAnd: 'And',
  2199. logicOr: 'Or',
  2200. rightTitle: 'Indent criteria',
  2201. title: {
  2202. 0: 'Custom Search Builder',
  2203. _: 'Custom Search Builder (%d)'
  2204. },
  2205. value: 'Value',
  2206. valueJoiner: 'and'
  2207. },
  2208. logic: 'AND',
  2209. orthogonal: {
  2210. display: 'display',
  2211. search: 'filter'
  2212. },
  2213. preDefined: false
  2214. };
  2215. return Criteria;
  2216. }());
  2217. var $$1;
  2218. var dataTable$1;
  2219. /**
  2220. * Sets the value of jQuery for use in the file
  2221. *
  2222. * @param jq the instance of jQuery to be set
  2223. */
  2224. function setJQuery$1(jq) {
  2225. $$1 = jq;
  2226. dataTable$1 = jq.fn.dataTable;
  2227. }
  2228. /**
  2229. * The Group class is used within SearchBuilder to represent a group of criteria
  2230. */
  2231. var Group = /** @class */ (function () {
  2232. function Group(table, opts, topGroup, index, isChild, depth) {
  2233. if (index === void 0) { index = 0; }
  2234. if (isChild === void 0) { isChild = false; }
  2235. if (depth === void 0) { depth = 1; }
  2236. // Check that the required version of DataTables is included
  2237. if (!dataTable$1 || !dataTable$1.versionCheck || !dataTable$1.versionCheck('1.10.0')) {
  2238. throw new Error('SearchBuilder requires DataTables 1.10 or newer');
  2239. }
  2240. this.classes = $$1.extend(true, {}, Group.classes);
  2241. // Get options from user
  2242. this.c = $$1.extend(true, {}, Group.defaults, opts);
  2243. this.s = {
  2244. criteria: [],
  2245. depth: depth,
  2246. dt: table,
  2247. index: index,
  2248. isChild: isChild,
  2249. logic: undefined,
  2250. opts: opts,
  2251. toDrop: undefined,
  2252. topGroup: topGroup
  2253. };
  2254. this.dom = {
  2255. add: $$1('<button/>')
  2256. .addClass(this.classes.add)
  2257. .addClass(this.classes.button)
  2258. .attr('type', 'button'),
  2259. clear: $$1('<button>&times</button>')
  2260. .addClass(this.classes.button)
  2261. .addClass(this.classes.clearGroup)
  2262. .attr('type', 'button'),
  2263. container: $$1('<div/>')
  2264. .addClass(this.classes.group),
  2265. logic: $$1('<button/>')
  2266. .addClass(this.classes.logic)
  2267. .addClass(this.classes.button)
  2268. .attr('type', 'button'),
  2269. logicContainer: $$1('<div/>')
  2270. .addClass(this.classes.logicContainer)
  2271. };
  2272. // A reference to the top level group is maintained throughout any subgroups and criteria that may be created
  2273. if (this.s.topGroup === undefined) {
  2274. this.s.topGroup = this.dom.container;
  2275. }
  2276. this._setup();
  2277. return this;
  2278. }
  2279. /**
  2280. * Destroys the groups buttons, clears the internal criteria and removes it from the dom
  2281. */
  2282. Group.prototype.destroy = function () {
  2283. // Turn off listeners
  2284. $$1(this.dom.add).off('.dtsb');
  2285. $$1(this.dom.logic).off('.dtsb');
  2286. // Trigger event for groups at a higher level to pick up on
  2287. $$1(this.dom.container)
  2288. .trigger('dtsb-destroy')
  2289. .remove();
  2290. this.s.criteria = [];
  2291. };
  2292. /**
  2293. * Gets the details required to rebuild the group
  2294. */
  2295. // Eslint upset at empty object but needs to be done
  2296. // eslint-disable-next-line @typescript-eslint/ban-types
  2297. Group.prototype.getDetails = function () {
  2298. if (this.s.criteria.length === 0) {
  2299. return {};
  2300. }
  2301. var details = {
  2302. criteria: [],
  2303. logic: this.s.logic
  2304. };
  2305. // NOTE here crit could be either a subgroup or a criteria
  2306. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  2307. var crit = _a[_i];
  2308. details.criteria.push(crit.criteria.getDetails());
  2309. }
  2310. return details;
  2311. };
  2312. /**
  2313. * Getter for the node for the container of the group
  2314. *
  2315. * @returns Node for the container of the group
  2316. */
  2317. Group.prototype.getNode = function () {
  2318. return this.dom.container;
  2319. };
  2320. /**
  2321. * Rebuilds the group based upon the details passed in
  2322. *
  2323. * @param loadedDetails the details required to rebuild the group
  2324. */
  2325. Group.prototype.rebuild = function (loadedDetails) {
  2326. // If no criteria are stored then just return
  2327. if (loadedDetails.criteria === undefined ||
  2328. loadedDetails.criteria === null ||
  2329. (Array.isArray(loadedDetails.criteria) && loadedDetails.criteria.length === 0)) {
  2330. return;
  2331. }
  2332. this.s.logic = loadedDetails.logic;
  2333. $$1(this.dom.logic).text(this.s.logic === 'OR'
  2334. ? this.s.dt.i18n('searchBuilder.logicOr', this.c.i18n.logicOr)
  2335. : this.s.dt.i18n('searchBuilder.logicAnd', this.c.i18n.logicAnd));
  2336. // Add all of the criteria, be it a sub group or a criteria
  2337. if (Array.isArray(loadedDetails.criteria)) {
  2338. for (var _i = 0, _a = loadedDetails.criteria; _i < _a.length; _i++) {
  2339. var crit = _a[_i];
  2340. if (crit.logic !== undefined) {
  2341. this._addPrevGroup(crit);
  2342. }
  2343. else if (crit.logic === undefined) {
  2344. this._addPrevCriteria(crit);
  2345. }
  2346. }
  2347. }
  2348. // For all of the criteria children, update the arrows incase they require changing and set the listeners
  2349. for (var _b = 0, _c = this.s.criteria; _b < _c.length; _b++) {
  2350. var crit = _c[_b];
  2351. if (crit.criteria instanceof Criteria) {
  2352. crit.criteria.updateArrows(this.s.criteria.length > 1, false);
  2353. this._setCriteriaListeners(crit.criteria);
  2354. }
  2355. }
  2356. };
  2357. /**
  2358. * Redraws the Contents of the searchBuilder Groups and Criteria
  2359. */
  2360. Group.prototype.redrawContents = function () {
  2361. // Clear the container out and add the basic elements
  2362. $$1(this.dom.container)
  2363. .empty()
  2364. .append(this.dom.logicContainer)
  2365. .append(this.dom.add);
  2366. // Sort the criteria by index so that they appear in the correct order
  2367. this.s.criteria.sort(function (a, b) {
  2368. if (a.criteria.s.index < b.criteria.s.index) {
  2369. return -1;
  2370. }
  2371. else if (a.criteria.s.index > b.criteria.s.index) {
  2372. return 1;
  2373. }
  2374. return 0;
  2375. });
  2376. this.setListeners();
  2377. for (var i = 0; i < this.s.criteria.length; i++) {
  2378. var crit = this.s.criteria[i].criteria;
  2379. if (crit instanceof Criteria) {
  2380. // Reset the index to the new value
  2381. this.s.criteria[i].index = i;
  2382. this.s.criteria[i].criteria.s.index = i;
  2383. // Add to the group
  2384. $$1(this.s.criteria[i].criteria.dom.container).insertBefore(this.dom.add);
  2385. // Set listeners for various points
  2386. this._setCriteriaListeners(crit);
  2387. this.s.criteria[i].criteria.rebuild(this.s.criteria[i].criteria.getDetails());
  2388. }
  2389. else if (crit instanceof Group && crit.s.criteria.length > 0) {
  2390. // Reset the index to the new value
  2391. this.s.criteria[i].index = i;
  2392. this.s.criteria[i].criteria.s.index = i;
  2393. // Add the sub group to the group
  2394. $$1(this.s.criteria[i].criteria.dom.container).insertBefore(this.dom.add);
  2395. // Redraw the contents of the group
  2396. crit.redrawContents();
  2397. this._setGroupListeners(crit);
  2398. }
  2399. else {
  2400. // The group is empty so remove it
  2401. this.s.criteria.splice(i, 1);
  2402. i--;
  2403. }
  2404. }
  2405. this.setupLogic();
  2406. };
  2407. /**
  2408. * Resizes the logic button only rather than the entire dom.
  2409. */
  2410. Group.prototype.redrawLogic = function () {
  2411. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  2412. var crit = _a[_i];
  2413. if (crit instanceof Group) {
  2414. crit.redrawLogic();
  2415. }
  2416. }
  2417. this.setupLogic();
  2418. };
  2419. /**
  2420. * Search method, checking the row data against the criteria in the group
  2421. *
  2422. * @param rowData The row data to be compared
  2423. * @returns boolean The result of the search
  2424. */
  2425. Group.prototype.search = function (rowData, rowIdx) {
  2426. if (this.s.logic === 'AND') {
  2427. return this._andSearch(rowData, rowIdx);
  2428. }
  2429. else if (this.s.logic === 'OR') {
  2430. return this._orSearch(rowData, rowIdx);
  2431. }
  2432. return true;
  2433. };
  2434. /**
  2435. * Locates the groups logic button to the correct location on the page
  2436. */
  2437. Group.prototype.setupLogic = function () {
  2438. // Remove logic button
  2439. $$1(this.dom.logicContainer).remove();
  2440. $$1(this.dom.clear).remove();
  2441. // If there are no criteria in the group then keep the logic removed and return
  2442. if (this.s.criteria.length < 1) {
  2443. if (!this.s.isChild) {
  2444. $$1(this.dom.container).trigger('dtsb-destroy');
  2445. // Set criteria left margin
  2446. $$1(this.dom.container).css('margin-left', 0);
  2447. }
  2448. return;
  2449. }
  2450. // Set width, take 2 for the border
  2451. var height = $$1(this.dom.container).height() - 1;
  2452. $$1(this.dom.clear).height('0px');
  2453. $$1(this.dom.logicContainer).append(this.dom.clear).width(height);
  2454. // Prepend logic button
  2455. $$1(this.dom.container).prepend(this.dom.logicContainer);
  2456. this._setLogicListener();
  2457. // Set criteria left margin
  2458. $$1(this.dom.container).css('margin-left', $$1(this.dom.logicContainer).outerHeight(true));
  2459. var logicOffset = $$1(this.dom.logicContainer).offset();
  2460. // Set horizontal alignment
  2461. var currentLeft = logicOffset.left;
  2462. var groupLeft = $$1(this.dom.container).offset().left;
  2463. var shuffleLeft = currentLeft - groupLeft;
  2464. var newPos = currentLeft - shuffleLeft - $$1(this.dom.logicContainer).outerHeight(true);
  2465. $$1(this.dom.logicContainer).offset({ left: newPos });
  2466. // Set vertical alignment
  2467. var firstCrit = $$1(this.dom.logicContainer).next();
  2468. var currentTop = logicOffset.top;
  2469. var firstTop = $$1(firstCrit).offset().top;
  2470. var shuffleTop = currentTop - firstTop;
  2471. var newTop = currentTop - shuffleTop;
  2472. $$1(this.dom.logicContainer).offset({ top: newTop });
  2473. $$1(this.dom.clear).outerHeight($$1(this.dom.logicContainer).height());
  2474. this._setClearListener();
  2475. };
  2476. /**
  2477. * Sets listeners on the groups elements
  2478. */
  2479. Group.prototype.setListeners = function () {
  2480. var _this = this;
  2481. $$1(this.dom.add).unbind('click');
  2482. $$1(this.dom.add).on('click', function () {
  2483. // If this is the parent group then the logic button has not been added yet
  2484. if (!_this.s.isChild) {
  2485. $$1(_this.dom.container).prepend(_this.dom.logicContainer);
  2486. }
  2487. _this.addCriteria();
  2488. $$1(_this.dom.container).trigger('dtsb-add');
  2489. _this.s.dt.state.save();
  2490. return false;
  2491. });
  2492. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  2493. var crit = _a[_i];
  2494. crit.criteria.setListeners();
  2495. }
  2496. this._setClearListener();
  2497. this._setLogicListener();
  2498. };
  2499. /**
  2500. * Adds a criteria to the group
  2501. *
  2502. * @param crit Instance of Criteria to be added to the group
  2503. */
  2504. Group.prototype.addCriteria = function (crit, redraw) {
  2505. if (crit === void 0) { crit = null; }
  2506. if (redraw === void 0) { redraw = true; }
  2507. var index = crit === null ? this.s.criteria.length : crit.s.index;
  2508. var criteria = new Criteria(this.s.dt, this.s.opts, this.s.topGroup, index, this.s.depth);
  2509. // If a Criteria has been passed in then set the values to continue that
  2510. if (crit !== null) {
  2511. criteria.c = crit.c;
  2512. criteria.s = crit.s;
  2513. criteria.s.depth = this.s.depth;
  2514. criteria.classes = crit.classes;
  2515. }
  2516. criteria.populate();
  2517. var inserted = false;
  2518. for (var i = 0; i < this.s.criteria.length; i++) {
  2519. if (i === 0 && this.s.criteria[i].criteria.s.index > criteria.s.index) {
  2520. // Add the node for the criteria at the start of the group
  2521. $$1(criteria.getNode()).insertBefore(this.s.criteria[i].criteria.dom.container);
  2522. inserted = true;
  2523. }
  2524. else if (i < this.s.criteria.length - 1 &&
  2525. this.s.criteria[i].criteria.s.index < criteria.s.index &&
  2526. this.s.criteria[i + 1].criteria.s.index > criteria.s.index) {
  2527. // Add the node for the criteria in the correct location
  2528. $$1(criteria.getNode()).insertAfter(this.s.criteria[i].criteria.dom.container);
  2529. inserted = true;
  2530. }
  2531. }
  2532. if (!inserted) {
  2533. $$1(criteria.getNode()).insertBefore(this.dom.add);
  2534. }
  2535. // Add the details for this criteria to the array
  2536. this.s.criteria.push({
  2537. criteria: criteria,
  2538. index: index
  2539. });
  2540. this.s.criteria = this.s.criteria.sort(function (a, b) { return a.criteria.s.index - b.criteria.s.index; });
  2541. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  2542. var opt = _a[_i];
  2543. if (opt.criteria instanceof Criteria) {
  2544. opt.criteria.updateArrows(this.s.criteria.length > 1, redraw);
  2545. }
  2546. }
  2547. this._setCriteriaListeners(criteria);
  2548. criteria.setListeners();
  2549. this.setupLogic();
  2550. };
  2551. /**
  2552. * Checks the group to see if it has any filled criteria
  2553. */
  2554. Group.prototype.checkFilled = function () {
  2555. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  2556. var crit = _a[_i];
  2557. if ((crit.criteria instanceof Criteria && crit.criteria.s.filled) ||
  2558. (crit.criteria instanceof Group && crit.criteria.checkFilled())) {
  2559. return true;
  2560. }
  2561. }
  2562. return false;
  2563. };
  2564. /**
  2565. * Gets the count for the number of criteria in this group and any sub groups
  2566. */
  2567. Group.prototype.count = function () {
  2568. var count = 0;
  2569. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  2570. var crit = _a[_i];
  2571. if (crit.criteria instanceof Group) {
  2572. count += crit.criteria.count();
  2573. }
  2574. else {
  2575. count++;
  2576. }
  2577. }
  2578. return count;
  2579. };
  2580. /**
  2581. * Rebuilds a sub group that previously existed
  2582. *
  2583. * @param loadedGroup The details of a group within this group
  2584. */
  2585. Group.prototype._addPrevGroup = function (loadedGroup) {
  2586. var idx = this.s.criteria.length;
  2587. var group = new Group(this.s.dt, this.c, this.s.topGroup, idx, true, this.s.depth + 1);
  2588. // Add the new group to the criteria array
  2589. this.s.criteria.push({
  2590. criteria: group,
  2591. index: idx,
  2592. logic: group.s.logic
  2593. });
  2594. // Rebuild it with the previous conditions for that group
  2595. group.rebuild(loadedGroup);
  2596. this.s.criteria[idx].criteria = group;
  2597. $$1(this.s.topGroup).trigger('dtsb-redrawContents');
  2598. this._setGroupListeners(group);
  2599. };
  2600. /**
  2601. * Rebuilds a criteria of this group that previously existed
  2602. *
  2603. * @param loadedCriteria The details of a criteria within the group
  2604. */
  2605. Group.prototype._addPrevCriteria = function (loadedCriteria) {
  2606. var idx = this.s.criteria.length;
  2607. var criteria = new Criteria(this.s.dt, this.s.opts, this.s.topGroup, idx, this.s.depth);
  2608. criteria.populate();
  2609. // Add the new criteria to the criteria array
  2610. this.s.criteria.push({
  2611. criteria: criteria,
  2612. index: idx
  2613. });
  2614. // Rebuild it with the previous conditions for that criteria
  2615. criteria.rebuild(loadedCriteria);
  2616. this.s.criteria[idx].criteria = criteria;
  2617. $$1(this.s.topGroup).trigger('dtsb-redrawContents');
  2618. };
  2619. /**
  2620. * Checks And the criteria using AND logic
  2621. *
  2622. * @param rowData The row data to be checked against the search criteria
  2623. * @returns boolean The result of the AND search
  2624. */
  2625. Group.prototype._andSearch = function (rowData, rowIdx) {
  2626. // If there are no criteria then return true for this group
  2627. if (this.s.criteria.length === 0) {
  2628. return true;
  2629. }
  2630. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  2631. var crit = _a[_i];
  2632. // If the criteria is not complete then skip it
  2633. if (crit.criteria instanceof Criteria && !crit.criteria.s.filled) {
  2634. continue;
  2635. }
  2636. // Otherwise if a single one fails return false
  2637. else if (!crit.criteria.search(rowData, rowIdx)) {
  2638. return false;
  2639. }
  2640. }
  2641. // If we get to here then everything has passed, so return true for the group
  2642. return true;
  2643. };
  2644. /**
  2645. * Checks And the criteria using OR logic
  2646. *
  2647. * @param rowData The row data to be checked against the search criteria
  2648. * @returns boolean The result of the OR search
  2649. */
  2650. Group.prototype._orSearch = function (rowData, rowIdx) {
  2651. // If there are no criteria in the group then return true
  2652. if (this.s.criteria.length === 0) {
  2653. return true;
  2654. }
  2655. // This will check to make sure that at least one criteria in the group is complete
  2656. var filledfound = false;
  2657. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  2658. var crit = _a[_i];
  2659. if (crit.criteria instanceof Criteria && crit.criteria.s.filled) {
  2660. // A completed criteria has been found so set the flag
  2661. filledfound = true;
  2662. // If the search passes then return true
  2663. if (crit.criteria.search(rowData, rowIdx)) {
  2664. return true;
  2665. }
  2666. }
  2667. else if (crit.criteria instanceof Group && crit.criteria.checkFilled()) {
  2668. filledfound = true;
  2669. if (crit.criteria.search(rowData, rowIdx)) {
  2670. return true;
  2671. }
  2672. }
  2673. }
  2674. // If we get here we need to return the inverse of filledfound,
  2675. // as if any have been found and we are here then none have passed
  2676. return !filledfound;
  2677. };
  2678. /**
  2679. * Removes a criteria from the group
  2680. *
  2681. * @param criteria The criteria instance to be removed
  2682. */
  2683. Group.prototype._removeCriteria = function (criteria, group) {
  2684. if (group === void 0) { group = false; }
  2685. // If removing a criteria and there is only then then just destroy the group
  2686. if (this.s.criteria.length <= 1 && this.s.isChild) {
  2687. this.destroy();
  2688. }
  2689. else {
  2690. // Otherwise splice the given criteria out and redo the indexes
  2691. var last = void 0;
  2692. for (var i = 0; i < this.s.criteria.length; i++) {
  2693. if (this.s.criteria[i].index === criteria.s.index &&
  2694. (!group || this.s.criteria[i].criteria instanceof Group)) {
  2695. last = i;
  2696. }
  2697. }
  2698. // We want to remove the last element with the desired index, as its replacement will be inserted before it
  2699. if (last !== undefined) {
  2700. this.s.criteria.splice(last, 1);
  2701. }
  2702. for (var i = 0; i < this.s.criteria.length; i++) {
  2703. this.s.criteria[i].index = i;
  2704. this.s.criteria[i].criteria.s.index = i;
  2705. }
  2706. }
  2707. };
  2708. /**
  2709. * Sets the listeners in group for a criteria
  2710. *
  2711. * @param criteria The criteria for the listeners to be set on
  2712. */
  2713. Group.prototype._setCriteriaListeners = function (criteria) {
  2714. var _this = this;
  2715. $$1(criteria.dom["delete"])
  2716. .unbind('click')
  2717. .on('click', function () {
  2718. _this._removeCriteria(criteria);
  2719. $$1(criteria.dom.container).remove();
  2720. for (var _i = 0, _a = _this.s.criteria; _i < _a.length; _i++) {
  2721. var crit = _a[_i];
  2722. if (crit.criteria instanceof Criteria) {
  2723. crit.criteria.updateArrows(_this.s.criteria.length > 1);
  2724. }
  2725. }
  2726. criteria.destroy();
  2727. _this.s.dt.draw();
  2728. $$1(_this.s.topGroup).trigger('dtsb-redrawContents');
  2729. $$1(_this.s.topGroup).trigger('dtsb-updateTitle');
  2730. return false;
  2731. });
  2732. $$1(criteria.dom.right)
  2733. .unbind('click')
  2734. .on('click', function () {
  2735. var idx = criteria.s.index;
  2736. var group = new Group(_this.s.dt, _this.s.opts, _this.s.topGroup, criteria.s.index, true, _this.s.depth + 1);
  2737. // Add the criteria that is to be moved to the new group
  2738. group.addCriteria(criteria);
  2739. // Update the details in the current groups criteria array
  2740. _this.s.criteria[idx].criteria = group;
  2741. _this.s.criteria[idx].logic = 'AND';
  2742. $$1(_this.s.topGroup).trigger('dtsb-redrawContents');
  2743. _this._setGroupListeners(group);
  2744. return false;
  2745. });
  2746. $$1(criteria.dom.left)
  2747. .unbind('click')
  2748. .on('click', function () {
  2749. _this.s.toDrop = new Criteria(_this.s.dt, _this.s.opts, _this.s.topGroup, criteria.s.index);
  2750. _this.s.toDrop.s = criteria.s;
  2751. _this.s.toDrop.c = criteria.c;
  2752. _this.s.toDrop.classes = criteria.classes;
  2753. _this.s.toDrop.populate();
  2754. // The dropCriteria event mutates the reference to the index so need to store it
  2755. var index = _this.s.toDrop.s.index;
  2756. $$1(_this.dom.container).trigger('dtsb-dropCriteria');
  2757. criteria.s.index = index;
  2758. _this._removeCriteria(criteria);
  2759. // By tracking the top level group we can directly trigger a redraw on it,
  2760. // bubbling is also possible, but that is slow with deep levelled groups
  2761. $$1(_this.s.topGroup).trigger('dtsb-redrawContents');
  2762. _this.s.dt.draw();
  2763. return false;
  2764. });
  2765. };
  2766. /**
  2767. * Set's the listeners for the group clear button
  2768. */
  2769. Group.prototype._setClearListener = function () {
  2770. var _this = this;
  2771. $$1(this.dom.clear)
  2772. .unbind('click')
  2773. .on('click', function () {
  2774. if (!_this.s.isChild) {
  2775. $$1(_this.dom.container).trigger('dtsb-clearContents');
  2776. return false;
  2777. }
  2778. _this.destroy();
  2779. $$1(_this.s.topGroup).trigger('dtsb-updateTitle');
  2780. $$1(_this.s.topGroup).trigger('dtsb-redrawContents');
  2781. return false;
  2782. });
  2783. };
  2784. /**
  2785. * Sets listeners for sub groups of this group
  2786. *
  2787. * @param group The sub group that the listeners are to be set on
  2788. */
  2789. Group.prototype._setGroupListeners = function (group) {
  2790. var _this = this;
  2791. // Set listeners for the new group
  2792. $$1(group.dom.add)
  2793. .unbind('click')
  2794. .on('click', function () {
  2795. _this.setupLogic();
  2796. $$1(_this.dom.container).trigger('dtsb-add');
  2797. return false;
  2798. });
  2799. $$1(group.dom.container)
  2800. .unbind('dtsb-add')
  2801. .on('dtsb-add', function () {
  2802. _this.setupLogic();
  2803. $$1(_this.dom.container).trigger('dtsb-add');
  2804. return false;
  2805. });
  2806. $$1(group.dom.container)
  2807. .unbind('dtsb-destroy')
  2808. .on('dtsb-destroy', function () {
  2809. _this._removeCriteria(group, true);
  2810. $$1(group.dom.container).remove();
  2811. _this.setupLogic();
  2812. return false;
  2813. });
  2814. $$1(group.dom.container)
  2815. .unbind('dtsb-dropCriteria')
  2816. .on('dtsb-dropCriteria', function () {
  2817. var toDrop = group.s.toDrop;
  2818. toDrop.s.index = group.s.index;
  2819. toDrop.updateArrows(_this.s.criteria.length > 1, false);
  2820. _this.addCriteria(toDrop, false);
  2821. return false;
  2822. });
  2823. group.setListeners();
  2824. };
  2825. /**
  2826. * Sets up the Group instance, setting listeners and appending elements
  2827. */
  2828. Group.prototype._setup = function () {
  2829. this.setListeners();
  2830. $$1(this.dom.add).text(this.s.dt.i18n('searchBuilder.add', this.c.i18n.add));
  2831. $$1(this.dom.logic).text(this.c.logic === 'OR'
  2832. ? this.s.dt.i18n('searchBuilder.logicOr', this.c.i18n.logicOr)
  2833. : this.s.dt.i18n('searchBuilder.logicAnd', this.c.i18n.logicAnd));
  2834. this.s.logic = this.c.logic === 'OR' ? 'OR' : 'AND';
  2835. if (this.c.greyscale) {
  2836. $$1(this.dom.logic).addClass(this.classes.greyscale);
  2837. }
  2838. $$1(this.dom.logicContainer).append(this.dom.logic).append(this.dom.clear);
  2839. // Only append the logic button immediately if this is a sub group,
  2840. // otherwise it will be prepended later when adding a criteria
  2841. if (this.s.isChild) {
  2842. $$1(this.dom.container).append(this.dom.logicContainer);
  2843. }
  2844. $$1(this.dom.container).append(this.dom.add);
  2845. };
  2846. /**
  2847. * Sets the listener for the logic button
  2848. */
  2849. Group.prototype._setLogicListener = function () {
  2850. var _this = this;
  2851. $$1(this.dom.logic)
  2852. .unbind('click')
  2853. .on('click', function () {
  2854. _this._toggleLogic();
  2855. _this.s.dt.draw();
  2856. for (var _i = 0, _a = _this.s.criteria; _i < _a.length; _i++) {
  2857. var crit = _a[_i];
  2858. crit.criteria.setListeners();
  2859. }
  2860. });
  2861. };
  2862. /**
  2863. * Toggles the logic for the group
  2864. */
  2865. Group.prototype._toggleLogic = function () {
  2866. if (this.s.logic === 'OR') {
  2867. this.s.logic = 'AND';
  2868. $$1(this.dom.logic).text(this.s.dt.i18n('searchBuilder.logicAnd', this.c.i18n.logicAnd));
  2869. }
  2870. else if (this.s.logic === 'AND') {
  2871. this.s.logic = 'OR';
  2872. $$1(this.dom.logic).text(this.s.dt.i18n('searchBuilder.logicOr', this.c.i18n.logicOr));
  2873. }
  2874. };
  2875. Group.version = '1.1.0';
  2876. Group.classes = {
  2877. add: 'dtsb-add',
  2878. button: 'dtsb-button',
  2879. clearGroup: 'dtsb-clearGroup',
  2880. greyscale: 'dtsb-greyscale',
  2881. group: 'dtsb-group',
  2882. inputButton: 'dtsb-iptbtn',
  2883. logic: 'dtsb-logic',
  2884. logicContainer: 'dtsb-logicContainer'
  2885. };
  2886. Group.defaults = {
  2887. columns: true,
  2888. conditions: {
  2889. 'date': Criteria.dateConditions,
  2890. 'html': Criteria.stringConditions,
  2891. 'html-num': Criteria.numConditions,
  2892. 'html-num-fmt': Criteria.numFmtConditions,
  2893. 'luxon': Criteria.luxonDateConditions,
  2894. 'moment': Criteria.momentDateConditions,
  2895. 'num': Criteria.numConditions,
  2896. 'num-fmt': Criteria.numFmtConditions,
  2897. 'string': Criteria.stringConditions
  2898. },
  2899. depthLimit: false,
  2900. enterSearch: false,
  2901. filterChanged: undefined,
  2902. greyscale: false,
  2903. i18n: {
  2904. add: 'Add Condition',
  2905. button: {
  2906. 0: 'Search Builder',
  2907. _: 'Search Builder (%d)'
  2908. },
  2909. clearAll: 'Clear All',
  2910. condition: 'Condition',
  2911. data: 'Data',
  2912. deleteTitle: 'Delete filtering rule',
  2913. leftTitle: 'Outdent criteria',
  2914. logicAnd: 'And',
  2915. logicOr: 'Or',
  2916. rightTitle: 'Indent criteria',
  2917. title: {
  2918. 0: 'Custom Search Builder',
  2919. _: 'Custom Search Builder (%d)'
  2920. },
  2921. value: 'Value',
  2922. valueJoiner: 'and'
  2923. },
  2924. logic: 'AND',
  2925. orthogonal: {
  2926. display: 'display',
  2927. search: 'filter'
  2928. },
  2929. preDefined: false
  2930. };
  2931. return Group;
  2932. }());
  2933. var $;
  2934. var dataTable;
  2935. /**
  2936. * Sets the value of jQuery for use in the file
  2937. *
  2938. * @param jq the instance of jQuery to be set
  2939. */
  2940. function setJQuery(jq) {
  2941. $ = jq;
  2942. dataTable = jq.fn.DataTable;
  2943. }
  2944. /**
  2945. * SearchBuilder class for DataTables.
  2946. * Allows for complex search queries to be constructed and implemented on a DataTable
  2947. */
  2948. var SearchBuilder = /** @class */ (function () {
  2949. function SearchBuilder(builderSettings, opts) {
  2950. var _this = this;
  2951. // Check that the required version of DataTables is included
  2952. if (!dataTable || !dataTable.versionCheck || !dataTable.versionCheck('1.10.0')) {
  2953. throw new Error('SearchBuilder requires DataTables 1.10 or newer');
  2954. }
  2955. var table = new dataTable.Api(builderSettings);
  2956. this.classes = $.extend(true, {}, SearchBuilder.classes);
  2957. // Get options from user
  2958. this.c = $.extend(true, {}, SearchBuilder.defaults, opts);
  2959. this.dom = {
  2960. clearAll: $('<button type="button">' + table.i18n('searchBuilder.clearAll', this.c.i18n.clearAll) + '</button>')
  2961. .addClass(this.classes.clearAll)
  2962. .addClass(this.classes.button)
  2963. .attr('type', 'button'),
  2964. container: $('<div/>')
  2965. .addClass(this.classes.container),
  2966. title: $('<div/>')
  2967. .addClass(this.classes.title),
  2968. titleRow: $('<div/>')
  2969. .addClass(this.classes.titleRow),
  2970. topGroup: undefined
  2971. };
  2972. this.s = {
  2973. dt: table,
  2974. opts: opts,
  2975. search: undefined,
  2976. topGroup: undefined
  2977. };
  2978. // If searchbuilder is already defined for this table then return
  2979. if (table.settings()[0]._searchBuilder !== undefined) {
  2980. return;
  2981. }
  2982. table.settings()[0]._searchBuilder = this;
  2983. // Run the remaining setup when the table is initialised
  2984. if (this.s.dt.settings()[0]._bInitComplete) {
  2985. this._setUp();
  2986. }
  2987. else {
  2988. table.one('init.dt', function () {
  2989. _this._setUp();
  2990. });
  2991. }
  2992. return this;
  2993. }
  2994. /**
  2995. * Gets the details required to rebuild the SearchBuilder as it currently is
  2996. */
  2997. // eslint upset at empty object but that is what it is
  2998. // eslint-disable-next-line @typescript-eslint/ban-types
  2999. SearchBuilder.prototype.getDetails = function () {
  3000. return this.s.topGroup.getDetails();
  3001. };
  3002. /**
  3003. * Getter for the node of the container for the searchBuilder
  3004. *
  3005. * @returns JQuery<HTMLElement> the node of the container
  3006. */
  3007. SearchBuilder.prototype.getNode = function () {
  3008. return this.dom.container;
  3009. };
  3010. /**
  3011. * Rebuilds the SearchBuilder to a state that is provided
  3012. *
  3013. * @param details The details required to perform a rebuild
  3014. */
  3015. SearchBuilder.prototype.rebuild = function (details) {
  3016. $(this.dom.clearAll).click();
  3017. // If there are no details to rebuild then return
  3018. if (details === undefined || details === null) {
  3019. return this;
  3020. }
  3021. this.s.topGroup.rebuild(details);
  3022. this.s.dt.draw();
  3023. this.s.topGroup.setListeners();
  3024. return this;
  3025. };
  3026. /**
  3027. * Applies the defaults to preDefined criteria
  3028. *
  3029. * @param preDef the array of criteria to be processed.
  3030. */
  3031. SearchBuilder.prototype._applyPreDefDefaults = function (preDef) {
  3032. var _this = this;
  3033. if (preDef.criteria !== undefined && preDef.logic === undefined) {
  3034. preDef.logic = 'AND';
  3035. }
  3036. var _loop_1 = function (crit) {
  3037. // Apply the defaults to any further criteria
  3038. if (crit.criteria !== undefined) {
  3039. crit = this_1._applyPreDefDefaults(crit);
  3040. }
  3041. else {
  3042. this_1.s.dt.columns().every(function (index) {
  3043. if (_this.s.dt.settings()[0].aoColumns[index].sTitle === crit.data) {
  3044. crit.dataIdx = index;
  3045. }
  3046. });
  3047. }
  3048. };
  3049. var this_1 = this;
  3050. for (var _i = 0, _a = preDef.criteria; _i < _a.length; _i++) {
  3051. var crit = _a[_i];
  3052. _loop_1(crit);
  3053. }
  3054. return preDef;
  3055. };
  3056. /**
  3057. * Set's up the SearchBuilder
  3058. */
  3059. SearchBuilder.prototype._setUp = function (loadState) {
  3060. var _this = this;
  3061. if (loadState === void 0) { loadState = true; }
  3062. // Register an Api method for getting the column type
  3063. $.fn.DataTable.Api.registerPlural('columns().type()', 'column().type()', function (selector, opts) {
  3064. return this.iterator('column', function (settings, column) {
  3065. return settings.aoColumns[column].sType;
  3066. }, 1);
  3067. });
  3068. // Check that DateTime is included, If not need to check if it could be used
  3069. if (!dataTable.DateTime) {
  3070. var types = this.s.dt.columns().type().toArray();
  3071. var columnIdxs = this.s.dt.columns().toArray();
  3072. // If the types are not yet set then draw to see if they can be retrieved then
  3073. if (types === undefined) {
  3074. this.s.dt.draw();
  3075. types = this.s.dt.columns().type().toArray();
  3076. }
  3077. for (var i = 0; i < columnIdxs[0].length; i++) {
  3078. var column = columnIdxs[0][i];
  3079. var type = types[column];
  3080. if (
  3081. // Check if this column can be filtered
  3082. (this.c.columns === true ||
  3083. (Array.isArray(this.c.columns) &&
  3084. this.c.columns.indexOf(i) !== -1)) &&
  3085. // Check if the type is one of the restricted types
  3086. (type.indexOf('date') !== -1 ||
  3087. type.indexOf('moment') !== -1 ||
  3088. type.indexOf('luxon') !== -1)) {
  3089. alert('SearchBuilder Requires DateTime when used with dates.');
  3090. throw new Error('SearchBuilder requires DateTime');
  3091. }
  3092. }
  3093. }
  3094. this.s.topGroup = new Group(this.s.dt, this.c, undefined);
  3095. this._setClearListener();
  3096. this.s.dt.on('stateSaveParams', function (e, settings, data) {
  3097. data.searchBuilder = _this.getDetails();
  3098. data.page = _this.s.dt.page();
  3099. });
  3100. this._build();
  3101. if (loadState) {
  3102. var loadedState = this.s.dt.state.loaded();
  3103. // If the loaded State is not null rebuild based on it for statesave
  3104. if (loadedState !== null && loadedState.searchBuilder !== undefined) {
  3105. this.s.topGroup.rebuild(loadedState.searchBuilder);
  3106. $(this.s.topGroup.dom.container).trigger('dtsb-redrawContents');
  3107. this.s.dt.page(loadedState.page).draw('page');
  3108. this.s.topGroup.setListeners();
  3109. }
  3110. // Otherwise load any predefined options
  3111. else if (this.c.preDefined !== false) {
  3112. this.c.preDefined = this._applyPreDefDefaults(this.c.preDefined);
  3113. this.rebuild(this.c.preDefined);
  3114. }
  3115. }
  3116. this._setEmptyListener();
  3117. this.s.dt.state.save();
  3118. };
  3119. /**
  3120. * Updates the title of the SearchBuilder
  3121. *
  3122. * @param count the number of filters in the SearchBuilder
  3123. */
  3124. SearchBuilder.prototype._updateTitle = function (count) {
  3125. $(this.dom.title).html(this.s.dt.i18n('searchBuilder.title', this.c.i18n.title, count));
  3126. };
  3127. /**
  3128. * Builds all of the dom elements together
  3129. */
  3130. SearchBuilder.prototype._build = function () {
  3131. var _this = this;
  3132. // Empty and setup the container
  3133. $(this.dom.clearAll).remove();
  3134. $(this.dom.container).empty();
  3135. var count = this.s.topGroup.count();
  3136. this._updateTitle(count);
  3137. $(this.dom.titleRow).append(this.dom.title);
  3138. $(this.dom.container).append(this.dom.titleRow);
  3139. this.dom.topGroup = this.s.topGroup.getNode();
  3140. $(this.dom.container).append(this.dom.topGroup);
  3141. this._setRedrawListener();
  3142. var tableNode = this.s.dt.table(0).node();
  3143. if ($.fn.dataTable.ext.search.indexOf(this.s.search) === -1) {
  3144. // Custom search function for SearchBuilder
  3145. this.s.search = function (settings, searchData, dataIndex, origData) {
  3146. if (settings.nTable !== tableNode) {
  3147. return true;
  3148. }
  3149. return _this.s.topGroup.search(searchData, dataIndex);
  3150. };
  3151. // Add SearchBuilder search function to the dataTables search array
  3152. $.fn.dataTable.ext.search.push(this.s.search);
  3153. }
  3154. this.s.dt.on('destroy.dt', function () {
  3155. $(_this.dom.container).remove();
  3156. $(_this.dom.clearAll).remove();
  3157. var searchIdx = $.fn.dataTable.ext.search.indexOf(_this.s.search);
  3158. while (searchIdx !== -1) {
  3159. $.fn.dataTable.ext.search.splice(searchIdx, 1);
  3160. searchIdx = $.fn.dataTable.ext.search.indexOf(_this.s.search);
  3161. }
  3162. });
  3163. };
  3164. /**
  3165. * Checks if the clearAll button should be added or not
  3166. */
  3167. SearchBuilder.prototype._checkClear = function () {
  3168. if (this.s.topGroup.s.criteria.length > 0) {
  3169. $(this.dom.clearAll).insertAfter(this.dom.title);
  3170. this._setClearListener();
  3171. }
  3172. else {
  3173. $(this.dom.clearAll).remove();
  3174. }
  3175. };
  3176. /**
  3177. * Update the count in the title/button
  3178. *
  3179. * @param count Number of filters applied
  3180. */
  3181. SearchBuilder.prototype._filterChanged = function (count) {
  3182. var fn = this.c.filterChanged;
  3183. if (typeof fn === 'function') {
  3184. fn(count, this.s.dt.i18n('searchBuilder.button', this.c.i18n.button, count));
  3185. }
  3186. };
  3187. /**
  3188. * Set the listener for the clear button
  3189. */
  3190. SearchBuilder.prototype._setClearListener = function () {
  3191. var _this = this;
  3192. $(this.dom.clearAll).unbind('click');
  3193. $(this.dom.clearAll).on('click', function () {
  3194. _this.s.topGroup = new Group(_this.s.dt, _this.c, undefined);
  3195. _this._build();
  3196. _this.s.dt.draw();
  3197. _this.s.topGroup.setListeners();
  3198. $(_this.dom.clearAll).remove();
  3199. _this._setEmptyListener();
  3200. _this._filterChanged(0);
  3201. return false;
  3202. });
  3203. };
  3204. /**
  3205. * Set the listener for the Redraw event
  3206. */
  3207. SearchBuilder.prototype._setRedrawListener = function () {
  3208. var _this = this;
  3209. $(this.s.topGroup.dom.container).unbind('dtsb-redrawContents');
  3210. $(this.s.topGroup.dom.container).on('dtsb-redrawContents', function () {
  3211. _this._checkClear();
  3212. _this.s.topGroup.redrawContents();
  3213. _this.s.topGroup.setupLogic();
  3214. _this._setEmptyListener();
  3215. var count = _this.s.topGroup.count();
  3216. _this._updateTitle(count);
  3217. _this._filterChanged(count);
  3218. _this.s.dt.state.save();
  3219. });
  3220. $(this.s.topGroup.dom.container).unbind('dtsb-redrawLogic');
  3221. $(this.s.topGroup.dom.container).on('dtsb-redrawLogic', function () {
  3222. _this.s.topGroup.redrawLogic();
  3223. var count = _this.s.topGroup.count();
  3224. _this._updateTitle(count);
  3225. _this._filterChanged(count);
  3226. });
  3227. $(this.s.topGroup.dom.container).on('dtsb-add', function () {
  3228. var count = _this.s.topGroup.count();
  3229. _this._updateTitle(count);
  3230. _this._filterChanged(count);
  3231. });
  3232. $(this.s.dt).on('postEdit postCreate postRemove', function () {
  3233. _this.s.topGroup.redrawContents();
  3234. });
  3235. $(this.s.topGroup.dom.container).unbind('dtsb-clearContents');
  3236. $(this.s.topGroup.dom.container).on('dtsb-clearContents', function () {
  3237. _this._setUp(false);
  3238. _this._filterChanged(0);
  3239. _this.s.dt.draw();
  3240. });
  3241. $(this.s.topGroup.dom.container).on('dtsb-updateTitle', function () {
  3242. var count = _this.s.topGroup.count();
  3243. _this._updateTitle(count);
  3244. _this._filterChanged(count);
  3245. });
  3246. };
  3247. /**
  3248. * Sets listeners to check whether clearAll should be added or removed
  3249. */
  3250. SearchBuilder.prototype._setEmptyListener = function () {
  3251. var _this = this;
  3252. $(this.s.topGroup.dom.add).on('click', function () {
  3253. _this._checkClear();
  3254. });
  3255. $(this.s.topGroup.dom.container).on('dtsb-destroy', function () {
  3256. $(_this.dom.clearAll).remove();
  3257. });
  3258. };
  3259. SearchBuilder.version = '1.1.0';
  3260. SearchBuilder.classes = {
  3261. button: 'dtsb-button',
  3262. clearAll: 'dtsb-clearAll',
  3263. container: 'dtsb-searchBuilder',
  3264. inputButton: 'dtsb-iptbtn',
  3265. title: 'dtsb-title',
  3266. titleRow: 'dtsb-titleRow'
  3267. };
  3268. SearchBuilder.defaults = {
  3269. columns: true,
  3270. conditions: {
  3271. 'date': Criteria.dateConditions,
  3272. 'html': Criteria.stringConditions,
  3273. 'html-num': Criteria.numConditions,
  3274. 'html-num-fmt': Criteria.numFmtConditions,
  3275. 'luxon': Criteria.luxonDateConditions,
  3276. 'moment': Criteria.momentDateConditions,
  3277. 'num': Criteria.numConditions,
  3278. 'num-fmt': Criteria.numFmtConditions,
  3279. 'string': Criteria.stringConditions
  3280. },
  3281. depthLimit: false,
  3282. enterSearch: false,
  3283. filterChanged: undefined,
  3284. greyscale: false,
  3285. i18n: {
  3286. add: 'Add Condition',
  3287. button: {
  3288. 0: 'Search Builder',
  3289. _: 'Search Builder (%d)'
  3290. },
  3291. clearAll: 'Clear All',
  3292. condition: 'Condition',
  3293. conditions: {
  3294. array: {
  3295. contains: 'Contains',
  3296. empty: 'Empty',
  3297. equals: 'Equals',
  3298. not: 'Not',
  3299. notEmpty: 'Not Empty',
  3300. without: 'Without'
  3301. },
  3302. date: {
  3303. after: 'After',
  3304. before: 'Before',
  3305. between: 'Between',
  3306. empty: 'Empty',
  3307. equals: 'Equals',
  3308. not: 'Not',
  3309. notBetween: 'Not Between',
  3310. notEmpty: 'Not Empty'
  3311. },
  3312. // eslint-disable-next-line id-blacklist
  3313. number: {
  3314. between: 'Between',
  3315. empty: 'Empty',
  3316. equals: 'Equals',
  3317. gt: 'Greater Than',
  3318. gte: 'Greater Than Equal To',
  3319. lt: 'Less Than',
  3320. lte: 'Less Than Equal To',
  3321. not: 'Not',
  3322. notBetween: 'Not Between',
  3323. notEmpty: 'Not Empty'
  3324. },
  3325. // eslint-disable-next-line id-blacklist
  3326. string: {
  3327. contains: 'Contains',
  3328. empty: 'Empty',
  3329. endsWith: 'Ends With',
  3330. equals: 'Equals',
  3331. not: 'Not',
  3332. notEmpty: 'Not Empty',
  3333. startsWith: 'Starts With'
  3334. }
  3335. },
  3336. data: 'Data',
  3337. deleteTitle: 'Delete filtering rule',
  3338. leftTitle: 'Outdent criteria',
  3339. logicAnd: 'And',
  3340. logicOr: 'Or',
  3341. rightTitle: 'Indent criteria',
  3342. title: {
  3343. 0: 'Custom Search Builder',
  3344. _: 'Custom Search Builder (%d)'
  3345. },
  3346. value: 'Value',
  3347. valueJoiner: 'and'
  3348. },
  3349. logic: 'AND',
  3350. orthogonal: {
  3351. display: 'display',
  3352. search: 'filter'
  3353. },
  3354. preDefined: false
  3355. };
  3356. return SearchBuilder;
  3357. }());
  3358. /*! SearchBuilder 1.0.1
  3359. * ©2020 SpryMedia Ltd - datatables.net/license/mit
  3360. */
  3361. // DataTables extensions common UMD. Note that this allows for AMD, CommonJS
  3362. // (with window and jQuery being allowed as parameters to the returned
  3363. // function) or just default browser loading.
  3364. (function (factory) {
  3365. if (typeof define === 'function' && define.amd) {
  3366. // AMD
  3367. define(['jquery', 'datatables.net'], function ($) {
  3368. return factory($, window, document);
  3369. });
  3370. }
  3371. else if (typeof exports === 'object') {
  3372. // CommonJS
  3373. module.exports = function (root, $) {
  3374. if (!root) {
  3375. root = window;
  3376. }
  3377. if (!$ || !$.fn.dataTable) {
  3378. // eslint-disable-next-line @typescript-eslint/no-var-requires
  3379. $ = require('datatables.net')(root, $).$;
  3380. }
  3381. return factory($, root, root.document);
  3382. };
  3383. }
  3384. else {
  3385. // Browser - assume jQuery has already been loaded
  3386. factory(window.jQuery, window, document);
  3387. }
  3388. }(function ($, window, document) {
  3389. setJQuery($);
  3390. setJQuery$1($);
  3391. setJQuery$2($);
  3392. var dataTable = $.fn.dataTable;
  3393. $.fn.dataTable.SearchBuilder = SearchBuilder;
  3394. $.fn.DataTable.SearchBuilder = SearchBuilder;
  3395. $.fn.dataTable.Group = Group;
  3396. $.fn.DataTable.Group = Group;
  3397. $.fn.dataTable.Criteria = Criteria;
  3398. $.fn.DataTable.Criteria = Criteria;
  3399. var apiRegister = $.fn.dataTable.Api.register;
  3400. // Set up object for plugins
  3401. $.fn.dataTable.ext.searchBuilder = {
  3402. conditions: {}
  3403. };
  3404. $.fn.dataTable.ext.buttons.searchBuilder = {
  3405. action: function (e, dt, node, config) {
  3406. e.stopPropagation();
  3407. this.popover(config._searchBuilder.getNode(), {
  3408. align: 'dt-container'
  3409. });
  3410. // Need to redraw the contents to calculate the correct positions for the elements
  3411. if (config._searchBuilder.s.topGroup !== undefined) {
  3412. config._searchBuilder.s.topGroup.dom.container.trigger('dtsb-redrawContents');
  3413. }
  3414. },
  3415. config: {},
  3416. init: function (dt, node, config) {
  3417. var sb = new $.fn.dataTable.SearchBuilder(dt, $.extend({
  3418. filterChanged: function (count, text) {
  3419. dt.button(node).text(text);
  3420. }
  3421. }, config.config));
  3422. dt.button(node).text(config.text || dt.i18n('searchBuilder.button', sb.c.i18n.button, 0));
  3423. config._searchBuilder = sb;
  3424. },
  3425. text: null
  3426. };
  3427. apiRegister('searchBuilder.getDetails()', function () {
  3428. var ctx = this.context[0];
  3429. // If SearchBuilder has not been initialised on this instance then return
  3430. return ctx._searchBuilder ?
  3431. ctx._searchBuilder.getDetails() :
  3432. null;
  3433. });
  3434. apiRegister('searchBuilder.rebuild()', function (details) {
  3435. var ctx = this.context[0];
  3436. // If SearchBuilder has not been initialised on this instance then return
  3437. if (ctx._searchBuilder === undefined) {
  3438. return null;
  3439. }
  3440. ctx._searchBuilder.rebuild(details);
  3441. return this;
  3442. });
  3443. apiRegister('searchBuilder.container()', function () {
  3444. var ctx = this.context[0];
  3445. // If SearchBuilder has not been initialised on this instance then return
  3446. return ctx._searchBuilder ?
  3447. ctx._searchBuilder.getNode() :
  3448. null;
  3449. });
  3450. /**
  3451. * Init function for SearchBuilder
  3452. *
  3453. * @param settings the settings to be applied
  3454. * @param options the options for SearchBuilder
  3455. * @returns JQUERY<HTMLElement> Returns the node of the SearchBuilder
  3456. */
  3457. function _init(settings, options) {
  3458. var api = new dataTable.Api(settings);
  3459. var opts = options
  3460. ? options
  3461. : api.init().searchBuilder || dataTable.defaults.searchBuilder;
  3462. var searchBuilder = new SearchBuilder(api, opts);
  3463. var node = searchBuilder.getNode();
  3464. return node;
  3465. }
  3466. // Attach a listener to the document which listens for DataTables initialisation
  3467. // events so we can automatically initialise
  3468. $(document).on('preInit.dt.dtsp', function (e, settings, json) {
  3469. if (e.namespace !== 'dt') {
  3470. return;
  3471. }
  3472. if (settings.oInit.searchBuilder ||
  3473. dataTable.defaults.searchBuilder) {
  3474. if (!settings._searchBuilder) {
  3475. _init(settings);
  3476. }
  3477. }
  3478. });
  3479. // DataTables `dom` feature option
  3480. dataTable.ext.feature.push({
  3481. cFeature: 'Q',
  3482. fnInit: _init
  3483. });
  3484. // DataTables 2 layout feature
  3485. if (dataTable.ext.features) {
  3486. dataTable.ext.features.register('searchBuilder', _init);
  3487. }
  3488. }));
  3489. }());