Beispiel #1
0
	private function output($applet = false) {
		Base_ThemeCommon::load_css($this->get_type(), 'tray');

		$tray_settings = Utils_TrayCommon::get_trays();

		$tray_def = array();
		$total_pending = 0;
		$displayed = 0;

		foreach ($tray_settings as $module=>$module_settings) {
			foreach ($module_settings as $tab=>$tab_settings) {
				if (!isset($tab_settings['__title__'])) continue;

				$tray = Utils_TrayCommon::get_tray($tab, $tab_settings);

				if (!isset($tray['__slots__']) || count($tray['__slots__'])==0) continue;

				$tray_id = $this->get_type().'__'.Utils_RecordBrowserCommon::get_field_id($tray['__title__']);

				$tray_def += array($tray_id =>array('__title__' => $tray['__title__'], '__weight__'=>isset($tray['__weight__'])?$tray['__weight__']:0));

				foreach ($tray['__slots__'] as $slot_id=>$slot_def) {
					$total_pending += $slot_def['__count__'];
					$displayed += $slot_def['__count__'];

					$tray_def[$tray_id]['__slots__'][$slot_id]['__weight__'] = isset($slot_def['__weight__'])? $slot_def['__weight__']: 0;

					$icon = $this->get_icon($slot_def['__count__']);
					$tray_count_width = ($slot_def['__count__']>99)? 'style="width:28px;"':'';

					$tip_text = __('Click to view %s items from %s<br><br>%d item(s)', array(_V($slot_def['__name__']),_V($tray['__title__']), $slot_def['__count__']));

					$tray_def[$tray_id]['__slots__'][$slot_id]['__html__'] = '<td><a '.$this->create_main_href($module, null, array($tab), null, array('tray_slot'=>$slot_id)).'><div class="Utils_Tray__slot">'.
					Utils_TooltipCommon::create('<img src="'.$icon.'">
					<div class="Utils_Tray__count" '.$tray_count_width.'>'.$slot_def['__count__'].'</div><div>'._V($slot_def['__name__']).'</div>',$tip_text).'</div></a></td>';				
				}
			}
		}

		Utils_TrayCommon::sort_trays($tray_def);

		$trays = array();
		$tray_slots_html = array();
		$current_tray = 0;

		$tray_cols = $applet? 2:$this->get_tray_cols();

		foreach ($tray_def as $tray_id=>$def) {
			$current_tray += 1;
			$current_row = max(array(round($current_tray/$tray_cols), 1));
			$current_col = $current_tray - $tray_cols*($current_row-1);

			if (isset($this->max_trays) && $this->max_trays != '__NULL__') {
				//allow only trays in applet mode as per setting
				if (count($trays) >= $this->max_trays) 	break;
			}

			if (self::get_tray_layout()=='checkered')
			$class = (($current_row+$current_col) % 2)?'Utils_Tray__group_even':'Utils_Tray__group_odd';
			else
			$class = 'Utils_Tray__group_even';

			$trays[] = array(
			'class' => $class,
			'col'=>$current_col,
			'title'=>_V($def['__title__']),
			'id'=>$tray_id);

			foreach ($def['__slots__'] as $slot) {
				$tray_slots_html[$tray_id][] = $slot['__html__'];

				if (isset($this->max_slots) && $this->max_slots != '__NULL__') {
					//allow slots in applet mode as per setting
					if (count($tray_slots_html[$tray_id]) >= $this->max_slots) continue 2;
				}
			}
		}

		eval_js(
		'function Utils_Tray__trays() {
			var trays = '.json_encode($tray_slots_html).';
			return trays;		
		}
		
		jq( document ).ready(function() {
			var resizeId;
			jq(window).resize(function(){
				clearTimeout(resizeId);
				resizeId = setTimeout(Utils_Tray__resize, 300);
			});	
			Utils_Tray__resize();	
		});');

		load_js($this->get_module_dir().'tray.js');

		$theme = $this->init_module('Base/Theme');
		$icon = Base_ThemeCommon::get_template_file($this->get_type(),'pile2.png');

		$theme->assign('main_page', !$applet);
		$theme->assign('caption', Utils_TrayCommon::caption());
		$theme->assign('icon', $icon);
		$theme->assign('trays', $trays);
		$theme->assign('tray_cols', $tray_cols);

		if ($total_pending!=$displayed) {
			print (__('Displaying %d of %d pending', array($displayed, $total_pending)));
		}

		$theme->display('tray');
	}