Skip to content

Commit b6f77d3

Browse files
committed
Add a button in ticket "complete modal" linked to edition while setting selected status in the modal
1 parent c16448a commit b6f77d3

File tree

6 files changed

+94
-34
lines changed

6 files changed

+94
-34
lines changed

src/Controllers/TicketsController.php

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(Ticket $tickets, \PanicHDMember $member)
3535
{
3636
$this->middleware('PanicHD\PanicHD\Middleware\EnvironmentReadyMiddleware', ['only' => ['create']]);
3737
$this->middleware('PanicHD\PanicHD\Middleware\UserAccessMiddleware', ['only' => ['show', 'downloadAttachment', 'viewAttachment']]);
38-
$this->middleware('PanicHD\PanicHD\Middleware\AgentAccessMiddleware', ['only' => ['edit', 'update', 'changeAgent', 'changePriority', 'hide']]);
38+
$this->middleware('PanicHD\PanicHD\Middleware\AgentAccessMiddleware', ['only' => ['edit', 'edit_with_values', 'update', 'changeAgent', 'changePriority', 'hide']]);
3939
$this->middleware('PanicHD\PanicHD\Middleware\IsAdminMiddleware', ['only' => ['destroy']]);
4040

4141
$this->tickets = $tickets;
@@ -616,11 +616,12 @@ protected function getCacheList($list)
616616
});
617617
break;
618618
case 'statuses':
619-
$instance = Cache::remember('panichd::statuses', 60, function () {
620-
if (Setting::grab('use_default_status_id')){
621-
return Models\Status::all();
622-
}else
619+
case 'complete_statuses':
620+
$instance = Cache::remember('panichd::' . $list, 60, function () use($list) {
621+
if (!Setting::grab('use_default_status_id') or $list == 'complete_statuses'){
623622
return Models\Status::all()->where('id', '!=', Setting::grab('default_status_id'));
623+
}else
624+
return Models\Status::all();
624625
});
625626
break;
626627
default:
@@ -649,8 +650,12 @@ public function create()
649650

650651
return view('panichd::tickets.createedit', $data);
651652
}
652-
653-
public function edit($id){
653+
654+
/*
655+
* Edit a ticket
656+
*/
657+
public function edit($id)
658+
{
654659
$ticket = $this->tickets->findOrFail($id);
655660

656661
$data = $this->create_edit_data($ticket);
@@ -663,8 +668,44 @@ public function edit($id){
663668

664669
return view('panichd::tickets.createedit', $data);
665670
}
671+
672+
/*
673+
* Edit a ticket and setting one or many fields by URL
674+
*
675+
* Usage: Show ticket -> complete modal -> "Edit more fields" option
676+
*/
677+
public function edit_with_values($id, $parameters)
678+
{
679+
$ticket = $this->tickets->findOrFail($id);
680+
681+
$data = $this->create_edit_data($ticket);
682+
683+
// Get URL parameters and replace a_current array with them
684+
$a_temp = explode('/', $parameters);
685+
$a_parameters = [];
686+
687+
if (count($a_temp) % 2 == 0){
688+
$key = "";
689+
foreach($a_temp as $param){
690+
if ($key == ""){
691+
$key = $param;
692+
}else{
693+
$data['a_current'][$key] = $param;
694+
$key = "";
695+
}
696+
}
697+
}
698+
699+
$data['ticket'] = $ticket;
700+
701+
$data['ticket_owner_id'] = $data['ticket']->user_id;
702+
703+
$data['categories'] = $this->member->findOrFail(auth()->user()->id)->getEditTicketCategories();
704+
705+
return view('panichd::tickets.createedit', $data);
706+
}
666707

667-
public function create_edit_data($ticket = false)
708+
public function create_edit_data($ticket = false, $a_parameters = false)
668709
{
669710
$member = $this->member->find(auth()->user()->id);
670711

@@ -777,7 +818,7 @@ public function create_edit_data($ticket = false)
777818
}else{
778819
$a_tags_selected = [];
779820
}
780-
821+
781822
return compact('a_owners', 'priorities', 'status_lists', 'categories', 'agent_lists', 'a_current', 'permission_level', 'tag_lists', 'a_tags_selected');
782823
}
783824

@@ -1131,6 +1172,7 @@ public function show($id)
11311172
}
11321173

11331174
$status_lists = $this->getCacheList('statuses');
1175+
$complete_status_list = $this->getCacheList('complete_statuses');
11341176

11351177
// Category tags
11361178
$tag_lists = Category::whereHas('tags')
@@ -1149,7 +1191,7 @@ public function show($id)
11491191
$comments = $ticket->comments()->forLevel($user->levelInCategory($ticket->category_id))->orderBy('id','desc')->paginate(Setting::grab('paginate_items'));
11501192

11511193
return view('panichd::tickets.show',
1152-
compact('ticket', 'a_reasons', 'a_tags_selected', 'status_lists', 'agent_lists', 'tag_lists',
1194+
compact('ticket', 'a_reasons', 'a_tags_selected', 'status_lists', 'complete_status_list', 'agent_lists', 'tag_lists',
11531195
'comments', 'close_perm', 'reopen_perm'));
11541196
}
11551197

src/Translations/ca/lang.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@
249249
'show-ticket-js-delete' => 'Esteu segur que voleu esborrar?: ',
250250
'show-ticket-modal-delete-title' => 'Esborrar Tiquet',
251251
'show-ticket-modal-delete-message' => 'Esteu segur que voleu esborrar el tiquet?: :subject?',
252+
'show-ticket-modal-edit-fields' => 'Editar més camps',
253+
252254

253255
'show-ticket-modal-complete-blank-intervention-check' => 'Deixar actuació en blanc',
254256
'show-ticket-complete-blank-intervention-alert' => 'Per a tancar el tiquet cal que confirmis que deixes el camp actuació en blanc',

src/Translations/en/lang.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,9 @@
251251
'show-ticket-js-delete' => 'Are you sure you want to delete: ',
252252
'show-ticket-modal-delete-title' => 'Delete Ticket',
253253
'show-ticket-modal-delete-message' => 'Are you sure you want to delete ticket: :subject?',
254-
255-
'show-ticket-modal-complete-blank-intervention-check' => 'Leave blank intervention',
254+
'show-ticket-modal-edit-fields' => 'Edit more fields',
255+
256+
'show-ticket-modal-complete-blank-intervention-check' => 'Leave blank intervention',
256257
'show-ticket-complete-blank-intervention-alert' => 'To complete the ticket you must confirm that you leave intervention field blank',
257258
'show-ticket-modal-complete-blank-reason-alert' => 'To complete the ticket you must indicate a closing reason',
258259
'show-ticket-complete-bad-status' => 'Ticket not completed: The specified status is not valid',

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<div class="form-group row">
2222
{!! CollectiveForm::label('status_id', trans('panichd::lang.status') . trans('panichd::lang.colon'), ['class' => 'col-lg-2 col-form-label']) !!}
2323
<div class="col-lg-10">
24-
{!! CollectiveForm::select('status_id', $status_lists, $setting->grab('default_close_status_id'), [
24+
{!! CollectiveForm::select('status_id', $complete_status_list, $setting->grab('default_close_status_id'), [
2525
'class' => 'form-control'
2626
]) !!}
2727
</div>
@@ -61,9 +61,12 @@
6161
{!! CollectiveForm::close() !!}
6262
</div>
6363
<div class="modal-footer">
64-
<button type="button" id="complete_form_submit" class="btn btn-danger">{{ trans('panichd::lang.btn-submit') }}</button>
64+
@if ($u->currentLevel() > 1)
65+
<a id="edit-with-values" class="btn btn-default pull-left 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>
66+
@endif
67+
<button type="button" id="complete_form_submit" class="btn btn-danger">{{ trans('panichd::lang.btn-submit') }}</button>
6568
</div>
66-
67-
</div>
68-
</div>
69+
70+
</div>
71+
</div>
6972
</div>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@
5858
$('#confirmDelete').find('.modal-footer #confirm').on('click', function(){
5959
$(this).data('form').submit();
6060
});
61-
61+
62+
// Complete modal status_id change
63+
$('#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/']) }}';
65+
$('#ticket-complete-modal #edit-with-values')
66+
.prop('href', url + '/' + $(this).val());
67+
});
68+
6269
// Complete modal submit button
6370
$('#complete_form_submit').click(function(e){
6471
@if ($u->currentLevel() > 1 && $u->canManageTicket($ticket->id))

src/routes.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,24 @@
2626

2727
$field_name = last(explode('/', $main_route_path));
2828
Route::resource($main_route_path, 'PanicHD\PanicHD\Controllers\TicketsController', [
29-
'names' => [
30-
'index' => $main_route.'.index',
31-
'store' => $main_route.'.store',
32-
'create' => $main_route.'.create',
33-
'update' => $main_route.'.update',
34-
'show' => $main_route.'.show',
35-
'destroy' => $main_route.'.destroy',
36-
'edit' => $main_route.'.edit',
37-
],
38-
'parameters' => [
39-
$field_name => 'ticket',
40-
],
41-
]);
29+
'names' => [
30+
'index' => $main_route.'.index',
31+
'store' => $main_route.'.store',
32+
'create' => $main_route.'.create',
33+
'update' => $main_route.'.update',
34+
'show' => $main_route.'.show',
35+
'destroy' => $main_route.'.destroy',
36+
'edit' => $main_route.'.edit',
37+
],
38+
'parameters' => [
39+
$field_name => 'ticket',
40+
],
41+
]);
42+
43+
// Open Ticket edit page with one or more parameters set by URL
44+
Route::get("$main_route_path/{id}/editwithvalues/{parameters}", 'PanicHD\PanicHD\Controllers\TicketsController@edit_with_values')
45+
->where('parameters', '(.*)')
46+
->name("$main_route.edit-with-values");
4247

4348
// Attachment routes
4449
Route::get("$main_route_path/download-attachment/{attachment}", 'PanicHD\PanicHD\Controllers\TicketsController@downloadAttachment')
@@ -65,9 +70,9 @@
6570
],
6671
]);
6772

68-
//Ticket complete route for permitted user.
69-
Route::patch("$main_route_path/{id}/complete", 'PanicHD\PanicHD\Controllers\TicketsController@complete')
70-
->name("$main_route.complete");
73+
//Ticket complete route for permitted user.
74+
Route::patch("$main_route_path/{id}/complete", 'PanicHD\PanicHD\Controllers\TicketsController@complete')
75+
->name("$main_route.complete");
7176

7277
//Ticket reopen route for permitted user.
7378
Route::get("$main_route_path/{id}/reopen", 'PanicHD\PanicHD\Controllers\TicketsController@reopen')

0 commit comments

Comments
 (0)