protected void createNewButton_OnClick(object sender, EventArgs e) { Hashtable metadataProblems = checkMetadataState(); if (metadataProblems.Count > 0) { RecordsTypeFieldMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__RECORDS_TYPE].WBxToString(); FunctionalAreaFieldMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__FUNCTIONAL_AREA].WBxToString(); WorkBoxShortTitleMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__WORK_BOX_SHORT_TITLE].WBxToString(); ReferenceIDMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__REFERENCE_ID].WBxToString();; ReferenceDateMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__REFERENCE_DATE].WBxToString();; SeriesTagFieldMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__SERIES_TAG].WBxToString(); OwningTeamFieldMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__OWNING_TEAM].WBxToString(); InvolvedTeamsFieldMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__INVOLVED_TEAMS].WBxToString(); pageRenderingRequired = true; } else { pageRenderingRequired = false; } // The event should only be processed if there is no other need to render the page again if (pageRenderingRequired) { renderPage(); } else { WBCollection collection = new WBCollection(WorkBoxCollectionUrl.Value); collection.Web.AllowUnsafeUpdates = true; WBUtils.logMessage("OK so we've set to allow unsafe updates of the WorkBoxCollectionWeb"); string selectedWorkBoxTemplateValue = WorkBoxTemplateID.Value; if (selectedWorkBoxTemplateValue == "") { selectedWorkBoxTemplateValue = WorkBoxTemplates.SelectedValue; } int templateID = Convert.ToInt32(selectedWorkBoxTemplateValue); WBTemplate template = collection.GetTypeByID(templateID); WBTeam owningTeam = new WBTeam(teams, OwningTeamUIControlValue.Value); WBTermCollection <WBTeam> involvedTeams = new WBTermCollection <WBTeam>(teams, InvolvedTeamsField.Text); Hashtable extraValues = null; extraValues = new Hashtable(); if (ReferenceID.Text != "") { extraValues.Add(WorkBox.COLUMN_NAME__REFERENCE_ID, ReferenceID.Text); } if (!ReferenceDate.IsDateEmpty) { extraValues.Add(WorkBox.COLUMN_NAME__REFERENCE_DATE, ReferenceDate.SelectedDate); } if (SeriesTagDropDownList.SelectedValue != "") { extraValues.Add(WorkBox.COLUMN_NAME__SERIES_TAG, SeriesTagDropDownList.SelectedValue); } if (functionalAreaFieldIsEditable) { extraValues.Add(WorkBox.COLUMN_NAME__FUNCTIONAL_AREA, FunctionalAreaField.Text); } else { extraValues.Add(WorkBox.COLUMN_NAME__FUNCTIONAL_AREA, workBoxRecordsType.DefaultFunctionalArea(functionalAreas).UIControlValue); } WBLogging.Generic.Unexpected("Owning team has values: " + owningTeam.Name + " " + owningTeam.Id); WorkBox newWorkBox = collection.RequestNewWorkBox(WorkBoxShortTitle.Text, "", template, owningTeam, involvedTeams, extraValues); if (newWorkBox == null) { string pageTitle = Uri.EscapeDataString("Failed to create new work box"); string pageText = Uri.EscapeDataString("Your request to create a new work box was not successful."); string redirectUrl = "WorkBoxFramework/GenericOKPage.aspx"; string queryString = "pageTitle=" + pageTitle + "&pageText=" + pageText; SPUtility.Redirect(redirectUrl, SPRedirectFlags.RelativeToLayoutsPage, Context, queryString); } collection.Web.AllowUnsafeUpdates = false; using (SPLongOperation longOperation = new SPLongOperation(this.Page)) { longOperation.LeadingHTML = "Creating your new work box."; longOperation.TrailingHTML = "Please wait while the work box is being created."; longOperation.Begin(); newWorkBox.Open("Requested via NewWorkBox.aspx."); if (relatedWorkBox != null) { switch (RelationType.Value) { case WorkBox.RELATION_TYPE__DYNAMIC: break; case WorkBox.RELATION_TYPE__MANUAL_LINK: { relatedWorkBox.LinkToWorkBox(newWorkBox, WorkBox.RELATION_TYPE__MANUAL_LINK); break; } case WorkBox.RELATION_TYPE__CHILD: { relatedWorkBox.LinkToWorkBox(newWorkBox, WorkBox.RELATION_TYPE__CHILD); newWorkBox.LinkToWorkBox(relatedWorkBox, WorkBox.RELATION_TYPE__PARENT); break; } default: { WBUtils.shouldThrowError("Did not recognise the relation type: " + RelationType.Value); break; } } relatedWorkBox.Dispose(); } collection.Dispose(); string html = "<h1>Successfully created</h1><p>Your new work box has been successfully created.</p>"; html += String.Format("<p>Go to your new work box: <a href=\"#\" onclick=\"javascript: dialogReturnOKAndRedirect('{0}');\">{1}</a></p>", newWorkBox.Url, newWorkBox.Title); string pageTitle = Uri.EscapeDataString("Created new work box"); string pageText = Uri.EscapeDataString(html); string okPageUrl = "WorkBoxFramework/GenericOKPage.aspx"; string refreshQueryString = "?recordsTypeGUID=" + newWorkBox.RecordsType.Id.ToString(); newWorkBox.Dispose(); string queryString = "pageTitle=" + pageTitle + "&pageText=" + pageText + "&refreshQueryString=" + refreshQueryString; longOperation.End(okPageUrl, SPRedirectFlags.RelativeToLayoutsPage, Context, queryString); } } }
private void renderPage() { if (pageRendered) { return; } WBLogging.Generic.Unexpected("Rendering 'New Work Box' page"); WBCollection collection = new WBCollection(WorkBoxCollectionUrl.Value); CreateNewWorkBoxText.Text = workBoxRecordsType.CreateNewWorkBoxText; RecordsType.Text = workBoxRecordsType.FullPath.Replace("/", " / "); string namingConvention = workBoxRecordsType.WorkBoxNamingConvention; string uniqueIDprefix = workBoxRecordsType.WorkBoxUniqueIDPrefix; if (uniqueIDprefix != "") { namingConvention = namingConvention.Replace("<Unique ID Prefix>", uniqueIDprefix); namingConvention = namingConvention.Replace("<UID Prefix>", uniqueIDprefix); } WorkBoxNamingConvention.Text = namingConvention.Replace("<", "<").Replace(">", ">"); DataView templates = GetTemplatesDataSource(collection, workBoxRecordsType); if (templates.Count == 0) { NoTemplatesError.Text = "There are no templates for this work box records type!"; onlyOneWorkBoxTemplate = true; } else { if (templates.Count == 1) { DataRow theTemplate = templates.Table.Rows[0]; onlyOneWorkBoxTemplate = true; WorkBoxTemplate.Text = theTemplate["WorkBoxTemplateTextField"].WBxToString(); WorkBoxTemplateID.Value = theTemplate["WorkBoxTemplateValueField"].WBxToString(); } else { onlyOneWorkBoxTemplate = false; WorkBoxTemplates.DataSource = templates; WorkBoxTemplates.DataTextField = "WorkBoxTemplateTextField"; WorkBoxTemplates.DataValueField = "WorkBoxTemplateValueField"; WorkBoxTemplates.DataBind(); WBTemplate defaultTemplate = collection.DefaultTemplate(workBoxRecordsType); if (defaultTemplate != null) { WorkBoxTemplates.SelectedValue = defaultTemplate.ID.ToString(); } // We're going to use the fact that this hidden field is blank to assume // that there was more than one value: WorkBoxTemplateID.Value = ""; } } if (functionalAreaFieldIsEditable) { functionalAreas.InitialiseTaxonomyControl(FunctionalAreaField, WorkBox.COLUMN_NAME__FUNCTIONAL_AREA, true, true, null); if (!IsPostBack && functionalAreaInitialValue != null) { FunctionalAreaField.Text = functionalAreaInitialValue; } } else { ReadOnlyFunctionalAreaField.Text = workBoxRecordsType.DefaultFunctionalArea(functionalAreas).Names(); } // teams.InitialiseTaxonomyControl(OwningTeamField, WorkBox.COLUMN_NAME__OWNING_TEAM, false); teams.InitialiseTaxonomyControl(InvolvedTeamsField, WorkBox.COLUMN_NAME__INVOLVED_TEAMS, true); showShortTitle = workBoxRecordsType.WorkBoxShortTitleRequirement != WBRecordsType.METADATA_REQUIREMENT__HIDDEN; if (showShortTitle) { if (workBoxRecordsType.IsWorkBoxShortTitleRequired) { ShortTitleTitle.Text = "Short Title" + WBConstant.REQUIRED_ASTERISK; } else { ShortTitleTitle.Text = "Short Title (optional)"; } ShortTitleDescription.Text = workBoxRecordsType.WorkBoxShortTitleDescription; } showReferenceID = workBoxRecordsType.WorkBoxReferenceIDRequirement != WBRecordsType.METADATA_REQUIREMENT__HIDDEN; if (showReferenceID) { if (workBoxRecordsType.IsWorkBoxReferenceIDRequired) { ReferenceIDTitle.Text = "Reference ID" + WBConstant.REQUIRED_ASTERISK; } else { ReferenceIDTitle.Text = "Reference ID (optional)"; } ReferenceIDDescription.Text = workBoxRecordsType.WorkBoxReferenceIDDescription; // ReferenceID.Text = sourceDocAsItem.WBxGetColumnAsString(WorkBox.COLUMN_NAME__REFERENCE_ID); } showReferenceDate = workBoxRecordsType.WorkBoxReferenceDateRequirement != WBRecordsType.METADATA_REQUIREMENT__HIDDEN; if (showReferenceDate) { // Setting the local to a value that should make the date format DD/MM/YYYY // ReferenceDate.LocaleId = 2057; if (workBoxRecordsType.IsWorkBoxReferenceDateRequired) { ReferenceDateTitle.Text = "Reference Date" + WBConstant.REQUIRED_ASTERISK; } else { ReferenceDateTitle.Text = "Reference Date (optional)"; } ReferenceDateDescription.Text = workBoxRecordsType.WorkBoxReferenceDateDescription; /* * if (sourceDocAsItem.WBxColumnHasValue(WorkBox.COLUMN_NAME__REFERENCE_DATE)) * { * ReferenceDate.SelectedDate = (DateTime)sourceDocAsItem[WorkBox.COLUMN_NAME__REFERENCE_DATE]; * } * else * { * } * */ } showSeriesTag = workBoxRecordsType.WorkBoxSeriesTagRequirement != WBRecordsType.METADATA_REQUIREMENT__HIDDEN; if (showSeriesTag) { if (workBoxRecordsType.IsWorkBoxSeriesTagRequired) { SeriesTagTitle.Text = "Series Tag" + WBConstant.REQUIRED_ASTERISK; } else { SeriesTagTitle.Text = "Series Tag (optional)"; } SeriesTagDescription.Text = workBoxRecordsType.DocumentSeriesTagDescription; SeriesTagDropDownList.DataSource = GetSeriesTagsDataSource(workBoxRecordsType.WorkBoxSeriesTagParentTerm(seriesTags)); SeriesTagDropDownList.DataTextField = "SeriesTagTermName"; SeriesTagDropDownList.DataValueField = "SeriesTagTermUIControlValue"; SeriesTagDropDownList.DataBind(); if (!IsPostBack && seriesTagInitialValue != "") { if (SeriesTagDropDownList.Items.FindByValue(seriesTagInitialValue) != null) { SeriesTagDropDownList.SelectedValue = seriesTagInitialValue; } } } ErrorMessageLabel.Text = errorMessage; if (functionalAreaFieldIsEditable) { FunctionalAreaField.Focus(); } else { if (!onlyOneWorkBoxTemplate) { WorkBoxTemplates.Focus(); } else { if (showShortTitle) { WorkBoxShortTitle.Focus(); } else { // Just to have the focus somewhere: InvolvedTeamsField.Focus(); } } } if (relatedWorkBox != null) { relatedWorkBox.Dispose(); } collection.Dispose(); pageRendered = true; }