Skip to content

Instantly share code, notes, and snippets.

@hvitorino
Created October 12, 2011 18:12
Show Gist options
  • Save hvitorino/1282052 to your computer and use it in GitHub Desktop.
Save hvitorino/1282052 to your computer and use it in GitHub Desktop.
sammyjs
//Rota no Sammy
this.get('#/evento/criar', Views.Evento.Criacao.Inicializa);
// Arquivo da View
;(function() {
if(!Views.Evento)
Views.Evento = { };
Views.Evento.Criacao = function (ctx) {
var self = this;
self.EventosController = new Aramis.Controllers.Eventos();
self.Contexto = ctx;
self.Contexto.partial(self.Contexto.montaUrl('pagamentos', 'criarEvento')).then(function () {
self.configuraValidacao();
self.carregaFormulario();
self.configuraEventos();
if(self.estaEmModoDeEdicao()) {
self.EventosController.consulta(self.Contexto.params.id, function(response) {
self.preencheFormulario(response.data);
self.Contexto.breadcrumb([{ path: '#/evento', name: 'Evento'}], response.data.Nome);
});
} else {
self.Contexto.breadcrumb([{ path: '#/evento', name: 'Evento'}], 'Criar');
}
});
};
Views.Evento.Criacao.Inicializa = function(ctx) {
return new Views.Evento.Criacao(ctx);
};
Views.Evento.Criacao.prototype = {
estaEmModoDeEdicao: function () {
return verdadeiro(self.Contexto.params.id);
},
configuraValidacao: function () {
$('#criarEvento').validationEngine({
scroll: false,
doNotShowAllErrosOnSubmit: true,
showOnlyOneError: true,
sendAllFormValues: true,
hideDelay: 2000,
showDelay: 0,
customFieldClass: 'error'
});
},
configuraEventos: function() {
var self = this;
$('#criarEvento').submit(function() {
if (!$('#criarEvento .error').length) {
var evento = $('#criarEvento').serializeObject();
if(self.estaEmModoDeEdicao()) {
self.EventosController.altera(evento, function () {
self.Contexto.redirect('/#/evento');
});
} else {
self.EventosController.inclui(evento, function () {
self.Contexto.redirect('/#/evento');
});
}
}
return false;
});
$('#cancelar').click(function () {
self.Contexto.redirect('/#/evento');
});
},
carregaFormulario: function () {
var self = this;
self.EventosController.formularioDeCriacao(function (response) {
$('#criarEvento').carregaSelect({
Tipo: response.data.TiposDeEventos
});
});
},
preencheFormulario: function (evento) {
$('#criarEvento').deserialize(evento);
if (evento.SomenteLeitura) {
$('input:text, select, textarea', '#criarEvento').prop('disabled', evento.SomenteLeitura);
$('#finalizar').prop('disabled',evento.SomenteLeitura).remove();
$('#somenteLeitura').show();
}
}
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment