[+] BO : #PSFV-94 - AdminProduct form features

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10239 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
mMarinetti
2011-11-17 18:52:54 +00:00
parent 2eb10a760f
commit 5ef065bbca
3 changed files with 99 additions and 370 deletions
@@ -1,270 +0,0 @@
{*
* 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$
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<link href="../css/fileuploader.css" rel="stylesheet" type="text/css">
<script src="../js/fileuploader.js" type="text/javascript"></script>
<script src="../js/jquery/ui/jquery.ui.core.min.js" type="text/javascript"></script>
<script src="../js/jquery/ui/jquery.ui.widget.min.js" type="text/javascript"></script>
<script src="../js/jquery/ui/jquery.ui.progressbar.min.js" type="text/javascript"></script>
<script type="text/javascript" src="../js/admin.js"></script>
<div id="productBox">
{if isset($product_tabs)}
<div class="toolbarBox">
<ul class="cc_button">
{foreach from=$toolbar_btn item=btn key=k}
<li>
<a class="toolbar_btn action-{$k}" href="{$btn.href}" title="{$btn.desc}">
<span class="process-icon-{$k} {$btn.class|default:''}" ></span>{$btn.desc}
</a>
</li>
{/foreach}
</ul>
<script type="text/javascript">
$(document).ready(function(){
$("a.toolbar_btn").click(function(e){
e.preventDefault();
});
});
</script>
{if isset($product)}
<div class="pageTitle">
<h3>{l s='Current product:'}<span id="current_product" style="font-weight: normal;">&nbsp;</span></h3>
</div>
{/if}
</div>
<div class="productTabs">
<ul class="tab">
{foreach $product_tabs key=numStep item=tab}
<li class="tab-row">
<a class="tab-page {if $tab.selected}selected{/if}" id="link-{$tab.id}" href="{$tab.href}">{$tab.name}</a>{*todo href when nojs*}
</li>
{/foreach}
</ul>
</div>
<script type="text/javascript">
var toload = new Array();
var pos_select = {$pos_select};
$(document).ready(function(){
{* submenu binding *}
$(".tab-page").click(function(e){
e.preventDefault();
// currentId is the current producttab id
currentId = $(".productTabs a.selected").attr('id').substr(5);
// id is the wanted producttab id
id = $(this).attr('id').substr(5);
if ($(this).attr("id") != $(".productTabs a.selected").attr('id'))
{
$(".tab-page").removeClass('selected');
$("#product-tab-content-"+currentId).hide();
}
else
{
if (confirm(' {l s='Do you really want to reload the current tab (all modifications will be lost)'}'))
$("#product-tab-content-"+currentId).html();
else
return false;
}
$("#product-tab-content-wait").show();
if ($("#product-tab-content-"+id).hasClass('not-loaded') || $(this).hasClass('selected'))
{
myurl = $(this).attr("href")+"&ajax=1";
$.ajax({
url : myurl,
async : true,
success :function(data)
{
$("#product-tab-content-wait").hide();
$("#product-tab-content-"+id).html(data);
$("#product-tab-content-"+id).removeClass('not-loaded');
$("#product-tab-content-"+id).show();
$("#link-"+id).addClass('selected');
}
});
}
else
{
$("#product-tab-content-"+id).show();
$("#link-"+id).addClass('selected');
}
var languages = new Array();
if (id == 3)
populate_attrs();
if (id == 7)
{
$("#addAttachment").click(function() {
return !$("#selectAttachment1 option:selected").remove().appendTo("#selectAttachment2");
});
$("#removeAttachment").click(function() {
return !$("#selectAttachment2 option:selected").remove().appendTo("#selectAttachment1");
});
$("#product").submit(function() {
$("#selectAttachment1 option").each(function(i) {
$(this).attr("selected", "selected");
});
});
}
});
});
</script>
{***********************************************}
{********** TO CHECK !!!!!!!!!!!!!!! ***********}
<script type="text/javascript">
// <![CDATA[
ThickboxI18nImage = "{l s='Image'}";
ThickboxI18nOf = "{l s='of'}";
ThickboxI18nClose = "{l s='Close'}";
ThickboxI18nOrEscKey = "{l s='(or "Esc")'}";
ThickboxI18nNext = "{l s='Next >'}";
ThickboxI18nPrev = "{l s='< Previous'}";
tb_pathToImage = "../img/loadingAnimation.gif";
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
function toggleVirtualProduct(elt)
{
$("#is_virtual_file_product").hide();
$("#virtual_good_attributes").hide();
if (elt.checked)
{
$('#virtual_good').show('slow');
$('#virtual_good_more').show('slow');
getE('out_of_stock_1').checked = 'checked';
getE('out_of_stock_2').disabled = 'disabled';
getE('out_of_stock_3').disabled = 'disabled';
getE('label_out_of_stock_2').setAttribute('for', '');
getE('label_out_of_stock_3').setAttribute('for', '');
}
else
{
$('#virtual_good').hide('slow');
$('#virtual_good_more').hide('slow');
getE('out_of_stock_2').disabled = false;
getE('out_of_stock_3').disabled = false;
getE('label_out_of_stock_2').setAttribute('for', 'out_of_stock_2');
getE('label_out_of_stock_3').setAttribute('for', 'out_of_stock_3');
}
}
function uploadFile()
{
$.ajaxFileUpload (
{
url:'./uploadProductFile.php',
secureuri:false,
fileElementId:'virtual_product_file',
dataType: 'xml',
success: function (data, status)
{
data = data.getElementsByTagName('return')[0];
var result = data.getAttribute("result");
var msg = data.getAttribute("msg");
var fileName = data.getAttribute("filename")
if(result == "error")
$("#upload-confirmation").html('<p>error: ' + msg + '</p>');
else
{
$('#virtual_product_file').remove();
$('#virtual_product_file_label').hide();
$('#file_missing').hide();
$('#delete_downloadable_product').show();
$('#virtual_product_name').attr('value', fileName);
$('#upload-confirmation').html(
'<a class="link" href="get-file-admin.php?file='+msg+'&filename='+fileName+'">{l s='The file'}&nbsp;"' + fileName + '"&nbsp;{l s='has successfully been uploaded'}</a>' +
'<input type="hidden" id="virtual_product_filename" name="virtual_product_filename" value="' + msg + '" />');
}
}
}
);
}
function uploadFile2()
{
var link = '';
$.ajaxFileUpload (
{
url:'./uploadProductFileAttribute.php',
secureuri:false,
fileElementId:'virtual_product_file_attribute',
dataType: 'xml',
success: function (data, status)
{
data = data.getElementsByTagName('return')[0];
var result = data.getAttribute("result");
var msg = data.getAttribute("msg");
var fileName = data.getAttribute("filename");
if(result == "error")
$("#upload-confirmation2").html('<p>error: ' + msg + '</p>');
else
{
$('#virtual_product_file_attribute').remove();
$('#virtual_product_file_label').hide();
$('#file_missing').hide();
$('#delete_downloadable_product_attribute').show();
$('#virtual_product_name_attribute').attr('value', fileName);
$('#upload-confirmation2').html(
'<a class="link" href="get-file-admin.php?file='+msg+'&filename='+fileName+'">{l s='The file'}&nbsp;"' + fileName + '"&nbsp;{l s='has successfully been uploaded'}</a>' +
'<input type="hidden" id="virtual_product_filename_attribute" name="virtual_product_filename_attribute" value="' + msg + '" />');
link = $("#delete_downloadable_product_attribute").attr('href');
$("#delete_downloadable_product_attribute").attr('href', link+"&file="+msg);
}
}
}
);
}
//]]>
</script>
<form action="{$form_action}" method="post" enctype="multipart/form-data" name="product" id="product">
{$draft_warning}
<input type="hidden" name="id_product" value="{$id_product}" />
<input type="hidden" name="tabs" id="tabs" value="0" />
<div class="tab-pane" id="tabPane1">
<div id="product-tab-content-wait" style="display:none" >{l s='loading ...'}</div>
{if !$newproduct}
{foreach $product_tabs key=numStep item=tab}
<div id="product-tab-content-{$tab.id}" class="{if !$tab.selected}not-loaded{/if} product-tab-content" {if !$tab.selected}style="display:none"{/if}>
{if $tab.selected}{$content}{/if}
</div>
{/foreach}
{else}{* @todo : this is a temporary fix*}
<div id="product-tab-content-1" class="product-tab-content">{$content}</div>
{/if}
</div>
<input type="hidden" name="id_product_attribute" id="id_product_attribute" value="0" />
</form>
</div>
<br/>
<a href="{$link->getAdminLink('AdminCatalog')}"><img src="../img/admin/arrow2.gif" />{l s='Back to list'}</a><br/>
{else}
{$content}
{/if}
@@ -0,0 +1,75 @@
<table cellpadding="5">
<tr>
<td colspan="2">
<b>{l s='Assign features to this product:'}</b><br />
<ul style="margin: 10px 0 0 20px;">
<li>{l s='You can specify a value for each relevant feature regarding this product, empty fields will not be displayed.'}</li>
<li>{l s='You can either set a specific value, or select among existing pre-defined values you added previously.'}</li>
</ul>
</td>
</tr>
</table>
<div class="separation"></div><br />
<table border="0" cellpadding="0" cellspacing="0" class="table" style="width:900px;">
<tr>
<th>{l s='Feature'}</td>
<th style="width:30%">{l s='Pre-defined value'}</td>
<th style="width:40%"><u>{l s='or'}</u> {l s='Customized value'}</td>
</tr>
</table>
{foreach from=$available_features item=available_feature}
<table cellpadding="5" style="width: 900px; margin-top: 10px">
<tr>
<td>{$available_feature.name}</td>
<td style="width: 30%">
{if sizeof($available_feature.featureValues)}
<select id="feature_{$available_feature.id_feature}_value" name="feature_{$available_feature.id_feature}_value"
onchange="$('.custom_{$available_feature.id_feature}_').val('');">
<option value="0">---&nbsp;</option>
{foreach from=$available_feature.featureValues item=value}
<option value="{$value.id_feature_value}"{if $available_feature.current_item == $value.id_feature_value}selected="selected"{/if} >
{$value.value|truncate:40}&nbsp;
</option>
{/foreach}
</select>
{else}
<input type="hidden" name="feature_{$available_feature.id_feature}_value" value="0" />
<span style="font-size: 10px; color: #666;">{l s='N/A'} -
<a href="{$link->getAdminLink('AdminFeatures')}&amp;addfeature_value&id_feature={$available_feature.id_feature}"
style="color: #666; text-decoration: underline;">{l s='Add pre-defined values first'}</a>
</span>
{/if}
</td>
<td style="width:40%" class="translatable">
{foreach from=$languages item=language}
<div class="lang_{$language.id_lang}" style="{if $language.id_lang != $default_form_language}display:none;{/if}float: left;">
<textarea class="custom_{$available_feature.id_feature}_" name="custom_{$available_feature.id_feature}_{$language.id_lang}" cols="40" rows="1"
onkeyup="if (isArrowKey(event)) return ;$('#feature_{$available_feature.id_feature}_value').val(0);" >{$available_feature.val[$language.id_lang].value|htmlentitiesUTF8|default:""}</textarea>
</div>
{/foreach}
</td>
</tr>
{foreachelse}
<tr><td colspan="3" style="text-align:center;">{l s='No features defined'}</td></tr>
{/foreach}
<tr>
<td style="height: 50px; text-align: center;" colspan="3">
<input type="submit" name="submitProductFeature" id="submitProductFeature" value="{l s='Save modifications'}" class="button" />
</td>
</tr>
</table>
<div class="separation"></div>
<div style="text-align:center;">
<a href="{$link->getAdminLink('AdminFeatures')}&amp;addfeature" onclick="return confirm('{l s='You will lose all modifications not saved, you may want to save modifications first?' js=1}');">
<img src="../img/admin/add.gif" alt="new_features" title="{l s='Add a new feature'}" />&nbsp;{l s='Add a new feature'}
</a>
</div>
<script type="text/javascript">
displayFlags(languages, id_language, allowEmployeeFormLang);
</script>
+24 -100
View File
@@ -1837,7 +1837,7 @@ if (false)
$token = Tools::encrypt('PreviewProduct'.$product->id);
if (strpos($preview_url, '?') === false)
$preview_url .= '?';
$preview_url = ($this->context->link->getProductLink($this->getFieldValue($product, 'id'), $this->getFieldValue($product, 'link_rewrite', $this->_defaultFormLanguage), Category::getLinkRewrite($this->getFieldValue($product, 'id_category_default'), $this->context->language->id)));
$preview_url = ($this->context->link->getProductLink($this->getFieldValue($product, 'id'), $this->getFieldValue($product, 'link_rewrite', $this->default_form_language), Category::getLinkRewrite($this->getFieldValue($product, 'id_category_default'), $this->context->language->id)));
if (!$product->active)
{
$admin_dir = dirname($_SERVER['PHP_SELF']);
@@ -3161,119 +3161,43 @@ if (false)
{
if (!Feature::isFeatureActive())
{
$this->tpl_form_vars['custom_form'] = '';
$this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').' <a href="index.php?tab=AdminPerformance&token='.Tools::getAdminTokenLite('AdminPerformance').'#featuresDetachables">'.$this->l('Performances').'</a>');
return;
}
$content = '';
$data = $this->context->smarty->createData();
if ($obj->id)
{
$feature = Feature::getFeatures($this->context->language->id);
$ctab = '';
foreach ($feature as $tab)
$ctab .= 'ccustom_'.$tab['id_feature'].'¤';
$ctab = rtrim($ctab, '¤');
$features = Feature::getFeatures($this->context->language->id);
$content .= '
<table cellpadding="5">
<tr>
<td colspan="2">
<b>'.$this->l('Assign features to this product:').'</b><br />
<ul style="margin: 10px 0 0 20px;">
<li>'.$this->l('You can specify a value for each relevant feature regarding this product, empty fields will not be displayed.').'</li>
<li>'.$this->l('You can either set a specific value, or select among existing pre-defined values you added previously.').'</li>
</ul>
</td>
</tr>
</table>
<div class="separation"></div><br />';
// Header
$nb_feature = Feature::nbFeatures($this->context->language->id);
$content .= '
<table border="0" cellpadding="0" cellspacing="0" class="table" style="width:900px;">
<tr>
<th>'.$this->l('Feature').'</td>
<th style="width:30%">'.$this->l('Pre-defined value').'</td>
<th style="width:40%"><u>'.$this->l('or').'</u> '.$this->l('Customized value').'</td>
</tr>';
if (!$nb_feature)
$content .= '<tr><td colspan="3" style="text-align:center;">'.$this->l('No features defined').'</td></tr>';
$content .= '</table>';
// Listing
if ($nb_feature)
foreach ($features as $k => $tab_features)
{
$content .= '
<table cellpadding="5" style="width: 900px; margin-top: 10px">';
$features[$k]['current_item'] = false;
$features[$k]['val'] = array();
foreach ($feature as $tab_features)
{
$current_item = false;
$custom = true;
foreach ($obj->getFeatures() as $tab_products)
if ($tab_products['id_feature'] == $tab_features['id_feature'])
$current_item = $tab_products['id_feature_value'];
$custom = true;
foreach ($this->object->getFeatures() as $tab_products)
if ($tab_products['id_feature'] == $tab_features['id_feature'])
$features[$k]['current_item'] = $tab_products['id_feature_value'];
$featureValues = FeatureValue::getFeatureValuesWithLang($this->context->language->id, (int)$tab_features['id_feature']);
$features[$k]['featureValues'] = FeatureValue::getFeatureValuesWithLang($this->context->language->id, (int)$tab_features['id_feature']);
if (sizeof($features[$k]['featureValues']))
foreach ($features[$k]['featureValues'] as $value)
if ($features[$k]['current_item'] == $value['id_feature_value'])
$custom = false;
$content .= '
<tr>
<td>'.$tab_features['name'].'</td>
<td style="width: 30%">';
if (sizeof($featureValues))
{
$content .= '
<select id="feature_'.$tab_features['id_feature'].'_value" name="feature_'.$tab_features['id_feature'].'_value"
onchange="$(\'.custom_'.$tab_features['id_feature'].'_\').val(\'\');">
<option value="0">---&nbsp;</option>';
foreach ($featureValues as $value)
{
if ($current_item == $value['id_feature_value'])
$custom = false;
$content .= '<option value="'.$value['id_feature_value'].'"'.(($current_item == $value['id_feature_value']) ? ' selected="selected"' : '').'>'.substr($value['value'], 0, 40).(Tools::strlen($value['value']) > 40 ? '...' : '').'&nbsp;</option>';
}
$content .= '</select>';
}
else
$content .= '<input type="hidden" name="feature_'.$tab_features['id_feature'].'_value" value="0" /><span style="font-size: 10px; color: #666;">'.$this->l('N/A').' - <a href="index.php?tab=AdminFeatures&addfeature_value&id_feature='.(int)$tab_features['id_feature'].'&token='.Tools::getAdminToken('AdminFeatures'.(int)(Tab::getIdFromClassName('AdminFeatures')).(int)$this->context->employee->id).'" style="color: #666; text-decoration: underline;">'.$this->l('Add pre-defined values first').'</a></span>';
$content .= '
</td>
<td style="width:40%" class="translatable">';
$tab_customs = ($custom ? FeatureValue::getFeatureValueLang($current_item) : array());
foreach ($this->_languages as $language)
$content .= '
<div class="lang_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->default_form_language ? 'block' : 'none').'; float: left;">
<textarea class="custom_'.$tab_features['id_feature'].'_" name="custom_'.$tab_features['id_feature'].'_'.$language['id_lang'].'" cols="40" rows="1"
onkeyup="if (isArrowKey(event)) return ;$(\'#feature_'.$tab_features['id_feature'].'_value\').val(0);" >'.htmlentities(Tools::getValue('custom_'.$tab_features['id_feature'].'_'.$language['id_lang'], FeatureValue::selectLang($tab_customs, $language['id_lang'])), ENT_COMPAT, 'UTF-8').'</textarea>
</div>';
$content .= '
</td>
</tr>';
}
$content .= '
<tr>
<td style="height: 50px; text-align: center;" colspan="3"><input type="submit" name="submitProductFeature" id="submitProductFeature" value="'.$this->l('Save modifications').'" class="button" /></td>
</tr>';
if($custom)
$features[$k]['val'] = FeatureValue::getFeatureValueLang($features[$k]['current_item']);
}
$content .= '</table>
<div class="separation"></div>
<div style="text-align:center;">
<a href="index.php?tab=AdminFeatures&addfeature&token='.Tools::getAdminToken('AdminFeatures'.(int)(Tab::getIdFromClassName('AdminFeatures')).(int)$this->context->employee->id).'" onclick="return confirm(\''.$this->l('You will lose all modifications not saved, you may want to save modifications first?', __CLASS__, true, false).'\');"><img src="../img/admin/add.gif" alt="new_features" title="'.$this->l('Add a new feature').'" />&nbsp;'.$this->l('Add a new feature').'</a>
</div>';
}
else
$content .= '<b>'.$this->l('You must save this product before adding features').'.</b>';
$content .= '<script type="text/javascript">
displayFlags(languages, id_language, allowEmployeeFormLang);
</script>';
$this->tpl_form_vars['custom_form'] = $content;
$data->assign('available_features', $features);
$data->assign('product', $obj);
$data->assign('link', $this->context->link);
$data->assign('languages', $this->_languages);
$data->assign('default_form_language', $this->default_form_language);
$this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch();
}
public function ajaxProcessProductQuantity()