Initialize frontend and delivers required javascript files and configuration to the global template.
214 : void
215 {
217
218 if (!self::$frontend_initialized) {
219 $clientSettings =
new ilSetting(
'chatroom');
220
221 if (!self::isOnScreenChatAccessible($clientSettings)) {
222 self::$frontend_initialized = true;
223 return;
224 }
225
227
228 $DIC->language()->loadLanguageModule(
'chatroom');
229 $DIC->language()->loadLanguageModule(
'user');
230
231 $renderer =
$DIC->ui()->renderer();
233
234 $chatWindowTemplate =
new ilTemplate(
'tpl.chat-window.html',
false,
false,
'Services/OnScreenChat');
235 $chatWindowTemplate->setVariable('SUBMIT_ACTION', $renderer->render(
236 $factory->button()->standard(
$DIC->language()->txt(
'chat_osc_send'),
'onscreenchat-submit')
237 ));
238 $chatWindowTemplate->setVariable('ADD_ACTION', $renderer->render(
239 $factory->symbol()->glyph()->add(
'addUser')
240 ));
241 $chatWindowTemplate->setVariable('CLOSE_ACTION', $renderer->render(
243 ));
245
247
248 $guiConfig = array(
249 'chatWindowTemplate' => $chatWindowTemplate->get(),
251 'tpl.chat-message.html',
252 false,
253 false,
254 'Services/OnScreenChat'
255 ))->get(),
257 'tpl.chat-add-user.html',
258 false,
259 false,
260 'Services/OnScreenChat'
261 ))->get(),
262 'userId' =>
$DIC->user()->getId(),
263 'username' =>
$DIC->user()->getLogin(),
264 'userListURL' =>
$DIC->ctrl()->getLinkTargetByClass(
265 'ilonscreenchatgui',
266 'getUserList',
267 '',
268 true,
269 false
270 ),
271 'userProfileDataURL' =>
$DIC->ctrl()->getLinkTargetByClass(
272 'ilonscreenchatgui',
273 'getUserProfileData',
274 '',
275 true,
276 false
277 ),
278 'verifyLoginURL' =>
$DIC->ctrl()->getLinkTargetByClass(
279 'ilonscreenchatgui',
280 'verifyLogin',
281 '',
282 true,
283 false
284 ),
285 'renderNotificationItemsURL' =>
$DIC->ctrl()->getLinkTargetByClass(
286 'ilonscreenchatgui',
287 'getRenderedNotificationItems',
288 '',
289 true,
290 false
291 ),
293 'emoticons' => self::getEmoticons($settings),
294 'locale' =>
$DIC->language()->getLangKey(),
295 'initialUserData' => $subscriberRepo->getInitialUserProfileData(),
296 'enabledBrowserNotifications' => (
297 $clientSettings->get('enable_browser_notifications', false) &&
299 ),
301 );
302
303 $chatConfig = array(
304 'url' => $settings->generateClientUrl() . '/' . $settings->getInstance() . '-im',
305 'subDirectory' => $settings->getSubDirectory() . '/socket.io',
306 'userId' =>
$DIC->user()->getId(),
307 'username' =>
$DIC->user()->getLogin(),
308 );
309
310 $DIC->language()->toJS([
311 'chat_osc_no_usr_found',
312 'chat_osc_emoticons',
313 'chat_osc_write_a_msg',
314 'autocomplete_more',
315 'close',
316 'chat_osc_invite_to_conversation',
317 'chat_osc_user',
318 'chat_osc_add_user',
319 'chat_osc_subs_rej_msgs',
320 'chat_osc_subs_rej_msgs_p',
321 'chat_osc_self_rej_msgs',
322 'chat_osc_search_modal_info',
323 'chat_osc_head_grp_x_persons',
324 'osc_noti_title',
325 'chat_osc_conversations',
326 'chat_osc_sure_to_leave_grp_conv',
327 'chat_osc_user_left_grp_conv',
328 'confirm',
329 'cancel',
330 'chat_osc_leave_grp_conv',
331 'chat_osc_no_conv',
332 'chat_osc_nc_conv_x_p',
333 'chat_osc_nc_conv_x_s',
334 'chat_osc_nc_no_conv',
335 'today',
336 'yesterday',
337 ], $page);
338
342
343 $page->
addJavaScript(
'./libs/bower/bower_components/jquery-outside-events/jquery.ba-outside-events.min.js');
344 $page->
addJavaScript(
'./libs/bower/bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.min.js');
345 $page->addJavascript('./Services/UIComponent/Modal/js/Modal.js');
346 $page->addJavascript('./libs/bower/bower_components/moment/min/moment-with-locales.min.js');
347 $page->addJavascript('./Services/Notifications/js/browser_notifications.js');
348 $page->addJavascript('./Services/OnScreenChat/js/onscreenchat-notifications.js');
349 $page->addJavascript('./Services/OnScreenChat/js/moment.js');
350 $page->addJavascript('./Modules/Chatroom/chat/node_modules/socket.io-client/dist/socket.io.js');
351 $page->addJavascript('./Services/OnScreenChat/js/chat.js');
352 $page->addJavascript('./Services/OnScreenChat/js/onscreenchat.js');
353 $page->
addOnLoadCode(
"il.Chat.setConfig(" . json_encode($chatConfig) .
");");
354 $page->
addOnLoadCode(
"il.OnScreenChat.setConfig(" . json_encode($guiConfig) .
");");
356 $page->
addOnLoadCode(
'il.OnScreenChatNotifications.init(' . json_encode([
357 'conversationIdleTimeThreshold' => max(
358 1,
359 (int) $clientSettings->get('conversation_idle_state_in_minutes', 1)
360 ),
361 'logLevel' =>
$DIC[
'ilLoggerFactory']->getSettings()->getLevelByComponent(
'osch'),
362 ]) . ');');
363
364 self::$frontend_initialized = true;
365 }
366 }
static initLinkify($a_tpl=null)
Init Linkify.
special template class to simplify handling of ITX/PEAR
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static yn2tf($a_yn)
convert "y"/"n" to true/false
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
static initjQueryUI($a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components....
addJavaScript($a_js_file, $a_add_version_parameter=true, $a_batch=2)
Add a javascript file that should be included in the header.
addOnLoadCode($a_code, $a_batch=2)
Add on load code.