From: Ivan Kohler Date: Tue, 27 Nov 2018 23:20:05 +0000 (-0800) Subject: Merge branch 'master' of git.freeside.biz:/home/git/freeside X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=219c811aa5ee634bb17e1fa19a2d75351949b8d4;hp=3e6b291920daf5546efa5355e3ea6199e875d9db Merge branch 'master' of git.freeside.biz:/home/git/freeside --- diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index bb3ca1265..de35c5197 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -745,8 +745,15 @@ sub edit_info { or return { 'error' => "unknown custnum $custnum" }; my $conf = new FS::Conf; - if (($p->{payby} eq "CHEK" || $p->{payby} eq "DCHEK") && $conf->exists('selfservice-ACH_info_readonly')) { - return { 'error' => "You do not have authority to add a bank account" }; + + if ($p->{payby}) { + return { 'error' => "You do not have authority to add a bank account" } + if (($p->{payby} eq "CHEK" || $p->{payby} eq "DCHEK") && $conf->exists('selfservice-ACH_info_readonly')); + + ## get default cust_payby and change it. For old v3 selfservice that upgraded to v4. this is for v4 only + my ($cust_payby) = $cust_main->cust_payby(); + $p->{'custpaybynum'} = $cust_payby->custpaybynum; + update_payby($p); } my $new = new FS::cust_main { $cust_main->hash }; @@ -876,38 +883,35 @@ sub payment_info { $return{$_} = $cust_main->bill_location->get($_) for qw(address1 address2 city state zip); - $p->{'payment_payby'} = $payment_info->{paybys} if !$p->{'payment_payby'}; - # look for stored cust_payby info - # only if we've been given a clear payment_payby (to avoid payname conflicts) - if ($p->{'payment_payby'} =~ /^(CARD|CHEK)$/ || (ref($p->{'payment_payby'}))) { - my @search_payby = (); - if ($p->{'payment_payby'} eq 'CARD') { @search_payby = ('CARD','DCRD'); } - elsif ($p->{'payment_payby'} eq 'CHEK') { @search_payby = ('CHEK','DCHK'); } - elsif (ref($p->{'payment_payby'}) eq 'ARRAY') { @search_payby = @{$payment_info->{paybys}}; } - my ($cust_payby) = $cust_main->cust_payby(@search_payby); - if ($cust_payby) { - $return{payby} = $cust_payby->payby; - $return{payname} = $cust_payby->payname + # v3 to v4 upgrade would break change_pay because change_pay does not send payment_payby + # so for change_pay to work need to search for all allowed paybys and grab default payment account + my @search_payby = (); + @search_payby = ($p->{'payment_payby'} eq 'CARD') ? ('CARD','DCRD') : ('CHEK','DCHK') + if ($p->{'payment_payby'} =~ /^(CARD|CHEK)$/); + + my ($cust_payby) = $cust_main->cust_payby(@search_payby); + if ($cust_payby) { + $return{payby} = $cust_payby->payby; + $return{payname} = $cust_payby->payname || ( $cust_main->first. ' '. $cust_main->get('last') ); - $return{custpaybynum} = $cust_payby->custpaybynum; + $return{custpaybynum} = $cust_payby->custpaybynum; - if ( $cust_payby->payby =~ /^(CARD|DCRD)$/ ) { - $return{card_type} = cardtype($cust_payby->payinfo); - $return{payinfo} = $cust_payby->paymask; + if ( $cust_payby->payby =~ /^(CARD|DCRD)$/ ) { + $return{card_type} = cardtype($cust_payby->payinfo); + $return{payinfo} = $cust_payby->paymask; - @return{'month', 'year'} = $cust_payby->paydate_monthyear; + @return{'month', 'year'} = $cust_payby->paydate_monthyear; - } + } - if ( $cust_payby->payby =~ /^(CHEK|DCHK)$/ ) { - my ($payinfo1, $payinfo2) = split '@', $cust_payby->paymask; - $return{payinfo1} = $payinfo1; - $return{payinfo2} = $payinfo2; - $return{paytype} = $cust_payby->paytype; - $return{paystate} = $cust_payby->paystate; - $return{payname} = $cust_payby->payname; # override 'first/last name' default from above, if any. Is instution-name here. (#15819) - } + if ( $cust_payby->payby =~ /^(CHEK|DCHK)$/ ) { + my ($payinfo1, $payinfo2) = split '@', $cust_payby->paymask; + $return{payinfo1} = $payinfo1; + $return{payinfo2} = $payinfo2; + $return{paytype} = $cust_payby->paytype; + $return{paystate} = $cust_payby->paystate; + $return{payname} = $cust_payby->payname; # override 'first/last name' default from above, if any. Is instution-name here. (#15819) } } @@ -1724,7 +1728,10 @@ sub update_payby { or return { 'error' => "illegal ABA/routing number ". $p->{'payinfo2'} }; my $payinfo2 = $1; $p->{'payinfo'} = $payinfo1. '@'. $payinfo2; - } + } + elsif ($p->{'payby'} eq 'CARD') { + $p->{paydate} = $p->{year} . '-' . $p->{month} . '-01' unless $p->{paydate}; + } my $cust_payby = qsearchs('cust_payby', { 'custnum' => $custnum, diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index f29ab9fc0..d39dbbbcd 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -5614,6 +5614,8 @@ sub _X_show_zero { =item order CUSTNUM, PKGPARTS_ARYREF, [ REMOVE_PKGNUMS_ARYREF [ RETURN_CUST_PKG_ARRAYREF [ REFNUM ] ] ] +=item order \%PARAMS + Bulk cancel + order subroutine. Perhaps slightly deprecated, only used by the bulk cancel+order in the web UI and nowhere else (edit/process/cust_pkg.cgi) @@ -5638,10 +5640,25 @@ setting I to an array reference of refnums or a hash reference with refnums as keys. If no I is defined, a default FS::pkg_referral record will be created corresponding to cust_main.refnum. +LOCATIONNUM, if specified, will be set on newly created cust_pkg records + =cut sub order { - my ($custnum, $pkgparts, $remove_pkgnum, $return_cust_pkg, $refnum) = @_; + my ($custnum, $pkgparts, $remove_pkgnum, $return_cust_pkg, $refnum, + $locationnum); + + if ( ref $_[0] ) { + my $args = $_[0]; + $custnum = $args->{custnum}; + $pkgparts = $args->{pkgparts}; + $remove_pkgnum = $args->{remove_pkgnum}; + $return_cust_pkg = $args->{return_cust_pkg}; + $refnum = $args->{refnum}; + $locationnum = $args->{locationnum}; + } else { + ($custnum, $pkgparts, $remove_pkgnum, $return_cust_pkg, $refnum) = @_; + } my $conf = new FS::Conf; @@ -5685,6 +5702,8 @@ sub order { } + $hash{locationnum} = $locationnum if $locationnum; + # Create the new packages. foreach my $pkgpart (@$pkgparts) { diff --git a/FS/FS/pay_batch/RBC.pm b/FS/FS/pay_batch/RBC.pm index 3d1d98b17..22521e0e1 100644 --- a/FS/FS/pay_batch/RBC.pm +++ b/FS/FS/pay_batch/RBC.pm @@ -3,6 +3,7 @@ package FS::pay_batch::RBC; use strict; use vars qw(@ISA %import_info %export_info $name); use Date::Format 'time2str'; +use Date::Parse; use FS::Conf; use Encode 'encode'; use feature 'state'; @@ -31,7 +32,7 @@ $name = 'RBC'; 'filetype' => 'fixed', #this only really applies to Debit Detail, but we otherwise only need first char 'formatre' => - '^(.).{3}(.{10}).{5}(.{4}).{3}(.).{11}(.{19}).{6}(.{30}).{17}(.{9})(.{18}).{6}(.{14}).{23}(.).{9}\r?$', + '^(.).{3}(.{10}).{5}(.{4}).{3}(.).{11}(.{19}).{6}(.{30})(.{2})(.{2})(.{4}).{9}(.{9})(.{18}).{6}(.{14}).{23}(.).{9}\r?$', 'fields' => [ qw( recordtype clientnum @@ -39,6 +40,9 @@ $name = 'RBC'; subtype paybatchnum custname + paydate_month + paydate_day + paydate_year bank payinfo paid @@ -54,7 +58,8 @@ $name = 'RBC'; my $hash = shift; $hash->{'paid'} = sprintf("%.2f", $hash->{'paid'} / 100 ); - $hash->{'_date'} = time; + my $paydate = $hash->{'paydate_year'} . $hash->{'paydate_month'} . $hash->{'paydate_day'}; + $hash->{'_date'} = str2time($paydate, 'local'); $hash->{'payinfo'} =~ s/^(\S+).*/$1/; # these often have trailing spaces $hash->{'payinfo'} = $hash->{'payinfo'} . '@' . $hash->{'bank'}; diff --git a/fs_selfservice/FS-SelfService/cgi/change_pay.html b/fs_selfservice/FS-SelfService/cgi/change_pay.html index 75ceee8f7..e272669dc 100644 --- a/fs_selfservice/FS-SelfService/cgi/change_pay.html +++ b/fs_selfservice/FS-SelfService/cgi/change_pay.html @@ -14,7 +14,6 @@ my $tail = qq(). qq(). - qq(). qq(
). qq( ). diff --git a/fs_selfservice/FS-SelfService/cgi/image.cgi b/fs_selfservice/FS-SelfService/cgi/image.cgi index 129ac438b..ee17683a6 100755 --- a/fs_selfservice/FS-SelfService/cgi/image.cgi +++ b/fs_selfservice/FS-SelfService/cgi/image.cgi @@ -22,7 +22,7 @@ if ( $query =~ /^(\w+)$/ ) { my $info = skin_info( agentnum=>$agentnum ); print $cgi->header( '-type' => 'image/png', #for now - '-expires' => 'now', + #'-expires' => 'now', ). $info->{$name}; diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi index 698640574..6eab11dae 100755 --- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi +++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi @@ -12,7 +12,7 @@ use Date::Format; use Date::Parse 'str2time'; use Number::Format 1.50; use FS::SelfService qw( - access_info login_info login customer_info edit_info insert_payby update_payby + access_info login_info login customer_info edit_info insert_payby update_payby invoice payment_info process_payment realtime_collect process_prepay list_pkgs order_pkg signup_info order_recharge part_svc_info provision_acct provision_external provision_phone provision_forward @@ -388,9 +388,8 @@ sub process_change_ship { sub process_change_pay { my $postal = $cgi->param( 'postal_invoicing' ); my $payby = $cgi->param( 'payby' ); - $cgi->param('paydate', $cgi->param('year') . '-' . $cgi->param('month') . '-01'); my @list = - qw( payby payinfo payinfo1 payinfo2 month year paydate payname custpaybynum + qw( payby payinfo payinfo1 payinfo2 month year payname address1 address2 city county state zip country auto paytype paystate ss stateid stateid_state invoicing_list ); @@ -408,11 +407,7 @@ sub process_change_pay { }; } - if (FS::SelfService->can('update_payby')) { - if ($cgi->param( 'custpaybynum' )) { _process_change_payby( 'change_pay', @list ); } - else { _process_insert_payby( 'change_pay', @list ); } - } - else { _process_change_info( 'change_pay', @list ); } + _process_change_info( 'change_pay', @list ); } sub process_change_creditcard_pay { diff --git a/httemplate/edit/cust_pkg.cgi b/httemplate/edit/cust_pkg.cgi index 7ffbb1fc0..4e4f4d2b2 100755 --- a/httemplate/edit/cust_pkg.cgi +++ b/httemplate/edit/cust_pkg.cgi @@ -1,115 +1,207 @@ -<% include('/elements/header.html', "Add/Edit Packages", '') %> +<%doc> + Bulk package Edit Page + + +<& /elements/header-cust_main.html, + view => 'packages', + cust_main => $cust_main, + include_selectize => 1, +&> <% include('/elements/error.html') %> -
- - - -%#current packages -%if (@cust_pkg) { - - Current packages - select to remove (services are moved to a new package below) - - - - - -

-% -% foreach ( @main_pkgs ) { -% my($pkgnum,$pkgpart)=( $_->getfield('pkgnum'), $_->getfield('pkgpart') ); -% my $checked = $remove_pkg{$pkgnum} ? ' CHECKED' : ''; -% -% - - - - - - - -% foreach my $supp_pkg ( @{ $supp_pkgs_of{$pkgnum} } ) { - - - - - + + + + + + +

+ + <% include( '/elements/select-cust_location.html', + cust_main => $cust_main, + addnew => 0, + onchange => 'javascript:location_changed(this);', + ) %>
+ + Bulk-edit works with one customer location at a time + +

+ +
Pkg #Package description
><% $pkgnum %>:<% $all_pkg{$pkgpart} |h %> - <% $all_comment{$pkgpart} |h %>
+ <% $all_pkg{$supp_pkg->pkgpart} |h %> - <% $all_comment{$supp_pkg->pkgpart} |h %>
+ + + + + + + +% for my $cust_pkg ( @cust_pkg ) { +% my $id = sprintf 'remove_cust_pkg[%s]', $cust_pkg->pkgnum; +% my $is_displayed = $cust_main->ship_locationnum == $cust_pkg->locationnum ? 1 : 0; + + + + + % } -% } - - -
+ Pkg # + + Current Packages
+
+ Selected packages are removed.
+ Attached services are moved to the new package selected below + +
+ + #<% $cust_pkg->pkgnum %> + +% } +
-

-% } - - -Order new packages -

- -%my $cust_main = qsearchs('cust_main',{'custnum'=>$custnum}); -%my $agent = qsearchs('agent',{'agentnum'=> $cust_main->agentnum }); -% -%my %agent_pkgs = map { ( $_->pkgpart => $all_pkg{$_->pkgpart} ) } -% ( qsearch('type_pkgs',{ typenum => $agent->typenum }), -% qsearch('part_pkg', { agentnum => $cust_main->agentnum }), -% ); -% -%my $count = 0; -%my $pkgparts = 0; - - - - - - -% -%#foreach my $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) { -%foreach my $pkgpart ( sort { $agent_pkgs{$a} cmp $agent_pkgs{$b} } -% keys(%agent_pkgs) ) { -% $pkgparts++; -% next unless exists $pkg{$pkgpart}; #skip disabled ones -% #print qq!! if ( $count == 0 ); -% my $value = $cgi->param("pkg$pkgpart") || 0; -% - - - - - - - -% -% $count ++ ; -% #if ( $count == 2 ) { -% # print qq!\n! ; -% # $count = 0; -% #} -%} -% - - -
Qty.Package Description
- " VALUE="<% $value %>" SIZE="2" MAXLENGTH="2"> - <% $pkgpart %>:<% $pkg{$pkgpart} |h %> - <% $comment{$pkgpart} |h %>
-% unless ( $pkgparts ) { -% my $p2 = popurl(2); -% my $typenum = $agent->typenum; -% my $agent_type = qsearchs( 'agent_type', { 'typenum' => $typenum } ); -% my $atype = $agent_type->atype; -% - - - (No package definitions, - or agent type - <% $atype %> - is not allowed to purchase any packages.) -% } - - -

- -

+ + + + + + + + + + + + + + + +% for my $part_pkg ( @part_pkg_enabled ) { +% my $id = sprintf 'qty_part_pkg[%s]', $part_pkg->pkgpart; + + + + + +% } + +
+ <% include('/elements/selectize/select-multiple-pkg_class.html', + id => 'filter_pkg_class', + onchange => 'pkg_class_filter_onchange', + ) %> +
QtyClassOrder New Packages
+ + <% $part_pkg->classname || '(none)' %><% $part_pkg->pkg %>
+ + + + <% include('/elements/footer.html') %> @@ -118,53 +210,41 @@ Order new packages die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Bulk change customer packages'); -my %pkg = (); -my %comment = (); -my %all_pkg = (); -my %all_comment = (); -#foreach (qsearch('part_pkg', { 'disabled' => '' })) { -# $pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg'); -# $comment{ $_ -> getfield('pkgpart') } = $_->getfield('comment'); -#} -foreach (qsearch('part_pkg', {} )) { - $all_pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg'); - $all_comment{ $_ -> getfield('pkgpart') } = $_->custom_comment; - next if $_->disabled; - $pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg'); - $comment{ $_ -> getfield('pkgpart') } = $_->custom_comment; -} +my $custnum = $cgi->param('keywords') || $cgi->param('custnum'); +$custnum =~ /^\d+$/ + or die "Invalid custnum($custnum)"; -my($custnum, %remove_pkg); -if ( $cgi->param('error') ) { - $custnum = $cgi->param('custnum'); - %remove_pkg = map { $_ => 1 } $cgi->param('remove_pkg'); -} else { - my($query) = $cgi->keywords; - $query =~ /^(\d+)$/; - $custnum = $1; - %remove_pkg = (); -} +my $cust_main = qsearchs( cust_main => { custnum => $custnum }) + or die "Invalid custnum ($custnum)"; -my $p1 = popurl(1); +my %part_pkg; +my @part_pkg_enabled; -my @cust_pkg = qsearch('cust_pkg', { 'custnum' => $custnum, 'cancel' => '' } ); -my @main_pkgs; -my %supp_pkgs_of; # main pkgnum => arrayref of cust_pkgs - - -foreach my $cust_pkg - ( sort { $all_pkg{ $a->pkgpart } cmp $all_pkg{ $b->getfield('pkgpart') } } - @cust_pkg +for my $part_pkg ( qsearch( part_pkg => {} )) { + $part_pkg{ $part_pkg->pkgpart } = $part_pkg; + push @part_pkg_enabled, $part_pkg + unless $part_pkg->disabled; +} +@part_pkg_enabled = + sort { $a->classname cmp $b->classname || $a->pkg cmp $b->pkg } + @part_pkg_enabled; + +my @cust_pkg; +my %cust_pkg_supp_of; +for my $cust_pkg ( + qsearch( + cust_pkg => { + custnum => $custnum, + cancel => '', + } ) - # XXX does not properly handle recursive supplemental links -{ +) { if ( my $main_pkgnum = $cust_pkg->main_pkgnum ) { - $supp_pkgs_of{$main_pkgnum} ||= []; - push @{ $supp_pkgs_of{$main_pkgnum} }, $cust_pkg; + $cust_pkg_supp_of{ $main_pkgnum } //= []; + push @{ $cust_pkg_supp_of{ $main_pkgnum } }, $cust_pkg; } else { - push @main_pkgs, $cust_pkg; - $supp_pkgs_of{$cust_pkg->pkgnum} ||= []; + $cust_pkg_supp_of{ $cust_pkg->pkgnum } //= []; + push @cust_pkg, $cust_pkg; } } - diff --git a/httemplate/edit/process/cust_pkg.cgi b/httemplate/edit/process/cust_pkg.cgi index c564c417e..82a9e2375 100755 --- a/httemplate/edit/process/cust_pkg.cgi +++ b/httemplate/edit/process/cust_pkg.cgi @@ -5,38 +5,61 @@ <% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %> % } <%init> - +use Data::Dumper; +my $DEBUG = 0; my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" unless $curuser->access_right('Bulk change customer packages'); my $error = ''; +my %param = $cgi->Vars; + +my $custnum = $param{custnum}; +$error = "Invalid custnum ($custnum)" if $custnum =~ /\D/; + +my $locationnum = $param{locationnum}; +$error = "Invalid locationnum ($locationnum)" if $locationnum =~ /\D/; + +my @remove_pkgnum = + map { $_ =~ /remove_cust_pkg\[(\d+)\]/ ? $1 : () } + keys %param; + +my @pkgparts; +for my $k ( keys %param ) { + next unless $k =~ /qty_part_pkg\[(\d+)\]/; + my $pkgpart = $1; + my $qty = $param{$k}; + $qty =~ s/(^\s+|\s+$)//g; -#untaint custnum -$cgi->param('custnum') =~ /^(\d+)$/; -my $custnum = $1; - -my @remove_pkgnums = map { - /^(\d+)$/ or die "Illegal remove_pkg value!"; - $1; -} $cgi->param('remove_pkg'); - -my( $action, $error_redirect ) = ( '', '' ); -my @pkgparts = (); - -foreach my $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $cgi->param ) { - if ( $cgi->param("pkg$pkgpart") =~ /^(\d+)$/ ) { - my $num_pkgs = $1; - while ( $num_pkgs-- ) { - push @pkgparts,$pkgpart; - } - } else { - $error = "Illegal quantity"; + warn "k($k) param{k}($param{$k}) pkgpart($pkgpart) qty($qty)\n" + if $DEBUG; + + if ( $qty =~ /\D/ ) { + $error = "Invalid quantity $qty for pkgpart $pkgpart - please use a number"; last; } + + next if $qty == 0; + + push ( @pkgparts, $pkgpart ) for ( 1..$qty ); +} + +if ( $DEBUG ) { + warn Dumper({ + custnum => $custnum, + locationnum => $locationnum, + remove_pkgnum => \@remove_pkgnum, + pkgparts => \@pkgparts, + param => \%param, + }); } -$error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums); +$error ||= FS::cust_pkg::order({ + custnum => $custnum, + pkgparts => \@pkgparts, + remove_pkgnum => \@remove_pkgnum, + locationnum => $locationnum, +}); diff --git a/httemplate/elements/dropdown-menu.html b/httemplate/elements/dropdown-menu.html index 1ba4c00cc..8c99db07f 100644 --- a/httemplate/elements/dropdown-menu.html +++ b/httemplate/elements/dropdown-menu.html @@ -5,6 +5,12 @@ border: none; } +#<% $opt{id} %> .ui-state-active { + color: inherit; + background-color: transparent; + border-color: transparent; +} + #<% $opt{id} %> li { float: left; padding: .25em; diff --git a/httemplate/elements/header-cust_main.html b/httemplate/elements/header-cust_main.html index c094f950f..f29f32567 100644 --- a/httemplate/elements/header-cust_main.html +++ b/httemplate/elements/header-cust_main.html @@ -10,12 +10,12 @@ Examples: <& /elements/header.html, { - 'title' => $title, - 'title_noescape' => $title_noescape, - #'nobr' => 1, - 'etc' => $opt{'etc'}, - } -&> + 'title' => $title, + 'title_noescape' => $title_noescape, + #'nobr' => 1, + 'etc' => $opt{'etc'}, + include_selectize => $opt{include_selectize} ? 1 : 0, +} &> % my @part_tag = $cust_main->part_tag; % if ( $conf->config('cust_tag-location') eq 'top' && @part_tag ) { diff --git a/httemplate/elements/header-full.html b/httemplate/elements/header-full.html index b459a11cf..08e20c875 100644 --- a/httemplate/elements/header-full.html +++ b/httemplate/elements/header-full.html @@ -53,6 +53,11 @@ Example: % } % } +% if ( $include_selectize ) { + + + +% } <% include('init_overlib.html') |n %> <% include('rs_init_object.html') |n %> @@ -221,6 +226,7 @@ my( $title, $title_noescape, $menubar, $etc, $head ) = ( '', '', '', '', '' ); my( $nobr, $nocss, $no_jquery ) = ( 0, 0, 0 ); my $mobile; +my $include_selectize; if ( ref($_[0]) ) { my $opt = shift; @@ -233,6 +239,7 @@ if ( ref($_[0]) ) { $nocss = $opt->{nocss}; $mobile = $opt->{mobile}; $no_jquery = $opt->{no_jquery}; + $include_selectize = $opt->{include_selectize} ? 1 : 0; } else { ($title, $menubar) = ( shift, shift ); $etc = @_ ? shift : ''; #$etc is for things like onLoad= etc. diff --git a/httemplate/elements/selectize/select-multiple-pkg_class.html b/httemplate/elements/selectize/select-multiple-pkg_class.html new file mode 100644 index 000000000..10c2163f1 --- /dev/null +++ b/httemplate/elements/selectize/select-multiple-pkg_class.html @@ -0,0 +1,46 @@ +<%doc> + + Render a Selectize.js multiple-select to choose from + package classes + + Selectize js and css must be included in the page header. + Use the include_selectize option on header.html + + + Parameters: + * id - id of the element + * onchange - name of a javascript function + * placeholder - Text displayed when no options are selected + + + + + + +<%init> + +my %opt = ( + id => 'selectize-pkg_class', + name => 'selectize_pkg_class', + placeholder => 'Filter Package Classes', + @_ +); + +my @pkg_class = qsearch( pkg_class => { disabled => '' } ); + + \ No newline at end of file diff --git a/httemplate/elements/selectize/selectize-freeside.css b/httemplate/elements/selectize/selectize-freeside.css new file mode 100644 index 000000000..298c4a03b --- /dev/null +++ b/httemplate/elements/selectize/selectize-freeside.css @@ -0,0 +1,37 @@ +/** +* Freeside CSS theme overrides for selectize.js +* +*/ + +.selectize-label { + display: none !important; +} + +.selectize-input { + border-radius: 0 !important; + padding: 1px !important; + display: inline-block; + width: 250px; + text-align: left !important; +} + +.selectize-input .item { + margin: 2px !important; + text-align: left !important; +} + +.selectize-input .optgroup-header { + font-weight: bold; + background-color: #eee; + border-bottom: solid 1px #ccc; + text-align: left !important; +} + +.selectize-dropdown .option { + text-align: left !important; +} + +.selectize-input .optgroup .option { + padding-left: 1em; + text-align: left !important; +} diff --git a/httemplate/elements/selectize/selectize.css b/httemplate/elements/selectize/selectize.css new file mode 100644 index 000000000..3ec90ad0e --- /dev/null +++ b/httemplate/elements/selectize/selectize.css @@ -0,0 +1,333 @@ +/** + * selectize.css (v0.12.6) + * Copyright (c) 2013–2015 Brian Reavis & contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this + * file except in compliance with the License. You may obtain a copy of the License at: + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF + * ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + * + * @author Brian Reavis + */ + +.selectize-control.plugin-drag_drop.multi > .selectize-input > div.ui-sortable-placeholder { + visibility: visible !important; + background: #f2f2f2 !important; + background: rgba(0, 0, 0, 0.06) !important; + border: 0 none !important; + -webkit-box-shadow: inset 0 0 12px 4px #fff; + box-shadow: inset 0 0 12px 4px #fff; +} +.selectize-control.plugin-drag_drop .ui-sortable-placeholder::after { + content: '!'; + visibility: hidden; +} +.selectize-control.plugin-drag_drop .ui-sortable-helper { + -webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); +} +.selectize-dropdown-header { + position: relative; + padding: 5px 8px; + border-bottom: 1px solid #d0d0d0; + background: #f8f8f8; + -webkit-border-radius: 3px 3px 0 0; + -moz-border-radius: 3px 3px 0 0; + border-radius: 3px 3px 0 0; +} +.selectize-dropdown-header-close { + position: absolute; + right: 8px; + top: 50%; + color: #303030; + opacity: 0.4; + margin-top: -12px; + line-height: 20px; + font-size: 20px !important; +} +.selectize-dropdown-header-close:hover { + color: #000000; +} +.selectize-dropdown.plugin-optgroup_columns .optgroup { + border-right: 1px solid #f2f2f2; + border-top: 0 none; + float: left; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +.selectize-dropdown.plugin-optgroup_columns .optgroup:last-child { + border-right: 0 none; +} +.selectize-dropdown.plugin-optgroup_columns .optgroup:before { + display: none; +} +.selectize-dropdown.plugin-optgroup_columns .optgroup-header { + border-top: 0 none; +} +.selectize-control.plugin-remove_button [data-value] { + position: relative; + padding-right: 24px !important; +} +.selectize-control.plugin-remove_button [data-value] .remove { + z-index: 1; + /* fixes ie bug (see #392) */ + position: absolute; + top: 0; + right: 0; + bottom: 0; + width: 17px; + text-align: center; + font-weight: bold; + font-size: 12px; + color: inherit; + text-decoration: none; + vertical-align: middle; + display: inline-block; + padding: 2px 0 0 0; + border-left: 1px solid #d0d0d0; + -webkit-border-radius: 0 2px 2px 0; + -moz-border-radius: 0 2px 2px 0; + border-radius: 0 2px 2px 0; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +.selectize-control.plugin-remove_button [data-value] .remove:hover { + background: rgba(0, 0, 0, 0.05); +} +.selectize-control.plugin-remove_button [data-value].active .remove { + border-left-color: #cacaca; +} +.selectize-control.plugin-remove_button .disabled [data-value] .remove:hover { + background: none; +} +.selectize-control.plugin-remove_button .disabled [data-value] .remove { + border-left-color: #ffffff; +} +.selectize-control.plugin-remove_button .remove-single { + position: absolute; + right: 0; + top: 0; + font-size: 23px; +} +.selectize-control { + position: relative; +} +.selectize-dropdown, +.selectize-input, +.selectize-input input { + color: #303030; + font-family: inherit; + font-size: 13px; + line-height: 18px; + -webkit-font-smoothing: inherit; +} +.selectize-input, +.selectize-control.single .selectize-input.input-active { + background: #fff; + cursor: text; + display: inline-block; +} +.selectize-input { + border: 1px solid #d0d0d0; + padding: 8px 8px; + display: inline-block; + width: 100%; + overflow: hidden; + position: relative; + z-index: 1; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1); + -webkit-border-radius: 3px; + -moz-border-radius: 3px; + border-radius: 3px; +} +.selectize-control.multi .selectize-input.has-items { + padding: 6px 8px 3px; +} +.selectize-input.full { + background-color: #fff; +} +.selectize-input.disabled, +.selectize-input.disabled * { + cursor: default !important; +} +.selectize-input.focus { + -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15); + box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15); +} +.selectize-input.dropdown-active { + -webkit-border-radius: 3px 3px 0 0; + -moz-border-radius: 3px 3px 0 0; + border-radius: 3px 3px 0 0; +} +.selectize-input > * { + vertical-align: baseline; + display: -moz-inline-stack; + display: inline-block; + zoom: 1; + *display: inline; +} +.selectize-control.multi .selectize-input > div { + cursor: pointer; + margin: 0 3px 3px 0; + padding: 2px 6px; + background: #f2f2f2; + color: #303030; + border: 0 solid #d0d0d0; +} +.selectize-control.multi .selectize-input > div.active { + background: #e8e8e8; + color: #303030; + border: 0 solid #cacaca; +} +.selectize-control.multi .selectize-input.disabled > div, +.selectize-control.multi .selectize-input.disabled > div.active { + color: #7d7d7d; + background: #ffffff; + border: 0 solid #ffffff; +} +.selectize-input > input { + display: inline-block !important; + padding: 0 !important; + min-height: 0 !important; + max-height: none !important; + max-width: 100% !important; + margin: 0 2px 0 0 !important; + text-indent: 0 !important; + border: 0 none !important; + background: none !important; + line-height: inherit !important; + -webkit-user-select: auto !important; + -webkit-box-shadow: none !important; + box-shadow: none !important; +} +.selectize-input > input::-ms-clear { + display: none; +} +.selectize-input > input:focus { + outline: none !important; +} +.selectize-input::after { + content: ' '; + display: block; + clear: left; +} +.selectize-input.dropdown-active::before { + content: ' '; + display: block; + position: absolute; + background: #f0f0f0; + height: 1px; + bottom: 0; + left: 0; + right: 0; +} +.selectize-dropdown { + position: absolute; + z-index: 10; + border: 1px solid #d0d0d0; + background: #fff; + margin: -1px 0 0 0; + border-top: 0 none; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); + -webkit-border-radius: 0 0 3px 3px; + -moz-border-radius: 0 0 3px 3px; + border-radius: 0 0 3px 3px; +} +.selectize-dropdown [data-selectable] { + cursor: pointer; + overflow: hidden; +} +.selectize-dropdown [data-selectable] .highlight { + background: rgba(125, 168, 208, 0.2); + -webkit-border-radius: 1px; + -moz-border-radius: 1px; + border-radius: 1px; +} +.selectize-dropdown .option, +.selectize-dropdown .optgroup-header { + padding: 5px 8px; +} +.selectize-dropdown .option, +.selectize-dropdown [data-disabled], +.selectize-dropdown [data-disabled] [data-selectable].option { + cursor: inherit; + opacity: 0.5; +} +.selectize-dropdown [data-selectable].option { + opacity: 1; +} +.selectize-dropdown .optgroup:first-child .optgroup-header { + border-top: 0 none; +} +.selectize-dropdown .optgroup-header { + color: #303030; + background: #fff; + cursor: default; +} +.selectize-dropdown .active { + background-color: #f5fafd; + color: #495c68; +} +.selectize-dropdown .active.create { + color: #495c68; +} +.selectize-dropdown .create { + color: rgba(48, 48, 48, 0.5); +} +.selectize-dropdown-content { + overflow-y: auto; + overflow-x: hidden; + max-height: 200px; + -webkit-overflow-scrolling: touch; +} +.selectize-control.single .selectize-input, +.selectize-control.single .selectize-input input { + cursor: pointer; +} +.selectize-control.single .selectize-input.input-active, +.selectize-control.single .selectize-input.input-active input { + cursor: text; +} +.selectize-control.single .selectize-input:after { + content: ' '; + display: block; + position: absolute; + top: 50%; + right: 15px; + margin-top: -3px; + width: 0; + height: 0; + border-style: solid; + border-width: 5px 5px 0 5px; + border-color: #808080 transparent transparent transparent; +} +.selectize-control.single .selectize-input.dropdown-active:after { + margin-top: -4px; + border-width: 0 5px 5px 5px; + border-color: transparent transparent #808080 transparent; +} +.selectize-control.rtl.single .selectize-input:after { + left: 15px; + right: auto; +} +.selectize-control.rtl .selectize-input > input { + margin: 0 4px 0 -2px !important; +} +.selectize-control .selectize-input.disabled { + opacity: 0.5; + background-color: #fafafa; +} diff --git a/httemplate/elements/selectize/selectize.min.js b/httemplate/elements/selectize/selectize.min.js new file mode 100644 index 000000000..43046c90d --- /dev/null +++ b/httemplate/elements/selectize/selectize.min.js @@ -0,0 +1,4 @@ +/*! selectize.js - v0.12.6 | https://github.com/selectize/selectize.js | Apache License (v2) */ + +!function(a,b){"function"==typeof define&&define.amd?define("sifter",b):"object"==typeof exports?module.exports=b():a.Sifter=b()}(this,function(){var a=function(a,b){this.items=a,this.settings=b||{diacritics:!0}};a.prototype.tokenize=function(a){if(!(a=e(String(a||"").toLowerCase()))||!a.length)return[];var b,c,d,g,i=[],j=a.split(/ +/);for(b=0,c=j.length;b0)&&d.items.push({score:c,id:e})}):g.iterator(g.items,function(a,b){d.items.push({score:1,id:b})}),e=g.getSortFunction(d,b),e&&d.items.sort(e),d.total=d.items.length,"number"==typeof b.limit&&(d.items=d.items.slice(0,b.limit)),d};var b=function(a,b){return"number"==typeof a&&"number"==typeof b?a>b?1:ab?1:b>a?-1:0)},c=function(a,b){var c,d,e,f;for(c=1,d=arguments.length;c=0&&a.data.length>0){var f=a.data.match(c),g=document.createElement("span");g.className="highlight";var h=a.splitText(e),i=(h.splitText(f[0].length),h.cloneNode(!0));g.appendChild(i),h.parentNode.replaceChild(g,h),b=1}}else if(1===a.nodeType&&a.childNodes&&!/(script|style)/i.test(a.tagName)&&("highlight"!==a.className||"SPAN"!==a.tagName))for(var j=0;j/g,">").replace(/"/g,""")},m={};m.before=function(a,b,c){var d=a[b];a[b]=function(){return c.apply(a,arguments),d.apply(a,arguments)}},m.after=function(a,b,c){var d=a[b];a[b]=function(){var b=d.apply(a,arguments);return c.apply(a,arguments),b}};var n=function(a){var b=!1;return function(){b||(b=!0,a.apply(this,arguments))}},o=function(a,b){var c;return function(){var d=this,e=arguments;window.clearTimeout(c),c=window.setTimeout(function(){a.apply(d,e)},b)}},p=function(a,b,c){var d,e=a.trigger,f={};a.trigger=function(){var c=arguments[0];if(-1===b.indexOf(c))return e.apply(a,arguments);f[c]=arguments},c.apply(a,[]),a.trigger=e;for(d in f)f.hasOwnProperty(d)&&e.apply(a,f[d])},q=function(a,b,c,d){a.on(b,c,function(b){for(var c=b.target;c&&c.parentNode!==a[0];)c=c.parentNode;return b.currentTarget=c,d.apply(this,[b])})},r=function(a){var b={};if("selectionStart"in a)b.start=a.selectionStart,b.length=a.selectionEnd-b.start;else if(document.selection){a.focus();var c=document.selection.createRange(),d=document.selection.createRange().text.length;c.moveStart("character",-a.value.length),b.start=c.text.length-d,b.length=d}return b},s=function(a,b,c){var d,e,f={};if(c)for(d=0,e=c.length;d").css({position:"absolute",top:-99999,left:-99999,width:"auto",padding:0,whiteSpace:"pre"}).appendTo("body")),w.$testInput.text(b),s(c,w.$testInput,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"]),w.$testInput.width()):0},u=function(a){var b=null,c=function(c,d){var e,f,g,h,i,j,k,l;c=c||window.event||{},d=d||{},c.metaKey||c.altKey||(d.force||!1!==a.data("grow"))&&(e=a.val(),c.type&&"keydown"===c.type.toLowerCase()&&(f=c.keyCode,g=f>=48&&f<=57||f>=65&&f<=90||f>=96&&f<=111||f>=186&&f<=222||32===f,46===f||8===f?(l=r(a[0]),l.length?e=e.substring(0,l.start)+e.substring(l.start+l.length):8===f&&l.start?e=e.substring(0,l.start-1)+e.substring(l.start+1):46===f&&void 0!==l.start&&(e=e.substring(0,l.start)+e.substring(l.start+1))):g&&(j=c.shiftKey,k=String.fromCharCode(c.keyCode),k=j?k.toUpperCase():k.toLowerCase(),e+=k)),h=a.attr("placeholder"),!e&&h&&(e=h),(i=t(e,a)+4)!==b&&(b=i,a.width(i),a.triggerHandler("resize")))};a.on("keydown keyup update blur",c),c()},v=function(a){var b=document.createElement("div");return b.appendChild(a.cloneNode(!0)),b.innerHTML},w=function(c,d){var e,f,g,h,i=this;h=c[0],h.selectize=i;var j=window.getComputedStyle&&window.getComputedStyle(h,null);if(g=j?j.getPropertyValue("direction"):h.currentStyle&&h.currentStyle.direction,g=g||c.parents("[dir]:first").attr("dir")||"",a.extend(i,{order:0,settings:d,$input:c,tabIndex:c.attr("tabindex")||"",tagType:"select"===h.tagName.toLowerCase()?1:2,rtl:/rtl/i.test(g),eventNS:".selectize"+ ++w.count,highlightedValue:null,isBlurring:!1,isOpen:!1,isDisabled:!1,isRequired:c.is("[required]"),isInvalid:!1,isLocked:!1,isFocused:!1,isInputHidden:!1,isSetup:!1,isShiftDown:!1,isCmdDown:!1,isCtrlDown:!1,ignoreFocus:!1,ignoreBlur:!1,ignoreHover:!1,hasOptions:!1,currentResults:null,lastValue:"",caretPos:0,loading:0,loadedSearches:{},$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:null===d.loadThrottle?i.onSearchChange:o(i.onSearchChange,d.loadThrottle)}),i.sifter=new b(this.options,{diacritics:d.diacritics}),i.settings.options){for(e=0,f=i.settings.options.length;e").addClass(r.wrapperClass).addClass(m).addClass(l),c=a("
").addClass(r.inputClass).addClass("items").appendTo(b),d=a('').appendTo(c).attr("tabindex",w.is(":disabled")?"-1":p.tabIndex),k=a(r.dropdownParent||b),e=a("
").addClass(r.dropdownClass).addClass(l).hide().appendTo(k),j=a("
").addClass(r.dropdownContentClass).appendTo(e),(o=w.attr("id"))&&(d.attr("id",o+"-selectized"),a("label[for='"+o+"']").attr("for",o+"-selectized")),p.settings.copyClassesToDropdown&&e.addClass(m),b.css({width:w[0].style.width}),p.plugins.names.length&&(n="plugin-"+p.plugins.names.join(" plugin-"),b.addClass(n),e.addClass(n)),(null===r.maxItems||r.maxItems>1)&&1===p.tagType&&w.attr("multiple","multiple"),p.settings.placeholder&&d.attr("placeholder",r.placeholder),!p.settings.splitOn&&p.settings.delimiter){var x=p.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");p.settings.splitOn=new RegExp("\\s*"+x+"+\\s*")}w.attr("autocorrect")&&d.attr("autocorrect",w.attr("autocorrect")),w.attr("autocapitalize")&&d.attr("autocapitalize",w.attr("autocapitalize")),d[0].type=w[0].type,p.$wrapper=b,p.$control=c,p.$control_input=d,p.$dropdown=e,p.$dropdown_content=j,e.on("mouseenter mousedown click","[data-disabled]>[data-selectable]",function(a){a.stopImmediatePropagation()}),e.on("mouseenter","[data-selectable]",function(){return p.onOptionHover.apply(p,arguments)}),e.on("mousedown click","[data-selectable]",function(){return p.onOptionSelect.apply(p,arguments)}),q(c,"mousedown","*:not(input)",function(){return p.onItemSelect.apply(p,arguments)}),u(d),c.on({mousedown:function(){return p.onMouseDown.apply(p,arguments)},click:function(){return p.onClick.apply(p,arguments)}}),d.on({mousedown:function(a){a.stopPropagation()},keydown:function(){return p.onKeyDown.apply(p,arguments)},keyup:function(){return p.onKeyUp.apply(p,arguments)},keypress:function(){return p.onKeyPress.apply(p,arguments)},resize:function(){p.positionDropdown.apply(p,[])},blur:function(){return p.onBlur.apply(p,arguments)},focus:function(){return p.ignoreBlur=!1,p.onFocus.apply(p,arguments)},paste:function(){return p.onPaste.apply(p,arguments)}}),v.on("keydown"+s,function(a){p.isCmdDown=a[f?"metaKey":"ctrlKey"],p.isCtrlDown=a[f?"altKey":"ctrlKey"],p.isShiftDown=a.shiftKey}),v.on("keyup"+s,function(a){a.keyCode===h&&(p.isCtrlDown=!1),16===a.keyCode&&(p.isShiftDown=!1),a.keyCode===g&&(p.isCmdDown=!1)}),v.on("mousedown"+s,function(a){if(p.isFocused){if(a.target===p.$dropdown[0]||a.target.parentNode===p.$dropdown[0])return!1;p.$control.has(a.target).length||a.target===p.$control[0]||p.blur(a.target)}}),t.on(["scroll"+s,"resize"+s].join(" "),function(){p.isOpen&&p.positionDropdown.apply(p,arguments)}),t.on("mousemove"+s,function(){p.ignoreHover=!1}),this.revertSettings={$children:w.children().detach(),tabindex:w.attr("tabindex")},w.attr("tabindex",-1).hide().after(p.$wrapper),a.isArray(r.items)&&(p.setValue(r.items),delete r.items),i&&w.on("invalid"+s,function(a){a.preventDefault(),p.isInvalid=!0,p.refreshState()}),p.updateOriginalInput(),p.refreshItems(),p.refreshState(),p.updatePlaceholder(),p.isSetup=!0,w.is(":disabled")&&p.disable(),p.on("change",this.onChange),w.data("selectize",p),w.addClass("selectized"),p.trigger("initialize"),!0===r.preload&&p.onSearchChange("")},setupTemplates:function(){var b=this,c=b.settings.labelField,d=b.settings.optgroupLabelField,e={optgroup:function(a){return'
'+a.html+"
"},optgroup_header:function(a,b){return'
'+b(a[d])+"
"},option:function(a,b){return'
'+b(a[c])+"
"},item:function(a,b){return'
'+b(a[c])+"
"},option_create:function(a,b){return'
Add '+b(a.input)+"
"}};b.settings.render=a.extend({},e,b.settings.render)},setupCallbacks:function(){var a,b,c={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur"};for(a in c)c.hasOwnProperty(a)&&(b=this.settings[c[a]])&&this.on(a,b)},onClick:function(a){var b=this;b.isFocused&&b.isOpen||(b.focus(),a.preventDefault())},onMouseDown:function(b){var c=this,d=b.isDefaultPrevented();a(b.target);if(c.isFocused){if(b.target!==c.$control_input[0])return"single"===c.settings.mode?c.isOpen?c.close():c.open():d||c.setActiveItem(null),!1}else d||window.setTimeout(function(){c.focus()},0)},onChange:function(){this.$input.trigger("change")},onPaste:function(b){var c=this;if(c.isFull()||c.isInputHidden||c.isLocked)return void b.preventDefault();c.settings.splitOn&&setTimeout(function(){var b=c.$control_input.val();if(b.match(c.settings.splitOn))for(var d=a.trim(b).split(c.settings.splitOn),e=0,f=d.length;eh&&(j=g,g=h,h=j),e=g;e<=h;e++)i=l.$control[0].childNodes[e],-1===l.$activeItems.indexOf(i)&&(a(i).addClass("active"),l.$activeItems.push(i));c.preventDefault()}else"mousedown"===d&&l.isCtrlDown||"keydown"===d&&this.isShiftDown?b.hasClass("active")?(f=l.$activeItems.indexOf(b[0]),l.$activeItems.splice(f,1),b.removeClass("active")):l.$activeItems.push(b.addClass("active")[0]):(a(l.$activeItems).removeClass("active"),l.$activeItems=[b.addClass("active")[0]]);l.hideInput(),this.isFocused||l.focus()}},setActiveOption:function(b,c,d){var e,f,g,h,i,k=this;k.$activeOption&&k.$activeOption.removeClass("active"),k.$activeOption=null,b=a(b),b.length&&(k.$activeOption=b.addClass("active"),!c&&j(c)||(e=k.$dropdown_content.height(),f=k.$activeOption.outerHeight(!0),c=k.$dropdown_content.scrollTop()||0,g=k.$activeOption.offset().top-k.$dropdown_content.offset().top+c,h=g,i=g-e+f,g+f>e+c?k.$dropdown_content.stop().animate({scrollTop:i},d?k.settings.scrollDuration:0):g=0;c--)-1!==f.items.indexOf(k(d.items[c].id))&&d.items.splice(c,1);return d},refreshOptions:function(b){var c,e,f,g,h,i,j,l,m,n,o,p,q,r,s,t;void 0===b&&(b=!0);var u=this,w=a.trim(u.$control_input.val()),x=u.search(w),y=u.$dropdown_content,z=u.$activeOption&&k(u.$activeOption.attr("data-value"));for(g=x.items.length,"number"==typeof u.settings.maxOptions&&(g=Math.min(g,u.settings.maxOptions)),h={},i=[],c=0;c0||q,u.hasOptions?(x.items.length>0?(s=z&&u.getOption(z),s&&s.length?r=s:"single"===u.settings.mode&&u.items.length&&(r=u.getOption(u.items[0])),r&&r.length||(r=t&&!u.settings.addPrecedence?u.getAdjacentOption(t,1):y.find("[data-selectable]:first"))):r=t,u.setActiveOption(r),b&&!u.isOpen&&u.open()):(u.setActiveOption(null),b&&u.isOpen&&u.close())},addOption:function(b){var c,d,e,f=this;if(a.isArray(b))for(c=0,d=b.length;c=0&&e0),b.$control_input.data("grow",!c&&!d)},isFull:function(){ +return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems},updateOriginalInput:function(a){var b,c,d,e,f=this;if(a=a||{},1===f.tagType){for(d=[],b=0,c=f.items.length;b'+l(e)+"");d.length||this.$input.attr("multiple")||d.push(''),f.$input.html(d.join(""))}else f.$input.val(f.getValue()),f.$input.attr("value",f.$input.val());f.isSetup&&(a.silent||f.trigger("change",f.$input.val()))},updatePlaceholder:function(){if(this.settings.placeholder){var a=this.$control_input;this.items.length?a.removeAttr("placeholder"):a.attr("placeholder",this.settings.placeholder),a.triggerHandler("update",{force:!0})}},open:function(){var a=this;a.isLocked||a.isOpen||"multi"===a.settings.mode&&a.isFull()||(a.focus(),a.isOpen=!0,a.refreshState(),a.$dropdown.css({visibility:"hidden",display:"block"}),a.positionDropdown(),a.$dropdown.css({visibility:"visible"}),a.trigger("dropdown_open",a.$dropdown))},close:function(){var a=this,b=a.isOpen;"single"===a.settings.mode&&a.items.length&&(a.hideInput(),a.isBlurring||a.$control_input.blur()),a.isOpen=!1,a.$dropdown.hide(),a.setActiveOption(null),a.refreshState(),b&&a.trigger("dropdown_close",a.$dropdown)},positionDropdown:function(){var a=this.$control,b="body"===this.settings.dropdownParent?a.offset():a.position();b.top+=a.outerHeight(!0),this.$dropdown.css({width:a[0].getBoundingClientRect().width,top:b.top,left:b.left})},clear:function(a){var b=this;b.items.length&&(b.$control.children(":not(input)").remove(),b.items=[],b.lastQuery=null,b.setCaret(0),b.setActiveItem(null),b.updatePlaceholder(),b.updateOriginalInput({silent:a}),b.refreshState(),b.showInput(),b.trigger("clear"))},insertAtCaret:function(a){var b=Math.min(this.caretPos,this.items.length),c=a[0],d=this.buffer||this.$control[0];0===b?d.insertBefore(c,d.firstChild):d.insertBefore(c,d.childNodes[b]),this.setCaret(b+1)},deleteSelection:function(b){var c,d,e,f,g,h,i,j,k,l=this;if(e=b&&8===b.keyCode?-1:1,f=r(l.$control_input[0]),l.$activeOption&&!l.settings.hideSelected&&(i=l.getAdjacentOption(l.$activeOption,-1).attr("data-value")),g=[],l.$activeItems.length){for(k=l.$control.children(".active:"+(e>0?"last":"first")),h=l.$control.children(":not(input)").index(k),e>0&&h++,c=0,d=l.$activeItems.length;c0&&f.start===l.$control_input.val().length&&g.push(l.items[l.caretPos]));if(!g.length||"function"==typeof l.settings.onDelete&&!1===l.settings.onDelete.apply(l,[g]))return!1;for(void 0!==h&&l.setCaret(h);g.length;)l.removeItem(g.pop());return l.showInput(),l.positionDropdown(),l.refreshOptions(!0),i&&(j=l.getOption(i),j.length&&l.setActiveOption(j)),!0},advanceSelection:function(a,b){var c,d,e,f,g,h=this;0!==a&&(h.rtl&&(a*=-1),c=a>0?"last":"first",d=r(h.$control_input[0]),h.isFocused&&!h.isInputHidden?(f=h.$control_input.val().length,(a<0?0===d.start&&0===d.length:d.start===f)&&!f&&h.advanceCaret(a,b)):(g=h.$control.children(".active:"+c),g.length&&(e=h.$control.children(":not(input)").index(g),h.setActiveItem(null),h.setCaret(a>0?e+1:e))))},advanceCaret:function(a,b){var c,d,e=this;0!==a&&(c=a>0?"next":"prev",e.isShiftDown?(d=e.$control_input[c](),d.length&&(e.hideInput(),e.setActiveItem(d),b&&b.preventDefault())):e.setCaret(e.caretPos+a))},setCaret:function(b){var c=this;if(b="single"===c.settings.mode?c.items.length:Math.max(0,Math.min(c.items.length,b)),!c.isPending){var d,e,f,g;for(f=c.$control.children(":not(input)"),d=0,e=f.length;d
'+a.title+'×
'}},b),c.setup=function(){var d=c.setup;return function(){d.apply(c,arguments),c.$dropdown_header=a(b.html(b)),c.$dropdown.prepend(c.$dropdown_header)}}()}),w.define("optgroup_columns",function(b){var c=this;b=a.extend({equalizeWidth:!0,equalizeHeight:!0},b),this.getAdjacentOption=function(b,c){var d=b.closest("[data-group]").find("[data-selectable]"),e=d.index(b)+c;return e>=0&&e
',a=a.firstChild,c.body.appendChild(a),b=d.width=a.offsetWidth-a.clientWidth,c.body.removeChild(a)),b},e=function(){var e,f,g,h,i,j,k;if(k=a("[data-group]",c.$dropdown_content),(f=k.length)&&c.$dropdown_content.width()){if(b.equalizeHeight){for(g=0,e=0;e1&&(i=j-h*(f-1),k.eq(f-1).css({width:i})))}};(b.equalizeHeight||b.equalizeWidth)&&(m.after(this,"positionDropdown",e),m.after(this,"refreshOptions",e))}),w.define("remove_button",function(b){b=a.extend({label:"×",title:"Remove",className:"remove",append:!0},b);if("single"===this.settings.mode)return void function(b,c){c.className="remove-single";var d=b,e=''+c.label+"",f=function(b,c){return a("").append(b).append(c)};b.setup=function(){var g=d.setup;return function(){if(c.append){var h=a(d.$input.context).attr("id"),i=(a("#"+h),d.settings.render.item);d.settings.render.item=function(a){return f(i.apply(b,arguments),e)}}g.apply(b,arguments),b.$control.on("click","."+c.className,function(a){a.preventDefault(),d.isLocked||d.clear()})}}()}(this,b);!function(b,c){var d=b,e=''+c.label+"",f=function(a,b){var c=a.search(/(<\/[^>]+>\s*)$/);return a.substring(0,c)+b+a.substring(c)};b.setup=function(){var g=d.setup;return function(){if(c.append){var h=d.settings.render.item;d.settings.render.item=function(a){return f(h.apply(b,arguments),e)}}g.apply(b,arguments),b.$control.on("click","."+c.className,function(b){if(b.preventDefault(),!d.isLocked){var c=a(b.currentTarget).parent();d.setActiveItem(c),d.deleteSelection()&&d.setCaret(d.items.length)}})}}()}(this,b)}),w.define("restore_on_backspace",function(a){var b=this;a.text=a.text||function(a){return a[this.settings.labelField]},this.onKeyDown=function(){var c=b.onKeyDown;return function(b){var d,e;return 8===b.keyCode&&""===this.$control_input.val()&&!this.$activeItems.length&&(d=this.caretPos-1)>=0&&d