Commits

Tom Fulton committed fe408ce

Add Template config to dashboard control

  • Participants
  • Parent commits 15394dc

Comments (0)

Files changed (3)

File Our.Umbraco.HttpsRedirect/Install/HttpsRedirectInstaller.ascx

 		<umb:Feedback runat="server" ID="Failure" type="error" Visible="false" />
 		
 		<p>Now that <strong>HTTPS Redirect</strong> has been installed, you can configure the settings.</p>
-
-		<h2>Document Types</h2>
-		<p>Select the document-types that will redirect to HTTPS:</p>
-		<asp:CheckBoxList runat="server" ID="cblDocTypes"></asp:CheckBoxList>
+		
+		<div style="float: left; margin-right: 15px;">
+			<h2>Document Types</h2>
+			<p>Select the document-types that will redirect to HTTPS:</p>
+			<asp:CheckBoxList runat="server" ID="cblDocTypes"></asp:CheckBoxList>
+		</div>
+		
+		<div style="float: left;">
+			<h2>Templates</h2>
+			<p>Select the templates that will redirect to HTTPS:</p>
+			<asp:CheckBoxList runat="server" ID="cblTemplates"></asp:CheckBoxList>
+		</div>
+		
+		<br style="clear: both;" />
 
 		<h2>Page/Node Ids</h2>
 		<p>Enter a comma-separated list of specific page/node ids:</p>

File Our.Umbraco.HttpsRedirect/Install/HttpsRedirectInstaller.ascx.cs

 using System.Web.UI;
 using System.Web.UI.WebControls;
 using System.Xml;
+using umbraco.cms.businesslogic.template;
 using umbraco.cms.businesslogic.web;
 
 namespace Our.Umbraco.HttpsRedirect.Install
 			this.cblDocTypes.DataTextField = "Text";
 			this.cblDocTypes.DataValueField = "Alias";
 			this.cblDocTypes.DataBind();
+
+			// bind the templates
+			this.cblTemplates.DataSource = Template.GetAllAsList();
+			this.cblTemplates.DataTextField = "Text";
+			this.cblTemplates.DataValueField = "Alias";
+			this.cblTemplates.DataBind();
 		}
 
 		protected void Page_Load(object sender, EventArgs e)
 
 				}
 
+				// populate the templates
+				csv = WebConfigurationManager.AppSettings[Settings.AppKey_Templates];
+				if (!string.IsNullOrWhiteSpace(csv))
+				{
+					var templates = csv.Split(new[] { Settings.COMMA }, StringSplitOptions.RemoveEmptyEntries).ToList();
+
+					foreach (ListItem item in this.cblTemplates.Items)
+					{
+						item.Selected = templates.Contains(item.Value);
+					}
+
+				}
+
 				// populate the page-ids
 				var pageIds = WebConfigurationManager.AppSettings[Settings.AppKey_PageIds];
 				if (!string.IsNullOrWhiteSpace(pageIds))
 			var settings = new Dictionary<string, string>();
 			var xml = new XmlDocument();
 
-			// loops through the selected doc-types
-			var docTypes = new List<string>();
-			foreach (ListItem item in this.cblDocTypes.Items)
-			{
-				if (item.Selected)
-				{
-					docTypes.Add(item.Value);
-				}
-			}
-
-			// adds the appSettings keys for the doc-types
-			if (docTypes.Count > 0)
-			{
-				settings.Add(Settings.AppKey_DocTypes, string.Join(Settings.COMMA.ToString(), docTypes.ToArray()));
-			}
-            else
-            {
-                //Clear the field if there is nothing selected
-                settings.Add(Settings.AppKey_DocTypes, string.Empty);
-            }
-
-			// adds the appSettings keys for the page-ids
+			// adds the appSettings keys for doctypes, templates, pageIds
+			settings.Add(Settings.AppKey_DocTypes, GetSringFromCheckboxList(cblDocTypes));
+			settings.Add(Settings.AppKey_Templates, GetSringFromCheckboxList(cblTemplates));
 			settings.Add(Settings.AppKey_PageIds, this.txtPageIds.Text.Trim());
 
 			foreach (var setting in settings)
 				this.Success.Visible = true;
 			}
 		}
+
+		private string GetSringFromCheckboxList(CheckBoxList cbl)
+		{
+			// loops through the selected list items
+			var selectedItems = new List<string>();
+			foreach (ListItem item in cbl.Items)
+			{
+				if (item.Selected)
+				{
+					selectedItems.Add(item.Value);
+				}
+			}
+
+			// create a csv string
+			if (selectedItems.Count > 0)
+			{
+				return string.Join(Settings.COMMA.ToString(), selectedItems.ToArray());
+			}
+
+			//Clear the field if there is nothing selected
+			return string.Empty;
+		}
 	}
 }

File Our.Umbraco.HttpsRedirect/Install/HttpsRedirectInstaller.ascx.designer.cs

         protected global::System.Web.UI.WebControls.CheckBoxList cblDocTypes;
         
         /// <summary>
+        /// cblTemplates control.
+        /// </summary>
+        /// <remarks>
+        /// Auto-generated field.
+        /// To modify move field declaration from designer file to code-behind file.
+        /// </remarks>
+        protected global::System.Web.UI.WebControls.CheckBoxList cblTemplates;
+        
+        /// <summary>
         /// txtPageIds control.
         /// </summary>
         /// <remarks>