Blame view

administrator/components/com_jmap/views/wizard/view.html.php 6.62 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
<?php
// namespace administrator\components\com_jmap\views\wizard;
/**
 * @package JMAP::WIZARD::administrator::components::com_jmap
 * @subpackage views
 * @subpackage wizard
 * @author Joomla! Extensions Store
 * @copyright (C) 2015 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html  
 */
defined ( '_JEXEC' ) or die ( 'Restricted access' );
 
/**
 * Wizard view class. Only use is to render wizard control panel for supported extensions data source creation 
 * 
 * @package JMAP::WIZARD::administrator::components::com_jmap
 * @subpackage views
 * @subpackage wizard
 * @since 2.0
 */
class JMapViewWizard extends JMapView {
	/**
	 * Render default user defined icon for cpanel
	 *
	 * @param $link string
	 * @param $image string
	 * @access private
	 * @return string
	 */
	private function renderCustomDatasourceIcon() {
		$lang =  JFactory::getLanguage ();
		$langDirection = $lang->isRTL() ? 'right' : 'left';
		$dataContent = JText::_('COM_JMAP_CREATE_CUSTOM_DATASOURCE_DESC');
		$text = JText::_('COM_JMAP_CREATE_CUSTOM_DATASOURCE');
		$link = JFilterOutput::ampReplace('index.php?option=com_jmap&task=sources.editentity');
		$imageAlt = JText::_('COM_JMAP_CREATE_CUSTOM_DATASOURCE');
		$iconSnippet = <<<HTML
			<div style="float: $langDirection;">
				<div class="icon hasPopover" data-content="$dataContent">
					<a href="$link">
						<img src="components/com_jmap/images/wizard/custom.png" alt="$imageAlt"/>
						<span>$text</span>
					</a>
				</div>
			</div>
HTML;
		return $iconSnippet;
	}

	/**
	 * Render plugin data source type icon for cpanel
	 *
	 * @param $link string
	 * @param $image string
	 * @access private
	 * @return string
	 */
	private function renderPluginDatasourceIcon() {
		$lang =  JFactory::getLanguage ();
		$langDirection = $lang->isRTL() ? 'right' : 'left';
		$dataContent = JText::_('COM_JMAP_CREATE_PLUGIN_DATASOURCE_DESC');
		$text = JText::_('COM_JMAP_CREATE_PLUGIN_DATASOURCE');
		$link = JFilterOutput::ampReplace('index.php?option=com_jmap&task=sources.editentity&type=plugin');
		$imageAlt = JText::_('COM_JMAP_CREATE_PLUGIN_DATASOURCE');
		$iconSnippet = <<<HTML
			<div style="float: $langDirection;">
				<div class="icon hasPopover" data-content="$dataContent">
					<a href="$link">
						<img src="components/com_jmap/images/wizard/plugin.png" alt="$imageAlt"/>
						<span>$text</span>
					</a>
				</div>
			</div>
HTML;
		return $iconSnippet;
	}

	/**
	 * Render links data source type icon for cpanel
	 *
	 * @param $link string
	 * @param $image string
	 * @access private
	 * @return string
	 */
	private function renderLinksDatasourceIcon() {
		$lang =  JFactory::getLanguage ();
		$langDirection = $lang->isRTL() ? 'right' : 'left';
		$dataContent = JText::_('COM_JMAP_CREATE_LINKS_DATASOURCE_DESC');
		$text = JText::_('COM_JMAP_CREATE_LINKS_DATASOURCE');
		$link = JFilterOutput::ampReplace('index.php?option=com_jmap&task=sources.editentity&type=links');
		$imageAlt = JText::_('COM_JMAP_CREATE_LINKS_DATASOURCE');
		$iconSnippet = <<<HTML
			<div style="float: $langDirection;">
				<div class="icon hasPopover" data-content="$dataContent">
					<a href="$link">
						<img src="components/com_jmap/images/wizard/links.png" alt="$imageAlt"/>
						<span>$text</span>
					</a>
				</div>
			</div>
HTML;
		return $iconSnippet;
	}

	/**
	 * Render iconset for cpanel
	 *
	 * @param $link string
	 * @param $image string
	 * @access private
	 * @return void
	 */
	private function renderIcon($link, $dataSourceName, $dataSourceUserViewName, $extensionName) {
		$lang =  JFactory::getLanguage ();
		?>
		<div style="float:<?php echo ($lang->isRTL()) ? 'right' : 'left'; ?>;">
			<div class="icon hasPopover" data-content="<?php echo sprintf(JText::_('COM_JMAP_CREATE_DATASOURCE'), $dataSourceUserViewName);?>">
				<a data-role="start_create_process" data-extension="<?php echo $extensionName; ?>" href="<?php echo JFilterOutput::ampReplace($link); ?>">
					<img src="components/com_jmap/images/wizard/<?php echo $dataSourceName;?>/icon.png" alt="<?php echo $dataSourceUserViewName;?>"/>
					<span><?php echo $dataSourceUserViewName; ?></span>
				</a>
			</div>
		</div>
		<?php
	}
	
	/**
	 * Add the page title and toolbar.
	 *
	 * @since	1.6
	 */
	protected function addDisplayToolbar() {
		$doc = JFactory::getDocument();
		$doc->addStyleDeclaration('.icon-48-jmap{background-image:url("components/com_jmap/images/icon-48-wizard.png")}');
		JToolBarHelper::title( JText::_('COM_JMAP_JMAPWIZARD' ), 'jmap' );
		JToolBarHelper::custom('sources.display', 'list', 'list', 'COM_JMAP_DATA_SOURCES', false);
		JToolBarHelper::custom('cpanel.display', 'home', 'home', 'COM_JMAP_CPANEL', false);
	}
	
	/**
	 * Default display that renders wizard icons control panel and inject JS APP
	 *        	
	 * @access public
	 * @param string $tpl
	 * @return void
	 */
	public function display($tpl = null) {
		$doc = $this->document;
		$this->loadJQuery($doc);
		$this->loadBootstrap($doc);
		$base = JUri::base();
		$doc->addStylesheet ( JUri::root ( true ) . '/administrator/components/com_jmap/css/wizard.css' );
		$doc->addScript ( JUri::root ( true ) . '/administrator/components/com_jmap/js/wizard.js' );
		$doc->addScriptDeclaration("var jmap_baseURI='$base';");
		
		// Inject js translations
		$translations = array(	'COM_JMAP_PROGRESSINFOTITLE1', 
								'COM_JMAP_PROGRESSINFOSUBTITLE1',
								'COM_JMAP_PROGRESSINFOSUBTITLE1_2',
								'COM_JMAP_PROGRESSINFOSUBTITLE1_2ERROR',
								'COM_JMAP_PROGRESSINFOTITLE2',
								'COM_JMAP_PROGRESSINFOSUBTITLE2',
								'COM_JMAP_PROGRESSINFOSUBTITLE2_2');
		$this->injectJsTranslations($translations, $doc);
		
		// get Filter Input to mor security safe
		$filterInput = JFilterInput::getInstance();
		$discoveredExtensions = $this->getModel()->getData(JPATH_COMPONENT . '/images/wizard');
		
		// Buffer delle icons
		ob_start ();
		if(!empty($discoveredExtensions)) {
			foreach ($discoveredExtensions as $discoveredExtension) {
				$dataSourceName = $discoveredExtension['dataSourceName'];
				$extensionName = $discoveredExtension['extensionName']; 
				$dataSourceUserViewName = ucfirst(str_replace('_', ' ', $dataSourceName));
				$this->renderIcon ( 'index.php?option=com_jmap&task=wizard.createEntity&extension=' . $filterInput->clean($dataSourceName, 'CMD'), $dataSourceName, $dataSourceUserViewName, $extensionName);
			}
		}
		$contents = ob_get_clean ();
		 
		// Assign reference variables
		$this->icons = $contents;
		$this->customIcon = $this->renderCustomDatasourceIcon();
		$this->pluginIcon = $this->renderPluginDatasourceIcon();
		$this->linksIcon = $this->renderLinksDatasourceIcon();
		
		// Aggiunta toolbar
		$this->addDisplayToolbar();
		
		// Output del template
		parent::display ();
	}
}