<?php
cs()->registerScriptFile(Yii::app()->baseUrl . '/js/addressbookAddresses/addressForm.js', CClientScript::POS_HEAD);
echo '<link rel="stylesheet" type="text/css" href="css/addressbookAddresses/default.css">'; // HOTFIX 
cs()->registerScriptFile(Yii::app()->baseUrl . '/js/plCallFromGUI/plCallFromGUI.js', CClientScript::POS_HEAD);

$addressBookList = $this->getAddressBookList();
$addressBookList[$bookId]['active'] = true;

$this->widget('ext.PlNavbar', array(
    'brand' => false,
    'collapse' => true, // requires bootstrap-responsive.css
    'items' => array(
        array(
            'class' => 'bootstrap.widgets.TbMenu',
            'items' => $addressBookList,
        ),
        array(
            'class' => 'bootstrap.widgets.TbMenu',
            'htmlOptions' => array('class' => 'pull-right'),
            'items' => array(
                array(
                    'icon' => 'user',
                    'label' => __('ADDRESSBOOK_ADRESSES_ADMIN_SHORTCUT'),
                    'url' => url('addressbookGeneral'),
                    'visible' => app()->user->realUserInstance->isSystemAdmin,
                    'linkOptions' => array(
                        'data-translation-id' => "ADDRESSBOOK_ADRESSES_ADMIN_SHORTCUT"
                    )
                ),
            ),
        ),
    ),
));
?>
<script>
    $(function () {
        $('#addressBookView').addressForm({
            deleteButtonId: "deleteButton",
            deleteConfirmMessage: "<?php echo __('ADDESSBOOKGENERAL_ADMIN_DELETE_CONFIRM_MESSAGE'); ?>",
            deleteConfirmHeader: "<?php echo __('ADRESSBOOK_ADDRESSES_MODEL_HEADER'); ?>",
            deleteConfirmBtnConfirm: "<?php echo __('ADRESSBOOK_ADDRESSES_MODAL_CONFIRM_BUTTON'); ?>",
            deleteConfirmBtnCancel: "<?php echo __('ADRESSBOOK_ADDRESSES_MODEL_CANCLE_BUTTON'); ?>",
            deleteUrl: "<?php echo $this->createUrl('delete', array('bookId' => $bookId)) ?>",
            getJsonAddressUrl: "<?php echo $this->createUrl('getJsonAddress', array('bookId' => $bookId)) ?>",
            getAjaxDeleteConfirmMessageURL: "<?php echo $this->createUrl('ajaxCreateDeleteMessage') ?>",
            bookId: "<?php echo $bookId ?>",
            photoshowUrl: "<?php echo $this->createUrl('photoshow', array('size' => 80)) ?>",
            getJsonAddressCanonizedNumberUrl: "<?php echo url('addressbookAddresses/default/getJsonAddressCanonizedNumber'); ?>",
            createFaxUrl: "<?php echo url('homeUCItem/default/createFax'); ?>",
            createFaxModalHeader: "<?php echo __('DASHBOARD_NAVBAR_NEW_FAX'); ?>",
            createFaxSaveBtnText: "<?php echo __('GLOBAL_SEND_BUTTON'); ?>",
            modelIsNewRecord: <?php echo $model->isNewRecord(); ?>,
            faxGUIEnabled: "<?php echo PhonalisaLicenseManager::faxGUIEnabled(); ?>",
            ajaxGetContactTypeValuesUrl: "<?php echo url('addressbookAddresses/default/ajaxGetContactTypeValues'); ?>",
            defaultContactSourceName: "<?php echo AddressSourceType::getSourceName(0) ?>",
            sourceIconClasses: {
                0: '<?php echo AddressSourceType::getIcon(0) ?>',
                1: '<?php echo AddressSourceType::getIcon(1) ?>',
                2: '<?php echo AddressSourceType::getIcon(2) ?>',
                3: '<?php echo AddressSourceType::getIcon(3) ?>',
                4: '<?php echo AddressSourceType::getIcon(4) ?>',
            },
            sourceIconNames: {
                0: '<?php echo AddressSourceType::getSourceName(0) ?>',
                1: '<?php echo AddressSourceType::getSourceName(1) ?>',
                2: '<?php echo AddressSourceType::getSourceName(2) ?>',
                3: '<?php echo AddressSourceType::getSourceName(3) ?>',
                4: '<?php echo AddressSourceType::getSourceName(4) ?>',
            },
            bdayFormat: "<?php echo phpUserDatePattern(); ?>",
            noWritePermissionsErrorMessage: "<?php echo __("ADDESSBOOKADDRESSES_NO_WRITE_PERMISSIONS_MESSAGE"); ?>"
        });
    });

    $(function () {
        var options = {
            ws: ws,
            canonizeNumberURL: '<?php echo url('addressbookAddresses/default/canonizeNumber') ?>'
        };
        new $.plCallFromGUI(options);
    });

</script>
<?php
Yii::app()->clientScript->registerScript(
        'autoHideAlert', 'setTimeout(function(){$(".alert").alert("close")}, 3000);', CClientScript::POS_READY
);
$this->widget('bootstrap.widgets.TbAlert', array(
    'block' => true, // display a larger alert block?
    'fade' => false, // use transitions?
    'closeText' => '&times;', // close link text - if set to false, no close link is displayed
));
?>

<div id="addressBookView">

    <div id="addressList">
        <?php
        $this->renderPartial('addressList', array(
            'model' => $model,
            'writePermissions' => $writePermissions,
            'dataProvider' => $dataProvider,
            'addressBookModel' => $addressBookModel,
            'bookId' => $bookId,
        ));
        ?>
    </div>
    <div id="addressDetail" class="fade">
        <?php
        $this->renderPartial(
                '_view3', array(
            'model' => $this->getFirstModelFromDataprovider($dataProvider),
            'bookId' => $bookId,
            'writePermissions' => $writePermissions
                )
        );
        ?>
    </div> <!-- close addressDetail div -->
</div> 
<?php
if (Yii::app()->user->translateMode) {
    $this->renderPartial('_translationTags');
}