Skip to content

Commit 1285898

Browse files
committed
Unique route for ticket edition with our without parameters
1 parent 9c1e64d commit 1285898

4 files changed

Lines changed: 63 additions & 92 deletions

File tree

src/Controllers/TicketsController.php

Lines changed: 26 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -656,77 +656,49 @@ public function create($parameters = null)
656656
}
657657

658658
/*
659-
* Process parameter pairs passed by URL and update and return $data array
659+
* Edit a ticket with optional parameters set by URL
660+
*
660661
*/
661-
public function ticket_URL_parameters($data, $parameters)
662+
public function edit($id, $parameters = null)
662663
{
663-
// Get URL parameters and replace a_current array with them
664-
$a_temp = explode('/', $parameters);
665-
$a_parameters = [];
666-
667-
if (count($a_temp) % 2 == 0){
668-
$key = "";
669-
foreach($a_temp as $param){
670-
if ($key == ""){
671-
$key = $param;
672-
}else{
673-
$data['a_current'][$key] = $param;
674-
$key = "";
675-
}
676-
}
677-
}
678-
679-
return $data;
680-
}
664+
$ticket = $this->tickets->findOrFail($id);
681665

682-
/*
683-
* Edit a ticket
684-
*/
685-
public function edit($id)
686-
{
687-
$ticket = $this->tickets->findOrFail($id);
666+
$data = $this->create_edit_data($ticket);
688667

689-
$data = $this->create_edit_data($ticket);
668+
// Get URL parameters and replace a_current array with them
669+
if (!is_null($parameters)){
670+
$data = $this->ticket_URL_parameters($data, $parameters);
671+
}
690672

691-
$data['ticket'] = $ticket;
673+
$data['ticket'] = $ticket;
692674

693-
$data['categories'] = $this->member->findOrFail(auth()->user()->id)->getEditTicketCategories();
675+
$data['categories'] = $this->member->findOrFail(auth()->user()->id)->getEditTicketCategories();
694676

695677
return view('panichd::tickets.createedit', $data);
696-
}
678+
}
697679

698-
/*
699-
* Edit a ticket and setting one or many fields by URL
700-
*
701-
* Usage: Show ticket -> complete modal -> "Edit more fields" option
702-
*/
703-
public function edit_with_values($id, $parameters)
680+
/*
681+
* Process parameter pairs passed by URL and update $data array
682+
*/
683+
public function ticket_URL_parameters($data, $parameters)
704684
{
705-
$ticket = $this->tickets->findOrFail($id);
706-
707-
$data = $this->create_edit_data($ticket);
708-
709685
// Get URL parameters and replace a_current array with them
710686
$a_temp = explode('/', $parameters);
711687
$a_parameters = [];
712688

713689
if (count($a_temp) % 2 == 0){
714-
$key = "";
715-
foreach($a_temp as $param){
716-
if ($key == ""){
717-
$key = $param;
718-
}else{
719-
$data['a_current'][$key] = $param;
720-
$key = "";
721-
}
722-
}
690+
$key = "";
691+
foreach($a_temp as $param){
692+
if ($key == ""){
693+
$key = $param;
694+
}else{
695+
$data['a_current'][$key] = $param;
696+
$key = "";
697+
}
698+
}
723699
}
724700

725-
$data['ticket'] = $ticket;
726-
727-
$data['categories'] = $this->member->findOrFail(auth()->user()->id)->getEditTicketCategories();
728-
729-
return view('panichd::tickets.createedit', $data);
701+
return $data;
730702
}
731703

732704
public function create_edit_data($ticket = false, $a_parameters = false)

src/Views/tickets/show/modal_complete.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</div>
6363
<div class="modal-footer">
6464
@if ($u->currentLevel() > 1)
65-
<a id="edit-with-values" class="btn btn-default mr-auto" href="{{ route($setting->grab('main_route').'.edit-with-values', ['id' => $ticket->id, 'parameters' => 'complete/yes/status_id/' . $setting->grab('default_close_status_id')]) }}">{{ trans('panichd::lang.show-ticket-modal-edit-fields') }}</a>
65+
<a id="edit-with-values" class="btn btn-default mr-auto" href="{{ route($setting->grab('main_route').'.edit', ['id' => $ticket->id]) . '/complete/yes/status_id/' . $setting->grab('default_close_status_id') }}">{{ trans('panichd::lang.show-ticket-modal-edit-fields') }}</a>
6666
@endif
6767
<button type="button" id="complete_form_submit" class="btn btn-danger">{{ trans('panichd::lang.btn-mark-complete') }}</button>
6868
</div>

src/Views/tickets/show/script.blade.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
w: {{ $sizes[0] }},
1212
h: {{ $sizes[1] }},
1313
pid: {{ $attachment->id }},
14-
title: '{{ $attachment->new_filename . ($attachment->description == "" ? '' : trans('panichd::lang.colon').$attachment->description) }}'
14+
title: '{{ $attachment->new_filename . ($attachment->description == "" ? '' : trans('panichd::lang.colon').$attachment->description) }}'
1515
},
1616
@endif
1717
@endforeach
@@ -32,12 +32,12 @@
3232
// Update agent list
3333
var loadpage = "{!! route($setting->grab('main_route').'agentselectlist') !!}/" + $(this).val() + "/{{ $ticket->id }}";
3434
$('#agent_id').load(loadpage);
35-
36-
// Update tag list
35+
36+
// Update tag list
3737
$('#jquery_select2_container .select2-container').hide();
3838
$('#jquery_tag_category_'+$(this).val()).next().show();
3939
});
40-
40+
4141
$('#agent_id').change(function(){
4242
if ($('#status_id').val()=="{!! $setting->grab('default_status_id') !!}"){
4343
$('#status_id').val("{!! $setting->grab('default_reopen_status_id') !!}")
@@ -61,13 +61,13 @@
6161
6262
// Complete modal status_id change
6363
$('#ticket-complete-modal #status_id').change(function(){
64-
var url = '{{ route($setting->grab('main_route').'.edit-with-values', ['id' => $ticket->id, 'parameters' => 'complete/yes/status_id/']) }}';
64+
var url = '{{ route($setting->grab('main_route').'.edit', ['id' => $ticket->id, 'parameters' => 'complete/yes/status_id/']) }}';
6565
$('#ticket-complete-modal #edit-with-values')
6666
.prop('href', url + '/' + $(this).val());
6767
});
6868
6969
// Complete modal submit button
70-
$('#complete_form_submit').click(function(e){
70+
$('#complete_form_submit').click(function(e){
7171
@if ($u->currentLevel() > 1 && $u->canManageTicket($ticket->id))
7272
// Agent / Admin
7373
@if (!$ticket->intervention_html)
@@ -83,16 +83,16 @@
8383
return false;
8484
}
8585
@endif
86-
$('#complete-ticket-form').submit();
87-
});
88-
89-
// When opening a comment modal,
86+
$('#complete-ticket-form').submit();
87+
});
88+
89+
// When opening a comment modal,
9090
$('.comment-modal').on('show.bs.modal', function (e) {
9191
$('.comment-modal .alert-danger').hide();
9292
$(this).find('.fieldset-for-comment').show();
9393
$(this).find('.fieldset-for-attachment').hide();
9494
});
95-
95+
9696
$('.comment-modal').on('shown.bs.modal', function (e) {
9797
$(this).find('.modal-title').text($(e.relatedTarget).text());
9898
if ($(e.relatedTarget).data('add-comment') == 'no') $(this).find('#comment-type-buttons').hide();
@@ -103,21 +103,21 @@
103103
$('.comment-modal').on('hidden.bs.modal', function (e) {
104104
$(this).find("textarea.modal-summernote-editor").summernote('destroy');
105105
});
106-
106+
107107
// Comment form: Click on response type buttons (reply or note)
108108
$('.response_type').click(function(){
109-
var type = $(this).attr('data-type');
109+
var type = $(this).attr('data-type');
110110
$('#modal-comment-new #response_type').val(type);
111111
$(this).addClass($(this).attr('data-active-class'));
112-
112+
113113
if (type == 'reply'){
114114
$('#add_in_user_notification_text, #add_to_intervention').prop('disabled', false);
115115
$('#add_in_user_notification_text, #add_to_intervention').closest('div').show();
116116
}else{
117117
$('#add_in_user_notification_text, #add_to_intervention').prop('disabled', true);
118118
$('#add_in_user_notification_text, #add_to_intervention').closest('div').hide();
119119
}
120-
120+
121121
var alt = type == 'note' ? 'reply' : 'note';
122122
$('#popup_comment_btn_'+alt).removeClass($('#popup_comment_btn_'+alt).attr('data-active-class'));
123123
});
@@ -126,50 +126,50 @@
126126
$('.jquery_panel_hightlight').on('show.bs.modal', function (e) {
127127
$(e.relatedTarget).closest('div.card').addClass('card-highlight');
128128
});
129-
129+
130130
$('.jquery_panel_hightlight').on('hidden.bs.modal', function (e) {
131131
$('div.card').removeClass('card-highlight');
132132
});
133-
133+
134134
$('#new_comment_submit').click(function(e){
135135
e.preventDefault();
136-
136+
137137
@if($u->currentLevel() > 1 && !$ticket->intervention_html != "")
138138
if ($(this).closest('form').find('input[name="add_to_intervention"]').is(':checked') == false && $(this).closest('form').find('input[name="complete_ticket"]').is(':checked')){
139139
if(!confirm('{!! trans('panichd::lang.add-comment-confirm-blank-intervention') !!}')) return false;
140-
}
140+
}
141141
@endif
142-
142+
143143
ajax_form_submit($(this));
144144
});
145-
145+
146146
// Click "X" to delete comment
147147
$('#modal-comment-delete').on('show.bs.modal', function (e) {
148148
if ($('#delete-comment-form').attr('data-default-action') == ''){
149149
$('#delete-comment-form').attr('data-default-action',$('#delete-comment-form').attr('action'));
150150
}
151-
151+
152152
// Add value to form
153153
$('#delete-comment-form').attr('action',$('#delete-comment-form').attr('action').replace('action_comment_id',$(e.relatedTarget).attr('data-id')));
154154
});
155-
155+
156156
// Dismiss comment deletion
157157
$('#modal-comment-delete').on('hidden.bs.modal', function (e) {
158158
$('#delete-comment-form').attr('action',$('#delete-comment-form').attr('data-default-action'));
159159
});
160-
160+
161161
// Comment confirm delete
162162
$( "#delete-comment-submit" ).click(function( event ) {
163163
event.preventDefault();
164164
$("#delete-comment-form").submit();
165-
});
166-
167-
165+
});
166+
167+
168168
// Comment (reply) notifications resend modal
169169
$( "#email-resend-modal" ).on('show.bs.modal', function (e) {
170170
var button = $(e.relatedTarget);
171171
$(this).find('#owner').text($(button).attr('data-owner'));
172172
$(this).find('#comment_id').val($(button).attr('data-id'))
173-
});
173+
});
174174
});
175-
</script>
175+
</script>

src/routes.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,30 @@
2424
// Hide or show ticket to user
2525
Route::get("$main_route_path/hide/{value}/{ticket}", 'PanicHD\PanicHD\Controllers\TicketsController@hide')->name("$main_route.hide");
2626

27-
// Open Ticket create page with one or more parameters set by URL
27+
// Open Ticket create page with optional parameters set by URL
2828
Route::get("$main_route_path/create/{parameters?}", 'PanicHD\PanicHD\Controllers\TicketsController@create')
2929
->where('parameters', '(.*)')
3030
->name("$main_route.create");
3131

32+
// Open Ticket edit page with optional parameters set by URL
33+
Route::get("$main_route_path/{id}/edit/{parameters?}", 'PanicHD\PanicHD\Controllers\TicketsController@edit')
34+
->where('parameters', '(.*)')
35+
->name("$main_route.edit");
36+
3237
$field_name = last(explode('/', $main_route_path));
3338
Route::resource($main_route_path, 'PanicHD\PanicHD\Controllers\TicketsController', [
3439
'names' => [
3540
'index' => $main_route.'.index',
3641
'store' => $main_route.'.store',
3742
'update' => $main_route.'.update',
3843
'show' => $main_route.'.show',
39-
'destroy' => $main_route.'.destroy',
40-
'edit' => $main_route.'.edit',
44+
'destroy' => $main_route.'.destroy'
4145
],
4246
'parameters' => [
4347
$field_name => 'ticket',
4448
],
4549
]);
4650

47-
// Open Ticket edit page with one or more parameters set by URL
48-
Route::get("$main_route_path/{id}/editwithvalues/{parameters}", 'PanicHD\PanicHD\Controllers\TicketsController@edit_with_values')
49-
->where('parameters', '(.*)')
50-
->name("$main_route.edit-with-values");
51-
5251
// Attachment routes
5352
Route::get("$main_route_path/download-attachment/{attachment}", 'PanicHD\PanicHD\Controllers\TicketsController@downloadAttachment')
5453
->name("$main_route.download-attachment");

0 commit comments

Comments
 (0)