/// <summary> /// Adds a new field to the content type /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Add_Click(object sender, EventArgs e) { String guid = Request.QueryString["tid"]; CmsContentType type = ContentManager.Instance.GetContentType(guid); int existing = 0; Int32.TryParse(this.ExistingId.Value, out existing); CmsContentTypeField field = ContentManager.Instance.GetContentTypeField(guid, existing); if (field == null) field = new CmsContentTypeField(); field.Parent = type; field.SystemName = this.TxtSystemName.Text; field.Name = this.TxtName.Text; field.Description = this.Description.Text; field.IsRequired = this.ChkRequiredField.Checked; this.SetFieldProperties(field); ContentManager.Instance.AddContentTypeField(type, field); BtnAddNew_Click(sender, e); this.FieldTable.DataBind(); }
public void AddContentTypeField(CmsContentType type, CmsContentTypeField field) { CmsContentTypeDao dao = new CmsContentTypeDao(); field.Parent = type; using (Transaction tx = new Transaction()) { dao.Save<CmsContentTypeField>(field); tx.Commit(); } }
protected void AddContentType_Click(object sender, EventArgs e) { try { String guid = this.ExistingContentTypeGuid.Value; CmsContentType type = ContentManager.Instance.GetContentType(guid); Boolean isNew = false; if (type == null) { type = new CmsContentType(); isNew = true; } type.DisplayName = this.ContentDispayName.Text; type.Name = this.ContentSystemName.Text.Replace(" ","_"); type.Description = this.ContentDescription.Text; type.IsFileType = this.ContentFileYes.Checked; type.IsEditorVisible = this.ContentEditorYes.Checked; if (isNew) ContentManager.Instance.AddContentType(type); else ContentManager.Instance.Save(type); if (isNew) { CmsContentTypeField field = new CmsContentTypeField(); field.Name = "Title"; field.ObjectType = "System.String"; field.IsRequired = true; field.Description = "Title"; field.SystemName = "title"; field.FieldType = CmsContentTypeField.Textbox; ContentManager.Instance.AddContentTypeField(type, field); //Set the default title to the one we just created type.TitleFieldName = field.SystemName; ContentManager.Instance.Save(type); } Response.Redirect("./ContentTypeFields.aspx?tid=" + Server.UrlEncode(type.Guid), true); } catch (Exception ex) { Status.ForeColor = System.Drawing.Color.Red; Status.Text = ex.Message; } }
/// <summary> /// Creates a duplicate of the specified content type. Adjusting the names as necessary to avoid conflicts. /// </summary> /// <param name="guid"></param> /// <param name="systemType"></param> public void Duplicate(Data.Guid siteGuid, CmsContentType typeToCopy) { String systemName = typeToCopy.Name; //Make sure that this system name doesn't already exist CmsContentTypeDao dao = new CmsContentTypeDao(); CmsContentType existing = dao.FindBySiteAndName(siteGuid.Value, systemName); if (existing != null) systemName = systemName + "_c"; CmsContentType type = new CmsContentType(); type.Guid = System.Guid.NewGuid().ToString(); type.DisplayName = typeToCopy.DisplayName; type.Description = type.Description; type.IsEditorVisible = type.IsEditorVisible; type.IsFileType = type.IsFileType; type.IsGlobalType = false; type.Name = systemName; type.SubscriptionId = siteGuid.Value; type.TitleFieldName = typeToCopy.TitleFieldName; AddContentType(siteGuid,type); //Copy all of the fields IList<CmsContentTypeField> fieldsToCopy = GetContentTypeFields(typeToCopy.Guid); foreach (CmsContentTypeField fieldToCopy in fieldsToCopy) { CmsContentTypeField field = new CmsContentTypeField(); field._SelectOptions = fieldToCopy._SelectOptions; field.Columns = fieldToCopy.Columns; field.Description = fieldToCopy.Description; field.FieldType = fieldToCopy.FieldType; field.IsRequired = fieldToCopy.IsRequired; field.IsSystemDefault = fieldToCopy.IsSystemDefault; field.Name = fieldToCopy.Name; field.ObjectType = fieldToCopy.ObjectType; field.Parent = fieldToCopy.Parent; field.Position = fieldToCopy.Position; field.Rows = fieldToCopy.Rows; field.SystemName = fieldToCopy.SystemName; AddContentTypeField(type, field); } }
private void SetFieldProperties(CmsContentTypeField field) { field.FieldType = this.FieldType.SelectedValue; //Set any specific attributes for field types that are unique if (this.FieldType.SelectedValue.ToLower().Equals("textarea")) { field.Columns = Int32.Parse(this.Cols.Text); field.Rows = Int32.Parse(this.Rows.Text); } if (this.FieldType.SelectedValue.ToLower().Equals("dropdown")) { field._SelectOptions = this.Options.Text; } //set the object type switch (field.FieldType.ToLower()) { case CmsContentTypeField.Datetime: field.ObjectType = typeof(System.DateTime).FullName; break; default: field.ObjectType = typeof(System.String).FullName; break; } }