Add keyword status toggle functionality and styling

- Introduced a new button to toggle the status of keywords between PAUSED and ENABLED in the keywords table.
- Added corresponding styles for the toggle button to enhance user experience.
- Updated the keywords table rendering logic to display the status and toggle button correctly.
- Created a new migration to add a 'status' column to the 'campaign_keywords' table, defaulting to 'ENABLED'.
This commit is contained in:
2026-02-24 23:31:17 +01:00
parent 2a87d0b77e
commit 651d925b20
10 changed files with 324 additions and 24 deletions

View File

@@ -1612,12 +1612,22 @@ function build_keywords_table( rows )
pagingType: 'simple_numbers',
order: [[ 4, 'desc' ]],
columns: [
{ data: 'keyword_text', defaultContent: '' },
{ data: 'keyword_text', defaultContent: '', render: function( data, type, row ) {
if ( type !== 'display' ) return data;
var text = $('<span>').text( data ).html();
if ( row.status === 'PAUSED' ) return '<span class="text-muted">' + text + '</span>';
return text;
} },
{ data: 'match_type', defaultContent: '', render: render_match_type_label },
{ data: 'ad_group_name', defaultContent: '-' },
{ data: 'id', orderable: false, searchable: false, render: function( data, type, row ) {
if ( type !== 'display' ) return data;
return '<button type="button" class="terms-change-match-type-btn" data-keyword-id="' + data + '" title="Zmien dopasowanie"><i class="fa-solid fa-pen-to-square"></i></button>' +
var is_paused = ( row.status === 'PAUSED' );
var toggle_icon = is_paused ? 'fa-play' : 'fa-pause';
var toggle_title = is_paused ? 'Wznow fraze' : 'Wstrzymaj fraze';
var toggle_class = is_paused ? 'text-success' : 'text-warning';
return '<button type="button" class="terms-toggle-keyword-status-btn ' + toggle_class + '" data-keyword-id="' + data + '" title="' + toggle_title + '"><i class="fa-solid ' + toggle_icon + '"></i></button>' +
' <button type="button" class="terms-change-match-type-btn" data-keyword-id="' + data + '" title="Zmien dopasowanie"><i class="fa-solid fa-pen-to-square"></i></button>' +
' <button type="button" class="terms-delete-keyword-btn" data-keyword-id="' + data + '" title="Usun fraze"><i class="fa-solid fa-trash"></i></button>';
} },
{ data: 'clicks_all_time', render: function( data, type ){ return type === 'display' ? format_num( data, 0 ) : Number( data || 0 ); } },
@@ -1637,7 +1647,7 @@ function build_keywords_table( rows )
columnDefs: [
{ targets: 0, className: 'text-cell phrase-nowrap', width: '220px' },
{ targets: [1,2], className: 'text-cell', width: '140px' },
{ targets: 3, className: 'dt-center', width: '90px' },
{ targets: 3, className: 'dt-center', width: '110px' },
{ targets: [4,9], className: 'num-cell', width: '70px' },
{ targets: [5,6,10,11], className: 'num-cell', width: '85px' },
{ targets: [7,12], className: 'num-cell', width: '80px' },
@@ -2523,6 +2533,80 @@ $( function()
});
});
$( 'body' ).on( 'click', '.terms-toggle-keyword-status-btn', function()
{
var btn = $( this );
var keyword_id = parseInt( btn.data( 'keyword-id' ), 10 );
var row_data = terms_keywords_table ? terms_keywords_table.row( btn.closest( 'tr' ) ).data() : null;
var keyword_text = row_data ? String( row_data.keyword_text || '' ) : '';
var is_paused = row_data && row_data.status === 'PAUSED';
if ( !keyword_id ) return;
var action_label = is_paused ? 'wznowic' : 'wstrzymac';
var action_past = is_paused ? 'wznowiona' : 'wstrzymana';
$.confirm({
title: is_paused ? 'Wznow fraze' : 'Wstrzymaj fraze',
columnClass: 'col-md-4 col-md-offset-4',
content: 'Czy na pewno ' + action_label + ' fraze <strong>' + $('<span>').text( keyword_text ).html() + '</strong>?',
type: is_paused ? 'green' : 'orange',
buttons: {
confirm: {
text: is_paused ? 'Wznow' : 'Wstrzymaj',
btnClass: is_paused ? 'btn-green' : 'btn-warning',
keys: [ 'enter' ],
action: function()
{
var modal = this;
modal.showLoading( true );
$.ajax({
url: '/campaign_terms/toggle_keyword_status/',
type: 'POST',
data: { keyword_id: keyword_id },
success: function( response )
{
var data = JSON.parse( response );
modal.close();
var debugHtml = terms_build_debug_details_html( data.debug || null );
if ( data.success )
{
var successDialog = $.alert({
title: 'Sukces',
columnClass: 'col-md-4 col-md-offset-4',
content: ( data.message || 'Status frazy zmieniony.' ) + debugHtml,
type: 'green'
});
setTimeout( function() { successDialog.close(); }, 5000 );
load_phrase_tables();
}
else
{
$.alert({
title: 'Blad',
columnClass: 'col-md-4 col-md-offset-4',
content: ( data.message || 'Nie udalo sie zmienic statusu.' ) + ( data.error ? '<br><small>' + data.error + '</small>' : '' ) + debugHtml,
type: 'red'
});
}
},
error: function()
{
modal.close();
$.alert({ title: 'Blad', columnClass: 'col-md-4 col-md-offset-4', content: 'Blad komunikacji z serwerem.', type: 'red' });
}
});
return false;
}
},
cancel: { text: 'Anuluj' }
}
});
});
$( 'body' ).on( 'click', '#terms_add_keyword_btn', function()
{
var campaign_id = $( '#terms_campaign_id' ).val();