mirror of
https://github.com/Mibew/mibew.git
synced 2025-02-07 16:24:43 +03:00
Initialize chat js application from controller
This commit is contained in:
parent
dcd17ed01c
commit
452446a375
@ -68,4 +68,66 @@ abstract class AbstractController extends BaseAbstractController
|
|||||||
|
|
||||||
return $this->redirect($path);
|
return $this->redirect($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates JavaScript code that starts client side application.
|
||||||
|
*
|
||||||
|
* @param Request $request Incomming request.
|
||||||
|
* @param array $options Client side application options. At the moment the
|
||||||
|
* method accepts the following options:
|
||||||
|
* - "company": array, a set of company info. See {@link setup_logo()}
|
||||||
|
* for details.
|
||||||
|
* - "mibewHost": string, a URL which is used as a Mibew host. See
|
||||||
|
* {@link setup_logo()} for details.
|
||||||
|
* - "page.title": string, a value which will be used as a page title.
|
||||||
|
* - "startFrom": string, indicates what module should be invoked first.
|
||||||
|
* - "chatOptions": array, (optional) list of chat module options.
|
||||||
|
* - "surveyOptions": array, (optional) list of pre-chat survey module
|
||||||
|
* options.
|
||||||
|
* - "leaveMessageOptions": array, (optional) list of leave message module
|
||||||
|
* options.
|
||||||
|
* - "invitationOptions": array, (optional) list of invitation module
|
||||||
|
* options.
|
||||||
|
* @return string JavaScript code that starts "users" client side
|
||||||
|
* application.
|
||||||
|
* @todo The way options passed here should be reviewed. The method must get
|
||||||
|
* finite number of well-structured arguments.
|
||||||
|
*/
|
||||||
|
protected function startJsApplication(Request $request, $options)
|
||||||
|
{
|
||||||
|
$app_settings = array(
|
||||||
|
'server' => array(
|
||||||
|
'url' => $this->generateUrl('chat_thread_update'),
|
||||||
|
'requestsFrequency' => Settings::get('updatefrequency_chat'),
|
||||||
|
),
|
||||||
|
'page' => array(
|
||||||
|
'style' => $this->getStyle()->getName(),
|
||||||
|
'mibewBasePath' => $request->getBasePath(),
|
||||||
|
'mibewBaseUrl' => $request->getBaseUrl(),
|
||||||
|
'stylePath' => $request->getBasePath() . '/' . $this->getStyle()->getFilesPath(),
|
||||||
|
'company' => $options['company'],
|
||||||
|
'mibewHost' => $options['mibewHost'],
|
||||||
|
'title' => $options['page.title'],
|
||||||
|
),
|
||||||
|
'startFrom' => $options['startFrom'],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add module specific options
|
||||||
|
$module_options_list = array(
|
||||||
|
'chatOptions',
|
||||||
|
'surveyOptions',
|
||||||
|
'leaveMessageOptions',
|
||||||
|
'invitationOptions',
|
||||||
|
);
|
||||||
|
foreach ($module_options_list as $key) {
|
||||||
|
if (isset($options[$key])) {
|
||||||
|
$app_settings[$key] = $options[$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf(
|
||||||
|
'jQuery(document).ready(function() {Mibew.Application.start(%s);});',
|
||||||
|
json_encode($app_settings)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
namespace Mibew\Controller\Chat;
|
namespace Mibew\Controller\Chat;
|
||||||
|
|
||||||
|
use Mibew\Asset\AssetManagerInterface;
|
||||||
use Mibew\Http\Exception\NotFoundException;
|
use Mibew\Http\Exception\NotFoundException;
|
||||||
use Mibew\Thread;
|
use Mibew\Thread;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@ -68,13 +69,15 @@ class OperatorChatController extends AbstractController
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Build js application options
|
// Build js application options
|
||||||
$page['chatOptions'] = json_encode($page['chat']);
|
$page['chatOptions'] = $page['chat'];
|
||||||
|
|
||||||
$page['mibewBasePath'] = $request->getBasePath();
|
|
||||||
$page['mibewBaseUrl'] = $request->getBaseUrl();
|
|
||||||
|
|
||||||
// Initialize client side application
|
// Initialize client side application
|
||||||
$this->getAssetManager()->attachJs('js/compiled/chat_app.js');
|
$this->getAssetManager()->attachJs('js/compiled/chat_app.js');
|
||||||
|
$this->getAssetManager()->attachJs(
|
||||||
|
$this->startJsApplication($request, $page),
|
||||||
|
AssetManagerInterface::INLINE,
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
|
||||||
// Render the page with chat.
|
// Render the page with chat.
|
||||||
return $this->render('chat', $page);
|
return $this->render('chat', $page);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
namespace Mibew\Controller\Chat;
|
namespace Mibew\Controller\Chat;
|
||||||
|
|
||||||
|
use Mibew\Asset\AssetManagerInterface;
|
||||||
use Mibew\Http\Exception\NotFoundException;
|
use Mibew\Http\Exception\NotFoundException;
|
||||||
use Mibew\Settings;
|
use Mibew\Settings;
|
||||||
use Mibew\Thread;
|
use Mibew\Thread;
|
||||||
@ -54,13 +55,15 @@ class UserChatController extends AbstractController
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Build js application options
|
// Build js application options
|
||||||
$page['chatOptions'] = json_encode($page['chat']);
|
$page['chatOptions'] = $page['chat'];
|
||||||
|
|
||||||
$page['mibewBasePath'] = $request->getBasePath();
|
|
||||||
$page['mibewBaseUrl'] = $request->getBaseUrl();
|
|
||||||
|
|
||||||
// Initialize client side application
|
// Initialize client side application
|
||||||
$this->getAssetManager()->attachJs('js/compiled/chat_app.js');
|
$this->getAssetManager()->attachJs('js/compiled/chat_app.js');
|
||||||
|
$this->getAssetManager()->attachJs(
|
||||||
|
$this->startJsApplication($request, $page),
|
||||||
|
AssetManagerInterface::INLINE,
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
|
||||||
// Expand page
|
// Expand page
|
||||||
return $this->render('chat', $page);
|
return $this->render('chat', $page);
|
||||||
@ -150,13 +153,15 @@ class UserChatController extends AbstractController
|
|||||||
$group_id,
|
$group_id,
|
||||||
$info,
|
$info,
|
||||||
$referrer
|
$referrer
|
||||||
),
|
|
||||||
array(
|
|
||||||
'mibewBasePath' => $request->getBasePath(),
|
|
||||||
'mibewBaseUrl' => $request->getBaseUrl(),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$page['leaveMessageOptions'] = json_encode($page['leaveMessage']);
|
$page['leaveMessageOptions'] = $page['leaveMessage'];
|
||||||
|
|
||||||
|
$this->getAssetManager()->attachJs(
|
||||||
|
$this->startJsApplication($request, $page),
|
||||||
|
AssetManagerInterface::INLINE,
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
|
||||||
return $this->render('chat', $page);
|
return $this->render('chat', $page);
|
||||||
}
|
}
|
||||||
@ -186,13 +191,15 @@ class UserChatController extends AbstractController
|
|||||||
$group_id,
|
$group_id,
|
||||||
$info,
|
$info,
|
||||||
$referrer
|
$referrer
|
||||||
),
|
|
||||||
array(
|
|
||||||
'mibewBasePath' => $request->getBasePath(),
|
|
||||||
'mibewBaseUrl' => $request->getBaseUrl(),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$page['surveyOptions'] = json_encode($page['survey']);
|
$page['surveyOptions'] = $page['survey'];
|
||||||
|
|
||||||
|
$this->getAssetManager()->attachJs(
|
||||||
|
$this->startJsApplication($request, $page),
|
||||||
|
AssetManagerInterface::INLINE,
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
|
||||||
return $this->render('chat', $page);
|
return $this->render('chat', $page);
|
||||||
}
|
}
|
||||||
@ -254,13 +261,15 @@ class UserChatController extends AbstractController
|
|||||||
$page = setup_invitation_view($thread);
|
$page = setup_invitation_view($thread);
|
||||||
|
|
||||||
// Build js application options
|
// Build js application options
|
||||||
$page['invitationOptions'] = json_encode($page['invitation']);
|
$page['invitationOptions'] = $page['invitation'];
|
||||||
|
|
||||||
$page['mibewBasePath'] = $request->getBasePath();
|
|
||||||
$page['mibewBaseUrl'] = $request->getBaseUrl();
|
|
||||||
|
|
||||||
// Initialize client side application
|
// Initialize client side application
|
||||||
$this->getAssetManager()->attachJs('js/compiled/chat_app.js');
|
$this->getAssetManager()->attachJs('js/compiled/chat_app.js');
|
||||||
|
$this->getAssetManager()->attachJs(
|
||||||
|
$this->startJsApplication($request, $page),
|
||||||
|
AssetManagerInterface::INLINE,
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
|
||||||
// Expand page
|
// Expand page
|
||||||
return $this->render('chat', $page);
|
return $this->render('chat', $page);
|
||||||
|
@ -6,43 +6,6 @@
|
|||||||
|
|
||||||
<!-- Add style scripts -->
|
<!-- Add style scripts -->
|
||||||
<script type="text/javascript" src="{{asset "@CurrentStyle/js/compiled/scripts.js"}}"></script>
|
<script type="text/javascript" src="{{asset "@CurrentStyle/js/compiled/scripts.js"}}"></script>
|
||||||
|
|
||||||
<!-- Run application -->
|
|
||||||
<script type="text/javascript"><!--
|
|
||||||
jQuery(document).ready(function(){
|
|
||||||
Mibew.Application.start({
|
|
||||||
server: {
|
|
||||||
url: '{{route "chat_thread_update"}}',
|
|
||||||
requestsFrequency: {{frequency}}
|
|
||||||
},
|
|
||||||
page: {
|
|
||||||
style: '{{styleName}}',
|
|
||||||
mibewBasePath: '{{mibewBasePath}}',
|
|
||||||
mibewBaseUrl: '{{mibewBaseUrl}}',
|
|
||||||
stylePath: '{{mibewBasePath}}/{{stylePath}}',
|
|
||||||
company: {
|
|
||||||
name: '{{#jsString}}{{company.name}}{{/jsString}}',
|
|
||||||
chatLogoURL: '{{company.chatLogoURL}}'
|
|
||||||
},
|
|
||||||
mibewHost: '{{mibewHost}}',
|
|
||||||
title: '{{#jsString}}{{[page.title]}}{{/jsString}}'
|
|
||||||
},
|
|
||||||
{{#if chatOptions}}
|
|
||||||
chatOptions: {{{chatOptions}}},
|
|
||||||
{{/if}}
|
|
||||||
{{#if surveyOptions}}
|
|
||||||
surveyOptions: {{{surveyOptions}}},
|
|
||||||
{{/if}}
|
|
||||||
{{#if leaveMessageOptions}}
|
|
||||||
leaveMessageOptions: {{{leaveMessageOptions}}},
|
|
||||||
{{/if}}
|
|
||||||
{{#if invitationOptions}}
|
|
||||||
invitationOptions: {{{invitationOptions}}},
|
|
||||||
{{/if}}
|
|
||||||
startFrom: '{{startFrom}}'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//--></script>
|
|
||||||
{{/override}}
|
{{/override}}
|
||||||
|
|
||||||
{{#override "page"}}
|
{{#override "page"}}
|
||||||
|
Loading…
Reference in New Issue
Block a user