this.setBreadcrumb = function() { BackOffice.Breadcrumb .reset() .add('Catalogue','/ec-catalogue/index.html') .add('{$fAction} un produit','/ec-catalogue/add-product.html'); } //---------------------------------------------------------------------------------------------------- this.addEvent('load', function() { this.setBreadcrumb(); // on initialise les différents variable; this.initVariable(); // on récupére les ids des catégories this.ids = this.database.get('ids'); // Application des visuels s'il y en a (modification de produit) var visuals = this.database.get('visuals'); if(visuals) { this.FileChoosed.bind(this,[visuals])(); } // Application des produits associés (modification de produit) var assocsIDS = this.database.get('assocsIDS'); if(assocsIDS) { this.listAssocProduct = assocsIDS; } // Application des combinaisons de critères s'il y en a (modification de produit) var combis = this.database.get('combis'); if(combis) { // $P('ec-catalogue','modifier').runner.getInfos().combinaison_criteria_list this.listCombinaison = []; combis.each(function(combi) { this.afficheCombi.bind(this,[combi])(); this.listCombinaison[this.iCombinaison] = combi; this.iCombinaison++; }.bind(this)); this.resetFormCombi(); } {if $ecommerce.mode not like catalog testCommerce} // on ajoute les calendrier sur les bons champs this.addCalendar(); {end testCommerce} // Ajout de l'évement lors d'une selection de critère this.addEventCriteria(); // ajout de l'événement sur le boutton "Ajouter" et "Supprimer" une combinaison de critére this.addEventButtonCombinaison(); // Ajouter un evénement sur le boutton "Enregistrer le combinaison de critère" this.addEventSaveCriteria(); // on ajoute les évenements le check des catégories this.addEventCategorie(); // on affiche la boite de dialog si l'utilisateur clique sur annuler this.addMsgCancel(); // on ajoute l'evénement sur le click du boutton "Créer la fiche produit" this.addEventEnregistrer(); // ajout de l'événement sur le boutton "Télécharger de nouvelles images" $W('upload-picture').addEvent('click', function(){ $bo.historyManager.go('bibliotheque/envoyer.html?cat=2&dir=0'); }); // ajout de l'événement lorsqu'un fichier est selectionné dans le filechooser $W('chooser-images-gallery').addEvent('choosed', this.FileChoosed.bind(this)); // ajout de l'événement sur le boutton de suppression des images selectionné this.addEventButtonDeleteFile(); // ajout de l'événement lorsque l'on selectionne tout les fichiers this.addEventAllFiles(); // Génére la liste des images de pour les critères lors du changement de tab this.addEventTabs(); // Modifie le prix final lors d'un changement de champ this.addEventPrice(); // Charge les produits lors du changement de catégorie dans les produits associé this.addEventCategorieAssocProd(); }); //---------------------------------------------------------------------------------------------------- this.addEvent('focus', this.setBreadcrumb.bind(this)); //---------------------------------------------------------------------------------------------------- // Avant de fermer on demande la confirmation this.addEvent('closing', function() { // Annuler la fermeture de la page this.cancelClose(); // si la position à changer if(!this.productEmpty()) { var msg = new BackOffice.Alert(); msg.addEvent('onAccept', function() { if($P('ec-catalogue','index')!=null) $P('ec-catalogue','index').refresh('time='+time(), false); this.close(true); }.bind(this)); // ouvre la boite de dialogue stylééééé msg.ask('{$lang.common.closeWithoutRecording}', '{$lang.ecommerce.backoffice.closeWithoutRecording}'); } else { this.close(true); } }); //---------------------------------------------------------------------------------------------------- this.initVariable = function() { this.isNew = this.database.get('isNew') == 1 ? true : false; this.listCriteriaValue = {}; this.listCombinaison=[]; this.filesList = {}; this.listAssocProduct = []; this.iCombinaison = 0; } //---------------------------------------------------------------------------------------------------- // Verification du formulaire : si non vide this.productEmpty = function () { if(this.$W('name')!=null && this.$W('name').getValue().trim() != '') return false; if(this.$W('prix_ht')!=null && this.$W('prix_ht').getValue().trim() != '') return false; if(this.$W('prix_ttc')!=null && this.$W('prix_ttc').getValue().trim() != '') return false; if(tinyMCE.get('fiche')!=null && tinyMCE.getContent('fiche').trim() != '') return false; return true; } //---------------------------------------------------------------------------------------------------- this.addEventCategorie = function() { this.$W('cat-none').addEvent('check', function(){ this.$W('categorie').uncheckAll(); }.bind(this)); this.$W('categorie').addEvent('check', function() { this.$W('cat-none').check(false); }.bind(this)); } //---------------------------------------------------------------------------------------------------- this.addMsgCancel = function() { this.$W('btn-cancel').addEvent('click', function(){ this.close(); }.bind(this)); } //---------------------------------------------------------------------------------------------------- this.addEventEnregistrer = function() { this.$W('btn-save').addEvent('click', this.save.bind(this)); } //---------------------------------------------------------------------------------------------------- this.getInfos = function() { var infos = {}; infos['name'] = $W('name').getValue(); infos['on_line'] = $W('on_line').getValue(); infos['brand'] = $$('select[name=brand]')[0].value; infos['reference'] = $W('ref').getValue(); infos['weight'] = $W('poids').getValue(); infos['ttc_price'] = $W('prix_ttc').getValue(); infos['description'] = base64_encode($('description').value); infos['categories'] = $W('categorie').getValues(); infos['files_list'] = this.filesList; infos['combinaison_criteria_list'] = this.listCombinaison; infos['meta_title'] = $W('meta_title').getValue(); infos['meta_keyword'] = $W('meta_keyword').getValue(); infos['meta_description'] = $W('meta_description').getValue(); infos['fiche'] = base64_encode(tinyMCE.getContent('fiche')); infos['associated_products'] = this.listAssocProduct; infos['pid'] = {$pid}; {if $ecommerce.mode not like catalog promo} infos['reduce'] = $W('reduce').getValue(); infos['reduce_unite'] = $W('reduce_unite').getValue(); infos['reduce_date_debut'] = $W('reduce_date_debut').getValue(); infos['reduce_date_fin'] = $W('reduce_date_fin').getValue(); infos['reduce_limit'] = null; //$W('reduce_limit').getValue(); infos['pr_stock_value'] = $W('pr_stock_value').getValue(); infos['pr_stock_unite'] = $('pr_stock_unite').value; {else promo} infos['reduce'] = 0; infos['reduce_unite'] = 0; infos['reduce_date_debut'] = 0; infos['reduce_date_fin'] = 0; infos['reduce_limit'] = 0; infos['pr_stock_value'] = 0; infos['pr_stock_unite'] = 0; {end promo} // visuel par défaut var val = 0; inputs = $$('input[name=default]'); if(inputs.length>0) { inputs.each(function(inp) { if(inp.checked) { val = inp.value; } }); } infos['defaultVisual'] = val; // Flags de produit infos['flags'] = []; var flags = this.database.get('flags'); if(flags && flags.length>0) { for(var i=0; iVérifiez votre connexion Internet.'); }); remote.call(); } else { new BackOffice.Alert().notice('Enregistrement de la fiche produit','Vous devez spécifier au minimum le nom, le prix et la description du produit.') return true; } } //---------------------------------------------------------------------------------------------------- this.addCalendar = function() { //* new DatePicker('.date_toggled', { pickerClass: 'datepicker_vista', allowEmpty: true, toggleElements: '.date_toggler', days : [$L.date.Sun, $L.date.Mon, $L.date.Tue, $L.date.Wed, $L.date.Thu, $L.date.Fri, $L.date.Sat], months : [$L.date.Jan, $L.date.Feb, $L.date.Mar, $L.date.Apr, $L.date.May, $L.date.Jun, $L.date.Jul, $L.date.Aug, $L.date.Sep, $L.date.Oct, $L.date.Nov, $L.date.Dec] }); //*/ } //---------------------------------------------------------------------------------------------------- this.addEventCriteria = function() { var selectCriterionField = $$('select[name=critere]')[0]; var selectValueField = $$('select[name=critere_value]')[0]; if(selectCriterionField == null || selectValueField == null) { new BackOffice.Alert().error('Structure incorrect','Merci de vérifier votre structure HTML.'); return false; } selectCriterionField.addEvent('change', function(){ selectValueField.disabled = "disabled"; // Si on selectionne un critere alors on recherche une valeur if(selectCriterionField.value.toInt() > 0) { // on créer la remote var remote = new Remote({ name:'criteria' , command:'GetByCriterion' , params:{ 'cid':selectCriterionField.value.toInt() } }); // ** // remote.addEvent('complete', function(r){ selectValueField.disabled = ""; // on supprime tout les valeurs déjà inserer selectValueField.getElements('option').each(function(option) { option.dispose(); }); // on ajoute les valeurs par défaut var t = selectCriterionField.options[selectCriterionField.selectedIndex].get('text').replace(/[\s\-]+/g,''); selectValueField.adopt(new Element('option', {'value': 0, 'html':'-- '+t+' --', 'disabled':'disabled'})); // unique si la remote à réussi if(r.getResponseCode() == 1) { // on insert les valeurs dans le select r.getResponseData().each(function(value) { selectValueField.adopt(new Element('option', { 'value':value.vid ,'html':value.valeur /*+ ' (' + ( (value['mod_valeur']==null) ? 0 : value['mod_valeur'] ) + ' €)'*/ })); }); } }); // ** // remote.addEvent('error', function(){ new BackOffice.Alert().error('Erreur internet','Erreur pendant la communication avec le serveur Web.
Vérifiez votre connexion Internet.'); }); // ** // remote.call(); } }.bind(this)) } //---------------------------------------------------------------------------------------------------- this.addEventButtonCombinaison = function() { if($W('add_combinaison') == null || $W('remove_combinaison') == null) { new BackOffice.Alert().error('Structure incorrect','Merci de vérifier votre structure HTML.'); return false; } $W('add_combinaison').addEvent('click', function(){ var selectCriterionField = $$('select[name=critere]')[0]; var selectValueField = $$('select[name=critere_value]')[0]; var modValeur = $('mod_valeur'); var selectCombinaisonField = $$('select[name=critere_combinaison]')[0]; if(typeof this.listCriteriaValue[selectCriterionField.value] == "undefined") { this.listCriteriaValue[selectCriterionField.value] = { 'criterion':{ 'cid' : selectCriterionField.value, 'text': selectCriterionField.options[selectCriterionField.selectedIndex].get('html') }, 'value':{ 'vid' : selectValueField.value, 'text': selectValueField.options[selectValueField.selectedIndex].get('html') } }; selectCombinaisonField.adopt(new Element('option', { 'value': selectCriterionField.value + '-' + selectValueField.value, 'text' : this.listCriteriaValue[selectCriterionField.value].criterion.text + ' : ' + this.listCriteriaValue[selectCriterionField.value].value.text })); D(this.listCriteriaValue); } else { new BackOffice.Alert().notice('Critère existant','Le critère choisi a déjà été ajouté à la liste.'); } }.bind(this)); // ** // $W('remove_combinaison').addEvent('click', function(){ var selectCombinaisonField = $$('select[name=critere_combinaison]')[0]; delete this.listCriteriaValue[selectCombinaisonField.value.split('-')[0]]; selectCombinaisonField.options[selectCombinaisonField.selectedIndex].dispose(); /* if(selectCombinaisonField.options.length>0) { selectCombinaisonField.options.each(function(op) { op.dispose(); }); } */ }.bind(this)); } //---------------------------------------------------------------------------------------------------- this.FileChoosed = function(files) { if(files.length <=0) return; if($$('#fileListing div.filelist')[0].getElement('p') != null) $$('#fileListing div.filelist')[0].getElement('p').addClass('disabled'); $$('div.button.disabled').removeClass('disabled'); var hightlight = false; files.each(function(file){ if(typeof this.filesList[file.id.toInt()] == "undefined") { var divL = new Element('div', {'id': 'file-'+file.id ,'class':'line' + ( hightlight ? ' hightlight':'' ) }); var divA = new Element('div', {'class':'action'}); divA.adopt( new Widget.checkbox({'label':' ', 'name':'files', 'value':file.id, 'checked':0}) ) divL.adopt( divA ); var divP = new Element('div', {'class':'apercu'}); divP.adopt( new Element('img', { 'src': wwwroot+'/temp/uploads/'+file.upname ,'class' : 'radius-2px' }) ); divL.adopt(divP); divL.adopt( new Element('div', {'class':'taille', 'html': convertSize((file.size==false) ? 0 : file.size.toInt())}) ); var divD = new Element('div', {'class': 'default-picture'}); divD.adopt( new Element('input', {'type':'radio', 'name':'default', 'id':'default', 'value':file.id , 'checked':((typeof file.def != 'undefined' && file.def==1) ?'checked':'') }) ); divL.adopt( divD ); divL.adopt( new Element('div', {'class':'element', 'html':file.filename}) ) $$('#fileListing div.filelist')[0].adopt(divL); this.filesList[file.id.toInt()] = file; hightlight = !hightlight; } }.bind(this)); } //---------------------------------------------------------------------------------------------------- this.addEventAllFiles = function() { $W('all-file').addEvent('check', function() { if($W('files')!= null) $W('files').checkAll(); }); $W('all-file').addEvent('uncheck', function() { if($W('files')!=null) $W('files').uncheckAll(); }); } //---------------------------------------------------------------------------------------------------- this.addEventButtonDeleteFile = function() { $W('delete-file').addEvent('click', function(){ if($W('files') == null) return; var ids = $W('files').getValues(); $each(ids, function(fileid){ if($('file-'+fileid) != null) { $('file-'+fileid).dispose(); } delete this.filesList[fileid.toInt()]; }.bind(this)); $W('all-file').check(false); if(length(this.filesList) <= 0) { $$('div.button').addClass('disabled'); $$('#fileListing div.filelist')[0].getElement('p').removeClass('disabled'); } }.bind(this)) } //---------------------------------------------------------------------------------------------------- this.addEventTabs = function() { $W('tabProduct').addEvent('change', function(tab){ if( tab.retrieve('number').toInt() == 3) { this.refreshPhoto(); } }.bind(this)) } //---------------------------------------------------------------------------------------------------- this.refreshPhoto = function() { var tdPhoto = $$('tr.assoc_image td')[0]; if(tdPhoto != null) { tdPhoto.getElements('div').each(function(div){ div.dispose(); }); $each(this.filesList, function(file){ var div = new Element('div', {'class':'photo', 'id':'visuel-'+file.id}); div.adopt( new Widget.radio({'label':' ', 'name':'visualValue', 'value':file.id}) ); div.adopt( new Element('img', {'src':wwwroot+'/temp/uploads/'+file.upname, 'class':'radius-2px'}) ); tdPhoto.adopt(div); }.bind(this)); } } //---------------------------------------------------------------------------------------------------- this.addEventPrice = function() { $W('prix_ttc').addEvent('blur', this.calculPrice.bind(this)); {if $ecommerce.mode not like catalog test} $W('reduce').addEvent('blur', this.calculPrice.bind(this)); $W('reduce_unite').addEvent('change', this.calculPrice.bind(this)); {end test} } //---------------------------------------------------------------------------------------------------- this.calculPrice = function() { var prix_final = $W('prix_ttc').getValue().toFloat(); if($W('reduce') && $W('reduce').getValue().toFloat() > 0) { if($W('reduce_unite').getValue() == 'pourcent') prix_final = prix_final - ( ( $W('reduce').getValue().toFloat() * prix_final ) / 100 ); else prix_final = prix_final - $W('reduce').getValue().toFloat(); } if(!isNaN(prix_final)) $W('prix_vente').setValue( prix_final.round(2) + '€' ); else $W('prix_vente').setValue(''); } //---------------------------------------------------------------------------------------------------- this.addEventSaveCriteria = function() { $W('save_criteria').addEvent('click', this.saveCriteria.bind(this)); } //---------------------------------------------------------------------------------------------------- this.saveCriteria = function() { var Combi = {}; Combi.criteria = []; if($$('select[name=critere_combinaison]')[0].options.length <= 0){ (new BackOffice.Alert()).warn('Critère obligatoire', 'Veuillez choisir un critère au min.'); return false; } $each(( $$('select[name=critere_combinaison]')[0].options ),function(option){ Combi.criteria.push({'ids':option.get('value'), 'text':option.get('html')}); }); Combi.listCriteriaValue = this.listCriteriaValue; Combi.modValeur = ($('mod_valeur')) ? $('mod_valeur').value.toString().toFloat() : 0; Combi.stock = { value:0 , unity:0, label:'' } if($W('stock_valeur')) { Combi.stock.value = $W('stock_valeur').getValue().toFloat(); Combi.stock.unity = $$('select[name=stock_unite]')[0].get('value'); Combi.stock.label = $$('select[name=stock_unite]')[0].options[$$('select[name=stock_unite]')[0].selectedIndex].get('html'); } Combi['default'] = $W('criteria_default').checked(); Combi.visual = 0; $$('input[name=visualValue]').each(function(radio){ if(radio.checked) Combi.visual = radio.get('value'); }); if(!this.combinaisonExists(Combi)){ this.listCombinaison[this.iCombinaison]= Combi; this.afficheCombi(Combi); this.resetFormCombi(); this.iCombinaison++; } } //---------------------------------------------------------------------------------------------------- this.resetFormCombi = function() { $$('select[name=critere]')[0].selectedIndex = 0; $$('select[name=critere_value]')[0].selectedIndex = 0; if($('mod_valeur')) $('mod_valeur').value = ''; if($W('stock_valeur')) { $W('stock_valeur').setValue(''); $$('select[name=stock_unite]')[0].selectedIndex = 0; } $W('criteria_default').check(false); $$('input[name=visualValue]').each(function(radio){ radio.checked = false; }); tab = $$('select[name=critere_combinaison] option'); for(var i=0; i'); // Visuel combinaison thumb = (typeof this.filesList[Combi.visual] != 'undefined') ? wwwroot+'/temp/uploads/'+this.filesList[Combi.visual].upname : wwwroot+'/temp/thumbnails/default.jpg'; tr.adopt( new Element('td', {'class':'image', 'html': ''}) ); // Liste des critrères et valeurs de la combinaison tr.adopt( new Element('td', {'class':'combi', 'html':html}) ); // Stock de la combinaison {if $ecommerce.mode not like catalog testCommerce} stock = (isNaN(Combi.stock.value)||Combi.stock.value==-1||Combi.stock.value==0) ? 'Infini' : Combi.stock.value.toInt()+' '+Combi.stock.label; tr.adopt( new Element('td', {'class':'qte', 'html': stock}) ); {end testCommerce} // Combinaison par défaut var defaut = ''; tr.adopt( new Element('td', {'class':'default', 'html':defaut}) ); // Supplément if(Combi.modValeur && Combi.modValeur.toFloat() > 0) tr.adopt( new Element('td', {'class':'default', 'html': Combi.modValeur+' €' }) ); else tr.adopt( new Element('td', {'class':'default', 'html': '-' }) ); // Actions var widget = new Widget.button({'name':'supp', 'rel':this.iCombinaison, 'icon':'{$wwwroot}/{$system.iconPath}/no-10px.png', 'small':1}); tr.adopt( new Element('td', {'class':'action'}).adopt( widget ) ); // Ajout des actions de boutons var i = this.iCombinaison; widget.addEvent('click', function() { this.deleteLineCriteria(i); }.bind(this)); // Finalisation $$('.productCriteriaSaved')[0].adopt(tr); } //---------------------------------------------------------------------------------------------------- this.deleteLineCriteria = function(iCombi) { if( $('combi-'+iCombi) != null ) { $('combi-'+iCombi).dispose(); delete this.listCombinaison[iCombi]; this.listCombinaison = this.listCombinaison.clean(); } } //---------------------------------------------------------------------------------------------------- this.addEventCategorieAssocProd = function () { $W('categorie-prod-assoc').addEvent('change', function() { var remote = new Remote({ name:'commerce' , command:'getProductsByCategorie' , params:{ 'catid':$W('categorie-prod-assoc').getValue() } }); remote.addEvent('complete', function(r){ if(r.getResponseCode()==1){ $$('#product-assoc-list > div > p')[0].setStyle('display', 'none'); if($$('#product-assoc-list > div > ul').length > 0) { $$('#product-assoc-list > div > ul').dispose(); } var ul = new Element('ul'); r.getResponseData().each(function(prod){ var li = new Element('li'); li.adopt( new Widget.checkbox({ 'label':prod.name , 'name':'produit' , 'value':prod.id , 'checked': (this.listAssocProduct.contains(prod.id) ? 1 : 0) })); ul.adopt(li); }.bind(this)); $$('#product-assoc-list > div')[0].adopt(ul); if($W('produit') != null) { $W('produit').addEvent('check', function(widget) { this.addAssociateProduct( widget.getValue() ); }.bind(this)); $W('produit').addEvent('uncheck', function(widget) { this.removeAssociateProduct( widget.getValue() ); }.bind(this)); /* $W('produit').addEvent('change', function() { W(this.listAssocProduct); }.bind(this)); //*/ } } else { (new BackOffice.Alert()).error('Récupération des produits', 'Impossible de récupérer la liste des produits'); return false; } }.bind(this)); remote.call(); }.bind(this)); } //---------------------------------------------------------------------------------------------------- this.addAssociateProduct = function(prod_id) { if(!this.listAssocProduct.contains(prod_id)) { this.listAssocProduct.push(prod_id); } } //---------------------------------------------------------------------------------------------------- this.removeAssociateProduct = function(prod_id) { this.listAssocProduct = this.listAssocProduct.erase(prod_id); }