Improved the field builder around JCB, moved some xml function into the JCB helper class core

This commit is contained in:
2018-04-08 08:12:18 +02:00
parent 6a77d71095
commit 10fdac5d60
38 changed files with 1123 additions and 472 deletions

View File

@ -106,7 +106,7 @@ jQuery(document).ready(function($) {
<div id="j-main-container">
<?php endif; ?>
<div id="form">
<div class="span6">
<div class="span4">
<h3><?php echo JText::_('COM_COMPONENTBUILDER_READY_TO_COMPILE_A_COMPONENT'); ?></h3>
<form action="index.php?option=com_componentbuilder&view=compiler" method="post" name="compilerForm" id="compilerForm" class="form-validate" enctype="multipart/form-data">
<div>
@ -130,7 +130,7 @@ jQuery(document).ready(function($) {
<?php echo JHtml::_('form.token'); ?>
</form>
</div>
<div class="span6">
<div class="span7">
<div id="component-details"><?php echo $selectNotice; ?></div>
<div id="noticeboard" class="well well-small">
<h2 class="module-title nav-header"><?php echo JText::_('COM_COMPONENTBUILDER_VDM_NOTICE_BOARD'); ?><span id="vdm-new-notice" style="display:none; color:red;"> (<?php echo JText::_('COM_COMPONENTBUILDER_NEW_NOTICE'); ?>)</span></h2>

View File

@ -80,61 +80,143 @@ class ComponentbuilderViewCompiler extends JViewLegacy
{
if(ComponentbuilderHelper::checkArray($this->Components)){
jimport('joomla.form.form');
// start the form
$form = array();
// get the sales radio field
$sales = JFormHelper::loadFieldType('radio',true);
// start sales xml
$salesXML = new SimpleXMLElement('<field/>');
// sales attributes
$salesAttributes = array(
'type' => 'radio',
'name' => 'backup',
'label' => 'COM_COMPONENTBUILDER_ADD_TO_BACKUP_FOLDER_AMP_SALES_SERVER_SMALLIF_SETSMALL',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_SHOULD_THE_ZIPPED_PACKAGE_OF_THE_COMPONENT_BE_MOVED_TO_THE_LOCAL_BACKUP_AND_REMOTE_SALES_SERVER_THIS_IS_ONLY_APPLICABLE_IF_THIS_COMPONENT_HAS_THOSE_VALUES_SET',
'default' => '0');
// load the sales attributes
ComponentbuilderHelper::xmlAddAttributes($salesXML, $salesAttributes);
// set the sales options
$salesOptions = array(
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
// load the sales options
ComponentbuilderHelper::xmlAddOptions($salesXML, $salesOptions);
// setup the sales radio field
$sales->setup($salesXML,0);
// add to form
$form[] = $sales;
$radio1 = JFormHelper::loadFieldType('radio',true);
// start building add to sales folder xml field
$xml = '<field label="'.JText::_('COM_COMPONENTBUILDER_ADD_TO_BACKUP_FOLDER_AMP_SALES_SERVER_LTSMALLGTIF_SETLTSMALLGT').'" description="'.JText::_('COM_COMPONENTBUILDER_SHOULD_THE_ZIPPED_PACKAGE_OF_THE_COMPONENT_BE_MOVED_TO_THE_LOCAL_BACKUP_AND_REMOTE_SALES_SERVER_THIS_IS_ONLY_APPLICABLE_IF_THIS_COMPONENT_HAS_THOSE_VALUES_SET').'" name="backup" type="radio" class="btn-group btn-group-yesno" default="0">';
$xml .= '<option value="1">'.JText::_('COM_COMPONENTBUILDER_YES').'</option> <option value="0">'.JText::_('COM_COMPONENTBUILDER_NO').'</option>';
$xml .= "</field>";
// prepare the xml
$sales = new SimpleXMLElement($xml);
// set components to form
$radio1->setup($sales,0);
$radio2 = JFormHelper::loadFieldType('radio',true);
// start building add to repository folder xml field
$xml = '<field label="'.JText::_('COM_COMPONENTBUILDER_ADD_TO_REPOSITORY_FOLDER').'" description="'.JText::_('COM_COMPONENTBUILDER_SHOULD_THE_COMPONENT_BE_MOVED_TO_YOUR_LOCAL_REPOSITORY_FOLDER').'" name="repository" type="radio" class="btn-group btn-group-yesno" default="1">';
$xml .= '<option value="1">'.JText::_('COM_COMPONENTBUILDER_YES').'</option> <option value="0">'.JText::_('COM_COMPONENTBUILDER_NO').'</option>';
$xml .= "</field>";
// prepare the xml
$repository = new SimpleXMLElement($xml);
// set components to form
$radio2->setup($repository,1);
$radio3 = JFormHelper::loadFieldType('radio',true);
// start building custom code placeholders
$xml = '<field label="'.JText::_('COM_COMPONENTBUILDER_ADD_CUSTOM_CODE_PLACEHOLDERS').'" description="'.JText::_('COM_COMPONENTBUILDER_SHOULD_JCB_INSERT_THE_CUSTOM_CODE_PLACEHOLDERS_THIS_IS_ONLY_APPLICABLE_IF_THIS_COMPONENT_HAS_CUSTOM_CODE').'" name="placeholders" type="radio" class="btn-group btn-group-yesno" default="2">';
$xml .= '<option value="2">'.JText::_('COM_COMPONENTBUILDER_GLOBAL').'</option> <option value="1">'.JText::_('COM_COMPONENTBUILDER_YES').'</option> <option value="0">'.JText::_('COM_COMPONENTBUILDER_NO').'</option>';
$xml .= "</field>";
// prepare the xml
$placeholder = new SimpleXMLElement($xml);
// set components to form
$radio3->setup($placeholder,2);
$radio4 = JFormHelper::loadFieldType('radio',true);
// add debug line numbers
$xml = '<field label="'.JText::_('COM_COMPONENTBUILDER_DEBUG_LINE_NUMBERS').'" description="'.JText::_('COM_COMPONENTBUILDER_ADD_CORRESPONDING_LINE_NUMBERS_TO_THE_DYNAMIC_COMMENTS_SO_TO_SEE_WHERE_IN_THE_COMPILER_THE_LINES_OF_CODE_WAS_BUILD_THIS_WILL_HELP_IF_YOU_NEED_TO_GET_MORE_TECHNICAL_WITH_AN_ISSUE_ON_GITHUB_OR_EVEN_FOR_YOUR_OWN_DEBUGGING').'" name="debuglinenr" type="radio" class="btn-group btn-group-yesno" default="2">';
$xml .= '<option value="2">'.JText::_('COM_COMPONENTBUILDER_GLOBAL').'</option> <option value="1">'.JText::_('COM_COMPONENTBUILDER_YES').'</option> <option value="0">'.JText::_('COM_COMPONENTBUILDER_NO').'</option>';
$xml .= "</field>";
// prepare the xml
$debug_linenr = new SimpleXMLElement($xml);
// set components to form
$radio4->setup($debug_linenr,2);
$list = JFormHelper::loadFieldType('list',true);
// start building componet xml field
$xml = '<field label="'.JText::_('COM_COMPONENTBUILDER_COMPONENTS').'" description="'.JText::_('COM_COMPONENTBUILDER_SELECT_THE_COMPONENT_TO_COMPILE').'" name="component" type="list" class="btn-group" required="true">';
$xml .= '<option value="">'.JText::_('COM_COMPONENTBUILDER__SELECT_COMPONENT_').'</option>';
foreach($this->Components as $componet){
$xml .= '<option value="'.$componet->id.'">'.$this->escape($componet->name).'</option>';
// get the repository radio field
$repository = JFormHelper::loadFieldType('radio',true);
// start repository xml
$repositoryXML = new SimpleXMLElement('<field/>');
// repository attributes
$repositoryAttributes = array(
'type' => 'radio',
'name' => 'repository',
'label' => 'COM_COMPONENTBUILDER_ADD_TO_REPOSITORY_FOLDER',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_SHOULD_THE_COMPONENT_BE_MOVED_TO_YOUR_LOCAL_REPOSITORY_FOLDER',
'default' => '1');
// load the repository attributes
ComponentbuilderHelper::xmlAddAttributes($repositoryXML, $repositoryAttributes);
// start the repository options
$repositoryOptions = array(
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
// load the repository options
ComponentbuilderHelper::xmlAddOptions($repositoryXML, $repositoryOptions);
// setup the repository radio field
$repository->setup($repositoryXML,1);
// add to form
$form[] = $repository;
// get the placeholders radio field
$placeholders = JFormHelper::loadFieldType('radio',true);
// start placeholders xml
$placeholdersXML = new SimpleXMLElement('<field/>');
// placeholders attributes
$placeholdersAttributes = array(
'type' => 'radio',
'name' => 'placeholders',
'label' => 'COM_COMPONENTBUILDER_ADD_CUSTOM_CODE_PLACEHOLDERS',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_SHOULD_JCB_INSERT_THE_CUSTOM_CODE_PLACEHOLDERS_THIS_IS_ONLY_APPLICABLE_IF_THIS_COMPONENT_HAS_CUSTOM_CODE',
'default' => '2');
// load the placeholders attributes
ComponentbuilderHelper::xmlAddAttributes($placeholdersXML, $placeholdersAttributes);
// start the placeholders options
$placeholdersOptions = array(
'2' => 'COM_COMPONENTBUILDER_GLOBAL',
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
// load the placeholders options
ComponentbuilderHelper::xmlAddOptions($placeholdersXML, $placeholdersOptions);
// setup the placeholders radio field
$placeholders->setup($placeholdersXML,2);
// add to form
$form[] = $placeholders;
// get the debuglinenr radio field
$debuglinenr = JFormHelper::loadFieldType('radio',true);
// start debuglinenr xml
$debuglinenrXML = new SimpleXMLElement('<field/>');
// debuglinenr attributes
$debuglinenrAttributes = array(
'type' => 'radio',
'name' => 'debuglinenr',
'label' => 'COM_COMPONENTBUILDER_DEBUG_LINE_NUMBERS',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_ADD_CORRESPONDING_LINE_NUMBERS_TO_THE_DYNAMIC_COMMENTS_SO_TO_SEE_WHERE_IN_THE_COMPILER_THE_LINES_OF_CODE_WAS_BUILD_THIS_WILL_HELP_IF_YOU_NEED_TO_GET_MORE_TECHNICAL_WITH_AN_ISSUE_ON_GITHUB_OR_EVEN_FOR_YOUR_OWN_DEBUGGING',
'default' => '2');
// load the debuglinenr attributes
ComponentbuilderHelper::xmlAddAttributes($debuglinenrXML, $debuglinenrAttributes);
// start the debuglinenr options
$debuglinenrOptions = array(
'2' => 'COM_COMPONENTBUILDER_GLOBAL',
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
// load the debuglinenr options
ComponentbuilderHelper::xmlAddOptions($debuglinenrXML, $debuglinenrOptions);
// setup the debuglinenr radio field
$debuglinenr->setup($debuglinenrXML,2);
// add to form
$form[] = $debuglinenr;
// get the component list field
$component = JFormHelper::loadFieldType('list',true);
// start component xml
$componentXML = new SimpleXMLElement('<field/>');
// component attributes
$componentAttributes = array(
'type' => 'list',
'name' => 'component',
'label' => 'COM_COMPONENTBUILDER_COMPONENTS',
'class' => 'list_class',
'description' => 'COM_COMPONENTBUILDER_SELECT_THE_COMPONENT_TO_COMPILE',
'required' => 'true');
// load the component attributes
ComponentbuilderHelper::xmlAddAttributes($componentXML, $componentAttributes);
// start the component options
$componentOptions = array();
$componentOptions[''] = 'COM_COMPONENTBUILDER__SELECT_COMPONENT_';
// load component options from array
foreach($this->Components as $componet)
{
$componentOptions[(int) $componet->id] = $this->escape($componet->name);
}
$xml .= "</field>";
// prepare the xml
$componets = new SimpleXMLElement($xml);
// set components to form
$list->setup($componets,0);
return array($radio1,$radio2,$radio3,$radio4,$list);
// load the component options
ComponentbuilderHelper::xmlAddOptions($componentXML, $componentOptions);
// setup the component radio field
$component->setup($componentXML,'');
// add to form
$form[] = $component;
// return the form array
return $form;
}
return false;
}

View File

@ -104,91 +104,160 @@ class ComponentbuilderViewImport_joomla_components extends JViewLegacy
$form = array();
if ('smart_package' === $type)
{
$radio1 = JFormHelper::loadFieldType('radio',true);
// Switch to force local update
$xml = '<field label="'.JText::_('COM_COMPONENTBUILDER_FORCE_LOCAL_UPDATE').'" description="'.JText::_('COM_COMPONENTBUILDER_SHOULD_WE_FORCE_THE_UPDATE_OF_ALL_LOCAL_DATA_EVEN_IF_IT_IS_NEWER_THEN_THE_DATA_BEING_IMPORTED').'" name="force_update" type="radio" class="btn-group btn-group-yesno" default="0" filter="INT">';
$xml .= '<option value="1">'.JText::_('COM_COMPONENTBUILDER_YES').'</option> <option value="0">'.JText::_('COM_COMPONENTBUILDER_NO').'</option>';
$xml .= "</field>";
// prepare the xml
$force = new SimpleXMLElement($xml);
// set components to form
$radio1->setup($force,0);
// get the force_update radio field
$force_update = JFormHelper::loadFieldType('radio',true);
// start force_update xml
$force_updateXML = new SimpleXMLElement('<field/>');
// force_update attributes
$force_updateAttributes = array(
'type' => 'radio',
'name' => 'backup',
'label' => 'COM_COMPONENTBUILDER_FORCE_LOCAL_UPDATE',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_SHOULD_WE_FORCE_THE_UPDATE_OF_ALL_LOCAL_DATA_EVEN_IF_IT_IS_NEWER_THEN_THE_DATA_BEING_IMPORTED',
'default' => '0');
// load the force_update attributes
ComponentbuilderHelper::xmlAddAttributes($force_updateXML, $force_updateAttributes);
// set the force_update options
$force_updateOptions = array(
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
// load the force_update options
ComponentbuilderHelper::xmlAddOptions($force_updateXML, $force_updateOptions);
// setup the force_update radio field
$force_update->setup($force_updateXML,0);
// add to form
$form[] = $radio1;
$form[] = $force_update;
$radio2 = JFormHelper::loadFieldType('radio',true);
// Switch to show more information about the import
$xml = '<field label="'.JText::_('COM_COMPONENTBUILDER_QUIET').'" description="'.JText::_('COM_COMPONENTBUILDER_SELECT_IF_THE_IMPORT_SHOULD_BE_SHOWING_MORE_ELABORATE_OR_LESS_QUIET_INFORMATION_DURING_IMPORT').'" name="more_info" type="radio" class="btn-group btn-group-yesno" default="0" filter="INT">';
$xml .= '<option value="0">'.JText::_('COM_COMPONENTBUILDER_YES').'</option> <option value="1">'.JText::_('COM_COMPONENTBUILDER_NO').'</option>';
$xml .= "</field>";
// prepare the xml
$information = new SimpleXMLElement($xml);
// set information to form
$radio2->setup($information,0);
// get the more_info radio field
$more_info = JFormHelper::loadFieldType('radio',true);
// start more_info xml
$more_infoXML = new SimpleXMLElement('<field/>');
// more_info attributes
$more_infoAttributes = array(
'type' => 'radio',
'name' => 'backup',
'label' => 'COM_COMPONENTBUILDER_SEE_ALL_IMPORT_INFO',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_SHOULD_WE_BE_SHOWING_MORE_ELABORATE_INFORMATION_DURING_IMPORT',
'default' => '0');
// load the more_info attributes
ComponentbuilderHelper::xmlAddAttributes($more_infoXML, $more_infoAttributes);
// set the more_info options
$more_infoOptions = array(
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
// load the more_info options
ComponentbuilderHelper::xmlAddOptions($more_infoXML, $more_infoOptions);
// setup the more_info radio field
$more_info->setup($more_infoXML,0);
// add to form
$form[] = $radio2;
$form[] = $more_info;
if (!$this->packageInfo || (isset($this->packageInfo['getKeyFrom']) && ComponentbuilderHelper::checkArray($this->packageInfo['getKeyFrom'])))
{
// set required field
$required = 'required="true"';
$required = true;
// does the packages has info
if (!$this->packageInfo)
{
$radio2 = JFormHelper::loadFieldType('radio',true);
// has key
$xml = '<field label="'.JText::_('COM_COMPONENTBUILDER_USE_KEY').'" description="'.JText::_('COM_COMPONENTBUILDER_DOES_THIS_PACKAGE_REQUIRE_A_KEY_TO_INSTALL').'" name="haskey" type="radio" class="btn-group btn-group-yesno" default="1" filter="INT">';
$xml .= '<option value="1">'.JText::_('COM_COMPONENTBUILDER_YES').'</option> <option value="0">'.JText::_('COM_COMPONENTBUILDER_NO').'</option>';
$xml .= "</field>";
// prepare the xml
$license = new SimpleXMLElement($xml);
// set components to form
$radio2->setup($license,1);
$required = ''; // change required field
// get the haskey radio field
$haskey = JFormHelper::loadFieldType('radio',true);
// start haskey xml
$haskeyXML = new SimpleXMLElement('<field/>');
// haskey attributes
$haskeyAttributes = array(
'type' => 'radio',
'name' => 'backup',
'label' => 'COM_COMPONENTBUILDER_USE_KEY',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_DOES_THIS_PACKAGE_REQUIRE_A_KEY_TO_INSTALL',
'default' => '1',
'filter' => 'INT');
// load the haskey attributes
ComponentbuilderHelper::xmlAddAttributes($haskeyXML, $haskeyAttributes);
// set the haskey options
$haskeyOptions = array(
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
// load the haskey options
ComponentbuilderHelper::xmlAddOptions($haskeyXML, $haskeyOptions);
// setup the haskey radio field
$haskey->setup($haskeyXML,1);
// add to form
$form[] = $radio2;
$form[] = $haskey;
// now make required false
$required = false;
}
$text1 = JFormHelper::loadFieldType('text',true);
// add the key
$xml = '<field type="password" label="'.JText::_('COM_COMPONENTBUILDER_KEY').'" description="'.JText::_('COM_COMPONENTBUILDER_THE_KEY_OF_THIS_PACKAGE').'" name="sleutle" autocomplete="false" class="text_area" filter="STRING" hint="add key here" '.$required.' />';
// prepare the xml
$sleutle = new SimpleXMLElement($xml);
// set components to form
$text1->setup($sleutle,'');
// get the sleutle password field
$sleutle = JFormHelper::loadFieldType('password',true);
// start sleutle xml
$sleutleXML = new SimpleXMLElement('<field/>');
// sleutle attributes
$sleutleAttributes = array(
'type' => 'password',
'name' => 'backup',
'label' => 'COM_COMPONENTBUILDER_KEY',
'class' => 'text_area',
'description' => 'COM_COMPONENTBUILDER_THE_KEY_OF_THIS_PACKAGE',
'autocomplete' => 'false',
'filter' => 'STRING',
'hint' => 'COM_COMPONENTBUILDER_ADD_KEY_HERE');
// should this be required
if ($required)
{
$sleutleAttributes['required'] = 'true';
}
// load the sleutle attributes
ComponentbuilderHelper::xmlAddAttributes($sleutleXML, $sleutleAttributes);
// setup the sleutle password field
$sleutle->setup($sleutleXML,'');
// add to form
$form[] = $text1;
$form[] = $sleutle;
}
}
elseif ('vdm_package' === $type && $listObjects = ComponentbuilderHelper::getGithubRepoFileList('jcbGithubPackages', ComponentbuilderHelper::$jcbGithubPackagesUrl.ComponentbuilderHelper::$accessToken))
{
if (ComponentbuilderHelper::checkArray($listObjects))
{
// load the vdm packages if available
$list = JFormHelper::loadFieldType('list',true);
// get the vdm_package list field
$vdm_package = JFormHelper::loadFieldType('list',true);
// start vdm_package xml
$vdm_packageXML = new SimpleXMLElement('<field/>');
// vdm_package attributes
$vdm_packageAttributes = array(
'type' => 'list',
'name' => 'vdm_package',
'label' => 'COM_COMPONENTBUILDER_PACKAGE',
'class' => 'list_class',
'description' => 'COM_COMPONENTBUILDER_SELECT_THE_PACKAGE_TO_IMPORT');
// load the list
$load = false;
// start building componet xml field
$xml = '<field label="Package" description="'.JText::_('COM_COMPONENTBUILDER_SELECT_THE_PACKAGE_TO_IMPORT').'" name="vdm_package" type="list" class="list_class">';
$xml .= '<option value="">'.JText::_('COM_COMPONENTBUILDER__SELECT_PACKAGE_').'</option>';
// load the vdm_package attributes
ComponentbuilderHelper::xmlAddAttributes($vdm_packageXML, $vdm_packageAttributes);
// start the vdm_package options
$vdm_packageOptions = array();
$vdm_packageOptions[''] = 'COM_COMPONENTBUILDER__SELECT_PACKAGE_';
// load vdm_package options from array
foreach($listObjects as $listObject)
{
if (strpos($listObject->path, '.zip') !== false)
{
$xml .= '<option value="'.ComponentbuilderHelper::$jcbGithubPackageUrl.$listObject->path.'">'.$this->setPackageName($listObject->path).'</option>';
$vdm_packageOptions[ComponentbuilderHelper::$jcbGithubPackageUrl.$listObject->path] = $this->setPackageName($listObject->path);
$load = true;
}
}
$xml .= "</field>";
// only load if at least one item was found
if ($load)
{
// prepare the xml
$packages = new SimpleXMLElement($xml);
// set components to form
$list->setup($packages, '');
// set to form
$form[] = $list;
// load the vdm_package options
ComponentbuilderHelper::xmlAddOptions($vdm_packageXML, $vdm_packageOptions);
// setup the vdm_package radio field
$vdm_package->setup($vdm_packageXML,'');
// add to form
$form[] = $vdm_package;
}
}
}