<?php
 /* @var $this PersonPosController */
 /* @var $model PersonPos */
 /* @var $form CActiveForm */
?>

<?php yii::app()->clientScript->registerScript('', "
$(document).ready(function() {
    $('#btnRight').click(function(e) {
        var selectedOpts = $('#assigned_POSs 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_POSs').append($(selectedOpts).clone());
        $(selectedOpts).remove();
        e.preventDefault();
    });
});

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

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


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


 echo $form->hiddenField($model, 'person_id');
 echo $form->hiddenField($model, 'pos_id');
?>
<div id="aym-flash-msg<?php echo $model->id; ?>">
</div>
<table style='width:970px;max-width: none;'>
     <tr>
         <td style='width:510px;' height="300">
            <?php
             echo '<br/>';
             echo $form->dropDownListRow($model, 'assigned_POSs', CHtml::listData(Pos::model()->with('personPoses')->findAll(array('condition' => 'person_id =' . $model->person_id)), 'id', 'name'), array('class' => 'span5', 'multiple' => 'multiple', 'id' => 'assigned_POSs'));
            ?>
         </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:510px;' height="300">
             <br/>
             <label for="lstBox2">
                <?php
                 echo Yii::t('default', 'All POSs');
                 echo'</label>';
                 echo CHtml::dropDownList('lstBox2', '', CHtml::listData(Pos::getFreePerson($person->id), 'id', 'name'),
                         array('class' => 'span5', 'multiple' => 'multiple', 'id' => 'lstBox2'));
                ?>
         </td>
     </tr>
</table>

<div class="actions">
     &ensp;
    <?php
                 $action = '/personPos/create&personId=' . $model->person_id;
                 $submit_id = 'personPos_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_POSs');", 'onmouseout' => "unselectAllOptions('assigned_POSs');")
                 ); ?>

    <?php echo CHtml::link(Yii::t('default', 'Back'), ($person->getViewUrl()), 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(); ?>


