Skip to content

Instantly share code, notes, and snippets.

@thelinuxlich
Created February 9, 2011 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thelinuxlich/819053 to your computer and use it in GitHub Desktop.
Save thelinuxlich/819053 to your computer and use it in GitHub Desktop.
# Modelo do evento para persistência no banco de dados.
class @Evento
constructor: ->
@descricao.subscribe ((value) ->
if value.length > 4000
@descricao value.substr(0, 4000)
).bind @
@tipo.subscribe ((value) ->
if value isnt "OUTROS"
@outro_tipo ""
).bind @
@todos_os_cursos.subscribe ((value) ->
if value is true
@cursos []
).bind @
id: KO ""
tipo: KO "CURSO"
outro_tipo: KO ""
descricao: KO ""
carga_horaria: KO ""
numero_de_vagas: KO ""
estado: KO ""
cidade: KO ""
local: KO ""
vagas_ocupadas: KO 0
vagas_restantes: KO (-> parseInt(@numero_de_vagas()) - @vagas_ocupadas()),@
status: KO "A"
data_inicio: KO ""
data_termino: KO ""
data_inicio_inscricao: KO ""
data_termino_inscricao: KO ""
hora_inicio: KO ""
responsavel: KO ""
autorizado: KO ""
expirado: KO ""
recebe_presenca: KO ""
textoStatus: KO (-> if @status() is "A" then "Ativo" else "Inativo" ), @
hora_termino: KO ->
if TIME_REGEX.test(@hora_inicio()) is false or TIME_REGEX.test(@carga_horaria()) is false
""
else
d = new Date()
hora = @hora_inicio().split ":"
hora_ch = @carga_horaria().split ":"
d.setHours parseInt hora[0]
d.setHours parseInt(d.getHours()) + parseInt(hora_ch[0])
d.setMinutes parseInt hora[1]
d.setMinutes parseInt(d.getMinutes()) + parseInt(hora_ch[1])
pad(d.getHours(),2)+":"+pad(d.getMinutes(),2)
, @
atividade_complementar: KO true
cursos: KO []
todos_os_cursos: KO false
valido: KO false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment