Skip to content

Instantly share code, notes, and snippets.

@pbalduino
Created September 9, 2011 14:42
Show Gist options
  • Save pbalduino/1206409 to your computer and use it in GitHub Desktop.
Save pbalduino/1206409 to your computer and use it in GitHub Desktop.
JS generated by CS
var data, drawMontante, fillData, onLoadContrato, onLoadMontante, readMontanteData, update_tributos;
data = void 0;
onLoadContrato = function() {
enableStep4();
return $('.right_selector').click(drawMontante);
};
drawMontante = function() {
var endDate, endMonth, endYear, params, startDate, startMonth, startYear;
startDate = $('#contrato_inicio_vigencia').val().split('/');
endDate = $('#contrato_fim_vigencia').val().split('/');
if (startDate.length !== 3 || endDate.length !== 3 || $('#contrato_preco').val().trim() === '' || $('#contrato_mwmcontratado').val().trim() === '') {
$('#edit_form').hide();
return;
}
if (data === void 0) {
data = fillData();
}
startYear = startDate[2];
endYear = endDate[2];
startMonth = startDate[1];
endMonth = endDate[1];
params = {
rows: [
{
'title': 'Montante',
'id': 'power',
'class': 'millesimal'
}, {
'title': 'Preço',
'id': 'price',
'class': 'centesimal'
}
],
startMonth: "" + startYear + "-" + startMonth,
finalMonth: "" + endYear + "-" + endMonth,
data: data,
editForm: $('#edit_form'),
validator: {
rules: 'true'
},
formName: 'data',
onOpenDialog: function() {
$('#power').maskMoney({
symbol: "",
decimal: ".",
thousands: "",
precision: 3
});
return $('#price').maskMoney({
symbol: "",
decimal: ".",
thousands: "",
precision: 2
});
},
onCloseDialog: function() {
$('#power').unmaskMoney();
return $('#price').unmaskMoney();
}
};
return $('#montante').gusfoo(params);
};
onLoadMontante = function(id) {
return $.get('/montantes', {
contrato: id
}, readMontanteData, "json");
};
readMontanteData = function(jsonData) {
data = jsonData;
if (data.length === 0) {
data = fillData();
}
return drawMontante();
};
fillData = function() {
var endDate, endMonth, endYear, month, mwmDefault, priceDefault, ret, startDate, startMonth, startYear, year, _ref, _ref2;
ret = {
power: {},
price: {}
};
startDate = $('#contrato_inicio_vigencia').val().split('/');
endDate = $('#contrato_fim_vigencia').val().split('/');
startYear = startDate[2];
endYear = endDate[2];
startMonth = startDate[1];
endMonth = endDate[1];
mwmDefault = ($('#contrato_mwmcontratado').val() * 1000) / 1000;
priceDefault = ($('#contrato_preco').val() * 100) / 100;
for (year = startYear; startYear <= endYear ? year <= endYear : year >= endYear; startYear <= endYear ? year++ : year--) {
ret['power'][year] = [null, null, null, null, null, null, null, null, null, null, null, null];
ret['price'][year] = [null, null, null, null, null, null, null, null, null, null, null, null];
for (month = _ref = ((startYear === endYear) || year === startYear ? startMonth : 1), _ref2 = ((startYear === endYear) || (year === endYear) ? endMonth : 12); _ref <= _ref2 ? month <= _ref2 : month >= _ref2; _ref <= _ref2 ? month++ : month--) {
ret['power'][year][month - 1] = mwmDefault;
ret['price'][year][month - 1] = priceDefault;
}
}
return ret;
};
update_tributos = function() {
if ($("#contrato_icms").attr("value") === "true") {
$("#contrato_aliquota_icms").show();
$("label[for='contrato_aliquota_icms']").show();
} else {
$("#contrato_aliquota_icms").hide();
$("label[for='contrato_aliquota_icms']").hide();
}
if ($("#contrato_pis_cofins").attr("value") === "true") {
$("#contrato_aliquota_pis_cofins").show();
return $("label[for='contrato_aliquota_pis_cofins']").show();
} else {
$("#contrato_aliquota_pis_cofins").hide();
return $("label[for='contrato_aliquota_pis_cofins']").hide();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment