CMenu - active class not rendering - yii

'items'=>array(
array(
'label'=>'About',
'url'=>array('about/index')
),
about/index - we get the class on the menu - active.
about/graphic - we don't get the class on the menu active.
about/print - we don't get the class on the menu active.
Please note that the menu has NO subitems.
Only About.
No mater if the user is on graphic, print or whatever, we wish to have the About highlighted.
How can we accomplish this ?
I've tried to edit that 'url' param a lot. No luck.

'items'=>array(
array(
'label'=>'About',
'url'=>array('about/index'),
'active'=>Yii::app()->controller->id=='about',
),
Added the active param. This worked.
active: boolean, optional, whether this menu item is in active state
(currently selected). If a menu item is active and activeClass is not
empty, its CSS class will be appended with activeClass. If this option
is not set, the menu item will be set active automatically when the
current request is triggered by url. Note that the GET parameters
not specified in the 'url' option will be ignored.
I've set that property. Otherwise it wouldn't work.
However, as you can see on the bold line, they say this should be automatically triggered. It wasn't on this case.
I suppose this was the case due to the fact that Yii is expecting a child element of About in order to apply that class, since there's any, we have to force it, to get the parent instead.
Not sure however.

CMenu is comparing item's route to current route, so by default it will work only for about/index.
I see two ways of forcing it - first is just set 'active' => true in items list:
$isActive = strpos(Yii::app()->controller->route, 'about/') === 0;
// ....
'items'=>array(
array(
'label'=>'About',
'url'=>array('about/index'),
'active' => $isActive
),
Or you can subclass CMenu class and overwrite CMenu::isItemActive($item,$route) method

simple but effective:
$action = Yii::app()->controller->action->id; // this is the action name currently running
'items'=>array(
array(
'label'=>'About',
'url'=>'/about/something',
'active'=>$action == 'something',
),
also...
to activate a menu, regardless of the action, just for a controller:
$controller = Yii::app()->controller->id; // this is the controller name
...
'active'=>$controller == 'something',
Notes:
add the $controller or $action variables, you can use them for more menu items. Your code will be cleaner.
you'll be 100% sure, the menu items will 'stick' active

Related

How to remove Label for attribute from checkBoxList in yii

$records_skincolor1 = array('Black'=> 'Black','Brown'=> 'Brown','Dark Brown'=> 'Dark Brown','Blue'=> 'Blue','Grey Blue'=> 'Grey Blue','Hazel'=> 'Hazel','True Green'=> 'True Green');
echo CHtml::checkBoxList('Superadvancesearch[talent_skincolor][]','',$records_skincolor1, array(
'template'=><li>{input}{label}</li>,
'separator'=>'',
));
I need to remove label for attribute. How to remove it.
If you use Yii 1.1.14 you can use the new beginLabel, labelTitle and endLabel placeholder. In this case, no for will be rendered:
'template' => '{input}{beginLabel}{labelTitle}{endLabel}'
But to be honest I can hardly see a reason why you would want to remove this attribute. Because then you can't click the label anymore to check/uncheck a checkbox. Maybe your rather look for surrounding labels:
'template' => '{beginLabel}{input}{labelTitle}{endLabel}'
This is how Bootstrap expects checkboxes and here the label can still be clicked to check/uncheck the checkbox.
The same works for radiobuttons, too, BTW.
you can do this:
you are giving an array to your CHtml::checkBoxList method.
you just define the array before this method and make it with your condition.
if ($value == $someValue)
$yourArray=array(
'template'=><li>{input}{label}</li>,
'separator'=>'',);
else
$yourArray=array(
'template'=><li>{input}</li>,
'separator'=>'',);
and give this to your method:
echo CHtml::checkBoxList('Superadvancesearch[talent_skincolor][]','',$records_skincolor1, $yourArray
));
cheers.

Dynamic menu button items in TinyMCE

I have a custom menubutton in my tinyMCE editor that uses specific HTML elements elsewhere on the page as the menu items. I use a jQuery selector to get the list of elements and then add one each as a menu item:
c.onRenderMenu.add(function(c,m) {
m.add({ title: 'Pick One:', 'class': 'mceMenuItemTitle' }).setDisabled(1);
$('span[data-menuitem]').each(function() {
var val = $(this).html();
m.add({
title: $(this).attr("data-menuitem"),
onclick: function () { tinyMCE.activeEditor.execCommand('mceInsertContent', false, val) }
});
});
});
My problem is that this only happens once when the button is first clicked and the menu is first rendered. The HTML elements on the current page will change occasionally based on user clicks and some AJAX, so I need this selector code to run each time the menu is rendered to make sure the menu is fully up-to-date. Is that possible?
Failing that, is it possible to dynamically update the control from the end of my AJAX call elsewhere in the page? I'm not sure how to access the menu item and to update it. Something using tinyMCE.activeEditor.controlManager...?
Thanks!
I found a solution to this problem, though I'm not sure it's the best path.
It doesn't look like I can make tinyMCE re-render the menu, so instead I've added some code at the end of my AJAX call: after it has updated the DOM then it manually updates the tinymce drop menu.
The menu object is accessible using:
tinyMCE.activeEditor.controlManager.get('editor_mybutton_menu')
where mybutton is the name of my custom control. My quick-and-dirty solution is to call removeAll() on this menu object (to remove all the current menu items) and then to re-execute my selector code to find the matching elements in the (new) DOM and to add the menu items back based on the new state.
It seems to work just fine, though tweaks & ideas are always welcome!

Yii CActiveForm - please wait message

We wish to trow a modal popup telling the user to "please wait" until the forms finishes submitting.
Here is part of my _form.php (just a snipped for readable proposes):
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'event-form',
'enableClientValidation' => true,
'clientOptions'=>
array('validateOnSubmit'=>true,
'afterValidate'=>'js:function() {
$("#publishErrors").empty();
$("#event-form_es_").empty();
i = true;
if($("#EntityEvent_active").is(":checked"))
{
$("#publishErrors").show().append("<p>Please check:</p>")
if($("#Event_name").val()=="")
{
$("#Event_name").addClass("error");
...
...
I confess I'm a little lost on this process and I'm not sure if this will even work, still:
I'm thinking about placing this:
$this->beginWidget('zii.widgets.jui.CJuiDialog'
, array('options'=>array(
'title'=>'My Title'
, 'modal'=>true
))
);
echo 'Please Wait While Your Form is Being Submitted';
$this->endWidget('zii.widgets.jui.CJuiDialog');
at the very end of 'afterValidate' -
Is there a better approach ?
Please advice
There is already a jquery plugin for this: jQuery BlockUI plugin.
But if you want to use CJuiDialog, just make sure that closeOnEscape is false, and modal is true, also autoOpen should be false.
You could also use a jQueryUI Progressbar inside a CJuiDialog to show progress if you wish.
Edit:
Sample code to hide x button of the dialog:
$this->beginWidget('zii.widgets.jui.CJuiDialog',
array(
'id'=>'mywaitdialog',
'options'=>array(
'title'=>'My Title',
'modal'=>true,
'autoOpen'=>false,// default is true
'closeOnEscape'=>false,
'open'=>// supply a callback function to handle the open event
'js:function(){ // in this function hide the close button
$(".class-of-closebutton").hide();
}'
))
);
To open the dialog: $("#mywaitdialog").dialog("open");.
You can open the dialog in afterValidate, as you had guessed. While the form data is passed to the server the dialog will show, and after completion url navigation will occur(new page will be loaded).

Yii bootstrap grid: Trying to get property of non-object

This:
$gridDataProvider = new CArrayDataProvider(array(
array('id'=>1, 'firstName'=>'Mark', 'lastName'=>'Otto', 'language'=>'CSS'),
array('id'=>2, 'firstName'=>'Jacob', 'lastName'=>'Thornton', 'language'=>'JavaScript'),
array('id'=>3, 'firstName'=>'Stu', 'lastName'=>'Dent', 'language'=>'HTML'),
));
$this->widget('bootstrap.widgets.BootGridView', array(
'type'=>'striped bordered condensed',
'dataProvider'=>$gridDataProvider,
'template'=>"{items}",
'columns'=>array(
array('name'=>'id', 'header'=>'#'),
array('name'=>'firstName', 'header'=>'First name'),
array('name'=>'lastName', 'header'=>'Last name'),
array('name'=>'language', 'header'=>'Language'),
array(
'class'=>'bootstrap.widgets.BootButtonColumn',
'htmlOptions'=>array('style'=>'width: 50px'),
),
),
));
is returning:
Trying to get property of non-object
Menu, buttons (and everything else) works fine.
This hapens because the example uses CArrayDataProvider to populate the grid.
When you get inside BootButton (the class that generates this column) to see what runs through it, you will see that it is trying to get the primaryKey property from dataprovider, but there is no such property, as the data is of array type.
You have to pass a CActiveDataProvider for your grid, if you plan to use buttons with it.
So try to use like this:
$this->widget('bootstrap.widgets.BootGridView', array(
'type'=>'striped bordered condensed',
'dataProvider'=>$model->search(),
'template'=>"{items}{pager}",
'filter'=>$model,...
Where $model is a CActiveRecord passed to the view by your controller.
I don't know what is the code you got in this class -- bootstrap.widgets.BootButtonColumn
But whatever it is, this is a what is causing the issue.
Make sure you have the full action of each button defined, in order to avoid this issue.
what I mean is, for every button in the button column set the url as --
'$this->grid->controller->createUrl("action_name", array("param_name" => "param_value"))'
this should solve the problem.
It's caused by the Button Column missing variables
It should be
array(
'class'=>'bootstrap.widgets.BootButtonColumn',
'htmlOptions'=>array('style'=>'width: 50px'),
'viewButtonUrl'=>null,
'updateButtonUrl'=>null,
'deleteButtonUrl'=>null,
),
//reposted from here

Yii CListView - how to use the public property $template?

I have this generated CListView code with some divs that I don't need.
I wish not to be absurd and hard code the class on zii/widgets.
I've seen this:
/**
* #var string the template to be used to control the layout of various components in the list view.
* These tokens are recognized: {summary}, {sorter}, {items} and {pager}. They will be replaced with the
* summary text, the sort links, the data item list, and the pager.
*/
public $template="{summary}\n{sorter}\n{items}\n{pager}";
It seems I can access $template and do something with it - can anyone please tell me, how can we remove the summary the sorter the items or the pager ?
Please advice.
Simply remove any of the {placeholder}s that you do not wish to render. To remove e.g. the sorter:
$this->widget('zii.widgets.CListView', array(
// set up CListView like you want, and then:
'template' => "{summary}\n{items}\n{pager}",
));