Skip to content

Commit

Permalink
Fix: when adding channel logo and editing channel again, image refere…
Browse files Browse the repository at this point in the history
…nce disparaged #6
  • Loading branch information
Jackysi committed Jan 29, 2025
1 parent 87ea771 commit ca189b1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion panel/channels.edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
// Prepare output config array
$conf[] = [
'name' => $pawtunes->strToUTF8($_POST['name']),
'logo' => ((empty($logoPath)) ? ($channels[$_GET['e'] ?? null]['logo'] ?? null) : $logoPath),
'logo' => ((empty($logoPath)) ? ($channels[$_GET['channel'] ?? null]['logo'] ?? null) : $logoPath),
'skin' => ( ! empty($_POST['skin'])) ? $_POST['skin'] : null,
'streams' => $quality_groups,
'stats' => $stats ?? [],
Expand Down
136 changes: 68 additions & 68 deletions panel/views/channel-edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,19 @@
h5 {
font-size: 14px;
padding: 0 0 5px;
margin: 0;
padding: 0 0 5px;
margin: 0;
}
h5 a {
font-size: 12px;
font-size: 12px;
font-weight: normal;
}
.quality-group {
padding: 5px 0 5px;
padding: 5px 0 5px;
border-radius: 3px;
margin: 0 0 15px;
margin: 0 0 15px;
}
.quality-group:last-child {
Expand All @@ -191,39 +191,39 @@
}
.input-quality {
position: relative;
padding: 0;
position: relative;
padding: 0;
margin-bottom: -5px;
background: transparent;
border: 0;
outline: none 0;
font-size: 14px;
font-weight: 500;
min-width: 350px;
background: transparent;
border: 0;
outline: none 0;
font-size: 14px;
font-weight: 500;
min-width: 350px;
}
.channel-logo {
display: inline-block;
border: 1px solid #808080;
display: inline-block;
border: 1px solid #808080;
background: #585858;
color: #fff;
padding: 5px 10px;
color: #fff;
padding: 5px 10px;
}
</style>
<script type="text/javascript">
window.loadInit = function() {
window.loadInit = function () {
// ### Initial Focus on Channel Name Field
// When the page loads, focus on the input field with the name "name".
$( 'input[name="name"]' ).focus();
$('input[name="name"]').focus();
// ### Handle Stat Input Changes
// When the stat selection changes, update the stat configuration fields accordingly.
$( 'select#stats' ).on( 'change', function() {
$('select#stats').on('change', function () {
let $this = $( this );
let $statsConf = $( '.stats-conf' );
switch ( $this.val() ) {
let $this = $(this);
let $statsConf = $('.stats-conf');
switch ($this.val()) {
// ### Dynamic Cases Generated via PHP
// For each tracking method, generate corresponding fields.
Expand All @@ -234,7 +234,7 @@
}
@endphp
case '<?= $key ?>':
$statsConf.html( '<?= $fields ?>' );
$statsConf.html('<?= $fields ?>');
break;
@php endforeach @endphp
Expand All @@ -246,15 +246,15 @@
return false;
} );
});
// ### Add a New Stream Group
// When the "Add Group" button is clicked, add a new quality group.
$( '.add-group' ).on( 'click', function() {
$('.add-group').on('click', function () {
// Calculate the new group's index.
let xid = parseInt( $( '.quality-group' ).index( $( '.quality-group' ).last() ) ) + 1 || 0;
let quality = 'Default Quality' + ( xid >= 1 ? ' (' + ( xid + 1 ) + ')' : '' );
let xid = parseInt($('.quality-group').index($('.quality-group').last())) + 1 || 0;
let quality = 'Default Quality' + (xid >= 1 ? ' (' + (xid + 1) + ')' : '');
// Create the HTML structure for the new quality group.
let $html = $(
Expand All @@ -270,75 +270,75 @@
'</div>'
);
// Append the new group to the streams list.
$( '.streams-list' ).append( $html );
// Append the new group to the stream list.
$('.streams-list').append($html);
// Automatically add a stream row to the new group.
$html.find( '.add-row' ).trigger( 'click' );
$html.find('.add-row').trigger('click');
return false;
} );
});
// ### Delete a Stream Group
// Handle the deletion of a quality group.
$( '.streams-list' ).on( 'click', '.delete-group', function() {
if ( confirm( 'Are you sure you wish to delete the whole group?' ) ) {
$('.streams-list').on('click', '.delete-group', function () {
if (confirm('Are you sure you wish to delete the whole group?')) {
// Remove the quality group.
$( this ).closest( '.quality-group' ).remove();
$(this).closest('.quality-group').remove();
// ### Reindex the Remaining Groups
// Update the name attributes to maintain correct indices.
let xid = 0;
$( '.quality-group' ).each( function() {
$( this ).find( 'select, input' ).each( function() {
$('.quality-group').each(function () {
$(this).find('select, input').each(function () {
let $input = $( this );
let currentName = $input.attr( 'name' );
let $input = $(this);
let currentName = $input.attr('name');
if ( currentName != null ) {
if (currentName != null) {
// Use regex to replace the index number in the name attribute.
$input.attr( 'name', currentName.replace( /_([0-9]+)\[\]/, '_' + xid + '[]' ) );
$input.attr('name', currentName.replace(/_([0-9]+)\[\]/, '_' + xid + '[]'));
}
} );
});
xid++; // Increment the group index.
} );
});
}
return false;
} );
});
// ### Delete a Stream Row
// Handle the deletion of individual stream rows.
$( '.streams-list' ).on( 'click', '.remove-row', function() {
$('.streams-list').on('click', '.remove-row', function () {
if ( confirm( 'Are you sure you wish to delete this stream?' ) ) {
if (confirm('Are you sure you wish to delete this stream?')) {
// Remove the entire table row containing the stream.
$( this ).closest( 'tr' ).remove();
$(this).closest('tr').remove();
}
return false;
} );
});
// ### Add a Stream Row
// Add a new stream input row within a quality group.
$( '.streams-list' ).on( 'click', '.add-row', function() {
$('.streams-list').on('click', '.add-row', function () {
// Get the index of the current quality group.
let xid = parseInt( $( '.quality-group' ).index( $( this ).closest( '.quality-group' ) ) ) || 0;
let xid = parseInt($('.quality-group').index($(this).closest('.quality-group'))) || 0;
// Append a new stream row to the group's table body.
$( this )
.closest( '.quality-group' )
.find( 'tbody' )
$(this)
.closest('.quality-group')
.find('tbody')
.append(
'<tr class="stream-row">' +
'<td class="col-sm-9">' +
Expand All @@ -360,51 +360,51 @@
);
// Re-initialize custom select boxes (if using a plugin).
$( 'select' ).selectbox();
$('select').selectbox();
return false;
} );
});
// ### Update File Input
// the selected file name in a custom input field.
$( 'input[type="file"]' ).on( 'change', function() {
$('input[type="file"]').on('change', function () {
let fileName = $( this ).val().replace( /.*\\fakepath\\/, '' );
$( this ).parent( '.file-input' ).find( 'input.file-name' ).val( fileName );
let fileName = $(this).val().replace(/.*\\fakepath\\/, '');
$(this).parent('.file-input').find('input.file-name').val(fileName);
} );
});
// ### Delete Existing Logo (Edit Mode Only)
// Allow users to delete the existing logo when editing.
@if (isset($_GET['action']) && $_GET['action'] === 'edit')
$( '.delete-logo' ).on( 'click', function() {
$('.delete-logo').on('click', function () {
let $this = $( this );
let $this = $(this);
// Send a request to delete the logo.
$.get( 'index.php?page=channels&action=edit&channel={{$_GET['channel']}}&logo=delete', function() {
$.get('index.php?page=channels&action=edit&channel={{$_GET['channel']}}&logo=delete', function () {
// Remove the logo container from the DOM.
$this.closest( '.logo-container' ).remove();
$this.closest('.logo-container').remove();
} );
});
return false;
} );
});
@endif
// ### Trigger Stats Change on Page Load
// If the form has been submitted or the action is not 'add', trigger the stat change event to populate fields.
@if (!empty( $_POST ) || $_GET['action'] !== 'add')
$( 'select#stats' ).trigger( 'change' );
$('select#stats').trigger('change');
@endif
// ### Ensure at Least One Quality Group Exists
// If no quality groups are present, automatically add one.
if ( $( '.streams-list .quality-group' ).length === 0 ) {
if ($('.streams-list .quality-group').length === 0) {
$( '.add-group' ).trigger( 'click' );
$('.add-group').trigger('click');
}
};
Expand Down

0 comments on commit ca189b1

Please sign in to comment.