var App_Form_Element_Budget = { init: function(id){ App_Form_Element_Budget.initMask(id); $.Calculation.setDefaults({ reNumbers: /(-|-\$)?(\d+(,\d{3})*(\.\d{1,})?|\.\d{1,})/g, cleanseNumber: function (v){ return v.replace(",", "").replace(/[^0-9.\-]/g, ""); } }); App_Form_Element_Budget.sum(id, true); $('#' + id + '-enable').click(function(){ var editText = $("#" + id + "-budget-sum"); $("input[id*='" + id + "-total']").unbind("keyup"); if (editText.attr('disabled')){ editText.removeAttr("disabled"); if ($("#"+id+"-3").size()){ App_Form_Element_Budget.removeHidden(id); } $(this).val('apply'); } else { if (parseFloat($('#' + editText.attr('id')).val().replace(',', '')) > 0){ editText.after(''); editText.attr('name', '_' + editText.attr('name')); } App_Form_Element_Budget.sum(id, true); editText.attr('disabled', true); $(this).val('edit'); } }) }, sum: function(id, init){ $("input[id*='" + id + "-total']").sum({ bind: "keyup", selector: "#" + id + "-budget-sum", oncalc: function (value, options){ var selector = options.selector; var val = value; if (typeof init != 'undefined' && init){ if ($("#"+id+"-3").size()){ val = $("#"+id+"-3").val().replace(",", "").replace(",", ""); } init = false; } else { App_Form_Element_Budget.removeHidden(id); } $(selector).val($.fn.autoNumeric.Format($(selector).attr('id'), val)); } }); }, removeHidden: function(id, editText) { var sumName = $("#"+id+"-3").attr('name'); $("#"+id+"-3").remove(); $("#" + id + "-budget-sum").attr('name', sumName); }, initMask: function(id){ /*$("input[id*='" + id + "']").focus(function(){ if ($(this).attr('tagName') != 'SELECT' && $(this).attr('type') != 'button'){ $(this).autoNumeric(); //$('#field_' + id + '-budget-sum').change(); } }); */ $("input[id*='" + id + "']").each(function(){ if ($(this).attr('tagName') != 'SELECT' && $(this).attr('type') != 'button'){ if ($(this).val() != ''){ $(this).val($.fn.autoNumeric.Format($(this).attr('id'), $(this).val())); } $(this).autoNumeric(); } }); } }