Commits

ScrewTurn Wiki committed 02088d1

Hide template selection if there aren't any templates. Auto-select category matching selected template. Suppress 'are you sure' message when selecting a template if no text entered. Fix bug when reselecting a template. Fix #360.

Comments (0)

Files changed (4)

AssemblyVersion.cs

 //
 // You can specify all the values or you can default the Revision and Build Numbers 
 // by using the '*' as shown below:
-[assembly: AssemblyVersion("3.0.0.341")]
-[assembly: AssemblyFileVersion("3.0.0.341")]
+[assembly: AssemblyVersion("3.0.0.342")]
+[assembly: AssemblyFileVersion("3.0.0.342")]

WebApplication/Edit.aspx

 	
 		var submitted = false;
 		function __UnloadPage(e) {
-			if (!submitted) {
-				e.returnValue = " ";
+		    if (!submitted) {
+		        if (document.getElementById('EditorDiv').getElementsByTagName('textarea')[0].value.length != 0) {
+				    e.returnValue = " ";
+				}
 			}
 		}
 
 		function __SetSubmitted() {
 			submitted = true;
+        }
+		
+		function __RequestConfirmIfNotEmpty() {
+		    if (document.getElementById('EditorDiv').getElementsByTagName('textarea')[0].value.length != 0) {
+		      return(__RequestConfirm());
+		    }
 		}
 		
 	// -->
 			Display="Dynamic" ControlToValidate="txtTitle" ValidationGroup="nametitle" meta:resourcekey="rfvTitleResource1" />
 	</div>
 	
-	<div id="TemplatesDiv">
+	<div id="TemplatesDiv" runat="server">
 		<small>
 			<anthem:LinkButton ID="btnTemplates" runat="server" Text="Content Templates..." OnClick="btnTemplates_Click" 
 				AutoUpdateAfterCallBack="True" meta:resourcekey="btnTemplatesResource1" UpdateAfterCallBack="True" />
 				</div>
 				<small>
 					<anthem:LinkButton ID="btnUseTemplate" runat="server" Text="Use Template" ToolTip="Use this Template (replace current content)"
-						CausesValidation="False" AutoUpdateAfterCallBack="True" Visible="False" PreCallBackFunction="__RequestConfirm" OnClick="btnUseTemplate_Click" 
+						CausesValidation="False" AutoUpdateAfterCallBack="True" Visible="False" PreCallBackFunction="__RequestConfirmIfNotEmpty" OnClick="btnUseTemplate_Click" 
 						meta:resourcekey="btnUseTemplateResource1" UpdateAfterCallBack="True" />
 					&bull;
 					<anthem:LinkButton ID="btnCancelTemplate" runat="server" Text="Cancel" ToolTip="Close the Templates toolbar"

WebApplication/Edit.aspx.cs

 			// Check and manage editing collisions
 			ManageEditingCollisions();
 
-			// Display draft status
 			if(!Page.IsPostBack) {
+
+				// Hide templates selection if there aren't any
+				if(Templates.GetTemplates().Count == 0)	{
+					TemplatesDiv.Visible = false;
+				}
+
+				// Display draft status
 				ManageDraft();
+
 			}
 
 			// Setup session refresh iframe
 			foreach(ContentTemplate temp in Templates.GetTemplates()) {
 				lstTemplates.Items.Add(new ListItem(temp.Name, temp.Name));
 			}
+			// Hide select button and preview text because the user hasn't selected a template yet
+			btnUseTemplate.Visible = false;
+			lblTemplatePreview.Text = "";
 		}
 
 		protected void lstTemplates_SelectedIndexChanged(object sender, EventArgs e) {
 
 			editor.SetContent(template.Content, Settings.UseVisualEditorAsDefault);
 			btnCancelTemplate_Click(sender, e);
+			// If there's a category matching the selected template name, select it automatically
+			for (int i = 0; i < lstCategories.Items.Count; i++)	{
+				if (lstCategories.Items[i].Value.ToLower().Trim() == lstTemplates.SelectedValue.ToLower().Trim()) {
+					lstCategories.Items[i].Selected = true;
+				}
+			}
 		}
 
 		protected void btnCancelTemplate_Click(object sender, EventArgs e) {

WebApplication/Edit.aspx.designer.cs

 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:2.0.50727.4927
+//     Runtime Version:2.0.50727.3074
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
         protected global::System.Web.UI.WebControls.RequiredFieldValidator rfvTitle;
         
         /// <summary>
+        /// TemplatesDiv control.
+        /// </summary>
+        /// <remarks>
+        /// Auto-generated field.
+        /// To modify move field declaration from designer file to code-behind file.
+        /// </remarks>
+        protected global::System.Web.UI.HtmlControls.HtmlGenericControl TemplatesDiv;
+        
+        /// <summary>
         /// btnTemplates control.
         /// </summary>
         /// <remarks>