/// <summary> /// Verify the UI template can be saved. /// </summary> /// <param name="invalidReason">A message describing why the validation failed. Set to <see cref="String.Empty" /> when /// validation succeeds.</param> /// <returns><c>true</c> if business rules for saving are satisfied, <c>false</c> otherwise</returns> private bool ValidateUiTemplateBeforeSave(out string invalidReason) { // TEST 1: Cannot save changes to the default template. if (CurrentUiTemplate.Name.Equals("Default", StringComparison.OrdinalIgnoreCase)) { var htmlHasChanged = !CurrentUiTemplate.HtmlTemplate.Equals(txtTemplate.Text, StringComparison.Ordinal); var scriptHasChanged = !CurrentUiTemplate.ScriptTemplate.Equals(txtScript.Text, StringComparison.Ordinal); if (htmlHasChanged || scriptHasChanged) { invalidReason = Resources.GalleryServer.Admin_Templates_Cannot_Modify_Default_Tmpl_Msg; return(false); } } // TEST 2: Verify no other template has the same name in this category. var tmpl = (from t in UiTemplates where t.TemplateType == CurrentUiTemplate.TemplateType && t.GalleryId == GalleryId && t.Name == txtTemplateName.Text && t.UiTemplateId != CurrentUiTemplate.UiTemplateId select t).FirstOrDefault(); if (tmpl != null) { invalidReason = Resources.GalleryServer.Admin_Templates_Cannot_Save_Duplicate_Name_Msg; return(false); } // TEST 3: Verify user isn't removing the last template from the root album. var rootAlbumId = Factory.LoadRootAlbumInstance(GalleryId).Id; var curTmplNotAssignedToRootAlbum = !tvUC.SelectedAlbumIds.Contains(rootAlbumId); // Need to use tvUC.SelectedAlbumIds instead of CurrentUiTemplate.RootAlbumIds because CurrentUiTemplate has not yet been unbound var noOtherTmplAssignedToRootAlbum = !UiTemplates.Any(t => t.TemplateType == CurrentUiTemplate.TemplateType && t.UiTemplateId != CurrentUiTemplate.UiTemplateId && t.RootAlbumIds.Contains(rootAlbumId)); if (curTmplNotAssignedToRootAlbum && noOtherTmplAssignedToRootAlbum) { invalidReason = Resources.GalleryServer.Admin_Templates_Cannot_Save_No_Tmpl_Msg; return(false); } // TEST 4: The default template cannot be renamed to something else. if (CurrentUiTemplate.Name.Equals("Default", StringComparison.OrdinalIgnoreCase) && !txtTemplateName.Text.Equals("Default", StringComparison.OrdinalIgnoreCase)) { invalidReason = Resources.GalleryServer.Admin_Templates_Cannot_Save_No_Default_Tmpl_Msg; return(false); } // All the tests pass, so return true. invalidReason = String.Empty; return(true); }
private string GetRightPaneTemplates() { var uiTemplate = UiTemplates.Get(UiTemplateType.RightPane, GetAlbum()); return(String.Format(CultureInfo.InvariantCulture, @" <script id='{0}' type='text/x-jsrender'> {1} </script> <script id='{2}' type='text/x-jsrender'> {3} </script> ", RightPaneHtmlTmplClientId, // 0 uiTemplate.HtmlTemplate, // 1 RightPaneScriptTmplClientId, // 2 uiTemplate.ScriptTemplate // 3 )); }
/// <summary> /// If the template being saved applies to all albums, then deactivate any sibling templates that apply to all albums. /// This saves the admin from having to bounce back to the original template, deactivate it, then return to the new /// template. It also reduces confusion because it prevents multiple templates from being assigned to the root album /// at the same time. /// </summary> /// <returns><c>true</c> if at least one template was deactivated, <c>false</c> otherwise.</returns> private bool DeactivateSiblingTemplatesOnSave() { var deactivatedTmpl = false; var rootAlbumId = Factory.LoadRootAlbumInstance(GalleryId).Id; if (CurrentUiTemplate.RootAlbumIds.Contains(rootAlbumId)) { // UI template is assigned to root album. If any other templates are also assigned to the root album, de-select it. foreach (var uiTemplate in UiTemplates.Where(t => t.TemplateType == CurrentUiTemplate.TemplateType && t.UiTemplateId != CurrentUiTemplate.UiTemplateId && t.RootAlbumIds.Contains(rootAlbumId))) { uiTemplate.RootAlbumIds.Remove(rootAlbumId); uiTemplate.Save(); deactivatedTmpl = true; } } return(deactivatedTmpl); }
/// <summary> /// Verify the UI template can be deleted. /// </summary> /// <param name="invalidReason">A message describing why the validation failed. Set to <see cref="String.Empty" /> when /// validation succeeds.</param> /// <returns><c>true</c> if business rules for deleting are satisfied, <c>false</c> otherwise</returns> private bool ValidateUiTemplateBeforeDelete(out string invalidReason) { // TEST 1: Cannot delete the default template. if (CurrentUiTemplate.Name.Equals("Default", StringComparison.OrdinalIgnoreCase)) { invalidReason = Resources.GalleryServer.Admin_Templates_Cannot_Modify_Default_Tmpl_Msg; return(false); } // TEST 2: Cannot delete a template if it leaves one ore more albums without a template var rootAlbumId = Factory.LoadRootAlbumInstance(GalleryId).Id; var noOtherTmplAssignedToRootAlbum = !UiTemplates.Any(t => t.TemplateType == CurrentUiTemplate.TemplateType && t.UiTemplateId != CurrentUiTemplate.UiTemplateId && t.RootAlbumIds.Contains(rootAlbumId)); if (noOtherTmplAssignedToRootAlbum) { invalidReason = Resources.GalleryServer.Admin_Templates_Cannot_Delete_No_Tmpl_Msg; return(false); } // All the tests pass, so return true. invalidReason = String.Empty; return(true); }