Created
September 9, 2011 14:41
-
-
Save pbalduino/1206405 to your computer and use it in GitHub Desktop.
CS sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = undefined | |
onLoadContrato = -> | |
enableStep4() | |
$('.right_selector').click drawMontante | |
drawMontante = -> | |
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 == undefined | |
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 : -> | |
$('#power').maskMoney({symbol:"",decimal:".",thousands:"",precision:3}) | |
$('#price').maskMoney({symbol:"",decimal:".",thousands:"",precision:2}) | |
onCloseDialog: -> | |
$('#power').unmaskMoney() | |
$('#price').unmaskMoney() | |
$('#montante').gusfoo params | |
onLoadMontante = (id) -> | |
$.get('/montantes', {contrato: id}, readMontanteData, "json") | |
readMontanteData = (jsonData) -> | |
data = jsonData | |
if data.length == 0 | |
data = fillData() | |
drawMontante() | |
fillData = -> | |
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 in [startYear..endYear] | |
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 in [(if (startYear == endYear) || year == startYear then startMonth else 1)..(if (startYear == endYear) || (year == endYear) then endMonth else 12)] | |
ret['power'][year][month - 1] = mwmDefault | |
ret['price'][year][month - 1] = priceDefault | |
ret | |
update_tributos = -> | |
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() | |
$("label[for='contrato_aliquota_pis_cofins']").show() | |
else | |
$("#contrato_aliquota_pis_cofins").hide() | |
$("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