(function($){ changeName = function(name){ if($('#change_nom_portefeuille').hasClass('cache')){ $('#change_nom_portefeuille').removeClass('cache'); } else { $('#change_nom_portefeuille').addClass('cache'); } }; deletePortfolio = function(name){ if (confirm('Etes-vous sûr de vouloir supprimer le portefeuille '+name+' ?')){ return true; } else { return false; } }; displayModule = function(module){ if (module.substr(0,1)!="#") { module = "#"+module; } $('.symex_module').each(function (index, domEle) { if (!$(domEle).hasClass('cache')){ $(domEle).addClass('cache'); } }); if ($(module).hasClass('cache')){ $(module).removeClass('cache'); } return false; }; hideModule = function(module){ if (module.substr(0,1)!="#") { module = "#"+module; } if(!$(module).hasClass('cache')){ $(module).addClass('cache'); } return false; }; getSearchResults = function(){ if ($('#search_results').hasClass('cache')){ $('#search_results').removeClass('cache'); } // $('#search_results').html(loading_picture); $.ajax({ type: 'POST', processData: true, url: '/operations_get', data: { choice: 'search_results', nom: $('#searched_name').val(), pays: $('#searched_pays').val() }, dataType: 'html', success: function(data){ $('#search_results').html(data); }, error: function(data){ $('#search_results').html('Erreur lors de la recherche.'); } }); return false; }; getCheckboxes = function(){ if ($('#search_results').hasClass('cache')){ $('#search_results').removeClass('cache'); }else if (!$('#search_results').hasClass('cache')){ $('#search_results').addClass('cache'); } // $('#search_results').html(loading_picture); $.ajax({ type: 'POST', processData: true, url: '/operations_get', data: { choice: 'checkboxes', nom: $('#searched_name').val(), pays: $('#searched_pays').val() }, dataType: 'html', success: function(data){ $('#search_results').html(data); }, error: function(data){ $('#search_results').html('Erreur lors de la recherche.'); } }); return false; }; addToList = function (item) { var tmp = document.form1.new_tablist.value.split(item); if (tmp.length > 1){ // document.form1.new_tablist.value = tmp[0]+tmp[1]; document.form2.new_tablist.value = tmp[0]+tmp[1]; }else{ //document.form1.new_tablist.value += item; document.form2.new_tablist.value += item; } document.form2.submit(); }; getOperationBuy = function(code,pays){ if ($('#operation_buy').hasClass('cache')){ $('#operation_buy').removeClass('cache'); } if (!$('#search_results').hasClass('cache')){ $('#search_results').addClass('cache'); } if (!$('#search').hasClass('cache')){ $('#search').addClass('cache'); } // $('#operation_buy').html(loading_picture); $.ajax({ type: 'POST', processData: true, url: '/operations_get', data: { choice: 'buy', code: code, pays: pays }, dataType: 'html', success: function(data){ $('#operation_buy').html(data); }, error: function(data){ $('#operation_buy').html('Erreur lors du chargement.'); } }); return false; }; getOperationAdd = function(code,pays){ if ($('#operation_buy').hasClass('cache')){ $('#operation_buy').removeClass('cache'); } if (!$('#search_results').hasClass('cache')){ $('#search_results').addClass('cache'); } if (!$('#search').hasClass('cache')){ $('#search').addClass('cache'); } // $('#operation_buy').html(loading_picture); $.ajax({ type: 'POST', processData: true, url: '/operations_get', data: { choice: 'buy', code: code, pays: pays }, dataType: 'html', success: function(data){ $('#operation_buy').html(data); }, error: function(data){ $('#operation_buy').html('Erreur lors du chargement.'); } }); return false; }; hideOperationBuy = function(){ if (!$('#operation_buy').hasClass('cache')){ $('#operation_buy').addClass('cache'); } if (!$('#search_results').hasClass('cache')){ $('#search_results').addClass('cache'); } if (!$('#ajouter_titre').hasClass('cache')){ $('#ajouter_titre').addClass('cache'); } if ($('#search').hasClass('cache')){ $('#search').removeClass('cache'); } return false; }; getTotal = function (form) { if (form.substr(0,1)!="#") { form = "#"+form; } var p_achatValue =$(form).find('input[name="p_achat"]').val().replace(',', '.'); var quantiteValue =$(form).find('input[name="quantite"]').val().replace(',', '.'); var fraisValue =$(form).find('input[name="frais"]').val().replace(',', '.'); var finalTotal; if (quantiteValue !== 0 && p_achatValue !== 0){ var typeFraisValue = $(form).find('select[name="type_frais"]').val(); if (typeFraisValue == "e"){ finalTotal = (parseFloat(quantiteValue) * parseFloat(p_achatValue) + parseFloat(fraisValue)); finalTotal = Math.round(finalTotal*100)/100; finalTotal.replace('.', ','); $(form).find('input[name="total"]').val(finalTotal); } else { finalTotal = (parseFloat(quantiteValue) * parseFloat(p_achatValue)); var totalfrais = ((parseFloat(finalTotal) / 100) * parseFloat(fraisValue)); finalTotal = parseFloat(finalTotal) + totalfrais; $(form).find('input[name="total"]').val(Math.round(finalTotal*100)/100); } } else { $(form).find('input[name="total"]').val(0); } return false; }; getTotalSell = function (form) { if (form.substr(0,1)!="#") { form = "#"+form; } var p_achatValue =$(form).find('input[name="p_achat"]').val().replace(',', '.'); var quantiteValue =$(form).find('input[name="quantite"]').val().replace(',', '.'); var fraisValue =$(form).find('input[name="frais"]').val().replace(',', '.'); var finalTotal; if (quantiteValue !== 0 && p_achatValue !== 0){ var typeFraisValue = $(form).find('select[name="type_frais"]').val(); if (typeFraisValue == "e"){ finalTotal = ((parseFloat(quantiteValue) * parseFloat(p_achatValue)) - parseFloat(fraisValue)); finalTotal = Math.round(finalTotal*100)/100; $(form).find('input[name="total"]').val(finalTotal.replace('.', ',')); } else { finalTotal = (parseFloat(quantiteValue) * parseFloat(p_achatValue)); var totalfrais = ((parseFloat(finalTotal) / 100) * parseFloat(fraisValue)); finalTotal = parseFloat(finalTotal) - totalfrais; finalTotal =Math.round(finalTotal*100)/100; $(form).find('input[name="total"]').val(finalTotal); } } else { $(form).find('input[name="total"]').val(0); } return false; }; })(jQuery);