ISSUE SUMMARY:
I need to create more complex logic for guest event participation approval. The logic is done and works well, but I am looking for a way how I can show the result of my internal check as popup window while the system process ajaxApproveInvite method in /com_community/controllers/events.php
I am trying to find a way how I can create a popup window based on my calculation and I need your help here.
I place code as follows:
At the beggining of the function there was a line as follows:
$response = new JAXResponse();
At the end of the code I put the line as follows:
$response->addScriptCall('cWindowShow', $header, $message, 450, 300, 'warning');
where $header and $messages are 2 strings defined before. But the systems doesn;t show any popup window..
I tried to use the following code just before the end:
$json = array(
'title' => JText::_('COM_COMMUNITY_EVENTS_REQUEST_APPROVED'),
'html' => $contents,
'btnYes' => JText::_('COM_COMMUNITY_YES_BUTTON'),
'btnNo' => JText::_('COM_COMMUNITY_NO_BUTTON')
);
die( json_encode($json) );
But got nothing.
Please provide any guidance how I can get a popup window at ajaxApproveInvite?
HI Vlad,
You also need to change the javascript trigger, I suggest you compare the code with reject button, reject button call this function eventRejectGuest to show the popup first.
well, this hack is really complicated and not easy one, you need to have good knowladge on PHP and Javascript.
thank you!
I am good in development on PHP but with JavaScript I am not always sure.
For ApproveGuest the JS code is as follows:
onclick="joms.api.eventRejectGuest('152', '484');"
while for ApproveInvite:
onclick="jax.call('community','events,ajaxApproveInvite','484' , '152');"
For me, for Approve - it is clear how the system comes at ajaxApproveInvite function at event.php but for eventRejectGuest - this is not clear at all. If I replace jax.call on joms.apa.eventApproveInvite, where I need to add a call for the ajaxApproveInvite ands where can I set a hook for eventApproveInvite?
Thx, Vlad.
Hi Vlad,
Please you look this file components/com_community/assets/source/js/popups/event.rejectguest.js
and function eventRejectGuest on this file
components/com_community/assets/source/js/api.js
our Javascript developer use high level code, so its really hard to be followed :) but you can learn on it :)
thank you!
It would be great if you ask him for an advise. I learned the code and now I understand the whole logic better. Anyway, it would be great if your JS developer share any thoughts here.
Thx, Vlad.
I just need to understand better how "joms.api.eventRejectGuest('152', '484');" is linked with the event.rejectguest.js file and how and where you include this js script file into the php page?
Hi Vlad,
Our javascript developer will give you the example code (the easy method), please stay tuned :)
thank you!
Guys, I need your help. I arrived with creation several changes as follows:
1) I added a block about my new JS function in the components/com_community/assets/source/js/api.js. As far as I understand, this file is loaded from loader.js... Hereby are changes:
... something existing before ...
/** Events. */
eventApproveInvite: function( id, userId ) {
joms.popup.event.approveInvite( id, userId );
},
2) I added a new file which provides popup functionality here: components/com_community/assets/source/js/popups/event.approveInvite.js... something existing before ...
define([
.... something existing before ....
'popups/event.approveinvite',
... something existig before ...
], function() {
return joms.popup.event;
});
onclick="joms.api.eventApproveInvite('<?php echo $eventid; ?>' , '<?php echo $guest->id; ?>');"
I've finally got access into ajaxApproveInvite at events.php with the use of the example of code. Just need a bit more tie to complete the task and as soon as I finish, I update the ticket status.
So far, thank you very much for the support, Vlad.
you're welcome,and good luck :)
Hello Guys, the example really helps, but I am a bit confused with different methods of JavaScript usage in different functions, so I need some guidance.
For my method a simple message is not enough, I have to return html code in some cases with form. Different buttons like Yes, No or done, can be in place.
1. My first problem, when I created my code based on the example, I didn't realize that I have to replace symbols " with \'... well, if you provide more advises about the concretion or just provide a reference for a function or methods you use, it would be great.
2. Second thing - in the php of events.php I saw many times the use of code as follows:
$actions = '<button class="btn" onclick="cWindowHide();">' . JText::_('COM_COMMUNITY_NO') . '</button>';
$response->addAssign('cwin_logo', 'innerHTML', $header);
$response->addScriptCall('cWindowAddContent', $message, $actions);
return $response->sendResponse();
die( json_encode($json) );
As I didn't get any additional help, I want to share my knowledge based on real experience working with the code of JomSocial. Hereby are my comments on questions, which were published above:
1. This is the most important question from all others. The problem is as follows - we prepare HTML code to tranfer it inside of JavaScript. In such a case, we are to prepare the code by removing \r \n characters and by adding characters to symbols like ' or ". There are several links which can help anyone in writing such a case as follows:
1.1
http://stackoverflow.com/questions/3986299/how-to-remove-new-lines-and-returns-from-php-string
1.2
http://stackoverflow.com/questions/3986299/how-to-remove-new-lines-and-returns-from-php-string
Based on those links, I removed from the HTML code all \n \t \r characters and add slashes based on the article from here:
http://stackoverflow.com/questions/5298776/clean-php-output-into-javascript
Those 3 operations help a lot.
2. Without good knowledge of how the Jos team supports such functions, it is difficult to use the, So, I need more info from JOS team.
3. It is quite simple, I just added a style 'joms-js--button-close' for "No" button and it does the magic.
4. Well, it is a way how to return the code from php into JavaScript. For the moment I stay with the method, which was suggested by JOS team above.
Anyway, I would say the support is not so good, but it helps me to solve my problem with losing time on investigation on my side. WiKi and Developers documentation are nothing to help here.
Thank you again the JOS team,
Vlad.