private static void RegisterAttachments(Page page, ObjectEditMenu menu, EmailTemplateInfo emailTemplate) { const string ATTACHMENTS_ACTION_CLASS = "attachments-header-action"; // Register attachments count update module ScriptHelper.RegisterModule(page, "CMS/AttachmentsCountUpdater", new { Selector = "." + ATTACHMENTS_ACTION_CLASS, Text = ResHelper.GetString("general.attachments") }); // Prepare metafile dialog URL var metaFileDialogUrl = UrlResolver.ResolveUrl(@"~/CMSModules/AdminControls/Controls/MetaFiles/MetaFileDialog.aspx"); var query = string.Format("?objectid={0}&objecttype={1}&siteid={2}", emailTemplate.TemplateID, EmailTemplateInfo.OBJECT_TYPE, emailTemplate.TemplateSiteID); metaFileDialogUrl += string.Format("{0}&category={1}&hash={2}", query, ObjectAttachmentsCategories.TEMPLATE, QueryHelper.GetHash(query)); var attachCount = GetAttachmentsCount(emailTemplate); var attachmentsCaption = ResHelper.GetString("general.attachments"); // Add attachments action menu.AddExtraAction(new HeaderAction { Text = attachmentsCaption + (attachCount > 0 ? " (" + attachCount + ")" : string.Empty), Tooltip = attachmentsCaption, OnClientClick = string.Format(@"if (modalDialog) {{modalDialog('{0}', 'Attachments', '700', '500');}}", metaFileDialogUrl) + " return false;", Enabled = !SynchronizationHelper.UseCheckinCheckout || emailTemplate.Generalized.IsCheckedOutByUser(MembershipContext.AuthenticatedUser), CssClass = ATTACHMENTS_ACTION_CLASS, ButtonStyle = ButtonStyle.Default }); }
/// <summary> /// Adds extra action to the object edit menu. /// </summary> /// <param name="action">Header action</param> public void AddExtraHeaderAction(HeaderAction action) { if ((action != null) && (ObjectEditMenu != null)) { // Add extra action to object menu ObjectEditMenu.AddExtraAction(action); } }
/// <summary> /// Initializes header actions. /// </summary> /// <param name="templateId">Email template ID</param> /// <param name="siteId">Site ID</param> protected void InitHeaderActions(int templateId, int siteId) { if (templateId > 0) { // Get number of attachments InfoDataSet <MetaFileInfo> ds = MetaFileInfoProvider.GetMetaFiles(templateId, PredefinedObjectType.EMAILTEMPLATE, MetaFileInfoProvider.OBJECT_CATEGORY_TEMPLATE, siteId > 0 ? "MetaFileSiteID=" + siteId : "MetaFileSiteID IS NULL", null, "MetafileID", -1); int attachCount = ds.Items.Count; string script = @" function UpdateAttachmentCount(count) { var counter = document.getElementById('attachmentCount'); if (counter != null) { if (count > 0) { counter.innerHTML = ' (' + count + ')'; } else { counter.innerHTML = ''; } } }"; ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "UpdateAttachmentScript_" + this.ClientID, script, true); // Register dialog scripts ScriptHelper.RegisterDialogScript(Page); // Prepare metafile dialog URL string metaFileDialogUrl = ResolveUrl(@"~/CMSModules/AdminControls/Controls/MetaFiles/MetaFileDialog.aspx"); string query = string.Format("?objectid={0}&objecttype={1}&siteid={2}", templateId, PredefinedObjectType.EMAILTEMPLATE, siteId); metaFileDialogUrl += string.Format("{0}&category={1}&hash={2}", query, MetaFileInfoProvider.OBJECT_CATEGORY_TEMPLATE, QueryHelper.GetHash(query)); // Init attachment button ObjectEditMenu menu = ControlsHelper.GetChildControl(Page, typeof(ObjectEditMenu)) as ObjectEditMenu; if (menu != null) { attachmentsAction = new HeaderAction() { ControlType = HeaderActionTypeEnum.LinkButton, Text = GetString("general.attachments") + string.Format("<span id='attachmentCount'>{0}</span>", (attachCount > 0) ? " (" + attachCount.ToString() + ")" : string.Empty), Tooltip = GetString("general.attachments"), OnClientClick = string.Format(@"if (modalDialog) {{modalDialog('{0}', 'Attachments', '700', '500');}}", metaFileDialogUrl) + " return false;", ImageUrl = GetImageUrl("Objects/CMS_MetaFile/attachment.png"), Visible = !pnlObjectLocking.IsObjectLocked() }; menu.AddExtraAction(attachmentsAction); } } }
private static void RegisterSendDraft(ObjectEditMenu menu, EmailTemplateInfo emailTemplate) { // Prepare draft dialog URL var draftDialogUrl = UrlResolver.ResolveUrl("~/CMSModules/EmailTemplates/Pages/SendDraft.aspx"); draftDialogUrl = URLHelper.AddParameterToUrl(draftDialogUrl, "objectid", emailTemplate.TemplateID.ToString()); var draftCaption = ResHelper.GetString("emailtemplates.senddraft"); // Add send draft action menu.AddExtraAction(new HeaderAction { Text = draftCaption, Tooltip = draftCaption, OnClientClick = string.Format(@"if (modalDialog) {{modalDialog('{0}', 'SendDraft', '700', '325');}}", draftDialogUrl) + " return false;", Enabled = true, ButtonStyle = ButtonStyle.Default }); }
protected void InitAttachmentAction() { EmailTemplateInfo emailTemplate = Control.EditedObject as EmailTemplateInfo; if ((emailTemplate != null) && (emailTemplate.TemplateID > 0)) { int siteId = emailTemplate.TemplateSiteID; Page page = Control.Page; // Get number of attachments InfoDataSet <MetaFileInfo> ds = MetaFileInfoProvider.GetMetaFiles(emailTemplate.TemplateID, EmailTemplateInfo.OBJECT_TYPE, ObjectAttachmentsCategories.TEMPLATE, siteId > 0 ? "MetaFileSiteID=" + siteId : "MetaFileSiteID IS NULL", null, "MetafileID", -1); int attachCount = ds.Items.Count; // Register attachments count update module ScriptHelper.RegisterModule(page, "CMS/AttachmentsCountUpdater", new { Selector = "." + mAttachmentsActionClass, Text = ResHelper.GetString("general.attachments") }); // Register dialog scripts ScriptHelper.RegisterDialogScript(page); // Prepare metafile dialog URL string metaFileDialogUrl = URLHelper.ResolveUrl(@"~/CMSModules/AdminControls/Controls/MetaFiles/MetaFileDialog.aspx"); string query = String.Format("?objectid={0}&objecttype={1}&siteid={2}", emailTemplate.TemplateID, EmailTemplateInfo.OBJECT_TYPE, siteId); metaFileDialogUrl += String.Format("{0}&category={1}&hash={2}", query, ObjectAttachmentsCategories.TEMPLATE, QueryHelper.GetHash(query)); ObjectEditMenu menu = (ObjectEditMenu)ControlsHelper.GetChildControl(page, typeof(ObjectEditMenu)); if (menu != null) { menu.AddExtraAction(new HeaderAction() { Text = ResHelper.GetString("general.attachments") + ((attachCount > 0) ? " (" + attachCount.ToString() + ")" : String.Empty), OnClientClick = String.Format(@"if (modalDialog) {{modalDialog('{0}', 'Attachments', '700', '500');}}", metaFileDialogUrl) + " return false;", Enabled = !SynchronizationHelper.UseCheckinCheckout || emailTemplate.Generalized.IsCheckedOutByUser(MembershipContext.AuthenticatedUser), CssClass = mAttachmentsActionClass }); } } }