<?php
/* @var $this PosScheduleController */
/* @var $model PosSchedule */
/* @var $form CActiveForm */
?>

<?php
yii::app()->clientScript->registerScript('', "
$(document).ready(function() {
    $('#btnRight').click(function(e) {
        var selectedOpts = $('#assigned_schedules option:selected');
        if (selectedOpts.length == 0) {
            e.preventDefault();
        }

        $('#lstBox2').append($(selectedOpts).clone());
        $(selectedOpts).remove();
        e.preventDefault();
    });

    $('#btnLeft').click(function(e) {
        var selectedOpts = $('#lstBox2 option:selected');
        if (selectedOpts.length == 0) {
            e.preventDefault();
        }

        $('#assigned_schedules').append($(selectedOpts).clone());
        $(selectedOpts).remove();
        e.preventDefault();
    });
});

"); ?>
<div id="loading-div" >&nbsp;</div>


<?php
$form = $this->beginWidget('ext.bootstrap.widgets.TbActiveForm', array(
            'id' => 'pos-schedule-form',
            'enableAjaxValidation' => false,
        ));


$this->widget('bootstrap.widgets.TbAlert');


echo $form->hiddenField($model, 'pos_id');
echo $form->hiddenField($model, 'schedule_id');
?>
<div id="aym-flash-msg<?php echo $model->id; ?>">
</div>
<table style='width:770px;'>
    <tr>
        <td style='width:460px;' height="300">
            <?php
            echo '<br/>';
            echo $form->dropDownListRow($model, 'assigned_schedules', CHtml::listData(Schedule::model()->with('posSchedules')->findAll(array('condition' => 'pos_id =' . $model->pos_id)), 'id', 'description'), array('class' => 'span5', 'multiple' => 'multiple', 'id' => 'assigned_schedules'));
            ?>
        </td>
        <td style='width:50px;text-align:center;vertical-align:middle;'>
            <br>
            <br>
            <?php
            echo CHtml::link('>>', '#', array('class' => 'btn btn-primary', 'id' => 'btnRight'));
            echo '<br/>';
            echo '<br/>';
            echo CHtml::link('<<', '#', array('class' => 'btn btn-primary', 'id' => 'btnLeft'));
            ?>

        </td>
        <td style='width:460px;' height="300">
            <br/>
            <label for="lstBox2">
                <?php
                echo CHtml::link(Yii::t('default', 'All Schedules'), array('/schedule/index'));
                echo'</label>';
                echo CHtml::dropDownList('lstBox2', '', CHtml::listData(Schedule::getFreeSchedule($_GET['posId']), 'id', 'description'),
                        array('class' => 'span5', 'multiple' => 'multiple', 'id' => 'lstBox2'));
                ?>
        </td>
    </tr>
</table>

<div class="actions">
    &ensp;
    <?php
                $action = '/posSchedule/create&posId=' . $model->pos_id;
                $submit_id = 'posSchedule_create';
                echo CHtml::ajaxSubmitButton(
                        Yii::t('default', 'Save'),
                        array($action),
                        array(
                            'beforeSend' => 'js:function(){
                                           $("#loading-div").addClass("loading");
                                          
                           }',
                            'success' => 'js:function(data){
                                           $("#loading-div").removeClass("loading");
                                           $("#aym-flash-msg' . $model->id . '").html(data);
                           }',
                        ),
                        array('type' => 'submit', 'class' => 'btn', 'name' => $submit_id, 'id' => $submit_id, 'onmouseover' => "selectAllOptions('assigned_schedules');", 'onmouseout' => "unselectAllOptions('assigned_schedules');")
                ); ?>

    <?php echo CHtml::link(Yii::t('default', 'Back'), array('/pos/view/', 'id' => $model->pos_id), array('class' => 'btn primary')); ?>
            </div>
            <script type="text/javascript">
                function selectAllOptions(selStr)   {
                    var selObj = document.getElementById(selStr);
                    for (var i=0; i<selObj.options.length; i++) {
                        selObj.options[i].selected = true;
                    }
                }
                function unselectAllOptions(selStr)   {
                    var selObj = document.getElementById(selStr);
                    for (var i=0; i<selObj.options.length; i++) {
                        selObj.options[i].selected = false;
                    }
                }
            </script>
<?php $this->endWidget(); ?>


