[-] MO : #PSTEST-41 : update ProcessAttachment method

This commit is contained in:
lLefevre
2011-12-20 13:06:28 +00:00
parent 56459ba586
commit 758d9297f1
3 changed files with 43 additions and 14 deletions
@@ -99,11 +99,45 @@
</tr>
</table>
<div class="clear">&nbsp;</div>
<input type="hidden" name="arrayAttachments" id="arrayAttachments" value="{foreach $attach1 as $attach}{$attach.id_attachment},{/foreach}" />
<input type="submit" name="submitAttachments" id="submitAttachments" value="{l s='Update attachments'}" class="button" />
<script type="text/javascript">
displayFlags(languages, id_language, allowEmployeeFormLang);
$(document).ready(function() {
$("#addAttachment").live('click', function() {
$("#selectAttachment2 option:selected").each(function(){
var val = $('#arrayAttachments').val();
var tab = val.split(',');
for (var i=0; i < tab.length; i++)
if (tab[i] == $(this).val())
return false;
$('#arrayAttachments').val(val+$(this).val()+',');
});
return !$("#selectAttachment2 option:selected").remove().appendTo("#selectAttachment1");
});
$("#removeAttachment").live('click', function() {
$("#selectAttachment1 option:selected").each(function(){
var val = $('#arrayAttachments').val();
var tab = val.split(',');
var tabs = '';
for (var i=0; i < tab.length; i++)
if (tab[i] != $(this).val())
{
tabs = tabs+','+tab[i];
$('#arrayAttachments').val(tabs);
}
});
return !$("#selectAttachment1 option:selected").remove().appendTo("#selectAttachment2");
});
$("#product").submit(function() {
$("#selectAttachment1 option").each(function(i) {
$(this).attr("selected", "selected");
});
});
});
</script>
{/if}
@@ -165,20 +165,6 @@
$('#desc-product-newCombination').show();
populate_attrs();
}
else if (btn_name == 'Attachments')
{
$("#addAttachment").live('click', function() {
return !$("#selectAttachment2 option:selected").remove().appendTo("#selectAttachment1");
});
$("#removeAttachment").live('click', function() {
return !$("#selectAttachment1 option:selected").remove().appendTo("#selectAttachment2");
});
$("#product").submit(function() {
$("#selectAttachment1 option").each(function(i) {
$(this).attr("selected", "selected");
});
});
}
else
{
$('#desc-product-newCombination').hide();
@@ -1024,6 +1024,15 @@ class AdminProductsControllerCore extends AdminController
*/
public function postProcess($token = null)
{
if ($this->action == 'attachments')
if ($id = (int)Tools::getValue($this->identifier))
{
$attachments = trim(Tools::getValue('arrayAttachments'), ',');
$attachments_tab = explode(',', $attachments);
if (Attachment::attachToProduct($id, $attachments_tab))
$this->redirect_after = self::$currentIndex.'&id_product='.(int)$id.(isset($_POST['id_category']) ? '&id_category='.(int)$_POST['id_category'] : '').'&conf=4&add'.$this->table.'&action=Attachments&token='.($token ? $token : $this->token);
}
if (!$this->redirect_after)
parent::postProcess(true);
}