-
-
Save cmilfont/1282526 to your computer and use it in GitHub Desktop.
sammyjs
This file contains hidden or 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
| //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.breadcrumb([{ path: '#/', name: 'Evento'}], 'Criar'); | |
| self.Contexto.partial(self.Contexto.montaUrl('pagamentos', 'criarEvento')).then(function () { | |
| self.carregaFormulario(); | |
| self.configuraEventos(); | |
| if(self.Contexto.params.id) { | |
| self.EventosController.consulta(self.Contexto.params.id, function(response) { | |
| self.preencheFormulario(response.data); | |
| }); | |
| } | |
| }); | |
| }; | |
| Views.Evento.Criacao.Inicializa = function(ctx) { | |
| return new Views.Evento.Criacao(ctx); | |
| }; | |
| Views.Evento.Criacao.prototype = { | |
| configuraEventos: function() { | |
| var self = this; | |
| $('#cancelar').click(function () { | |
| self.Contexto.redirect('/#/evento'); | |
| }); | |
| $('#finalizar').click(function (event) { | |
| event.preventDefault(); | |
| //use https://github.com/milfont/jsonform | |
| //ponha os ids do input igual ao json e troque pelo name se puder | |
| var evento = $('#criarEvento').getJSON(); | |
| if(self.Contexto.params.id) { | |
| self.EventosController.altera(evento, function () { | |
| self.Contexto.redirect('/#/evento'); | |
| }); | |
| } else { | |
| self.EventosController.inclui(evento, function () { | |
| self.Contexto.redirect('/#/evento'); | |
| }); | |
| } | |
| }); | |
| }, | |
| carregaFormulario: function () { | |
| var self = this; | |
| self.EventosController.formularioDeCriacao(function (response) { | |
| //crie um plugin do jquery para fazer mais ou menos isso assim | |
| $("#form").carregaSelect({ | |
| 'tipoevento': response.data.TiposDeEventos, | |
| 'funcoes' : response.data.Funcoes, | |
| 'variaveis' : response.data.Variaveis}); | |
| //centraliza a manutenção, evita funções soltas e trabalha conforme o Framework | |
| // qualquer pessoa com conhecimento em jQuery se sentirá familiar quando ler | |
| }); | |
| }, | |
| preencheFormulario: function (evento) { | |
| //use https://github.com/milfont/jsonform e faça | |
| $("#form").populate(evento, true); | |
| // mude o id dos inputs para Maiusculo igual ao que vem do servidor | |
| } | |
| }; | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment