void BindSubjectTagForm() { var selectedSubjectTag = _subjectTags.GetSelectedTermByPath(tvAllSubjectTags.SelectedNode.ValuePath); if (selectedSubjectTag != null) { WBSubjectTag subjectTag = null; subjectTag = new WBSubjectTag(_subjectTags, selectedSubjectTag); if (subjectTag == null) { return; // something better! } if (String.IsNullOrEmpty(subjectTag.PageContent)) { litPageContent.Text = subjectTag.Description; } else { litPageContent.Text = subjectTag.PageContent; } litInternalContact.Text = subjectTag.InternalContactLoginName; litExternalContact.Text = subjectTag.ExternalContact; taxTeams.Text = subjectTag.TeamsWithPermissionToEditUIControlValue; } }
/// <summary> /// Updates and existing subject tag /// </summary> void UpdateTag() { // It appears that a TaxonomySession will always run as the current user, even if elevated. // See: http://scle.me/1skLGCY var currentSiteGuid = SPContext.Current.Site.ID; var oldContext = HttpContext.Current; HttpContext.Current = null; SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite elevatedSite = new SPSite(currentSiteGuid)) { WBTaxonomy wbTax = WBTaxonomy.GetSubjectTags(elevatedSite); Term rootSubjectTagTerm = wbTax.GetSelectedTermByPath(_path); WBSubjectTag subjectTag = null; if (rootSubjectTagTerm != null) { subjectTag = new WBSubjectTag(wbTax, rootSubjectTagTerm); if (subjectTag == null) { return; } } // Page content subjectTag.PageContent = htmlDescription.Html; // Internal Contact SPUser pickedUser = ppInternalContact.WBxGetSingleResolvedUser(elevatedSite.RootWeb); if (pickedUser != null) { subjectTag.InternalContactLoginName = pickedUser.LoginName; } else { subjectTag.InternalContactLoginName = string.Empty; } // External Contact subjectTag.ExternalContact = htmlExternalContact.Html; // Tag Name subjectTag.Name = txtEdit_CurrentTagName.Text; subjectTag.Update(); } }); HttpContext.Current = oldContext; }
/* Added by Steve Clements to support Add / Edit tag functionality */ /// <summary> /// Setup the properties for the add / edit buttons /// </summary> void SetupAddEditButtons(WBSubjectTag tag) { canEditOrCreate = false; if (tag == null) { return; } WBTaxonomy teamsTax = WBTaxonomy.GetTeams(SPContext.Current.Site); if (tag.TeamsWithPermissionToEdit(teamsTax).WBxContainsCurrentUserAsTeamMember()) { canEditOrCreate = true; // properties on the button var mmspath = String.Concat(webPart.RootSubjectTag, Request.QueryString["AdditionalPath"] ?? String.Empty); btnNewSubjectTag.Attributes.Add("data-mmspath", mmspath); btnEditSubjectTag.Attributes.Add("data-mmspath", mmspath); } }
protected void btnSave_Click(object sender, EventArgs e) { // Save permission group changes - its the only thing editable at the moment. var selectedSubjectTag = _subjectTags.GetSelectedTermByPath(tvAllSubjectTags.SelectedNode.ValuePath); if (selectedSubjectTag != null) { WBSubjectTag subjectTag = null; subjectTag = new WBSubjectTag(_subjectTags, selectedSubjectTag); if (subjectTag == null) { return; // something better! } subjectTag.TeamsWithPermissionToEditUIControlValue = taxTeams.Text; subjectTag.Update(); lblPageMessage.Text = "Saved"; } }
/// <summary> /// Initialise the form /// </summary> void BindForm() { if (String.IsNullOrEmpty(_path)) { return; } SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite elevatedSite = new SPSite(SPContext.Current.Site.ID)) { WBTaxonomy subjectTags = WBTaxonomy.GetSubjectTags(elevatedSite); Term rootSubjectTagTerm = subjectTags.GetSelectedTermByPath(_path); WBSubjectTag subjectTag = null; if (rootSubjectTagTerm != null) { subjectTag = new WBSubjectTag(subjectTags, rootSubjectTagTerm); if (subjectTag == null) { return; } } // DOes the current user have permission? WBTaxonomy teamsTax = WBTaxonomy.GetTeams(elevatedSite); if (!subjectTag.TeamsWithPermissionToEdit(teamsTax).WBxContainsCurrentUserAsTeamMember()) { Response.Redirect("AccessDenied.html"); } if (!CreateNew) // Edit Mode { txtTagName.Text = subjectTag.Name; txtTagName.ReadOnly = true; // To support existing terms where content is stored in the description, first attempt to read from the the multi-property array Page Content, // then fall back to the description. Changes will be saved to the multi-property array. if (String.IsNullOrEmpty(subjectTag.PageContent)) { htmlDescription.Field.Html = subjectTag.Description; } else { htmlDescription.Field.Html = subjectTag.PageContent; } ppInternalContact.WBxInitialise(subjectTag.InternalContact(SPContext.Current.Web)); // It's an option to use the RootWeb of the elevated site here, I have used SPContext for consistency htmlExternalContact.Field.Html = subjectTag.ExternalContact; // Added this due to issue with the Html editor in IE in a modal dialog! If the value is null, you cannot click in to start editing. if (String.IsNullOrEmpty(htmlExternalContact.Field.Html)) { htmlExternalContact.Field.Html = " "; } if (String.IsNullOrEmpty(htmlDescription.Field.Html)) { htmlDescription.Field.Html = " "; } } else { // Nothing to do if creating a new child term } } }); }
/// <summary> /// Creates a new Subject Tag /// </summary> void CreateNewTag() { // It appears that a TaxonomySession will always run as the current user, even if elevated. // See: http://scle.me/1skLGCY var currentSiteGuid = SPContext.Current.Site.ID; var oldContext = HttpContext.Current; HttpContext.Current = null; SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite elevatedSite = new SPSite(currentSiteGuid)) { WBTaxonomy wbTax = WBTaxonomy.GetSubjectTags(elevatedSite); _path = String.Concat(_path, "/", txtTagName.Text); Term rootSubjectTagTerm = wbTax.GetSelectedTermByPath(_path); // Try and get the tag, but don't auto create WBSubjectTag subjectTag = null; if (rootSubjectTagTerm != null) { lblValidationMessage.Text = "The term you are trying to create already exists"; } else { rootSubjectTagTerm = wbTax.GetSelectedTermByPath(_path, true); // Now create } if (rootSubjectTagTerm != null) { subjectTag = new WBSubjectTag(wbTax, rootSubjectTagTerm); if (subjectTag == null) { return; } subjectTag.PageContent = htmlDescription.Html; if (htmlExternalContact.Html.ToLower() != "<div> </div>") { subjectTag.ExternalContact = htmlExternalContact.Html; } SPUser pickedUser = ppInternalContact.WBxGetSingleResolvedUser(elevatedSite.RootWeb); if (pickedUser != null) { subjectTag.InternalContactLoginName = pickedUser.LoginName; } /*if (ppInternalContact.Entities != null && ppInternalContact.Entities.Count > 0) * { * PickerEntity pe = (PickerEntity)ppInternalContact.Entities[0]; * subjectTag.InternalContactLoginName = pe.DisplayText; * }*/ wbTax.CommitAll(); } else { lblValidationMessage.Text = "Your new tag could not be created, please contact support"; } } }); HttpContext.Current = oldContext; }
protected void Page_Load(object sender, EventArgs e) { webPart = this.Parent as ViewSubjectPages; DocumentsForSubject.AllowSorting = true; DocumentsForSubject.Sorting += new GridViewSortEventHandler(DocumentsForSubject_Sorting); DocumentsForSubject.AllowPaging = true; DocumentsForSubject.PageIndexChanging += new GridViewPageEventHandler(DocumentsForSubject_PageIndexChanging); DocumentsForSubject.PagerSettings.Mode = PagerButtons.Numeric; DocumentsForSubject.PagerSettings.Position = PagerPosition.Bottom; DocumentsForSubject.PagerSettings.PageButtonCount = 20; DocumentsForSubject.PagerSettings.Visible = true; DocumentsForSubject.PageSize = 20; // this odd statement is required in order to get the pagination to work with an SPGridView! DocumentsForSubject.PagerTemplate = null; showAtoZ = webPart.ShowAToZ; showFilters = false; string additionalPath = ""; if (String.IsNullOrEmpty(webPart.RootSubjectTag)) { PageName.Text = "<i>(Web part not yet configured)</i>"; return; } // Let's capture the information about what we should be looking at: pickedLetter = Request.QueryString["Letter"]; if (!String.IsNullOrEmpty(pickedLetter)) { viewingALetter = true; } additionalPath = Request.QueryString["AdditionalPath"]; if (additionalPath == null) { additionalPath = ""; } recordsTypeFullPath = Request.QueryString["RecordsType"]; if (String.IsNullOrEmpty(recordsTypeFullPath)) { recordsTypeFullPath = NO_RECORDS_TYPE_SELECTED; } if (webPart.ShowRecordTypes) { WBLogging.Debug("ViewSubjectPages: Using records types. Currently set as: " + recordsTypeFullPath); } else { WBLogging.Debug("ViewSubjectPages: Not using records types"); } FullSubjectTagPath = webPart.RootSubjectTag + additionalPath; WBLogging.Debug("FullSubjectTagPath = " + FullSubjectTagPath); WBTaxonomy subjectTags = WBTaxonomy.GetSubjectTags(SPContext.Current.Site); Term rootSubjectTagTerm = subjectTags.GetSelectedTermByPath(webPart.RootSubjectTag); WBTerm rootSubjectTag = null; if (rootSubjectTagTerm != null) { rootSubjectTag = new WBTerm(subjectTags, rootSubjectTagTerm); } if (rootSubjectTag == null) { PageName.Text = "<i>(Could not find the root subject tag with path: " + webPart.RootSubjectTag + ")</i>"; return; } Term pageSubjectTagTerm = subjectTags.GetSelectedTermByPath(FullSubjectTagPath); //SC: WBTerm pageSubjectTag = null; WBSubjectTag pageSubjectTag = null; if (pageSubjectTagTerm != null) { //SC: pageSubjectTag = new WBTerm(subjectTags, pageSubjectTagTerm); pageSubjectTag = new WBSubjectTag(subjectTags, pageSubjectTagTerm); } if (pageSubjectTag == null) { PageName.Text = "<i>(Could not find the page subject tag with path: " + FullSubjectTagPath + ")</i>"; return; } string html = ""; string recordsTypeParameter = ""; if (webPart.ShowRecordTypes) { recordsTypeParameter = "&RecordsType=" + recordsTypeFullPath; } //webPart.OnlyTermsWithDocuments = false; if (webPart.OnlyTermsWithDocuments) { BuildListOfAllowedTerms(); } if (viewingALetter) { PageName.Text = "<a href='?'>" + webPart.RootSubjectTag + "</a> - " + pickedLetter; PageSubjectTagDescription.Text = "You are viewing a list of all of the subjects with the letter '" + pickedLetter + "'."; Dictionary <String, String> allTermPaths = new Dictionary <string, string>(); AddAllTermsThatMatch(pickedLetter, "", rootSubjectTagTerm, allTermPaths); if (allTermPaths.Count > 0) { List <String> terms = new List <String>(allTermPaths.Keys); terms.Sort(); List <String> termsWithLetterFirst = new List <String>(); List <String> remainingTerms = new List <String>(); foreach (String term in terms) { if (term.IndexOf(pickedLetter) == 0) { termsWithLetterFirst.Add(term); } else { remainingTerms.Add(term); } } foreach (String term in termsWithLetterFirst) { html += "<div class='lbi-a-to-z-child-subject'><a href='?AdditionalPath=" + allTermPaths[term] + recordsTypeParameter + "'>" + term + "</a></div>\n"; } if (remainingTerms.Count > 0) { html += "<div> </div>\n"; foreach (String term in remainingTerms) { html += "<div class='lbi-a-to-z-child-subject'><a href='?AdditionalPath=" + allTermPaths[term] + recordsTypeParameter + "'>" + term + "</a></div>\n"; } } } else { html += "<p>There were no terms found for the letter '" + pickedLetter + "'.</p>"; } } else { List <String> names = new List <String>(FullSubjectTagPath.Split('/')); List <String> path = new List <String>(names); path.RemoveAt(0); String justRecordsType = ""; if (!String.IsNullOrEmpty(recordsTypeFullPath) && recordsTypeFullPath != NO_RECORDS_TYPE_SELECTED) { justRecordsType = GetJustRecordsTypeName(recordsTypeFullPath); } PageName.Text = BuildPageNamePath(names, path, justRecordsType); //SC: PageSubjectTagDescription.Text = pageSubjectTag.Description; if (String.IsNullOrEmpty(pageSubjectTag.PageContent)) { PageSubjectTagDescription.Text = pageSubjectTag.Description; } else { PageSubjectTagDescription.Text = pageSubjectTag.PageContent; } // Contacts if (!String.IsNullOrEmpty(pageSubjectTag.InternalContactLoginName)) { panInternalContact.Visible = true; var user = pageSubjectTag.InternalContact(SPContext.Current.Web); if (user != null) { // Bind user to control for presentation ((WBFUser)wbfInternalContact).User = user; } } else { panInternalContact.Visible = false; } if (!pageSubjectTag.ExternalContact.WBxIsHtmlFieldEmpty()) { panExternalContact.Visible = true; litExternalContact.Text = pageSubjectTag.ExternalContact; } else { panExternalContact.Visible = false; } foundChildSubjectTags = false; onRootOfAtoZ = (webPart.ShowAToZ && pageSubjectTag.Name == webPart.RootSubjectTag); bool showDocuments = true; if (!onRootOfAtoZ) { // OK so now we need to find the sub terms and put them in order. List <String> termLabels = new List <String>(); foreach (Term child in pageSubjectTag.Term.Terms) { if (child.IsAvailableForTagging && CheckTermIsAllowed(child)) { termLabels.Add(child.Name); foundChildSubjectTags = true; } } if (termLabels.Count > 0) { if (webPart.OnlyShowDocumentsOnLeafPages) { showDocuments = false; } termLabels.Sort(); foreach (String label in termLabels) { html += "<div class='lbi-a-to-z-child-subject'><a href='?AdditionalPath=" + additionalPath + "/" + label + recordsTypeParameter + "'>" + label + "</a></div>\n"; } } else { // OK so there are no further subject tags, but should we be presenting records types: if (webPart.ShowRecordTypes) { if (recordsTypeFullPath == NO_RECORDS_TYPE_SELECTED) { Dictionary <String, String> recordsTypesToList = FindRecordsTypesToList(); if (recordsTypesToList.Count > 0) { if (webPart.OnlyShowDocumentsOnLeafPages) { showDocuments = false; } List <String> justRecordsTypes = new List <String>(recordsTypesToList.Keys); justRecordsTypes.Sort(); foreach (String recordsType in justRecordsTypes) { String recordsTypePath = recordsTypesToList[recordsType]; html += "<div class='lbi-a-to-z-child-subject'><a href='?AdditionalPath=" + additionalPath + "&RecordsType=" + recordsTypePath + "'>" + recordsType + "</a></div>\n"; } } } } } } else { if (webPart.ShowDocumentsOnAtoZRootPage) { showDocuments = true; } else { showDocuments = false; } } if (showDocuments) { RefreshBoundDocumentsList(); } } if (!String.IsNullOrEmpty(html)) { //TableOfChildSubjects.Text = String.Concat("<h3 class='wbf-subject-tag-section-head'>Child Subject Tags</h3>", html); TableOfChildSubjects.Text = html; } // Added by Steve Clements SetupAddEditButtons(pageSubjectTag); }