void nameElem_Click(object sender, EventArgs e) { // Check 'EditForm' permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.form", "EditForm")) { RedirectToCMSDeskAccessDenied("cms.form", "EditForm"); } // Code name validation string err = new Validator().IsIdentificator(nameElem.CodeName, GetString("general.erroridentificatorformat")).Result; if (err != String.Empty) { lblError.Visible = true; lblError.Text = err; return; } // Checking for duplicate items DataSet ds = AlternativeFormInfoProvider.GetAlternativeForms("FormName='" + nameElem.CodeName + "' AND FormClassID=" + classId, null); if (!DataHelper.DataSourceIsEmpty(ds)) { lblError.Visible = true; lblError.Text = GetString("general.codenameexists"); return; } // Create new info object AlternativeFormInfo afi = new AlternativeFormInfo(); afi.FormID = 0; afi.FormGUID = Guid.NewGuid(); afi.FormClassID = classId; afi.FormName = nameElem.CodeName; afi.FormDisplayName = nameElem.DisplayName; AlternativeFormInfoProvider.SetAlternativeFormInfo(afi); // Required to log staging task, alternative form is not binded to bizform as child using (CMSActionContext context = new CMSActionContext()) { context.CreateVersion = false; // Log synchronization SynchronizationHelper.LogObjectChange(bfi, TaskTypeEnum.UpdateObject); } URLHelper.Redirect("AlternativeForms_Frameset.aspx?formid=" + formId.ToString() + "&altformid=" + afi.FormID + "&saved=1"); }
/// <summary> /// After form definition update event handler. /// </summary> private void fieldEditor_OnAfterDefinitionUpdate(object sender, EventArgs e) { // Perform OnBeforeSave if defined if (OnBeforeSave != null) { OnBeforeSave(this, EventArgs.Empty); } // Stop processing if set from outside if (StopProcessing) { return; } // Get alternative form info object and data class info object AlternativeFormInfo afi = AlternativeFormInfoProvider.GetAlternativeFormInfo(mAlternativeFormId); if (afi != null) { DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(afi.FormClassID); if (dci != null) { string formDefinition = dci.ClassFormDefinition; if (afi.FormCoupledClassID > 0) { // Combine form definitions of class and its coupled class DataClassInfo coupledDci = DataClassInfoProvider.GetDataClassInfo(afi.FormCoupledClassID); if (coupledDci != null) { formDefinition = FormHelper.MergeFormDefinitions(formDefinition, coupledDci.ClassFormDefinition); } } // Compare original and alternative form definitions - store differences only afi.FormDefinition = FormHelper.GetFormDefinitionDifference(formDefinition, fieldEditor.FormDefinition, true); // Update alternative form info in database AlternativeFormInfoProvider.SetAlternativeFormInfo(afi); } else { ShowError(GetString("general.invalidid")); } } // Perform OnAfterSave if defined if (OnAfterSave != null) { OnAfterSave(this, EventArgs.Empty); } }
/// <summary> /// Click event - updates new values. /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Params</param> void btnOK_Click(object sender, EventArgs e) { // Code name validation string err = new Validator().IsIdentificator(txtCodeName.Text, GetString("general.erroridentificatorformat")).Result; if (err != String.Empty) { lblError.Visible = true; lblError.Text = err; lblInfo.Visible = false; return; } // Validate form id AlternativeFormInfo afi = AlternativeFormInfoProvider.GetAlternativeFormInfo(altFormId); EditedObject = afi; if (afi == null) { return; } // Checking for duplicate items DataSet ds = AlternativeFormInfoProvider.GetAlternativeForms("FormName='" + SqlHelperClass.GetSafeQueryString(txtCodeName.Text, false) + "' AND FormClassID=" + afi.FormClassID, null); if (!DataHelper.DataSourceIsEmpty(ds)) { if (!((ds.Tables.Count == 1) && (ds.Tables[0].Rows.Count == 1) && ( ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["FormID"], 0) == altFormId))) { lblError.Visible = true; lblError.Text = GetString("general.codenameexists"); lblInfo.Visible = false; return; } } afi.FormDisplayName = txtDisplayName.Text; afi.FormName = txtCodeName.Text; AlternativeFormInfoProvider.SetAlternativeFormInfo(afi); lblInfo.Visible = true; lblInfo.Text = GetString("general.changessaved"); // Reload header if changes were saved ScriptHelper.RefreshTabHeader(Page, null); }
protected void nameElem_Click(object sender, EventArgs e) { // Code name validation string err = new Validator().IsIdentificator(nameElem.CodeName, GetString("general.erroridentificatorformat")).Result; if (err != String.Empty) { lblError.Visible = true; lblError.Text = err; return; } // Checking for duplicate items DataSet ds = AlternativeFormInfoProvider.GetAlternativeForms("FormName='" + SqlHelperClass.GetSafeQueryString(nameElem.CodeName, false) + "' AND FormClassID=" + classId, null); if (!DataHelper.DataSourceIsEmpty(ds)) { lblError.Visible = true; lblError.Text = GetString("general.codenameexists"); return; } // Create new info object AlternativeFormInfo alternativeFormInfo = new AlternativeFormInfo(); alternativeFormInfo.FormID = 0; alternativeFormInfo.FormGUID = Guid.NewGuid(); alternativeFormInfo.FormClassID = classId; alternativeFormInfo.FormName = nameElem.CodeName; alternativeFormInfo.FormDisplayName = nameElem.DisplayName; try { AlternativeFormInfoProvider.SetAlternativeFormInfo(alternativeFormInfo); URLHelper.Redirect("AlternativeForms_Frameset.aspx?classid=" + classId + "&altformid=" + alternativeFormInfo.FormID + "&saved=1"); } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; } }
void btnOK_Click(object sender, EventArgs e) { // Code name validation string err = new Validator().IsIdentificator(this.txtCodeName.Text, GetString("general.erroridentificatorformat")).Result; if (err != String.Empty) { lblError.Visible = true; lblError.Text = err; return; } // Checking for duplicate items DataSet ds = AlternativeFormInfoProvider.GetAlternativeForms("FormName='" + SqlHelperClass.GetSafeQueryString(this.txtCodeName.Text, false) + "' AND FormClassID=" + classId, null); if (!DataHelper.DataSourceIsEmpty(ds)) { lblError.Visible = true; lblError.Text = GetString("general.codenameexists"); return; } // Create new info object AlternativeFormInfo afi = new AlternativeFormInfo(); afi.FormID = 0; afi.FormGUID = Guid.NewGuid(); afi.FormClassID = classId; afi.FormName = this.txtCodeName.Text; afi.FormDisplayName = this.txtDisplayName.Text; DataClassInfo dci = DataClassInfoProvider.GetDataClass(SiteObjectType.USERSETTINGS); if (dci != null) { afi.FormCoupledClassID = (this.chkCombineUserSettings.Checked) ? dci.ClassID : 0; } AlternativeFormInfoProvider.SetAlternativeFormInfo(afi); URLHelper.Redirect("Frameset.aspx?classid=" + classId + "&altformid=" + afi.FormID + "&saved=1"); }
// Contains initialization code that is executed when the application starts protected override void OnInit() { base.OnInit(); // Custom Relationship Name logging since adhoc is disabled in staging by default (since usually tied to page type) RelationshipNameInfo.TYPEINFO.Events.Insert.After += RelationshipName_Insert_After; RelationshipNameInfo.TYPEINFO.Events.Update.After += RelationshipName_Update_After; RelationshipNameInfo.TYPEINFO.Events.Delete.After += RelationshipName_Delete_After; RelationshipNameSiteInfo.TYPEINFO.Events.Insert.After += RelationshipNameSiteInfo_Insert_After; RelationshipNameSiteInfo.TYPEINFO.Events.Delete.After += RelationshipNameSiteInfo_Delete_After; // Since normally a page is "Saved" (changed) when you handle ad-hoc relationships, must also handle triggering the update on the document RelationshipInfo.TYPEINFO.Events.Insert.After += Relationship_Insert_Or_Delete_After; RelationshipInfo.TYPEINFO.Events.Delete.After += Relationship_Insert_Or_Delete_After; // Add in events to handle Document-bound node categories, or adjust to synchronize manually if (DataHelper.GetNotEmpty(SettingsKeyInfoProvider.GetValue(new SettingsKeyName("NodeCategoryStagingMode")), "WithDocument") == "WithDocument") { // Similar to Relationships, a Node Category needs to touch the Node, however this really is touching the 'document' not the node, so must manually trigger TreeCategoryInfo.TYPEINFO.Events.Insert.After += TreeCategory_Insert_Or_Delete_After; TreeCategoryInfo.TYPEINFO.Events.Delete.After += TreeCategory_Insert_Or_Delete_After; // Need to add TreeCategories to document data set and then processes it since sadly isn't doing it automatically :( StagingEvents.LogTask.Before += LogTask_Before; StagingEvents.ProcessTask.After += ProcessTask_After; } else { // Add some custom logic to create a more readable Task Title StagingEvents.LogTask.Before += NonBindingLogTask_Before; // Handle object deletions, additions work but removals don't for node object relationships StagingEvents.ProcessTask.After += NonBindingNodeDocument_ProcessTask_After; } // Handle any tasks that need to be deleted due to originating from another server StagingEvents.LogTask.After += LogTask_After; // Also make sure that the foreign key exists for the class try { if (DataClassInfoProvider.GetDataClassInfo("CMS.TreeCategory") != null) { ConnectionHelper.ExecuteQuery("CMS.TreeCategory.EnsureForeignKeys", null); } } catch (Exception ex) { Service.Resolve <IEventLogService>().LogException("RelationshipsExtended", "ErrorSettingForeignKeys", ex, additionalMessage: "Make sure the Query CMS.TreeCategory.EnsureForeignKey exists. IGNORE if you just installed the module as this will run before the class installs on the first application start after installation."); } // Registers "CustomNamespace" into the macro engine MacroContext.GlobalResolver.SetNamedSourceData("RelHelper", RelHelperMacroNamespace.Instance); MacroContext.GlobalResolver.SetNamedSourceData("RelEnums", EnumMacroEvaluator.EnumMacroObjects()); /* Check to make sure the 2 forms exist */ if (AlternativeFormInfoProvider.GetAlternativeFormInfo("cms.relationshipname.NewForm") == null) { int ClassID = DataClassInfoProvider.GetDataClassInfo("cms.relationshipname").ClassID; AlternativeFormInfo RelationshipNewForm = new AlternativeFormInfo() { FormClassID = ClassID, FormName = "NewForm", FormDisplayName = "New Form", FormDefinition = "<form version=\"2\"><field column=\"RelationshipNameID\" guid=\"47839bd6-f19c-4cfd-b67f-1ca754694d46\" /><field column=\"RelationshipDisplayName\" guid=\"6515b190-003a-44b6-b541-8814760de218\" /><field column=\"RelationshipName\" guid=\"42221f4a-30fa-47a6-bc80-3f99ee81f8a5\" /><field column=\"RelationshipAllowedObjects\" guid=\"2a02c9d5-f0f9-4a19-be8d-9a007f4464ac\" /><field column=\"RelationshipNameIsAdHoc\" guid=\"f1d3667d-77eb-47de-9ad0-5f22ad63e082\" visible=\"true\"><settings><controlname>CheckBoxControl</controlname></settings><properties><fieldcaption>Relationship Is AdHoc (Sortable)</fieldcaption><fielddescription>Must be true if you wish to use sorting.</fielddescription></properties></field><field column=\"RelationshipGUID\" guid=\"03ad948a-2bb7-44b2-b580-b05abf3a2a8b\" /><field column=\"RelationshipLastModified\" guid=\"ea7edf35-ed86-4cef-91c5-7bfdde27c389\" /><field column=\"ReltionshipSite\" guid=\"a733ba02-3675-481a-b586-b87c49e23268\" /></form>", FormHideNewParentFields = false, FormIsCustom = true }; AlternativeFormInfoProvider.SetAlternativeFormInfo(RelationshipNewForm); } if (AlternativeFormInfoProvider.GetAlternativeFormInfo("cms.relationshipname.EditForm") == null) { int ClassID = DataClassInfoProvider.GetDataClassInfo("cms.relationshipname").ClassID; AlternativeFormInfo RelationshipNewForm = new AlternativeFormInfo() { FormClassID = ClassID, FormName = "EditForm", FormDisplayName = "Edit Form", FormDefinition = "<form version=\"2\"><field column=\"RelationshipNameID\" guid=\"47839bd6-f19c-4cfd-b67f-1ca754694d46\" /><field column=\"RelationshipDisplayName\" guid=\"6515b190-003a-44b6-b541-8814760de218\" /><field column=\"RelationshipName\" guid=\"42221f4a-30fa-47a6-bc80-3f99ee81f8a5\" /><field column=\"RelationshipAllowedObjects\" guid=\"2a02c9d5-f0f9-4a19-be8d-9a007f4464ac\" /><field column=\"RelationshipNameIsAdHoc\" guid=\"f1d3667d-77eb-47de-9ad0-5f22ad63e082\" visible=\"true\"><settings><controlname>CheckBoxControl</controlname></settings><properties><fieldcaption>Relationship Is AdHoc (Sortable)</fieldcaption><fielddescription>Must be true if you wish to use sorting.</fielddescription></properties></field><field column=\"RelationshipGUID\" guid=\"03ad948a-2bb7-44b2-b580-b05abf3a2a8b\" /><field column=\"RelationshipLastModified\" guid=\"ea7edf35-ed86-4cef-91c5-7bfdde27c389\" /><field column=\"ReltionshipSite\" guid=\"a733ba02-3675-481a-b586-b87c49e23268\" /></form>", FormHideNewParentFields = false, FormIsCustom = true }; AlternativeFormInfoProvider.SetAlternativeFormInfo(RelationshipNewForm); } }
/// <summary> /// Saves form layout. /// </summary> protected void SaveData() { bool saved = false; bool deleted = false; // Get form layout string layout = FormLayout; // Delete layout if editor is hidden if (!CustomLayoutEnabled) { deleted = LayoutIsSet; layout = null; } if (DataClassID > 0) { if (!IsAlternative) { classInfo = DataClassInfoProvider.GetDataClassInfo(DataClassID); UIContext.EditedObject = classInfo; if (classInfo != null) { // Update dataclass form layout and save object classInfo.ClassFormLayout = layout; classInfo.ClassFormLayoutType = LayoutHelper.GetLayoutTypeEnum(drpLayoutType.SelectedValue); DataClassInfoProvider.SetDataClassInfo(classInfo); saved = true; } } else { altFormInfo = AlternativeFormInfoProvider.GetAlternativeFormInfo(ObjectID); UIContext.EditedObject = altFormInfo; if (altFormInfo != null) { // Update alternative form layout and save object altFormInfo.FormLayout = layout; altFormInfo.FormLayoutType = LayoutHelper.GetLayoutTypeEnum(drpLayoutType.SelectedValue); AlternativeFormInfoProvider.SetAlternativeFormInfo(altFormInfo); saved = true; } } // Display info if successfully saved if (saved) { if (!deleted) { ShowChangesSaved(); } else { ShowConfirmation(GetString("DocumentType_Edit_Form.LayoutDeleted")); } } } else { UIContext.EditedObject = null; } }
/// <summary> /// Saves form layout. /// </summary> protected void SaveData() { bool saved = false; bool deleted = false; // Get form layout string layout = FormLayout; // Delete layout if editor is hidden if (!CustomLayoutEnabled) { deleted = LayoutIsSet; layout = null; } if (DataClassID > 0) { if (!IsAlternative) { DataClassInfo dci = DataClassInfoProvider.GetDataClass(DataClassID); CMSPage.EditedObject = dci; if (dci != null) { // Update dataclass form layout and save object dci.ClassFormLayout = layout; DataClassInfoProvider.SetDataClass(dci); saved = true; } } else { AlternativeFormInfo afi = AlternativeFormInfoProvider.GetAlternativeFormInfo(ObjectID); CMSPage.EditedObject = afi; if (afi != null) { // Update alternative form layout and save object afi.FormLayout = layout; AlternativeFormInfoProvider.SetAlternativeFormInfo(afi); saved = true; } } // Display info if successfully saved if (saved) { lblInfo.Visible = true; if (!deleted) { lblInfo.Text = GetString("general.changessaved"); } else { lblInfo.Text = GetString("DocumentType_Edit_Form.LayoutDeleted"); } } } else { CMSPage.EditedObject = null; } }
/// <summary> /// Adds form field info to the form to the specified position. /// </summary> /// <param name="ffi">Form field info which will be added</param> /// <param name="category">Category name</param> /// <param name="position">Field position in the category</param> private string AddField(FormFieldInfo ffi, string category, int position) { if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.form", "EditForm")) { RedirectToAccessDenied("cms.form", "EditForm"); } var dci = DataClassInfoProvider.GetDataClassInfo(ClassName); if (dci != null) { // Ensure the transaction using (var tr = new CMSLateBoundTransaction()) { string tableName = dci.ClassTableName; string columnType = DataTypeManager.GetSqlType(ffi.DataType, ffi.Size, ffi.Precision); TableManager tm = new TableManager(dci.ClassConnectionString); tr.BeginTransaction(); // Add new column tm.AddTableColumn(tableName, ffi.Name, columnType, true, null); // Add field to form mFormInfo.AddFormItem(ffi); if (!String.IsNullOrEmpty(category) || position >= 0) { mFormInfo.MoveFormFieldToPositionInCategory(ffi.Name, category, position); } // Update form definition dci.ClassFormDefinition = mFormInfo.GetXmlDefinition(); // Update class schema dci.ClassXmlSchema = tm.GetXmlSchema(dci.ClassTableName); try { // Save the class data DataClassInfoProvider.SetDataClassInfo(dci); } catch (Exception) { return(GetString("FormBuilder.ErrorSavingForm")); } // Generate default view SqlGenerator.GenerateDefaultView(dci, SiteContext.CurrentSiteName); QueryInfoProvider.ClearDefaultQueries(dci, true, true); // Hide field for alternative forms that require it string where = "FormClassID=" + dci.ClassID; where = SqlHelper.AddWhereCondition(where, "FormHideNewParentFields=1"); var altforms = AlternativeFormInfoProvider.GetAlternativeForms(where, null); foreach (AlternativeFormInfo afi in altforms) { afi.HideField(ffi); AlternativeFormInfoProvider.SetAlternativeFormInfo(afi); } // Commit the transaction tr.Commit(); } ClearHashtables(); // Update inherited classes with new fields FormHelper.UpdateInheritedClasses(dci); } else { return(GetString("FormBuilder.ErrorSavingForm")); } return(string.Empty); }