%# BEGIN BPS TAGGED BLOCK {{{
%#
%# COPYRIGHT:
%#
%# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC
%#                                          <sales@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
%#
%#
%# LICENSE:
%#
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%#
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%# General Public License for more details.
%#
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
%# 02110-1301 or visit their web page on the internet at
%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
%#
%#
%# CONTRIBUTION SUBMISSION POLICY:
%#
%# (The following paragraph is not intended to limit the rights granted
%# to you to modify and distribute this software under the terms of
%# the GNU General Public License and is only of importance to you if
%# you choose to contribute your changes and enhancements to the
%# community by submitting them to Best Practical Solutions, LLC.)
%#
%# By intentionally submitting any modifications, corrections or
%# derivatives to this work, or any other work intended for use with
%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
%# you are the copyright holder for those contributions and you grant
%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
%# royalty-free, perpetual, license to use, copy, create derivative
%# works based on those contributions, and sublicense and distribute
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
<div class="form-row">
  <div class="col-1"></div>
  <div class="col-10">
<form name="AddCustomFieldValue" action="Modify.html" method="post">
<input type="hidden" class="hidden" name="id" value="<% $CustomField->id %>" />

% # we need to allow for an extra col-2 if not combobox and categories are enabled
% # if so, make the description cols -2 smaller to allow for categories
% my $description_col_size = ( $CustomField->Type ne 'Combobox' && $Categories ? 4 : 6 );

  <div class="form-row">
    <div class="label col-1 text-left">
      <&|/l&>Sort</&>
    </div>
    <div class="label col-4 text-left">
      <&|/l&>Name</&>
    </div>
    <div class="label col-<% $description_col_size %> text-left">
      <&|/l&>Description</&>
    </div>
% if ( $CustomField->Type ne 'Combobox' && $Categories ) {
    <div class="label categoryheader col-2 text-left">
      <&|/l&>Category</&>
    </div>
% }
  </div>

% my $paramtag = "CustomField-". $CustomField->Id ."-Value-new";
  <div class="form-row">
    <div class="value col-1">
      <input class="form-control" type="text" size="3"  name="<% $paramtag %>-SortOrder" />
    </div>
    <div class="value col-4">
      <input class="form-control" type="text" size="25" name="<% $paramtag %>-Name" />
    </div>
    <div class="value col-<% $description_col_size %>">
      <input class="form-control" type="text" size="45" name="<% $paramtag %>-Description" />
    </div>
% if ( $CustomField->Type ne 'Combobox' && $Categories ) {
    <div class="value col-2">
      <select class="form-control selectpicker editcategory " name="<% $paramtag %>-Category" size="1">
<option value=""><&|/l&>(no value)</&></option>
% while (my $Value = $Categories->Next) {
        <option value="<% $Value->Name %>"><% $Value->Name %></option>
%   }
      </select>
    </div>
% }
    <div class="col-1">
      <input type="submit" class="btn btn-primary btn-sm form-control" name="AddValue" value="<&|/l&>Add</&>" />
    </div>
  </div>
% $m->callback(CallbackName => 'AfterCustomFieldValueInput', CustomFieldObj => $CustomField, ARGSRef => \%ARGS );
</form>
</div>
  <div class="col-1"></div>
</div>

<script type="text/javascript">
jQuery( function() {
    jQuery('form[name=AddCustomFieldValue]').submit(function() {
        jQuery.post('<% RT->Config->Get('WebPath') %>/Helpers/Admin/EditCustomFieldValue', {
            action: 'add',
            cf_id: <% $CustomField->id %>,
            sort_order: jQuery('input[name=CustomField-<% $CustomField->id %>-Value-new-SortOrder]').val(),
            name: jQuery('input[name=CustomField-<% $CustomField->id %>-Value-new-Name]').val(),
            description: jQuery('input[name=CustomField-<% $CustomField->id %>-Value-new-Description]').val(),
            category: jQuery('[name=CustomField-<% $CustomField->id %>-Value-new-Category]').val()
        }, function(data) {
            if ( data.status != 0 ) {
                jQuery('div.edit_custom_field_values').html(data.html);
                jQuery('input[name=CustomField-<% $CustomField->id %>-Value-new-SortOrder]').val(''),
                jQuery('input[name=CustomField-<% $CustomField->id %>-Value-new-Name]').val('').focus(),
                jQuery('input[name=CustomField-<% $CustomField->id %>-Value-new-Description]').val(''),
                jQuery('[name=CustomField-<% $CustomField->id %>-Value-new-Category]').val('');
                jQuery('form[name=AddCustomFieldValue] select.selectpicker, div.edit_custom_field_values select.selectpicker').selectpicker('refresh');
            }
            else {
                alert(data.message);
            }
        }, 'json');
        return false;
    });
});
</script>
<%init>
my $BasedOnObj = $CustomField->BasedOnObj;
my $Categories;
if ($BasedOnObj and $BasedOnObj->Id) {
    $Categories = $BasedOnObj->Values;
}
</%init>
<%args>
$CustomField => undef
</%args>
