public function run()
	{
		$elements = '';
		
		$cnt = 0;
		$extraCss = '';

		Yii::import('nfy.controllers.QueueController');
		if ($this->owner instanceof QueueController) {
			$queueController = $this->owner;
		} else {
			$queueController = new QueueController('queue', Yii::app()->getModule('nfy'));
		}
		
		foreach($this->messages as $queueName => $messages) {
			foreach($messages as $message) {
				$text = addcslashes($message->body, "'\r\n");
				$detailsUrl = $queueController->createMessageUrl($queueName, $message);
				
				$extraCss = (++$cnt % 2) === 0 ? 'even' : 'odd';
				$elements .= "<div class=\"messagePopoverItem {$extraCss}\" onclick=\"window.location=\\'{$detailsUrl}\\'; return false;\">{$text}</div>";
			}
		}


		$label = Yii::t('NfyModule.app', 'Mark all as read');
		//! @todo fix this
		$deleteUrl = $this->owner->createUrl('/nfy/message/mark');
		$widgetId = $this->getId();
		
		$js = <<<JavaScript
$('#{$widgetId}').popover({
    html: true,
    trigger: 'manual',
    placement: 'bottom',
    selector: '[rel=popover]',
    title: 'Wiadomości',
    content: function() { 
        var ret = '<div class="messagePopoverContainer">{$elements}</div>';
        ret += '<div class="messagePopoverMarkAll"><a href="$deleteUrl">{$label}</a></div>';
        return ret;
    }
});

$('body').click(function(e) {
    var obj = $('div.popover');
    if(obj !== null && obj.length > 0 && (obj.is(':visible') || !obj.is(':hidden'))) {
        $('#{$widgetId}').popover('hide');
    }
});

$('#{$widgetId}').hover(function(e) {
    var obj = $('div.popover');
    if(obj === null || obj.length <= 0 || !obj.is(':visible') || obj.is(':hidden')) {
        obj = $('div.nav-collapse li.dropdown.open');
        if(obj === null || obj.length <= 0) {
            $(this).popover('show');
        }
    }
});

JavaScript;

        $css = <<<CSS
div.messagePopoverItem {
    cursor: pointer;
    font-size: 10px;
    padding: 2px 10px 2px 10px;
    word-wrap: break-word;
}

div.messagePopoverItem.even {
    background: rgb(250, 250, 250);
}

div.messagePopoverItem:hover {
    background: rgb(238, 238, 238);
}
                    
div.messagePopoverItem p {
    padding: 2px;
    margin: 0;
}

div.messagePopoverContainer {
    overflow-y: auto;
    max-height: 400px;
}

div.messagePopoverMarkAll {
    text-align: center;
    background: rgb(247, 247, 247);
    border-top: 1px solid rgb(235, 235, 235);
    padding-top: 3px;
    padding-bottom: 3px;
}

div.messagePopoverMarkAll a {
    font-size: 10px;
    text-decoration: none;
}

.popover {
    color: #444444;
    background: white;
    text-shadow: none;
    padding: 0;
    margin: 0;
    min-width: 250px;
    max-width: 400px;
}

.popover * {
    text-shadow: none;
    text-align: center;
}

.popover-content {
    padding: 0;
}

.popover-content * {
    text-align: left;
}
CSS;
		Yii::app()->clientScript->registerCss(__CLASS__.'#popup', $css);
		Yii::app()->clientScript->registerScript(__CLASS__.'#popup', $js, CClientScript::POS_END);
    }
	public function run()
	{
		$elements = '';
		
		$cnt = 0;
		$extraCss = '';

		Yii::import('nfy.controllers.QueueController');
		if ($this->owner instanceof QueueController) {
			$queueController = $this->owner;
		} else {
			$queueController = new QueueController('queue', Yii::app()->getModule('nfy'));
		}
        if(!empty($this->messages)) {  
		foreach($this->messages as $queueName => $messages) {
			foreach($messages as $data) {
			//	$text = addcslashes($message->body, "'\r\n");
				
     

				$text = $data->body;
				$ago = MHelper::Date()->timeAgo($data->created_on, array('short'=>true)); 
				$notification_icon = 'fa-truck bg-info';
				
				if(!empty($data->subject_pk)  && !empty($data->notification_id)  && $data->class_name == 'Users'){
					$user = User::model()->findByPk($data->subject_pk);
					if(!$user)
						return;
					$url_user =  CHtml::link($user->fullname, Yii::app()->createUrl('/users/user/view', array('url' => $user->username)), array('style'=>'text-decoration:underline'));
					$text = str_replace('{user}', $url_user, $text);
					$notification_icon = 'fa-users bg-success';


				} else if(!empty($data->subject_pk)){
					$user = User::model()->findByPk($data->subject_pk);
					if(!$user)
						continue;
					$url =  CHtml::link($user->username, Yii::app()->createUrl('/users/user/view', array('url' => $user->username)), array('style'=>'text-decoration:underline'));
					$text = str_replace('{user}', $url, $text);
				}


				$detailsUrl = $queueController->createMessageUrl($queueName, $data);
				
				$elements .= '<div class="notification">';
				
				$elements .= '<div class="notification-title text-info">'.Yii::t('site','New contact').'</div>';
				
				$elements .= '<div class="notification-description">'.$text.'</div>
                            <div class="notification-ago">'.$ago.'</div>
							<div class="notification-icon fa '.$notification_icon.'"></div>
							</div>';
				
				
			}
		}
		}

		$label = Yii::t('NfyModule.app', 'Mark all as read');
		//! @todo fix this
		//$deleteUrl = $this->owner->createUrl('/nfy/message/mark');
		$widgetId = $this->getId();

		$this->elements = $elements;
		
    }