[*] BO #PSFV-94 : added class HelperForm
This commit is contained in:
1 parent
b8ffadf7b3
commit
9569eced26
4 files changed
+322
-69
No files matched your search
@@ -0,0 +1,109 @@
|
|||||||
|
{*
|
||||||
|
* 2007-2011 PrestaShop
|
||||||
|
*
|
||||||
|
* NOTICE OF LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||||
|
* that is bundled with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://opensource.org/licenses/afl-3.0.php
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@prestashop.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* DISCLAIMER
|
||||||
|
*
|
||||||
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||||
|
* versions in the future. If you wish to customize PrestaShop for your
|
||||||
|
* needs please refer to http://www.prestashop.com for more information.
|
||||||
|
*
|
||||||
|
* @author PrestaShop SA <contact@prestashop.com>
|
||||||
|
* @copyright 2007-2011 PrestaShop SA
|
||||||
|
* @version Release: $Revision: 8971 $
|
||||||
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*}
|
||||||
|
|
||||||
|
{if $firstCall}
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function() {
|
||||||
|
var id_language = {$defaultFormLanguage};
|
||||||
|
var languages = new Array();
|
||||||
|
{foreach $languages as $k => $language}
|
||||||
|
languages[{$k}] = {
|
||||||
|
id_lang: {$language.id_lang},
|
||||||
|
iso_code: '{$language.iso_code}',
|
||||||
|
name: '{$language.name}'
|
||||||
|
};
|
||||||
|
{/foreach}
|
||||||
|
displayFlags(languages, id_language, {$allowEmployeeFormLang});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<form action="{$current}&submitAdd{$table}=1&token={$token}" method="post">
|
||||||
|
{if $form_id}
|
||||||
|
<input type="hidden" name="id_{$table}" value="{$form_id}" />
|
||||||
|
{/if}
|
||||||
|
<fieldset>
|
||||||
|
{foreach $fields as $key => $field}
|
||||||
|
{if $key == 'legend'}
|
||||||
|
<legend>
|
||||||
|
{if isset($field.image)}<img src="{$field.image}" alt="{$field.title}" />{/if}
|
||||||
|
{$field.title}
|
||||||
|
</legend>
|
||||||
|
{elseif $key == 'input'}
|
||||||
|
{foreach $field as $input}
|
||||||
|
<label>{$input.label} </label>
|
||||||
|
<div class="margin-form">
|
||||||
|
{if $input.type == 'text'}
|
||||||
|
<input type="text" {if isset($input.size)}size="{$input.size}"{/if} name="{$input.name}" value="{$fields_value[$input.name]}" {if isset($input.class)}class="{$input.class}"{/if} />
|
||||||
|
{elseif $input.type == 'select'}
|
||||||
|
<select name="{$input.name}">
|
||||||
|
{foreach $input.options.query AS $option}
|
||||||
|
<option value="{$option[$input.options.id]}" {if $fields_value[$input.name] == $option[$input.options.id]}selected="selected"{/if}>{$option[$input.options.name]}</option>
|
||||||
|
{/foreach}
|
||||||
|
</select>
|
||||||
|
{elseif $input.type == 'radio'}
|
||||||
|
{foreach $input.values as $value}
|
||||||
|
<input type="radio" name="{$input.name}" id="{$value.id}" value="{$value.value}" {if $fields_value[$input.name] == $value.value}checked="checked"{/if}/>
|
||||||
|
<label {if isset($input.class)}class="{$input.class}"{/if} for="{$value.id}"> {$value.label}</label>
|
||||||
|
{/foreach}
|
||||||
|
{elseif $input.type == 'textarea'}
|
||||||
|
<textarea name="{$input.name}" cols="{$input.cols}" rows="{$input.rows}">{$fields_value[$input.name]}</textarea>
|
||||||
|
{/if}
|
||||||
|
{if isset($input.required) && $input.required} <sup>*</sup>{/if}
|
||||||
|
{if isset($input.p)}
|
||||||
|
<p class="clear">
|
||||||
|
{if is_array($input.p)}
|
||||||
|
{foreach $input.p as $p}
|
||||||
|
{$p}<br />
|
||||||
|
{/foreach}
|
||||||
|
{else}
|
||||||
|
{$input.p}
|
||||||
|
{/if}
|
||||||
|
</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/foreach}
|
||||||
|
{elseif $key == 'submit'}
|
||||||
|
<div class="margin-form">
|
||||||
|
<input type="submit" value="{$field.title}" name="submitAdd{$table}" {if isset($field.class)}class="{$field.class}"{/if} />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/foreach}
|
||||||
|
{if $requiredFields}
|
||||||
|
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
|
||||||
|
{/if}
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<br /><br />
|
||||||
|
{if $firstCall}
|
||||||
|
{if $back}
|
||||||
|
<a href="{$back}"><img src="../img/admin/arrow2.gif" />{l s='Back'}</a>
|
||||||
|
{else}
|
||||||
|
<a href="{$current}&token={$token}"><img src="../img/admin/arrow2.gif" />{l s='Back to list'}</a>
|
||||||
|
{/if}
|
||||||
|
<br />
|
||||||
|
{/if}
|
||||||
@@ -33,77 +33,85 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{if count($errors)} {* @todo what is ??? AND $this->_includeContainer *}
|
{if count($errors)} {* @todo what is ??? AND $this->_includeContainer *}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function()
|
$(document).ready(function()
|
||||||
{
|
{
|
||||||
$('#hideError').unbind('click').click(function()
|
$('#hideError').unbind('click').click(function()
|
||||||
{
|
{
|
||||||
$('.error').hide('slow', function (){
|
$('.error').hide('slow', function (){
|
||||||
$('.error').remove();
|
$('.error').remove();
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return false;
|
</script>
|
||||||
});
|
<div class="error">
|
||||||
});
|
<span style="float:right"><a id="hideError" href=""><img alt="X" src="../img/admin/close.png" /></a></span><img src="../img/admin/error2.png" />
|
||||||
</script>
|
{if count($errors) == 1}
|
||||||
<div class="error">
|
{$errors[0]}
|
||||||
<span style="float:right"><a id="hideError" href=""><img alt="X" src="../img/admin/close.png" /></a></span><img src="../img/admin/error2.png" />
|
{else}
|
||||||
{if count($errors) == 1}
|
{$errors|count} {l s='errors'}
|
||||||
{$errors[0]}
|
<br/>
|
||||||
{else}
|
<ol>
|
||||||
{$errors|count} {l s='errors'}
|
{foreach from=$errors item=$error}
|
||||||
<br/>
|
<li>{$error}</li>
|
||||||
<ol>
|
{/foreach}
|
||||||
{foreach from=$errors item=$error}
|
</ol>
|
||||||
<li>{$error}</li>
|
{/if}
|
||||||
{/foreach}
|
</div>
|
||||||
</ol>
|
{/if}
|
||||||
{/if}
|
|
||||||
</div>
|
{if count($informations) && $informations}
|
||||||
|
<div class="hint clear" style="display:block;">
|
||||||
|
{foreach $informations as $info}
|
||||||
|
{$info}
|
||||||
|
{/foreach}
|
||||||
|
</div><br />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{if count($warnings)}
|
{if count($warnings)}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#linkSeeMore').unbind('click').click(function(){
|
$('#linkSeeMore').unbind('click').click(function(){
|
||||||
$('#seeMore').show('slow');
|
$('#seeMore').show('slow');
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
$('#linkHide').show();
|
$('#linkHide').show();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$('#linkHide').unbind('click').click(function(){
|
$('#linkHide').unbind('click').click(function(){
|
||||||
$('#seeMore').hide('slow');
|
$('#seeMore').hide('slow');
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
$('#linkSeeMore').show();
|
$('#linkSeeMore').show();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$('#hideWarn').unbind('click').click(function(){
|
$('#hideWarn').unbind('click').click(function(){
|
||||||
$('.warn').hide('slow', function (){
|
$('.warn').hide('slow', function (){
|
||||||
$('.warn').remove();
|
$('.warn').remove();
|
||||||
|
});
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
});
|
</script>
|
||||||
</script>
|
<div class="warn">
|
||||||
<div class="warn">
|
<span style="float:right">
|
||||||
<span style="float:right">
|
<a id="hideWarn" href=""><img alt="X" src="../img/admin/close.png" /></a>
|
||||||
<a id="hideWarn" href=""><img alt="X" src="../img/admin/close.png" /></a>
|
</span>
|
||||||
</span>
|
<img src="../img/admin/warn2.png" />
|
||||||
<img src="../img/admin/warn2.png" />
|
{if count($warnings) > 1}
|
||||||
{if count($warnings) > 1}
|
{l s='There are'} {count($warnings)} {l s='warnings'}
|
||||||
{l s='There are'} {count($warnings)} {l s='warnings'}
|
{else}
|
||||||
{else}
|
{l s='There is'} {count($warnings)} {l s='warning'}
|
||||||
{l s='There is'} {count($warnings)} {l s='warning'}
|
{/if}
|
||||||
{/if}
|
<span style="margin-left:20px;" id="labelSeeMore">
|
||||||
<span style="margin-left:20px;" id="labelSeeMore">
|
<a id="linkSeeMore" href="#" style="text-decoration:underline">{l s='Click here to see more'}</a>
|
||||||
<a id="linkSeeMore" href="#" style="text-decoration:underline">{l s='Click here to see more'}</a>
|
<a id="linkHide" href="#" style="text-decoration:underline;display:none">{l s='Hide warning'}</a>
|
||||||
<a id="linkHide" href="#" style="text-decoration:underline;display:none">{l s='Hide warning'}</a>
|
</span>
|
||||||
</span>
|
<ul style="display:none;" id="seeMore">
|
||||||
<ul style="display:none;" id="seeMore">
|
{foreach $warnings item=warning}
|
||||||
{foreach $warnings item=warning}
|
<li>{$warning}</li>
|
||||||
<li>{$warning}</li>
|
{/foreach}
|
||||||
{/foreach}
|
</ul>
|
||||||
</ul>
|
</div>
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{$page}
|
{$page}
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ class AdminControllerCore extends Controller
|
|||||||
|
|
||||||
public static $currentIndex;
|
public static $currentIndex;
|
||||||
public $content;
|
public $content;
|
||||||
public $warnings;
|
public $warnings = array();
|
||||||
|
public $informations = array();
|
||||||
|
|
||||||
public $content_only = false;
|
public $content_only = false;
|
||||||
public $layout = 'layout.tpl';
|
public $layout = 'layout.tpl';
|
||||||
@@ -715,6 +716,7 @@ class AdminControllerCore extends Controller
|
|||||||
|
|
||||||
$this->context->smarty->assign('errors', $this->_errors);
|
$this->context->smarty->assign('errors', $this->_errors);
|
||||||
$this->context->smarty->assign('warnings', $this->warnings);
|
$this->context->smarty->assign('warnings', $this->warnings);
|
||||||
|
$this->context->smarty->assign('informations', $this->informations);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->context->smarty->assign('page', $page);
|
$this->context->smarty->assign('page', $page);
|
||||||
@@ -731,6 +733,16 @@ class AdminControllerCore extends Controller
|
|||||||
$this->warnings[] = $msg;
|
$this->warnings[] = $msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add a info message to display at the top of the page
|
||||||
|
*
|
||||||
|
* @param string $msg
|
||||||
|
*/
|
||||||
|
protected function displayInformation($msg)
|
||||||
|
{
|
||||||
|
$this->informations[] = $msg;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign smarty variables for the header
|
* Assign smarty variables for the header
|
||||||
*/
|
*/
|
||||||
@@ -889,7 +901,25 @@ class AdminControllerCore extends Controller
|
|||||||
{
|
{
|
||||||
if ($this->display == 'edit')
|
if ($this->display == 'edit')
|
||||||
{
|
{
|
||||||
$this->content .= $this->displayForm();
|
|
||||||
|
if (!($obj = $this->loadObject(true)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (isset($this->fields_form))
|
||||||
|
{
|
||||||
|
$helper = new HelperForm();
|
||||||
|
$helper::$currentIndex = self::$currentIndex;
|
||||||
|
$helper->token = $this->token;
|
||||||
|
$helper->table = $this->table;
|
||||||
|
$helper->table = $this->table;
|
||||||
|
$helper->id = $obj->id;
|
||||||
|
$helper->fields_value = $this->getFieldsValue($obj);
|
||||||
|
$this->content .= $helper->generateForm($this->fields_form);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
//@TODO à supprimer
|
||||||
|
$this->content .= $this->displayForm();
|
||||||
|
|
||||||
if ($this->tabAccess['view'])
|
if ($this->tabAccess['view'])
|
||||||
{
|
{
|
||||||
if (Tools::getValue('back'))
|
if (Tools::getValue('back'))
|
||||||
@@ -897,8 +927,6 @@ class AdminControllerCore extends Controller
|
|||||||
else
|
else
|
||||||
$this->context->smarty->assign('back', Tools::safeOutput(Tools::getValue(self::$currentIndex.'&token='.$this->token)));
|
$this->context->smarty->assign('back', Tools::safeOutput(Tools::getValue(self::$currentIndex.'&token='.$this->token)));
|
||||||
}
|
}
|
||||||
// move to form.tpl
|
|
||||||
$this->content .= '<br /><br /><a href="'.((Tools::getValue('back')) ? Tools::getValue('back') : self::$currentIndex.'&token='.$this->token).'"><img src="../img/admin/arrow2.gif" /> '.((Tools::getValue('back')) ? $this->l('Back') : $this->l('Back to list')).'</a><br />';
|
|
||||||
}
|
}
|
||||||
else if ($this->display == 'list')
|
else if ($this->display == 'list')
|
||||||
{
|
{
|
||||||
@@ -1288,6 +1316,14 @@ class AdminControllerCore extends Controller
|
|||||||
$this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`');
|
$this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFieldsValue($obj)
|
||||||
|
{
|
||||||
|
foreach ($this->fields_form['input'] as $input)
|
||||||
|
if (empty($this->fields_value[$input['name']]))
|
||||||
|
$this->fields_value[$input['name']] = $this->getFieldValue($obj, $input['name']);
|
||||||
|
return $this->fields_value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return field value if possible (both classical and multilingual fields)
|
* Return field value if possible (both classical and multilingual fields)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* 2007-2011 PrestaShop
|
||||||
|
*
|
||||||
|
* NOTICE OF LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the Open Software License (OSL 3.0)
|
||||||
|
* that is bundled with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://opensource.org/licenses/osl-3.0.php
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@prestashop.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* DISCLAIMER
|
||||||
|
*
|
||||||
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||||
|
* versions in the future. If you wish to customize PrestaShop for your
|
||||||
|
* needs please refer to http://www.prestashop.com for more information.
|
||||||
|
*
|
||||||
|
* @author PrestaShop SA <contact@prestashop.com>
|
||||||
|
* @copyright 2007-2011 PrestaShop SA
|
||||||
|
* @version Release: $Revision: 9194 $
|
||||||
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*/
|
||||||
|
|
||||||
|
class HelperFormCore extends Helper
|
||||||
|
{
|
||||||
|
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
public $first_call = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array of forms fields
|
||||||
|
* Usage :
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected $fields_form = array();
|
||||||
|
|
||||||
|
public $fields_value = array();
|
||||||
|
|
||||||
|
public $table;
|
||||||
|
|
||||||
|
public $token;
|
||||||
|
|
||||||
|
public static $currentIndex;
|
||||||
|
|
||||||
|
public function generateForm($fields_form)
|
||||||
|
{
|
||||||
|
$this->fields_form = $fields_form;
|
||||||
|
|
||||||
|
return $this->displayForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayForm()
|
||||||
|
{
|
||||||
|
$allowEmployeeFormLang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||||
|
if ($allowEmployeeFormLang && !$this->context->cookie->employee_form_lang)
|
||||||
|
$this->context->cookie->employee_form_lang = (int)(Configuration::get('PS_LANG_DEFAULT'));
|
||||||
|
$useLangFromCookie = false;
|
||||||
|
$languages = Language::getLanguages(false);
|
||||||
|
if ($allowEmployeeFormLang)
|
||||||
|
foreach ($languages as $lang)
|
||||||
|
if ($this->context->cookie->employee_form_lang == $lang['id_lang'])
|
||||||
|
$useLangFromCookie = true;
|
||||||
|
if (!$useLangFromCookie)
|
||||||
|
$defaultFormLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
|
||||||
|
else
|
||||||
|
$defaultFormLanguage = (int)($this->context->cookie->employee_form_lang);
|
||||||
|
|
||||||
|
info($this->fields_value);
|
||||||
|
$this->context->smarty->assign(array(
|
||||||
|
'firstCall' => $this->first_call,
|
||||||
|
'current' => self::$currentIndex,
|
||||||
|
'token' => $this->token,
|
||||||
|
'table' => $this->table,
|
||||||
|
'defaultFormLanguage' => $defaultFormLanguage,
|
||||||
|
'languages' => $languages,
|
||||||
|
'allowEmployeeFormLang' => $allowEmployeeFormLang,
|
||||||
|
'form_id' => $this->id,
|
||||||
|
'back' => Tools::getValue('back'),
|
||||||
|
'fields' => $this->fields_form,
|
||||||
|
'fields_value' => $this->fields_value,
|
||||||
|
'requiredFields' => $this->getFieldsRequired()
|
||||||
|
));
|
||||||
|
|
||||||
|
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/form.tpl');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFieldsRequired()
|
||||||
|
{
|
||||||
|
foreach ($this->fields_form['input'] as $input)
|
||||||
|
if (array_key_exists('required', $input) && $input['required'])
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user