<?php
Yii::app()->clientScript->registerCoreScript('jquery.ui');
Yii::import('ext.imperavi-redactor-widget.ImperaviRedactorWidget');
cs()->registerCssFile(Yii::app()->request->baseUrl . '/css/dashboard.css');
cs()->registerScriptFile(Yii::app()->baseUrl . '/js/plDashboard/plDashboard.js', CClientScript::POS_HEAD);
cs()->registerScriptFile(Yii::app()->baseUrl . '/js/plCallFromGUI/plCallFromGUI.js', CClientScript::POS_HEAD);

$this->widget('ext.PlNavbar', array(
    'brand' => false,
    'fixed' => false,
    'brandUrl' => url('homeUCItem/default/index'),
    'collapse' => true, // requires bootstrap-responsive.css
    'htmlOptions' => array('id' => 'ucNavbar'),
    'items' => array(
        '<div class="navbar-search pull-left" action="" style="padding-top:2px;">
        <input type="text" class="search-query span2" placeholder="' . __("DASHBOARD_DIAL_INPUT_PLACEHOLDER") . '" id="ucDialInput">
        </div>',
        array(
            'class' => 'bootstrap.widgets.TbMenu',
            'items' => array(
                '---',
                array(
                    'label' => __('DASHBOARD_NAVBAR_CALLS'),
                    'url' => url('homeUCItem/default/index', array('typ' => 'call')),
                    'icon' => 'phone',
                    'active' => isset($_REQUEST['typ']) && $_REQUEST['typ'] == "call",
                ),
                array(
                    'label' => __('DASHBOARD_NAVBAR_VOICE_MAIL'),
                    'url' => url('homeUCItem/default/index', array('typ' => 'vm')),
                    'icon' => 'volume-up',
                    'active' => isset($_REQUEST['typ']) && $_REQUEST['typ'] == "vm",
                ),
                array(
                    'label' => __('DASHBOARD_NAVBAR_CALLRECORDING'),
                    'url' => url('homeUCItem/default/index', array('typ' => 'callrecording')),
                    'icon' => 'microphone',
                    'active' => isset($_REQUEST['typ']) && $_REQUEST['typ'] == "callrecording",
                ),
                $faxMenuAllowed ? array(
                    'label' => __('DASHBOARD_NAVBAR_FAX'),
                    'url' => url('homeUCItem/default/index', array('typ' => 'fax')),
                    'icon' => 'print',
                    'active' => isset($_REQUEST['typ']) && $_REQUEST['typ'] == "fax",
                        ) : array(),
                $faxMenuAllowed ? array(
                    'label' => __('DASHBOARD_NAVBAR_NEW_FAX'),
                    'url' => '#',
                    'icon' => 'plus',
                    'linkOptions' => array(
                        'data-translation-id' => 'DASHBOARD_NAVBAR_NEW_FAX',
                        'id' => 'createNewFax',
                    ),
                        ) : array(),
                '---',
            ),
        ),
    ),
));

$this->beginWidget('bootstrap.widgets.TbModal', array('id' => 'create-fax-modal'));
?>
<div class="modal-header">
    <a class="close" data-dismiss="modal">&times;</a>
    <h4> <?php echo __("DASHBOARD_NAVBAR_NEW_FAX"); ?> </h4>

</div>

<div class="modal-body"></div>

<div class="modal-footer">
    <?php
    $url = Yii::app()->controller->getHelpUrl('homeUCItem', false);

    $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType' => 'link',
        'icon' => 'icon-question',
        'url' => $url,
        'encodeLabel' => false,
        'htmlOptions' => array(
            'id' => 'dashboardHelpBtn',
            'data-translation-id' => 'GLOBAL_HELP_BTN',
            'title' => __('GLOBAL_HELP_BTN'),
            'target' => "_blank",
            'class' => 'pull-left'
        ),
    ));

    $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType' => 'submit',
        'type' => 'primary',
        'url' => url('homeUCItem/default/createFax'),
        'label' => __('GLOBAL_SEND_BUTTON'),
        'loadingText' => __('GLOBAL_LOADING_TEXT'),
        'htmlOptions' => array('name' => 'Send', 'id' => 'sendBtnFax', 'data-translation-id' => 'GLOBAL_SEND_BUTTON'),
    ));

    $this->widget('bootstrap.widgets.TbButton', array(
        'label' => __('GLOBAL_CANCEL_BUTTON'),
        'url' => '#',
        'htmlOptions' => array('data-dismiss' => 'modal'),
    ));
    ?>
</div>

<?php
$this->endWidget();

$faxScript = '
    $("#dashboardHelpBtn").attr("href", "' . $url . '-importNumber");
        
    $(".sendFax").on("click" ,function() {
        var value = $(this).parent().parent().attr("data-phone-number"); 
        $.get("' . url('homeUCItem/default/createFax') . '", function(data) {
            $("#create-fax-modal .modal-body").html(data);
            $("#create-fax-modal .modal-header h4").text("' . __("DASHBOARD_NAVBAR_NEW_FAX") . '");
            $( ".btn[data-translation-id|=\'GLOBAL_SEND_BUTTON\']" ).text("' . __('GLOBAL_SEND_BUTTON') . '");
            $("#UCItem_fax_number").val(value);
            $("#dashboardHelpBtn").attr("href", "' . $url . '-sendNewFax");
            $("#create-fax-modal").modal("show");
        });
    })

    $("#createNewFax").click(function(){
        $.get("' . url('homeUCItem/default/createFax') . '", function(data) {
            $("#create-fax-modal .modal-body").html(data);
            $("#create-fax-modal .modal-header h4").text("' . __("DASHBOARD_NAVBAR_NEW_FAX") . '");
            $( ".btn[data-translation-id|=\'GLOBAL_SEND_BUTTON\']" ).text("' . __('GLOBAL_SEND_BUTTON') . '");
            $("#dashboardHelpBtn").attr("href", "' . $url . '-sendNewFax");
            $("#create-fax-modal").modal("show");
        });
    });

    $("#sendBtnFax").click(function(){
        if ( $("#create-fax-grid_hiddenSaveBtn").val()) {
            $("#create-fax-grid_hiddenSaveBtn").click();
        } else {
            $("#import-number-grid_hiddenSaveBtn").click();
        }
    });

    $("#create-fax-modal").on("hidden", function () {
        $("#dashboardHelpBtn").attr("href", "' . $url . '-importNumber");
        $("#create-fax-grid_Modal_progressBar > div").width(0+"%");
        $("#sendBtnFax").button("reset");
        $("#create-fax-modal form").trigger("reset");
    })
';

cs()->registerScript('faxScript', $faxScript, CClientScript::POS_READY);

if (Yii::app()->user->translateMode) {
    echo '<i data-translation-id="GLOBAL_INCOMMING">GLOBAL_INCOMMING</i> => ' . __('GLOBAL_INCOMMING') . '<br>';
    echo '<i data-translation-id="GLOBAL_OUTGOING">GLOBAL_OUTGOING</i> => ' . __('GLOBAL_OUTGOING') . '<br>';

    echo '<i data-translation-id="DASHBORD_ITEM_FORWARDED_TO_FILE">DASHBORD_ITEM_FORWARDED_TO_FILE</i> => ' . __('DASHBORD_ITEM_FORWARDED_TO_FILE') . '<br>';

    echo '<i data-translation-id="DASHBOARD_DIAL_INPUT_PLACEHOLDER">DASHBOARD_DIAL_INPUT_PLACEHOLDER</i> => ' . __('DASHBOARD_DIAL_INPUT_PLACEHOLDER') . '<br>';
    echo '<i data-translation-id="DASHBOARD_NAVBAR_CALLS">DASHBOARD_NAVBAR_CALLS</i> => ' . __('DASHBOARD_NAVBAR_CALLS') . '<br>';
    echo '<i data-translation-id="DASHBOARD_NAVBAR_VOICE_MAIL">DASHBOARD_NAVBAR_VOICE_MAIL</i> => ' . __('DASHBOARD_NAVBAR_VOICE_MAIL') . '<br>';
    echo '<i data-translation-id="DASHBOARD_NAVBAR_CALLRECORDING">DASHBOARD_NAVBAR_CALLRECORDING</i> => ' . __('DASHBOARD_NAVBAR_CALLRECORDING') . '<br>';

    echo '<i data-translation-id="DASHBOARD_NAVBAR_FAX">DASHBOARD_NAVBAR_FAX</i> => ' . __('DASHBOARD_NAVBAR_FAX') . '<br>' . '<br>';

    echo '<i data-translation-id="UCITEMS_LOADING">UCITEMS_LOADING</i> => ' . __('UCITEMS_LOADING') . '<br>';
    echo '<i data-translation-id="UCITEMS_END_REACHED">UCITEMS_END_REACHED</i> => ' . __('UCITEMS_END_REACHED') . '<br>';

    echo '<i data-translation-id="UCITEMS_DOWNLOAD">UCITEMS_DOWNLOAD</i> => ' . __('UCITEMS_DOWNLOAD') . '<br>';
    echo '<i data-translation-id="UCITEMS_PREVIEW">UCITEMS_PREVIEW</i> => ' . __('UCITEMS_PREVIEW') . '<br>';

    echo '<i data-translation-id="UCITEMS_DELETE_TOOLTIP">UCITEMS_DELETE_TOOLTIP</i> => ' . __('UCITEMS_DELETE_TOOLTIP') . '<br>';
    echo '<i data-translation-id="UCITEMS_DELETE_CONFIRM_MESSAGE">UCITEMS_DELETE_CONFIRM_MESSAGE</i> => ' . __('UCITEMS_DELETE_CONFIRM_MESSAGE') . '<br>';
    echo '<i data-translation-id="UCITEMS_DELETE_NOTE_CONFIRM_MESSAGE">UCITEMS_DELETE_NOTE_CONFIRM_MESSAGE</i> => ' . __('UCITEMS_DELETE_NOTE_CONFIRM_MESSAGE') . '<br><br>';

    echo '<i data-translation-id="FAX_STATE_SUBMITTED">FAX_STATE_SUBMITTED</i> => ' . __('FAX_STATE_SUBMITTED') . '<br>';
    echo '<i data-translation-id="FAX_STATE_QUEUED">FAX_STATE_QUEUED</i> => ' . __('FAX_STATE_QUEUED') . '<br>';
    echo '<i data-translation-id="FAX_STATE_PROGRESS">FAX_STATE_PROGRESS</i> => ' . __('FAX_STATE_PROGRESS') . '<br>';
    echo '<i data-translation-id="FAX_STATE_SENT">FAX_STATE_SENT</i> => ' . __('FAX_STATE_SENT') . '<br>';
    echo '<i data-translation-id="FAX_STATE_FAILED">FAX_STATE_FAILED</i> => ' . __('FAX_STATE_FAILED') . '<br>';
    echo '<i data-translation-id="FAX_STATE_GIVING_UP">FAX_STATE_GIVING_UP</i> => ' . __('FAX_STATE_GIVING_UP') . '<br>';

    echo '<i data-translation-id="FAX_INBOUND_SUCCESS">FAX_INBOUND_SUCCESS</i> => ' . __('FAX_INBOUND_SUCCESS') . '<br>';
    echo '<i data-translation-id="FAX_INBOUND_FAIL">FAX_INBOUND_FAIL</i> => ' . __('FAX_INBOUND_FAIL') . '<br>' . '<br>';

    echo '<i data-translation-id="CALLABLE_MAKE_CALL">CALLABLE_MAKE_CALL</i> => ' . __('CALLABLE_MAKE_CALL') . '<br>';
    echo '<i data-translation-id="CALLABLE_VIEW_ADDRESS">CALLABLE_VIEW_ADDRESS</i> => ' . __('CALLABLE_VIEW_ADDRESS') . '<br>';

    echo '<i data-translation-id="UCITEMS_UPDATE_NOTE">UCITEMS_UPDATE_NOTE</i> => ' . __('UCITEMS_UPDATE_NOTE') . '<br>';
    echo '<i data-translation-id="UCITEMS_REMOVE_NOTE">UCITEMS_REMOVE_NOTE</i> => ' . __('UCITEMS_REMOVE_NOTE') . '<br>';
    echo '<i data-translation-id="UCITEMS_FAX_INFO">UCITEMS_FAX_INFO</i> => ' . __('UCITEMS_FAX_INFO') . '<br>';
}
?>

<div id="ucItems" style="display:table;width:100%">
    <?php
    foreach ($items as $item) {
        $this->widget('ext.DashboardItem', array('item' => $item));
    }
    ?>
</div>
<div id="loadingMessages"></div>

<?php
$this->widget('ext.yiinfinite-scroll.YiinfiniteScroller', array(
    'loading' => array(
        'finishedMsg' => __('UCITEMS_END_REACHED'),
        'speed' => 'fast',
        'msgText' => __('UCITEMS_LOADING'),
        'selector' => '#loadingMessages',
        'img' => 'img/loading.gif',
    ),
    'state' => array(),
    'bufferPx' => 600,
    'contentSelector' => '#ucItems',
    'itemSelector' => 'div.ucItem',
    'animate' => false,
    'pages' => $pages,
));

$this->widget('ImperaviRedactorWidget', array(
    'selector' => '.redactor',
    'options' => array(
        'lang' => 'de',
    ),
    'plugins' => array(
        'fullscreen' => array(
            'js' => array('fullscreen.js',),
        ),
        'clips' => array(
            'css' => array('clips.css',),
            'js' => array('clips.js',),
            'depends' => array('imperavi-redactor',),
        ),
    ),
));
?>
<script>
    $(function () {
        var options = {
            ws: ws,
            rateUcItemURL: '<?php echo url('homeUCItem/default/rateUcItem') ?>',
            canonizeNumberURL: '<?php echo url('addressbookAddresses/default/canonizeNumber') ?>',
            deleteConfirmMsg: '<?php echo __("UCITEMS_DELETE_CONFIRM_MESSAGE"); ?>',
            deleteBtnText: '<?php echo __("GLOBAL_DELETE_BUTTON"); ?>',
            cancelBtnText: '<?php echo __("GLOBAL_CANCEL_BUTTON"); ?>',
            saveBtnText: '<?php echo __("GLOBAL_SAVE_BUTTON"); ?>',
            setReadURL: '<?php echo url('homeUCItem/default/setRead') ?>',
            language: '<?php echo substr(Yii::app()->language, 0, 2); ?>',
            saveNoteURL: '<?php echo url('homeUCItem/default/saveNote') ?>',
            deleteNoteURL: '<?php echo url('homeUCItem/default/deleteNote') ?>',
            deleteNoteConfirmMsg: '<?php echo __('UCITEMS_DELETE_NOTE_CONFIRM_MESSAGE') ?>',
            viewAddressTxt: '<?php echo __('CALLABLE_VIEW_ADDRESS') ?>',
            newAddressTxt: '<?php echo __('ADDRESSBOOK_NAVBAR_NEW_ADDRESS') ?>',
            ajaxImportNumberURL: '<?php echo url('homeUCItem/default/ajaxImportNumber') ?>',
            viewAddressURL: '<?php echo url('homeUCItem/default/viewAddress') ?>'
        };
        new $.plDashboard(options);
    });

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