develop loesung zu Lösung #3
@@ -138,7 +138,21 @@ jQuery(function($){
|
||||
$(document).on("change", "#kc-force-wahl-dropdown", function(){
|
||||
var $w = $(this);
|
||||
var $phase = $w.closest("form").find("[name='phase']");
|
||||
refreshPhaseSelect($w, $phase);
|
||||
// try immediate refresh; if no data found, fallback to AJAX
|
||||
var sel = $w.find('option:selected');
|
||||
var einheiten = sel.data('einheiten') || kcWahlPhases[parseInt($w.val(),10)];
|
||||
if (einheiten) {
|
||||
refreshPhaseSelect($w, $phase);
|
||||
} else {
|
||||
// AJAX fallback to ask server for anzahl_einheiten
|
||||
$.get(ajaxurl, {action: 'kc_get_wahl', id: $w.val()}).done(function(r){
|
||||
if (r && r.success && r.data && r.data.anzahl_einheiten) {
|
||||
// set data attribute so future reads find it
|
||||
sel.data('einheiten', parseInt(r.data.anzahl_einheiten,10));
|
||||
}
|
||||
refreshPhaseSelect($w, $phase);
|
||||
}).fail(function(){ refreshPhaseSelect($w, $phase); });
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize existing phase selects based on their selected wahl
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
<?php
|
||||
// AJAX endpoint to return wahl details (anzahl_einheiten)
|
||||
add_action('wp_ajax_kc_get_wahl', function(){
|
||||
global $wpdb;
|
||||
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
|
||||
if (!$id) {
|
||||
wp_send_json_error('missing id');
|
||||
}
|
||||
$row = $wpdb->get_row($wpdb->prepare("SELECT id, COALESCE(anzahl_einheiten,1) as anzahl_einheiten FROM {$wpdb->prefix}kc_wahlen WHERE id=%d", $id));
|
||||
if (!$row) wp_send_json_error('not found');
|
||||
wp_send_json_success(['id'=>intval($row->id),'anzahl_einheiten'=>intval($row->anzahl_einheiten)]);
|
||||
});
|
||||
|
||||
/**
|
||||
* Plugin Name: Workshop-Wahlen
|
||||
* Description: Workshop-Wahl-System für Konfi-Castle.com
|
||||
|
||||
Reference in New Issue
Block a user