ajaxlink refresh window after "delete" - ajax

Yii: 1.1.15
I have a list in my view and behind every row an ajaxLink to delete the row. It works but the browser does not refresh automatically ... with STRG-R it refreshes and the deleted row disappers.
My code:
echo CHtml::ajaxLink('X',
Yii::app()->createUrl('forumkommentar/delete', array("id" => $kommentar->id)), array(
'type' => 'POST',
'data' => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
// 'data' => 'js:{"data":' . $kommentar->id . '}',
// 'success' => 'js:function(string){ document.getElementById("' . $kommentar->id . '").remove(); }'
), array(
'class' => 'btn btn-danger small-btn',
'confirm' => 'Are you sure?', //Confirmation
));
I think I need the two commented lines above to refresh the window - but it does not work.
My questions:
How can I combine the two "data"-lines? (line 4 and 5)
What is wrong in my code - or how would you do it?

Firs, you are making ajax request with POST type, so you can't use url parameters, because url parameters are GET parameters. Therefore I think this can be helpful:
echo CHtml::ajaxLink('X',
Yii::app()->createUrl('forumkommentar/delete'), array(
'type' => 'POST',
'data' => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken, "kommentar" => $kommentar->id),
//'success' => 'js:function(string){ document.getElementById("' . $kommentar->id . '").remove(); }'
), array(
'class' => 'btn btn-danger small-btn',
'confirm' => 'Are you sure?', //Confirmation
));
Now, you can access $_POST['kommentar'] in the actionDelete() of ForumkommentarController.

Related

Laravel: Whole lang files in on view

I want to localize my Laravel app.
I call it on blade like this: #lang('bot.bots')
But my view I got this:
My bot.php is:
<?
return [
'bots' => 'Bot|Bots',
'addBot' => 'Add bot',
'editBot' => 'Edit bot',
'deleteBot' => 'Delete bot',
'compose' => 'Compose',
'addGroup' => 'Add group',
'editGroup' => 'Edit group',
'deleteGroup' => 'Delete group',
'confirmDeleteGroup' => 'Are you sure you want to delete the group?',
'textRecognition' => 'Text recognition',
'newRule' => 'Add rule',
'deleteRule' => 'Delete rule',
'confirmDeleteRule' => 'Are you sure you want to delete the rule?',
'editBot' => 'Bot szerkesztése',
'input' => 'Input',
'output' => 'Output',
'addInput' => 'Add input',
'addOutput' => 'Add output',
'blocks' => 'Block|Blocks',
'groups' => 'Group|Groups',
'text' => 'Text',
'broadcast' => 'Broadcast',
'analytics' => 'Analytics',
'chatPartners' => 'Chat Partners',
];
What can be the problem? I did everything like what's in the documentation
Just indicate the count like this
$bots_count = 4 //replace with count
#lang('bot.bots', $bots_count)
You may also use translation choices, for which your array would look like this
return [
'bots' => '{0} No Bots|{1} Bot|[2,*] Bots',
...
];

How to add elements to a fieldset in magento horizontally rather than vertically

I am adding few check boxes in to magento using the fieldset option like the following.
$fieldset = $form->addFieldset('display', array(
'legend' => $helper->__('Schedule Sales Order Transfer'),
'class' => 'fieldset-wide'
));
for($i=01; $i*5<60; $i++){
$time = $i*5;
$fieldset->addField('min'.$time, 'checkbox', array(
'name' => 'Checkbox',
'checked' => false,
'onclick' => self::setAll("min"),
'onchange' => "",
'value' => ''.$time,
'disabled' => false,
'after_element_html' => '<small>'.$time.'</small>',
'tabindex' => 1
));
}
By doing so, all the check boxes are coming one below another. Is it possible to make it one adjacent to another i.e., horizontally?
Anybody Please suggest the solution ASAP...
Thank you,
In your Code return like <tr>...</tr><tr>..</tr>, so if you need to add custom css or js to achieve what you expected,
or
for($i=01; $i*5<60; $i++){
$time[$i]['value'] = $i*5;
$time[$i]['label'] = $i*5;
}
$fieldset->addField('Time', 'checkboxes', array(
'label' => $this->__('Time'),
'name' => 'time[]',
'values' => $time,
'value' => '1',
'tabindex' => 1
));
its return like <tr><td>label</td><td>value<ul><li></li>....<li></li></ul></td></tr>
then you continue your stuff.,
Note: I'm just suggest the possible ways

CakePHP: How to define multiple success parameters when creating an AJAX-link?

I have currently the problem with CakePHP that I don't know how to define multiple success parameters in an AJAX/JS-link.
Currently, that's my code I have:
<?php echo $this->Js->link('Firma entknüpfen', array(
'controller' => 'contacts',
'action' => 'unbindCompany',
$contact['Contact']['id']
),
array(
'update' => '#success',
'success' => $this->Js->get('#current_company')->effect('fadeOut')
)); ?>
Now, I need a second 'success'-parameter/action to fade in another element, like this:
<?php echo $this->Js->link('Firma entknüpfen', array(
'controller' => 'contacts',
'action' => 'unbindCompany',
$contact['Contact']['id']
),
array(
'update' => '#success',
'success' => $this->Js->get('#current_company')->effect('fadeOut')
'success' => $this->Js->get('#assign_company')->effect('fadeIn')
)); ?>
I tried to pass an array to success but this didn't work, too.
How can I realise this correctly?
JsHelper::effect() returns a string, so you could simply concat the return values:
'success' => $this->Js->get('#current_company')->effect('fadeOut') .
$this->Js->get('#assign_company')->effect('fadeIn')

TbJsonGridView + TbJsonCheckBoxColumn - how call action for multi rows? (screen)

I have situation like on this screen:
I have column where user check rows. After that user can call some actions like example delete data.
To show menu with multi actions for users i use button dropdown in yii-booster TbButtonGroup. I tried all possible buttonType and all doesnt work.
All what i need is send information about what rows are selected, do some action inside controller and after that reload grid. I dont have any idea how...
To generate button dropdown i use code:
Yii::app()->controller->widget('bootstrap.widgets.TbButtonGroup', array(
'size'=>'mini',
'type'=>'link',
'buttons'=>array(
array('icon'=>'edit', 'items'=>$this->filter),
),
));
To generate grid i use code:
$this->widget('bootstrap.widgets.TbJsonGridView', array(
'dataProvider' => $model->search(),
'filter' => $model,
'type' => 'striped condensed',
'summaryText' => false,
'cacheTTL' => 10, // cache will be stored 10 seconds (see cacheTTLType)
'cacheTTLType' => 's', // type can be of seconds, minutes or hours
'selectableRows'=>2,
'columns' => array(
array(
'class'=>'ext._TbJsonCheckBoxColumn._TbJsonCheckBoxColumn',
'id'=>'selectedTickets',
'filter'=>array(
array('label'=>'close', 'url'=>'javascript:'.CHtml::ajax(array('type'=>'POST', 'url'=>array('','multi_action'=>'close'), 'success'=>'function(data, status){ console.log(data); console.log(status); }', 'error'=>"function(data, status){ console.log(data); console.log(status); }")) ),
array('label'=>'Another action', 'url'=>'#'),
array('label'=>'Something else', 'url'=>'#'),
'---',
array('label'=>'Separate link', 'url'=>'#'),
),
),
'id',
'email_from',
'subject',
'status',
array(
'name'=>'last_update',
'value'=>'$data->last_update_from_now',
//'filter'=>false,
),
array(
'header' => Yii::t('ses', 'Edit'),
'class' => 'bootstrap.widgets.TbJsonButtonColumn',
'template' => '{view} {update} {delete}',
),
),
));
To generate form i use code:
$this->widget('bootstrap.widgets.TbButton',array(
'label' => 'Add new ticket',
'type' => 'primary',
'size' => 'medium',
'url' => $this->createUrl('create'),
));
<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'tickets',
'type'=>'horizontal',
'enableAjaxValidation'=>true,
));
echo $this->renderPartial('_grid', array('model'=>$model));
echo CHtml::ajaxSubmitButton('Activate',array('menu/ajaxupdate','act'=>'doActive'), array('success'=>'reloadGrid'));
$this->endWidget();
After many spent hours i wrote something like that and it solved my problem:
Yii::app()->clientScript->registerScript('multi_button', "
$('[data-multi=action]').delegate('li a', 'click', function(event){
event.preventDefault();
var th = $(this),
action = th.attr('href').substr(1);
if( action=='delete' && !confirm('Are you sure you want to delete selected items?') ) return true;
".
CHtml::ajax(array(
'type'=>'POST',
'data'=>'js:th.closest("form").serialize()',
'url'=>'js:location.href+(/\?/.test(location.href) ? "&" : "?")+"multi_action="+action',
'success'=>'function(data, status){ th.closest("div.grid-view").yiiJsonGridView("update"); }',
'error'=>'function(data, status){ alert(status); }',
'cache'=>false
))."
});
");

Simultaneous ajax requests

I am trying to run the remote function in the code below every 5 seconds. It runs only once if I remove the frequency option. I tried remoteTimer function, but when I use remoteTimer function, some code of the script goes outside the script tags and I see that in the webpage.
echo $ajax->form(array('type' => 'post', 'options' => array('model' => 'Thing',
'url' => array('controller' => 'things', 'action' => 'xyz'),'update' => 'dy4', 'indicator' => 'ldng', 'loading' => ( $ajax->
remoteFunction(array('url' => array('controller' => 'stories', 'action' =>
'keep'), 'update' => 'dy3', 'frequency' => 5))))));echo $form->input('a', array('type' => 'checkbox'));echo $form->input('b', array('type' => 'checkbox')); echo $form->end('RUN');
If in case, this cannot be done using CakePHP helpers, how can I do it with JavaScript?
Use remoteTimer in a very simple controller. See the page source and between <script> tags you'll get code that does what you want.You can use that code as value for "loading" option.

Resources