How to open a modal window with a "view" event and FullCalendar in Yii2?

Hello.
I currently have configured a call of a modal window with a page "create":
$.ajax({
 url: 'events/create',
 type: "GET",
 data: {
 date: date
},
 success: function(data) {
$('#crEvent').modal('show')
.find('#modalContent')
.html(data);
},
 error: function() {
alert('Error');
}
 });


Now I need to call a "view" for each event a, and also in a modal window (and then, respectively, and "update").
Here told me how to go to "view" just like on the page. Now, for the same event (click on event-u) to cause the desired "view" in a modal window?

Thank you.

UPD.
3bad0e57bc274bae8a6312086cc52751.png
You need to call a window with information for that event, which I clicked (in fact, I click on the green block).
July 9th 19 at 10:22
3 answers
July 9th 19 at 10:24
Solution
Many thanks to all, and especially for the discussions and help!
Put here the code of their files (those that I changed), maybe useful to someone.
Files CRUD:
_form;
index.php
view.php (just replaced one button).

Controller:
EventsController

When you click on an existing event opens the information about him on top of the same buttons "Edit" and "Delete" (standard when generating CRUD), except that the "Edit" button now causes the edit page for this event inside this modal window. While it is always possible to go back to the information with the button "Back to info" added to new condition in _form.php.
July 9th 19 at 10:26
If you need to display data in vsplyvat, then it is better to use the corresponding response component, Ala:
$('#calendar').fullCalendar({
 eventClick: function(calEvent, jsEvent, view) {
 url = 'http://site.com/default/view?id=' + calEvent.id;
 // then Ajax loaded the content to display url
 // display it in the previously harvested vsplyvala
 // and display it
}
});
The fact that I use a widget for yii2. What you wrote would work if I wrote using jquery. I tried thus to prescribe eventClick not working, moreover, the calendar ceases to boot. - Jayne_Windler commented on July 9th 19 at 10:29
give an example of Your code as You're trying to do - bryana.Renn commented on July 9th 19 at 10:32
I'm just looking for a solution that you can register without editing the code. Because right now, I'm just in the bower folder, in the file fullcalendar.js added eventClick and it works. But it's a crutch. I expected that it is possible to do without such rude edits - what to do widget if it is worse than normal js? - Jayne_Windler commented on July 9th 19 at 10:35
"Because right now, I'm just in the bower folder, in the file fullcalendar.js added eventClick and it works." - don't ever do that, it's bad, very bad.

Yii2 widget is essentially a wrapper for the JS-plugin, which creates a JS object and configures it according to the specified settings. In this widget if I am not mistaken, the responses to the events can be konfigurierbare through property clientOptions, i.e.:

$JSEventClick =new JsExpression("function(calEvent, jsEvent, view) {}); 

yii2fullcalendar\yii2fullcalendar::widget([
 'clientOptions' => [ 
 'eventClick' => new JsExpression($JSEventClick),
],
]);
- bryana.Renn commented on July 9th 19 at 10:38
:
pastebin.com/Z2D9Rvs7 - index.php;
pastebin.com/5M87vW7b - EventsController;
pastebin.com/Jtzg5dTG - calendar.js - Jayne_Windler commented on July 9th 19 at 10:41
: I agree that it's not necessary to do, I just tried it. I'm just new to yii2, so I'm not aware of all the possibilities. Here you are talking about JsExpression them, as I have never dealt with this and I immediately question - and then, in this expression need ID to shoot? - Jayne_Windler commented on July 9th 19 at 10:44
um, what kind of id? Eventa on which clicked? - bryana.Renn commented on July 9th 19 at 10:47
Yes. Look, now tried code
'eventClick' => new JsExpression("function(event) {
alert(event.id);
}")
And it worked!Gives the id of the event! Thanks for the tip!
Now we have to figure out how to call via ajax view with this ID, and even in a modal window and to update is also in the same window, called... - Jayne_Windler commented on July 9th 19 at 10:50
// vsplyvala viewing window
Modal::begin([
 'id' => 'view',
 'header' => '<h2>View Form</h2>', 
 'footer' => \yii\helpers\Html::a('Edit', '$', [
 'id' => 'edit-link',
 'onClick' =>"$('#edit').find('.modal-body').load($(this).attr('href')); $('#edit').modal('show'); return false;" 
])
]);
Modal::end();

// vsplyvala edit window
Modal::begin([
 'id' => 'edit',
 'header' => '<h2>Edit Form</h2>', 
]);
Modal::end();?>

// handler for click event
'eventClick' => new JsExpression("function(event) {
 viewUrl = 'http://site.com/default/view?id=' + event.id;
 updateUrl = 'http://site.com/default/update?id=' + event.id;
 $('#edit-link').attr('href', updateUrl); 
 $('#view').find('.modal-body').load(updateUrl); 
$('#view').modal('show');
}")
- bryana.Renn commented on July 9th 19 at 10:53
: thank you, corrected the code that was called from view, and how to make the update in the same modal window?Not want to produce a bunch of modal Windows. - Jayne_Windler commented on July 9th 19 at 10:56
replace the ID
onClick' =>"$('#view').find('.modal-body').load($(this).attr('href')); $('#edit').modal('show'); return false;" - bryana.Renn commented on July 9th 19 at 10:59
July 9th 19 at 10:28
If the project has a lot of modulok and they loaded ajax content, it is easier to make one modelku and the download code parametrized via data attributes to the button that causes it. For example:
<button type="button" data-toggle="modal" data-url="/myurl" data-header="some header"></button>

call "view" for each event a,

describe what You have in mind, what events are You?
the click event

How can I make a click event if the "click" is the"event"
Apparently You event called something completely different?
I have a modal window is not called via the button. I click on the day and invoked a modal window with the loaded form.
Under the click event I mean click on the event line (i.e. block), as I don't know any other way to bring up a new window with information about this event. - Jayne_Windler commented on July 9th 19 at 10:31
: Then what's the problem? The button contains the id of the block that is sent to ajax in the standard actionView render only there, and rendeAjax. In js success in changing the content means jquery. At what stage of complexity? - bryana.Renn commented on July 9th 19 at 10:34
: I have no id block, you know? And I have not set id of the event in his unit. - Jayne_Windler commented on July 9th 19 at 10:37
And then to understand what the unit of the event click? Write the data-id what's the problem? - bryana.Renn commented on July 9th 19 at 10:40
: the problem is that I wanted to implement it with a minimum of JavaScript code. Just the fact that I already have a full calendar in jquery. However, I want it through the CRUD in Yii 2 to do exactly as I have done in jquery.
How to set data-id, and id there to shoot the event, if obtaining an ID either have to go to the calendar (event.id and all that) or php? - Jayne_Windler commented on July 9th 19 at 10:43
: Show the code where you generated the calendar, You pass it data that it displays? There are not arbitrary data? Here with them, and pass id. - Jayne_Windler commented on July 9th 19 at 10:46
: read the comments to the answer by Maxim Fedorov. I already did that to the id passed through JsExpression. I have even had the view I was shown in a modal window. Now was the update in the same modal window call... - bryana.Renn commented on July 9th 19 at 10:49
: What's the problem? As well as view, only to another action - Jayne_Windler commented on July 9th 19 at 10:52
: I just don't yet know how to alter the links in the buttons :)
$model->id] [
'id' => 'update',
'class' => 'btn btn-primary'
]) ?>
This I have now, but the problem is that when I write the address to click on a button with ID "update", then I'm all in a modal window is loaded, but then flips to the page. But this is easily remedied in a few minutes in the documentation and Google, and everything is OK. - bryana.Renn commented on July 9th 19 at 10:55

Find more questions by tags Yii