Skip to content

Commit

Permalink
Added tabular input widget and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
erikuus committed Oct 1, 2013
1 parent ab4fa32 commit abd1d25
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 0 deletions.
17 changes: 17 additions & 0 deletions protected/views/site/extensions/_tabularInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="simple">
<?php echo CHtml::activeLabelEx($model,"firstname"); ?>
<?php echo CHtml::activeTextField($model,"[$index]firstname"); ?>
<?php echo CHtml::error($model,"[$index]firstname"); ?>
</div>

<div class="simple">
<?php echo CHtml::activeLabelEx($model,"lastname"); ?>
<?php echo CHtml::activeTextField($model,"[$index]lastname"); ?>
<?php echo CHtml::error($model,"[$index]lastname"); ?>
</div>

<div class="simple">
<?php echo CHtml::activeLabelEx($model,"eyecolor_code"); ?>
<?php echo CHtml::activeDropDownList($model,"[$index]eyecolor_code", Lookup::items('eyecolor')); ?>
<?php echo CHtml::error($model,"[$index]eyecolor_code"); ?>
</div>
17 changes: 17 additions & 0 deletions protected/views/site/extensions/_tabularInputAsTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<td>
<?php echo CHtml::activeTextField($model,"[$index]firstname"); ?>
<?php echo CHtml::error($model,"[$index]firstname"); ?>
</td>
<td>
<?php $this->widget('ext.widgets.autocomplete.XJuiAutoComplete', array(
'model'=>$model,
'attribute'=>"[$index]lastname",
'source'=>$this->createUrl('request/suggestLastname'),

)); ?>
<?php echo CHtml::error($model,"[$index]lastname"); ?>
</td>
<td>
<?php echo CHtml::activeDropDownList($model,"[$index]eyecolor_code", Lookup::items('eyecolor')); ?>
<?php echo CHtml::error($model,"[$index]eyecolor_code"); ?>
</td>
125 changes: 125 additions & 0 deletions protected/views/site/extensions/tabular.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php
$this->pageTitle=Yii::app()->name . ' - ' . Yii::t('ui', 'Tabular Inputs');
$this->layout='leftbar';
$this->leftPortlets['application.portlets.ExtensionMenu']=array();

// set demo value
$persons=array(
Person::model()->findbyPk(1),
Person::model()->findbyPk(2)
);
$persons2=array(
Person2::model()->findbyPk(1),
Person2::model()->findbyPk(2),
Person2::model()->findbyPk(3),
Person2::model()->findbyPk(4)
);
?>

<h2><?php echo Yii::t('ui','Tabular Inputs'); ?></h2>

<h3>Basic Example</h3>
<p>minimal configuration, no style</p>

<div class="form">
<?php $this->widget('ext.widgets.tabularinput.XTabularInput',array(
'models'=>$persons,
'inputView'=>'extensions/_tabularInput',
'inputUrl'=>$this->createUrl('request/addTabularInputs'),
'removeTemplate'=>'<div class="action">{link}</div>',
'addTemplate'=>'<div class="action">{link}</div>',
)); ?>
</div>

<div class="tpanel">
<div class="toggle"><?php echo Yii::t('ui','View code'); ?></div>
<?php $this->beginWidget('CTextHighlighter',array('language'=>'PHP')); ?>
$this->widget('ext.widgets.tabularinput.XTabularInput',array(
'models'=>$persons,
'inputView'=>'extensions/_tabularInput',
'inputUrl'=>$this->createUrl('request/addTabularInputs'),
'removeTemplate'=>'<div class="action">{link}</div>',
'addTemplate'=>'<div class="action">{link}</div>',
));
<?php $this->endWidget(); ?>
</div>

<div class="tpanel">
<div class="toggle"><?php echo Yii::t('ui','Browse code'); ?></div>
<pre>
/protected/extensions/widgets/tabularinput/XTabularInput.php
/protected/views/site/extensions/_tabularInput.php
/protected/controllers/RequestController.php
/protected/extensions/actions/XTabularInputAction.php
</pre></div>

<br />

<h3>Advanced Example</h3>
<p>tabular inputs configured into table layout, buttons styled, autocomplete widget used in dynamic rows</p>

<div class="form">
<?php $this->widget('ext.widgets.tabularinput.XTabularInput',array(
'models'=>$persons2,
'containerTagName'=>'table',
'headerTagName'=>'thead',
'header'=>'
<tr>
<td>'.CHtml::activeLabelEX(Person::model(),'firstname').'</td>
<td>'.CHtml::activeLabelEX(Person::model(),'lastname').'</td>
<td>'.CHtml::activeLabelEX(Person::model(),'eyecolor_code').'</td>
<td></td>
</tr>
',
'inputContainerTagName'=>'tbody',
'inputTagName'=>'tr',
'inputView'=>'extensions/_tabularInputAsTable',
'inputUrl'=>$this->createUrl('request/addTabularInputsAsTable'),
'addTemplate'=>'<tbody><tr><td colspan="3">{link}</td></tr></tbody>',
'addLabel'=>Yii::t('ui','Add new row'),
'addHtmlOptions'=>array('class'=>'blue pill full-width'),
'removeTemplate'=>'<td>{link}</td>',
'removeLabel'=>Yii::t('ui','Delete'),
'removeHtmlOptions'=>array('class'=>'red pill'),
)); ?>
</div>

<div class="tpanel">
<div class="toggle"><?php echo Yii::t('ui','View code'); ?></div>
<?php $this->beginWidget('CTextHighlighter',array('language'=>'PHP')); ?>
$this->widget('ext.widgets.tabularinput.XTabularInput',array(
'models'=>$persons2,
'containerTagName'=>'table',
'headerTagName'=>'thead',
'header'=>'
<tr>
<td>'.CHtml::activeLabelEX(Person::model(),'firstname').'</td>
<td>'.CHtml::activeLabelEX(Person::model(),'lastname').'</td>
<td>'.CHtml::activeLabelEX(Person::model(),'eyecolor_code').'</td>
<td></td>
</tr>
',
'inputContainerTagName'=>'tbody',
'inputTagName'=>'tr',
'inputView'=>'extensions/_tabularInputAsTable',
'inputUrl'=>$this->createUrl('request/addTabularInputsAsTable'),
'addTemplate'=>'<tbody><tr><td colspan="3">{link}</td></tr></tbody>',
'addLabel'=>Yii::t('ui','Add new row'),
'addHtmlOptions'=>array('class'=>'blue pill full-width'),
'removeTemplate'=>'<td>{link}</td>',
'removeLabel'=>Yii::t('ui','Delete'),
'removeHtmlOptions'=>array('class'=>'red pill'),
));
<?php $this->endWidget(); ?>
</div>

<div class="tpanel">
<div class="toggle"><?php echo Yii::t('ui','Browse code'); ?></div>
<pre>
/protected/extensions/widgets/tabularinput/XTabularInput.php
/protected/views/site/extensions/_tabularInputAsTable.php
/protected/controllers/RequestController.php
/protected/extensions/actions/XTabularInputAction.php
</pre></div>

<br />
24 changes: 24 additions & 0 deletions protected/views/skins/XJuiAutoComplete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* To apply classic skin, assign skin attribute:
* $this->widget('XJuiAutocomplete', array('skin'=>'notDefault'));
*/
return array(
'default'=>array(
'options'=>array(
'delay'=>300,
'minLength'=>2,
'open'=>'js: function( event, ui ) {
$( this ).autocomplete( "widget" )
.find( "ui-menu-item-alternate" )
.removeClass( "ui-menu-item-alternate" )
.end()
.find( "li.ui-menu-item:odd a" )
.addClass( "ui-menu-item-alternate" );
}',
),
'htmlOptions'=>array(
'style'=>'background: #ffffe0;'
),
),
);

0 comments on commit abd1d25

Please sign in to comment.