Changed to use Authenticate asp.net event instead of Authorize
[castle.git] / MonoRail / TestSiteNVelocity / Controllers / AjaxController.cs
blobfabe5a5ada5f003a2e8830c60c83c5dc722af1ca
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace TestSiteNVelocity.Controllers
17 using System;
18 using System.Collections;
20 using Castle.MonoRail.Framework;
23 public class AjaxController : SmartDispatcherController
25 #region ObserveField
27 public void ObserveField()
31 public void InferAddress(String value)
33 RenderText("Address " + value);
36 #endregion
38 #region ObserveForm
40 public void ObserveForm()
45 public void AccountFormValidate(String name, String addressf)
47 RenderText("name {0} address {1}", name, addressf);
50 #endregion
52 #region AutoCompletion
54 /// <summary>
55 /// Auto completion action
56 /// </summary>
57 public void AutoCom()
61 /// <summary>
62 /// Auto completion results
63 /// </summary>
64 public void NameAutoCompletion(String name)
66 RenderText("<ul class=\"names\"><li class=\"name\">Jisheng Johnny</li><li class=\"name\">John Diana</li><li class=\"name\">Johnathan Maurice</li></ul>");
69 #endregion
71 #region Periodically calls
73 public void PeriodicallyCall()
77 /// <summary>
78 /// Invoked by Ajax
79 /// </summary>
80 public void PeriodicallyCalled(int value)
82 RenderText((value + value).ToString());
85 #endregion
87 #region JS Proxies
89 public void JsProxies()
94 [AjaxAction]
95 public void InvocableMethod1()
97 RenderText("Success");
100 [AjaxAction("friendlyName")]
101 public void InvocableMethod2(String value)
103 RenderText("Success " + value);
106 #endregion
108 #region BuildFormRemoteTag
110 public void FormRemoteTag()
112 IList list = GetList();
113 PropertyBag.Add("users", list);
116 public void AddUserWithAjax(String name, String email)
118 GetList().Add(new User(name, email));
120 IList list = GetList();
121 PropertyBag.Add("users", list);
123 RenderView("/userlist");
126 private IList GetList()
128 IList list = Context.Session["list"] as IList;
130 if (list == null)
132 list = new ArrayList();
134 list.Add(new User("somefakeuser", "fakeemail@server.net"));
135 list.Add(new User("someotherfakeuser", "otheremail@server.net"));
137 Context.Session["list"] = list;
140 return list;
143 #endregion
146 public class User
148 private String name;
149 private String email;
151 public User(string name, string email)
153 this.name = name;
154 this.email = email;
157 public string Name
159 get { return name; }
162 public string Email
164 get { return email; }