Configure plugins data with a request instead of a page name

This commit is contained in:
Dmitriy Simushev 2014-09-08 12:29:30 +00:00
parent 3a3b7f362b
commit f107ae4556
6 changed files with 50 additions and 50 deletions

View File

@ -260,9 +260,6 @@ 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();
@ -312,9 +309,6 @@ 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();
@ -500,9 +494,6 @@ function setup_chatview_for_user(
) {
$data = setup_chatview($thread);
// Load JavaScript plugins and JavaScripts, CSS files required by them
$data = array_merge_recursive($data, get_plugins_data('client_chat_window'));
// Set user info
$data['chat']['user'] = array(
'name' => htmlspecialchars($thread->userName),
@ -557,9 +548,6 @@ function setup_chatview_for_operator(
) {
$data = setup_chatview($thread);
// Load JavaScript plugins and JavaScripts, CSS files required by them
$data = array_merge_recursive($data, get_plugins_data('agent_chat_window'));
// Set operator info
$data['chat']['user'] = array(
'name' => htmlspecialchars(

View File

@ -60,11 +60,14 @@ class OperatorChatController extends AbstractController
return $this->showErrors(array('Cannot view threads'));
}
$page = setup_chatview_for_operator(
$this->getRouter(),
$request,
$thread,
$operator
$page = array_merge_recursive(
setup_chatview_for_operator(
$this->getRouter(),
$request,
$thread,
$operator
),
get_plugins_data($request)
);
// Build js application options

View File

@ -47,10 +47,13 @@ class UserChatController extends AbstractController
throw new NotFoundException('The thread is not found.');
}
$page = setup_chatview_for_user(
$this->getRouter(),
$request,
$thread
$page = array_merge_recursive(
setup_chatview_for_user(
$this->getRouter(),
$request,
$thread
),
get_plugins_data($request)
);
// Build js application options
@ -145,6 +148,7 @@ class UserChatController extends AbstractController
$info,
$referrer
),
get_plugins_data($request),
array(
'mibewBasePath' => $request->getBasePath(),
'mibewBaseUrl' => $request->getBaseUrl(),
@ -181,6 +185,7 @@ class UserChatController extends AbstractController
$info,
$referrer
),
get_plugins_data($request),
array(
'mibewBasePath' => $request->getBasePath(),
'mibewBaseUrl' => $request->getBaseUrl(),
@ -245,7 +250,10 @@ class UserChatController extends AbstractController
$thread = Thread::load($invitation_state['threadid']);
// Prepare page
$page = setup_invitation_view($thread);
$page = array_merge_recursive(
setup_invitation_view($request, $thread),
get_plugins_data($request)
);
// Build js application options
$page['invitationOptions'] = json_encode($page['invitation']);

View File

@ -81,7 +81,7 @@ class UsersController extends AbstractController
$page['menuid'] = "users";
// Get additional plugins data
$page = array_merge($page, get_plugins_data('users'));
$page = array_merge($page, get_plugins_data($request));
$page = array_merge($page, prepare_menu($operator));
return $this->render('users', $page);

View File

@ -17,8 +17,8 @@
* limitations under the License.
*/
// Import namespaces and classes of the core
use Mibew\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
function get_popup($href, $js_href, $message, $title, $wnd_name, $options)
{
@ -39,18 +39,19 @@ function get_popup($href, $js_href, $message, $title, $wnd_name, $options)
*
* Triggers 'pageAddCSS' and pass listeners associative array with
* following keys:
* - 'page': string, name of page to which CSS files will be attached.
* - 'js': array, with CSS files paths. Modify this array to add or remove
* - 'request': {@link \Symfony\Component\HttpFoundation\Request}, a request
* instance. CSS files will be attached to the requested page.
* - 'css': array, with CSS files paths. Modify this array to add or remove
* additional CSS files.
*
* @param string $page_name CSS files load to this page
* @param Request $request A Request instance.
* @return string HTML block of 'link' tags
*/
function get_additional_css($page_name)
function get_additional_css(Request $request)
{
// Prepare event arguments array
$args = array(
'page' => $page_name,
'request' => $request,
'css' => array(),
);
@ -73,18 +74,19 @@ function get_additional_css($page_name)
*
* Triggers 'pageAddJS' and pass listeners associative array with
* following keys:
* - 'page': string, name of page to which JavaScript files will be attached.
* - 'request': {@link \Symfony\Component\HttpFoundation\Request}, a request
* instance. JavaScript files will be attached to the requested page.
* - 'js': array, with JavaScript files paths. Modify this array to add or
* remove additional JavaScript files.
*
* @param string $page_name JavaScript files load to this page
* @param Request $request A Request instance.
* @return string HTML block of 'script' tags
*/
function get_additional_js($page_name)
function get_additional_js(Request $request)
{
// Prepare event arguments array
$args = array(
'page' => $page_name,
'request' => $request,
'js' => array()
);
@ -106,17 +108,18 @@ function get_additional_js($page_name)
*
* Triggers 'pageAddLocalizedStrings' and pass listeners associative array with
* following keys:
* - 'page': string, name of page to which localized strings will be added.
* - 'request': {@link \Symfony\Component\HttpFoundation\Request}, a request
* instance. Localized strings will be attached to the requested page.
* - 'localized_strings': associative array with localized strings.
*
* @param string $page_name Localized strings add to this page
* @param Request $request A Request instance.
* @return string JSON encoded localized strings
*/
function get_additional_localized_strings($page_name)
function get_additional_localized_strings(Request $request)
{
// Prepare event arguments array
$args = array(
'page' => $page_name,
'request' => $request,
'localized_strings' => array(),
);
@ -139,18 +142,19 @@ function get_additional_localized_strings($page_name)
*
* Triggers 'pageAddJSPluginOptions' and pass listeners associative array with
* following keys:
* - 'page': string, name of page at which plugins will work.
* - 'request': {@link \Symfony\Component\HttpFoundation\Request}, a request
* instance. Plugins will work at the requested page.
* - 'plugins': associative array, whose keys are plugins names and values are
* plugins options. Modify this array to add or change plugins options
*
* @param string $page_name Plugins initialize at this page
* @param Request $request A Request instance.
* @return string JavaScript options block
*/
function get_js_plugin_options($page_name)
function get_js_plugin_options(Request $request)
{
// Prepare event arguments array
$args = array(
'page' => $page_name,
'request' => $request,
'plugins' => array()
);
@ -165,7 +169,7 @@ function get_js_plugin_options($page_name)
/**
* Get additional plugins data for specified page
*
* @param string $page_name Plugins initialize at this page
* @param Request $request A Request instance.
* @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
@ -174,13 +178,13 @@ function get_js_plugin_options($page_name)
* - 'js_plugin_options': contains results of the 'get_js_plugin_options'
* function
*/
function get_plugins_data($page_name)
function get_plugins_data(Request $request)
{
return array(
'additional_css' => get_additional_css($page_name),
'additional_js' => get_additional_js($page_name),
'additional_localized_strings' => get_additional_localized_strings($page_name),
'js_plugin_options' => get_js_plugin_options($page_name)
'additional_css' => get_additional_css($request),
'additional_js' => get_additional_js($request),
'additional_localized_strings' => get_additional_localized_strings($request),
'js_plugin_options' => get_js_plugin_options($request)
);
}

View File

@ -293,9 +293,6 @@ function setup_invitation_view(Thread $thread)
// Set refresh frequency
$data['frequency'] = Settings::get('updatefrequency_chat');
// 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['invitation'] = array();