dataTables.searchBuilder.js 157 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376
  1. (function () {
  2. 'use strict';
  3. /*! DateTime picker for DataTables.net v1.0.1
  4. *
  5. * ©2020 SpryMedia Ltd, all rights reserved.
  6. * License: MIT datatables.net/license/mit
  7. */
  8. /**
  9. * @summary DateTime picker for DataTables.net
  10. * @version 1.0.1
  11. * @file dataTables.dateTime.js
  12. * @author SpryMedia Ltd
  13. * @contact www.datatables.net/contact
  14. */
  15. (function( factory ){
  16. if ( typeof define === 'function' && define.amd ) {
  17. // AMD
  18. define( ['jquery'], function ( $ ) {
  19. return factory( $, window, document );
  20. } );
  21. }
  22. else if ( typeof exports === 'object' ) {
  23. // CommonJS
  24. module.exports = function (root, $) {
  25. if ( ! root ) {
  26. root = window;
  27. }
  28. return factory( $, root, root.document );
  29. };
  30. }
  31. else {
  32. // Browser
  33. factory( jQuery, window, document );
  34. }
  35. }(function( $, window, document, undefined$1 ) {
  36. // Support libraries which support a Moment like API
  37. var dateLib = window.moment
  38. ? window.moment
  39. : window.dayjs
  40. ? window.dayjs
  41. : null;
  42. /*
  43. * This file provides a DateTime GUI picker (calendar and time input). Only the
  44. * format YYYY-MM-DD is supported without additional software, but the end user
  45. * experience can be greatly enhanced by including the momentjs or dayjs library
  46. * which provide date / time parsing and formatting options.
  47. *
  48. * This functionality is required because the HTML5 date and datetime input
  49. * types are not widely supported in desktop browsers.
  50. *
  51. * Constructed by using:
  52. *
  53. * new DateTime( input, opts )
  54. *
  55. * where `input` is the HTML input element to use and `opts` is an object of
  56. * options based on the `DateTime.defaults` object.
  57. */
  58. var DateTime = function ( input, opts ) {
  59. this.c = $.extend( true, {}, DateTime.defaults, opts );
  60. var classPrefix = this.c.classPrefix;
  61. var i18n = this.c.i18n;
  62. // Only IS8601 dates are supported without moment pr dayjs
  63. if ( ! dateLib && this.c.format !== 'YYYY-MM-DD' ) {
  64. throw "DateTime: Without momentjs or dayjs only the format 'YYYY-MM-DD' can be used";
  65. }
  66. // Min and max need to be `Date` objects in the config
  67. if (typeof this.c.minDate === 'string') {
  68. this.c.minDate = new Date(this.c.minDate);
  69. }
  70. if (typeof this.c.maxDate === 'string') {
  71. this.c.maxDate = new Date(this.c.maxDate);
  72. }
  73. // DOM structure
  74. var structure = $(
  75. '<div class="'+classPrefix+'">'+
  76. '<div class="'+classPrefix+'-date">'+
  77. '<div class="'+classPrefix+'-title">'+
  78. '<div class="'+classPrefix+'-iconLeft">'+
  79. '<button>'+i18n.previous+'</button>'+
  80. '</div>'+
  81. '<div class="'+classPrefix+'-iconRight">'+
  82. '<button>'+i18n.next+'</button>'+
  83. '</div>'+
  84. '<div class="'+classPrefix+'-label">'+
  85. '<span></span>'+
  86. '<select class="'+classPrefix+'-month"></select>'+
  87. '</div>'+
  88. '<div class="'+classPrefix+'-label">'+
  89. '<span></span>'+
  90. '<select class="'+classPrefix+'-year"></select>'+
  91. '</div>'+
  92. '</div>'+
  93. '<div class="'+classPrefix+'-calendar"></div>'+
  94. '</div>'+
  95. '<div class="'+classPrefix+'-time">'+
  96. '<div class="'+classPrefix+'-hours"></div>'+
  97. '<div class="'+classPrefix+'-minutes"></div>'+
  98. '<div class="'+classPrefix+'-seconds"></div>'+
  99. '</div>'+
  100. '<div class="'+classPrefix+'-error"></div>'+
  101. '</div>'
  102. );
  103. this.dom = {
  104. container: structure,
  105. date: structure.find( '.'+classPrefix+'-date' ),
  106. title: structure.find( '.'+classPrefix+'-title' ),
  107. calendar: structure.find( '.'+classPrefix+'-calendar' ),
  108. time: structure.find( '.'+classPrefix+'-time' ),
  109. error: structure.find( '.'+classPrefix+'-error' ),
  110. input: $(input)
  111. };
  112. this.s = {
  113. /** @type {Date} Date value that the picker has currently selected */
  114. d: null,
  115. /** @type {Date} Date of the calendar - might not match the value */
  116. display: null,
  117. /** @type {number} Used to select minutes in a range where the range base is itself unavailable */
  118. minutesRange: null,
  119. /** @type {number} Used to select minutes in a range where the range base is itself unavailable */
  120. secondsRange: null,
  121. /** @type {String} Unique namespace string for this instance */
  122. namespace: 'dateime-'+(DateTime._instance++),
  123. /** @type {Object} Parts of the picker that should be shown */
  124. parts: {
  125. date: this.c.format.match( /[YMD]|L(?!T)|l/ ) !== null,
  126. time: this.c.format.match( /[Hhm]|LT|LTS/ ) !== null,
  127. seconds: this.c.format.indexOf( 's' ) !== -1,
  128. hours12: this.c.format.match( /[haA]/ ) !== null
  129. }
  130. };
  131. this.dom.container
  132. .append( this.dom.date )
  133. .append( this.dom.time )
  134. .append( this.dom.error );
  135. this.dom.date
  136. .append( this.dom.title )
  137. .append( this.dom.calendar );
  138. this._constructor();
  139. };
  140. $.extend( DateTime.prototype, {
  141. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  142. * Public
  143. */
  144. /**
  145. * Destroy the control
  146. */
  147. destroy: function () {
  148. this._hide(true);
  149. this.dom.container.off().empty();
  150. this.dom.input.off('.datetime');
  151. },
  152. errorMsg: function ( msg ) {
  153. var error = this.dom.error;
  154. if ( msg ) {
  155. error.html( msg );
  156. }
  157. else {
  158. error.empty();
  159. }
  160. return this;
  161. },
  162. hide: function () {
  163. this._hide();
  164. return this;
  165. },
  166. max: function ( date ) {
  167. this.c.maxDate = typeof date === 'string'
  168. ? new Date(date)
  169. : date;
  170. this._optionsTitle();
  171. this._setCalander();
  172. return this;
  173. },
  174. min: function ( date ) {
  175. this.c.minDate = typeof date === 'string'
  176. ? new Date(date)
  177. : date;
  178. this._optionsTitle();
  179. this._setCalander();
  180. return this;
  181. },
  182. /**
  183. * Check if an element belongs to this control
  184. *
  185. * @param {node} node Element to check
  186. * @return {boolean} true if owned by this control, false otherwise
  187. */
  188. owns: function ( node ) {
  189. return $(node).parents().filter( this.dom.container ).length > 0;
  190. },
  191. /**
  192. * Get / set the value
  193. *
  194. * @param {string|Date} set Value to set
  195. * @param {boolean} [write=true] Flag to indicate if the formatted value
  196. * should be written into the input element
  197. */
  198. val: function ( set, write ) {
  199. if ( set === undefined$1 ) {
  200. return this.s.d;
  201. }
  202. if ( set instanceof Date ) {
  203. this.s.d = this._dateToUtc( set );
  204. }
  205. else if ( set === null || set === '' ) {
  206. this.s.d = null;
  207. }
  208. else if ( set === '--now' ) {
  209. this.s.d = new Date();
  210. }
  211. else if ( typeof set === 'string' ) {
  212. if ( dateLib ) {
  213. // Use moment or dayjs if possible (even for ISO8601 strings, since it
  214. // will correctly handle 0000-00-00 and the like)
  215. var m = dateLib.utc( set, this.c.format, this.c.locale, this.c.strict );
  216. this.s.d = m.isValid() ? m.toDate() : null;
  217. }
  218. else {
  219. // Else must be using ISO8601 without a date library (constructor would
  220. // have thrown an error otherwise)
  221. var match = set.match(/(\d{4})\-(\d{2})\-(\d{2})/ );
  222. this.s.d = match ?
  223. new Date( Date.UTC(match[1], match[2]-1, match[3]) ) :
  224. null;
  225. }
  226. }
  227. if ( write || write === undefined$1 ) {
  228. if ( this.s.d ) {
  229. this._writeOutput();
  230. }
  231. else {
  232. // The input value was not valid...
  233. this.dom.input.val( set );
  234. }
  235. }
  236. // We need a date to be able to display the calendar at all
  237. if ( ! this.s.d ) {
  238. this.s.d = this._dateToUtc( new Date() );
  239. }
  240. this.s.display = new Date( this.s.d.toString() );
  241. // Set the day of the month to be 1 so changing between months doesn't
  242. // run into issues when going from day 31 to 28 (for example)
  243. this.s.display.setUTCDate( 1 );
  244. // Update the display elements for the new value
  245. this._setTitle();
  246. this._setCalander();
  247. this._setTime();
  248. return this;
  249. },
  250. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  251. * Constructor
  252. */
  253. /**
  254. * Build the control and assign initial event handlers
  255. *
  256. * @private
  257. */
  258. _constructor: function () {
  259. var that = this;
  260. var classPrefix = this.c.classPrefix;
  261. var onChange = function () {
  262. that.c.onChange.call( that, that.dom.input.val(), that.s.d, that.dom.input );
  263. };
  264. if ( ! this.s.parts.date ) {
  265. this.dom.date.css( 'display', 'none' );
  266. }
  267. if ( ! this.s.parts.time ) {
  268. this.dom.time.css( 'display', 'none' );
  269. }
  270. if ( ! this.s.parts.seconds ) {
  271. this.dom.time.children('div.'+classPrefix+'-seconds').remove();
  272. this.dom.time.children('span').eq(1).remove();
  273. }
  274. // Render the options
  275. this._optionsTitle();
  276. window.allan = this;
  277. // When attached to a hidden input, we always show the input picker, and
  278. // do so inline
  279. if (this.dom.input.attr('type') === 'hidden') {
  280. this.dom.container.addClass('inline');
  281. this.c.attachTo = 'input';
  282. this.val( this.dom.input.val(), false );
  283. this._show();
  284. }
  285. // Trigger the display of the widget when clicking or focusing on the
  286. // input element
  287. this.dom.input
  288. .attr('autocomplete', 'off')
  289. .on('focus.datetime click.datetime', function () {
  290. // If already visible - don't do anything
  291. if ( that.dom.container.is(':visible') || that.dom.input.is(':disabled') ) {
  292. return;
  293. }
  294. // In case the value has changed by text
  295. that.val( that.dom.input.val(), false );
  296. that._show();
  297. } )
  298. .on('keyup.datetime', function () {
  299. // Update the calendar's displayed value as the user types
  300. if ( that.dom.container.is(':visible') ) {
  301. that.val( that.dom.input.val(), false );
  302. }
  303. } );
  304. // Main event handlers for input in the widget
  305. this.dom.container
  306. .on( 'change', 'select', function () {
  307. var select = $(this);
  308. var val = select.val();
  309. if ( select.hasClass(classPrefix+'-month') ) {
  310. // Month select
  311. that._correctMonth( that.s.display, val );
  312. that._setTitle();
  313. that._setCalander();
  314. }
  315. else if ( select.hasClass(classPrefix+'-year') ) {
  316. // Year select
  317. that.s.display.setUTCFullYear( val );
  318. that._setTitle();
  319. that._setCalander();
  320. }
  321. else if ( select.hasClass(classPrefix+'-hours') || select.hasClass(classPrefix+'-ampm') ) {
  322. // Hours - need to take account of AM/PM input if present
  323. if ( that.s.parts.hours12 ) {
  324. var hours = $(that.dom.container).find('.'+classPrefix+'-hours').val() * 1;
  325. var pm = $(that.dom.container).find('.'+classPrefix+'-ampm').val() === 'pm';
  326. that.s.d.setUTCHours( hours === 12 && !pm ?
  327. 0 :
  328. pm && hours !== 12 ?
  329. hours + 12 :
  330. hours
  331. );
  332. }
  333. else {
  334. that.s.d.setUTCHours( val );
  335. }
  336. that._setTime();
  337. that._writeOutput( true );
  338. onChange();
  339. }
  340. else if ( select.hasClass(classPrefix+'-minutes') ) {
  341. // Minutes select
  342. that.s.d.setUTCMinutes( val );
  343. that._setTime();
  344. that._writeOutput( true );
  345. onChange();
  346. }
  347. else if ( select.hasClass(classPrefix+'-seconds') ) {
  348. // Seconds select
  349. that.s.d.setSeconds( val );
  350. that._setTime();
  351. that._writeOutput( true );
  352. onChange();
  353. }
  354. that.dom.input.focus();
  355. that._position();
  356. } )
  357. .on( 'click', function (e) {
  358. var d = that.s.d;
  359. var nodeName = e.target.nodeName.toLowerCase();
  360. var target = nodeName === 'span' ?
  361. e.target.parentNode :
  362. e.target;
  363. nodeName = target.nodeName.toLowerCase();
  364. if ( nodeName === 'select' ) {
  365. return;
  366. }
  367. e.stopPropagation();
  368. if ( nodeName === 'button' ) {
  369. var button = $(target);
  370. var parent = button.parent();
  371. if ( parent.hasClass('disabled') && ! parent.hasClass('range') ) {
  372. button.blur();
  373. return;
  374. }
  375. if ( parent.hasClass(classPrefix+'-iconLeft') ) {
  376. // Previous month
  377. that.s.display.setUTCMonth( that.s.display.getUTCMonth()-1 );
  378. that._setTitle();
  379. that._setCalander();
  380. that.dom.input.focus();
  381. }
  382. else if ( parent.hasClass(classPrefix+'-iconRight') ) {
  383. // Next month
  384. that._correctMonth( that.s.display, that.s.display.getUTCMonth()+1 );
  385. that._setTitle();
  386. that._setCalander();
  387. that.dom.input.focus();
  388. }
  389. else if ( button.parents('.'+classPrefix+'-time').length ) {
  390. var val = button.data('value');
  391. var unit = button.data('unit');
  392. if ( unit === 'minutes' ) {
  393. if ( parent.hasClass('disabled') && parent.hasClass('range') ) {
  394. that.s.minutesRange = val;
  395. that._setTime();
  396. return;
  397. }
  398. else {
  399. that.s.minutesRange = null;
  400. }
  401. }
  402. if ( unit === 'seconds' ) {
  403. if ( parent.hasClass('disabled') && parent.hasClass('range') ) {
  404. that.s.secondsRange = val;
  405. that._setTime();
  406. return;
  407. }
  408. else {
  409. that.s.secondsRange = null;
  410. }
  411. }
  412. // Specific to hours for 12h clock
  413. if ( val === 'am' ) {
  414. if ( d.getUTCHours() >= 12 ) {
  415. val = d.getUTCHours() - 12;
  416. }
  417. else {
  418. return;
  419. }
  420. }
  421. else if ( val === 'pm' ) {
  422. if ( d.getUTCHours() < 12 ) {
  423. val = d.getUTCHours() + 12;
  424. }
  425. else {
  426. return;
  427. }
  428. }
  429. var set = unit === 'hours' ?
  430. 'setUTCHours' :
  431. unit === 'minutes' ?
  432. 'setUTCMinutes' :
  433. 'setSeconds';
  434. d[set]( val );
  435. that._setTime();
  436. that._writeOutput( true );
  437. onChange();
  438. }
  439. else {
  440. // Calendar click
  441. if ( ! d ) {
  442. d = that._dateToUtc( new Date() );
  443. }
  444. // Can't be certain that the current day will exist in
  445. // the new month, and likewise don't know that the
  446. // new day will exist in the old month, But 1 always
  447. // does, so we can change the month without worry of a
  448. // recalculation being done automatically by `Date`
  449. d.setUTCDate( 1 );
  450. d.setUTCFullYear( button.data('year') );
  451. d.setUTCMonth( button.data('month') );
  452. d.setUTCDate( button.data('day') );
  453. that._writeOutput( true );
  454. // Don't hide if there is a time picker, since we want to
  455. // be able to select a time as well.
  456. if ( ! that.s.parts.time ) {
  457. // This is annoying but IE has some kind of async
  458. // behaviour with focus and the focus from the above
  459. // write would occur after this hide - resulting in the
  460. // calendar opening immediately
  461. setTimeout( function () {
  462. that._hide();
  463. }, 10 );
  464. }
  465. else {
  466. that._setCalander();
  467. }
  468. onChange();
  469. }
  470. }
  471. else {
  472. // Click anywhere else in the widget - return focus to the
  473. // input element
  474. that.dom.input.focus();
  475. }
  476. } );
  477. },
  478. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  479. * Private
  480. */
  481. /**
  482. * Compare the date part only of two dates - this is made super easy by the
  483. * toDateString method!
  484. *
  485. * @param {Date} a Date 1
  486. * @param {Date} b Date 2
  487. * @private
  488. */
  489. _compareDates: function( a, b ) {
  490. // Can't use toDateString as that converts to local time
  491. return this._dateToUtcString(a) === this._dateToUtcString(b);
  492. },
  493. /**
  494. * When changing month, take account of the fact that some months don't have
  495. * the same number of days. For example going from January to February you
  496. * can have the 31st of Jan selected and just add a month since the date
  497. * would still be 31, and thus drop you into March.
  498. *
  499. * @param {Date} date Date - will be modified
  500. * @param {integer} month Month to set
  501. * @private
  502. */
  503. _correctMonth: function ( date, month ) {
  504. var days = this._daysInMonth( date.getUTCFullYear(), month );
  505. var correctDays = date.getUTCDate() > days;
  506. date.setUTCMonth( month );
  507. if ( correctDays ) {
  508. date.setUTCDate( days );
  509. date.setUTCMonth( month );
  510. }
  511. },
  512. /**
  513. * Get the number of days in a method. Based on
  514. * http://stackoverflow.com/a/4881951 by Matti Virkkunen
  515. *
  516. * @param {integer} year Year
  517. * @param {integer} month Month (starting at 0)
  518. * @private
  519. */
  520. _daysInMonth: function ( year, month ) {
  521. //
  522. var isLeap = ((year % 4) === 0 && ((year % 100) !== 0 || (year % 400) === 0));
  523. var months = [31, (isLeap ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  524. return months[month];
  525. },
  526. /**
  527. * Create a new date object which has the UTC values set to the local time.
  528. * This allows the local time to be used directly for the library which
  529. * always bases its calculations and display on UTC.
  530. *
  531. * @param {Date} s Date to "convert"
  532. * @return {Date} Shifted date
  533. */
  534. _dateToUtc: function ( s ) {
  535. return new Date( Date.UTC(
  536. s.getFullYear(), s.getMonth(), s.getDate(),
  537. s.getHours(), s.getMinutes(), s.getSeconds()
  538. ) );
  539. },
  540. /**
  541. * Create a UTC ISO8601 date part from a date object
  542. *
  543. * @param {Date} d Date to "convert"
  544. * @return {string} ISO formatted date
  545. */
  546. _dateToUtcString: function ( d ) {
  547. return d.getUTCFullYear()+'-'+
  548. this._pad(d.getUTCMonth()+1)+'-'+
  549. this._pad(d.getUTCDate());
  550. },
  551. /**
  552. * Hide the control and remove events related to its display
  553. *
  554. * @private
  555. */
  556. _hide: function (destroy) {
  557. if (! destroy && this.dom.input.attr('type') === 'hidden') {
  558. return;
  559. }
  560. var namespace = this.s.namespace;
  561. this.dom.container.detach();
  562. $(window).off( '.'+namespace );
  563. $(document).off( 'keydown.'+namespace );
  564. $('div.dataTables_scrollBody').off( 'scroll.'+namespace );
  565. $('div.DTE_Body_Content').off( 'scroll.'+namespace );
  566. $('body').off( 'click.'+namespace );
  567. },
  568. /**
  569. * Convert a 24 hour value to a 12 hour value
  570. *
  571. * @param {integer} val 24 hour value
  572. * @return {integer} 12 hour value
  573. * @private
  574. */
  575. _hours24To12: function ( val ) {
  576. return val === 0 ?
  577. 12 :
  578. val > 12 ?
  579. val - 12 :
  580. val;
  581. },
  582. /**
  583. * Generate the HTML for a single day in the calendar - this is basically
  584. * and HTML cell with a button that has data attributes so we know what was
  585. * clicked on (if it is clicked on) and a bunch of classes for styling.
  586. *
  587. * @param {object} day Day object from the `_htmlMonth` method
  588. * @return {string} HTML cell
  589. */
  590. _htmlDay: function( day )
  591. {
  592. if ( day.empty ) {
  593. return '<td class="empty"></td>';
  594. }
  595. var classes = [ 'selectable' ];
  596. var classPrefix = this.c.classPrefix;
  597. if ( day.disabled ) {
  598. classes.push( 'disabled' );
  599. }
  600. if ( day.today ) {
  601. classes.push( 'now' );
  602. }
  603. if ( day.selected ) {
  604. classes.push( 'selected' );
  605. }
  606. return '<td data-day="' + day.day + '" class="' + classes.join(' ') + '">' +
  607. '<button class="'+classPrefix+'-button '+classPrefix+'-day" type="button" ' +'data-year="' + day.year + '" data-month="' + day.month + '" data-day="' + day.day + '">' +
  608. '<span>'+day.day+'</span>'+
  609. '</button>' +
  610. '</td>';
  611. },
  612. /**
  613. * Create the HTML for a month to be displayed in the calendar table.
  614. *
  615. * Based upon the logic used in Pikaday - MIT licensed
  616. * Copyright (c) 2014 David Bushell
  617. * https://github.com/dbushell/Pikaday
  618. *
  619. * @param {integer} year Year
  620. * @param {integer} month Month (starting at 0)
  621. * @return {string} Calendar month HTML
  622. * @private
  623. */
  624. _htmlMonth: function ( year, month ) {
  625. var now = this._dateToUtc( new Date() ),
  626. days = this._daysInMonth( year, month ),
  627. before = new Date( Date.UTC(year, month, 1) ).getUTCDay(),
  628. data = [],
  629. row = [];
  630. if ( this.c.firstDay > 0 ) {
  631. before -= this.c.firstDay;
  632. if (before < 0) {
  633. before += 7;
  634. }
  635. }
  636. var cells = days + before,
  637. after = cells;
  638. while ( after > 7 ) {
  639. after -= 7;
  640. }
  641. cells += 7 - after;
  642. var minDate = this.c.minDate;
  643. var maxDate = this.c.maxDate;
  644. if ( minDate ) {
  645. minDate.setUTCHours(0);
  646. minDate.setUTCMinutes(0);
  647. minDate.setSeconds(0);
  648. }
  649. if ( maxDate ) {
  650. maxDate.setUTCHours(23);
  651. maxDate.setUTCMinutes(59);
  652. maxDate.setSeconds(59);
  653. }
  654. for ( var i=0, r=0 ; i<cells ; i++ ) {
  655. var day = new Date( Date.UTC(year, month, 1 + (i - before)) ),
  656. selected = this.s.d ? this._compareDates(day, this.s.d) : false,
  657. today = this._compareDates(day, now),
  658. empty = i < before || i >= (days + before),
  659. disabled = (minDate && day < minDate) ||
  660. (maxDate && day > maxDate);
  661. var disableDays = this.c.disableDays;
  662. if ( Array.isArray( disableDays ) && $.inArray( day.getUTCDay(), disableDays ) !== -1 ) {
  663. disabled = true;
  664. }
  665. else if ( typeof disableDays === 'function' && disableDays( day ) === true ) {
  666. disabled = true;
  667. }
  668. var dayConfig = {
  669. day: 1 + (i - before),
  670. month: month,
  671. year: year,
  672. selected: selected,
  673. today: today,
  674. disabled: disabled,
  675. empty: empty
  676. };
  677. row.push( this._htmlDay(dayConfig) );
  678. if ( ++r === 7 ) {
  679. if ( this.c.showWeekNumber ) {
  680. row.unshift( this._htmlWeekOfYear(i - before, month, year) );
  681. }
  682. data.push( '<tr>'+row.join('')+'</tr>' );
  683. row = [];
  684. r = 0;
  685. }
  686. }
  687. var classPrefix = this.c.classPrefix;
  688. var className = classPrefix+'-table';
  689. if ( this.c.showWeekNumber ) {
  690. className += ' weekNumber';
  691. }
  692. // Show / hide month icons based on min/max
  693. if ( minDate ) {
  694. var underMin = minDate >= new Date( Date.UTC(year, month, 1, 0, 0, 0 ) );
  695. this.dom.title.find('div.'+classPrefix+'-iconLeft')
  696. .css( 'display', underMin ? 'none' : 'block' );
  697. }
  698. if ( maxDate ) {
  699. var overMax = maxDate < new Date( Date.UTC(year, month+1, 1, 0, 0, 0 ) );
  700. this.dom.title.find('div.'+classPrefix+'-iconRight')
  701. .css( 'display', overMax ? 'none' : 'block' );
  702. }
  703. return '<table class="'+className+'">' +
  704. '<thead>'+
  705. this._htmlMonthHead() +
  706. '</thead>'+
  707. '<tbody>'+
  708. data.join('') +
  709. '</tbody>'+
  710. '</table>';
  711. },
  712. /**
  713. * Create the calendar table's header (week days)
  714. *
  715. * @return {string} HTML cells for the row
  716. * @private
  717. */
  718. _htmlMonthHead: function () {
  719. var a = [];
  720. var firstDay = this.c.firstDay;
  721. var i18n = this.c.i18n;
  722. // Take account of the first day shift
  723. var dayName = function ( day ) {
  724. day += firstDay;
  725. while (day >= 7) {
  726. day -= 7;
  727. }
  728. return i18n.weekdays[day];
  729. };
  730. // Empty cell in the header
  731. if ( this.c.showWeekNumber ) {
  732. a.push( '<th></th>' );
  733. }
  734. for ( var i=0 ; i<7 ; i++ ) {
  735. a.push( '<th>'+dayName( i )+'</th>' );
  736. }
  737. return a.join('');
  738. },
  739. /**
  740. * Create a cell that contains week of the year - ISO8601
  741. *
  742. * Based on https://stackoverflow.com/questions/6117814/ and
  743. * http://techblog.procurios.nl/k/n618/news/view/33796/14863/
  744. *
  745. * @param {integer} d Day of month
  746. * @param {integer} m Month of year (zero index)
  747. * @param {integer} y Year
  748. * @return {string}
  749. * @private
  750. */
  751. _htmlWeekOfYear: function ( d, m, y ) {
  752. var date = new Date( y, m, d, 0, 0, 0, 0 );
  753. // First week of the year always has 4th January in it
  754. date.setDate( date.getDate() + 4 - (date.getDay() || 7) );
  755. var oneJan = new Date( y, 0, 1 );
  756. var weekNum = Math.ceil( ( ( (date - oneJan) / 86400000) + 1)/7 );
  757. return '<td class="'+this.c.classPrefix+'-week">' + weekNum + '</td>';
  758. },
  759. /**
  760. * Create option elements from a range in an array
  761. *
  762. * @param {string} selector Class name unique to the select element to use
  763. * @param {array} values Array of values
  764. * @param {array} [labels] Array of labels. If given must be the same
  765. * length as the values parameter.
  766. * @private
  767. */
  768. _options: function ( selector, values, labels ) {
  769. if ( ! labels ) {
  770. labels = values;
  771. }
  772. var select = this.dom.container.find('select.'+this.c.classPrefix+'-'+selector);
  773. select.empty();
  774. for ( var i=0, ien=values.length ; i<ien ; i++ ) {
  775. select.append( '<option value="'+values[i]+'">'+labels[i]+'</option>' );
  776. }
  777. },
  778. /**
  779. * Set an option and update the option's span pair (since the select element
  780. * has opacity 0 for styling)
  781. *
  782. * @param {string} selector Class name unique to the select element to use
  783. * @param {*} val Value to set
  784. * @private
  785. */
  786. _optionSet: function ( selector, val ) {
  787. var select = this.dom.container.find('select.'+this.c.classPrefix+'-'+selector);
  788. var span = select.parent().children('span');
  789. select.val( val );
  790. var selected = select.find('option:selected');
  791. span.html( selected.length !== 0 ?
  792. selected.text() :
  793. this.c.i18n.unknown
  794. );
  795. },
  796. /**
  797. * Create time options list.
  798. *
  799. * @param {string} unit Time unit - hours, minutes or seconds
  800. * @param {integer} count Count range - 12, 24 or 60
  801. * @param {integer} val Existing value for this unit
  802. * @param {integer[]} allowed Values allow for selection
  803. * @param {integer} range Override range
  804. * @private
  805. */
  806. _optionsTime: function ( unit, count, val, allowed, range ) {
  807. var classPrefix = this.c.classPrefix;
  808. var container = this.dom.container.find('div.'+classPrefix+'-'+unit);
  809. var i, j;
  810. var render = count === 12 ?
  811. function (i) { return i; } :
  812. this._pad;
  813. var classPrefix = this.c.classPrefix;
  814. var className = classPrefix+'-table';
  815. var i18n = this.c.i18n;
  816. if ( ! container.length ) {
  817. return;
  818. }
  819. var a = '';
  820. var span = 10;
  821. var button = function (value, label, className) {
  822. // Shift the value for PM
  823. if ( count === 12 && typeof value === 'number' ) {
  824. if (val >= 12 ) {
  825. value += 12;
  826. }
  827. if (value == 12) {
  828. value = 0;
  829. }
  830. else if (value == 24) {
  831. value = 12;
  832. }
  833. }
  834. var selected = val === value || (value === 'am' && val < 12) || (value === 'pm' && val >= 12) ?
  835. 'selected' :
  836. '';
  837. if (allowed && $.inArray(value, allowed) === -1) {
  838. selected += ' disabled';
  839. }
  840. if ( className ) {
  841. selected += ' '+className;
  842. }
  843. return '<td class="selectable '+selected+'">' +
  844. '<button class="'+classPrefix+'-button '+classPrefix+'-day" type="button" data-unit="'+unit+'" data-value="'+value+ '">' +
  845. '<span>'+label+'</span>'+
  846. '</button>' +
  847. '</td>';
  848. };
  849. if ( count === 12 ) {
  850. // Hours with AM/PM
  851. a += '<tr>';
  852. for ( i=1 ; i<=6 ; i++ ) {
  853. a += button(i, render(i));
  854. }
  855. a += button('am', i18n.amPm[0]);
  856. a += '</tr>';
  857. a += '<tr>';
  858. for ( i=7 ; i<=12 ; i++ ) {
  859. a += button(i, render(i));
  860. }
  861. a += button('pm', i18n.amPm[1]);
  862. a += '</tr>';
  863. span = 7;
  864. }
  865. else if ( count === 24 ) {
  866. // Hours - 24
  867. var c = 0;
  868. for (j=0 ; j<4 ; j++ ) {
  869. a += '<tr>';
  870. for ( i=0 ; i<6 ; i++ ) {
  871. a += button(c, render(c));
  872. c++;
  873. }
  874. a += '</tr>';
  875. }
  876. span = 6;
  877. }
  878. else {
  879. // Minutes and seconds
  880. a += '<tr>';
  881. for (j=0 ; j<60 ; j+=10 ) {
  882. a += button(j, render(j), 'range');
  883. }
  884. a += '</tr>';
  885. // Slight hack to allow for the different number of columns
  886. a += '</tbody></thead><table class="'+className+' '+className+'-nospace"><tbody>';
  887. var start = range !== null ?
  888. range :
  889. Math.floor( val / 10 )*10;
  890. a += '<tr>';
  891. for (j=start+1 ; j<start+10 ; j++ ) {
  892. a += button(j, render(j));
  893. }
  894. a += '</tr>';
  895. span = 6;
  896. }
  897. container
  898. .empty()
  899. .append(
  900. '<table class="'+className+'">'+
  901. '<thead><tr><th colspan="'+span+'">'+
  902. i18n[unit] +
  903. '</th></tr></thead>'+
  904. '<tbody>'+
  905. a+
  906. '</tbody>'+
  907. '</table>'
  908. );
  909. },
  910. /**
  911. * Create the options for the month and year
  912. *
  913. * @param {integer} year Year
  914. * @param {integer} month Month (starting at 0)
  915. * @private
  916. */
  917. _optionsTitle: function () {
  918. var i18n = this.c.i18n;
  919. var min = this.c.minDate;
  920. var max = this.c.maxDate;
  921. var minYear = min ? min.getFullYear() : null;
  922. var maxYear = max ? max.getFullYear() : null;
  923. var i = minYear !== null ? minYear : new Date().getFullYear() - this.c.yearRange;
  924. var j = maxYear !== null ? maxYear : new Date().getFullYear() + this.c.yearRange;
  925. this._options( 'month', this._range( 0, 11 ), i18n.months );
  926. this._options( 'year', this._range( i, j ) );
  927. },
  928. /**
  929. * Simple two digit pad
  930. *
  931. * @param {integer} i Value that might need padding
  932. * @return {string|integer} Padded value
  933. * @private
  934. */
  935. _pad: function ( i ) {
  936. return i<10 ? '0'+i : i;
  937. },
  938. /**
  939. * Position the calendar to look attached to the input element
  940. * @private
  941. */
  942. _position: function () {
  943. var offset = this.c.attachTo === 'input' ? this.dom.input.position() : this.dom.input.offset();
  944. var container = this.dom.container;
  945. var inputHeight = this.dom.input.outerHeight();
  946. if (container.hasClass('inline')) {
  947. container.insertAfter( this.dom.input );
  948. return;
  949. }
  950. if ( this.s.parts.date && this.s.parts.time && $(window).width() > 550 ) {
  951. container.addClass('horizontal');
  952. }
  953. else {
  954. container.removeClass('horizontal');
  955. }
  956. if(this.c.attachTo === 'input') {
  957. container
  958. .css( {
  959. top: offset.top + inputHeight,
  960. left: offset.left
  961. } )
  962. .insertAfter( this.dom.input );
  963. }
  964. else {
  965. container
  966. .css( {
  967. top: offset.top + inputHeight,
  968. left: offset.left
  969. } )
  970. .appendTo( 'body' );
  971. }
  972. var calHeight = container.outerHeight();
  973. var calWidth = container.outerWidth();
  974. var scrollTop = $(window).scrollTop();
  975. // Correct to the bottom
  976. if ( offset.top + inputHeight + calHeight - scrollTop > $(window).height() ) {
  977. var newTop = offset.top - calHeight;
  978. container.css( 'top', newTop < 0 ? 0 : newTop );
  979. }
  980. // Correct to the right
  981. if ( calWidth + offset.left > $(window).width() ) {
  982. var newLeft = $(window).width() - calWidth;
  983. // Account for elements which are inside a position absolute element
  984. if (this.c.attachTo === 'input') {
  985. newLeft -= $(container).offsetParent().offset().left;
  986. }
  987. container.css( 'left', newLeft < 0 ? 0 : newLeft );
  988. }
  989. },
  990. /**
  991. * Create a simple array with a range of values
  992. *
  993. * @param {integer} start Start value (inclusive)
  994. * @param {integer} end End value (inclusive)
  995. * @param {integer} [inc=1] Increment value
  996. * @return {array} Created array
  997. * @private
  998. */
  999. _range: function ( start, end, inc ) {
  1000. var a = [];
  1001. if ( ! inc ) {
  1002. inc = 1;
  1003. }
  1004. for ( var i=start ; i<=end ; i+=inc ) {
  1005. a.push( i );
  1006. }
  1007. return a;
  1008. },
  1009. /**
  1010. * Redraw the calendar based on the display date - this is a destructive
  1011. * operation
  1012. *
  1013. * @private
  1014. */
  1015. _setCalander: function () {
  1016. if ( this.s.display ) {
  1017. this.dom.calendar
  1018. .empty()
  1019. .append( this._htmlMonth(
  1020. this.s.display.getUTCFullYear(),
  1021. this.s.display.getUTCMonth()
  1022. ) );
  1023. }
  1024. },
  1025. /**
  1026. * Set the month and year for the calendar based on the current display date
  1027. *
  1028. * @private
  1029. */
  1030. _setTitle: function () {
  1031. this._optionSet( 'month', this.s.display.getUTCMonth() );
  1032. this._optionSet( 'year', this.s.display.getUTCFullYear() );
  1033. },
  1034. /**
  1035. * Set the time based on the current value of the widget
  1036. *
  1037. * @private
  1038. */
  1039. _setTime: function () {
  1040. var that = this;
  1041. var d = this.s.d;
  1042. var hours = d ? d.getUTCHours() : 0;
  1043. var allowed = function ( prop ) { // Backwards compt with `Increment` option
  1044. return that.c[prop+'Available'] ?
  1045. that.c[prop+'Available'] :
  1046. that._range( 0, 59, that.c[prop+'Increment'] );
  1047. };
  1048. this._optionsTime( 'hours', this.s.parts.hours12 ? 12 : 24, hours, this.c.hoursAvailable );
  1049. this._optionsTime( 'minutes', 60, d ? d.getUTCMinutes() : 0, allowed('minutes'), this.s.minutesRange );
  1050. this._optionsTime( 'seconds', 60, d ? d.getSeconds() : 0, allowed('seconds'), this.s.secondsRange );
  1051. },
  1052. /**
  1053. * Show the widget and add events to the document required only while it
  1054. * is displayed
  1055. *
  1056. * @private
  1057. */
  1058. _show: function () {
  1059. var that = this;
  1060. var namespace = this.s.namespace;
  1061. this._position();
  1062. // Need to reposition on scroll
  1063. $(window).on( 'scroll.'+namespace+' resize.'+namespace, function () {
  1064. that._hide();
  1065. } );
  1066. $('div.DTE_Body_Content').on( 'scroll.'+namespace, function () {
  1067. that._hide();
  1068. } );
  1069. $('div.dataTables_scrollBody').on( 'scroll.'+namespace, function () {
  1070. that._hide();
  1071. } );
  1072. var offsetParent = this.dom.input[0].offsetParent;
  1073. if ( offsetParent !== document.body ) {
  1074. $(offsetParent).on( 'scroll.'+namespace, function () {
  1075. that._hide();
  1076. } );
  1077. }
  1078. // On tab focus will move to a different field (no keyboard navigation
  1079. // in the date picker - this might need to be changed).
  1080. $(document).on( 'keydown.'+namespace, function (e) {
  1081. if (
  1082. e.keyCode === 9 || // tab
  1083. e.keyCode === 27 || // esc
  1084. e.keyCode === 13 // return
  1085. ) {
  1086. that._hide();
  1087. }
  1088. } );
  1089. // Hide if clicking outside of the widget - but in a different click
  1090. // event from the one that was used to trigger the show (bubble and
  1091. // inline)
  1092. setTimeout( function () {
  1093. $('body').on( 'click.'+namespace, function (e) {
  1094. var parents = $(e.target).parents();
  1095. if ( ! parents.filter( that.dom.container ).length && e.target !== that.dom.input[0] ) {
  1096. that._hide();
  1097. }
  1098. } );
  1099. }, 10 );
  1100. },
  1101. /**
  1102. * Write the formatted string to the input element this control is attached
  1103. * to
  1104. *
  1105. * @private
  1106. */
  1107. _writeOutput: function ( focus ) {
  1108. var date = this.s.d;
  1109. // Use moment or dayjs if possible - otherwise it must be ISO8601 (or the
  1110. // constructor would have thrown an error)
  1111. var out = dateLib ?
  1112. dateLib.utc( date, undefined$1, this.c.locale, this.c.strict ).format( this.c.format ) :
  1113. date.getUTCFullYear() +'-'+
  1114. this._pad(date.getUTCMonth() + 1) +'-'+
  1115. this._pad(date.getUTCDate());
  1116. this.dom.input
  1117. .val( out )
  1118. .trigger('change', {write: date});
  1119. if ( this.dom.input.attr('type') === 'hidden' ) {
  1120. this.val(out, false);
  1121. }
  1122. if ( focus ) {
  1123. this.dom.input.focus();
  1124. }
  1125. }
  1126. } );
  1127. /**
  1128. * Use a specificmoment compatible date library
  1129. */
  1130. DateTime.use = function (lib) {
  1131. dateLib = lib;
  1132. };
  1133. /**
  1134. * For generating unique namespaces
  1135. *
  1136. * @type {Number}
  1137. * @private
  1138. */
  1139. DateTime._instance = 0;
  1140. /**
  1141. * Defaults for the date time picker
  1142. *
  1143. * @type {Object}
  1144. */
  1145. DateTime.defaults = {
  1146. attachTo: 'body',
  1147. // Not documented - could be an internal property
  1148. classPrefix: 'dt-datetime',
  1149. // function or array of ints
  1150. disableDays: null,
  1151. // first day of the week (0: Sunday, 1: Monday, etc)
  1152. firstDay: 1,
  1153. format: 'YYYY-MM-DD',
  1154. hoursAvailable: null,
  1155. i18n: {
  1156. previous: 'Previous',
  1157. next: 'Next',
  1158. months: [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ],
  1159. weekdays: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
  1160. amPm: [ 'am', 'pm' ],
  1161. hours: 'Hour',
  1162. minutes: 'Minute',
  1163. seconds: 'Second',
  1164. unknown: '-'
  1165. },
  1166. maxDate: null,
  1167. minDate: null,
  1168. minutesAvailable: null,
  1169. minutesIncrement: 1, // deprecated
  1170. strict: true,
  1171. locale: 'en',
  1172. onChange: function () {},
  1173. secondsAvailable: null,
  1174. secondsIncrement: 1, // deprecated
  1175. // show the ISO week number at the head of the row
  1176. showWeekNumber: false,
  1177. // overruled by max / min date
  1178. yearRange: 25
  1179. };
  1180. DateTime.version = '1.0.1';
  1181. // Global export - if no conflicts
  1182. if (! window.DateTime) {
  1183. window.DateTime = DateTime;
  1184. }
  1185. // Make available via jQuery
  1186. $.fn.dtDateTime = function (options) {
  1187. return this.each(function() {
  1188. new DateTime(this, options);
  1189. });
  1190. };
  1191. // Attach to DataTables if present
  1192. if ($.fn.dataTable) {
  1193. $.fn.dataTable.DateTime = DateTime;
  1194. $.fn.DataTable.DateTime = DateTime;
  1195. }
  1196. return DateTime;
  1197. }));
  1198. var $;
  1199. var DataTable;
  1200. var moment = window.moment;
  1201. /**
  1202. * Sets the value of jQuery for use in the file
  1203. * @param jq the instance of jQuery to be set
  1204. */
  1205. function setJQuery(jq) {
  1206. $ = jq;
  1207. DataTable = jq.fn.dataTable;
  1208. }
  1209. /**
  1210. * The Criteria class is used within SearchBuilder to represent a search criteria
  1211. */
  1212. var Criteria = /** @class */ (function () {
  1213. function Criteria(table, opts, topGroup, index, depth) {
  1214. var _this = this;
  1215. if (index === void 0) { index = 0; }
  1216. if (depth === void 0) { depth = 1; }
  1217. // Check that the required version of DataTables is included
  1218. if (!DataTable || !DataTable.versionCheck || !DataTable.versionCheck('1.10.0')) {
  1219. throw new Error('SearchPane requires DataTables 1.10 or newer');
  1220. }
  1221. this.classes = $.extend(true, {}, Criteria.classes);
  1222. // Get options from user and any extra conditions/column types defined by plug-ins
  1223. this.c = $.extend(true, {}, Criteria.defaults, $.fn.dataTable.ext.searchBuilder, opts);
  1224. var i18n = this.c.i18n;
  1225. this.s = {
  1226. condition: undefined,
  1227. conditions: {},
  1228. data: undefined,
  1229. dataIdx: -1,
  1230. dataPoints: [],
  1231. depth: depth,
  1232. dt: table,
  1233. filled: false,
  1234. index: index,
  1235. momentFormat: false,
  1236. topGroup: topGroup,
  1237. type: '',
  1238. value: []
  1239. };
  1240. this.dom = {
  1241. buttons: $('<div/>')
  1242. .addClass(this.classes.buttonContainer),
  1243. condition: $('<select disabled/>')
  1244. .addClass(this.classes.condition)
  1245. .addClass(this.classes.dropDown)
  1246. .addClass(this.classes.italic)
  1247. .attr('autocomplete', 'hacking'),
  1248. conditionTitle: $('<option value="" disabled selected hidden/>')
  1249. .text(this.s.dt.i18n('searchBuilder.condition', i18n.condition)),
  1250. container: $('<div/>')
  1251. .addClass(this.classes.container),
  1252. data: $('<select/>')
  1253. .addClass(this.classes.data)
  1254. .addClass(this.classes.dropDown)
  1255. .addClass(this.classes.italic),
  1256. dataTitle: $('<option value="" disabled selected hidden/>')
  1257. .text(this.s.dt.i18n('searchBuilder.data', i18n.data)),
  1258. defaultValue: $('<select disabled/>')
  1259. .addClass(this.classes.value)
  1260. .addClass(this.classes.dropDown),
  1261. "delete": $('<button>&times</button>')
  1262. .addClass(this.classes["delete"])
  1263. .addClass(this.classes.button)
  1264. .attr('title', this.s.dt.i18n('searchBuilder.deleteTitle', i18n.deleteTitle))
  1265. .attr('type', 'button'),
  1266. left: $('<button>\<</button>')
  1267. .addClass(this.classes.left)
  1268. .addClass(this.classes.button)
  1269. .attr('title', this.s.dt.i18n('searchBuilder.leftTitle', i18n.leftTitle))
  1270. .attr('type', 'button'),
  1271. right: $('<button>\></button>')
  1272. .addClass(this.classes.right)
  1273. .addClass(this.classes.button)
  1274. .attr('title', this.s.dt.i18n('searchBuilder.rightTitle', i18n.rightTitle))
  1275. .attr('type', 'button'),
  1276. value: [
  1277. $('<select disabled/>').addClass(this.classes.value).addClass(this.classes.dropDown).addClass(this.classes.italic)
  1278. ],
  1279. valueTitle: $('<option value="--valueTitle--" selected/>').text(this.s.dt.i18n('searchBuilder.value', i18n.value))
  1280. };
  1281. // If the greyscale option is selected then add the class to add the grey colour to SearchBuilder
  1282. if (this.c.greyscale) {
  1283. $(this.dom.data).addClass(this.classes.greyscale);
  1284. $(this.dom.condition).addClass(this.classes.greyscale);
  1285. $(this.dom.defaultValue).addClass(this.classes.greyscale);
  1286. for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
  1287. var val = _a[_i];
  1288. $(val).addClass(this.classes.greyscale);
  1289. }
  1290. }
  1291. // For responsive design, adjust the criterias properties on the following events
  1292. this.s.dt.on('draw.dtsp', function () {
  1293. _this._adjustCriteria();
  1294. });
  1295. this.s.dt.on('buttons-action', function () {
  1296. _this._adjustCriteria();
  1297. });
  1298. $(window).on('resize.dtsp', DataTable.util.throttle(function () {
  1299. _this._adjustCriteria();
  1300. }));
  1301. this._buildCriteria();
  1302. return this;
  1303. }
  1304. /**
  1305. * Adds the left button to the criteria
  1306. */
  1307. Criteria.prototype.updateArrows = function (hasSiblings, redraw) {
  1308. if (hasSiblings === void 0) { hasSiblings = false; }
  1309. if (redraw === void 0) { redraw = true; }
  1310. // Empty the container and append all of the elements in the correct order
  1311. $(this.dom.container)
  1312. .empty()
  1313. .append(this.dom.data)
  1314. .append(this.dom.condition)
  1315. .append(this.dom.value[0]);
  1316. // Trigger the inserted events for the value elements as they are inserted
  1317. $(this.dom.value[0]).trigger('dtsb-inserted');
  1318. for (var i = 1; i < this.dom.value.length; i++) {
  1319. $(this.dom.container).append(this.dom.value[i]);
  1320. $(this.dom.value[i]).trigger('dtsb-inserted');
  1321. }
  1322. // If this is a top level criteria then don't let it move left
  1323. if (this.s.depth > 1) {
  1324. $(this.dom.buttons).append(this.dom.left);
  1325. }
  1326. // If the depthLimit of the query has been hit then don't add the right button
  1327. if ((this.c.depthLimit === false || this.s.depth < this.c.depthLimit) && hasSiblings) {
  1328. $(this.dom.buttons).append(this.dom.right);
  1329. }
  1330. else {
  1331. $(this.dom.right).remove();
  1332. }
  1333. $(this.dom.buttons).append(this.dom["delete"]);
  1334. $(this.dom.container).append(this.dom.buttons);
  1335. if (redraw) {
  1336. // A different combination of arrows and selectors may lead to a need for responsive to be triggered
  1337. this._adjustCriteria();
  1338. }
  1339. };
  1340. /**
  1341. * Destroys the criteria, removing listeners and container from the dom
  1342. */
  1343. Criteria.prototype.destroy = function () {
  1344. // Turn off listeners
  1345. $(this.dom.data).off('.dtsb');
  1346. $(this.dom.condition).off('.dtsb');
  1347. $(this.dom["delete"]).off('.dtsb');
  1348. for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
  1349. var val = _a[_i];
  1350. $(val).off('.dtsb');
  1351. }
  1352. // Remove container from the dom
  1353. $(this.dom.container).remove();
  1354. };
  1355. /**
  1356. * Passes in the data for the row and compares it against this single criteria
  1357. * @param rowData The data for the row to be compared
  1358. * @returns boolean Whether the criteria has passed
  1359. */
  1360. Criteria.prototype.search = function (rowData, rowIdx) {
  1361. var condition = this.s.conditions[this.s.condition];
  1362. if (this.s.condition !== undefined && condition !== undefined) {
  1363. // This check is in place for if a custom decimal character is in place
  1364. if (this.s.type.indexOf('num') !== -1 && this.s.dt.settings()[0].oLanguage.sDecimal !== '') {
  1365. rowData[this.s.dataIdx] = rowData[this.s.dataIdx].replace(this.s.dt.settings()[0].oLanguage.sDecimal, '.');
  1366. }
  1367. var filter = rowData[this.s.dataIdx];
  1368. // If orthogonal data is in place we need to get it's values for searching
  1369. if (this.c.orthogonal.search !== 'search') {
  1370. var settings = this.s.dt.settings()[0];
  1371. filter = settings.oApi._fnGetCellData(settings, rowIdx, this.s.dataIdx, typeof this.c.orthogonal === 'string' ?
  1372. this.c.orthogonal :
  1373. this.c.orthogonal.search);
  1374. }
  1375. if (this.s.type === 'array') {
  1376. // Make sure we are working with an array
  1377. if (!Array.isArray(filter)) {
  1378. filter = [filter];
  1379. }
  1380. filter.sort();
  1381. }
  1382. return condition.search(filter, this.s.value, this);
  1383. }
  1384. };
  1385. /**
  1386. * Gets the details required to rebuild the criteria
  1387. */
  1388. Criteria.prototype.getDetails = function () {
  1389. var value = this.s.value;
  1390. // This check is in place for if a custom decimal character is in place
  1391. if (this.s.type.indexOf('num') !== -1 && this.s.dt.settings()[0].oLanguage.sDecimal !== '') {
  1392. for (var i = 0; i < this.s.value.length; i++) {
  1393. if (this.s.value[i].indexOf('.') !== -1) {
  1394. value[i] = this.s.value[i].replace('.', this.s.dt.settings()[0].oLanguage.sDecimal);
  1395. }
  1396. }
  1397. }
  1398. return {
  1399. condition: this.s.condition,
  1400. data: this.s.data,
  1401. value: value
  1402. };
  1403. };
  1404. /**
  1405. * Getter for the node for the container of the criteria
  1406. * @returns JQuery<HTMLElement> the node for the container
  1407. */
  1408. Criteria.prototype.getNode = function () {
  1409. return this.dom.container;
  1410. };
  1411. /**
  1412. * Populates the criteria data, condition and value(s) as far as has been selected
  1413. */
  1414. Criteria.prototype.populate = function () {
  1415. this._populateData();
  1416. // If the column index has been found attempt to select a condition
  1417. if (this.s.dataIdx !== -1) {
  1418. this._populateCondition();
  1419. // If the condittion has been found attempt to select the values
  1420. if (this.s.condition !== undefined) {
  1421. this._populateValue();
  1422. }
  1423. }
  1424. };
  1425. /**
  1426. * Rebuilds the criteria based upon the details passed in
  1427. * @param loadedCriteria the details required to rebuild the criteria
  1428. */
  1429. Criteria.prototype.rebuild = function (loadedCriteria) {
  1430. // Check to see if the previously selected data exists, if so select it
  1431. var foundData = false;
  1432. var dataIdx;
  1433. this._populateData();
  1434. // If a data selection has previously been made attempt to find and select it
  1435. if (loadedCriteria.data !== undefined) {
  1436. var italic_1 = this.classes.italic;
  1437. var data_1 = this.dom.data;
  1438. $(this.dom.data).children('option').each(function () {
  1439. if ($(this).text() === loadedCriteria.data) {
  1440. $(this).attr('selected', true);
  1441. $(data_1).removeClass(italic_1);
  1442. foundData = true;
  1443. dataIdx = $(this).val();
  1444. }
  1445. });
  1446. }
  1447. // If the data has been found and selected then the condition can be populated and searched
  1448. if (foundData) {
  1449. this.s.data = loadedCriteria.data;
  1450. this.s.dataIdx = dataIdx;
  1451. $(this.dom.dataTitle).remove();
  1452. this._populateCondition();
  1453. $(this.dom.conditionTitle).remove();
  1454. var condition_1;
  1455. // Check to see if the previously selected condition exists, if so select it
  1456. $(this.dom.condition).children('option').each(function () {
  1457. if ((loadedCriteria.condition !== undefined &&
  1458. $(this).val() === loadedCriteria.condition &&
  1459. typeof loadedCriteria.condition === 'string')) {
  1460. $(this).attr('selected', true);
  1461. condition_1 = $(this).val();
  1462. }
  1463. });
  1464. this.s.condition = condition_1;
  1465. // If the condition has been found and selected then the value can be populated and searched
  1466. if (this.s.condition !== undefined) {
  1467. $(this.dom.conditionTitle).remove();
  1468. $(this.dom.condition).removeClass(this.classes.italic);
  1469. this._populateValue(loadedCriteria);
  1470. }
  1471. else {
  1472. $(this.dom.conditionTitle).prependTo(this.dom.condition).attr('selected', true);
  1473. }
  1474. }
  1475. };
  1476. /**
  1477. * Sets the listeners for the criteria
  1478. */
  1479. Criteria.prototype.setListeners = function () {
  1480. var _this = this;
  1481. $(this.dom.data)
  1482. .unbind('input change')
  1483. .on('input change', function () {
  1484. $(_this.dom.dataTitle).attr('selected', false);
  1485. $(_this.dom.data).removeClass(_this.classes.italic);
  1486. _this.s.dataIdx = $(_this.dom.data).children('option:selected').val();
  1487. _this.s.data = $(_this.dom.data).children('option:selected').text();
  1488. _this.c.orthogonal = _this._getOptions().orthogonal;
  1489. // When the data is changed, the values in condition and value may also change so need to renew them
  1490. _this._clearCondition();
  1491. _this._clearValue();
  1492. _this._populateCondition();
  1493. // If this criteria was previously active in the search then remove it from the search and trigger a new search
  1494. if (_this.s.filled) {
  1495. _this.s.filled = false;
  1496. _this.s.dt.draw();
  1497. _this.setListeners();
  1498. }
  1499. _this.s.dt.state.save();
  1500. });
  1501. $(this.dom.condition)
  1502. .unbind('input change')
  1503. .on('input change', function () {
  1504. $(_this.dom.conditionTitle).attr('selected', false);
  1505. $(_this.dom.condition).removeClass(_this.classes.italic);
  1506. var condDisp = $(_this.dom.condition).children('option:selected').val();
  1507. // Find the condition that has been selected and store it internally
  1508. for (var _i = 0, _a = Object.keys(_this.s.conditions); _i < _a.length; _i++) {
  1509. var cond = _a[_i];
  1510. if (cond === condDisp) {
  1511. _this.s.condition = condDisp;
  1512. break;
  1513. }
  1514. }
  1515. // When the condition is changed, the value selector may switch between a select element and an input element
  1516. _this._clearValue();
  1517. _this._populateValue();
  1518. for (var _b = 0, _c = _this.dom.value; _b < _c.length; _b++) {
  1519. var val = _c[_b];
  1520. // If this criteria was previously active in the search then remove it from the search and trigger a new search
  1521. if (_this.s.filled && $(_this.dom.container).has(val).length !== 0) {
  1522. _this.s.filled = false;
  1523. _this.s.dt.draw();
  1524. _this.setListeners();
  1525. }
  1526. }
  1527. _this.s.dt.draw();
  1528. });
  1529. };
  1530. /**
  1531. * Adjusts the criteria to make SearchBuilder responsive
  1532. */
  1533. Criteria.prototype._adjustCriteria = function () {
  1534. // If this criteria is not present then don't bother adjusting it
  1535. if ($(document).has(this.dom.container).length === 0) {
  1536. return;
  1537. }
  1538. var valRight;
  1539. var valWidth;
  1540. var outmostval = this.dom.value[this.dom.value.length - 1];
  1541. // Calculate the width and right value of the outmost value element
  1542. if ($(this.dom.container).has(outmostval).length !== 0) {
  1543. valWidth = $(outmostval).outerWidth(true);
  1544. valRight = $(outmostval).offset().left + valWidth;
  1545. }
  1546. else {
  1547. return;
  1548. }
  1549. var leftOffset = $(this.dom.left).offset();
  1550. var rightOffset = $(this.dom.right).offset();
  1551. var clearOffset = $(this.dom["delete"]).offset();
  1552. var hasLeft = $(this.dom.container).has(this.dom.left).length !== 0;
  1553. var hasRight = $(this.dom.container).has(this.dom.right).length !== 0;
  1554. var buttonsLeft = hasLeft ?
  1555. leftOffset.left :
  1556. hasRight ?
  1557. rightOffset.left :
  1558. clearOffset.left;
  1559. // Perform the responsive calculations and redraw where necessary
  1560. if (buttonsLeft - valRight < 15 ||
  1561. (hasLeft && leftOffset.top !== clearOffset.top) ||
  1562. (hasRight && rightOffset.top !== clearOffset.top)) {
  1563. $(this.dom.container).parent().addClass(this.classes.vertical);
  1564. $(this.s.topGroup).trigger('dtsb-redrawContents');
  1565. }
  1566. else if (buttonsLeft -
  1567. ($(this.dom.data).offset().left +
  1568. $(this.dom.data).outerWidth(true) +
  1569. $(this.dom.condition).outerWidth(true) +
  1570. valWidth) > 15) {
  1571. $(this.dom.container).parent().removeClass(this.classes.vertical);
  1572. $(this.s.topGroup).trigger('dtsb-redrawContents');
  1573. }
  1574. };
  1575. /**
  1576. * Builds the elements of the dom together
  1577. */
  1578. Criteria.prototype._buildCriteria = function () {
  1579. // Append Titles for select elements
  1580. $(this.dom.data).append(this.dom.dataTitle);
  1581. $(this.dom.condition).append(this.dom.conditionTitle);
  1582. // Add elements to container
  1583. $(this.dom.container)
  1584. .append(this.dom.data)
  1585. .append(this.dom.condition);
  1586. for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
  1587. var val = _a[_i];
  1588. $(val).append(this.dom.valueTitle);
  1589. $(this.dom.container).append(val);
  1590. }
  1591. // Add buttons to container
  1592. $(this.dom.container)
  1593. .append(this.dom["delete"])
  1594. .append(this.dom.right);
  1595. this.setListeners();
  1596. };
  1597. /**
  1598. * Clears the condition select element
  1599. */
  1600. Criteria.prototype._clearCondition = function () {
  1601. $(this.dom.condition).empty();
  1602. $(this.dom.conditionTitle).attr('selected', true).attr('disabled', true);
  1603. $(this.dom.condition).prepend(this.dom.conditionTitle).prop('selectedIndex', 0);
  1604. this.s.conditions = {};
  1605. this.s.condition = undefined;
  1606. };
  1607. /**
  1608. * Clears the value elements
  1609. */
  1610. Criteria.prototype._clearValue = function () {
  1611. if (this.s.condition !== undefined) {
  1612. // Remove all of the value elements
  1613. for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
  1614. var val = _a[_i];
  1615. $(val).remove();
  1616. }
  1617. // Call the init function to get the value elements for this condition
  1618. this.dom.value = [].concat(this.s.conditions[this.s.condition].init(this, Criteria.updateListener));
  1619. $(this.dom.value[0]).insertAfter(this.dom.condition).trigger('dtsb-inserted');
  1620. // Insert all of the value elements
  1621. for (var i = 1; i < this.dom.value.length; i++) {
  1622. $(this.dom.value[i]).insertAfter(this.dom.value[i - 1]).trigger('dtsb-inserted');
  1623. }
  1624. }
  1625. else {
  1626. // Remove all of the value elements
  1627. for (var _b = 0, _c = this.dom.value; _b < _c.length; _b++) {
  1628. var val = _c[_b];
  1629. $(val).remove();
  1630. }
  1631. // Append the default valueTitle to the default select element
  1632. $(this.dom.valueTitle)
  1633. .attr('selected', true);
  1634. $(this.dom.defaultValue)
  1635. .append(this.dom.valueTitle)
  1636. .insertAfter(this.dom.condition);
  1637. }
  1638. this.s.value = [];
  1639. };
  1640. /**
  1641. * Gets the options for the column
  1642. * @returns {object} The options for the column
  1643. */
  1644. Criteria.prototype._getOptions = function () {
  1645. var table = this.s.dt;
  1646. return $.extend(true, {}, Criteria.defaults, table.settings()[0].aoColumns[this.s.dataIdx].searchBuilder);
  1647. };
  1648. /**
  1649. * Populates the condition dropdown
  1650. */
  1651. Criteria.prototype._populateCondition = function () {
  1652. var conditionOpts = [];
  1653. var conditionsLength = Object.keys(this.s.conditions).length;
  1654. // If there are no conditions stored then we need to get them from the appropriate type
  1655. if (conditionsLength === 0) {
  1656. var column = $(this.dom.data).children('option:selected').val();
  1657. this.s.type = this.s.dt.columns().type().toArray()[column];
  1658. // If the column type is unknown, call a draw to try reading it again
  1659. if (this.s.type === null) {
  1660. this.s.dt.draw();
  1661. this.setListeners();
  1662. this.s.type = this.s.dt.columns().type().toArray()[column];
  1663. }
  1664. // Enable the condition element
  1665. $(this.dom.condition)
  1666. .attr('disabled', false)
  1667. .empty()
  1668. .append(this.dom.conditionTitle)
  1669. .addClass(this.classes.italic);
  1670. $(this.dom.conditionTitle)
  1671. .attr('selected', true);
  1672. var decimal = this.s.dt.settings()[0].oLanguage.sDecimal;
  1673. // This check is in place for if a custom decimal character is in place
  1674. if (decimal !== '' && this.s.type.indexOf(decimal) === this.s.type.length - decimal.length) {
  1675. if (this.s.type.indexOf('num-fmt') !== -1) {
  1676. this.s.type = this.s.type.replace(decimal, '');
  1677. }
  1678. else if (this.s.type.indexOf('num') !== -1) {
  1679. this.s.type = this.s.type.replace(decimal, '');
  1680. }
  1681. }
  1682. // Select which conditions are going to be used based on the column type
  1683. var conditionObj = this.c.conditions[this.s.type] !== undefined ?
  1684. this.c.conditions[this.s.type] :
  1685. this.s.type.indexOf('moment') !== -1 ?
  1686. this.c.conditions.moment :
  1687. this.c.conditions.string;
  1688. // If it is a moment format then extract the date format
  1689. if (this.s.type.indexOf('moment') !== -1) {
  1690. this.s.momentFormat = this.s.type.replace(/moment\-/g, '');
  1691. }
  1692. // Add all of the conditions to the select element
  1693. for (var _i = 0, _a = Object.keys(conditionObj); _i < _a.length; _i++) {
  1694. var condition = _a[_i];
  1695. if (conditionObj[condition] !== null) {
  1696. this.s.conditions[condition] = conditionObj[condition];
  1697. var condName = conditionObj[condition].conditionName;
  1698. if (typeof condName === 'function') {
  1699. condName = condName(this.s.dt, this.c.i18n);
  1700. }
  1701. conditionOpts.push($('<option>', {
  1702. text: condName,
  1703. value: condition
  1704. })
  1705. .addClass(this.classes.option)
  1706. .addClass(this.classes.notItalic));
  1707. }
  1708. }
  1709. }
  1710. // Otherwise we can just load them in
  1711. else if (conditionsLength > 0) {
  1712. $(this.dom.condition).empty().attr('disabled', false).addClass(this.classes.italic);
  1713. for (var _b = 0, _c = Object.keys(this.s.conditions); _b < _c.length; _b++) {
  1714. var condition = _c[_b];
  1715. var condName = this.s.conditions[condition].conditionName;
  1716. if (typeof condName === 'function') {
  1717. condName = condName(this.s.dt, this.c.i18n);
  1718. }
  1719. var newOpt = $('<option>', {
  1720. text: condName,
  1721. value: condition
  1722. })
  1723. .addClass(this.classes.option)
  1724. .addClass(this.classes.notItalic);
  1725. if (this.s.condition !== undefined && this.s.condition === condName) {
  1726. $(newOpt).attr('selected', true);
  1727. $(this.dom.condition).removeClass(this.classes.italic);
  1728. }
  1729. conditionOpts.push(newOpt);
  1730. }
  1731. }
  1732. else {
  1733. $(this.dom.condition)
  1734. .attr('disabled', true)
  1735. .addClass(this.classes.italic);
  1736. return;
  1737. }
  1738. for (var _d = 0, conditionOpts_1 = conditionOpts; _d < conditionOpts_1.length; _d++) {
  1739. var opt = conditionOpts_1[_d];
  1740. $(this.dom.condition).append(opt);
  1741. }
  1742. $(this.dom.condition).prop('selectedIndex', 0);
  1743. };
  1744. /**
  1745. * Populates the data select element
  1746. */
  1747. Criteria.prototype._populateData = function () {
  1748. var _this = this;
  1749. $(this.dom.data).empty().append(this.dom.dataTitle);
  1750. // If there are no datas stored then we need to get them from the table
  1751. if (this.s.dataPoints.length === 0) {
  1752. this.s.dt.columns().every(function (index) {
  1753. // Need to check that the column can be filtered on before adding it
  1754. if (_this.c.columns === true ||
  1755. (_this.s.dt.columns(_this.c.columns).indexes().toArray().indexOf(index) !== -1)) {
  1756. var found = false;
  1757. for (var _i = 0, _a = _this.s.dataPoints; _i < _a.length; _i++) {
  1758. var val = _a[_i];
  1759. if (val.index === index) {
  1760. found = true;
  1761. break;
  1762. }
  1763. }
  1764. if (!found) {
  1765. var opt = { text: _this.s.dt.settings()[0].aoColumns[index].sTitle, index: index };
  1766. _this.s.dataPoints.push(opt);
  1767. $(_this.dom.data).append($('<option>', {
  1768. text: opt.text,
  1769. value: opt.index
  1770. })
  1771. .addClass(_this.classes.option)
  1772. .addClass(_this.classes.notItalic));
  1773. }
  1774. }
  1775. });
  1776. }
  1777. // Otherwise we can just load them in
  1778. else {
  1779. var _loop_1 = function (data) {
  1780. this_1.s.dt.columns().every(function (index) {
  1781. if (_this.s.dt.settings()[0].aoColumns[index].sTitle === data.text) {
  1782. data.index = index;
  1783. }
  1784. });
  1785. var newOpt = $('<option>', {
  1786. text: data.text,
  1787. value: data.index
  1788. })
  1789. .addClass(this_1.classes.option)
  1790. .addClass(this_1.classes.notItalic);
  1791. if (this_1.s.data === data.text) {
  1792. this_1.s.dataIdx = data.index;
  1793. $(newOpt).attr('selected', true);
  1794. $(this_1.dom.data).removeClass(this_1.classes.italic);
  1795. }
  1796. $(this_1.dom.data).append(newOpt);
  1797. };
  1798. var this_1 = this;
  1799. for (var _i = 0, _a = this.s.dataPoints; _i < _a.length; _i++) {
  1800. var data = _a[_i];
  1801. _loop_1(data);
  1802. }
  1803. }
  1804. };
  1805. /**
  1806. * Populates the Value select element
  1807. * @param loadedCriteria optional, used to reload criteria from predefined filters
  1808. */
  1809. Criteria.prototype._populateValue = function (loadedCriteria) {
  1810. var _this = this;
  1811. var prevFilled = this.s.filled;
  1812. this.s.filled = false;
  1813. // Remove any previous value elements
  1814. $(this.dom.defaultValue).remove();
  1815. for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
  1816. var val = _a[_i];
  1817. $(val).remove();
  1818. }
  1819. var children = $(this.dom.container).children();
  1820. if (children.length > 3) {
  1821. for (var i = 2; i < children.length - 1; i++) {
  1822. $(children[i]).remove();
  1823. }
  1824. }
  1825. // Find the column with the title matching the data for the criteria and take note of the index
  1826. if (loadedCriteria !== undefined) {
  1827. this.s.dt.columns().every(function (index) {
  1828. if (_this.s.dt.settings()[0].aoColumns[index].sTitle === loadedCriteria.data) {
  1829. _this.s.dataIdx = index;
  1830. }
  1831. });
  1832. }
  1833. // Initialise the value elements based on the condition
  1834. this.dom.value = [].concat(this.s.conditions[this.s.condition].init(this, Criteria.updateListener, loadedCriteria !== undefined ? loadedCriteria.value : undefined));
  1835. if (loadedCriteria !== undefined && loadedCriteria.value !== undefined) {
  1836. this.s.value = loadedCriteria.value;
  1837. }
  1838. // Insert value elements and trigger the inserted event
  1839. $(this.dom.value[0])
  1840. .insertAfter(this.dom.condition)
  1841. .trigger('dtsb-inserted');
  1842. for (var i = 1; i < this.dom.value.length; i++) {
  1843. $(this.dom.value[i])
  1844. .insertAfter(this.dom.value[i - 1])
  1845. .trigger('dtsb-inserted');
  1846. }
  1847. // Check if the criteria can be used in a search
  1848. this.s.filled = this.s.conditions[this.s.condition].isInputValid(this.dom.value, this);
  1849. this.setListeners();
  1850. // If it can and this is different to before then trigger a draw
  1851. if (prevFilled !== this.s.filled) {
  1852. this.s.dt.draw();
  1853. this.setListeners();
  1854. }
  1855. };
  1856. Criteria.version = '1.0.0';
  1857. Criteria.classes = {
  1858. button: 'dtsb-button',
  1859. buttonContainer: 'dtsb-buttonContainer',
  1860. condition: 'dtsb-condition',
  1861. container: 'dtsb-criteria',
  1862. data: 'dtsb-data',
  1863. "delete": 'dtsb-delete',
  1864. dropDown: 'dtsb-dropDown',
  1865. greyscale: 'dtsb-greyscale',
  1866. input: 'dtsb-input',
  1867. italic: 'dtsb-italic',
  1868. joiner: 'dtsp-joiner',
  1869. left: 'dtsb-left',
  1870. notItalic: 'dtsb-notItalic',
  1871. option: 'dtsb-option',
  1872. right: 'dtsb-right',
  1873. value: 'dtsb-value',
  1874. vertical: 'dtsb-vertical'
  1875. };
  1876. /**
  1877. * Default initialisation function for select conditions
  1878. */
  1879. Criteria.initSelect = function (that, fn, preDefined, array) {
  1880. if (preDefined === void 0) { preDefined = null; }
  1881. if (array === void 0) { array = false; }
  1882. var column = $(that.dom.data).children('option:selected').val();
  1883. var indexArray = that.s.dt.rows().indexes().toArray();
  1884. var settings = that.s.dt.settings()[0];
  1885. // Declare select element to be used with all of the default classes and listeners.
  1886. var el = $('<select/>')
  1887. .addClass(Criteria.classes.value)
  1888. .addClass(Criteria.classes.dropDown)
  1889. .addClass(Criteria.classes.italic)
  1890. .append(that.dom.valueTitle)
  1891. .on('input change', function () {
  1892. $(this).removeClass(Criteria.classes.italic);
  1893. fn(that, this);
  1894. });
  1895. if (that.c.greyscale) {
  1896. $(el).addClass(Criteria.classes.greyscale);
  1897. }
  1898. var added = [];
  1899. var options = [];
  1900. // Add all of the options from the table to the select element.
  1901. // Only add one option for each possible value
  1902. for (var _i = 0, indexArray_1 = indexArray; _i < indexArray_1.length; _i++) {
  1903. var index = indexArray_1[_i];
  1904. var filter = settings.oApi._fnGetCellData(settings, index, column, typeof that.c.orthogonal === 'string' ?
  1905. that.c.orthogonal :
  1906. that.c.orthogonal.search);
  1907. var value = {
  1908. filter: typeof filter === 'string' ?
  1909. filter.replace(/[\r\n\u2028]/g, ' ') : // Need to replace certain characters to match the search values
  1910. filter,
  1911. index: index,
  1912. text: settings.oApi._fnGetCellData(settings, index, column, typeof that.c.orthogonal === 'string' ?
  1913. that.c.orthogonal :
  1914. that.c.orthogonal.display)
  1915. };
  1916. // If we are dealing with an array type, either make sure we are working with arrays, or sort them
  1917. if (that.s.type === 'array') {
  1918. value.filter = !Array.isArray(value.filter) ?
  1919. [value.filter] :
  1920. value.filter = value.filter.sort();
  1921. value.text = !Array.isArray(value.text) ?
  1922. [value.text] :
  1923. value.text = value.text.sort();
  1924. }
  1925. // Function to add an option to the select element
  1926. var addOption = function (filt, text) {
  1927. // Add text and value, stripping out any html if that is the column type
  1928. var opt = $('<option>', {
  1929. text: typeof text === 'string' ?
  1930. text.replace(/(<([^>]+)>)/ig, '') :
  1931. text,
  1932. type: Array.isArray(filt) ? 'Array' : 'String',
  1933. value: that.s.type.indexOf('html') !== -1 && filt !== null && typeof filt === 'string' ?
  1934. filt.replace(/(<([^>]+)>)/ig, '') :
  1935. filt
  1936. })
  1937. .addClass(that.classes.option)
  1938. .addClass(that.classes.notItalic);
  1939. var val = $(opt).val();
  1940. // Check that this value has not already been added
  1941. if (added.indexOf(val) === -1) {
  1942. added.push(val);
  1943. options.push(opt);
  1944. if (preDefined !== null && Array.isArray(preDefined[0])) {
  1945. preDefined[0] = preDefined[0].sort().join(',');
  1946. }
  1947. // If this value was previously selected as indicated by preDefined, then select it again
  1948. if (preDefined !== null && opt.val() === preDefined[0]) {
  1949. opt.attr('selected', true);
  1950. $(el).removeClass(Criteria.classes.italic);
  1951. }
  1952. }
  1953. };
  1954. // If this is to add the individual values within the array we need to loop over the array
  1955. if (array) {
  1956. for (var i = 0; i < value.filter.length; i++) {
  1957. addOption(value.filter[i], value.text[i]);
  1958. }
  1959. }
  1960. // Otherwise the value that is in the cell is to be added
  1961. else {
  1962. addOption(value.filter, value.text);
  1963. }
  1964. }
  1965. options.sort(function (a, b) {
  1966. if (that.s.type === 'string' || that.s.type === 'num' || that.s.type === 'html' || that.s.type === 'html-num') {
  1967. if ($(a).val() < $(b).val()) {
  1968. return -1;
  1969. }
  1970. else if ($(a).val() < $(b).val()) {
  1971. return 1;
  1972. }
  1973. else {
  1974. return 0;
  1975. }
  1976. }
  1977. else if (that.s.type === 'num-fmt' || that.s.type === 'html-num-fmt') {
  1978. if (+$(a).val().replace(/[^0-9.]/g, '') < +$(b).val().replace(/[^0-9.]/g, '')) {
  1979. return -1;
  1980. }
  1981. else if (+$(a).val().replace(/[^0-9.]/g, '') < +$(b).val().replace(/[^0-9.]/g, '')) {
  1982. return 1;
  1983. }
  1984. else {
  1985. return 0;
  1986. }
  1987. }
  1988. });
  1989. for (var _a = 0, options_1 = options; _a < options_1.length; _a++) {
  1990. var opt = options_1[_a];
  1991. $(el).append(opt);
  1992. }
  1993. return el;
  1994. };
  1995. /**
  1996. * Default initialisation function for select array conditions
  1997. *
  1998. * This exists because there needs to be different select functionality for contains/without and equals/not
  1999. */
  2000. Criteria.initSelectArray = function (that, fn, preDefined) {
  2001. if (preDefined === void 0) { preDefined = null; }
  2002. return Criteria.initSelect(that, fn, preDefined, true);
  2003. };
  2004. /**
  2005. * Default initialisation function for input conditions
  2006. */
  2007. Criteria.initInput = function (that, fn, preDefined) {
  2008. if (preDefined === void 0) { preDefined = null; }
  2009. // Declare the input element
  2010. var el = $('<input/>')
  2011. .addClass(Criteria.classes.value)
  2012. .addClass(Criteria.classes.input)
  2013. .on('input', function () { fn(that, this); });
  2014. if (that.c.greyscale) {
  2015. $(el).addClass(Criteria.classes.greyscale);
  2016. }
  2017. // If there is a preDefined value then add it
  2018. if (preDefined !== null) {
  2019. $(el).val(preDefined[0]);
  2020. }
  2021. return el;
  2022. };
  2023. /**
  2024. * Default initialisation function for conditions requiring 2 inputs
  2025. */
  2026. Criteria.init2Input = function (that, fn, preDefined) {
  2027. if (preDefined === void 0) { preDefined = null; }
  2028. // Declare all of the necessary jQuery elements
  2029. var els = [
  2030. $('<input/>')
  2031. .addClass(Criteria.classes.value)
  2032. .addClass(Criteria.classes.input)
  2033. .on('input', function () { fn(that, this); }),
  2034. $('<span>')
  2035. .addClass(that.classes.joiner).text(that.s.dt.i18n('searchBuilder.valueJoiner', that.c.i18n.valueJoiner)),
  2036. $('<input/>')
  2037. .addClass(Criteria.classes.value)
  2038. .addClass(Criteria.classes.input)
  2039. .on('input', function () { fn(that, this); })
  2040. ];
  2041. if (that.c.greyscale) {
  2042. $(els[0]).addClass(Criteria.classes.greyscale);
  2043. $(els[2]).addClass(Criteria.classes.greyscale);
  2044. }
  2045. // If there is a preDefined value then add it
  2046. if (preDefined !== null) {
  2047. $(els[0]).val(preDefined[0]);
  2048. $(els[2]).val(preDefined[1]);
  2049. }
  2050. that.s.dt.off('draw');
  2051. that.s.dt.one('draw', function () {
  2052. $(that.s.topGroup).trigger('dtsb-redrawContents');
  2053. });
  2054. return els;
  2055. };
  2056. /**
  2057. * Default initialisation function for date conditions
  2058. */
  2059. Criteria.initDate = function (that, fn, preDefined) {
  2060. if (preDefined === void 0) { preDefined = null; }
  2061. // Declare date element using DataTables dateTime plugin
  2062. var el = $('<input/>')
  2063. .addClass(Criteria.classes.value)
  2064. .addClass(Criteria.classes.input)
  2065. .dtDateTime({
  2066. attachTo: 'input',
  2067. format: that.s.momentFormat ? that.s.momentFormat : undefined
  2068. })
  2069. .on('input change', function () { fn(that, this); });
  2070. if (that.c.greyscale) {
  2071. $(el).addClass(Criteria.classes.greyscale);
  2072. }
  2073. // If there is a preDefined value then add it
  2074. if (preDefined !== null) {
  2075. $(el).val(preDefined[0]);
  2076. }
  2077. return el;
  2078. };
  2079. Criteria.initNoValue = function (that) {
  2080. that.s.dt.off('draw');
  2081. that.s.dt.one('draw', function () {
  2082. $(that.s.topGroup).trigger('dtsb-redrawContents');
  2083. });
  2084. };
  2085. Criteria.init2Date = function (that, fn, preDefined) {
  2086. if (preDefined === void 0) { preDefined = null; }
  2087. // Declare all of the date elements that are required using DataTables dateTime plugin
  2088. var els = [
  2089. $('<input/>')
  2090. .addClass(Criteria.classes.value)
  2091. .addClass(Criteria.classes.input)
  2092. .dtDateTime({
  2093. attachTo: 'input',
  2094. format: that.s.momentFormat ? that.s.momentFormat : undefined
  2095. })
  2096. .on('input change', function () { fn(that, this); }),
  2097. $('<span>')
  2098. .addClass(that.classes.joiner)
  2099. .text(that.s.dt.i18n('searchBuilder.valueJoiner', that.c.i18n.valueJoiner)),
  2100. $('<input/>')
  2101. .addClass(Criteria.classes.value)
  2102. .addClass(Criteria.classes.input)
  2103. .dtDateTime({
  2104. attachTo: 'input',
  2105. format: that.s.momentFormat ? that.s.momentFormat : undefined
  2106. })
  2107. .on('input change', function () { fn(that, this); })
  2108. ];
  2109. if (that.c.greyscale) {
  2110. $(els[0]).addClass(Criteria.classes.greyscale);
  2111. $(els[2]).addClass(Criteria.classes.greyscale);
  2112. }
  2113. // If there are and preDefined values then add them
  2114. if (preDefined !== null && preDefined.length > 0) {
  2115. $(els[0]).val(preDefined[0]);
  2116. $(els[2]).val(preDefined[1]);
  2117. }
  2118. that.s.dt.off('draw');
  2119. that.s.dt.one('draw', function () {
  2120. $(that.s.topGroup).trigger('dtsb-redrawContents');
  2121. });
  2122. return els;
  2123. };
  2124. /**
  2125. * Default function for select elements to validate condition
  2126. */
  2127. Criteria.isInputValidSelect = function (el) {
  2128. var allFilled = true;
  2129. // Check each element to make sure that the selections are valid
  2130. for (var _i = 0, el_1 = el; _i < el_1.length; _i++) {
  2131. var element = el_1[_i];
  2132. if ($(element).children('option:selected').length === $(element).children('option').length - $(element).children('option.' + Criteria.classes.notItalic).length &&
  2133. $(element).children('option:selected').length === 1 &&
  2134. $(element).children('option:selected')[0] === $(element).children('option:hidden')[0]) {
  2135. allFilled = false;
  2136. }
  2137. }
  2138. return allFilled;
  2139. };
  2140. /**
  2141. * Default function for input and date elements to validate condition
  2142. */
  2143. Criteria.isInputValidInput = function (el) {
  2144. var allFilled = true;
  2145. // Check each element to make sure that the inputs are valid
  2146. for (var _i = 0, el_2 = el; _i < el_2.length; _i++) {
  2147. var element = el_2[_i];
  2148. if ($(element).is('input') && $(element).val().length === 0) {
  2149. allFilled = false;
  2150. }
  2151. }
  2152. return allFilled;
  2153. };
  2154. /**
  2155. * Default function for getting select conditions
  2156. */
  2157. Criteria.inputValueSelect = function (el) {
  2158. var values = [];
  2159. // Go through the select elements and push each selected option to the return array
  2160. for (var _i = 0, el_3 = el; _i < el_3.length; _i++) {
  2161. var element = el_3[_i];
  2162. if ($(element).is('select')) {
  2163. var val = $(element).children('option:selected').val();
  2164. // If the type of the option is an array we need to split it up and sort it
  2165. values.push($(element).children('option:selected').attr('type') === 'Array' ?
  2166. val.split(',').sort() :
  2167. val);
  2168. }
  2169. }
  2170. return values;
  2171. };
  2172. /**
  2173. * Default function for getting input conditions
  2174. */
  2175. Criteria.inputValueInput = function (el) {
  2176. var values = [];
  2177. // Go through the input elements and push each value to the return array
  2178. for (var _i = 0, el_4 = el; _i < el_4.length; _i++) {
  2179. var element = el_4[_i];
  2180. if ($(element).is('input')) {
  2181. values.push($(element).val());
  2182. }
  2183. }
  2184. return values;
  2185. };
  2186. /**
  2187. * Function that is run on each element as a call back when a search should be triggered
  2188. */
  2189. Criteria.updateListener = function (that, el) {
  2190. // When the value is changed the criteria is now complete so can be included in searches
  2191. // Get the condition from the map based on the key that has been selected for the condition
  2192. var condition = that.s.conditions[that.s.condition];
  2193. that.s.filled = condition.isInputValid(that.dom.value, that);
  2194. that.s.value = condition.inputValue(that.dom.value, that);
  2195. if (!Array.isArray(that.s.value)) {
  2196. that.s.value = [that.s.value];
  2197. }
  2198. for (var i = 0; i < that.s.value.length; i++) {
  2199. // If the value is an array we need to sort it
  2200. if (Array.isArray(that.s.value[i])) {
  2201. that.s.value[i].sort();
  2202. }
  2203. // Otherwise replace the decimal place character for i18n
  2204. else if (that.s.dt.settings()[0].oLanguage.sDecimal !== '') {
  2205. that.s.value[i] = that.s.value[i].replace(that.s.dt.settings()[0].oLanguage.sDecimal, '.');
  2206. }
  2207. }
  2208. // Take note of the cursor position so that we can refocus there later
  2209. var idx = null;
  2210. var cursorPos = null;
  2211. for (var i = 0; i < that.dom.value.length; i++) {
  2212. if (el === that.dom.value[i][0]) {
  2213. idx = i;
  2214. if (el.selectionStart !== undefined) {
  2215. cursorPos = el.selectionStart;
  2216. }
  2217. }
  2218. }
  2219. // Trigger a search
  2220. that.s.dt.draw();
  2221. // Refocus the element and set the correct cursor position
  2222. if (idx !== null) {
  2223. $(that.dom.value[idx]).removeClass(that.classes.italic);
  2224. $(that.dom.value[idx]).focus();
  2225. if (cursorPos !== null) {
  2226. $(that.dom.value[idx])[0].setSelectionRange(cursorPos, cursorPos);
  2227. }
  2228. }
  2229. };
  2230. // The order of the conditions will make tslint sad :(
  2231. Criteria.dateConditions = {
  2232. '=': {
  2233. conditionName: function (dt, i18n) {
  2234. return dt.i18n('searchBuilder.conditions.date.equals', i18n.conditions.date.equals);
  2235. },
  2236. init: Criteria.initDate,
  2237. inputValue: Criteria.inputValueInput,
  2238. isInputValid: Criteria.isInputValidInput,
  2239. search: function (value, comparison) {
  2240. value = value.replace(/(\/|\-|\,)/g, '-');
  2241. return value === comparison[0];
  2242. }
  2243. },
  2244. '!=': {
  2245. conditionName: function (dt, i18n) {
  2246. return dt.i18n('searchBuilder.conditions.date.not', i18n.conditions.date.not);
  2247. },
  2248. init: Criteria.initDate,
  2249. inputValue: Criteria.inputValueInput,
  2250. isInputValid: Criteria.isInputValidInput,
  2251. search: function (value, comparison) {
  2252. value = value.replace(/(\/|\-|\,)/g, '-');
  2253. return value !== comparison[0];
  2254. }
  2255. },
  2256. '<': {
  2257. conditionName: function (dt, i18n) {
  2258. return dt.i18n('searchBuilder.conditions.date.before', i18n.conditions.date.before);
  2259. },
  2260. init: Criteria.initDate,
  2261. inputValue: Criteria.inputValueInput,
  2262. isInputValid: Criteria.isInputValidInput,
  2263. search: function (value, comparison) {
  2264. value = value.replace(/(\/|\-|\,)/g, '-');
  2265. return value < comparison[0];
  2266. }
  2267. },
  2268. '>': {
  2269. conditionName: function (dt, i18n) {
  2270. return dt.i18n('searchBuilder.conditions.date.after', i18n.conditions.date.after);
  2271. },
  2272. init: Criteria.initDate,
  2273. inputValue: Criteria.inputValueInput,
  2274. isInputValid: Criteria.isInputValidInput,
  2275. search: function (value, comparison) {
  2276. value = value.replace(/(\/|\-|\,)/g, '-');
  2277. return value > comparison[0];
  2278. }
  2279. },
  2280. 'between': {
  2281. conditionName: function (dt, i18n) {
  2282. return dt.i18n('searchBuilder.conditions.date.between', i18n.conditions.date.between);
  2283. },
  2284. init: Criteria.init2Date,
  2285. inputValue: Criteria.inputValueInput,
  2286. isInputValid: Criteria.isInputValidInput,
  2287. search: function (value, comparison) {
  2288. value = value.replace(/(\/|\-|\,)/g, '-');
  2289. if (comparison[0] < comparison[1]) {
  2290. return comparison[0] <= value && value <= comparison[1];
  2291. }
  2292. else {
  2293. return comparison[1] <= value && value <= comparison[0];
  2294. }
  2295. }
  2296. },
  2297. '!between': {
  2298. conditionName: function (dt, i18n) {
  2299. return dt.i18n('searchBuilder.conditions.date.notBetween', i18n.conditions.date.notBetween);
  2300. },
  2301. init: Criteria.init2Date,
  2302. inputValue: Criteria.inputValueInput,
  2303. isInputValid: Criteria.isInputValidInput,
  2304. search: function (value, comparison) {
  2305. value = value.replace(/(\/|\-|\,)/g, '-');
  2306. if (comparison[0] < comparison[1]) {
  2307. return !(comparison[0] <= value && value <= comparison[1]);
  2308. }
  2309. else {
  2310. return !(comparison[1] <= value && value <= comparison[0]);
  2311. }
  2312. }
  2313. },
  2314. 'null': {
  2315. conditionName: function (dt, i18n) {
  2316. return dt.i18n('searchBuilder.conditions.date.empty', i18n.conditions.date.empty);
  2317. },
  2318. isInputValid: function () { return true; },
  2319. init: Criteria.initNoValue,
  2320. inputValue: function () {
  2321. return;
  2322. },
  2323. search: function (value) {
  2324. return (value === null || value === undefined || value.length === 0);
  2325. }
  2326. },
  2327. '!null': {
  2328. conditionName: function (dt, i18n) {
  2329. return dt.i18n('searchBuilder.conditions.date.notEmpty', i18n.conditions.date.notEmpty);
  2330. },
  2331. isInputValid: function () { return true; },
  2332. init: Criteria.initNoValue,
  2333. inputValue: function () {
  2334. return;
  2335. },
  2336. search: function (value) {
  2337. return !(value === null || value === undefined || value.length === 0);
  2338. }
  2339. }
  2340. };
  2341. // The order of the conditions will make tslint sad :(
  2342. Criteria.momentDateConditions = {
  2343. '=': {
  2344. conditionName: function (dt, i18n) {
  2345. return dt.i18n('searchBuilder.conditions.moment.equals', i18n.conditions.moment.equals);
  2346. },
  2347. init: Criteria.initDate,
  2348. inputValue: Criteria.inputValueInput,
  2349. isInputValid: Criteria.isInputValidInput,
  2350. search: function (value, comparison, that) {
  2351. return moment(value, that.s.momentFormat).valueOf() === moment(comparison[0], that.s.momentFormat).valueOf();
  2352. }
  2353. },
  2354. '!=': {
  2355. conditionName: function (dt, i18n) {
  2356. return dt.i18n('searchBuilder.conditions.moment.not', i18n.conditions.moment.not);
  2357. },
  2358. init: Criteria.initDate,
  2359. inputValue: Criteria.inputValueInput,
  2360. isInputValid: Criteria.isInputValidInput,
  2361. search: function (value, comparison, that) {
  2362. return moment(value, that.s.momentFormat).valueOf() !== moment(comparison[0], that.s.momentFormat).valueOf();
  2363. }
  2364. },
  2365. '<': {
  2366. conditionName: function (dt, i18n) {
  2367. return dt.i18n('searchBuilder.conditions.moment.before', i18n.conditions.moment.before);
  2368. },
  2369. init: Criteria.initDate,
  2370. inputValue: Criteria.inputValueInput,
  2371. isInputValid: Criteria.isInputValidInput,
  2372. search: function (value, comparison, that) {
  2373. return moment(value, that.s.momentFormat).valueOf() < moment(comparison[0], that.s.momentFormat).valueOf();
  2374. }
  2375. },
  2376. '>': {
  2377. conditionName: function (dt, i18n) {
  2378. return dt.i18n('searchBuilder.conditions.moment.after', i18n.conditions.moment.after);
  2379. },
  2380. init: Criteria.initDate,
  2381. inputValue: Criteria.inputValueInput,
  2382. isInputValid: Criteria.isInputValidInput,
  2383. search: function (value, comparison, that) {
  2384. return moment(value, that.s.momentFormat).valueOf() > moment(comparison[0], that.s.momentFormat).valueOf();
  2385. }
  2386. },
  2387. 'between': {
  2388. conditionName: function (dt, i18n) {
  2389. return dt.i18n('searchBuilder.conditions.moment.between', i18n.conditions.moment.between);
  2390. },
  2391. init: Criteria.init2Date,
  2392. inputValue: Criteria.inputValueInput,
  2393. isInputValid: Criteria.isInputValidInput,
  2394. search: function (value, comparison, that) {
  2395. var val = moment(value, that.s.momentFormat).valueOf();
  2396. var comp0 = moment(comparison[0], that.s.momentFormat).valueOf();
  2397. var comp1 = moment(comparison[1], that.s.momentFormat).valueOf();
  2398. if (comp0 < comp1) {
  2399. return comp0 <= val && val <= comp1;
  2400. }
  2401. else {
  2402. return comp1 <= val && val <= comp0;
  2403. }
  2404. }
  2405. },
  2406. '!between': {
  2407. conditionName: function (dt, i18n) {
  2408. return dt.i18n('searchBuilder.conditions.moment.notBetween', i18n.conditions.moment.notBetween);
  2409. },
  2410. init: Criteria.init2Date,
  2411. inputValue: Criteria.inputValueInput,
  2412. isInputValid: Criteria.isInputValidInput,
  2413. search: function (value, comparison, that) {
  2414. var val = moment(value, that.s.momentFormat).valueOf();
  2415. var comp0 = moment(comparison[0], that.s.momentFormat).valueOf();
  2416. var comp1 = moment(comparison[1], that.s.momentFormat).valueOf();
  2417. if (comp0 < comp1) {
  2418. return !(+comp0 <= +val && +val <= +comp1);
  2419. }
  2420. else {
  2421. return !(+comp1 <= +val && +val <= +comp0);
  2422. }
  2423. }
  2424. },
  2425. 'null': {
  2426. conditionName: function (dt, i18n) {
  2427. return dt.i18n('searchBuilder.conditions.moment.empty', i18n.conditions.moment.empty);
  2428. },
  2429. isInputValid: function () { return true; },
  2430. init: Criteria.initNoValue,
  2431. inputValue: function () {
  2432. return;
  2433. },
  2434. search: function (value) {
  2435. return (value === null || value === undefined || value.length === 0);
  2436. }
  2437. },
  2438. '!null': {
  2439. conditionName: function (dt, i18n) {
  2440. return dt.i18n('searchBuilder.conditions.moment.notEmpty', i18n.conditions.moment.notEmpty);
  2441. },
  2442. isInputValid: function () { return true; },
  2443. init: Criteria.initNoValue,
  2444. inputValue: function () {
  2445. return;
  2446. },
  2447. search: function (value) {
  2448. return !(value === null || value === undefined || value.length === 0);
  2449. }
  2450. }
  2451. };
  2452. // The order of the conditions will make tslint sad :(
  2453. Criteria.numConditions = {
  2454. '=': {
  2455. conditionName: function (dt, i18n) {
  2456. return dt.i18n('searchBuilder.conditions.number.equals', i18n.conditions.number.equals);
  2457. },
  2458. init: Criteria.initSelect,
  2459. inputValue: Criteria.inputValueSelect,
  2460. isInputValid: Criteria.isInputValidSelect,
  2461. search: function (value, comparison) {
  2462. return +value === +comparison[0];
  2463. }
  2464. },
  2465. '!=': {
  2466. conditionName: function (dt, i18n) {
  2467. return dt.i18n('searchBuilder.conditions.number.not', i18n.conditions.number.not);
  2468. },
  2469. init: Criteria.initSelect,
  2470. inputValue: Criteria.inputValueSelect,
  2471. isInputValid: Criteria.isInputValidSelect,
  2472. search: function (value, comparison) {
  2473. return +value !== +comparison[0];
  2474. }
  2475. },
  2476. '<': {
  2477. conditionName: function (dt, i18n) {
  2478. return dt.i18n('searchBuilder.conditions.number.lt', i18n.conditions.number.lt);
  2479. },
  2480. init: Criteria.initInput,
  2481. inputValue: Criteria.inputValueInput,
  2482. isInputValid: Criteria.isInputValidInput,
  2483. search: function (value, comparison) {
  2484. return +value < +comparison[0];
  2485. }
  2486. },
  2487. '<=': {
  2488. conditionName: function (dt, i18n) {
  2489. return dt.i18n('searchBuilder.conditions.number.lte', i18n.conditions.number.lte);
  2490. },
  2491. init: Criteria.initInput,
  2492. inputValue: Criteria.inputValueInput,
  2493. isInputValid: Criteria.isInputValidInput,
  2494. search: function (value, comparison) {
  2495. return +value <= +comparison[0];
  2496. }
  2497. },
  2498. '>=': {
  2499. conditionName: function (dt, i18n) {
  2500. return dt.i18n('searchBuilder.conditions.number.gte', i18n.conditions.number.gte);
  2501. },
  2502. init: Criteria.initInput,
  2503. inputValue: Criteria.inputValueInput,
  2504. isInputValid: Criteria.isInputValidInput,
  2505. search: function (value, comparison) {
  2506. return +value >= +comparison[0];
  2507. }
  2508. },
  2509. '>': {
  2510. conditionName: function (dt, i18n) {
  2511. return dt.i18n('searchBuilder.conditions.number.gt', i18n.conditions.number.gt);
  2512. },
  2513. init: Criteria.initInput,
  2514. inputValue: Criteria.inputValueInput,
  2515. isInputValid: Criteria.isInputValidInput,
  2516. search: function (value, comparison) {
  2517. return +value > +comparison[0];
  2518. }
  2519. },
  2520. 'between': {
  2521. conditionName: function (dt, i18n) {
  2522. return dt.i18n('searchBuilder.conditions.number.between', i18n.conditions.number.between);
  2523. },
  2524. init: Criteria.init2Input,
  2525. inputValue: Criteria.inputValueInput,
  2526. isInputValid: Criteria.isInputValidInput,
  2527. search: function (value, comparison) {
  2528. if (+comparison[0] < +comparison[1]) {
  2529. return +comparison[0] <= +value && +value <= +comparison[1];
  2530. }
  2531. else {
  2532. return +comparison[1] <= +value && +value <= +comparison[0];
  2533. }
  2534. }
  2535. },
  2536. '!between': {
  2537. conditionName: function (dt, i18n) {
  2538. return dt.i18n('searchBuilder.conditions.number.notBetween', i18n.conditions.number.notBetween);
  2539. },
  2540. init: Criteria.init2Input,
  2541. inputValue: Criteria.inputValueInput,
  2542. isInputValid: Criteria.isInputValidInput,
  2543. search: function (value, comparison) {
  2544. if (+comparison[0] < +comparison[1]) {
  2545. return !(+comparison[0] <= +value && +value <= +comparison[1]);
  2546. }
  2547. else {
  2548. return !(+comparison[1] <= +value && +value <= +comparison[0]);
  2549. }
  2550. }
  2551. },
  2552. 'null': {
  2553. conditionName: function (dt, i18n) {
  2554. return dt.i18n('searchBuilder.conditions.number.empty', i18n.conditions.number.empty);
  2555. },
  2556. init: Criteria.initNoValue,
  2557. inputValue: function () { return; },
  2558. isInputValid: function () { return true; },
  2559. search: function (value) {
  2560. return (value === null || value === undefined || value.length === 0);
  2561. }
  2562. },
  2563. '!null': {
  2564. conditionName: function (dt, i18n) {
  2565. return dt.i18n('searchBuilder.conditions.number.notEmpty', i18n.conditions.number.notEmpty);
  2566. },
  2567. isInputValid: function () { return true; },
  2568. init: Criteria.initNoValue,
  2569. inputValue: function () {
  2570. return;
  2571. },
  2572. search: function (value) {
  2573. return !(value === null || value === undefined || value.length === 0);
  2574. }
  2575. }
  2576. };
  2577. // The order of the conditions will make tslint sad :(
  2578. Criteria.numFmtConditions = {
  2579. '=': {
  2580. conditionName: function (dt, i18n) {
  2581. return dt.i18n('searchBuilder.conditions.number.equals', i18n.conditions.number.equals);
  2582. },
  2583. init: Criteria.initSelect,
  2584. inputValue: Criteria.inputValueSelect,
  2585. isInputValid: Criteria.isInputValidSelect,
  2586. search: function (value, comparison) {
  2587. var val = value.indexOf('-') === 0 ?
  2588. '-' + value.replace(/[^0-9.]/g, '') :
  2589. value.replace(/[^0-9.]/g, '');
  2590. var comp = comparison[0].indexOf('-') === 0 ?
  2591. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  2592. comparison[0].replace(/[^0-9.]/g, '');
  2593. return +val === +comp;
  2594. }
  2595. },
  2596. '!=': {
  2597. conditionName: function (dt, i18n) {
  2598. return dt.i18n('searchBuilder.conditions.number.not', i18n.conditions.number.not);
  2599. },
  2600. init: Criteria.initSelect,
  2601. inputValue: Criteria.inputValueSelect,
  2602. isInputValid: Criteria.isInputValidSelect,
  2603. search: function (value, comparison) {
  2604. var val = value.indexOf('-') === 0 ?
  2605. '-' + value.replace(/[^0-9.]/g, '') :
  2606. value.replace(/[^0-9.]/g, '');
  2607. var comp = comparison[0].indexOf('-') === 0 ?
  2608. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  2609. comparison[0].replace(/[^0-9.]/g, '');
  2610. return +val !== +comp;
  2611. }
  2612. },
  2613. '<': {
  2614. conditionName: function (dt, i18n) {
  2615. return dt.i18n('searchBuilder.conditions.number.lt', i18n.conditions.number.lt);
  2616. },
  2617. init: Criteria.initInput,
  2618. inputValue: Criteria.inputValueInput,
  2619. isInputValid: Criteria.isInputValidInput,
  2620. search: function (value, comparison) {
  2621. var val = value.indexOf('-') === 0 ?
  2622. '-' + value.replace(/[^0-9.]/g, '') :
  2623. value.replace(/[^0-9.]/g, '');
  2624. var comp = comparison[0].indexOf('-') === 0 ?
  2625. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  2626. comparison[0].replace(/[^0-9.]/g, '');
  2627. return +val < +comp;
  2628. }
  2629. },
  2630. '<=': {
  2631. conditionName: function (dt, i18n) {
  2632. return dt.i18n('searchBuilder.conditions.number.lte', i18n.conditions.number.lte);
  2633. },
  2634. init: Criteria.initInput,
  2635. inputValue: Criteria.inputValueInput,
  2636. isInputValid: Criteria.isInputValidInput,
  2637. search: function (value, comparison) {
  2638. var val = value.indexOf('-') === 0 ?
  2639. '-' + value.replace(/[^0-9.]/g, '') :
  2640. value.replace(/[^0-9.]/g, '');
  2641. var comp = comparison[0].indexOf('-') === 0 ?
  2642. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  2643. comparison[0].replace(/[^0-9.]/g, '');
  2644. return +val <= +comp;
  2645. }
  2646. },
  2647. '>=': {
  2648. conditionName: function (dt, i18n) {
  2649. return dt.i18n('searchBuilder.conditions.number.gte', i18n.conditions.number.gte);
  2650. },
  2651. init: Criteria.initInput,
  2652. inputValue: Criteria.inputValueInput,
  2653. isInputValid: Criteria.isInputValidInput,
  2654. search: function (value, comparison) {
  2655. var val = value.indexOf('-') === 0 ?
  2656. '-' + value.replace(/[^0-9.]/g, '') :
  2657. value.replace(/[^0-9.]/g, '');
  2658. var comp = comparison[0].indexOf('-') === 0 ?
  2659. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  2660. comparison[0].replace(/[^0-9.]/g, '');
  2661. return +val >= +comp;
  2662. }
  2663. },
  2664. '>': {
  2665. conditionName: function (dt, i18n) {
  2666. return dt.i18n('searchBuilder.conditions.number.gt', i18n.conditions.number.gt);
  2667. },
  2668. init: Criteria.initInput,
  2669. inputValue: Criteria.inputValueInput,
  2670. isInputValid: Criteria.isInputValidInput,
  2671. search: function (value, comparison) {
  2672. var val = value.indexOf('-') === 0 ?
  2673. '-' + value.replace(/[^0-9.]/g, '') :
  2674. value.replace(/[^0-9.]/g, '');
  2675. var comp = comparison[0].indexOf('-') === 0 ?
  2676. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  2677. comparison[0].replace(/[^0-9.]/g, '');
  2678. return +val > +comp;
  2679. }
  2680. },
  2681. 'between': {
  2682. conditionName: function (dt, i18n) {
  2683. return dt.i18n('searchBuilder.conditions.number.between', i18n.conditions.number.between);
  2684. },
  2685. init: Criteria.init2Input,
  2686. inputValue: Criteria.inputValueInput,
  2687. isInputValid: Criteria.isInputValidInput,
  2688. search: function (value, comparison) {
  2689. var val = value.indexOf('-') === 0 ?
  2690. '-' + value.replace(/[^0-9.]/g, '') :
  2691. value.replace(/[^0-9.]/g, '');
  2692. var comp0 = comparison[0].indexOf('-') === 0 ?
  2693. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  2694. comparison[0].replace(/[^0-9.]/g, '');
  2695. var comp1 = comparison[1].indexOf('-') === 0 ?
  2696. '-' + comparison[1].replace(/[^0-9.]/g, '') :
  2697. comparison[1].replace(/[^0-9.]/g, '');
  2698. if (+comp0 < +comp1) {
  2699. return +comp0 <= +val && +val <= +comp1;
  2700. }
  2701. else {
  2702. return +comp1 <= +val && +val <= +comp0;
  2703. }
  2704. }
  2705. },
  2706. '!between': {
  2707. conditionName: function (dt, i18n) {
  2708. return dt.i18n('searchBuilder.conditions.number.notBetween', i18n.conditions.number.notBetween);
  2709. },
  2710. init: Criteria.init2Input,
  2711. inputValue: Criteria.inputValueInput,
  2712. isInputValid: Criteria.isInputValidInput,
  2713. search: function (value, comparison) {
  2714. var val = value.indexOf('-') === 0 ?
  2715. '-' + value.replace(/[^0-9.]/g, '') :
  2716. value.replace(/[^0-9.]/g, '');
  2717. var comp0 = comparison[0].indexOf('-') === 0 ?
  2718. '-' + comparison[0].replace(/[^0-9.]/g, '') :
  2719. comparison[0].replace(/[^0-9.]/g, '');
  2720. var comp1 = comparison[1].indexOf('-') === 0 ?
  2721. '-' + comparison[1].replace(/[^0-9.]/g, '') :
  2722. comparison[1].replace(/[^0-9.]/g, '');
  2723. if (+comp0 < +comp1) {
  2724. return !(+comp0 <= +val && +val <= +comp1);
  2725. }
  2726. else {
  2727. return !(+comp1 <= +val && +val <= +comp0);
  2728. }
  2729. }
  2730. },
  2731. 'null': {
  2732. conditionName: function (dt, i18n) {
  2733. return dt.i18n('searchBuilder.conditions.number.empty', i18n.conditions.number.empty);
  2734. },
  2735. init: Criteria.initNoValue,
  2736. inputValue: function () { return; },
  2737. isInputValid: function () { return true; },
  2738. search: function (value) {
  2739. return (value === null || value === undefined || value.length === 0);
  2740. }
  2741. },
  2742. '!null': {
  2743. conditionName: function (dt, i18n) {
  2744. return dt.i18n('searchBuilder.conditions.number.notEmpty', i18n.conditions.number.notEmpty);
  2745. },
  2746. isInputValid: function () { return true; },
  2747. init: Criteria.initNoValue,
  2748. inputValue: function () {
  2749. return;
  2750. },
  2751. search: function (value) {
  2752. return !(value === null || value === undefined || value.length === 0);
  2753. }
  2754. }
  2755. };
  2756. // The order of the conditions will make tslint sad :(
  2757. Criteria.stringConditions = {
  2758. '=': {
  2759. conditionName: function (dt, i18n) {
  2760. return dt.i18n('searchBuilder.conditions.string.equals', i18n.conditions.string.equals);
  2761. },
  2762. init: Criteria.initSelect,
  2763. inputValue: Criteria.inputValueSelect,
  2764. isInputValid: Criteria.isInputValidSelect,
  2765. search: function (value, comparison) {
  2766. return value === comparison[0];
  2767. }
  2768. },
  2769. '!=': {
  2770. conditionName: function (dt, i18n) {
  2771. return dt.i18n('searchBuilder.conditions.string.not', i18n.conditions.string.not);
  2772. },
  2773. init: Criteria.initSelect,
  2774. inputValue: Criteria.inputValueSelect,
  2775. isInputValid: Criteria.isInputValidInput,
  2776. search: function (value, comparison) {
  2777. return value !== comparison[0];
  2778. }
  2779. },
  2780. 'starts': {
  2781. conditionName: function (dt, i18n) {
  2782. return dt.i18n('searchBuilder.conditions.string.startsWith', i18n.conditions.string.startsWith);
  2783. },
  2784. init: Criteria.initInput,
  2785. inputValue: Criteria.inputValueInput,
  2786. isInputValid: Criteria.isInputValidInput,
  2787. search: function (value, comparison) {
  2788. return value.toLowerCase().indexOf(comparison[0].toLowerCase()) === 0;
  2789. }
  2790. },
  2791. 'contains': {
  2792. conditionName: function (dt, i18n) {
  2793. return dt.i18n('searchBuilder.conditions.string.contains', i18n.conditions.string.contains);
  2794. },
  2795. init: Criteria.initInput,
  2796. inputValue: Criteria.inputValueInput,
  2797. isInputValid: Criteria.isInputValidInput,
  2798. search: function (value, comparison) {
  2799. return value.toLowerCase().indexOf(comparison[0].toLowerCase()) !== -1;
  2800. }
  2801. },
  2802. 'ends': {
  2803. conditionName: function (dt, i18n) {
  2804. return dt.i18n('searchBuilder.conditions.string.endsWith', i18n.conditions.string.endsWith);
  2805. },
  2806. init: Criteria.initInput,
  2807. inputValue: Criteria.inputValueInput,
  2808. isInputValid: Criteria.isInputValidInput,
  2809. search: function (value, comparison) {
  2810. return value.toLowerCase().endsWith(comparison[0].toLowerCase());
  2811. }
  2812. },
  2813. 'null': {
  2814. conditionName: function (dt, i18n) {
  2815. return dt.i18n('searchBuilder.conditions.string.empty', i18n.conditions.string.empty);
  2816. },
  2817. init: Criteria.initNoValue,
  2818. inputValue: function () { return; },
  2819. isInputValid: function () { return true; },
  2820. search: function (value) {
  2821. return (value === null || value === undefined || value.length === 0);
  2822. }
  2823. },
  2824. '!null': {
  2825. conditionName: function (dt, i18n) {
  2826. return dt.i18n('searchBuilder.conditions.string.notEmpty', i18n.conditions.string.notEmpty);
  2827. },
  2828. isInputValid: function () { return true; },
  2829. init: Criteria.initNoValue,
  2830. inputValue: function () {
  2831. return;
  2832. },
  2833. search: function (value) {
  2834. return !(value === null || value === undefined || value.length === 0);
  2835. }
  2836. }
  2837. };
  2838. // The order of the conditions will make tslint sad :(
  2839. Criteria.arrayConditions = {
  2840. 'contains': {
  2841. conditionName: function (dt, i18n) {
  2842. return dt.i18n('searchBuilder.conditions.array.contains', i18n.conditions.array.contains);
  2843. },
  2844. init: Criteria.initSelectArray,
  2845. inputValue: Criteria.inputValueSelect,
  2846. isInputValid: Criteria.isInputValidSelect,
  2847. search: function (value, comparison) {
  2848. return value.indexOf(comparison[0]) !== -1;
  2849. }
  2850. },
  2851. 'without': {
  2852. conditionName: function (dt, i18n) {
  2853. return dt.i18n('searchBuilder.conditions.array.without', i18n.conditions.array.without);
  2854. },
  2855. init: Criteria.initSelectArray,
  2856. inputValue: Criteria.inputValueSelect,
  2857. isInputValid: Criteria.isInputValidSelect,
  2858. search: function (value, comparison) {
  2859. return value.indexOf(comparison[0]) === -1;
  2860. }
  2861. },
  2862. '=': {
  2863. conditionName: function (dt, i18n) {
  2864. return dt.i18n('searchBuilder.conditions.array.equals', i18n.conditions.array.equals);
  2865. },
  2866. init: Criteria.initSelect,
  2867. inputValue: Criteria.inputValueSelect,
  2868. isInputValid: Criteria.isInputValidSelect,
  2869. search: function (value, comparison) {
  2870. if (value.length === comparison[0].length) {
  2871. for (var i = 0; i < value.length; i++) {
  2872. if (value[i] !== comparison[0][i]) {
  2873. return false;
  2874. }
  2875. }
  2876. return true;
  2877. }
  2878. return false;
  2879. }
  2880. },
  2881. '!=': {
  2882. conditionName: function (dt, i18n) {
  2883. return dt.i18n('searchBuilder.conditions.array.not', i18n.conditions.array.not);
  2884. },
  2885. init: Criteria.initSelect,
  2886. inputValue: Criteria.inputValueSelect,
  2887. isInputValid: Criteria.isInputValidSelect,
  2888. search: function (value, comparison) {
  2889. if (value.length === comparison[0].length) {
  2890. for (var i = 0; i < value.length; i++) {
  2891. if (value[i] !== comparison[0][i]) {
  2892. return true;
  2893. }
  2894. }
  2895. return false;
  2896. }
  2897. return true;
  2898. }
  2899. },
  2900. 'null': {
  2901. conditionName: function (dt, i18n) {
  2902. return dt.i18n('searchBuilder.conditions.array.empty', i18n.conditions.array.empty);
  2903. },
  2904. init: Criteria.initNoValue,
  2905. isInputValid: function () { return true; },
  2906. inputValue: function () { return; },
  2907. search: function (value) {
  2908. return (value === null || value === undefined || value.length === 0);
  2909. }
  2910. },
  2911. '!null': {
  2912. conditionName: function (dt, i18n) {
  2913. return dt.i18n('searchBuilder.conditions.array.notEmpty', i18n.conditions.array.notEmpty);
  2914. },
  2915. isInputValid: function () { return true; },
  2916. init: Criteria.initNoValue,
  2917. inputValue: function () { return; },
  2918. search: function (value) {
  2919. return (value !== null && value !== undefined && value.length !== 0);
  2920. }
  2921. }
  2922. };
  2923. Criteria.defaults = {
  2924. columns: true,
  2925. conditions: {
  2926. 'array': Criteria.arrayConditions,
  2927. 'date': Criteria.dateConditions,
  2928. 'html': Criteria.stringConditions,
  2929. 'html-num': Criteria.numConditions,
  2930. 'html-num-fmt': Criteria.numFmtConditions,
  2931. 'moment': Criteria.momentDateConditions,
  2932. 'num': Criteria.numConditions,
  2933. 'num-fmt': Criteria.numFmtConditions,
  2934. 'string': Criteria.stringConditions
  2935. },
  2936. depthLimit: false,
  2937. filterChanged: undefined,
  2938. greyscale: false,
  2939. i18n: {
  2940. add: 'Add Condition',
  2941. button: {
  2942. 0: 'Search Builder',
  2943. _: 'Search Builder (%d)'
  2944. },
  2945. clearAll: 'Clear All',
  2946. condition: 'Condition',
  2947. data: 'Data',
  2948. deleteTitle: 'Delete filtering rule',
  2949. leftTitle: 'Outdent criteria',
  2950. logicAnd: 'And',
  2951. logicOr: 'Or',
  2952. rightTitle: 'Indent criteria',
  2953. title: {
  2954. 0: 'Custom Search Builder',
  2955. _: 'Custom Search Builder (%d)'
  2956. },
  2957. value: 'Value',
  2958. valueJoiner: 'and'
  2959. },
  2960. logic: 'AND',
  2961. orthogonal: {
  2962. display: 'display',
  2963. search: 'filter'
  2964. },
  2965. preDefined: false
  2966. };
  2967. return Criteria;
  2968. }());
  2969. var $$1;
  2970. var DataTable$1;
  2971. /**
  2972. * Sets the value of jQuery for use in the file
  2973. * @param jq the instance of jQuery to be set
  2974. */
  2975. function setJQuery$1(jq) {
  2976. $$1 = jq;
  2977. DataTable$1 = jq.fn.dataTable;
  2978. }
  2979. /**
  2980. * The Group class is used within SearchBuilder to represent a group of criteria
  2981. */
  2982. var Group = /** @class */ (function () {
  2983. function Group(table, opts, topGroup, index, isChild, depth) {
  2984. if (index === void 0) { index = 0; }
  2985. if (isChild === void 0) { isChild = false; }
  2986. if (depth === void 0) { depth = 1; }
  2987. // Check that the required version of DataTables is included
  2988. if (!DataTable$1 || !DataTable$1.versionCheck || !DataTable$1.versionCheck('1.10.0')) {
  2989. throw new Error('SearchBuilder requires DataTables 1.10 or newer');
  2990. }
  2991. this.classes = $$1.extend(true, {}, Group.classes);
  2992. // Get options from user
  2993. this.c = $$1.extend(true, {}, Group.defaults, opts);
  2994. this.s = {
  2995. criteria: [],
  2996. depth: depth,
  2997. dt: table,
  2998. index: index,
  2999. isChild: isChild,
  3000. logic: undefined,
  3001. opts: opts,
  3002. toDrop: undefined,
  3003. topGroup: topGroup
  3004. };
  3005. this.dom = {
  3006. add: $$1('<button/>')
  3007. .addClass(this.classes.add)
  3008. .addClass(this.classes.button)
  3009. .attr('type', 'button'),
  3010. clear: $$1('<button>&times</button>')
  3011. .addClass(this.classes.button)
  3012. .addClass(this.classes.clearGroup)
  3013. .attr('type', 'button'),
  3014. container: $$1('<div/>')
  3015. .addClass(this.classes.group),
  3016. logic: $$1('<button/>')
  3017. .addClass(this.classes.logic)
  3018. .addClass(this.classes.button)
  3019. .attr('type', 'button'),
  3020. logicContainer: $$1('<div/>')
  3021. .addClass(this.classes.logicContainer)
  3022. };
  3023. // A reference to the top level group is maintained throughout any subgroups and criteria that may be created
  3024. if (this.s.topGroup === undefined) {
  3025. this.s.topGroup = this.dom.container;
  3026. }
  3027. this._setup();
  3028. return this;
  3029. }
  3030. /**
  3031. * Destroys the groups buttons, clears the internal criteria and removes it from the dom
  3032. */
  3033. Group.prototype.destroy = function () {
  3034. // Turn off listeners
  3035. $$1(this.dom.add).off('.dtsb');
  3036. $$1(this.dom.logic).off('.dtsb');
  3037. // Trigger event for groups at a higher level to pick up on
  3038. $$1(this.dom.container)
  3039. .trigger('dtsb-destroy')
  3040. .remove();
  3041. this.s.criteria = [];
  3042. };
  3043. /**
  3044. * Gets the details required to rebuild the group
  3045. */
  3046. Group.prototype.getDetails = function () {
  3047. if (this.s.criteria.length === 0) {
  3048. return {};
  3049. }
  3050. var details = {
  3051. criteria: [],
  3052. logic: this.s.logic
  3053. };
  3054. // NOTE here crit could be either a subgroup or a criteria
  3055. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  3056. var crit = _a[_i];
  3057. details.criteria.push(crit.criteria.getDetails());
  3058. }
  3059. return details;
  3060. };
  3061. /**
  3062. * Getter for the node for the container of the group
  3063. * @returns Node for the container of the group
  3064. */
  3065. Group.prototype.getNode = function () {
  3066. return this.dom.container;
  3067. };
  3068. /**
  3069. * Rebuilds the group based upon the details passed in
  3070. * @param loadedDetails the details required to rebuild the group
  3071. */
  3072. Group.prototype.rebuild = function (loadedDetails) {
  3073. // If no criteria are stored then just return
  3074. if (loadedDetails.criteria === undefined || loadedDetails.criteria === null || loadedDetails.criteria.length === 0) {
  3075. return;
  3076. }
  3077. this.s.logic = loadedDetails.logic;
  3078. $$1(this.dom.logic).text(this.s.logic === 'OR'
  3079. ? this.s.dt.i18n('searchBuilder.logicOr', this.c.i18n.logicOr)
  3080. : this.s.dt.i18n('searchBuilder.logicAnd', this.c.i18n.logicAnd));
  3081. // Add all of the criteria, be it a sub group or a criteria
  3082. for (var _i = 0, _a = loadedDetails.criteria; _i < _a.length; _i++) {
  3083. var crit = _a[_i];
  3084. if (crit.logic !== undefined) {
  3085. this._addPrevGroup(crit);
  3086. }
  3087. else if (crit.logic === undefined) {
  3088. this._addPrevCriteria(crit);
  3089. }
  3090. }
  3091. // For all of the criteria children, update the arrows incase they require changing and set the listeners
  3092. for (var _b = 0, _c = this.s.criteria; _b < _c.length; _b++) {
  3093. var crit = _c[_b];
  3094. if (crit.criteria instanceof Criteria) {
  3095. crit.criteria.updateArrows(this.s.criteria.length > 1, false);
  3096. this._setCriteriaListeners(crit.criteria);
  3097. }
  3098. }
  3099. };
  3100. /**
  3101. * Redraws the Contents of the searchBuilder Groups and Criteria
  3102. */
  3103. Group.prototype.redrawContents = function () {
  3104. // Clear the container out and add the basic elements
  3105. $$1(this.dom.container)
  3106. .empty()
  3107. .append(this.dom.logicContainer)
  3108. .append(this.dom.add);
  3109. // Sort the criteria by index so that they appear in the correct order
  3110. this.s.criteria.sort(function (a, b) {
  3111. if (a.criteria.s.index < b.criteria.s.index) {
  3112. return -1;
  3113. }
  3114. else if (a.criteria.s.index > b.criteria.s.index) {
  3115. return 1;
  3116. }
  3117. return 0;
  3118. });
  3119. this.setListeners();
  3120. for (var i = 0; i < this.s.criteria.length; i++) {
  3121. var crit = this.s.criteria[i].criteria;
  3122. if (crit instanceof Criteria) {
  3123. // Reset the index to the new value
  3124. this.s.criteria[i].index = i;
  3125. this.s.criteria[i].criteria.s.index = i;
  3126. // Add to the group
  3127. $$1(this.s.criteria[i].criteria.dom.container).insertBefore(this.dom.add);
  3128. // Set listeners for various points
  3129. this._setCriteriaListeners(crit);
  3130. this.s.criteria[i].criteria.rebuild(this.s.criteria[i].criteria.getDetails());
  3131. }
  3132. else if (crit instanceof Group && crit.s.criteria.length > 0) {
  3133. // Reset the index to the new value
  3134. this.s.criteria[i].index = i;
  3135. this.s.criteria[i].criteria.s.index = i;
  3136. // Add the sub group to the group
  3137. $$1(this.s.criteria[i].criteria.dom.container).insertBefore(this.dom.add);
  3138. // Redraw the contents of the group
  3139. crit.redrawContents();
  3140. this._setGroupListeners(crit);
  3141. }
  3142. else {
  3143. // The group is empty so remove it
  3144. this.s.criteria.splice(i, 1);
  3145. i--;
  3146. }
  3147. }
  3148. this.setupLogic();
  3149. };
  3150. /**
  3151. * Search method, checking the row data against the criteria in the group
  3152. * @param rowData The row data to be compared
  3153. * @returns boolean The result of the search
  3154. */
  3155. Group.prototype.search = function (rowData, rowIdx) {
  3156. if (this.s.logic === 'AND') {
  3157. return this._andSearch(rowData, rowIdx);
  3158. }
  3159. else if (this.s.logic === 'OR') {
  3160. return this._orSearch(rowData, rowIdx);
  3161. }
  3162. return true;
  3163. };
  3164. /**
  3165. * Locates the groups logic button to the correct location on the page
  3166. */
  3167. Group.prototype.setupLogic = function () {
  3168. // Remove logic button
  3169. $$1(this.dom.logicContainer).remove();
  3170. $$1(this.dom.clear).remove();
  3171. // If there are no criteria in the group then keep the logic removed and return
  3172. if (this.s.criteria.length < 1) {
  3173. if (!this.s.isChild) {
  3174. $$1(this.dom.container).trigger('dtsb-destroy');
  3175. // Set criteria left margin
  3176. $$1(this.dom.container).css('margin-left', 0);
  3177. }
  3178. return;
  3179. }
  3180. // Set width, take 2 for the border
  3181. var height = $$1(this.dom.container).height() - 2;
  3182. $$1(this.dom.clear).height('0px');
  3183. $$1(this.dom.logicContainer).append(this.dom.clear).width(height);
  3184. // Prepend logic button
  3185. $$1(this.dom.container).prepend(this.dom.logicContainer);
  3186. this._setLogicListener();
  3187. // Set criteria left margin
  3188. $$1(this.dom.container).css('margin-left', $$1(this.dom.logicContainer).outerHeight(true));
  3189. var logicOffset = $$1(this.dom.logicContainer).offset();
  3190. // Set horizontal alignment
  3191. var currentLeft = logicOffset.left;
  3192. var groupLeft = $$1(this.dom.container).offset().left;
  3193. var shuffleLeft = currentLeft - groupLeft;
  3194. var newPos = currentLeft - shuffleLeft - $$1(this.dom.logicContainer).outerHeight(true);
  3195. $$1(this.dom.logicContainer).offset({ left: newPos });
  3196. // Set vertical alignment
  3197. var firstCrit = $$1(this.dom.logicContainer).next();
  3198. var currentTop = logicOffset.top;
  3199. var firstTop = $$1(firstCrit).offset().top;
  3200. var shuffleTop = currentTop - firstTop;
  3201. var newTop = currentTop - shuffleTop;
  3202. $$1(this.dom.logicContainer).offset({ top: newTop });
  3203. $$1(this.dom.clear).outerHeight($$1(this.dom.logicContainer).height());
  3204. this._setClearListener();
  3205. };
  3206. /**
  3207. * Sets listeners on the groups elements
  3208. */
  3209. Group.prototype.setListeners = function () {
  3210. var _this = this;
  3211. $$1(this.dom.add).unbind('click');
  3212. $$1(this.dom.add).on('click', function () {
  3213. // If this is the parent group then the logic button has not been added yet
  3214. if (!_this.s.isChild) {
  3215. $$1(_this.dom.container).prepend(_this.dom.logicContainer);
  3216. }
  3217. _this.addCriteria();
  3218. $$1(_this.dom.container).trigger('dtsb-add');
  3219. _this.s.dt.state.save();
  3220. return false;
  3221. });
  3222. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  3223. var crit = _a[_i];
  3224. crit.criteria.setListeners();
  3225. }
  3226. this._setClearListener();
  3227. this._setLogicListener();
  3228. };
  3229. /**
  3230. * Adds a criteria to the group
  3231. * @param crit Instance of Criteria to be added to the group
  3232. */
  3233. Group.prototype.addCriteria = function (crit, redraw) {
  3234. if (crit === void 0) { crit = null; }
  3235. if (redraw === void 0) { redraw = true; }
  3236. var index = crit === null ? this.s.criteria.length : crit.s.index;
  3237. var criteria = new Criteria(this.s.dt, this.s.opts, this.s.topGroup, index, this.s.depth);
  3238. // If a Criteria has been passed in then set the values to continue that
  3239. if (crit !== null) {
  3240. criteria.c = crit.c;
  3241. criteria.s = crit.s;
  3242. criteria.s.depth = this.s.depth;
  3243. criteria.classes = crit.classes;
  3244. }
  3245. criteria.populate();
  3246. var inserted = false;
  3247. for (var i = 0; i < this.s.criteria.length; i++) {
  3248. if (i === 0 && this.s.criteria[i].criteria.s.index > criteria.s.index) {
  3249. // Add the node for the criteria at the start of the group
  3250. $$1(criteria.getNode()).insertBefore(this.s.criteria[i].criteria.dom.container);
  3251. inserted = true;
  3252. }
  3253. else if (i < this.s.criteria.length - 1 &&
  3254. this.s.criteria[i].criteria.s.index < criteria.s.index &&
  3255. this.s.criteria[i + 1].criteria.s.index > criteria.s.index) {
  3256. // Add the node for the criteria in the correct location
  3257. $$1(criteria.getNode()).insertAfter(this.s.criteria[i].criteria.dom.container);
  3258. inserted = true;
  3259. }
  3260. }
  3261. if (!inserted) {
  3262. $$1(criteria.getNode()).insertBefore(this.dom.add);
  3263. }
  3264. // Add the details for this criteria to the array
  3265. this.s.criteria.push({
  3266. criteria: criteria,
  3267. index: index
  3268. });
  3269. this.s.criteria = this.s.criteria.sort(function (a, b) {
  3270. return a.criteria.s.index - b.criteria.s.index;
  3271. });
  3272. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  3273. var opt = _a[_i];
  3274. if (opt.criteria instanceof Criteria) {
  3275. opt.criteria.updateArrows(this.s.criteria.length > 1, redraw);
  3276. }
  3277. }
  3278. this._setCriteriaListeners(criteria);
  3279. criteria.setListeners();
  3280. this.setupLogic();
  3281. };
  3282. /**
  3283. * Checks the group to see if it has any filled criteria
  3284. */
  3285. Group.prototype.checkFilled = function () {
  3286. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  3287. var crit = _a[_i];
  3288. if ((crit.criteria instanceof Criteria && crit.criteria.s.filled) ||
  3289. (crit.criteria instanceof Group && crit.criteria.checkFilled())) {
  3290. return true;
  3291. }
  3292. }
  3293. return false;
  3294. };
  3295. /**
  3296. * Gets the count for the number of criteria in this group and any sub groups
  3297. */
  3298. Group.prototype.count = function () {
  3299. var count = 0;
  3300. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  3301. var crit = _a[_i];
  3302. if (crit.criteria instanceof Group) {
  3303. count += crit.criteria.count();
  3304. }
  3305. else {
  3306. count++;
  3307. }
  3308. }
  3309. return count;
  3310. };
  3311. /**
  3312. * Rebuilds a sub group that previously existed
  3313. * @param loadedGroup The details of a group within this group
  3314. */
  3315. Group.prototype._addPrevGroup = function (loadedGroup) {
  3316. var idx = this.s.criteria.length;
  3317. var group = new Group(this.s.dt, this.c, this.s.topGroup, idx, true, this.s.depth + 1);
  3318. // Add the new group to the criteria array
  3319. this.s.criteria.push({
  3320. criteria: group,
  3321. index: idx,
  3322. logic: group.s.logic
  3323. });
  3324. // Rebuild it with the previous conditions for that group
  3325. group.rebuild(loadedGroup);
  3326. this.s.criteria[idx].criteria = group;
  3327. $$1(this.s.topGroup).trigger('dtsb-redrawContents');
  3328. this._setGroupListeners(group);
  3329. };
  3330. /**
  3331. * Rebuilds a criteria of this group that previously existed
  3332. * @param loadedCriteria The details of a criteria within the group
  3333. */
  3334. Group.prototype._addPrevCriteria = function (loadedCriteria) {
  3335. var idx = this.s.criteria.length;
  3336. var criteria = new Criteria(this.s.dt, this.s.opts, this.s.topGroup, idx, this.s.depth);
  3337. criteria.populate();
  3338. // Add the new criteria to the criteria array
  3339. this.s.criteria.push({
  3340. criteria: criteria,
  3341. index: idx
  3342. });
  3343. // Rebuild it with the previous conditions for that criteria
  3344. criteria.rebuild(loadedCriteria);
  3345. this.s.criteria[idx].criteria = criteria;
  3346. $$1(this.s.topGroup).trigger('dtsb-redrawContents');
  3347. };
  3348. /**
  3349. * Checks And the criteria using AND logic
  3350. * @param rowData The row data to be checked against the search criteria
  3351. * @returns boolean The result of the AND search
  3352. */
  3353. Group.prototype._andSearch = function (rowData, rowIdx) {
  3354. // If there are no criteria then return true for this group
  3355. if (this.s.criteria.length === 0) {
  3356. return true;
  3357. }
  3358. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  3359. var crit = _a[_i];
  3360. // If the criteria is not complete then skip it
  3361. if (crit.criteria instanceof Criteria && !crit.criteria.s.filled) {
  3362. continue;
  3363. }
  3364. // Otherwise if a single one fails return false
  3365. else if (!crit.criteria.search(rowData, rowIdx)) {
  3366. return false;
  3367. }
  3368. }
  3369. // If we get to here then everything has passed, so return true for the group
  3370. return true;
  3371. };
  3372. /**
  3373. * Checks And the criteria using OR logic
  3374. * @param rowData The row data to be checked against the search criteria
  3375. * @returns boolean The result of the OR search
  3376. */
  3377. Group.prototype._orSearch = function (rowData, rowIdx) {
  3378. // If there are no criteria in the group then return true
  3379. if (this.s.criteria.length === 0) {
  3380. return true;
  3381. }
  3382. // This will check to make sure that at least one criteria in the group is complete
  3383. var filledfound = false;
  3384. for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
  3385. var crit = _a[_i];
  3386. if (crit.criteria instanceof Criteria && crit.criteria.s.filled) {
  3387. // A completed criteria has been found so set the flag
  3388. filledfound = true;
  3389. // If the search passes then return true
  3390. if (crit.criteria.search(rowData, rowIdx)) {
  3391. return true;
  3392. }
  3393. }
  3394. else if (crit.criteria instanceof Group && crit.criteria.checkFilled()) {
  3395. filledfound = true;
  3396. if (crit.criteria.search(rowData, rowIdx)) {
  3397. return true;
  3398. }
  3399. }
  3400. }
  3401. // If we get here we need to return the inverse of filledfound,
  3402. // as if any have been found and we are here then none have passed
  3403. return !filledfound;
  3404. };
  3405. /**
  3406. * Removes a criteria from the group
  3407. * @param criteria The criteria instance to be removed
  3408. */
  3409. Group.prototype._removeCriteria = function (criteria, group) {
  3410. if (group === void 0) { group = false; }
  3411. // If removing a criteria and there is only then then just destroy the group
  3412. if (this.s.criteria.length <= 1 && this.s.isChild) {
  3413. this.destroy();
  3414. }
  3415. else {
  3416. // Otherwise splice the given criteria out and redo the indexes
  3417. var last = void 0;
  3418. for (var i = 0; i < this.s.criteria.length; i++) {
  3419. if (this.s.criteria[i].index === criteria.s.index && (!group || this.s.criteria[i].criteria instanceof Group)) {
  3420. last = i;
  3421. }
  3422. }
  3423. // We want to remove the last element with the desired index, as its replacement will be inserted before it
  3424. if (last !== undefined) {
  3425. this.s.criteria.splice(last, 1);
  3426. }
  3427. for (var i = 0; i < this.s.criteria.length; i++) {
  3428. this.s.criteria[i].index = i;
  3429. this.s.criteria[i].criteria.s.index = i;
  3430. }
  3431. }
  3432. };
  3433. /**
  3434. * Sets the listeners in group for a criteria
  3435. * @param criteria The criteria for the listeners to be set on
  3436. */
  3437. Group.prototype._setCriteriaListeners = function (criteria) {
  3438. var _this = this;
  3439. $$1(criteria.dom["delete"])
  3440. .unbind('click')
  3441. .on('click', function () {
  3442. _this._removeCriteria(criteria);
  3443. $$1(criteria.dom.container).remove();
  3444. for (var _i = 0, _a = _this.s.criteria; _i < _a.length; _i++) {
  3445. var crit = _a[_i];
  3446. if (crit.criteria instanceof Criteria) {
  3447. crit.criteria.updateArrows(_this.s.criteria.length > 1);
  3448. }
  3449. }
  3450. criteria.destroy();
  3451. _this.s.dt.draw();
  3452. $$1(_this.s.topGroup).trigger('dtsb-redrawContents');
  3453. $$1(_this.s.topGroup).trigger('dtsb-updateTitle');
  3454. return false;
  3455. });
  3456. $$1(criteria.dom.right)
  3457. .unbind('click')
  3458. .on('click', function () {
  3459. var idx = criteria.s.index;
  3460. var group = new Group(_this.s.dt, _this.s.opts, _this.s.topGroup, criteria.s.index, true, _this.s.depth + 1);
  3461. // Add the criteria that is to be moved to the new group
  3462. group.addCriteria(criteria);
  3463. // Update the details in the current groups criteria array
  3464. _this.s.criteria[idx].criteria = group;
  3465. _this.s.criteria[idx].logic = 'AND';
  3466. $$1(_this.s.topGroup).trigger('dtsb-redrawContents');
  3467. _this._setGroupListeners(group);
  3468. return false;
  3469. });
  3470. $$1(criteria.dom.left)
  3471. .unbind('click')
  3472. .on('click', function () {
  3473. _this.s.toDrop = new Criteria(_this.s.dt, _this.s.opts, _this.s.topGroup, criteria.s.index);
  3474. _this.s.toDrop.s = criteria.s;
  3475. _this.s.toDrop.c = criteria.c;
  3476. _this.s.toDrop.classes = criteria.classes;
  3477. _this.s.toDrop.populate();
  3478. // The dropCriteria event mutates the reference to the index so need to store it
  3479. var index = _this.s.toDrop.s.index;
  3480. $$1(_this.dom.container).trigger('dtsb-dropCriteria');
  3481. criteria.s.index = index;
  3482. _this._removeCriteria(criteria);
  3483. // By tracking the top level group we can directly trigger a redraw on it,
  3484. // bubbling is also possible, but that is slow with deep levelled groups
  3485. $$1(_this.s.topGroup).trigger('dtsb-redrawContents');
  3486. _this.s.dt.draw();
  3487. return false;
  3488. });
  3489. };
  3490. /**
  3491. * Set's the listeners for the group clear button
  3492. */
  3493. Group.prototype._setClearListener = function () {
  3494. var _this = this;
  3495. $$1(this.dom.clear)
  3496. .unbind('click')
  3497. .on('click', function () {
  3498. if (!_this.s.isChild) {
  3499. $$1(_this.dom.container).trigger('dtsb-clearContents');
  3500. return false;
  3501. }
  3502. _this.destroy();
  3503. $$1(_this.s.topGroup).trigger('dtsb-updateTitle');
  3504. $$1(_this.s.topGroup).trigger('dtsb-redrawContents');
  3505. return false;
  3506. });
  3507. };
  3508. /**
  3509. * Sets listeners for sub groups of this group
  3510. * @param group The sub group that the listeners are to be set on
  3511. */
  3512. Group.prototype._setGroupListeners = function (group) {
  3513. var _this = this;
  3514. // Set listeners for the new group
  3515. $$1(group.dom.add)
  3516. .unbind('click')
  3517. .on('click', function () {
  3518. _this.setupLogic();
  3519. $$1(_this.dom.container).trigger('dtsb-add');
  3520. return false;
  3521. });
  3522. $$1(group.dom.container)
  3523. .unbind('dtsb-add')
  3524. .on('dtsb-add', function () {
  3525. _this.setupLogic();
  3526. $$1(_this.dom.container).trigger('dtsb-add');
  3527. return false;
  3528. });
  3529. $$1(group.dom.container)
  3530. .unbind('dtsb-destroy')
  3531. .on('dtsb-destroy', function () {
  3532. _this._removeCriteria(group, true);
  3533. $$1(group.dom.container).remove();
  3534. _this.setupLogic();
  3535. return false;
  3536. });
  3537. $$1(group.dom.container)
  3538. .unbind('dtsb-dropCriteria')
  3539. .on('dtsb-dropCriteria', function () {
  3540. var toDrop = group.s.toDrop;
  3541. toDrop.s.index = group.s.index;
  3542. toDrop.updateArrows(_this.s.criteria.length > 1, false);
  3543. _this.addCriteria(toDrop, false);
  3544. return false;
  3545. });
  3546. group.setListeners();
  3547. };
  3548. /**
  3549. * Sets up the Group instance, setting listeners and appending elements
  3550. */
  3551. Group.prototype._setup = function () {
  3552. this.setListeners();
  3553. $$1(this.dom.add).text(this.s.dt.i18n('searchBuilder.add', this.c.i18n.add));
  3554. $$1(this.dom.logic).text(this.c.logic === 'OR'
  3555. ? this.s.dt.i18n('searchBuilder.logicOr', this.c.i18n.logicOr)
  3556. : this.s.dt.i18n('searchBuilder.logicAnd', this.c.i18n.logicAnd));
  3557. this.s.logic = this.c.logic === 'OR' ? 'OR' : 'AND';
  3558. if (this.c.greyscale) {
  3559. $$1(this.dom.logic).addClass(this.classes.greyscale);
  3560. }
  3561. $$1(this.dom.logicContainer).append(this.dom.logic).append(this.dom.clear);
  3562. // Only append the logic button immediately if this is a sub group,
  3563. // otherwise it will be prepended later when adding a criteria
  3564. if (this.s.isChild) {
  3565. $$1(this.dom.container).append(this.dom.logicContainer);
  3566. }
  3567. $$1(this.dom.container).append(this.dom.add);
  3568. };
  3569. /**
  3570. * Sets the listener for the logic button
  3571. */
  3572. Group.prototype._setLogicListener = function () {
  3573. var _this = this;
  3574. $$1(this.dom.logic)
  3575. .unbind('click')
  3576. .on('click', function () {
  3577. _this._toggleLogic();
  3578. _this.s.dt.draw();
  3579. for (var _i = 0, _a = _this.s.criteria; _i < _a.length; _i++) {
  3580. var crit = _a[_i];
  3581. crit.criteria.setListeners();
  3582. }
  3583. });
  3584. };
  3585. /**
  3586. * Toggles the logic for the group
  3587. */
  3588. Group.prototype._toggleLogic = function () {
  3589. if (this.s.logic === 'OR') {
  3590. this.s.logic = 'AND';
  3591. $$1(this.dom.logic).text(this.s.dt.i18n('searchBuilder.logicAnd', this.c.i18n.logicAnd));
  3592. }
  3593. else if (this.s.logic === 'AND') {
  3594. this.s.logic = 'OR';
  3595. $$1(this.dom.logic).text(this.s.dt.i18n('searchBuilder.logicOr', this.c.i18n.logicOr));
  3596. }
  3597. };
  3598. Group.version = '1.0.0';
  3599. Group.classes = {
  3600. add: 'dtsb-add',
  3601. button: 'dtsb-button',
  3602. clearGroup: 'dtsb-clearGroup',
  3603. greyscale: 'dtsb-greyscale',
  3604. group: 'dtsb-group',
  3605. inputButton: 'dtsb-iptbtn',
  3606. logic: 'dtsb-logic',
  3607. logicContainer: 'dtsb-logicContainer'
  3608. };
  3609. Group.defaults = {
  3610. columns: true,
  3611. conditions: {
  3612. 'date': Criteria.dateConditions,
  3613. 'html': Criteria.stringConditions,
  3614. 'html-num': Criteria.numConditions,
  3615. 'html-num-fmt': Criteria.numFmtConditions,
  3616. 'moment': Criteria.momentDateConditions,
  3617. 'num': Criteria.numConditions,
  3618. 'num-fmt': Criteria.numFmtConditions,
  3619. 'string': Criteria.stringConditions
  3620. },
  3621. depthLimit: false,
  3622. filterChanged: undefined,
  3623. greyscale: false,
  3624. i18n: {
  3625. add: 'Add Condition',
  3626. button: {
  3627. 0: 'Search Builder',
  3628. _: 'Search Builder (%d)'
  3629. },
  3630. clearAll: 'Clear All',
  3631. condition: 'Condition',
  3632. data: 'Data',
  3633. deleteTitle: 'Delete filtering rule',
  3634. leftTitle: 'Outdent criteria',
  3635. logicAnd: 'And',
  3636. logicOr: 'Or',
  3637. rightTitle: 'Indent criteria',
  3638. title: {
  3639. 0: 'Custom Search Builder',
  3640. _: 'Custom Search Builder (%d)'
  3641. },
  3642. value: 'Value',
  3643. valueJoiner: 'and'
  3644. },
  3645. logic: 'AND',
  3646. orthogonal: {
  3647. display: 'display',
  3648. search: 'filter'
  3649. },
  3650. preDefined: false
  3651. };
  3652. return Group;
  3653. }());
  3654. var $$2;
  3655. var DataTable$2;
  3656. /**
  3657. * Sets the value of jQuery for use in the file
  3658. * @param jq the instance of jQuery to be set
  3659. */
  3660. function setJQuery$2(jq) {
  3661. $$2 = jq;
  3662. DataTable$2 = jq.fn.DataTable;
  3663. }
  3664. /**
  3665. * SearchBuilder class for DataTables.
  3666. * Allows for complex search queries to be constructed and implemented on a DataTable
  3667. */
  3668. var SearchBuilder = /** @class */ (function () {
  3669. function SearchBuilder(builderSettings, opts) {
  3670. var _this = this;
  3671. // Check that the required version of DataTables is included
  3672. if (!DataTable$2 || !DataTable$2.versionCheck || !DataTable$2.versionCheck('1.10.0')) {
  3673. throw new Error('SearchBuilder requires DataTables 1.10 or newer');
  3674. }
  3675. var table = new DataTable$2.Api(builderSettings);
  3676. this.classes = $$2.extend(true, {}, SearchBuilder.classes);
  3677. // Get options from user
  3678. this.c = $$2.extend(true, {}, SearchBuilder.defaults, opts);
  3679. this.dom = {
  3680. clearAll: $$2('<button type="button">' + table.i18n('searchBuilder.clearAll', this.c.i18n.clearAll) + '</button>')
  3681. .addClass(this.classes.clearAll)
  3682. .addClass(this.classes.button)
  3683. .attr('type', 'button'),
  3684. container: $$2('<div/>')
  3685. .addClass(this.classes.container),
  3686. title: $$2('<div/>')
  3687. .addClass(this.classes.title),
  3688. titleRow: $$2('<div/>')
  3689. .addClass(this.classes.titleRow),
  3690. topGroup: undefined
  3691. };
  3692. this.s = {
  3693. dt: table,
  3694. opts: opts,
  3695. search: undefined,
  3696. topGroup: undefined
  3697. };
  3698. // If searchbuilder is already defined for this table then return
  3699. if (table.settings()[0]._searchBuilder !== undefined) {
  3700. return;
  3701. }
  3702. table.settings()[0]._searchBuilder = this;
  3703. // Run the remaining setup when the table is initialised
  3704. if (this.s.dt.settings()[0]._bInitComplete) {
  3705. this._setUp();
  3706. }
  3707. else {
  3708. table.one('init.dt', function () {
  3709. _this._setUp();
  3710. });
  3711. }
  3712. return this;
  3713. }
  3714. /**
  3715. * Gets the details required to rebuild the SearchBuilder as it currently is
  3716. */
  3717. SearchBuilder.prototype.getDetails = function () {
  3718. return this.s.topGroup.getDetails();
  3719. };
  3720. /**
  3721. * Getter for the node of the container for the searchBuilder
  3722. * @returns JQuery<HTMLElement> the node of the container
  3723. */
  3724. SearchBuilder.prototype.getNode = function () {
  3725. return this.dom.container;
  3726. };
  3727. /**
  3728. * Rebuilds the SearchBuilder to a state that is provided
  3729. * @param details The details required to perform a rebuild
  3730. */
  3731. SearchBuilder.prototype.rebuild = function (details) {
  3732. $$2(this.dom.clearAll).click();
  3733. // If there are no details to rebuild then return
  3734. if (details === undefined || details === null) {
  3735. return this;
  3736. }
  3737. this.s.topGroup.rebuild(details);
  3738. this.s.dt.draw();
  3739. this.s.topGroup.setListeners();
  3740. return this;
  3741. };
  3742. /**
  3743. * Applies the defaults to preDefined criteria
  3744. * @param preDef the array of criteria to be processed.
  3745. */
  3746. SearchBuilder.prototype._applyPreDefDefaults = function (preDef) {
  3747. var _this = this;
  3748. if (preDef.criteria !== undefined && preDef.logic === undefined) {
  3749. preDef.logic = 'AND';
  3750. }
  3751. var _loop_1 = function (crit) {
  3752. // Apply the defaults to any further criteria
  3753. if (crit.criteria !== undefined) {
  3754. crit = this_1._applyPreDefDefaults(crit);
  3755. }
  3756. else {
  3757. this_1.s.dt.columns().every(function (index) {
  3758. if (_this.s.dt.settings()[0].aoColumns[index].sTitle === crit.data) {
  3759. crit.dataIdx = index;
  3760. }
  3761. });
  3762. }
  3763. };
  3764. var this_1 = this;
  3765. for (var _i = 0, _a = preDef.criteria; _i < _a.length; _i++) {
  3766. var crit = _a[_i];
  3767. _loop_1(crit);
  3768. }
  3769. return preDef;
  3770. };
  3771. /**
  3772. * Set's up the SearchBuilder
  3773. */
  3774. SearchBuilder.prototype._setUp = function (loadState) {
  3775. var _this = this;
  3776. if (loadState === void 0) { loadState = true; }
  3777. this.s.topGroup = new Group(this.s.dt, this.c, undefined);
  3778. this._setClearListener();
  3779. this.s.dt.on('stateSaveParams', function (e, settings, data) {
  3780. data.searchBuilder = _this.getDetails();
  3781. data.page = _this.s.dt.page();
  3782. });
  3783. this._build();
  3784. if (loadState) {
  3785. var loadedState = this.s.dt.state.loaded();
  3786. // If the loaded State is not null rebuild based on it for statesave
  3787. if (loadedState !== null && loadedState.searchBuilder !== undefined) {
  3788. this.s.topGroup.rebuild(loadedState.searchBuilder);
  3789. $$2(this.s.topGroup.dom.container).trigger('dtsb-redrawContents');
  3790. this.s.dt.page(loadedState.page).draw('page');
  3791. this.s.topGroup.setListeners();
  3792. }
  3793. // Otherwise load any predefined options
  3794. else if (this.c.preDefined !== false) {
  3795. this.c.preDefined = this._applyPreDefDefaults(this.c.preDefined);
  3796. this.rebuild(this.c.preDefined);
  3797. }
  3798. }
  3799. this._setEmptyListener();
  3800. this.s.dt.state.save();
  3801. };
  3802. /**
  3803. * Updates the title of the SearchBuilder
  3804. * @param count the number of filters in the SearchBuilder
  3805. */
  3806. SearchBuilder.prototype._updateTitle = function (count) {
  3807. $$2(this.dom.title).text(this.s.dt.i18n('searchBuilder.title', this.c.i18n.title, count));
  3808. };
  3809. /**
  3810. * Builds all of the dom elements together
  3811. */
  3812. SearchBuilder.prototype._build = function () {
  3813. var _this = this;
  3814. // Empty and setup the container
  3815. $$2(this.dom.clearAll).remove();
  3816. $$2(this.dom.container).empty();
  3817. var count = this.s.topGroup.count();
  3818. this._updateTitle(count);
  3819. $$2(this.dom.titleRow).append(this.dom.title);
  3820. $$2(this.dom.container).append(this.dom.titleRow);
  3821. this.dom.topGroup = this.s.topGroup.getNode();
  3822. $$2(this.dom.container).append(this.dom.topGroup);
  3823. this._setRedrawListener();
  3824. var tableNode = this.s.dt.table(0).node();
  3825. if ($$2.fn.dataTable.ext.search.indexOf(this.s.search) === -1) {
  3826. // Custom search function for SearchBuilder
  3827. this.s.search = function (settings, searchData, dataIndex, origData) {
  3828. if (settings.nTable !== tableNode) {
  3829. return true;
  3830. }
  3831. return _this.s.topGroup.search(searchData, dataIndex);
  3832. };
  3833. // Add SearchBuilder search function to the dataTables search array
  3834. $$2.fn.dataTable.ext.search.push(this.s.search);
  3835. }
  3836. // Register an Api method for getting the column type
  3837. $$2.fn.DataTable.Api.registerPlural('columns().type()', 'column().type()', function (selector, opts) {
  3838. return this.iterator('column', function (settings, column) {
  3839. return settings.aoColumns[column].sType;
  3840. }, 1);
  3841. });
  3842. this.s.dt.on('destroy.dt', function () {
  3843. $$2(_this.dom.container).remove();
  3844. $$2(_this.dom.clearAll).remove();
  3845. var searchIdx = $$2.fn.dataTable.ext.search.indexOf(_this.s.search);
  3846. while (searchIdx !== -1) {
  3847. $$2.fn.dataTable.ext.search.splice(searchIdx, 1);
  3848. searchIdx = $$2.fn.dataTable.ext.search.indexOf(_this.s.search);
  3849. }
  3850. });
  3851. };
  3852. /**
  3853. * Checks if the clearAll button should be added or not
  3854. */
  3855. SearchBuilder.prototype._checkClear = function () {
  3856. if (this.s.topGroup.s.criteria.length > 0) {
  3857. $$2(this.dom.clearAll).insertAfter(this.dom.title);
  3858. this._setClearListener();
  3859. }
  3860. else {
  3861. $$2(this.dom.clearAll).remove();
  3862. }
  3863. };
  3864. /**
  3865. * Update the count in the title/button
  3866. * @param count Number of filters applied
  3867. */
  3868. SearchBuilder.prototype._filterChanged = function (count) {
  3869. var fn = this.c.filterChanged;
  3870. if (typeof fn === 'function') {
  3871. fn(count, this.s.dt.i18n('searchBuilder.button', this.c.i18n.button, count));
  3872. }
  3873. };
  3874. /**
  3875. * Set the listener for the clear button
  3876. */
  3877. SearchBuilder.prototype._setClearListener = function () {
  3878. var _this = this;
  3879. $$2(this.dom.clearAll).unbind('click');
  3880. $$2(this.dom.clearAll).on('click', function () {
  3881. _this.s.topGroup = new Group(_this.s.dt, _this.c, undefined);
  3882. _this._build();
  3883. _this.s.dt.draw();
  3884. _this.s.topGroup.setListeners();
  3885. $$2(_this.dom.clearAll).remove();
  3886. _this._setEmptyListener();
  3887. _this._filterChanged(0);
  3888. return false;
  3889. });
  3890. };
  3891. /**
  3892. * Set the listener for the Redraw event
  3893. */
  3894. SearchBuilder.prototype._setRedrawListener = function () {
  3895. var _this = this;
  3896. $$2(this.s.topGroup.dom.container).unbind('dtsb-redrawContents');
  3897. $$2(this.s.topGroup.dom.container).on('dtsb-redrawContents', function () {
  3898. _this._checkClear();
  3899. _this.s.topGroup.redrawContents();
  3900. _this.s.topGroup.setupLogic();
  3901. _this._setEmptyListener();
  3902. var count = _this.s.topGroup.count();
  3903. _this._updateTitle(count);
  3904. _this._filterChanged(count);
  3905. _this.s.dt.state.save();
  3906. });
  3907. $$2(this.s.topGroup.dom.container).unbind('dtsb-clearContents');
  3908. $$2(this.s.topGroup.dom.container).on('dtsb-clearContents', function () {
  3909. _this._setUp(false);
  3910. _this._filterChanged(0);
  3911. _this.s.dt.draw();
  3912. });
  3913. $$2(this.s.topGroup.dom.container).on('dtsb-updateTitle', function () {
  3914. var count = _this.s.topGroup.count();
  3915. _this._updateTitle(count);
  3916. _this._filterChanged(count);
  3917. });
  3918. };
  3919. /**
  3920. * Sets listeners to check whether clearAll should be added or removed
  3921. */
  3922. SearchBuilder.prototype._setEmptyListener = function () {
  3923. var _this = this;
  3924. $$2(this.s.topGroup.dom.add).on('click', function () {
  3925. _this._checkClear();
  3926. });
  3927. $$2(this.s.topGroup.dom.container).on('dtsb-destroy', function () {
  3928. $$2(_this.dom.clearAll).remove();
  3929. });
  3930. };
  3931. SearchBuilder.version = '1.0.1';
  3932. SearchBuilder.classes = {
  3933. button: 'dtsb-button',
  3934. clearAll: 'dtsb-clearAll',
  3935. container: 'dtsb-searchBuilder',
  3936. inputButton: 'dtsb-iptbtn',
  3937. title: 'dtsb-title',
  3938. titleRow: 'dtsb-titleRow'
  3939. };
  3940. SearchBuilder.defaults = {
  3941. columns: true,
  3942. conditions: {
  3943. 'date': Criteria.dateConditions,
  3944. 'html': Criteria.stringConditions,
  3945. 'html-num': Criteria.numConditions,
  3946. 'html-num-fmt': Criteria.numFmtConditions,
  3947. 'moment': Criteria.momentDateConditions,
  3948. 'num': Criteria.numConditions,
  3949. 'num-fmt': Criteria.numFmtConditions,
  3950. 'string': Criteria.stringConditions
  3951. },
  3952. depthLimit: false,
  3953. filterChanged: undefined,
  3954. greyscale: false,
  3955. i18n: {
  3956. add: 'Add Condition',
  3957. button: {
  3958. 0: 'Search Builder',
  3959. _: 'Search Builder (%d)'
  3960. },
  3961. clearAll: 'Clear All',
  3962. condition: 'Condition',
  3963. conditions: {
  3964. array: {
  3965. contains: 'Contains',
  3966. empty: 'Empty',
  3967. equals: 'Equals',
  3968. not: 'Not',
  3969. notEmpty: 'Not Empty',
  3970. without: 'Without'
  3971. },
  3972. date: {
  3973. after: 'After',
  3974. before: 'Before',
  3975. between: 'Between',
  3976. empty: 'Empty',
  3977. equals: 'Equals',
  3978. not: 'Not',
  3979. notBetween: 'Not Between',
  3980. notEmpty: 'Not Empty'
  3981. },
  3982. moment: {
  3983. after: 'After',
  3984. before: 'Before',
  3985. between: 'Between',
  3986. empty: 'Empty',
  3987. equals: 'Equals',
  3988. not: 'Not',
  3989. notBetween: 'Not Between',
  3990. notEmpty: 'Not Empty'
  3991. },
  3992. number: {
  3993. between: 'Between',
  3994. empty: 'Empty',
  3995. equals: 'Equals',
  3996. gt: 'Greater Than',
  3997. gte: 'Greater Than Equal To',
  3998. lt: 'Less Than',
  3999. lte: 'Less Than Equal To',
  4000. not: 'Not',
  4001. notBetween: 'Not Between',
  4002. notEmpty: 'Not Empty'
  4003. },
  4004. string: {
  4005. contains: 'Contains',
  4006. empty: 'Empty',
  4007. endsWith: 'Ends With',
  4008. equals: 'Equals',
  4009. not: 'Not',
  4010. notEmpty: 'Not Empty',
  4011. startsWith: 'Starts With'
  4012. }
  4013. },
  4014. data: 'Data',
  4015. deleteTitle: 'Delete filtering rule',
  4016. leftTitle: 'Outdent criteria',
  4017. logicAnd: 'And',
  4018. logicOr: 'Or',
  4019. rightTitle: 'Indent criteria',
  4020. title: {
  4021. 0: 'Custom Search Builder',
  4022. _: 'Custom Search Builder (%d)'
  4023. },
  4024. value: 'Value',
  4025. valueJoiner: 'and'
  4026. },
  4027. logic: 'AND',
  4028. orthogonal: {
  4029. display: 'display',
  4030. search: 'filter'
  4031. },
  4032. preDefined: false
  4033. };
  4034. return SearchBuilder;
  4035. }());
  4036. /*! SearchBuilder 1.0.1
  4037. * ©2020 SpryMedia Ltd - datatables.net/license/mit
  4038. */
  4039. // DataTables extensions common UMD. Note that this allows for AMD, CommonJS
  4040. // (with window and jQuery being allowed as parameters to the returned
  4041. // function) or just default browser loading.
  4042. (function (factory) {
  4043. if (typeof define === 'function' && define.amd) {
  4044. // AMD
  4045. define(['jquery', 'datatables.net'], function ($) {
  4046. return factory($, window, document);
  4047. });
  4048. }
  4049. else if (typeof exports === 'object') {
  4050. // CommonJS
  4051. module.exports = function (root, $) {
  4052. if (!root) {
  4053. root = window;
  4054. }
  4055. if (!$ || !$.fn.dataTable) {
  4056. $ = require('datatables.net')(root, $).$;
  4057. }
  4058. return factory($, root, root.document);
  4059. };
  4060. }
  4061. else {
  4062. // Browser - assume jQuery has already been loaded
  4063. factory(window.jQuery, window, document);
  4064. }
  4065. }(function ($, window, document) {
  4066. setJQuery$2($);
  4067. setJQuery$1($);
  4068. setJQuery($);
  4069. var DataTable = $.fn.dataTable;
  4070. $.fn.dataTable.SearchBuilder = SearchBuilder;
  4071. $.fn.DataTable.SearchBuilder = SearchBuilder;
  4072. $.fn.dataTable.Group = Group;
  4073. $.fn.DataTable.Group = Group;
  4074. $.fn.dataTable.Criteria = Criteria;
  4075. $.fn.DataTable.Criteria = Criteria;
  4076. var apiRegister = $.fn.dataTable.Api.register;
  4077. // Set up object for plugins
  4078. $.fn.dataTable.ext.searchBuilder = {
  4079. conditions: {}
  4080. };
  4081. $.fn.dataTable.ext.buttons.searchBuilder = {
  4082. action: function (e, dt, node, config) {
  4083. e.stopPropagation();
  4084. this.popover(config._searchBuilder.getNode(), {
  4085. align: 'dt-container'
  4086. });
  4087. },
  4088. config: {},
  4089. init: function (dt, node, config) {
  4090. var sb = new $.fn.dataTable.SearchBuilder(dt, $.extend({
  4091. filterChanged: function (count, text) {
  4092. dt.button(node).text(text);
  4093. }
  4094. }, config.config));
  4095. dt.button(node).text(config.text || dt.i18n('searchBuilder.button', sb.c.i18n.button, 0));
  4096. config._searchBuilder = sb;
  4097. },
  4098. text: null
  4099. };
  4100. apiRegister('searchBuilder.getDetails()', function () {
  4101. var ctx = this.context[0];
  4102. return ctx._searchBuilder.getDetails();
  4103. });
  4104. apiRegister('searchBuilder.rebuild()', function (details) {
  4105. var ctx = this.context[0];
  4106. ctx._searchBuilder.rebuild(details);
  4107. return this;
  4108. });
  4109. apiRegister('searchBuilder.container()', function () {
  4110. var ctx = this.context[0];
  4111. return ctx._searchBuilder.getNode();
  4112. });
  4113. /**
  4114. * Init function for SearchBuilder
  4115. * @param settings the settings to be applied
  4116. * @param options the options for SearchBuilder
  4117. * @returns JQUERY<HTMLElement> Returns the node of the SearchBuilder
  4118. */
  4119. function _init(settings, options) {
  4120. var api = new DataTable.Api(settings);
  4121. var opts = options
  4122. ? options
  4123. : api.init().searchBuilder || DataTable.defaults.searchBuilder;
  4124. var searchBuilder = new SearchBuilder(api, opts);
  4125. var node = searchBuilder.getNode();
  4126. return node;
  4127. }
  4128. // Attach a listener to the document which listens for DataTables initialisation
  4129. // events so we can automatically initialise
  4130. $(document).on('preInit.dt.dtsp', function (e, settings, json) {
  4131. if (e.namespace !== 'dt') {
  4132. return;
  4133. }
  4134. if (settings.oInit.searchBuilder ||
  4135. DataTable.defaults.searchBuilder) {
  4136. if (!settings._searchBuilder) {
  4137. _init(settings);
  4138. }
  4139. }
  4140. });
  4141. // DataTables `dom` feature option
  4142. DataTable.ext.feature.push({
  4143. cFeature: 'Q',
  4144. fnInit: _init
  4145. });
  4146. // DataTables 2 layout feature
  4147. if (DataTable.ext.features) {
  4148. DataTable.ext.features.register('searchBuilder', _init);
  4149. }
  4150. }));
  4151. }());