Your IP : 216.73.216.11


Current Path : /home/digilove/www/administrator/components/com_jmap/views/aigenerator/
Upload File :
Current File : /home/digilove/www/administrator/components/com_jmap/views/aigenerator/view.html.php

<?php
// namespace administrator\components\com_jmap\views\aigenerator;
/**
 * @package JMAP::AIGENERATOR::administrator::components::com_jmap
 * @subpackage views
 * @subpackage aigenerator
 * @author Joomla! Extensions Store
 * @copyright (C) 2021 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html  
 */
defined ( '_JEXEC' ) or die ( 'Restricted access' );

/**
 * @package JMAP::AIGENERATOR::administrator::components::com_jmap
 * @subpackage views
 * @subpackage aigenerator
 * @since 2.0
 */
class JMapViewAIGenerator extends JMapView {
	// Template view variables
	protected $pagination;
	protected $searchword;
	protected $orders;
	protected $items;
	protected $urischeme;
	protected $record;
	protected $lists;
	protected $languagePluginEnabled;
	protected $defaultLanguageCode;
	
	/**
	 * Add the page title and toolbar.
	 *
	 * @since	1.6
	 */
	protected function addEditEntityToolbar() {
		$user		= JFactory::getUser();
		$userId		= $user->get('id');
		$isNew		= ($this->record->id == 0);
		$checkedOut	= !($this->record->checked_out == 0 || $this->record->checked_out == $userId);
		$toolbarHelperTitle = $isNew ? 'COM_JMAP_AIGENERATOR_CONTENT_NEW' : 'COM_JMAP_AIGENERATOR_CONTENT_EDIT';
		
		JToolbarHelper::title( JText::_( $toolbarHelperTitle ), 'jmap' );
	
		if ($isNew)  {
			// For new records, check the create permission.
			if ($isNew && ($user->authorise('core.create', 'com_jmap'))) {
				JToolbarHelper::custom('aigenerator.generateEntity', 'cogs', 'cogs', 'COM_JMAP_AIGENERATOR_GENERATE_CONTENTS', false);
				JToolbarHelper::apply( 'aigenerator.applyEntity', 'JAPPLY');
				JToolbarHelper::save( 'aigenerator.saveEntity', 'JSAVE');
				JToolBarHelper::save2new( 'aigenerator.saveEntity2New');
			}
		} else {
			// Can't save the record if it's checked out.
			if (!$checkedOut) {
				// Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
				if ($user->authorise('core.edit', 'com_jmap')) {
					JToolbarHelper::custom('aigenerator.generateEntity', 'cogs', 'cogs', 'COM_JMAP_AIGENERATOR_GENERATE_CONTENTS', false);
					JToolbarHelper::apply( 'aigenerator.applyEntity', 'JAPPLY');
					JToolbarHelper::save( 'aigenerator.saveEntity', 'JSAVE');
					JToolBarHelper::save2new( 'aigenerator.saveEntity2New');
				}
			}
		}
			
		JToolbarHelper::custom('aigenerator.cancelEntity', 'cancel', 'cancel', 'JCANCEL', false);
	}
	
	
	/**
	 * Add the page title and toolbar.
	 *
	 * @since	1.6
	 */
	protected function addDisplayToolbar() {
		$user = JFactory::getUser();
		JToolbarHelper::title( JText::_('COM_JMAP_AIGENERATOR_TITLE' ), 'jmap' );
		// Access check.
		if ($user->authorise('core.create', 'com_jmap')) {
			JToolbarHelper::addNew('aigenerator.editEntity', 'COM_JMAP_AIGENERATOR_NEW_CONTENT');
		}
	
		if ($user->authorise('core.edit', 'com_jmap')) {
			JToolbarHelper::editList('aigenerator.editEntity', 'COM_JMAP_AIGENERATOR_EDIT_CONTENT');
		}
	
		if ($user->authorise('core.delete', 'com_jmap') && $user->authorise('core.edit', 'com_jmap')) {
			JToolbarHelper::deleteList('COM_JMAP_AIGENERATOR_DELETE_CONTENT', 'aigenerator.deleteEntity');
		}
			
		JToolbarHelper::custom('cpanel.display', 'home', 'home', 'COM_JMAP_CPANEL', false);
	}
	
	/**
	 * Default display listEntities
	 *        	
	 * @access public
	 * @param string $tpl
	 * @return void
	 */
	public function display($tpl = null) {
		// Get main records
		$rows = $this->get ( 'Data' );
		$lists = $this->get ( 'Filters' );
		$total = $this->get ( 'Total' );
		
		$doc = JFactory::getDocument();
		$this->loadJQuery($doc);
		$this->loadBootstrap($doc);
		$this->loadJQueryUI($doc);
		
		$orders = array ();
		$orders ['order'] = $this->getModel ()->getState ( 'order' );
		$orders ['order_Dir'] = $this->getModel ()->getState ( 'order_dir' );
		// Pagination view object model state populated
		$pagination = new JPagination ( $total, $this->getModel ()->getState ( 'limitstart' ), $this->getModel ()->getState ( 'limit' ) );
		
		$this->user = JFactory::getUser ();
		$this->pagination = $pagination;
		$this->searchword = $this->getModel ()->getState ( 'searchword' );
		$this->orders = $orders;
		$this->items = $rows;
		$this->lists = $lists;
		$this->option = $this->getModel ()->getState ( 'option' );
		$this->languagePluginEnabled = $this->getModel ()->getLanguagePluginEnabled();
		
		// Aggiunta toolbar
		$this->addDisplayToolbar();
			
		parent::display ( 'list' );
	}
	
	/**
	 * Edit entity view
	 *
	 * @access public
	 * @param Object& $row the item to edit
	 * @return void
	 */
	public function editEntity(&$row) {
		// Sanitize HTML Object2Form
		JFilterOutput::objectHTMLSafe( $row );
		
		// Detect uri scheme
		$instance = JUri::getInstance();
		$this->urischeme = $instance->isSSL() ? 'https' : 'http';
		
		// Load JS Client App dependencies
		$doc = JFactory::getDocument();
		$base = JUri::root();
		$this->loadJQuery($doc);
		$this->loadBootstrap($doc);
		$this->loadValidation($doc);
		
		$doc->addScriptDeclaration("var jmap_baseURI='$base';");
		$doc->addScriptDeclaration("var jmap_urischeme='$this->urischeme';");
		
		// Inject js translations
		$translations = array(	'COM_JMAP_PROGRESSAIGENERATORTITLE',
								'COM_JMAP_PROGRESSAIGENERATORSUBTITLE',
								'COM_JMAP_AIGENERATOR_COPIED_CONTENT',
								'COM_JMAP_PROGRESSAIGENERATOR_ARTICLE_CREATION_TITLE',
								'COM_JMAP_PROGRESSAIGENERATOR_MODULE_CREATION_TITLE',
								'COM_JMAP_PROGRESSAIGENERATOR_CONTENT_CREATION_SUBTITLE_ARTICLE',
								'COM_JMAP_PROGRESSAIGENERATOR_CONTENT_CREATION_SUBTITLE_MODULE',
								'COM_JMAP_PROGRESSAIGENERATOR_CONTENT_CREATION_SUBTITLE_ARTICLE_SUCCESS',
								'COM_JMAP_PROGRESSAIGENERATOR_CONTENT_CREATION_SUBTITLE_MODULE_SUCCESS',
								'COM_JMAP_PROGRESSAIGENERATOR_ARTICLE_CREATION_ERROR',
								'COM_JMAP_PROGRESSAIGENERATOR_MODULE_CREATION_ERROR',
								'COM_JMAP_PROGRESSAIGENERATOR_CONTENT_CREATION_EDIT_ARTICLE',
								'COM_JMAP_PROGRESSAIGENERATOR_CONTENT_CREATION_EDIT_MODULE');
		$this->injectJsTranslations($translations, $doc);
		
		// Load specific JS App
		$doc->addScript ( JUri::root ( true ) . '/administrator/components/com_jmap/js/aigenerator.js' );
		$doc->addScriptDeclaration("
						Joomla.submitbutton = function(pressbutton) {
							if(!jQuery.fn.validation) {
								jQuery.extend(jQuery.fn, jmapjQueryBackup.fn);
							}
				
							jQuery('#adminForm').validation();
							
							if (pressbutton == 'aigenerator.cancelEntity') {	
								jQuery('#adminForm').off();
								Joomla.submitform( pressbutton );
								return true;
							}
							
							if(jQuery('#adminForm').validate()) {
								if (pressbutton == 'aigenerator.generateEntity') {	
									// Start the progress bar
									JMapAIContentGenerator.openProgressContentGeneration();
								}
								Joomla.submitform( pressbutton );
								return true;
							}
							return false;
						};
					");
		
		// Get default site language
		$langParams = JComponentHelper::getParams('com_languages');
		// Setup predefined site language
		$this->defaultLanguageCode = $langParams->get('site');
		$this->defaultSefLanguageCode = JMapLanguageMultilang::getCurrentSefLanguage();
		
		$lists = $this->getModel()->getLists($row);
		$this->option = $this->getModel ()->getState ( 'option' );
		$this->record = $row;
		$this->lists = $lists;
		
		// Aggiunta toolbar
		$this->addEditEntityToolbar();
		
		parent::display ( 'edit' );
	}
}