コード例 #1
0
		public void Show()
		{
			Container = Div.CreateContainer(default(Element), container=>{
				Div.CreateRow(container, row=>{
					//
					new Div(row,element=>{
						
						element.ClassName="span4 offset4 well";
						new Legend(element, l=>l.Text("Por favor inicie session"));
						
						new Form(element, fe=>{
							fe.Action= "/api/User/login";

							new TextField(fe, i=>{
								i.SetPlaceHolder("NIT");i.Name="Nit";i.ClassName="span4";
								i.SetRequired();i.SetMinLength(8);
							});

							new TextField(fe, i=>{
								i.SetPlaceHolder("nombre usuario");	i.Name="Nombre";i.ClassName="span4";
								i.SetRequired();i.SetMinLength(4);
							});

							new TextField(fe, i=>{
								i.SetPlaceHolder("clave");	i.Name="Clave";i.ClassName="span4";
								i.SetRequired();i.SetMinLength(4);
								i.Type="password";
							});

							var bt = new SubmitButton(fe, b=>{
								b.JQuery().Text("Iniciar Session");
								b.ClassName="btn btn-info btn-block";
								b.LoadingText("  autenticando....");
							});
							
							var vo = new ValidateOptions()
								.SetSubmitHandler( f=>{
									
									bt.ShowLoadingText();
									
									var req=jQuery.PostRequest<UserLoginResponse>(f.Action, f.Serialize(), cb=>{},"json");
									req.Done(d=>{
										Cayita.Javascript.Firebug.Console.Log(d);
										f.Clear();
										if(OnLogin!=null) OnLogin(d,this);
											
									});
									req.Fail(e=> {
										Cayita.Javascript.Firebug.Console.Log("fail :",req); 
										Div.CreateAlertErrorBefore(fe.Elements[0], req.Status.ToString()+":"+
										                           (req.StatusText.StartsWith("ValidationException")?
										                           "Usario/clave no validos":
										                           req.StatusText)); 
									});
									req.Always(a=>{
												bt.ResetLoadingText();
									})	;
										
								});
							
							fe.Validate(vo);			
							
						});
						
					});
					
				});
			});
			
			Parent.AppendChild(Container.Element());
		}
コード例 #2
0
ファイル: App.cs プロジェクト: aicl/Calamar.Scripts
		public void Show()
		{
			Container = Div.CreateContainer(default(Element), container=>{
				Div.CreateRow(container, row=>{
					//
					new Div(row,element=>{

						element.ClassName="span4 offset4 well";
						new Legend(element, new LegendConfig{Text="Por favor inicie session"});
						
						new Form(element, fe=>{
							fe.Action= Config.Action;
							fe.Method = Config.Method;

							var cg = Div.CreateControlGroup(fe);
							
							var user= new InputText(cg.Element(), pe=>{
								pe.ClassName="span4";
								pe.SetPlaceHolder("nombre de usuario");
								pe.Name="UserName";
							});
							
							cg = Div.CreateControlGroup(fe);
							var pass =new InputPassword(cg.Element(), pe=>{
								pe.ClassName="span4";
								pe.SetPlaceHolder("Digite su clave");
								pe.Name="Password";
							});
																												
							var bt = new SubmitButton(fe, b=>{
								b.JSelect().Text("Iniciar Session");
								b.ClassName="btn btn-info btn-block";
								b.LoadingText("  autenticando....");
							});
														
							var vo = new ValidateOptions()
								.SetSubmitHandler( f=>{
									
									bt.ShowLoadingText();
									
									jQuery.PostRequest<LoginResponse>(f.Action, f.Serialize(), cb=>{
										Cayita.Javascript.Firebug.Console.Log("callback", cb);
									},"json")
										.Success(d=>{
											UserName= user.Element().Value;
											if(OnLogin!=null) OnLogin(d,this);
											
										})
											.Error((request,  textStatus,  error)=>{
												Div.CreateAlertErrorBefore(fe.Elements[0],textStatus+": "
												                           +( request.StatusText.StartsWith("ValidationException")?
												  "Usario/clave no validos":
												  request.StatusText));
											})
											.Always(a=>{
												bt.ResetLoadingText();
											})										;
									
									
								})
									.AddRule((rule, msg)=>{
										rule.Element=pass.Element();
										rule.Rule.Minlength(2).Required();
										msg.Minlength("minimo 2 caracteres").Required("Digite su password");
									})
									
									.AddRule( (rule, msg)=> {
										rule.Element= user.Element();
										rule.Rule.Required().Minlength(2);
										msg.Minlength("minimo 2 caracteres");
									});
							
							fe.Validate(vo);			
							
						});
						
					});

				});
			});
			
			Parent.AppendChild(Container.Element());
		}