PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/dotnet/prod-opennode2-net/src/Admin/Secure/FlowEdit.aspx.cs

http://opennode2.googlecode.com/
C# | 243 lines | 195 code | 17 blank | 31 comment | 23 complexity | c8e41eedb5ff5645fca00de2f2e10a36 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0, Apache-2.0, LGPL-2.1, CC-BY-SA-3.0, MPL-2.0-no-copyleft-exception
  1. #region License
  2. /*
  3. Copyright (c) 2009, The Environmental Council of the States (ECOS)
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. * Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. * Neither the name of the ECOS nor the names of its contributors may
  14. be used to endorse or promote products derived from this software
  15. without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  19. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  20. COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  22. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  26. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #endregion
  30. using System;
  31. using System.Data;
  32. using System.Configuration;
  33. using System.Collections;
  34. using System.Collections.Generic;
  35. using System.Text;
  36. using System.Web;
  37. using System.Web.Security;
  38. using System.Web.UI;
  39. using System.Web.Caching;
  40. using System.Web.UI.WebControls;
  41. using System.Web.UI.WebControls.WebParts;
  42. using System.Web.UI.HtmlControls;
  43. using Common.Logging;
  44. using Windsor.Node2008.WNOSConnector.Admin;
  45. using Windsor.Node2008.WNOSDomain;
  46. using Windsor.Node2008.Admin.Controls;
  47. using Windsor.Node2008.WNOSUtility;
  48. using Spring.DataBinding;
  49. using Windsor.Node2008.WNOSConnector.Server;
  50. using Windsor.Commons.Core;
  51. namespace Windsor.Node2008.Admin.Secure
  52. {
  53. public partial class FlowEdit : SecurePage
  54. {
  55. #region Members
  56. private class DataModel
  57. {
  58. public DataFlow DataFlow { get; set; }
  59. public bool IsNewFlow { get; set; }
  60. public string ContactUsername { get; set; }
  61. }
  62. private DataModel Model { get; set; }
  63. public IFlowService FlowService { get; set; }
  64. #endregion
  65. protected override void OnInit(EventArgs e)
  66. {
  67. if (FlowService == null)
  68. {
  69. throw new ArgumentNullException("Missing FlowService");
  70. }
  71. base.OnInit(e);
  72. }
  73. protected override void OnInitializeControls(EventArgs e)
  74. {
  75. LoadModel();
  76. if (Response.IsRequestBeingRedirected)
  77. {
  78. return;
  79. }
  80. base.OnInitializeControls(e);
  81. bool disableEditing = (Model == null);
  82. if (!disableEditing && !this.IsPostBack)
  83. {
  84. SecureMasterPage.SetupPage(SideTabs, SelectedTabIndex);
  85. introParagraphs.DataSource = IntroParagraphs;
  86. introParagraphs.DataBind();
  87. contactsDropDownList.DataSource = FlowService.GetFlowContactList();
  88. contactsDropDownList.DataBind();
  89. if (Model.IsNewFlow)
  90. {
  91. if (!CanEditNewFlows())
  92. {
  93. ResponseRedirect("~/Secure/Flow.aspx");
  94. return;
  95. }
  96. deleteBtn.Visible = false;
  97. }
  98. else
  99. {
  100. if (!CanViewFlowByName(Model.DataFlow.FlowName))
  101. {
  102. ResponseRedirect("~/Secure/Flow.aspx");
  103. return;
  104. }
  105. nameEdit.Text = Model.DataFlow.FlowName;
  106. descriptionTextBox.Text = Model.DataFlow.Description;
  107. contactsDropDownList.SelectedValue = Model.ContactUsername;
  108. webInfoTextBox.Text = Model.DataFlow.InfoUrl;
  109. protectedCheckBox.Checked = Model.DataFlow.IsProtected;
  110. disableEditing = !CanEditFlowByName(Model.DataFlow.FlowName);
  111. nameEdit.Enabled = false;
  112. deleteBtn.Visible = CanEditNewFlows();
  113. }
  114. }
  115. if (disableEditing)
  116. {
  117. nameEdit.Enabled = descriptionTextBox.Enabled = contactsDropDownList.Enabled =
  118. webInfoTextBox.Enabled = protectedCheckBox.Enabled = false;
  119. deleteBtn.Visible = saveBtn.Visible = false;
  120. CustomValidator7.Visible = false;
  121. cancelBtn.Text = "Back";
  122. }
  123. else if (!this.IsPostBack)
  124. {
  125. if (nameEdit.Enabled)
  126. {
  127. AspNetUtils.SetFocus(this, nameEdit, false);
  128. }
  129. else if (descriptionTextBox.Enabled)
  130. {
  131. AspNetUtils.SetFocus(this, descriptionTextBox, true);
  132. }
  133. }
  134. }
  135. #region Spring Biding Stuff
  136. protected void LoadModel()
  137. {
  138. try
  139. {
  140. Model = new DataModel();
  141. string id = Request["id"];
  142. if (!string.IsNullOrEmpty(id))
  143. {
  144. if (!CanViewFlowById(id))
  145. {
  146. Model = null;
  147. ResponseRedirect("~/Secure/Flow.aspx");
  148. return;
  149. }
  150. Model.DataFlow = FlowService.GetFlow(id, VisitHelper.GetVisit());
  151. if (Model.DataFlow == null)
  152. {
  153. throw new ArgumentException(string.Format("Flow with id \"{0}\" not found", id));
  154. }
  155. if (!string.IsNullOrEmpty(Model.DataFlow.ContactUserId))
  156. {
  157. Model.ContactUsername = FlowService.GetUsernameById(Model.DataFlow.ContactUserId);
  158. }
  159. }
  160. else
  161. {
  162. Model.IsNewFlow = true;
  163. Model.DataFlow = new DataFlow();
  164. }
  165. }
  166. catch (Exception ex)
  167. {
  168. Model = null;
  169. SetDivPageError("Failed to load data for flow: ", ex);
  170. }
  171. }
  172. protected void ControlsToModel()
  173. {
  174. Model.DataFlow.FlowName = nameEdit.Text.Trim();
  175. Model.DataFlow.Description = descriptionTextBox.Text.Trim();
  176. Model.ContactUsername = contactsDropDownList.SelectedValue;
  177. Model.DataFlow.InfoUrl = webInfoTextBox.Text.Trim();
  178. Model.DataFlow.IsProtected = protectedCheckBox.Checked;
  179. Model.DataFlow.ContactUserId = FlowService.GetUserIdByName(Model.ContactUsername);
  180. if (string.IsNullOrEmpty(Model.DataFlow.ContactUserId))
  181. {
  182. throw new ArgumentException("ContactUserId not found");
  183. }
  184. }
  185. protected void CancelItem(object sender, EventArgs e)
  186. {
  187. ResponseRedirect("../Secure/Flow.aspx");
  188. }
  189. protected void SaveDataItem(object sender, EventArgs e)
  190. {
  191. if (divPageError.Visible || !Page.IsValid)
  192. {
  193. // Error on page, get out of here
  194. return;
  195. }
  196. try
  197. {
  198. ControlsToModel();
  199. Model.DataFlow = FlowService.SaveFlow(Model.DataFlow, VisitHelper.GetVisit());
  200. ResponseRedirect("Flow.aspx");
  201. }
  202. catch (Exception ex)
  203. {
  204. LOG.Error(ex.Message, ex);
  205. SetDivPageError(ex);
  206. }
  207. }
  208. protected void DeleteDataItem(object sender, EventArgs e)
  209. {
  210. try
  211. {
  212. FlowService.DeleteFlow(Model.DataFlow, VisitHelper.GetVisit());
  213. ResponseRedirect("../Secure/Flow.aspx");
  214. }
  215. catch (Exception ex)
  216. {
  217. LOG.Error(ex.Message, ex);
  218. SetDivPageError(ex);
  219. }
  220. }
  221. #endregion
  222. }
  223. }