Add event handler for checkbox changes to manage refresh button state
- Implemented a new event listener for checkboxes with class 'g-checkbox'. - The listener updates the state of the '.multi-refresh' button based on the checked status of the checkbox. - Ensured that the refresh button is enabled or disabled appropriately when checkboxes are checked or unchecked.
This commit is contained in:
@@ -666,40 +666,57 @@ class GlobelusFirms
|
|||||||
{
|
{
|
||||||
global $mdb, $globelus_settings;
|
global $mdb, $globelus_settings;
|
||||||
|
|
||||||
$last_refresh = \front\factory\GlobelusAdverts::last_refresh($advert_id);
|
$advert = \front\factory\GlobelusAdverts::advert_details( $advert_id );
|
||||||
$refresh_diff = \S::date_diff( date('Y-m-d H:i:s', strtotime($last_refresh)), date('Y-m-d H:i:s'), 60 * 60 * 24 );
|
|
||||||
|
|
||||||
if ( $refresh_diff >= 1 and $points = \front\factory\GlobelusFirms::get_firm_points($user_id) >= $globelus_settings['pkt-odswiezenie-ogloszenia'])
|
if ( $advert['disabled_by_admin'] )
|
||||||
|
return [
|
||||||
|
'result' => false,
|
||||||
|
'msg' => '<p>Ogłoszenie <b>' . \front\factory\GlobelusAdverts::advert_title( $advert_id ) . '<\/b> zostało zablokowane przez administratora.</p>'
|
||||||
|
];
|
||||||
|
|
||||||
|
if ( !$advert['visible'] )
|
||||||
|
return [
|
||||||
|
'result' => false,
|
||||||
|
'msg' => '<p>Ogłoszenie <b>' . \front\factory\GlobelusAdverts::advert_title( $advert_id ) . '<\/b> nie jest widoczne.</p>'
|
||||||
|
];
|
||||||
|
|
||||||
|
$points = \front\factory\GlobelusFirms::get_firm_points( $user_id );
|
||||||
|
|
||||||
|
if ( $points < $globelus_settings['pkt-odswiezenie-ogloszenia'] )
|
||||||
{
|
{
|
||||||
$mdb->update('globelus_users', ['points[-]' => $globelus_settings['pkt-odswiezenie-ogloszenia']], ['id' => $user_id]);
|
return [
|
||||||
$mdb->insert('globelus_points_history', [
|
'result' => false,
|
||||||
'user_id' => $user_id,
|
'msg' => '<p>Nie masz wystarczającej ilości punktów, aby odświeżyć ogłoszenie <b>' . \front\factory\GlobelusAdverts::advert_title( $advert_id ) . '<\/b>.</p>'
|
||||||
'points' => $globelus_settings['pkt-odswiezenie-ogloszenia'],
|
];
|
||||||
'event_type' => 3
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($mdb->update('globelus_adverts', [
|
|
||||||
'last_refresh' => date('Y-m-d H:i:s'),
|
|
||||||
'refresh_count[+]' => 1
|
|
||||||
], [
|
|
||||||
'AND' => [
|
|
||||||
'id' => $advert_id,
|
|
||||||
'user_id' => $user_id
|
|
||||||
]
|
|
||||||
]))
|
|
||||||
{
|
|
||||||
\S::log($user_id, __METHOD__, [0 => ['points' => $points, 'advert_id' => $advert_id, 'refresh_diff' => $refresh_diff]]);
|
|
||||||
return [
|
|
||||||
'result' => true,
|
|
||||||
'msg' => '<p>Ogłoszenie <b>' . \front\factory\GlobelusAdverts::advert_title($advert_id) . '<\/b> zostało odświeżone.</p>'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
|
||||||
'result' => true,
|
$last_refresh = \front\factory\GlobelusAdverts::last_refresh( $advert_id );
|
||||||
'msg' => '<p>Ogłoszenie <b>' . \front\factory\GlobelusAdverts::advert_title($advert_id) . '<\/b> nie mogło zostać odświeżone.</p>'
|
$refresh_diff = \S::date_diff( date('Y-m-d H:i:s', strtotime($last_refresh)), date('Y-m-d H:i:s'), 60 * 60 * 24 );
|
||||||
];
|
|
||||||
|
if ( $refresh_diff < 1 )
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'result' => false,
|
||||||
|
'msg' => '<p>Ogłoszenie <b>' . \front\factory\GlobelusAdverts::advert_title( $advert_id ) . '<\/b> może być odświeżone raz na dobę.</p>'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$mdb -> update( 'globelus_users', [ 'points[-]' => $globelus_settings['pkt-odswiezenie-ogloszenia'] ], [ 'id' => $user_id] );
|
||||||
|
$mdb -> insert( 'globelus_points_history', [
|
||||||
|
'user_id' => $user_id,
|
||||||
|
'points' => $globelus_settings['pkt-odswiezenie-ogloszenia'],
|
||||||
|
'event_type' => 3
|
||||||
|
] );
|
||||||
|
|
||||||
|
if ( $mdb -> update( 'globelus_adverts', [ 'last_refresh' => date('Y-m-d H:i:s'), 'refresh_count[+]' => 1 ], [ 'AND' => [ 'id' => $advert_id, 'user_id' => $user_id ] ] ) )
|
||||||
|
{
|
||||||
|
\S::log($user_id, __METHOD__, [0 => ['points' => $points, 'advert_id' => $advert_id, 'refresh_diff' => $refresh_diff]]);
|
||||||
|
return [
|
||||||
|
'result' => true,
|
||||||
|
'msg' => '<p>Ogłoszenie <b>' . \front\factory\GlobelusAdverts::advert_title($advert_id) . '<\/b> zostało odświeżone.</p>'
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function advert_extend($advert_id, $user_id)
|
public static function advert_extend($advert_id, $user_id)
|
||||||
|
|||||||
@@ -540,6 +540,11 @@ input[type="radio"] {
|
|||||||
.btn-primary {
|
.btn-primary {
|
||||||
background-color: #334c75;
|
background-color: #334c75;
|
||||||
border-color: #334c75;
|
border-color: #334c75;
|
||||||
|
|
||||||
|
&.btn-disabled {
|
||||||
|
opacity: .5;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-system {
|
.btn-system {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -457,6 +457,14 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$( 'input.g-checkbox' ).on( 'ifChanged', function( event ) {
|
||||||
|
$( '.multi-refresh' ).removeClass( 'btn-disabled' );
|
||||||
|
var refresh_button = $( this ).closest( 'tr' ).next( 'tr' ).find( '.advert-refresh' );
|
||||||
|
if ( refresh_button.hasClass( 'btn-disabled' ) && event.target.checked ) {
|
||||||
|
$( '.multi-refresh' ).addClass( 'btn-disabled' );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$( 'body' ).on( click_event, '.multi-refresh', function(e)
|
$( 'body' ).on( click_event, '.multi-refresh', function(e)
|
||||||
{
|
{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user