Files
PyRIGS/RIGS/static/js/ajax-bootstrap-select.js
Arona Jones 3414204209 Refactor buildsystem to NPM/Gulp, port to BS4 & rewrite RIGS tests accordingly... (#412)
* Start to seperate versioning into its own app

* Start reworking invoice things

* Reduced overall font size a touch

* Improvements to generic lists

* Tweak some colours to be a bit less OTT

I need to work out if I can seperate background and primary colours like BS3 did

* Improvements to event table mobile

* First pass at mobile-ising the generic list

* Item table fixes

* Fixed fullcalendar print css not included

* Asset list table improvements

* Tweak asset list to be more in line with other lists

* Versioning template improvements

//TODO Rather than have seperate asset templates, convert 'id' into a template variable

* Tweak versioning templates to allow ID overrides

Asset specific templates begone. Still need to bring back the ID formatting for the Rigboard.

* Asset form fixes

* Use the right autocompleter.js...

* Breakout (most) user stuff to separate module

The model remains in RIGS for now, as it's pretty painful to move...

* Python Format/import opt

* Test Refactor Part 1 - Shuffle things around

* Fix migrations

TODO - need to ensure moved models are *moved* rather than deleted and recreated!

* Start on new tests

* Initial work on event create test reimpl

* Init other tests, more rigs test faffery

* Desaturate theme colors even more

Much closer to BS3

* Fix event item adding

Bit too heavy handed with the deduplication there Arona

* Initial refactor of event item testing

* Upgrade bootstrap-select

* Updated bootstrap-select for BS4

* Initial port of duplicate testing

Needs the latter half rewriting once we have an EventDetail POM

* Refactor date validation test

So close to killing test_functional.EventTest!

* Deduplication of testing code

* pep8

* Fix some tests

And some things that were actually borked

* FIX: Prevent setting access time after start time 

Cherry pick of d274ea4606. Will close #405.

* Refactor calendar tests

* FIX: Don't show asset buttons/history for basic users

* Really ought to get a pre-commit hook for pep8...

* Fully replace test_functional

* Dedupe generic search logic

* Fix the remaining tests

* Ensure submit button is scrolled to in tests

* Fix asset creation test + actually verify its results

* Make CI use latest (stable) chromedriver rather than some ancient one

Since Travis uses the latest stable chrome, should always match. Bash oneliner \o/

* Of course | is part of YAML syntax, of course...

Maybe this works.

* Update python version

Trying to get CI to match my local environment as much as possible...

* Minor test futzing

* Well that wasn't clever of me

* That was even less clever of me

* Revert to old submit wait behaviour

* What about if I did this

* Try disabling chrome cache

* Added screenshot recording of test failures

* Fixed RIGS tests not being run

* Fixed Pep8 - I promise I'll make a pre-commit hook sometime!

* Very initial work at togglable darktheme.

Dammit @alexdaniel654 just when I had my scope creep kinda under control. It'll be v. nice to have though...!

* More dark theme wangling

* Fix some asset template things

* FIX: CI Locale Issues

* Fix sample command

* Initial work at integrating the risk assessment

#136. No clever database structure as yet...

* FIX: Don't set every boolean input to radios

* Different approach to RA linking

* Move text definitions to somewhere more authoratitive

* FIX: Undo breakage causing autopep8

o.O

* Expand detail template

* Use correct view for RA history

* Initial work at coercing activity feed into showing RAs

Also shows Asset/Supplier on the homepage feed.

* Refactor activity feed template logic

Yay for removing arbitrary if/else chains!

* Initial work on caching activity feed

Server side that is. Ref #162.

* Start RA list template

* Refactor RA creation stuff, again

* Add H&S Details to Event Detail View

* Display venue notes in event detail

Notes are no use if nobody reads them. Not sure on this one.

* Add ability to filter event archive by status

Closes #168.

* Fix lingering naive time

* Use locmem cache in sqlite environments

Otherwise the tests just lock up totally. Should close #162

* Update dependencies

Mirrors/supersedes 0e67da82e2

* Add global ctrl/meta-enter shortcut for form submission

Wants rewriting for better efficiency, but hey, it works!

* Update dependencies

* Fix for a situation that should be impossible

* Fix navbar alignment

* FEAT: Improve 'omni'search

- Partialised template
- Added to assets header
- Added ability to search assets/suppliers
- Improved selection logic
- Have it display current query

* Move closemodal into PyRIGS

* Fix tests for search improvements

* Dark mode colour improvements

* Fix table colors for dry hires

* further darktheme fixes

* Remove the dark header from light theme

* Fix reload loops when CSS/JS is changed

* Move dark theme SCSS to separate file, fix inactive pagination styling

* Genercise detail pages

* Testing something re notes

I wonder if I can make that global, rather than per-template...

* Dark theme palette shenanigans

I just can't decide

* Match darktheme palette to forum darktheme palette

Why reinvent the wheel.

* Make supplier detail use the generic template

* Disable mobile event table PoC for now

* Remove the defaults from the RA fields + make them required

* More RA fixes

* Fixes to revisions for RAs

* Add bootstrap 4 test page

* Bunch of dark mode fixes from test page

* Do not use Django 'required' for radio selects

As this requires them to be True, whereas we just need to require that an option be entered.

* Properly fixed popover darktheme

* Fixed search for events

* Style fixes to asset list

* Start RA 'mark review' feature

* Add reviewing to revision history, fix RA editing not working

Also actually commit all the files, that helps

* Fix Power MIC being lost on RA edit

Why it is subtly different to the Event Update behaviour? Who knows

* Invalidate RA review if it is edited after review

* Start work on event checklist

* Add a button for creating and instantly voiding invoices

Handy dandy for when you have loads of cancelled events, like say, a pandemic

* Mooooore status chips, mooore

* Initial shenanigans on storing my overly fancy EC form

* Proof of concept for JSON parsing/storage

\o/

* Add new line functionality for vehicles/drivers

Might it have been easier to create 'dummy' models like with EventItems? Probably...

* Alter rig_count to not include un-checked-in dry hires

* Insert a divider between still-out dry hires and actually upcoming events on rigboard

* Initial work on new checklist handling. No more JSON!

* Versioning module now does magic

Automatic creation of views/urls for anything registered with reversion, with a small amount of hackage to preserve legacy stuff. (and the DAMNED asset IDs!) I would never get distracted...

* Cleanup

* Event checklist crew works

Mostly - its not happy with timezones

* Medium event power stuff done, barring worst case stuff

* Misc fixes

* Validation of power reqs

* Worst case points on checklist

* Templating improvements to RA/EC stuff

* Do event table color logic at python level

* Audit template fixes

* Restrict versioning to one level of depth for speed

Also fixed the template for nested changes

* Event properties internal/authorised always return a explicit boolean rather than sometimes None

* Use template filter for notes

* Fix list templates

TODO: Sensible place to define the 'expected answer' stuff.

* Fix cable table template

* Rethink rigboard color logic again

Also revert some broken stuff

* Test fixes

* Modify auth test so it doesn't try and test for external authorisations

Cause that's not a thing

* Why does this work

Bloody overzealous autoformatter...

* Formatting...

* Initial work on RA tests

* Pages/start of tests for EventChecklists

* Much better coverage of H&S things

* Cleanup & Squash migrations

* Fix wrong variable name in settings.py

* Fix broken invoice list template

* Add revision history to invoices/payments.

Also patches previously introduced reversion permissions hole.

Supersedes and closes #337.

* Various misc fixes

* Fix for my fix

* Curse youuuuu pep8

* Invoice template improvements

* Minor fixes

* More tweaks

* More fixes

* Major improvements/fixes to authorisation templates

* Add ability to mark event checklists as Large Event

This just disables the checks to allow the rest of it to be filled out for large events, though I expect paper forms may still be used...

* Remove database ID from generic list

* Put power threshold values in a collapse

* Use template filter for consistent removal of 'None links'

Plus cleaner template markup! More HTML-in-Python tho, which always feels a bit CSS-in-JS

* Tweak asset list markup

* Begin to change add buttons success -> primary

Also change search primary -> info to avoid clash

* Begin to improve event checklist on mobile

* Asset detail template improvements

* Fix #326 (again)

* Fix errors being squashed

* Fix rigboard validation tests

* Initial work on BS4 button templatetag

Newfeatureitis strikes again

* Allow multiple event checklists per event

TODO: Status chip now needs rethinking

* Minor event detail fixes

* Fix tests

* Rework button tag

* Mobile fixes for search

* Fix event checklist on mobile

* Redo light theme palette

* Switch rigboard new button to primary

* Kill off excess whitespace on rigboard

* Rigboard Timing display tweaks

* Fix tests

* Properly handle eventauthorisations in new versioning

It's not great, not terrible...

* Prevent creating duplicate revisions on event

Potential fix for #322 - I couldn't reproduce even before this change...

* Template improvements

* Minor test fixes

* Revert "Prevent creating duplicate revisions on event"

Apparently it was too strong at preventing dupes...

This reverts commit cce0ad0f9f.

# Conflicts:
#	RIGS/models.py

* Better approach to generic list templates + other deduplication

* Also apply better approach to generic detail pages

* One of these days I'll remember to test BEFORE pushing...

* And now the same for generic forms

* Display tick/cross rather than true/false in boolean version diffs

* Upgrade dependencies

* Fixes fixes fixes

* Fix dependency hell

Probably

* Correct handling of spaces in paperwork filenames

Also normalises display of Invoice IDs. Partial fix for #391.

* Buggerit millennium hand and shrimp

Knew I was gonna forget to fix the tests

* FIX: Set duplicated event status to provisional

Closes #398.

Flip flop. Flip flop.

* Update polyfill for datetime-local

Bloody Firefox. We love to hate you. Proper CSS of the fill to come, SoonTM.

Closes #391

* Curses!

* Minor typo fixes

* Initial pass at soop-consult confirmation screen for RAs

* Fix migration

* Make venue/date editable on EC

For multi venue, multi day events

Defaults to date and venue set on the event. Also made power MIC default to that set in RA

* Clearer logic for RA inverted fields

* (probably) fix tests

* Give keyholders supplier edit perm

* Generic list only displays edit button if user has perm

* Same perm check for generic details

* H&S Details takes up free space on non-internal events

* Remove flash of content when loading new rig page

* First pass at clearer display of asset list filters

* Fix tests / default to headless tests

(fingers crossed)

* Fix autocompleter.js to properly disable edit links again

* Move status color logic back to template

Cause that somehow makes it work better??

* Display note icon on event detail page

* Fix caching

* Put rounded corners back where they belong

* Remove lingering use of 'page-header'

BS removed that style

* More search and replace for BS changes

Thought I'd got them all. Clearly not!

* Remove enforced linebreak on status chips

* Fix horizontal-ness on some forms

* Remove animation on prefers-reduced-motion/low referesh rate devices

Also normalises handling of asset list cable table & improves its use of space on large devices

* Make version changes badges more readable

* First pass at making the calendar less crap

* Fix event table success logic

Yay for copy paste fails >.>

* Use borders rather than block colors for coloured tables under darktheme

* First pass at porting calendar from FC V3 to V5

Two major versions and all they did was rename a bunch of names...TWICE.

* Rework version name method to avoid blank names on eventchecklist vehicles/crew

* Fix cable test

* Made radio button focus much more obvious on dark theme

* Implement Jerb's wording changes

* Fix one test, break another...

* Fix recent change stream list mutation issue

* FIX: Do not naively cache event table

Not that easy, it turns out. Duh.

* FEAT: Implement #413 show associated assets on cable type detail pg

Closes #413

* Allow H&S for non-events

* Update emergency contact number

* Improvements to profile detail page

* Implement some of Jonny's suggested changes

TODO:
- Define event size at RA time, pass through to EC
- Have later power questions be context dependent

* Test fixes

* Add space for power/rigging plans to be linked to RAs

* Start move of event size logic to RA from Ec

* Javascript required shenanigans for RA power

* More moving of event size logic

* Fixing tests for new logic etc

* Why does this work

Indeed, it may not

* FIX: Stupid typo in versioning.py

* Further minor fixes to versioning

* Add icons to H&S menu items

* Should fix calendar breaking in production

* Small alignment fix in asset list

* Squash migrations

Co-authored-by: Matthew Smith <psyms13@nottingham.ac.uk>
2021-01-23 22:22:37 +00:00

22 lines
16 KiB
JavaScript

/*!
* Ajax Bootstrap Select
*
* Extends existing [Bootstrap Select] implementations by adding the ability to search via AJAX requests as you type. Originally for CROSCON.
*
* @version 1.4.5
* @author Adam Heim - https://github.com/truckingsim
* @link https://github.com/truckingsim/Ajax-Bootstrap-Select
* @copyright 2019 Adam Heim
* @license Released under the MIT license.
*
* Contributors:
* Mark Carver - https://github.com/markcarver
*
* Last build: 2019-04-23 12:18:55 PM EDT
*/
!function(t,e){var i=function(i,s){var o,l,n=this;s=s||{},this.$element=t(i),this.options=t.extend(!0,{},t.fn.ajaxSelectPicker.defaults,s),this.LOG_ERROR=1,this.LOG_WARNING=2,this.LOG_INFO=3,this.LOG_DEBUG=4,this.lastRequest=!1,this.previousQuery="",this.query="",this.request=!1;var a=[{from:"ajaxResultsPreHook",to:"preprocessData"},{from:"ajaxSearchUrl",to:{ajax:{url:"{{{value}}}"}}},{from:"ajaxOptions",to:"ajax"},{from:"debug",to:function(e){var i={};i.log=Boolean(n.options[e.from])?n.LOG_DEBUG:0,n.options=t.extend(!0,{},n.options,i),delete n.options[e.from],n.log(n.LOG_WARNING,'Deprecated option "'+e.from+'". Update code to use:',i)}},{from:"mixWithCurrents",to:"preserveSelected"},{from:"placeHolderOption",to:{locale:{emptyTitle:"{{{value}}}"}}}];a.length&&t.map(a,(function(e){if(n.options[e.from])if(t.isPlainObject(e.to))n.replaceValue(e.to,"{{{value}}}",n.options[e.from]),n.options=t.extend(!0,{},n.options,e.to),n.log(n.LOG_WARNING,'Deprecated option "'+e.from+'". Update code to use:',e.to),delete n.options[e.from];else if(t.isFunction(e.to))e.to.apply(n,[e]);else{var i={};i[e.to]=n.options[e.from],n.options=t.extend(!0,{},n.options,i),n.log(n.LOG_WARNING,'Deprecated option "'+e.from+'". Update code to use:',i),delete n.options[e.from]}}));var r=this.$element.data();r.searchUrl&&(n.log(n.LOG_WARNING,'Deprecated attribute name: "data-search-url". Update markup to use: \' data-abs-ajax-url="'+r.searchUrl+"\" '"),this.options.ajax.url=r.searchUrl);var p=function(t,e){return e.toLowerCase()},c=function(t,e,i){var s=[].concat(t),o=s.length,l=i||{};if(o){var n=s.shift();l[n]=c(s,e,l[n])}return o?l:e},h=Object.keys(r).filter(/./.test.bind(new RegExp("^abs[A-Z]")));if(h.length){var u={},g=["locale"];for(o=0,l=h.length;o<l;o++){var d=h[o].replace(/^abs([A-Z])/,p).replace(/([A-Z])/g,"-$1").toLowerCase(),f=d.split("-");if(f[0]&&f.length>1&&-1!==g.indexOf(f[0])){for(var v=[f.shift()],y="",O=0;O<f.length;O++)y+=0===O?f[O]:f[O].charAt(0).toUpperCase()+f[O].slice(1);v.push(y),f=v}this.log(this.LOG_DEBUG,'Processing data attribute "data-abs-'+d+'":',r[h[o]]),c(f,r[h[o]],u)}this.options=t.extend(!0,{},this.options,u),this.log(this.LOG_DEBUG,"Merged in the data attribute options: ",u,this.options)}if(this.selectpicker=r.selectpicker,!this.selectpicker)return this.log(this.LOG_ERROR,"Cannot instantiate an AjaxBootstrapSelect instance without selectpicker first being initialized!"),null;if(!this.options.ajax.url)return this.log(this.LOG_ERROR,'Option "ajax.url" must be set! Options:',this.options),null;if(this.locale=t.extend(!0,{},t.fn.ajaxSelectPicker.locale),this.options.langCode=this.options.langCode||e.navigator.userLanguage||e.navigator.language||"en",!this.locale[this.options.langCode]){var m=this.options.langCode;this.options.langCode="en";var G=m.split("-");for(o=0,l=G.length;o<l;o++){var k=G.join("-");if(k.length&&this.locale[k]){this.options.langCode=k;break}G.pop()}this.log(this.LOG_WARNING,'Unknown langCode option: "'+m+'". Using the following langCode instead: "'+this.options.langCode+'".')}this.locale[this.options.langCode]=t.extend(!0,{},this.locale[this.options.langCode],this.options.locale),this.list=new e.AjaxBootstrapSelectList(this),this.list.refresh(),setTimeout((function(){n.init()}),500)};i.prototype.init=function(){var i,s=this;this.options.preserveSelected&&this.selectpicker.$menu.off("click",".actions-btn").on("click",".actions-btn",(function(e){s.selectpicker.options.liveSearch?s.selectpicker.$searchbox.focus():s.selectpicker.$button.focus(),e.preventDefault(),e.stopPropagation(),t(this).is(".bs-select-all")?(null===s.selectpicker.$lis&&(s.selectpicker.$lis=s.selectpicker.$menu.find("li")),s.$element.find("option:enabled").prop("selected",!0),t(s.selectpicker.$lis).not(".disabled").addClass("selected"),s.selectpicker.render()):(null===s.selectpicker.$lis&&(s.selectpicker.$lis=s.selectpicker.$menu.find("li")),s.$element.find("option:enabled").prop("selected",!1),t(s.selectpicker.$lis).not(".disabled").removeClass("selected"),s.selectpicker.render()),s.selectpicker.$element.change()})),this.selectpicker.$searchbox.attr("placeholder",this.t("searchPlaceholder")).off("input propertychange"),this.selectpicker.$searchbox.on(this.options.bindEvent,(function(o){var l=s.selectpicker.$searchbox.val();if(s.log(s.LOG_DEBUG,'Bind event fired: "'+s.options.bindEvent+'", keyCode:',o.keyCode,o),s.options.cache||(s.options.ignoredKeys[13]="enter"),s.options.ignoredKeys[o.keyCode])s.log(s.LOG_DEBUG,"Key ignored.");else if(clearTimeout(i),l.length||(s.options.clearOnEmpty&&s.list.destroy(),s.options.emptyRequest))if(l.length<s.options.minLength)s.list.setStatus(s.t("statusTooShort"));else{if(s.previousQuery=s.query,s.query=l,s.options.cache&&13!==o.keyCode){var n=s.list.cacheGet(s.query);if(n)return s.list.setStatus(n.length?"":s.t("statusNoResults")),s.list.replaceOptions(n),void s.log(s.LOG_INFO,"Rebuilt options from cached data.")}i=setTimeout((function(){s.lastRequest&&s.lastRequest.jqXHR&&t.isFunction(s.lastRequest.jqXHR.abort)&&s.lastRequest.jqXHR.abort(),s.request=new e.AjaxBootstrapSelectRequest(s),s.request.jqXHR.always((function(){s.lastRequest=s.request,s.request=!1}))}),s.options.requestDelay||300)}}))},i.prototype.log=function(t,i){if(e.console&&this.options.log){if("number"!=typeof this.options.log)switch("string"==typeof this.options.log&&(this.options.log=this.options.log.toLowerCase()),this.options.log){case!0:case"debug":this.options.log=this.LOG_DEBUG;break;case"info":this.options.log=this.LOG_INFO;break;case"warn":case"warning":this.options.log=this.LOG_WARNING;break;default:case!1:case"error":this.options.log=this.LOG_ERROR}if(t<=this.options.log){var s=[].slice.apply(arguments,[2]);switch(t){case this.LOG_DEBUG:t="debug";break;case this.LOG_INFO:t="info";break;case this.LOG_WARNING:t="warn";break;default:case this.LOG_ERROR:t="error"}var o="["+t.toUpperCase()+"] AjaxBootstrapSelect:";"string"==typeof i?s.unshift(o+" "+i):(s.unshift(i),s.unshift(o)),e.console[t].apply(e.console,s)}}},i.prototype.replaceValue=function(e,i,s,o){var l=this;o=t.extend({recursive:!0,depth:!1,limit:!1},o),t.each(e,(function(n,a){if(!1!==o.limit&&"number"==typeof o.limit&&o.limit<=0)return!1;t.isArray(e[n])||t.isPlainObject(e[n])?(o.recursive&&!1===o.depth||o.recursive&&"number"==typeof o.depth&&o.depth>0)&&l.replaceValue(e[n],i,s,o):a===i&&(!1!==o.limit&&"number"==typeof o.limit&&o.limit--,e[n]=s)}))},i.prototype.t=function(t,e){return e=e||this.options.langCode,this.locale[e]&&this.locale[e].hasOwnProperty(t)?this.locale[e][t]:(this.log(this.LOG_WARNING,"Unknown translation key:",t),t)},e.AjaxBootstrapSelect=e.AjaxBootstrapSelect||i;var s=function(e){var i=this;this.$status=t(e.options.templates.status).hide().appendTo(e.selectpicker.$menu);var s=e.t("statusInitialized");s&&s.length&&this.setStatus(s),this.cache={},this.plugin=e,this.selected=[],this.title=null,this.selectedTextFormat=e.selectpicker.options.selectedTextFormat;var o=[];e.$element.find("option").each((function(){var i=t(this),s=i.attr("value");o.push({value:s,text:i.text(),class:i.attr("class")||"",data:i.data()||{},preserved:e.options.preserveSelected,selected:!!i.attr("selected")})})),this.cacheSet("",o),e.options.preserveSelected&&(i.selected=o,e.$element.on("change.abs.preserveSelected",(function(s){var o=e.$element.find(":selected");i.selected=[],e.selectpicker.multiple||(o=o.last()),o.each((function(){var e=t(this),s=e.attr("value");i.selected.push({value:s,text:e.text(),class:e.attr("class")||"",data:e.data()||{},preserved:!0,selected:!0})})),i.replaceOptions(i.cacheGet(i.plugin.query))})))};s.prototype.build=function(e){var i,s,o=e.length,l=t("<select/>"),n=t("<optgroup/>").attr("label",this.plugin.t("currentlySelected"));for(this.plugin.log(this.plugin.LOG_DEBUG,"Building the select list options from data:",e),s=0;s<o;s++){var a=e[s],r=t("<option/>").appendTo(a.preserved?n:l);if(a.hasOwnProperty("divider"))r.attr("data-divider","true");else for(i in r.val(a.value).text(a.text).attr("title",a.text),a.class.length&&r.attr("class",a.class),a.disabled&&r.attr("disabled",!0),a.selected&&!this.plugin.selectpicker.multiple&&l.find(":selected").prop("selected",!1),a.selected&&r.attr("selected",!0),a.data)a.data.hasOwnProperty(i)&&r.attr("data-"+i,a.data[i])}n.find("option").length&&n["before"===this.plugin.options.preserveSelectedPosition?"prependTo":"appendTo"](l);var p=l.html();return this.plugin.log(this.plugin.LOG_DEBUG,p),p},s.prototype.cacheGet=function(t,e){var i=this.cache[t]||e;return this.plugin.log(this.LOG_DEBUG,"Retrieving cache:",t,i),i},s.prototype.cacheSet=function(t,e){this.cache[t]=e,this.plugin.log(this.LOG_DEBUG,"Saving to cache:",t,e)},s.prototype.destroy=function(){this.replaceOptions(),this.plugin.list.setStatus(),this.plugin.log(this.plugin.LOG_DEBUG,"Destroyed select list.")},s.prototype.refresh=function(t){this.plugin.selectpicker.$menu.css("minHeight",0),this.plugin.selectpicker.$menu.find("> .inner").css("minHeight",0);var e=this.plugin.t("emptyTitle");!this.plugin.$element.find("option").length&&e&&e.length?this.setTitle(e):(this.title||"static"!==this.selectedTextFormat&&this.selectedTextFormat!==this.plugin.selectpicker.options.selectedTextFormat)&&this.restoreTitle(),this.plugin.selectpicker.refresh(),this.plugin.selectpicker.findLis(),t&&(this.plugin.log(this.plugin.LOG_DEBUG,"Triggering Change"),this.plugin.$element.trigger("change.$")),this.plugin.log(this.plugin.LOG_DEBUG,"Refreshed select list.")},s.prototype.replaceOptions=function(t){var e,i,s,o="",l=[],n=[],a=[];if(t=t||[],this.selected&&this.selected.length){for(this.plugin.log(this.plugin.LOG_INFO,"Processing preserved selections:",this.selected),i=(n=[].concat(this.selected,t)).length,e=0;e<i;e++)(s=n[e]).hasOwnProperty("value")&&-1===a.indexOf(s.value+"")?(a.push(s.value+""),l.push(s)):this.plugin.log(this.plugin.LOG_DEBUG,"Duplicate item found, ignoring.");t=l}t.length&&(o=this.plugin.list.build(t)),this.plugin.$element.html(o),this.refresh(),this.plugin.log(this.plugin.LOG_DEBUG,"Replaced options with data:",t)},s.prototype.restore=function(){var t=this.plugin.list.cacheGet(this.plugin.previousQuery);return t&&this.plugin.list.replaceOptions(t)&&this.plugin.log(this.plugin.LOG_DEBUG,"Restored select list to the previous query: ",this.plugin.previousQuery),this.plugin.log(this.plugin.LOG_DEBUG,"Unable to restore select list to the previous query:",this.plugin.previousQuery),!1},s.prototype.restoreTitle=function(){this.plugin.request||(this.plugin.selectpicker.options.selectedTextFormat=this.selectedTextFormat,this.title?this.plugin.$element.attr("title",this.title):this.plugin.$element.removeAttr("title"),this.title=null)},s.prototype.setTitle=function(t){this.plugin.request||(this.title=this.plugin.$element.attr("title"),this.plugin.selectpicker.options.selectedTextFormat="static",this.plugin.$element.attr("title",t))},s.prototype.setStatus=function(t){(t=t||"").length?this.$status.html(t).show():this.$status.html("").hide()},e.AjaxBootstrapSelectList=e.AjaxBootstrapSelectList||s;var o=function(e){var i,s=this,o=function(t){return function(){s.plugin.log(s.plugin.LOG_INFO,"Invoking AjaxBootstrapSelectRequest."+t+" callback:",arguments),s[t].apply(s,arguments),s.callbacks[t]&&(s.plugin.log(s.plugin.LOG_INFO,"Invoking ajax."+t+" callback:",arguments),s.callbacks[t].apply(s,arguments))}},l=["beforeSend","success","error","complete"],n=l.length;for(this.plugin=e,this.options=t.extend(!0,{},e.options.ajax),this.callbacks={},i=0;i<n;i++){var a=l[i];this.options[a]&&t.isFunction(this.options[a])&&(this.callbacks[a]=this.options[a]),this.options[a]=o(a)}this.options.data&&t.isFunction(this.options.data)&&(this.options.data=this.options.data.apply(this)||{q:"{{{q}}}"}),this.plugin.replaceValue(this.options.data,"{{{q}}}",this.plugin.query),this.options.url&&t.isFunction(this.options.url)&&(this.options.url=this.options.url.apply(this)),this.jqXHR=t.ajax(this.options)};o.prototype.beforeSend=function(t){this.plugin.list.destroy(),this.plugin.list.setStatus(this.plugin.t("statusSearching"))},o.prototype.complete=function(t,e){if("abort"!==e){var i=this.plugin.list.cacheGet(this.plugin.query);if(i){if(!i.length)return this.plugin.list.destroy(),this.plugin.list.setStatus(this.plugin.t("statusNoResults")),void this.plugin.log(this.plugin.LOG_INFO,"No results were returned.");this.plugin.list.setStatus()}this.plugin.list.refresh(!0)}},o.prototype.error=function(t,e,i){"abort"!==e&&(this.plugin.list.cacheSet(this.plugin.query),this.plugin.options.clearOnError&&this.plugin.list.destroy(),this.plugin.list.setStatus(this.plugin.t("errorText")),this.plugin.options.restoreOnError&&(this.plugin.list.restore(),this.plugin.list.setStatus()))},o.prototype.process=function(e){var i,s,o,l,n,a,r=[],p=[];if(this.plugin.log(this.plugin.LOG_INFO,"Processing raw data for:",this.plugin.query,e),n=e,t.isFunction(this.plugin.options.preprocessData)&&(this.plugin.log(this.plugin.LOG_DEBUG,"Invoking preprocessData callback:",this.plugin.options.processData),null!=(o=this.plugin.options.preprocessData.apply(this,[n]))&&!1!==o&&(n=o)),!t.isArray(n))return this.plugin.log(this.plugin.LOG_ERROR,'The data returned is not an Array. Use the "preprocessData" callback option to parse the results and construct a proper array for this plugin.',n),!1;for(s=n.length,i=0;i<s;i++)l=n[i],this.plugin.log(this.plugin.LOG_DEBUG,"Processing item:",l),t.isPlainObject(l)&&(l.hasOwnProperty("divider")||l.hasOwnProperty("data")&&t.isPlainObject(l.data)&&l.data.divider?(this.plugin.log(this.plugin.LOG_DEBUG,"Item is a divider, ignoring provided data."),r.push({divider:!0})):l.hasOwnProperty("value")?-1===p.indexOf(l.value+"")?(p.push(l.value+""),l=t.extend({text:l.value,class:"",data:{},disabled:!1,selected:!1},l),r.push(l)):this.plugin.log(this.plugin.LOG_DEBUG,"Duplicate item found, ignoring."):this.plugin.log(this.plugin.LOG_DEBUG,'Data item must have a "value" property, skipping.'));if(a=[].concat(r),t.isFunction(this.plugin.options.processData)&&(this.plugin.log(this.plugin.LOG_DEBUG,"Invoking processData callback:",this.plugin.options.processData),null!=(o=this.plugin.options.processData.apply(this,[a]))&&!1!==o)){if(!t.isArray(o))return this.plugin.log(this.plugin.LOG_ERROR,"The processData callback did not return an array.",o),!1;a=o}return this.plugin.list.cacheSet(this.plugin.query,a),this.plugin.log(this.plugin.LOG_INFO,"Processed data:",a),a},o.prototype.success=function(e,i,s){if(!t.isArray(e)&&!t.isPlainObject(e))return this.plugin.log(this.plugin.LOG_ERROR,"Request did not return a JSON Array or Object.",e),void this.plugin.list.destroy();var o=this.process(e);this.plugin.list.replaceOptions(o)},e.AjaxBootstrapSelectRequest=e.AjaxBootstrapSelectRequest||o,t.fn.ajaxSelectPicker=function(i){return this.each((function(){t(this).data("AjaxBootstrapSelect")||t(this).data("AjaxBootstrapSelect",new e.AjaxBootstrapSelect(this,i))}))},t.fn.ajaxSelectPicker.locale={},t.fn.ajaxSelectPicker.defaults={ajax:{url:null,type:"POST",dataType:"json",data:{q:"{{{q}}}"}},minLength:0,bindEvent:"keyup",cache:!0,clearOnEmpty:!0,clearOnError:!0,emptyRequest:!1,ignoredKeys:{9:"tab",16:"shift",17:"ctrl",18:"alt",27:"esc",37:"left",39:"right",38:"up",40:"down",91:"meta"},langCode:null,locale:null,log:"error",preprocessData:function(){},preserveSelected:!0,preserveSelectedPosition:"after",processData:function(){},requestDelay:300,restoreOnError:!1,templates:{status:'<div class="status"></div>'}},
/*!
* English translation for the "en-US" and "en" language codes.
* Mark Carver <mark.carver@me.com>
*/
t.fn.ajaxSelectPicker.locale["en-US"]={currentlySelected:"Currently Selected",emptyTitle:"Select and begin typing",errorText:"Unable to retrieve results",searchPlaceholder:"Search...",statusInitialized:"Start typing a search query",statusNoResults:"No Results",statusSearching:"Searching...",statusTooShort:"Please enter more characters"},t.fn.ajaxSelectPicker.locale.en=t.fn.ajaxSelectPicker.locale["en-US"]}(jQuery,window);