[Rt-commit] rt branch, 4.6/assetsql, created. rt-4.4.0-77-gd793881
Shawn Moore
shawn at bestpractical.com
Wed Jun 15 18:48:23 EDT 2016
The branch, 4.6/assetsql has been created
at d793881c1db37a00d530700d548153300147a662 (commit)
- Log -----------------------------------------------------------------
commit b16c120e24d1f2ac58768d2a68c587ff26b5d6ec
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Sep 18 04:56:02 2014 +0800
ajaxify add/delete actions for admin custom field values
Add's backend code on Modify.html is kept(with a bit tweaking) to only make tests happy.
diff --git a/share/html/Admin/CustomFields/Modify.html b/share/html/Admin/CustomFields/Modify.html
index eea4532..1751a63 100644
--- a/share/html/Admin/CustomFields/Modify.html
+++ b/share/html/Admin/CustomFields/Modify.html
@@ -47,9 +47,6 @@
%# END BPS TAGGED BLOCK }}}
<& /Admin/Elements/Header,
Title => $title,
- Focus => (($added_cfv or $ARGS{FocusAddValue})
- ? "input[name=CustomField-$id-Value-new-Name]"
- : undef),
&>
<& /Elements/Tabs &>
<& /Elements/ListActions, actions => \@results &>
@@ -169,15 +166,20 @@ jQuery( function() {
% if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType && !$CustomFieldObj->IsExternalValues ) {
<h2><&|/l&>Values</&></h2>
-<div>
+<div class="edit_custom_field_values">
<& /Admin/Elements/EditCustomFieldValues, CustomField => $CustomFieldObj &>
-<& /Admin/Elements/AddCustomFieldValue, CustomField => $CustomFieldObj &>
</div>
% }
<& /Elements/Submit, Name => 'Update', Label => $id eq 'new'? loc('Create'): loc('Save Changes') &>
</form>
+
+% if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType && !$CustomFieldObj->IsExternalValues ) {
+<div class="add_custom_field_value">
+<& /Admin/Elements/AddCustomFieldValue, CustomField => $CustomFieldObj &>
+</div>
+% }
<%INIT>
my ($title, @results, $added_cfv);
@@ -267,15 +269,8 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
push @results, $msg;
}
- my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
- # Delete any fields that want to be deleted
- foreach my $key ( keys %ARGS ) {
- next unless $key =~ /^Delete-$paramtag-(\d+)$/;
- my ($val, $msg) = $CustomFieldObj->DeleteValue( $1 );
- push (@results, $msg);
- }
-
# Update any existing values
+ my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
my $values = $CustomFieldObj->ValuesObj;
while ( my $value = $values->Next ) {
foreach my $attr (qw(Name Description SortOrder Category)) {
@@ -292,7 +287,12 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
$m->callback(CallbackName => 'AfterUpdateCustomFieldValue', CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $value, ARGSRef => \%ARGS );
}
+}
+
+# for old tests only, users should use ajax calls and this should never be called in real usage.
+if ( $ARGS{'AddValue'} ) {
# Add any new values
+ my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
if ( defined $ARGS{ $paramtag ."-new-Name" } && length $ARGS{ $paramtag ."-new-Name" } ) {
my ($id, $msg) = $CustomFieldObj->AddValue(
map {
@@ -301,12 +301,6 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
$_ => $ARGS{ $paramtag ."-new-$_" } } qw/ Name Description SortOrder Category/
);
push (@results, $msg);
- $added_cfv = 1 if $id;
-
- my $cfv = RT::CustomFieldValue->new( $session{CurrentUser} );
- $cfv->Load($id);
- $m->callback(CallbackName => 'AfterCreateCustomFieldValue',
-CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $cfv, ARGSRef => \%ARGS );
}
}
@@ -330,7 +324,7 @@ $id = $CustomFieldObj->id if $CustomFieldObj->id;
# This code does automatic redirection if any updates happen.
MaybeRedirectForResults(
Actions => \@results,
- Arguments => { id => $id, FocusAddValue => ($added_cfv ? 1 : 0) },
+ Arguments => { id => $id },
) if $CustomFieldObj->id;
diff --git a/share/html/Admin/Elements/AddCustomFieldValue b/share/html/Admin/Elements/AddCustomFieldValue
index ec1a34b..4cb2ce1 100644
--- a/share/html/Admin/Elements/AddCustomFieldValue
+++ b/share/html/Admin/Elements/AddCustomFieldValue
@@ -47,8 +47,9 @@
%# END BPS TAGGED BLOCK }}}
<h3><&|/l&>Add Value</&></h3>
+<form name="AddCustomFieldValue" action="Modify.html" method="post">
+<input type="hidden" class="hidden" name="id" value="<% $CustomField->id %>" />
<table border="0">
-
<tr>
<th><&|/l&>Sort</&></th>
<th><&|/l&>Name</&></th>
@@ -56,6 +57,7 @@
% if ( $CustomField->Type ne 'Combobox' ) {
<th class="categoryheader"><&|/l&>Category</&></th>
% }
+<th></th>
</tr>
% my $paramtag = "CustomField-". $CustomField->Id ."-Value-new";
@@ -78,11 +80,39 @@
% }
</td>
% }
-
+<td><input type="submit" name="AddValue" value="<&|/l&>Add</&>" /></td>
% $m->callback(CallbackName => 'AfterCustomFieldValueInput', CustomFieldObj => $CustomField, ARGSRef => \%ARGS );
</tr>
</table>
+</form>
+<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('');
+ }
+ else {
+ alert(data.message);
+ }
+ }, 'json');
+ return false;
+ });
+});
+</script>
+
<%args>
$CustomField => undef
</%args>
diff --git a/share/html/Admin/Elements/EditCustomFieldValues b/share/html/Admin/Elements/EditCustomFieldValues
index 5a81ec7..90db3be 100644
--- a/share/html/Admin/Elements/EditCustomFieldValues
+++ b/share/html/Admin/Elements/EditCustomFieldValues
@@ -53,19 +53,18 @@
<table>
<tr>
-<th> </th>
<th><&|/l&>Sort</&></th>
<th><&|/l&>Name</&></th>
<th><&|/l&>Description</&></th>
% if ($CustomField->Type ne 'Combobox') {
<th class="categoryheader"><&|/l&>Category</&></th>
% }
+<th></th>
</tr>
% while ( my $value = $values->Next ) {
% my $paramtag = "CustomField-". $CustomField->Id ."-Value-". $value->Id;
<tr>
-<td><input type="checkbox" class="checkbox" name="Delete-<% $paramtag %>" /></td>
<td><input type="text" size="3" name="<% $paramtag %>-SortOrder" value="<% $value->SortOrder %>" /></td>
<td><input type="text" size="25" name="<% $paramtag %>-Name" value="<% $value->Name %>" /></td>
<td><input type="text" size="45" name="<% $paramtag %>-Description" value="<% $value->Description || '' %>" /></td>
@@ -84,12 +83,29 @@
% }
</td>
% }
+<td><input type="button" class="delete_custom_field_value" data-cfv-id="<% $value->id %>" value="<&|/l&>Delete</&>" onclick="delete_custom_field_value(<% $value->id %>)" /></td>
% $m->callback(CallbackName => 'AfterCustomFieldValueInput', CustomFieldObj => $CustomField, CustomFieldValueObj => $value, ARGSRef => \%ARGS );
</tr>
% }
</table>
-<i><&|/l&>(Check box to delete)</&></i>
+
+<script type="text/javascript">
+function delete_custom_field_value(value_id) {
+ jQuery.post('<% RT->Config->Get('WebPath') %>/Helpers/Admin/EditCustomFieldValue', {
+ action: 'delete',
+ cf_id: <% $CustomField->id %>,
+ value_id: value_id
+ }, function(data) {
+ if ( data.status != 0 ) {
+ jQuery('div.edit_custom_field_values').html(data.html);
+ }
+ else {
+ alert(data.message);
+ }
+ }, 'json')
+}
+</script>
<%init>
my $values = $CustomField->ValuesObj();
diff --git a/share/html/Admin/Elements/AddCustomFieldValue b/share/html/Helpers/Admin/EditCustomFieldValue
similarity index 60%
copy from share/html/Admin/Elements/AddCustomFieldValue
copy to share/html/Helpers/Admin/EditCustomFieldValue
index ec1a34b..83cd86c 100644
--- a/share/html/Admin/Elements/AddCustomFieldValue
+++ b/share/html/Helpers/Admin/EditCustomFieldValue
@@ -45,44 +45,47 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<h3><&|/l&>Add Value</&></h3>
+% $r->content_type('application/json; charset=utf-8');
+<% JSON( $out ) |n %>
+% $m->abort;
+<%INIT>
-<table border="0">
+my $out = {};
-<tr>
-<th><&|/l&>Sort</&></th>
-<th><&|/l&>Name</&></th>
-<th><&|/l&>Description</&></th>
-% if ( $CustomField->Type ne 'Combobox' ) {
-<th class="categoryheader"><&|/l&>Category</&></th>
-% }
-</tr>
+if ( $cf_id ) {
+ my $cf = RT::CustomField->new($session{CurrentUser});
+ $cf->LoadById($cf_id);
+ if ( !$cf->Name ) {
+ $out = { status => 0, message => loc("Current User cannot see this Custom Field, terminating") };
+ }
+ else {
+ my ( $ret, $msg, $html );
+ if ( $action eq 'add' ) {
+ ( $ret, $msg ) = $cf->AddValue(
+ Name => $ARGS{name},
+ SortOrder => $ARGS{sort_order} || 0,
+ Description => $ARGS{description},
+ Category => $ARGS{category},
+ );
+ $html = $m->scomp('/Admin/Elements/EditCustomFieldValues', CustomField => $cf ) if $ret;
+ }
+ elsif ( $action eq 'delete' ) {
+ ( $ret, $msg ) = $cf->DeleteValue( $ARGS{value_id} );
+ $html = $m->scomp('/Admin/Elements/EditCustomFieldValues', CustomField => $cf ) if $ret;
+ }
+ else {
+ ( $ret, $msg ) = ( 0, loc('Invalid action') );
+ }
-% my $paramtag = "CustomField-". $CustomField->Id ."-Value-new";
-<tr>
-<td><input type="text" size="3" name="<% $paramtag %>-SortOrder" /></td>
-<td><input type="text" size="25" name="<% $paramtag %>-Name" /></td>
-<td><input type="text" size="45" name="<% $paramtag %>-Description" /></td>
-% if ( $CustomField->Type ne 'Combobox' ) {
-<td>
-% my $BasedOnObj = $CustomField->BasedOnObj;
-% if ( $BasedOnObj and $BasedOnObj->id ) {
-% my $Categories = $BasedOnObj->Values;
-<select class="editcategory" name="<% $paramtag %>-Category" size="1">
-<option value=""><&|/l&>(no value)</&></option>
-% while (my $Value = $Categories->Next) {
-<option value="<% $Value->Name %>"><% $Value->Name %></option>
-% }
-% } else {
-<input type="text" size="10" class="editcategory" name="<% $paramtag %>-Category" value="" />
-% }
-</td>
-% }
+ $out = { status => $ret || 0, message => $msg, html => $html };
+ }
+}
+else {
+ $out = { status => 0, message => loc("No CustomField provided") };
+}
+</%INIT>
-% $m->callback(CallbackName => 'AfterCustomFieldValueInput', CustomFieldObj => $CustomField, ARGSRef => \%ARGS );
-</tr>
-
-</table>
-<%args>
-$CustomField => undef
-</%args>
+<%ARGS>
+$action => ''
+$cf_id => undef
+</%ARGS>
diff --git a/t/web/cf_select_one.t b/t/web/cf_select_one.t
index 4f81e2a..8a2e3ac 100644
--- a/t/web/cf_select_one.t
+++ b/t/web/cf_select_one.t
@@ -30,11 +30,11 @@ diag "add 'qwe', 'ASD', '0' and ' foo ' as values to the CF";
{
foreach my $value(qw(qwe ASD 0), 'foo ') {
$m->submit_form(
- form_name => "ModifyCustomField",
+ form_name => "AddCustomFieldValue",
fields => {
"CustomField-". $cfid ."-Value-new-Name" => $value,
},
- button => 'Update',
+ button => 'AddValue',
);
$m->content_contains('Object created', 'added a value to the CF' ); # or diag $m->content;
my $v = $value;
commit 578049526ec53b537ba20cc08740b54a70316eba
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Mon Nov 16 11:09:22 2015 -0500
Fix mismerge of _DurationAsString
We shifted off $self, so use it instead of $_[0] for ->loc
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index bb4cf2c..e7df03c 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -1368,10 +1368,10 @@ sub _DurationAsString {
my $value = shift;
return "" unless $value;
if ($value < 60) {
- return $_[0]->loc("[quant,_1,minute,minutes]", $value);
+ return $self->loc("[quant,_1,minute,minutes]", $value);
} else {
my $h = sprintf("%.2f", $value / 60 );
- return $_[0]->loc("[quant,_1,hour,hours] ([quant,_2,minute,minutes])", $h, $value);
+ return $self->loc("[quant,_1,hour,hours] ([quant,_2,minute,minutes])", $h, $value);
}
}
commit 75865b30f8c693956dfc23db568cbf1ba2e29514
Merge: 5780495 fe8587f
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Fri Dec 4 10:50:18 2015 -0500
Merge branch '4.4.0-releng'
diff --cc sbin/rt-setup-database.in
index 1ec3c4a,d8e4fb2..d352143
--- a/sbin/rt-setup-database.in
+++ b/sbin/rt-setup-database.in
@@@ -353,7 -353,10 +353,8 @@@ sub action_insert
my %args = @_;
unless ($RAN_INIT) {
$RT::Handle = RT::Handle->new;
- my $has_custom_roles = grep { lc($_) eq 'customroles' } $RT::Handle->_TableNames(get_admin_dbh());
-
+ my $dbh = get_admin_dbh();
+ my $has_custom_roles = grep { lc($_) eq 'customroles' } $RT::Handle->_TableNames($dbh);
-
RT::Init(SkipCustomRoles => !$has_custom_roles);
$RAN_INIT++;
}
commit 79895e3ea85994f95fbcec28c97bc68e3b6d3f16
Merge: 75865b3 83ecd2a
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Mon Dec 28 17:53:17 2015 +0000
Merge branch '4.4-trunk'
commit e38da008b13b1e163fe3800035c4debfc3eecfff
Merge: 79895e3 b16c120
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Mon Dec 28 17:58:55 2015 +0000
Merge branch '4.4/ajax-admin-custom-field-values'
diff --cc share/html/Admin/CustomFields/Modify.html
index 446975e,1751a63..4e8f570
--- a/share/html/Admin/CustomFields/Modify.html
+++ b/share/html/Admin/CustomFields/Modify.html
@@@ -275,23 -269,8 +277,16 @@@ if ( $ARGS{'Update'} && $id ne 'new' )
push @results, $msg;
}
+ if ( $CustomFieldObj->SupportDefaultValues ) {
+ my ($ret, $msg) = $CustomFieldObj->SetDefaultValues(
+ Object => RT->System,
+ Values => $ARGS{'Default-' . $CustomFieldObj->id . '-Value'} // $ARGS{'Default-' . $CustomFieldObj->id . '-Values'},
+ );
+ push @results, $msg;
+ }
+
- my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
- # Delete any fields that want to be deleted
- foreach my $key ( keys %ARGS ) {
- next unless $key =~ /^Delete-$paramtag-(\d+)$/;
- my ($val, $msg) = $CustomFieldObj->DeleteValue( $1 );
- push (@results, $msg);
- }
-
# Update any existing values
+ my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
my $values = $CustomFieldObj->ValuesObj;
while ( my $value = $values->Next ) {
foreach my $attr (qw(Name Description SortOrder Category)) {
@@@ -314,15 -298,9 +314,9 @@@ if ( $ARGS{'AddValue'} )
map {
$ARGS{$paramtag."-new-$_"} =~ s/^\s+//;
$ARGS{$paramtag."-new-$_"} =~ s/\s+$//;
- $_ => $ARGS{ $paramtag ."-new-$_" } } qw/ Name Description SortOrder Category/
+ $_ => $ARGS{ $paramtag ."-new-$_" } } grep { defined $ARGS{ $paramtag ."-new-$_" } } qw/ Name Description SortOrder Category/
);
push (@results, $msg);
- $added_cfv = 1 if $id;
-
- my $cfv = RT::CustomFieldValue->new( $session{CurrentUser} );
- $cfv->Load($id);
- $m->callback(CallbackName => 'AfterCreateCustomFieldValue',
- CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $cfv, ARGSRef => \%ARGS );
}
}
diff --cc share/html/Admin/Elements/AddCustomFieldValue
index 2b5ce4e,4cb2ce1..7ef5b8e
--- a/share/html/Admin/Elements/AddCustomFieldValue
+++ b/share/html/Admin/Elements/AddCustomFieldValue
@@@ -53,9 -54,10 +54,10 @@@
<th><&|/l&>Sort</&></th>
<th><&|/l&>Name</&></th>
<th><&|/l&>Description</&></th>
-% if ( $CustomField->Type ne 'Combobox' ) {
+% if ( $CustomField->Type ne 'Combobox' && $Categories ) {
<th class="categoryheader"><&|/l&>Category</&></th>
% }
+ <th></th>
</tr>
% my $paramtag = "CustomField-". $CustomField->Id ."-Value-new";
@@@ -77,15 -85,34 +79,41 @@@
</tr>
</table>
+ </form>
+
+ <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('');
+ }
+ 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>
diff --cc share/html/Admin/Elements/EditCustomFieldValues
index 075a660,90db3be..8839f47
--- a/share/html/Admin/Elements/EditCustomFieldValues
+++ b/share/html/Admin/Elements/EditCustomFieldValues
@@@ -56,10 -56,10 +56,10 @@@
<th><&|/l&>Sort</&></th>
<th><&|/l&>Name</&></th>
<th><&|/l&>Description</&></th>
-% if ($CustomField->Type ne 'Combobox') {
+% if ( $CustomField->Type ne 'Combobox' && $Categories ) {
<th class="categoryheader"><&|/l&>Category</&></th>
% }
+ <th></th>
</tr>
% while ( my $value = $values->Next ) {
commit c2d3df18d24a005da5e2a1068d9adcdd3633f69d
Merge: e38da00 bb44b14
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Feb 4 12:02:56 2016 -0500
Merge branch '4.4-trunk'
commit d793881c1db37a00d530700d548153300147a662
Merge: c2d3df1 c50ba85
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Sat Mar 26 05:13:09 2016 +0000
Merge branch '4.4-trunk'
-----------------------------------------------------------------------
More information about the rt-commit
mailing list