I am trying to display a CGridView in a CJuiDialog but facing some problems.
In my view, I create a menu item as follow :
$this->menu = array(
array('label' => Yii::t('app', 'Afficher les participants ayant fourni cette information'),
'url' => array('Participant/ShowParticipantInfo', 'id' => $model->id_info),
'linkOptions' => array(
//'onclick' => "{viewP(); $('#dialogViewP').dialog('open'); return false}",
'ajax' => array(
'type' => 'POST',
'url' =>"js:$(this).attr('href')", //array('Participant/ShowParticipantInfo', 'id' => $model->id_info),
'update' => '#divForForm2',
),
),
);
Then I've created the dialog :
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'dialogViewP',
'options' => array(
'title' => 'Liste des participants ayant fourni cette information',
'autoOpen' => false,
'modal' => true,
'width' => 500,
'height' => 300,
),
));
?>
<div id="divForForm2"></div>
<?php $this->endWidget('dialogViewP'); ?>
And my controller looks like this one :
public function actionShowParticipantInfo($id){
$rows = Participant::findParticipantInfo($id);
$result = array();
foreach ($rows AS $key => $val){
$result[] = array('id' => $key +1, 'value' => $val['NomComplet']);
}
$arrayDataProvider = new CArrayDataProvider($result, array(
'id' => 'id',
'pagination' => array(
'pageSize' => 10,
),
));
if(Yii::app()->request->isAjaxRequest){
$this->renderPartial('_showparticipant', array(
'arrayDataProvider' => $arrayDataProvider,
), false, true);
echo CHtml::script('$("#dialogViewP").dialog("open")');
Yii::app()->end();
}
}
But but clicking on the menu item, there is any dialog diplayed. I cannot know why. Can somebody help me ?
I think there should not be both 'url' and 'linkOption' attributes in an menu item. Either one.
Thru web dev tools you need to check if you have ajax XHR upon menu item click.
I'd recommend you this extention if you want to realize an ajax manu.
Even if you initiate ajax request the response cannot activate hidden dialog because on success you ONLY update certain div #divForForm2 but the dialog window is still closed: 'autoOpen' => false. I'd recommend incorporate opening dialog upon ajax success.
'ajax' => array(
'type' => 'POST',
'url' => array('Participant/ShowParticipantInfo', 'id' => $model->id_info),
'success' =>'js:{function(data){$("#divForForm2").html(data); $("#dialogViewP").dialog("open");}'
),
Related
I have a custom admin page in prestashop and i would like to add a URL link at the bottom of that page. However, i am very new to prestashop and can not figure out how to do this.
I have an admin controller file for the module that creates the custom page with a form on it and was wondering how i can add a link at the bottom of the page that simply goes to another static page on the site or even an external page.
AdminFedeltaSchoolsController.php content
<?php
class AdminFedeltaSchoolsController extends ModuleAdminController {
public function __construct() {
// Configure admin controller with table, model, language and bootstrap theme
$this->table = 'fedeltapos_school';
$this->className = 'FedeltaposModel';
$this->lang = true;
$this->bootstrap = true;
// Generat action on list
$this->addRowAction('edit');
$this->addRowAction('delete');
// This adds a multiple deletion button
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?')
)
);
// Generat list
$this->fields_list = array(
'id_fedeltapos_school' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 25
),
'school_name' => array(
'title' => $this->l('School Name'),
'width' => 'auto'
),
'delivery' => array(
'title' => $this->l('Delivery'),
'width' => 'auto'
),
'pickup' => array(
'title' => $this->l('Pickup'),
'width' => 'auto'
),
'pricelevel' => array(
'title' => $this->l('Price Level'),
'width' => 'auto',
),
);
parent::__construct();
}
// This method generates the Add/Edit form
public function renderForm() {
// Building the Add/Edit form
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Schools'),
'icon' => 'icon-envelope-alt'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('School Name:'),
'name' => 'school_name',
'lang' => true,
'size' => 33,
'required' => true,
), array(
'type' => 'text',
'label' => $this->l('Delivery:'),
'name' => 'delivery',
'size' => 33,
'required' => true,
),
array(
'type' => 'text',
'label' => $this->l('Pickup:'),
'name' => 'pickup',
'size' => 33,
'required' => true,
),
array(
'type' => 'text',
'label' => $this->l('Price Level:'),
'name' => 'pricelevel',
'size' => 33,
'required' => true,
),
),
'submit' => array(
'title' => $this->l('Save')
)
);
return parent::renderForm();
}
}
I would like the link at the bottom of the page (see screenshot):
http://awesomescreenshot.com/08252wdh8a
Any assistance will be appreciated.
Override the default content admin template file of your admin controller.
Create /your-admin-folder/themes/default/template/controllers/fedelta_schools/content.tpl
{if isset($content)}
{$content}
{/if}
{block name="override_tpl_schools"}
<div class="row">
<div class="col-lg-12">
<div class="panel">
<h3>
<i class="icon-info"></i>
{l s='Help'}
</h3>
<p>{l s='You can find answer of your question here :'} <a href='#'>{l s='FAQ'}</a> </p>
</div>
</div>
</div>
{/block}
there are 2 columns check box in cgridViewtable and two bootstrap widgets TbButton in view page.
I can not get value of my checkbox very good. My value in checkboxs transfer into controller but changed id of checkboxs After a period of timeand , and controller don't knew checkbox,
View:
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id' => 'profile-information-form',
'enableAjaxValidation' => false,
));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'First validation'),));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'End validation'),));
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'profile-information-grid',
'dataProvider' => $model->children(),
'filter' => $model,
'columns' => array(
array(
'header' => '',
'value' => '$this->grid->dataProvider->pagination->offset + $row+1', // row is zero based
),
array(
'name' => 'ProfileInformation.user.scope',
'value' => 'CHtml::encode($data->user->scope->name)',
'filter' => Scope::model()->options,
),
array(
'name' => 'id',
'value' => 'CHtml::encode($data->id)',
),
array(
'name' => 'center',
'value' => 'CHtml::encode($data->center)',
),
array(
'name' => 'sendCount',
'value' => 'CHtml::encode($data->sendCount)',
'filter' => '',
),
// Use CCheckbox column with selectableRows = 2 for Select All
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser2(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser1(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
),
));
// action button
$this->endWidget();
Controller:
if (isset($_POST['profile-information-grid_c10']) & isset($_POST['yt0'])) {
////Do action1
}
if (isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])) {
////Do action2
}
}
my problem is in $_POST['profile-information-grid_c10'] and _POST['profile-information-grid_c12'] , before id were $_POST['profile-information-grid_c8'] and $_POST['profile-information-grid_c10'] , and now is $_POST['profile-information-grid_c12'] and $_POST['profile-information-grid_c14'].
my problem is very involved. I cannot explain very good.
I want to have a fix id.
I donto why change id of check box?
Can I assign ids for checkboxs?
Can I assign ids for checkboxs? Sure, you better explicitly set checkbox column id:
'class' => 'CCheckBoxColumn', 'id'=>'column1', ... see these docs.
This way you firmly set it and you'll have no things like these yt0, yt2...
The same you can do for the buttons. See TButton docs.
Also you need to use double && in logical condition:
isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])
I want to use Ajax through bootstrap button in Yii, and want to pass textfield values though that Ajax call.
here's the button code, where should i put the Ajax code for this button.
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'button', 'label'=>'ADD')); ?>
try this
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'button', 'label'=>'ADD',
'ajaxOptions' => array(
'type' => 'Post',
'url' => $this->createURL('url'),
'data' => Yii::app()->request->csrfTokenName."=".Yii::app()->request->getCsrfToken()."&action=cancel",
'success'=>"js:function(vals){
}",
)
)); ?>
another eg:
$this->widget('bootstrap.widgets.TbButton', array(
'buttonType' => 'ajaxButton',
'label' => 'Label Here',
'type' => 'danger',
'icon' => 'play white',
...
'ajaxOptions' => array(
'success' => '...',
'error' => '...',
'beforeSend' => '...',
)
));
So my form is
class Form_Group_ShareGroup extends Form_Abstract
{
public function init()
{
$this->setAttrib('class', 'shareForm');
//Row 1
$this->addElement('select', 'groups', array(
'decorators' => $this->getElementDecorators(),
'label' => Zend_Registry::get('Zend_Translate')->translate('Groups_Colon'),
'style' => 'width:320px;',
'multiple' => true,
'data-help' => Zend_Registry::get('Zend_Translate')->translate('Please_Select_Groups_Share')
));
$this->addElement('select', 'users', array(
'decorators' => $this->getElementDecorators(),
'label' => Zend_Registry::get('Zend_Translate')->translate('Users_Colon'),
'style' => 'width:320px;',
'multiple' => true,
'data-help' => Zend_Registry::get('Zend_Translate')->translate('Select_Users_To_Share_Group_With')
));
//Row 2
$this->addElement('button', 'share', array(
'decorators' => $this->buttonDecorators,
'required' => false,
'ignore' => true,
'type' => 'submit',
'label' => 'Share',
'class' => 'btn primary'
));
}
}
and I want to populate some user data into "users" element.
example could be :
array('10000105' => 'aamaddy1 m aamaddy1','10000106' => 'aamaddy2 m aamaddy2' )
How can I achieve this ?
I have use populate method but it didnt worked out.
to view the form I am using :
$usersGroup = new Form_Group_ShareGroup();
$this->view->usersGroup = $usersGroup;
Please help !
Thanks for reading .
Try this:
//$data = array('10000105' => 'aamaddy1 m aamaddy1','10000106' => 'aamaddy2 m aamaddy2' );
$usersGroup = new Form_Group_ShareGroup();
$usersGroup->getElement('users')->setMultiOptions($data);
What I'm trying to accomplish with the following code is when the 'roleSelector' dropdown is changed, it fires a ajax request to the 'admin/permissions/assign' url which in turn, sets a state for the role selected. I need it as a state so I can use it in the CLinkColumn column within the CGridView. However, when the success javascript fires and the grid view reloads the content of the cgridview does not update, while the summary does (it shows the number of results that should be in the grid view).
I'm not sure why either but this seems to be the only CGridView that I've had to use the 'ajaxUrl' property in order for the $.fn.yiiGridView.update() call to work. If I omit the url property it returns an error stating it could not find the url which I don't recall having to set in the past.
The Action:
class AssignAction extends CAction {
// Used in the url to determine if we are assigning or revoking permissions
const FLAG_APPLY = 'apply';
const FLAG_REVOKE = 'revoke';
// Identifier to the user saved state of the role selected
const STATE_ROLE = 'roleSelected';
public function run($name='', $action='') {
// Get the role the user selected
if (isset($_POST['roleSelector'])) {
$roleSelected = $_POST['roleSelector'];
Yii::app()->user->setState(self::STATE_ROLE, $roleSelected);
Yii::app()->end();
}
// Get all of the roles from the system
$roleSelected = Yii::app()->user->getState(self::STATE_ROLE);
$roles = AuthItem::model()->byTypes(array(CAuthItem::TYPE_ROLE))->findAll();
$authItemProvider = new CActiveDataProvider('AuthItem', array(
'criteria' => array(
'condition' => (!$roleSelected) ? '1=0' : '',
),
'pagination' => array(
'pageSize' => 30,
)
));
$this->getController()->render('assign', array(
'roles' => $roles,
'roleSelected' => $roleSelected,
'authItemProvider' => $authItemProvider,
));
}
}
The View:
<div id="content-header">
<h1 class="p-mt10">Assign Permissions</h1>
<div class="p-fr p-pb10">
<?php
$roleList = CHtml::listData($roles, 'name', 'label');
echo CHtml::dropDownList('roleSelector', $roleSelected, $roleList, $htmlOptions=array(
'empty' => 'Select a Role',
'ajax' => array(
'type' => 'POST',
'url' => $this->createUrl('/admin/permissions/assign'),
'data' => array('roleSelector' => 'js: $(this).val()'),
'success' => 'js: function() { $.fn.yiiGridView.update("GridView-AuthItem") }',
),
));
?>
</div>
</div>
<div id="content-body">
<table>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'GridView-AuthItem',
'dataProvider' => $authItemProvider,
'columns' => array(
'label:properCase',
'typeName:properCase',
'description',
'bizrule',
array(
'class' => 'CLinkColumn',
'label' => 'Assign',
'urlExpression' => 'array("/admin/permissions/assign",
"name" => $data->name,
"action" => (AuthItemChild::model()->byParentAndChild(Yii::app()->user->getState(AssignAction::STATE_ROLE), $data->name)->find()
? AssignAction::FLAG_REVOKE : AssignAction::FLAG_APPLY),
)',
'htmlOptions' => array(
'style' => 'text-align: center',
),
'linkHtmlOptions' => array(
'class' => 'button gray icon i_stm_edit',
),
),
),
));
?>
</table>
</div>
I forgot I left the table tags in there since it originally was a CListView. Removing those tags seems to have fixed my problem.