|
';
protected static $_required_keys = array('title','body','type');
/**
* Add a system message to be rendered
*
* @param array System Message attributes
*/
public static function add($msg,$prepend=FALSE) {
if ($msgs = Session::instance()->get('sessionmsgs')) {
static::$_data = $msgs;
}
parent::add($msg);
// Add a gribber popup
Style::add(array(
'type'=>'file',
'data'=>'css/jquery.gritter.css',
'media'=>'screen',
));
Script::add(array(
'type'=>'file',
'data'=>'js/jquery.gritter-1.5.js',
));
Script::add(array(
'type'=>'stdin',
'data'=>sprintf(
'$(document).ready(function() {
$.extend($.gritter.options, {
fade_in_speed: "medium",
fade_out_speed: 2000,
time: "3000",
sticky: false,
});
$.gritter.add({
title: "%s",
text: "%s",
image: "%s",
});});',$msg['title'],$msg['body'],URL::site().static::image($msg['type'],true))));
// Save our messages in our session, so that we get them for redirects
Session::instance()->set('sessionmsgs',static::$_data);
}
/**
* Return an instance of this class
*
* @return SystemMessage
*/
public static function factory() {
return new SystemMessage;
}
/**
* Render an image for the System Message
*/
public static function image($type,$raw=false,$big=false,$alt='') {
$mediapath = Route::get(static::$_media_path);
switch ($type) {
case 'error':
$file = sprintf('img/dialog-error%s.png',$big ? '-big' : '');
break;
case 'info':
$file = sprintf('img/dialog-information%s.png',$big ? '-big' : '');
break;
case 'warning':
$file = sprintf('img/dialog-warning%s.png',$big ? '-big' : '');
break;
case 'debug':
$file = sprintf('img/dialog-question%s.png',$big ? '-big' : '');
break;
default:
throw new Kohana_Exception('Unknown system message type :type',array(':type'=>$value['type']));
}
if ($raw)
return $mediapath->uri(array('file'=>$file));
else
return HTML::image($mediapath->uri(array('file'=>$file)),array('alt'=>$alt ? $alt : '','class'=>'sysicon'));
}
/**
* Render this system message
*
* @see HTMLRender::render()
*/
protected function render() {
$output = '';
$mediapath = Route::get(static::$_media_path);
// Reload our message from the session
if ($msgs = Session::instance()->get('sessionmsgs')) {
Session::instance()->delete('sessionmsgs');
static::$_data = $msgs;
}
$i = 0;
foreach (static::$_data as $value) {
if ($i++)
$output .= static::$_spacer;
$output .= '';
$output .= sprintf('%s | ',static::image($value['type'],false,false,isset($value['alt']) ? $value['alt'] : ''));
$output .= sprintf('%s | ',$value['title']);
$output .= '
';
$output .= sprintf('%s | ',$value['body']);
$output .= '
';
}
return $output;
}
}
?>