0

我正在使用 OO php 并通过此类生成前端页面,我正在尝试重新加载一个按钮,以便一旦按下它就会同时更改类和按钮。下面是生成按钮的函数:

public static function printStartStopAll($enabled = 'false')
{
    syslog(LOG_INFO, "HELLO");
    ?>
    <div class="big-button-wrapper">
    <?
    if ( is_combined_server() ) {
        // print start all button
        $title_text = dgettext('triplecast', "Start All Transfers");
        $btn_text   = dgettext('triplecast', "Start All");
        if ( !Transfer::CanTransferNow() || count(self::getPendingTransfers()) == 0 ) {
            $class = "big-green-button-off";
            $onclick='';
        } else {
            $class = "big-green-button";
            $onclick = 'onclick=\'startAllTransfers("'.str_replace('"', '\"', self::$txtOpts).'");\'';
        }
        ?>
        <div id='start-all' class='<?=$class?>' title='<?=$title_text?>' <?=$onclick?>><?=$btn_text?></div>
        <?
    }        
    //Separate out the text for readability.
    $title_text = dgettext('triplecast', "Stop Transfers and disable the system till you re-enable it in the configuration menu");
    $btn_text   = dgettext('triplecast', "Stop All");
    $confirm_msg= dgettext('triplecast', 'If you continue all current transfers will be stopped and the system disabled till you re-enable it.');
    $confirm    = dgettext('triplecast', 'Do you want to stop all transfers?');
    ?>
    <div id='stop-all' class='big-red-button' title='<?=$title_text?>' onclick='stopAllTransfers("<?=$confirm_msg.'\n\n'.$confirm?>", "<?=str_replace('"', '\"', self::$txtOpts)?>");'><?=$btn_text?></div>
    <?
    syslog(LOG_INFO, "===>".$enabled);
    if($enabled != "true") {
        $title_text = dgettext('triplecast', "Enable Select");
        $btn_text   = dgettext('triplecast', "Select");
        $class = "big-green-button";
        $onclick='onclick=\'enableSelect(true);\'';
         ?>
        <div id='enable_select' class='<?=$class?>' title='<?=$title_text?>' <?=$onclick?>><?=$btn_text?></div>
        <?
    }
    else {
        $title_text = dgettext('triplecast', "Stop selected Transfers");
        $btn_text   = dgettext('triplecast', "Stop Selected");
        ?>
        <div id='stop-select' class='big-red-button' title='<?=$title_text?>' onclick=''><?=$btn_text?></div>
        <?
    }
    ?>
    </div>
    <?
}

请忽略任何系统日志 :) 那是我测试...

我使用 ajax 将变量推回页面并重新加载此函数。

function enableSelect(value)
{
$.getJSON("ajax_requests/enableSelect.php", { enabled: value },
    function(data){
});
}

<?php
$requireAuthentication = false;
$requireLicensing = false;
$minimalIncludes = true; 
require_once('../Library.php');
header('content-type: application/json');

$enabled = getParameter('enabled');
$dist_server = TriplecastConfig::get('distribution_server');
$resp = new TriplecastMsg();


try {
TransferController::setSelectEnabled($enabled);
TransferController::printStartStopAll($enabled);
} catch (Exception $e) {
$resp->setCode(STATUS_ERROR);
$resp->setMessage($e->getMessage());
}

$json = new JSON();
echo $json->encode( array("code" => $resp->getCode(), "message" => $resp->getMessage())

); ?>

我知道代码很乱,我只是想弄清楚如何正确地做到这一点。

这样做的目的是使用户能够按下此按钮并使用停止选择的类(大红色按钮)重新加载按钮

任何帮助将不胜感激

4

0 回答 0