PageRenderTime 55ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/README.md

https://bitbucket.org/paulkish/jtogglecolumn
Markdown | 155 lines | 128 code | 27 blank | 0 comment | 0 complexity | 9d417b60c2492750c026b522bdede9ed MD5 | raw file
  1. JToggleColumn
  2. ====
  3. Column for CGridView which toggles the boolean ( TINYINT(1) ) value of model attribute. Tested with Yii 1.10.
  4. Example
  5. ====
  6. ![JToggleColumn](https://bitbucket.org/johonunu/jtogglecolumn/raw/6220c9674443/example.png)
  7. History
  8. ====
  9. 24.04.2012 - first release
  10. 25.04.2012 - added filter option and is now using assets
  11. 17.06.2012 - added ability to change action(two included: toggle(default) and switch), now using CActions
  12. 17.09.2012 - fixed bug with sorting, now sorts column in ajax way
  13. 18.09.2012 - New QtoggleAction allow toggles between range value!!!
  14. Tutorial
  15. ====
  16. Extract downloaded zip to your components or extensions directory.
  17. If you extracted to extensions directory add this line to import array in your /config/main.php :
  18. <?php
  19. 'import'=>array(
  20. ...
  21. 'application.extensions.jtogglecolumn.*',
  22. )
  23. ?>
  24. Define a JToggleColumn in your CGridView widget:
  25. <?php
  26. $this->widget('zii.widgets.grid.CGridView', array(
  27. 'id'=>'language-grid',
  28. 'dataProvider'=>$model->search(),
  29. 'filter'=>$model,
  30. 'columns'=>array(
  31. 'id',
  32. 'name',
  33. 'lang_code',
  34. 'time_format',
  35. array(
  36. 'class'=>'JToggleColumn',
  37. 'name'=>'is_active', // boolean model attribute (tinyint(1) with values 0 or 1)
  38. 'filter' => array('0' => 'No', '1' => 'Yes'), // filter
  39. 'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
  40. ),
  41. array(
  42. 'class'=>'JToggleColumn',
  43. 'name'=>'is_default', // boolean model attribute (tinyint(1) with values 0 or 1)
  44. 'filter' => array('0' => 'No', '1' => 'Yes'), // filter
  45. 'action'=>'switch', // other action, default is 'toggle' action
  46. 'checkedButtonLabel'=>'/images/toggle/yes.png', // Image,text-label or Html
  47. 'uncheckedButtonLabel'=>'/images/toggle/no.png', // Image,text-label or Html
  48. 'checkedButtonTitle'=>'Yes.Click to No', // tooltip
  49. 'uncheckedButtonTitle'=>'No. Click to Yes', // tooltip
  50. 'labeltype'=>'image',// New Option - may be 'image','html' or 'text'
  51. 'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
  52. ),
  53. array(
  54. 'class'=>'CButtonColumn',
  55. ),
  56. ),
  57. ));
  58. ?>
  59. Add action(s) in your controller:
  60. <?php
  61. public function actions(){
  62. return array(
  63. 'toggle'=>'ext.jtogglecolumn.ToggleAction',
  64. 'switch'=>'ext.jtogglecolumn.SwitchAction', // only if you need it
  65. 'qtoggle'=>'ext.jtogglecolumn.QtoggleAction', // only if you need it
  66. );
  67. }
  68. ?>
  69. Don't forget to add this action to controllers accessRules:
  70. <?php
  71. public function accessRules()
  72. {
  73. return array(
  74. array('allow',
  75. 'actions'=>array('toggle','switch','qtoggle'),
  76. 'users'=>array('admin'),
  77. )
  78. );
  79. }
  80. ?>
  81. New Qtoggle usage demo:
  82. <?php
  83. $this->widget('zii.widgets.grid.CGridView', array(
  84. 'id'=>'language-grid',
  85. 'dataProvider'=>$model->search(),
  86. 'filter'=>$model,
  87. 'columns'=>array(
  88. 'id',
  89. 'name',
  90. 'lang_code',
  91. 'time_format',
  92. array(
  93. 'class'=>'JToggleColumn',
  94. 'action'=>'qtoggle',
  95. 'name'=>'answer',
  96. 'filter' => array('no' => 'No', 'yes' => 'Yes','dn' => 'Don`t know'),
  97. 'queue'=>array('no' => '<span class="green">No</span>', 'yes' => '<span class="red">Yes</span>','dn' => '<span class="gray">???</span>'),//key-label pairs
  98. 'queueTitles'=>array('no' => 'No', 'yes' => 'Yes','dn' => 'I don`t know'),//key-tooltips pairs
  99. 'labeltype'=>'html',
  100. 'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
  101. ),
  102. array(
  103. 'class'=>'JToggleColumn',
  104. 'filter' => array('0' => 'Draft', '1' => 'Premod',2=>'Public','3'=>'Archive'), // filter
  105. 'name'=>'status',
  106. 'action'=>'qtoggle',
  107. 'queue'=>array('0' => '/images/toggle/draft.png', '1' => '/images/toggle/premod.png',2=>'/images/toggle/pub.png','3'=>'/images/toggle/arch.png'),
  108. 'queueTitles'=>array('0' => 'Draft. Toggle to premod', '1' => 'Premod. Toggle to public',2=>'Public. Toggle to archive','3'=>'Archive. Toggle to draft'),
  109. 'labeltype'=>'image',
  110. 'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
  111. ),
  112. array(
  113. 'class'=>'JToggleColumn',
  114. 'filter' => array('0' => 'Draft', '1' => 'Premod',2=>'Public','3'=>'Archive'), // filter
  115. 'name'=>'varsel',
  116. 'action'=>'qtoggle',
  117. 'queueType'=>'select', //Show all options in dropdownlist
  118. 'queue'=>array('0' => 'Opt1', '1' => 'Opt2',2=>'Opt3','3'=>'Opt4'),
  119. 'queueTitles'=>array('0' => 'Opt1', '1' => 'Opt2',2=>'Opt3','3'=>'Opt4'),
  120. 'labeltype'=>'text',
  121. 'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
  122. ),
  123. array(
  124. 'class'=>'CButtonColumn',
  125. ),
  126. ),
  127. ));
  128. ?>