Showing posts with label Yii Jui. Show all posts
Showing posts with label Yii Jui. Show all posts

Thursday, September 27, 2012

How To Handle CJuiTabs In Yii


I created this yii cjuitabs article from my experience.When you read this article you can understand the yii cuitabs to handle differenct way.When i work on project, I need to assign the color for each tabs. I did this using span.

Static CJuiTabs

<?php
$this->widget('zii.widgets.jui.CJuiTabs', array(
        'tabs' => array(
               'Tab 1' => 'Content for tab 1',
               'Tab 2' => array('content' => 'Content for tab 2', 'id' => 'tab2'),
               // panel 3 contains the content rendered by a partial view
               'AjaxTab' => array('ajax' => $this->createUrl('...')),
         ),
         // additional javascript options for the tabs plugin
        'options' => array(
  //Click the selected tab to toggle its content closed/open.
   //To enable this functionality, set the collapsible option to true
  'collapsible' => true,

   //Open CJuitabs on mouse over
  'event'=>'mouseover',   
         ),
));
?>

This is the normal CJuiTabs view in Yii framework. Just create the tab and assign content for that tab. 

Here I did 3 things. They are

  1. Static Content  for Tab l 
  2. Static Content with ID for Tab 2
  3. Content added dynamically using ajax url

Render CJuiTabs

<?php
$this->widget('zii.widgets.jui.CJuiTabs', array(
 'tabs' => array(
  'Tab 1' => 'Content for tab 1',
  'Tab 2' => array('content' => 'Content for tab 2', 'id' => 'tab2'),
   
  // panel 3 contains the content rendered by a partial view
  'AjaxTab' => array('ajax' => $this->createUrl('...')),
  
  // Get Content From Another page. Also Pass Parameter
  'Render View'=>$this->renderPartial('_newpage',
   array('value'=>$value),TRUE) ),
  // Render view with ID
   'Render View With ID'=>array(
     'id'=>'renderid'
     'content'=>$this->renderPartial('_newpage2',
       array('value'=>$value),TRUE
    ),
 ),
 // additional javascript options for the tabs plugin
 'options' => array(
  'collapsible' => true,
 ),
  
'id'=>'MyTab',
));
?>
 
In this code, We can add content using renderPartial method in CJuiTabs. Here i added one parameter that is "value"(Optional)

Dynamic CJuiTabs

<?php
$tab_list=Componenttabs::gettabs();
$tabarray=array();
$i=1;

// Create Dynamic Tabs 
foreach($tab_list as $key=>$value){
 $tabarray["Tab $i"]=array(
     'id'=>$i,
    'content'=>$this->renderPartial('_newpage',
      array('value'=>$value),TRUE)
     );
 $i++;
}

$this->widget('zii.widgets.jui.CJuiTabs',
 array( 
   'tabs'=>$tabarray,
   'options'=>array(
    'collapsible'=>true,
   ),
   'id'=>'categorytabs',
  ));
?>

components/Componenttabs.php
<?php
class Componenttabs extends CApplicationComponent{
public static function gettabs(){
$model=Category::model()->findAll();
$listdata=CHtml::listData($model,”,’name’);
return $listdata;
}
}
?>

This is my great work of my project. I created dynamic tabs and content.


CJuiTabs With Class(Style)

<style type='text/css' >
 .tabclass{
   color:'red';
   font-weight:bold; 
  }
</style> 
// Css class for dynamic CJuiTabs
<?php 
  $tabarray["<span class='tabclass'>Tab $i</span>"]=array(
       'id'=>$i, 
      'content'=>$this->renderPartial(
       '_newpage',
       array('value'=>$value),
       TRUE)
      );
?>

// Css class for static CJuiTabs
<?php
$this->widget('zii.widgets.jui.CJuiTabs', array(
        'tabs' => array(
               '<span class='tabclass'>Tab 1</span>' => 'Content for tab 1',
        ),
));
?>

When you create dynamic tab using $tabarray["Tab $i"], You can apply color class using span tag.

Hint: When you use more than one CJuiTabs "Dont Forget" to set "ID". Otherwise you will get some problem

 

Dynamic Yii CJui Tabs Menu With Color

<?php
$tablist=array("Red","Green","Blue");
foreach($tablist as $tabs){
    $css='';
  if($tabs=='Red'){$css='color:red;';}
  else if($tabs=='Green'){$css='color:green;';}
  else if($tabs=='Blue'){$css='color:blue';} 
  $tabarray["<span id='tab-$key' style='$css'>$tabs</span>"]="$tabs Color";
}
?>
<?php
$this->widget('zii.widgets.jui.CJuiTabs',array(
    'tabs'=>$tabarray,
    'options' => array(
        'collapsible' => true,        
    ),
    'id'=>'MyTab-Menu1'
));
?>

Yii CJui Tabs Mouse Over Event

<?php
$tablist=array("Red","Green","Blue");
foreach($tablist as $tabs){
    $css='';
  if($tabs=='Red'){$css='color:red;';}
  else if($tabs=='Green'){$css='color:green;';}
  else if($tabs=='Blue'){$css='color:blue';} 
  $tabarray["<span id='tab-$key' style='$css'>$tabs</span>"]="$tabs Color";
}
?>
 <?php
$this->widget('zii.widgets.jui.CJuiTabs',array(
    'tabs'=>$tabarray,
    'options' => array(         
        'event'=>'mouseover',
    ),
    'id'=>'MyTab-Menu-Mouse'
));
?>
Download Yii CJuiTabs
Read More...

Thursday, May 10, 2012

Date Picker In Yii

Yii CJuiDatePicker: Default

    <h1>Yii CJuiDatePicker: Default</h1>
 <script>
  $(function() {    
    $( "#anim" ).change(function() {
      $( "#datepicker" ).datepicker( "option", "showAnim", $( this ).val() );
    });
  });
  </script>
  <p>Animations:<br>
 <select id="anim">
  <option value="show">Show (default) => show</option>
  <option value="slideDown">Slide down => slideDown</option>
  <option value="fadeIn">Fade in => fadeIn</option>
  <option value="blind">Blind (UI Effect) => blind</option>
  <option value="bounce">Bounce (UI Effect) => bounce</option>
  <option value="clip">Clip (UI Effect) => clip</option>
  <option value="drop">Drop (UI Effect) => drop</option>
  <option value="fold">Fold (UI Effect) => fold</option>
  <option value="slide">Slide (UI Effect) => slide</option>
  <option value="">None</option>
 </select>
</p>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
    'name'=>'datepicker',
    // additional javascript options for the date picker plugin
    'options'=>array(
        'showAnim'=>'slide',
//'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop'
    ),
    'htmlOptions'=>array(
        'style'=>'height:20px;background-color:green;color:white;',
    ),
));
?>

Yii CJuiDatePicker: Inline

<h1>Yii CJuiDatePicker: Inline</h1>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
    'name'=>'datepicker-Inline',
    'flat'=>true,//remove to hide the datepicker
    'options'=>array(
        'showAnim'=>'slide',
//'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop'
    ),
    'htmlOptions'=>array(
        'style'=>''
    ),
));
?>

Yii CJuiDatePicker: Show/Select Other Month Dates

<h1>Yii CJuiDatePicker: Show/Select Other Month Dates</h1>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
    'name'=>'datepicker-other-month',
    'flat'=>true,//remove to hide the datepicker
    'options'=>array(
        'showAnim'=>'slide',
//'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop'
        'showOtherMonths'=>true,// Show Other month in jquery
        'selectOtherMonths'=>true,// Select Other month in jquery
    ),
    'htmlOptions'=>array(
        'style'=>''
    ),
));
?>

Yii CJuiDatePicker: Display Button Bar(showButtonPanel)


<h1>Yii CJuiDatePicker: Display Button Bar(showButtonPanel)</h1>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
    'name'=>'datepicker-showButtonPanel',
    'value'=>date('d-m-Y'),    
    'options'=>array(
        'showAnim'=>'slide',
//'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop'
        'showButtonPanel'=>true,
    ),
    'htmlOptions'=>array(
        'style'=>''
    ),
));
?>

Yii-CJuiDatePicker: Display Month & Year Menus

<h1>Yii CJuiDatePicker: Display Month & Year Menus</h1>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
    'name'=>'datepicker-month-year-menu',
    'flat'=>true,//remove to hide the datepicker
    'options'=>array(
     'dateFormat' => 'yy-mm-dd',
        'showAnim'=>'slide',
//'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop'
        'changeMonth'=>true,
        'changeYear'=>true,
        'yearRange'=>'2000:2099',
        'minDate' => '2000-01-01',      // minimum date
        'maxDate' => '2099-12-31',      // maximum date
    ),
    'htmlOptions'=>array(
        'style'=>''
    ),
));
?>

Yii CJuiDatePicker: Display Multiple Months

<h1>Yii CJuiDatePicker: Display Multiple Months</h1>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
    'name'=>'datepicker-multiple-month',
    'flat'=>true,//remove to hide the datepicker
    'options'=>array(        
        'numberOfMonths'=>2,
        'showButtonPanel'=>true,
    ),
    'htmlOptions'=>array(
        'style'=>''
    ),
));
?>

Yii CJuiDatePicker: Date Format

<h1>Yii CJuiDatePicker: Date Format</h1>
<script>
  $(function() {
    $( "#date-format" ).change(function() {
      $( "#datepicker-date-format" ).datepicker( "option", "dateFormat", $( this ).val() );
    });
  });
  </script>
<p>Format options:<br />
  <select id="date-format">
    <option value="mm/dd/yy">Default - mm/dd/yy</option>
    <option value="yy-mm-dd">ISO 8601 - yy-mm-dd</option>
    <option value="d M, y">Short - d M, y</option>
    <option value="d MM, y">Medium - d MM, y</option>
    <option value="DD, d MM, yy">Full - DD, d MM, yy</option>
    <option value="'day' d 'of' MM 'in the year' yy">With text - 'day' d 'of' MM 'in the year' yy</option>
  </select>
</p>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
    'name'=>'datepicker-date-format',    
    'value'=>date('d/m/Y'),
    'options'=>array(        
        'showButtonPanel'=>true,
        'dateFormat'=>'mm/dd/yy',//Date format 'mm/dd/yy','yy-mm-dd','d M, y','d MM, y','DD, d MM, yy'
    ),
    'htmlOptions'=>array(
        'style'=>''
    ),
));
?>

Yii CJuiDatePicker: Date Range

<h1>Yii CJuiDatePicker: Date Range</h1>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
    'name'=>'datepicker-min-max',    
    'value'=>date('d-m-Y'),
    'options'=>array(        
        'showButtonPanel'=>true,
        'minDate'=>-5,
        'maxDate'=>"+1M +5D",
    ),
    'htmlOptions'=>array(
        'style'=>''
    ),
));
?>
Read More...