Highcarts in Laravel - laravel

I'm trying to render a chart in a Laravel view, i built the chart in the controller but it doesn't work unless i disable the js/app.js, can someone tell me why?
Controller:
$chart1 = \Chart::title([
'text' => 'Voting',
])
->chart([
'type' => 'line', // pie , columnt ect
'renderTo' => 'chart1', // render the chart into your div with id
])
->subtitle([
'text' => 'This Subtitle',
])
->colors([
'#0c2959'
])
->xaxis([
'categories' => [
'data 1',
'data 2',
'data 3',
'data 4',
],
'labels' => [
'rotation' => 15,
'align' => 'top',
'formatter' => 'startJs:function(){return this.value + " (Player)"}:endJs',
// use 'startJs:yourjavasscripthere:endJs'
],
])
->yaxis([
'text' => 'This Y Axis',
])
->legend([
'layout' => 'vertikal',
'align' => 'right',
'verticalAlign' => 'middle',
])
->series(
[
[
'name' => 'Voting',
'data' => [43934, 52503, 57177, 69658],
// 'color' => '#0c2959',
],
]
)
->display();
return view('devices.show', compact('readings', 'chart1'));
Laravel View:
<div id="chart1"></div>
</div>
</div>
</div>
{!! $chart1 !!}
</body>
</html>
The {!! $chart1 !!} is outside of the id=app div

The problem was that i installed Laravel with VUE.js, and VUE was creating the div <div id="app">, and you can't run any JavaScript inside that DIV, i disabled VUE.js and the chart worked

Related

How to increase text area size of summnote field in laravel backpack

I am using laravel backpack as a crud and i'm creating a laravel admin panel with it. I need to use the summernote wysiwyg field and there is a options field attribute with laravel backpack and I am trying to input the minheight option for summer note however it does not add it to the intiatlaztion properly
$this->crud->addField([
'name' => 'desc',
'type' => 'summernote',
'label' => "feature description",
'options' => [
'minheight: 300'
]
]);
as you can see it does not increase the mineheight does anyone have any ideas?
i have a work around but it requires me to edit vendor files which it not something i want to have to deal with.
Place this script below your page to modify size and other characteristics of summernote editor:
<script type="text/javascript">
$(document).ready(function() {
$('#summernote').summernote({
height: 250,
disableResizeEditor: true // This is optional if you want to remove resize
});
});
</script>
Place your rows and cols size in the attributes array !
$this->crud->addField([
'name' => 'desc',
'type' => 'textarea',
'label' => "feature description",
'attributes' => [
'rows' => 20,
'cols' => 20
]
]);
You wrote your options property wrong.
'options' => [
'minheight: 300'
]
While actually it should be:
'options' => [
'minheight' => 300
]
See the difference?
You can use summernote API like this:
$this->crud->addField([
'name' => 'desc',
'type' => 'summernote',
'label' => "feature description",
'options' => [
'minheight' => 300,
'height' => 400
]
]);
$this->crud->addField([
// Summernote
'name' => 'description',
'label' => 'Описание',
'type' => 'summernote',
'options' => [
'placeholder'=> 'Содержание статьи',
'height'=> 500,
'toolbar'=>[
['style', ['style']],
['font', ['bold']], // show only bold button
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']],
['insert', ['link', 'picture', 'video']],
['view', ['fullscreen', 'codeview', 'help']]
],
]
]);

Yii2: How to add an image as a navbar menuitem

i'm trying without success to add an image inside a Navbar menuItem.
It works fine in the brandLabel
But doesn't work on anoter menu item
(I Want to display the logged user image near his name)
I Tryed several times but doesnt seem to make it work,
Would apreciate your help please...
The Code is this:
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => Html::img('#themes'.'/siteImages/Logo.jpg', ['alt'=>Yii::$app->name]),
'options' => [
'class' => 'navbar-default navbar-fixed-top',
],
]);
// display Login page to guests of the site
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => Yii::t('app', 'Login'), 'url' => ['/site/login'],
'options' => [
'class' => 'navbar-right',
],];
}
else
{
// Show sales content to sales+ users
if ( Yii::$app->user->can('useSalesContent'))
{
$menuItems[] = ['label' => Yii::t('app', 'Sales'),
// 'class' => "pull-left",
'url' => Yii::$app->homeUrl,
'linkOptions' => ['id' => 'sales',
'class' => 'navbar-left',
],
];
// Show Admin content to manager+ users
if (Yii::$app->user->can('useAdminContent'))
{
$menuItems[] = ['label' => Yii::t('app', 'Administration'),
'url' => Yii::$app->homeUrl,
'linkOptions' => ['id' => 'admin'],
'options' => [
'class' => 'navbar-left',
],];
}
// display Logout to logged in users
if (!Yii::$app->user->isGuest) {
$menuItems[] =
[
'label' => Yii::t('app', 'Logout'). ' (' . Yii::$app->user-
>identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
//****** This is where I want the user image to be shown ****//
];
}
}
// echo navbar with selected items
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="container">
<?= Alert::widget() ?>
<?= $content ?>
</div>
endBody() ?>
Provided the user model has an attribute imageUrl it would be accessible through:
Yii::$app->user->identity->imageUrl
This would become something like:
If you would like to add it to the logout button:
$menuItems[] = [ 'encode'=>false, label' => Yii::t('app', 'Logout'). ' (' . Yii::$app->user- >identity->username . ') ' . Html::img(Yii::$app->user- >identity->imageUrl), 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']];
make sure you include 'encode' => false,
To add it as a separate item (for instance, to give it a different link):
$menuItems[] = [ 'encode' => false, 'label' => Html::image(Yii::$app->user- >identity->imageUrl)];
Edit:
Make sure you include the Html with a use statement in your view, or provide the full namespace declaration with Html class.

CakePHP 3 : Retrieving data from database using Ajax

I am working on a CakePHP 3 project which is having a Apply Coupon form.
I want to apply the coupon using Ajax.
The view of coupon form is
<?= $this->Form->create(null, [
'url' => ['controller' => 'Coupons', 'action' => 'checkCoupon'],
'name' => 'checkCoupon'
]) ?>
<?= $this->Form->input('coupon_code', [
'type' => 'text',
'placeholder' => 'Apply Coupon Code',
'label' => false
]) ?>
<?= $this->Form->submit('Apply Coupon') ?>
and the checkCoupon action in CouponsController is
public function checkCoupon()
{
$this->request->onlyAllow('ajax'); // No direct access via browser URL
if ($this->request->is('post')) {
$couponCode = $this->request->data['coupon_code'];
$couponCheck = $this->Coupons->find('all', [
'conditions' => [
'coupon_code' => $couponCode
]
]);
if ($couponCheck->count() === 1) {
$coupon = $couponCheck->first();
$valid_till = $coupon->valid_till;
$dt = new Time($valid_till);
$date = $dt->format('Y-m-d');
if ($date >= date('Y-m-d')) {
echo 'Coupon is Valid. Discount of '.$coupon->value.'has been applied';
} else {
echo 'Coupon is Expired';
}
} else {
echo 'This is not a valid coupon code';
}
}
}
I want the $coupon->value and $coupon->id to be retrieved and added to the checkout link as
<?= $this->Html->link(__('Confirm Checkout'), ['controller' => 'ServiceRequests', 'action' => 'confirmCheckout', $service->id, $primaryAddressId, $serviceArea->id, $coupon->id], ['class' => 'btn btn-block btn-success']) ?>
The Apply Coupon form is in checkout action of RequestsController
Also the form is working well. I have checked it by removing the onlyAllow('ajax') line and printing values in check_coupon.ctp view.
How could I do it using Ajax ?
Edit 2 : checkout.ctp
<div class="form-info coupon">
<?= $this->Form->create(null, [
'url' => ['controller' => 'Coupons', 'action' => 'ajax_checkCoupon'],
'name' => 'checkCoupon',
'id' => 'checkCoupon'
]) ?>
<?= $this->Form->input('coupon_code', [
'type' => 'text',
'placeholder' => 'Apply Coupon Code',
'label' => false
]) ?>
<label class="hvr-sweep-to-right">
<?= $this->Form->submit('Apply Coupon', ['id' => 'applyCoupon']) ?>
</label>
<label id="couponUpdate"></label>
<label id="loading" style="display:none;">Loading...</label>
<?php
$data = $this->Html->script('#checkCoupon')->serializeForm(['isForm' => true, 'inline' => true]);
$this->Html->script('#checkCoupon')->event(
'submit',
$this->Html->script(
[
'controller' => 'Coupons',
'action' => 'ajax_checkCoupon'
],
[
'update' => '#couponUpdate',
'data' => $data,
'async' => true,
'dataExpression' => true,
'before' => "$('#loading').fadeIn();$('#applyCoupon').attr('disabled','disabled');",
'complete' => "$('#loading').fadeOut();$('#applyCoupon').removeAttr('disabled');"
]
)
);
?>
</div>
Error : Call to a member function serializeForm() on string on line 18 in checkout.ctp

Drupal 7 form ajax callback show no radio items

I have problem with drupal 7 and form ajax callback.
I have simple form with form select item and when i choose something ajax callback show item with form radios. Its actually works, but I get only radios item title and description but no options to choose.
function my_test_form($form, &$form_state) {
$form['places'] = array(
'#type' => 'select',
'#title' => t('Select twitter trends location'),
'#options' => array('1' => 'item 1', '2' => 'item 2'),
'#default_value' => 1,
'#description' => t('Select description'),
'#ajax' => array(
'callback' => 'my_test_form_callback',
'wrapper' => '.form-item.form-type-select.form-item-places',
'method' => 'append',
'effect' => 'fade',
),
);
return $form;
}
function my_test_form_callback($form, &$form_state) {
$form['trends'] = array(
'#type' => 'radios',
'#title' => t('Select'),
'#options' => array(0 => t('Closed'), 1 => t('Active')),
'#default_value' => 0,
'#description' => t('Radios description.'),
);
return $form['trends'];
}
result of print $form['trends'] -> dpm(drupal_render($form['trends']));
<div class="form-item form-type-radios">
<label>Select trend </label>
<div class="form-radios"></div>
<div class="description">Radios description.</div>
</div>
I would be happy for every advice.
Thanks a lot.
The callback receives a built form. It's only responsible for returning the right part of the form.
function my_test_form_callback($form, &$form_state) {
return $form['trends'];
}
my_test_form is responsible for building the form for the first call and all the following AJAX calls. Simply put your condition inside this function.

codeigniter bootstrap modal popup

I have used bootstrap modal popup in my site. By clicking the button pop will open. It is working on the following code.
HTML:
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
But the button come from array.
<?php
$args['test'] = array(
array(
'type' => 'submit',
'id' => ' text',
'label' => 'Launch demo modal',
'desc' => site_url('test'),
'class' => 'span3',
'default' => '',
'options' => ''),
);
?>
How can I pass "data-toggle="modal" data-target="#myModal" in array.
Nothing different, just add those attributes in the array like this:
array(
'type' => 'submit',
'id' => ' musicfileupload',
'label' => 'Launch demo modal',
'desc' => site_url('test'),
'class' => 'span3',
'default' => '',
'options' => '',
'data-toggle' => 'modal', // <--
'data-target' => '#myModal' // <--
);
Update: Following is a working example:
$data = array(
'type' => 'submit',
'id' => ' musicfileupload',
'label' => 'Launch demo modal',
'desc' => site_url('test'),
'class' => 'span3',
'default' => '',
'options' => '',
'data-toggle' => 'modal', // <--
'data-target' => '#myModal' // <--
);
echo form_button($data);

Resources