+ my $select_html = html_tag('select', $code, %attributes, name => $name);
+
+ if ($with_filter) {
+ my $input_style;
+
+ if (($attributes{style} // '') =~ m{width: *(\d+) *px}i) {
+ $input_style = "width: " . ($1 - 22) . "px";
+ }
+
+ my $input_html = html_tag(
+ 'input', undef,
+ autocomplete => 'off',
+ type => 'text',
+ id => $attributes{id} . '_filter',
+ 'data-select-id' => $attributes{id},
+ (placeholder => $fil_placeholder) x !!$fil_placeholder,
+ (style => $input_style) x !!$input_style,
+ );
+ $select_html = html_tag('div', $input_html . $select_html, class => "filtered_select");
+ }
+
+ return $select_html;
+}
+
+sub checkbox_tag {
+ my ($name, %attributes) = @_;
+
+ my %label_attributes = map { (substr($_, 6) => $attributes{$_}) } grep { m{^label_} } keys %attributes;
+ delete @attributes{grep { m{^label_} } keys %attributes};
+
+ _set_id_attribute(\%attributes, $name);
+
+ $attributes{value} = 1 unless defined $attributes{value};
+ my $label = delete $attributes{label};
+ my $checkall = delete $attributes{checkall};
+ my $for_submit = delete $attributes{for_submit};
+
+ if ($attributes{checked}) {
+ $attributes{checked} = 'checked';
+ } else {
+ delete $attributes{checked};
+ }
+
+ my $code = '';
+ $code .= hidden_tag($name, 0, %attributes, id => $attributes{id} . '_hidden') if $for_submit;
+ $code .= html_tag('input', undef, %attributes, name => $name, type => 'checkbox');
+ $code .= html_tag('label', $label, for => $attributes{id}, %label_attributes) if $label;
+ $code .= javascript(qq|\$('#$attributes{id}').checkall('$checkall');|) if $checkall;
+
+ return $code;
+}
+
+sub radio_button_tag {
+ my ($name, %attributes) = @_;
+
+ my %label_attributes = map { (substr($_, 6) => $attributes{$_}) } grep { m{^label_} } keys %attributes;
+ delete @attributes{grep { m{^label_} } keys %attributes};
+
+ $attributes{value} = 1 unless exists $attributes{value};
+
+ _set_id_attribute(\%attributes, $name, 1);
+ my $label = delete $attributes{label};
+
+ _set_id_attribute(\%attributes, $name . '_' . $attributes{value});
+
+ if ($attributes{checked}) {
+ $attributes{checked} = 'checked';
+ } else {
+ delete $attributes{checked};
+ }
+
+ my $code = html_tag('input', undef, %attributes, name => $name, type => 'radio');
+ $code .= html_tag('label', $label, for => $attributes{id}, %label_attributes) if $label;
+
+ return $code;
+}
+
+sub button_tag {
+ my ($onclick, $value, %attributes) = @_;
+
+ _set_id_attribute(\%attributes, $attributes{name}) if $attributes{name};
+ $attributes{type} ||= 'button';
+
+ $onclick = 'if (!confirm("'. _J(delete($attributes{confirm})) .'")) return false; ' . $onclick if $attributes{confirm};
+
+ html_tag('input', undef, %attributes, value => $value, (onclick => $onclick)x!!$onclick);
+}
+
+sub submit_tag {
+ my ($name, $value, %attributes) = @_;
+
+ _set_id_attribute(\%attributes, $attributes{name}) if $attributes{name};
+
+ if ( $attributes{confirm} ) {
+ $attributes{onclick} = 'return confirm("'. _J(delete($attributes{confirm})) .'");';
+ }
+
+ input_tag($name, $value, %attributes, type => 'submit', class => 'submit');
+}
+
+sub ajax_submit_tag {
+ my ($url, $form_selector, $text, %attributes) = @_;
+
+ $url = _J($url);
+ $form_selector = _J($form_selector);
+ my $onclick = qq|kivi.submit_ajax_form('${url}', '${form_selector}')|;
+
+ button_tag($onclick, $text, %attributes);
+}
+
+sub input_number_tag {
+ my ($name, $value, %params) = @_;
+
+ _set_id_attribute(\%params, $name);
+ my @onchange = $params{onchange} ? (onChange => delete $params{onchange}) : ();
+ my @classes = ('numeric');
+ push @classes, delete($params{class}) if $params{class};
+ my %class = @classes ? (class => join(' ', @classes)) : ();
+
+ $::request->layout->add_javascripts('kivi.Validator.js');
+ $::request->presenter->need_reinit_widgets($params{id});
+
+ input_tag(
+ $name, $::form->format_amount(\%::myconfig, $value, $params{precision}),
+ "data-validate" => "number",
+ %params,
+ %class, @onchange,
+ );
+}
+
+
+sub javascript {
+ my ($data) = @_;
+ html_tag('script', $data, type => 'text/javascript');