From 8869a560ed325b8cdf80826ee78a3fb25afdac97 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Mon, 8 Apr 2013 11:51:25 +0000 Subject: [PATCH] Fix bug with client side plugins initialization Fix prechat survey and leave message page initialization for client --- src/messenger/webim/libs/chat.php | 14 ++++++++------ src/messenger/webim/libs/common/response.php | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index 318fce94..8e88afe0 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -199,6 +199,9 @@ function prepare_chat_app_data() { function setup_leavemessage($name, $email, $group_id, $info, $referrer) { $data = prepare_chat_app_data(); + // Load JavaScript plugins and JavaScripts, CSS files required by them + $data = array_merge_recursive($data, get_plugins_data('client_chat_window')); + // Create some empty arrays $data['leaveMessage'] = array(); @@ -248,6 +251,9 @@ function setup_leavemessage($name, $email, $group_id, $info, $referrer) { function setup_survey($name, $email, $group_id, $info, $referrer) { $data = prepare_chat_app_data(); + // Load JavaScript plugins and JavaScripts, CSS files required by them + $data = array_merge_recursive($data, get_plugins_data('client_chat_window')); + // Create some empty arrays $data['survey'] = array(); @@ -440,9 +446,7 @@ function setup_chatview_for_user(Thread $thread) { $data = setup_chatview($thread); // Load JavaScript plugins and JavaScripts, CSS files required by them - $data['additional_css'] = get_additional_css('client_chat_window'); - $data['additional_js'] = get_additional_js('client_chat_window'); - $data['js_plugin_options'] = get_js_plugin_options('client_chat_window'); + $data = array_merge_recursive($data, get_plugins_data('client_chat_window')); // Set user info $data['chat']['user'] = array( @@ -485,9 +489,7 @@ function setup_chatview_for_operator(Thread $thread, $operator) { $data = setup_chatview($thread); // Load JavaScript plugins and JavaScripts, CSS files required by them - $data['additional_css'] = get_additional_css('agent_chat_window'); - $data['additional_js'] = get_additional_js('agent_chat_window'); - $data['js_plugin_options'] = get_js_plugin_options('agent_chat_window'); + $data = array_merge_recursive($data, get_plugins_data('agent_chat_window')); // Set operator info $data['chat']['user'] = array( diff --git a/src/messenger/webim/libs/common/response.php b/src/messenger/webim/libs/common/response.php index ab39f83a..1db5f363 100644 --- a/src/messenger/webim/libs/common/response.php +++ b/src/messenger/webim/libs/common/response.php @@ -159,6 +159,24 @@ function get_js_plugin_options($page_name) { return json_encode($args['plugins']); } +/** + * Get additional plugins data for specified page + * + * @param string $page_name Plugins initialize at this page + * @return array Associative array of plugins data. It contains following keys: + * - 'additional_css': contains results of the 'get_additional_css function + * - 'additional_js': contains results of the 'get_additional_js' function + * - 'js_plugin_options': contains results of the 'get_js_plugin_options' + * function + */ +function get_plugins_data($page_name) { + return array( + 'additional_css' => get_additional_css($page_name), + 'additional_js' => get_additional_js($page_name), + 'js_plugin_options' => get_js_plugin_options($page_name) + ); +} + function no_field($key) { return getlocal2("errors.required", array(getlocal($key)));