{extends file=$smarty.const.SMARTY_LAYOUT_MAIN_WINDOW}

{block name="template-head"}
	{* load dashboard.d3 group, don't load base group (including prototype.js) because dashboard.d3 already contains prototype & scriptaculous *}
	{$JS->loadGroup("dashboard.d3", [ 'defer'=>false ])}
	{$CSS->loadGroup("dashboard.d3")}

	{$JS->loadGroup("window")}
	{$CSS->loadGroup("window")}

	{$JS->loadGroup("effects", [ 'defer'=>false ])}
	{$CSS->loadGroup("effects")}

	{$JS->loadGroup("menu")}
	{$CSS->loadGroup("menu")}

	{$JS->loadGroup("inputs")}
	{$CSS->loadGroup("inputs")}

	{$JS->loadGroup("dashboard")}
	{$CSS->loadGroup("dashboard")}

	{$JS->loadGroup("optionsBox.icons")}
	{$CSS->loadGroup("optionsBox.icons")}
	
	{* used for remote details box on all entities *}
	{$JS->loadGroup("remoteLoad", [ 'defer'=>false ])}
	{$CSS->loadGroup("remoteLoad")}
	
{/block}

{block name="body-declaration-class"}messageDiv-absolute window withLogo{/block}

{block name="windowHeader"}
	<div class='messageDivContainer'>
		<ul class="notification" style="display:none;"></ul>
	</div>
{/block}

{block name="content" append}
	<div class="window-header">

		<div class="optionsBox sectionGlobal">
			{$menuComponent = $mvcView->buildOptionsComponent()}
			{$menuComponent->preloadCss($CSS)}
			{$menuComponent->preloadJs($JS)}
			{$menuComponent->renderHtml()}
		</div>

		<div class="section">
			<div class='current'>{$dashboard->getTitle()}</div>
		</div>

		{block name="subsection"}{/block}
	</div>

	{* the dashboard content **********************}
	<div id="dashboardContainer" class="engine-window-container">
		{$dashboard->render()}

		<div style='display: none;' class="dashboard hiddenContainer">
			{block name="hiddenContainer"}
				{include file="{$APP_REAL_PATH}_templates/engine/dashboard/default-dashboardEmpty.tpl"}
				{include file="{$APP_REAL_PATH}_templates/engine/dashboard/default-errorMessage.tpl"}
			{/block}
		</div>
	</div>
{/block}



{block name="js" append}
	<script type="text/javascript">
		MVC.scheduleOnLoad(function() {

			{$menuComponent->renderJs($JS)}

			// install the dasboard handlers for all elements in the dashboard
			var dashboard = new _dashboard($('{$dashboard->getId()}'), '{$dashboardId|escape:'javascript'}', {
				locked: {if $dashboard->isLocked()}true{else}false{/if},
				changeTemplateUrl: MVC.appUrl(MVC.CURRENT_MODULE, 'changeTemplate', { 'idEntity' : "{$idEntity}" }),
				editDashboardUrl: MVC.appUrl(MVC.CURRENT_MODULE, 'editDashboardElement', { 'idEntity' : "{$idEntity}" }),
				renderUrl: MVC.appUrl(MVC.CURRENT_MODULE, 'renderElement', { 'idEntity' : "{$idEntity}" }),
				editWidgetUrl: MVC.appUrl(MVC.CURRENT_MODULE, 'editWidgetElement', { 'idEntity' : "{$idEntity}" }),
				callMethodUrl: MVC.appUrl(MVC.CURRENT_MODULE, 'callMethod', { 'idEntity' : "{$idEntity}" }),
				templatesContainer: $$('#dashboardContainer >div.dashboard.hiddenContainer').first(),
			});
			dashboard.LANG.confirm = '{$_LANG['confirm']|escape:javascript}';
			dashboard.LANG.confirmTemplateChange     = '{$_LANG['dashboard']['messages']['confirmTemplateChange']|escape:javascript}';
			dashboard.LANG.confirmDashboardDestroy   = '{$_LANG['dashboard']['messages']['confirmDashboardDestroy']|escape:javascript}';
			dashboard.LANG.layoutDoesntFitTheContent = '{$_LANG['dashboard']['messages']['layoutDoesntFitTheContent']|escape:javascript}';
			dashboard.initialize();

			// initialize dashboard controller
			dashboardController = new _dashboardController(dashboard, {});
			dashboardController.LANG.close = '{$_LANG.close}';
			dashboardController.initialize();

			dashboard.overlay = dashboardController.overlay;

			optionsBox = new _optionsBox({});
			optionsBox.attach($$('.optionsBox.sectionGlobal').first());
			optionsBox.initialize();

			{if $extraMessages}
				var messagesList = [];
				{foreach $extraMessages->getMessages() as $msg}
					var object = {
						'type' : '{$msg->getType()|escape:"javascript"}',
						'message' : '{$msg->getText()|escape:"javascript"}'
					}
					messagesList.push(object);
				{/foreach}
				MVC.displayMessages(messagesList);
			{/if}
		});
	</script>
{/block}
