Ejemplo n.º 1
0
    /**
     * Run/render a set of inputs for each cron job that this form will manage.
     * 
     * "enable_$tag" is the value stored in the cron job enablement checkbox.
     * "$tag" will be the form data loaded from crontab.
     */
    public function run()
    {
        // Script for toggle checkboxes:
        Yii::app()->clientScript->registerScript('cronForm', '
var toggleCronJobInputs = function(checkbox,initial) {
    var tag = checkbox.prop("id").replace("cron-job-","");
    if (typeof initial == "undefined")
        initial = false;
    if(checkbox.is(":checked")) {
        $("#"+checkbox.attr("id")+"-form").each(function(){
            if(initial) {
                $("#"+checkbox.attr("id")+"-form").show();
            } else {
                $("#"+checkbox.attr("id")+"-form").slideDown().find("input,select").prop("disabled",false);
                cronForm[cronForm._nameSpaces[tag]].setup();
            }
        });
    } else {
        $("#"+checkbox.attr("id")+"-form").each(function(){
            if(initial) {
                $(this).hide();
            } else {
                $(this).slideUp();
            }
            $(this).find("input,select").prop("disabled",true);
        });
    }
}
$(".cron-enabled").each(function() {
    toggleCronJobInputs($(this),1);
}).change(function() {
    toggleCronJobInputs($(this));
});
', CClientScript::POS_READY);
        // Render form fields for each cron job managed by this widget:
        CrontabUtil::$printHint = false;
        $jobSections = array();
        foreach ($this->jobTags as $tag) {
            // Populate initial form data.
            //
            // The job is initially disabled if not found in the table
            $enabled = isset($this->j[$tag]);
            $this->formData[$tag] = CrontabUtil::cronJobToForm($enabled ? $this->j[$tag] : array());
            // Overwrite cmd/desc with default as defined in the widget declaration/job config:
            if (!$this->allowUserCmdInput) {
                $this->formData[$tag]['cmd'] = $this->jobAttr($tag, 'cmd');
                $this->formData[$tag]['desc'] = $this->jobAttr($tag, 'desc');
            }
            // Render the job form inputs for this particular job:
            $viewData = array();
            foreach (array('title', 'longdesc', 'instructions') as $attr) {
                $viewData[$attr] = $this->jobAttr($tag, $attr);
            }
            $jobSections[] = $this->render('application.components.views.cronJobForm', array_merge($viewData, array('userCmd' => $this->allowUserCmdInput, 'cmd' => $this->formData[$tag]['cmd'], 'displayCmd' => isset($this->displayCmds[$tag]) ? $this->displayCmds[$tag] : '', 'enabled' => $enabled, 'labelClass' => $this->labelCssClass, 'name' => $this->name, 'tag' => $tag, 'initialCron' => $this->formData[$tag])), true);
        }
        echo implode($this->jobSeparator, $jobSections);
    }
Ejemplo n.º 2
0
?>
" class="<?php 
echo $labelClass;
?>
"><?php 
echo $title;
?>
</label>
    <p><?php 
echo $longdesc;
?>
</p>
    <p><?php 
echo Yii::t('admin', 'Command:') . '&nbsp;<span style="word-break:break-all; font-family: monospace;font-weight:bold;">' . CHtml::encode($displayCmd) . '</span>';
?>
</p>
    <div id="cron-job-<?php 
echo $tag;
?>
-form" class="cron-job-form">
        <p><?php 
echo $instructions;
?>
</p>
        <?php 
echo CrontabUtil::schedForm($initialCron, $name, $userCmd ? $cmd : "echo>/dev/null ", $tag, $initialCron['desc']);
?>
    </div>

</div>