<?php
cs()->registerScriptFile(Yii::app()->baseUrl . '/js/routingQueueMonitor/wsOverwrite.js', CClientScript::POS_END);
cs()->registerScriptFile(Yii::app()->baseUrl . '/js/routingQueueMonitor/callGrid.js', CClientScript::POS_END);
cs()->registerScriptFile(Yii::app()->baseUrl . '/js/routingQueueMonitor/liveAgentGrid.js', CClientScript::POS_END);

Yii::app()->clientScript->registerCoreScript('jquery.ui');

$this->widget('ext.PlNavbar', array(
    'brand'=>__('ROUTING_QUEUEMONITOR_HEADER_TITLE'),
    'htmlOptions'=>array(
        'data-translation-id'=>'ROUTING_QUEUEMONITOR_HEADER_TITLE',
    ),
    'items'=>array(
        array(
            'class'=>'bootstrap.widgets.TbMenu',
            'items'=>array(
                '---',
//                array(
//                    'label' => __("ROUTING_QUEUE_MONITOR_QUEUEOVERVIEW_NAVBAR_LINK"),
//                    'url' => $this->createUrl("queueOverview"),
//                    'linkOptions' => array("data-translation-id" => "ROUTING_QUEUE_MONITOR_QUEUEOVERVIEW_NAVBAR_LINK")
//                )
            ),
        ),
    ),
));
echo "<div id='agentList'>";
$this->widget('bootstrap.widgets.TbGridView', array(
    'selectableRows' => 0,
    'id'=>'agent-grid',
    'type'=>'triped bordered condensed',
    'dataProvider'=>$agentDataProvider,
    'template'=>"{items}",
    'itemsCssClass'=>'plTable items',
    'rowCssClassExpression' => '!$data["id"]?"hideRow":""',
    'columns'=>array(
        array(
            "name"=>"agent_firstname",
            "header"=>__("QUEUE_MONITOR_AGENT_GRID_AGENT_NAME_HEADER"),
            "headerHtmlOptions"=>array("data-translation-id"=>"QUEUE_MONITOR_AGENT_GRID_AGENT_NAME_HEADER"),
            "htmlOptions"=>array("class" => "agent_firstname")
        ),
        array(
            "name"=>"loggedIn",
            "header"=>__("QUEUE_MONITOR_AGENT_GRID_LOGGIN_STATE_HEADER"),
            "headerHtmlOptions"=>array("data-translation-id"=>"QUEUE_MONITOR_AGENT_GRID_LOGGIN_STATE_HEADER"),
            "htmlOptions"=>array("class" => "loggedIn"),
            "value"=>array($this, "renderAgentLoginButtonPrototype"),
            "type"=>"raw"
        ),
        array(
            "name"=>"state",
            "header"=>__("QUEUE_MONITOR_AGENT_GRID_CALL_DROP_AEREA_HEADER"),
            "headerHtmlOptions"=>array("data-translation-id"=>"QUEUE_MONITOR_AGENT_GRID_CALL_DROP_AEREA_HEADER"),
            "htmlOptions"=>array("class" => "state"),
            "type"=>"raw"
        ),
    ),
));
echo "</div>";

echo "<div id='callList'>";
    $this->widget('bootstrap.widgets.TbGridView', array(
    'selectableRows' => 0,
    'id'=>'call-grid',
    'type'=>'triped bordered condensed',
    'dataProvider'=>$callDataProvider,
    'template'=>"{items}",
    'itemsCssClass'=>'plTable items',
    'rowCssClassExpression' => '!$data["id"]?"hideRow":""',
    'columns'=>array(
        array(
            "name"=>"agent",
            "header"=>__("QUEUE_MONITOR_CALL_GRID_AGENT_HEADER"),
            "headerHtmlOptions" => array("data-translation-id" => "QUEUE_MONITOR_CALL_GRID_AGENT_HEADER"),
            "htmlOptions"=>array("class" => "agent")
        ),
        array(
            "name"=>"queue_extension",
            "header"=>__("QUEUE_MONITOR_CALL_GRID_QUEUE_EXTENSION_HEADER"),
            "headerHtmlOptions"=>array("data-translation-id"=>"QUEUE_MONITOR_CALL_GRID_QUEUE_EXTENSION_HEADER"),
            "htmlOptions"=>array("class" => "queue_extension")
        ),
        array(
            "name"=>"remote_number",
            "header"=>__("QUEUE_MONITOR_CALL_GRID_REMOTE_NUMBER_HEADER"),
            "headerHtmlOptions"=>array("data-translation-id"=>"QUEUE_MONITOR_CALL_GRID_REMOTE_NUMBER_HEADER"),
            "htmlOptions"=>array("class" => "remote_number")
        ),
        array(
            "name"=>"timestamp",
            "header"=>__("QUEUE_MONITOR_CALL_GRID_TIMESTAMP_HEADER"),
            "headerHtmlOptions"=>array("data-translation-id"=>"QUEUE_MONITOR_CALL_GRID_TIMESTAMP_HEADER"),
            "htmlOptions"=>array("class" => "timestamp")
        ),
        array(
            "name"=>"state",
            "header"=>__("QUEUE_MONITOR_CALL_GRID_STATE_HEADER"),
            "headerHtmlOptions"=>array("data-translation-id"=>"QUEUE_MONITOR_CALL_GRID_STATE_HEADER"),
            "htmlOptions"=>array("class" => "state"),
        ),
    ),
));
echo "</div>";
?>
<style>
    
    .hideRow {
        display:none;
    }
    
    #agentList {
        display: inline-block;
        width: 50%;
    }
    
    #callList {
        float: right;
        display: inline-block;
        width: 50%;
    }
</style>

<script>
 var queue_ids = <?php echo $queueIds;?>;
 var toggleAgentLoginIds = <?php echo json_encode($toggleAgentLoginPermissions); ?>;
 var transferCallToPermissions = <?php echo json_encode($transferCallToPermissions); ?>;
 var transferCallFromPermissions = <?php echo json_encode($transferCallFromPermissions); ?>;
 var translatedLoginText = "<?php echo __("ROUTING_QUEUE_MONITOR_LOGIN_BUTTON"); ?>";
 var translatedLogoutText ="<?php echo __("ROUTING_QUEUE_MONITOR_LOGOUT_BUTTON"); ?>";
 var translatedStaticMemberText = "<?php echo __("ROUTING_QUEUE_MONITOR_STATIC_MEMBER_BUTTON"); ?>";
 var userTimeFormat = "<?php echo PhonalisaDate::userDatePattern(); ?>";
 var timezoneInSec = "<?php echo PhonalisaDate::convertServerDateTo('Z', PhonalisaDate::newServerDate(), true); ?>";
</script>

<?php
if (app()->user->translateMode) {
?>
<script>
    var alreadyShownTags = new Array();
    $("#content").append("<div id='translation_targets'></div>");
    $("#content").find("[data-translation-id]").each(function(index,element) {
        var translationTag = $(element).data("translation-id");
        
        if (jQuery.inArray( translationTag, alreadyShownTags) === -1) {
            alreadyShownTags.push(translationTag);
            $("#translation_targets").append("<i data-translation-id="+translationTag+">"+translationTag+"</i><br />");
        }
    });
</script>
<?php
}