Another window helper March 30, 2006
Posted by rossoft in CakePHP.trackback
1. Download the zip from http://blogus.xilinus.com/pages/javawin
Place window.js in /js/window/ and the content of css theme folder in /css/window/
2. Put this on /app/views/helpers/window.php
<?php
/**
* Window Helper
* @author RosSoft
* @license MIT
* @version 0.10
*
* @link http://blogus.xilinus.com/pages/javawin
*
*/
class WindowHelper extends Helper
{
var $helpers=array('javascript','head');
var $cssdir='window/';
var $js='window/window';
var $default_width=300;
var $default_height=70;
var $default_ok_label='Cerrar';
var $default_cancel_label='Cancelar';
var $default_cancel_function='void(0);';
var $default_ok_function='void(0);';
var $default_title='';
var $default_hide_effect='Effect.BlindUp';
var $default_show_effect='Effect.Appear';
var $default_resizable=true;
function _register_files()
{
$this->head->register_js($this->js);
$this->head->register_jsblock('var window_helper_index=0;');
$this->head->register_css($this->cssdir . 'alert');
$this->head->register_css($this->cssdir. 'default');
$this->head->register_css($this->cssdir. 'theme1');
}
/**
* Shows a confirmation dialog box
* @param string $content Content of the dialog box
* @param array Association array of parameters
* @see _get_params()
* @param boolean $jstag Enclose the javascript code in <javascript> tag
* @return string
*/
function show_confirm($content,$params=array(),$jstag=false)
{
$this->_register_files();
$params=$this->_get_params($params);
extract($params);
ob_start();
$jscode="Dialog.confirm('$content',
{windowParameters: {width:$width, height:$height}, okLabel: '$ok_label',
cancelLabel: '$cancel_label',
cancel:function(win){ $cancel_function },
ok:function(win){ $ok_function }});";
if ($jstag)
{
echo $this->javascript->codeBlock($jscode);
}
else
{
echo $jscode;
}
return ob_get_clean();
}
/**
* Shows a window
* @param string $value An url / or the html content of the window
* @param boolean $is_url If true, then $value is an url, else the content in html
* @param boolean $modal The window is modal
*/
function show_window($content,$is_url=false,$modal=false,$params=array(),$jstag=false)
{
static $index=0;
$params=$this->_get_params($params);
extract($params);
$this->_register_files();
ob_start();
$jscode="var win = new Window('window_' + window_helper_index, {className: 'dialog', title:'$title', zIndex:150, resizable: $resizable, width:$width, height:$height, hideEffect: $hide_effect, showEffect: $show_effect";
if ($is_url)
{
$jscode.=", url: '$content'";
}
$jscode.="});";
if (! $is_url)
{
$jscode.="win.getContent().innerHTML = '$content';";
}
if ($modal)
{
$jscode.="win.showCenter(true);";
}
else
{
$jscode.="win.showCenter(false);";
}
$jscode.="window_helper_index++;";
if ($jstag)
{
echo $this->javascript->codeBlock($jscode);
}
else
{
echo $jscode;
}
$index++;
return ob_get_clean();
}
function _get_params($params)
{
if (! isset($params['width']))
{
$params['width'] =$this->default_width;
}
if (!isset($params['height']))
{
$params['height']=$this->default_height;
}
if (!isset($params['ok_label']))
{
$params['ok_label']=$this->default_ok_label;
}
if (!isset($params['cancel_label']))
{
$params['cancel_label']=$this->default_cancel_label;
}
if (!isset($params['cancel_function']))
{
$params['cancel_function']=$this->default_cancel_function;
}
if (!isset($params['ok_function']))
{
$params['ok_function']=$this->default_ok_function;
}
if (!isset($params['title']))
{
$params['title']=$this->default_title;
}
if (!isset($params['hide_effect']))
{
$params['hide_effect']=$this->default_hide_effect;
}
if (!isset($params['show_effect']))
{
$params['show_effect']=$this->default_show_effect;
}
if (!isset($params['resizable']))
{
$params['resizable']=$this->default_resizable;
}
return $params;
}
}
?>
Some examples:
<a href="javascript: void(0)" onclick="<?=$window->show_confirm('Are you sure?',array('width'=>200,'height'=>150))?>" >click here 1</a>
<br/>
<a href="javascript: void(0)" onclick="<?=$window->show_window('<b>Hello world</b>',false,true)?>" >click here 2</a>
<br/>
<a href="javascript: void(0)" onclick="<?=$window->show_window($html->url('/pruebas/test_submodal_result'),true,true,array('hide_effect'=>'Effect.Disappear','width'=>600,'height'=>300))?>" >click here 3</a>
<br/>
[...] RosSoft » Another window helper show_confirm(’Are you sure?’,array(’width’=>200,’height’=>150))?>” >click here 1 (tags: cakephp) [...]
Best Poker Tools
best poker
payday loans
loans
home equity loan
good luck
Just like Peyton Manning
http://www.mexicoweb.com.mx/busca/buscador.cgi?query=%22%3E%20%3Ca%20href%3D%22http%3A%2F%2Fwww.hypotheek.ordercredit.info%22%3EHypotheek%20Vergelijk%3C%2Fa%3E
PI0kZu xf78fg623fv0skghlq56fd