/// <summary> /// Action button handler. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(drpAction.SelectedValue)) { List <string> items = null; if (drpWhat.SelectedValue == "all") { // Get only the appropriate set of items string where = filterWhere; switch (drpAction.SelectedValue) { case "deleteindatabase": case "copytofilesystem": // Only process those where binary is available in DB where = SqlHelper.AddWhereCondition(where, "MetaFileBinary IS NOT NULL"); break; case "copytodatabase": // Only copy those where the binary is missing where = SqlHelper.AddWhereCondition(where, "MetaFileBinary IS NULL"); break; } // Get all, build the list of items DataSet ds = MetaFileInfoProvider.GetMetaFiles(where, null, "MetaFileID", 0); if (!DataHelper.DataSourceIsEmpty(ds)) { items = new List <string>(); // Process all rows foreach (DataRow dr in ds.Tables[0].Rows) { int fileId = ValidationHelper.GetInteger(dr["MetaFileID"], 0); items.Add(fileId.ToString()); } } } else { // Take selected items items = gridFiles.SelectedItems; } if ((items != null) && (items.Count > 0)) { // Setup the async log pnlLog.Visible = true; pnlContent.Visible = false; ctlAsyncLog.TitleText = drpAction.SelectedItem.Text; CurrentError = string.Empty; // Process the file asynchronously var parameter = new object[] { items, drpAction.SelectedValue }; ctlAsyncLog.RunAsync(p => ProcessFiles(parameter), WindowsIdentity.GetCurrent()); } } }
/// <summary> /// Deletes the file binary from the file system. /// </summary> /// <param name="fileId">MetaFile ID</param> /// <param name="name">Returning the metafile name</param> protected bool DeleteFromFileSystem(int fileId, ref string name) { // Delete the file in file system MetaFileInfo mi = MetaFileInfoProvider.GetMetaFileInfo(fileId); if (mi != null) { name = mi.MetaFileName; // Ensure the binary column first (check if exists) DataSet ds = MetaFileInfoProvider.GetMetaFiles("MetaFileID = " + fileId, null, "CASE WHEN MetaFileBinary IS NULL THEN 0 ELSE 1 END AS HasBinary", -1); if (!DataHelper.DataSourceIsEmpty(ds)) { bool hasBinary = ValidationHelper.GetBoolean(ds.Tables[0].Rows[0][0], false); if (!hasBinary) { // Copy the binary data to database mi.MetaFileBinary = MetaFileInfoProvider.GetFile(mi, SiteInfoProvider.GetSiteName(mi.MetaFileSiteID)); mi.Generalized.UpdateData(); } // Delete the file from the disk MetaFileInfoProvider.DeleteFile(SiteInfoProvider.GetSiteName(mi.MetaFileSiteID), mi.MetaFileGUID.ToString(), true, false); return(true); } } return(false); }
protected void AttachmentList_OnAfterChange(object sender, EventArgs e) { // Get number of attachments InfoDataSet <MetaFileInfo> ds = MetaFileInfoProvider.GetMetaFiles(ObjectId, ObjectType, ObjectCategory, null, null, "MetafileID", -1); // Register script to update hdnCount value (it is used to update attachment count in wopener) ScriptHelper.RegisterStartupScript(this, typeof(string), "UpdateCountHolder", "document.getElementById('" + hdnCount.ClientID + "').value=" + ds.Items.Count.ToString(), true); }
/// <summary> /// Removes all metafiles used in invoices. /// </summary> private static void RemoveInvoiceMetafiles() { var invoiceMetafiles = MetaFileInfoProvider.GetMetaFiles() .WhereEquals("MetaFileGroupName", "Invoice"); foreach (var metafile in invoiceMetafiles) { metafile.Delete(); } }
private int GetAttachmentsCount() { var metafiles = MetaFileInfoProvider.GetMetaFiles( Issue.IssueID, Issue.IssueIsVariant ? IssueInfo.OBJECT_TYPE_VARIANT : IssueInfo.OBJECT_TYPE, ObjectAttachmentsCategories.ISSUE, null, null, "MetafileID", -1); return(metafiles.Items.Count); }
/// <summary> /// Saves the widget data and create string for inline widget. /// </summary> private string SaveInline() { string script = "var widgetObj = new Object(); \n"; if (IsInline) { // Validate data if (!SaveForm(formCustom)) { return(String.Empty); } DataRow dr = formCustom.DataRow; if (wi == null) { return(String.Empty); } // Name of the widget is first argument script += String.Format("widgetObj['name']='{0}';", HttpUtility.UrlEncode(wi.WidgetName)); if (mFields == null) { return(String.Empty); } foreach (FormFieldInfo ffi in mFields) { if (dr.Table.Columns.Contains(ffi.Name)) { script += String.Format("widgetObj['{0}'] = {1}; \n", ffi.Name, ScriptHelper.GetString(HttpUtility.UrlEncode(dr[ffi.Name].ToString().Replace("%", "%25")))); } } // Add image GUID DataSet ds = MetaFileInfoProvider.GetMetaFiles("MetaFileObjectID = " + wi.WidgetID + " AND MetaFileObjectType = 'cms.widget'", String.Empty, "MetafileGuid", 0); if (!SqlHelperClass.DataSourceIsEmpty(ds)) { Guid guid = ValidationHelper.GetGuid(ds.Tables[0].Rows[0]["MetafileGuid"], Guid.Empty); script += "widgetObj['image_guid'] = '" + guid.ToString() + "'; \n"; } // Add display name script += "widgetObj['widget_displayname'] = " + ScriptHelper.GetString(HttpUtility.UrlEncode(wi.WidgetDisplayName.Replace("%", "%25"))) + "; \n"; // Create javascript for save script += "widgetObj['cms_type'] = 'widget';\n InsertSelectedItem(widgetObj);\n"; // Add to recently used widgtets collection CMSContext.CurrentUser.UserSettings.UpdateRecentlyUsedWidget(wi.WidgetName); return(script); } return(string.Empty); }
/// <summary> /// Initializes header action control. /// </summary> /// <param name="templateId">Template ID</param> protected void InitHeaderActions(int templateId) { bool isAuthorized = CurrentUser.IsAuthorizedPerResource("CMS.Newsletter", "ManageTemplates") && (EditedObject != null); // Init save button CurrentMaster.HeaderActions.ActionsList.Add(new SaveAction { Enabled = isAuthorized }); // Init spellcheck button CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction { Text = GetString("spellcheck.title"), Tooltip = GetString("spellcheck.title"), OnClientClick = "checkSpelling(spellURL); return false;", ButtonStyle = ButtonStyle.Default, }); int attachCount = 0; if (isAuthorized) { // Get number of attachments InfoDataSet <MetaFileInfo> ds = MetaFileInfoProvider.GetMetaFiles(templateId, EmailTemplateInfo.OBJECT_TYPE, ObjectAttachmentsCategories.TEMPLATE, null, null, "MetafileID", -1); attachCount = ds.Items.Count; // Register attachments count update module ScriptHelper.RegisterModule(this, "CMS/AttachmentsCountUpdater", new { Selector = "." + mAttachmentsActionClass, Text = ResHelper.GetString("general.attachments") }); // 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}", templateId, EmailTemplateInfo.OBJECT_TYPE); metaFileDialogUrl += string.Format("{0}&category={1}&hash={2}", query, ObjectAttachmentsCategories.TEMPLATE, QueryHelper.GetHash(query)); // Init attachment button CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction { Text = GetString("general.attachments") + ((attachCount > 0) ? " (" + attachCount + ")" : string.Empty), Tooltip = GetString("general.attachments"), OnClientClick = string.Format(@"if (modalDialog) {{modalDialog('{0}', 'Attachments', '700', '500');}}", metaFileDialogUrl) + " return false;", Enabled = isAuthorized, CssClass = mAttachmentsActionClass, ButtonStyle = ButtonStyle.Default, }); CurrentMaster.HeaderActions.ActionPerformed += HeaderActions_ActionPerformed; }
/// <summary> /// Initializes header actions. /// </summary> protected void InitHeaderActions() { menu.ActionsList.Clear(); // Add save action save = new SaveAction(Page); menu.ActionsList.Add(save); bool isAuthorized = CurrentUser.IsAuthorizedPerResource("cms.form", "EditForm") && ((formId > 0) && (EditedObject != null)); int attachCount = 0; if (isAuthorized) { // Get number of attachments InfoDataSet <MetaFileInfo> ds = MetaFileInfoProvider.GetMetaFiles(formId, FormObjectType.BIZFORM, MetaFileInfoProvider.OBJECT_CATEGORY_FORM_LAYOUT, null, null, "MetafileID", -1); 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}", formId, FormObjectType.BIZFORM); metaFileDialogUrl += string.Format("{0}&category={1}&hash={2}", query, MetaFileInfoProvider.OBJECT_CATEGORY_FORM_LAYOUT, QueryHelper.GetHash(query)); // Init attachment button attachments = 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 = isAuthorized ? GetImageUrl("Objects/CMS_MetaFile/attachment.png") : GetImageUrl("Objects/CMS_MetaFile/attachment_disabled.png"), Enabled = isAuthorized }; menu.ActionsList.Add(attachments); }
/// <summary> /// Updates metafile image path. /// </summary> private void UpdateImagePath(MediaLibraryInfo mli) { // Update image path according to its meta file DataSet ds = MetaFileInfoProvider.GetMetaFiles(ucMetaFile.ObjectID, mli.TypeInfo.ObjectType); if (!DataHelper.DataSourceIsEmpty(ds)) { MetaFileInfo metaFile = new MetaFileInfo(ds.Tables[0].Rows[0]); mli.LibraryTeaserPath = MetaFileInfoProvider.GetMetaFileUrl(metaFile.MetaFileGUID, metaFile.MetaFileName); } else { mli.LibraryTeaserPath = ""; } }
/// <summary> /// Uploads file. /// </summary> public void UploadFile() { if ((uploader.PostedFile != null) && (uploader.PostedFile.ContentLength > 0) && (ObjectID > 0)) { try { MetaFileInfo existing = null; // Check if uploaded file already exists and delete it DataSet ds = MetaFileInfoProvider.GetMetaFiles(ObjectID, ObjectType, Category, null, null); if (!DataHelper.DataSourceIsEmpty(ds)) { // Get existing record ID and delete it existing = new MetaFileInfo(ds.Tables[0].Rows[0]); MetaFileInfoProvider.DeleteMetaFileInfo(existing); } // Create new meta file MetaFileInfo mfi = new MetaFileInfo(uploader.PostedFile, ObjectID, ObjectType, Category); if (existing != null) { // Preserve GUID mfi.MetaFileGUID = existing.MetaFileGUID; mfi.MetaFileTitle = existing.MetaFileTitle; mfi.MetaFileDescription = existing.MetaFileDescription; } mfi.MetaFileSiteID = SiteID; // Save to the database MetaFileInfoProvider.SetMetaFileInfo(mfi); // Set currently handled meta file this.CurrentlyHandledMetaFile = mfi; SetupControls(); } catch (Exception ex) { lblErrorUploader.Visible = true; lblErrorUploader.Text = ex.Message; ViewState["SavingFailed"] = true; SetupControls(); } // File was uploaded, do not delete in one postback mAlreadyUploadedDontDelete = true; } }
/// <summary> /// Gets metafile preview. /// </summary> /// <param name="objTemplateId">Template ID</param> protected string GetPreviewImage(object objTemplateId) { int templateId = ValidationHelper.GetInteger(objTemplateId, 0); DataSet dsPreview = MetaFileInfoProvider.GetMetaFiles(templateId, WebTemplateInfo.OBJECT_TYPE); if (!DataHelper.DataSourceIsEmpty(dsPreview)) { string guid = ValidationHelper.GetString(dsPreview.Tables[0].Rows[0]["MetaFileGUID"], ""); return(ResolveUrl("~/CMSPages/GetMetaFile.aspx?fileguid=" + guid)); } else { return(GetImageUrl("Others/Install/no_image.png")); } }
/// <summary> /// Updates metafile image path. /// </summary> private void UpdateImagePath(MediaLibraryInfo mli) { // Update image path according to its meta file DataSet ds = MetaFileInfoProvider.GetMetaFiles(ucMetaFile.ObjectID, mli.TypeInfo.ObjectType, MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL, null, null); if (!DataHelper.DataSourceIsEmpty(ds)) { MetaFileInfo metaFile = new MetaFileInfo(ds.Tables[0].Rows[0]); mli.LibraryTeaserGuid = metaFile.MetaFileGUID; mli.LibraryTeaserPath = MetaFileInfoProvider.GetMetaFileUrl(metaFile.MetaFileGUID, metaFile.MetaFileName); } else { mli.LibraryTeaserGuid = Guid.Empty; mli.LibraryTeaserPath = String.Empty; } }
/// <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); } } }
/// <summary> /// Creates new widget with setting from parent webpart. /// </summary> /// <param name="parentWebpartId">ID of parent webpart</param> /// <param name="categoryId">ID of parent widget category</param> /// <returns>Created widget info</returns> private WidgetInfo NewWidget(int parentWebpartId, int categoryId) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(parentWebpartId); // Widget cannot be created from inherited webpart if ((wpi != null) && (wpi.WebPartParentID == 0)) { // Set widget according to parent webpart WidgetInfo wi = new WidgetInfo(); wi.WidgetName = FindUniqueWidgetName(wpi.WebPartName, 100); wi.WidgetDisplayName = wpi.WebPartDisplayName; wi.WidgetDescription = wpi.WebPartDescription; wi.WidgetDocumentation = wpi.WebPartDocumentation; wi.WidgetSkipInsertProperties = wpi.WebPartSkipInsertProperties; wi.WidgetIconClass = wpi.WebPartIconClass; wi.WidgetProperties = FormHelper.GetFormFieldsWithDefaultValue(wpi.WebPartProperties, "visible", "false"); wi.WidgetWebPartID = parentWebpartId; wi.WidgetCategoryID = categoryId; // Save new widget to DB WidgetInfoProvider.SetWidgetInfo(wi); // Get thumbnail image from webpart DataSet ds = MetaFileInfoProvider.GetMetaFiles(wpi.WebPartID, WebPartInfo.OBJECT_TYPE, null, null, null, null, 1); if (!DataHelper.DataSourceIsEmpty(ds)) { MetaFileInfo mfi = new MetaFileInfo(ds.Tables[0].Rows[0]); mfi.Generalized.EnsureBinaryData(); mfi.MetaFileID = 0; mfi.MetaFileGUID = Guid.NewGuid(); mfi.MetaFileObjectID = wi.WidgetID; mfi.MetaFileObjectType = WidgetInfo.OBJECT_TYPE; MetaFileInfoProvider.SetMetaFileInfo(mfi); } // Return ID of newly created widget return(wi); } return(null); }
/// <summary> /// Returns url of item's (webpart,widget) image. /// </summary> /// <param name="itemID">ID of webpart (widget)</param> /// <param name="itemType">Type of item (webpart,widget)</param> private string GetItemImage(int itemID, string itemType) { DataSet mds = MetaFileInfoProvider.GetMetaFiles(itemID, itemType); // Check whether image exists if (!DataHelper.DataSourceIsEmpty(mds)) { // Ge tmetafile info object MetaFileInfo mtfi = new MetaFileInfo(mds.Tables[0].Rows[0]); // Image found - used in development mode isImagePresent = true; // Get image url return(ResolveUrl("~/CMSPages/GetMetaFile.aspx?fileguid=" + mtfi.MetaFileGUID.ToString())); } return(GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/imagenotavailable.png")); }
/// <summary> /// Initializes header actions. /// </summary> protected void InitHeaderActions() { menu.ActionsList.Clear(); // Add save action save = new SaveAction(); menu.ActionsList.Add(save); bool isAuthorized = CurrentUser.IsAuthorizedPerResource("cms.form", "EditForm") && (EditedObject != null); int attachCount = 0; if (isAuthorized) { // Get number of attachments InfoDataSet <MetaFileInfo> ds = MetaFileInfoProvider.GetMetaFiles(formInfo.FormID, BizFormInfo.OBJECT_TYPE, ObjectAttachmentsCategories.FORMLAYOUT, null, null, "MetafileID", -1); attachCount = ds.Items.Count; // Register attachments count update module ScriptHelper.RegisterModule(this, "CMS/AttachmentsCountUpdater", new { Selector = "." + mAttachmentsActionClass, Text = GetString("general.attachments") }); // 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}", formInfo.FormID, BizFormInfo.OBJECT_TYPE); metaFileDialogUrl += string.Format("{0}&category={1}&hash={2}", query, ObjectAttachmentsCategories.FORMLAYOUT, QueryHelper.GetHash(query)); // Init attachment button attachments = new HeaderAction { Text = GetString("general.attachments") + ((attachCount > 0) ? " (" + attachCount + ")" : string.Empty), Tooltip = GetString("general.attachments"), OnClientClick = string.Format(@"if (modalDialog) {{modalDialog('{0}', 'Attachments', '700', '500');}}", metaFileDialogUrl) + " return false;", Enabled = isAuthorized, CssClass = mAttachmentsActionClass, ButtonStyle = ButtonStyle.Default, }; menu.ActionsList.Add(attachments); }
private static int GetAttachmentsCount(EmailTemplateInfo emailTemplate) { var objectQuery = MetaFileInfoProvider.GetMetaFiles(); objectQuery.WhereCondition = MetaFileInfoProvider.GetWhereCondition(emailTemplate.TemplateID, EmailTemplateInfo.OBJECT_TYPE, ObjectAttachmentsCategories.TEMPLATE); objectQuery.Columns(MetaFileInfo.TYPEINFO.IDColumn); var siteId = emailTemplate.TemplateSiteID; if (siteId > 0) { objectQuery.OnSite(siteId); } else { objectQuery.WhereNull(MetaFileInfo.TYPEINFO.SiteIDColumn); } return(objectQuery.Count); }
protected void uploader_OnDeleteFile(object sender, EventArgs e) { // Careful with upload and delete in on postback - ignore delete request if (mAlreadyUploadedDontDelete) { return; } try { using (DataSet ds = MetaFileInfoProvider.GetMetaFiles(ObjectID, ObjectType, Category, null, null)) { if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { MetaFileInfo mfi = new MetaFileInfo(dr); if ((mfi != null) && (mfi.MetaFileName.ToLower() == uploader.CurrentFileName.ToLower())) { MetaFileInfoProvider.DeleteMetaFileInfo(mfi.MetaFileID); } } } } // Execute after delete event if (OnAfterDelete != null) { OnAfterDelete(this, null); } SetupControls(); } catch (Exception ex) { ViewState["DeletingFailed"] = true; lblErrorUploader.Visible = true; lblErrorUploader.Text = ex.Message; SetupControls(); } }
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 }); } } }
private void UpdateSKUImagePath(SKUInfo skuObj) { if (ECommerceSettings.UseMetaFileForProductImage && !hasAttachmentImagePath) { // Update product image path according to its meta file DataSet ds = MetaFileInfoProvider.GetMetaFiles(ucMetaFile.ObjectID, skuObj.TypeInfo.ObjectType, MetaFileInfoProvider.OBJECT_CATEGORY_IMAGE, null, null); if (!DataHelper.DataSourceIsEmpty(ds)) { MetaFileInfo metaFile = new MetaFileInfo(ds.Tables[0].Rows[0]); skuObj.SKUImagePath = MetaFileInfoProvider.GetMetaFileUrl(metaFile.MetaFileGUID, metaFile.MetaFileName); } else { skuObj.SKUImagePath = ""; } } else { // Update product image path from the image selector skuObj.SKUImagePath = imgSelect.Value; } }
protected void uploader_OnDeleteFile(object sender, EventArgs e) { // Careful with upload and delete in on postback - ignore delete request if (mAlreadyUploadedDontDelete) { return; } try { using (DataSet ds = MetaFileInfoProvider.GetMetaFiles(ObjectID, ObjectType, Category, null, null)) { if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { var mfi = new MetaFileInfo(dr); if (mfi.MetaFileName.ToLowerCSafe() == uploader.CurrentFileName.ToLowerCSafe()) { MetaFileInfoProvider.DeleteMetaFileInfo(mfi.MetaFileID); } } } } RaiseOnAfterDelete(); SetupControls(); } catch (Exception ex) { ViewState["DeletingFailed"] = true; ShowError(ex.Message); SetupControls(); } }
/// <summary> /// Initializes header action control. /// </summary> /// <param name="issueId">Issue ID</param> private void InitHeaderActions(int issueId) { // Show info message and get current issue state bool editingEnabled; bool variantSliderEnabled; UpdateDialog(issueId, out editingEnabled, out variantSliderEnabled); editElem.Enabled = editingEnabled; bool isIssueVariant = ucVariantSlider.Variants.Count > 0; ucVariantSlider.Visible = isIssueVariant; ucVariantSlider.EditingEnabled = editingEnabled && variantSliderEnabled; ScriptHelper.RegisterDialogScript(Page); CurrentMaster.HeaderActions.ActionsList.Clear(); // Init save button CurrentMaster.HeaderActions.ActionsList.Add(new SaveAction { OnClientClick = "if (GetContent != null) {return GetContent();} else {return false;}", Enabled = editingEnabled }); // Ensure spell check action if (editingEnabled) { CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction { Text = GetString("EditMenu.IconSpellCheck"), Tooltip = GetString("EditMenu.SpellCheck"), OnClientClick = "var frame = GetFrame(); if ((frame != null) && (frame.contentWindow.SpellCheck_" + ClientID + " != null)) {frame.contentWindow.SpellCheck_" + ClientID + "();} return false;", ButtonStyle = ButtonStyle.Default, }); } // Init send draft button CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction { Text = GetString("newsletterissue_content.senddraft"), Tooltip = GetString("newsletterissue_content.senddraft"), OnClientClick = string.Format(@"if (modalDialog) {{modalDialog('{0}?objectid={1}', 'SendDraft', '700', '300');}}", ResolveUrl(@"~/CMSModules/Newsletters/Tools/Newsletters/Newsletter_Issue_SendDraft.aspx"), issueId) + " return false;", Enabled = true, ButtonStyle = ButtonStyle.Default, }); // Init preview button CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction { Text = GetString("general.preview"), Tooltip = GetString("general.preview"), OnClientClick = string.Format(@"if (modalDialog) {{modalDialog('{0}?objectid={1}', 'Preview', '90%', '90%');}}", ResolveUrl(@"~/CMSModules/Newsletters/Tools/Newsletters/Newsletter_Issue_Preview.aspx"), issueId) + " return false;", ButtonStyle = ButtonStyle.Default, }); int attachCount = 0; // Get number of attachments InfoDataSet <MetaFileInfo> ds = MetaFileInfoProvider.GetMetaFiles(issueId, (isIssueVariant ? IssueInfo.OBJECT_TYPE_VARIANT : IssueInfo.OBJECT_TYPE), ObjectAttachmentsCategories.ISSUE, null, null, "MetafileID", -1); attachCount = ds.Items.Count; // Register attachments count update module ScriptHelper.RegisterModule(this, "CMS/AttachmentsCountUpdater", new { Selector = "." + mAttachmentsActionClass, Text = ResHelper.GetString("general.attachments") }); // Prepare metafile dialog URL string metaFileDialogUrl = ResolveUrl(@"~/CMSModules/AdminControls/Controls/MetaFiles/MetaFileDialog.aspx"); string query = string.Format("?objectid={0}&objecttype={1}", issueId, (isIssueVariant? IssueInfo.OBJECT_TYPE_VARIANT : IssueInfo.OBJECT_TYPE)); metaFileDialogUrl += string.Format("{0}&category={1}&hash={2}", query, ObjectAttachmentsCategories.ISSUE, QueryHelper.GetHash(query)); // Init attachment button CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction { Text = GetString("general.attachments") + ((attachCount > 0) ? " (" + attachCount + ")" : string.Empty), Tooltip = GetString("general.attachments"), OnClientClick = string.Format(@"if (modalDialog) {{modalDialog('{0}', 'Attachments', '700', '500');}}", metaFileDialogUrl) + " return false;", Enabled = true, CssClass = mAttachmentsActionClass, ButtonStyle = ButtonStyle.Default, }); // Init create A/B test button - online marketing, open email and click through tracking are required if (!isIssueVariant) { IssueInfo issue = (IssueInfo)EditedObject; if (editingEnabled && (issue.IssueStatus == IssueStatusEnum.Idle) && NewsletterHelper.IsABTestingAvailable()) { // Check that trackings are enabled bool trackingsEnabled = (newsletter != null) && newsletter.NewsletterTrackOpenEmails && newsletter.NewsletterTrackClickedLinks; CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction { Text = GetString("newsletterissue_content.createabtest"), Tooltip = trackingsEnabled ? GetString("newsletterissue_content.createabtest") : GetString("newsletterissue_content.abtesttooltip"), OnClientClick = trackingsEnabled ? "ShowVariantDialog_" + ucVariantDialog.ClientID + "('addvariant', ''); return false;" : "return false;", Enabled = trackingsEnabled, ButtonStyle = ButtonStyle.Default, }); ucVariantDialog.IssueID = issueId; ucVariantDialog.OnAddVariant += ucVariantSlider_OnVariantAdded; } } // Init masterpage CurrentMaster.HeaderActions.ActionPerformed += HeaderActions_ActionPerformed; CurrentMaster.DisplayControlsPanel = isIssueVariant; CurrentMaster.PanelContent.Attributes.Add("onmouseout", "if (RememberFocusedRegion) {RememberFocusedRegion();}"); }
protected override void OnLoad(EventArgs e) { plImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/plus.png"); minImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/minus.png"); if (WebpartID != String.Empty) { wpi = WebPartInfoProvider.GetWebPartInfo(WebpartID); } // Ensure correct view mode if (String.IsNullOrEmpty(AliasPath)) { // Ensure the dashboard mode for the dialog if (!string.IsNullOrEmpty(DashboardName)) { PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets); PortalContext.DashboardName = DashboardName; PortalContext.DashboardSiteName = DashboardSiteName; } // Ensure the design mode for the dialog else { PortalContext.SetRequestViewMode(ViewModeEnum.Design); } } if (WidgetID != String.Empty) { PageInfo pi = null; try { // Load page info from alias path and page template pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateID, CultureCode); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi != null) { PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (templateInstance != null) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(InstanceGUID, WidgetID); // Info for zone type WebPartZoneInstance zone = templateInstance.GetZone(ZoneID); if (zone != null) { zoneType = zone.WidgetZoneType; } if (widgetInstance != null) { // Create widget from webpart instance wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } } } // If inline widget display columns as in editor zone if (IsInline) { zoneType = WidgetZoneTypeEnum.Editor; } // If no zone set (only global admins allowed to continue) if (zoneType == WidgetZoneTypeEnum.None) { if (!CMSContext.CurrentUser.UserSiteManagerAdmin) { RedirectToAccessDenied(GetString("attach.actiondenied")); } } // If wi is still null (new item f.e.) if (wi == null) { // Try to get widget info directly by ID if (!IsNew) { wi = WidgetInfoProvider.GetWidgetInfo(WidgetID); } else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetID, 0)); } } } String itemDescription = String.Empty; String itemType = String.Empty; String itemDisplayName = String.Empty; String itemDocumentation = String.Empty; int itemID = 0; // Check whether webpart was found if (wpi != null) { itemDescription = wpi.WebPartDescription; itemType = PortalObjectType.WEBPART; itemID = wpi.WebPartID; itemDisplayName = wpi.WebPartDisplayName; itemDocumentation = wpi.WebPartDocumentation; } // Or widget was found else if (wi != null) { itemDescription = wi.WidgetDescription; itemType = PortalObjectType.WIDGET; itemID = wi.WidgetID; itemDisplayName = wi.WidgetDisplayName; itemDocumentation = wi.WidgetDocumentation; } if ((wpi != null) || (wi != null)) { // Get WebPart (widget) image DataSet ds = MetaFileInfoProvider.GetMetaFiles(itemID, itemType); // Set image url of exists if (!DataHelper.DataSourceIsEmpty(ds)) { MetaFileInfo mtfi = new MetaFileInfo(ds.Tables[0].Rows[0]); if (mtfi != null) { if (mtfi.MetaFileImageWidth > 385) { imgTeaser.Width = 385; } imgTeaser.ImageUrl = ResolveUrl("~/CMSPages/GetMetaFile.aspx?fileguid=" + mtfi.MetaFileGUID.ToString()); } } else { // Set default image imgTeaser.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/imagenotavailable.png"); } // Additional image information imgTeaser.ToolTip = HTMLHelper.HTMLEncode(itemDisplayName); imgTeaser.AlternateText = HTMLHelper.HTMLEncode(itemDisplayName); // Set description of webpart ltlDescription.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(itemDescription)); // Get description from parent weboart if webpart is inherited if ((wpi != null) && (string.IsNullOrEmpty(wpi.WebPartDescription) && (wpi.WebPartParentID > 0))) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { ltlDescription.Text = HTMLHelper.HTMLEncode(pwpi.WebPartDescription); } } FormInfo fi = null; // Generate properties if (wpi != null) { // Get form info from parent if webpart is inherited if (wpi.WebPartParentID != 0) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { fi = GetWebPartProperties(pwpi); } } else { fi = GetWebPartProperties(wpi); } } else if (wi != null) { fi = GetWidgetProperties(wi); } // Generate properties if (fi != null) { GenerateProperties(fi); } // Generate documentation text if (itemDocumentation == null || itemDocumentation.Trim() == "") { if ((wpi != null) && (wpi.WebPartParentID != 0)) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null && pwpi.WebPartDocumentation.Trim() != "") { ltlContent.Text = HTMLHelper.ResolveUrls(pwpi.WebPartDocumentation, null); } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = HTMLHelper.ResolveUrls(itemDocumentation, null); } } ScriptHelper.RegisterJQuery(Page); string script = @" $j(document.body).ready(initializeResize); function initializeResize () { resizeareainternal(); $j(window).resize(function() { resizeareainternal(); }); } function resizeareainternal () { var height = document.body.clientHeight ; var panel = document.getElementById ('" + divScrolable.ClientID + @"'); // Get parent footer to count proper height (with padding included) var footer = $j('.PageFooterLine'); panel.style.height = (height - footer.outerHeight() - panel.offsetTop) +'px'; }"; ScriptHelper.RegisterClientScriptBlock(Page, typeof(Page), "mainScript", ScriptHelper.GetScript(script)); string[,] tabs = new string[4, 4]; tabs[0, 0] = GetString("webparts.documentation"); tabs[1, 0] = GetString("general.properties"); tabControlElem.Tabs = tabs; tabControlElem.UsePostback = true; // Disable caching Response.Cache.SetNoStore(); base.OnLoad(e); }
/// <summary> /// Initializes header action control. /// </summary> /// <param name="issueId">Issue ID</param> private void InitHeaderActions(int issueId) { // Show info message and get current issue state bool editingEnabled = false; bool variantSliderEnabled = false; UpdateDialog(issueId, out editingEnabled, out variantSliderEnabled); editElem.Enabled = editingEnabled; bool isAuthorized = CurrentUser.IsAuthorizedPerResource("CMS.Newsletter", "AuthorIssues"); bool isIssueVariant = ucVariantSlider.Variants.Count > 0; string script = null; ucVariantSlider.Visible = isIssueVariant; ucVariantSlider.EditingEnabled = editingEnabled && variantSliderEnabled; ScriptHelper.RegisterDialogScript(Page); CurrentMaster.HeaderActions.ActionsList.Clear(); // Init save button CurrentMaster.HeaderActions.ActionsList.Add(new SaveAction(this) { OnClientClick = "if (GetContent != null) {return GetContent();} else {return false;}", SmallImageUrl = isAuthorized && editingEnabled ? GetImageUrl("CMSModules/CMS_Content/EditMenu/16/save.png") : GetImageUrl("CMSModules/CMS_Content/EditMenu/16/savedisabled.png"), Enabled = isAuthorized && editingEnabled }); // Ensure spell check action if (isAuthorized && editingEnabled) { CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction() { CssClass = "MenuItemEdit", Text = GetString("EditMenu.IconSpellCheck"), Tooltip = GetString("EditMenu.SpellCheck"), OnClientClick = "var frame = GetFrame(); if ((frame != null) && (frame.contentWindow.SpellCheck_" + ClientID + " != null)) {frame.contentWindow.SpellCheck_" + ClientID + "();} return false;", ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/spellcheck.png"), SmallImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/16/spellcheck.png"), }); } // Init send draft button CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction() { ControlType = HeaderActionTypeEnum.LinkButton, Text = GetString("newsletterissue_content.senddraft"), Tooltip = GetString("newsletterissue_content.senddraft"), OnClientClick = string.Format(@"if (modalDialog) {{modalDialog('{0}?issueid={1}', 'SendDraft', '500', '300');}}", ResolveUrl(@"~/CMSModules/Newsletters/Tools/Newsletters/Newsletter_Issue_SendDraft.aspx"), issueId) + " return false;", ImageUrl = GetImageUrl("CMSModules/CMS_Newsletter/senddraft.png"), Enabled = isAuthorized }); // Init preview button CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction() { ControlType = HeaderActionTypeEnum.Hyperlink, Text = GetString("general.preview"), Tooltip = GetString("general.preview"), OnClientClick = string.Format(@"if (modalDialog) {{modalDialog('{0}?issueid={1}', 'Preview', '90%', '90%');}}", ResolveUrl(@"~/CMSModules/Newsletters/Tools/Newsletters/Newsletter_Issue_Preview.aspx"), issueId) + " return false;", ImageUrl = GetImageUrl("CMSModules/CMS_Newsletter/preview.png") }); int attachCount = 0; if (isAuthorized) { // Get number of attachments InfoDataSet <MetaFileInfo> ds = MetaFileInfoProvider.GetMetaFiles(issueId, (isIssueVariant ? NewsletterObjectType.NEWSLETTERISSUEVARIANT : NewsletterObjectType.NEWSLETTERISSUE), MetaFileInfoProvider.OBJECT_CATEGORY_ISSUE, null, null, "MetafileID", -1); attachCount = ds.Items.Count; 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_" + ClientID, script, true); } // Prepare metafile dialog URL string metaFileDialogUrl = ResolveUrl(@"~/CMSModules/AdminControls/Controls/MetaFiles/MetaFileDialog.aspx"); string query = string.Format("?objectid={0}&objecttype={1}", issueId, (isIssueVariant? NewsletterObjectType.NEWSLETTERISSUEVARIANT : NewsletterObjectType.NEWSLETTERISSUE)); metaFileDialogUrl += string.Format("{0}&category={1}&hash={2}", query, MetaFileInfoProvider.OBJECT_CATEGORY_ISSUE, QueryHelper.GetHash(query)); // Init attachment button CurrentMaster.HeaderActions.ActionsList.Add(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"), Enabled = isAuthorized }); // Init create A/B test button - online marketing, open email and click through tracking are required if (!isIssueVariant) { IssueInfo issue = (IssueInfo)EditedObject; if (editingEnabled && (issue.IssueStatus == IssueStatusEnum.Idle) && NewsletterHelper.IsABTestingAvailable()) { // Check that trackings are enabled bool trackingsEnabled = (newsletter != null) && newsletter.NewsletterTrackOpenEmails && newsletter.NewsletterTrackClickedLinks; CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction() { ControlType = HeaderActionTypeEnum.LinkButton, Text = GetString("newsletterissue_content.createabtest"), Tooltip = trackingsEnabled ? GetString("newsletterissue_content.createabtest") : GetString("newsletterissue_content.abtesttooltip"), OnClientClick = isAuthorized && trackingsEnabled ? "ShowVariantDialog_" + ucVariantDialog.ClientID + "('addvariant', ''); return false;" : "return false;", ImageUrl = isAuthorized && trackingsEnabled ? GetImageUrl("CMSModules/CMS_Newsletter/abtest.png") : GetImageUrl("CMSModules/CMS_Newsletter/abtest_disabled.png"), Enabled = isAuthorized && trackingsEnabled }); ucVariantDialog.IssueID = issueId; ucVariantDialog.OnAddVariant += new EventHandler(ucVariantSlider_OnVariantAdded); } } // Init fullscreen button string imageOff = ResolveUrl(GetImageUrl("CMSModules/CMS_Newsletter/fullscreenoff.png")); string imageOn = ResolveUrl(GetImageUrl("CMSModules/CMS_Newsletter/fullscreenon.png")); // Create fullscreen toogle function script = string.Format(@" function ToogleFullScreen(elem) {{ if (window.maximized) {{ window.maximized = false; $j(elem).find('img').attr('src','{0}'); MaximizeAll(top.window); }} else {{ window.maximized = true; $j(elem).find('img').attr('src','{1}'); MinimizeAll(top.window); }} }}", imageOff, imageOn); // Register fullscreen toogle function and necessary scripts ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ToogleFullScreen_" + ClientID, script, true); ScriptHelper.RegisterResizer(this); ScriptHelper.RegisterJQuery(this); CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction() { ControlType = HeaderActionTypeEnum.LinkButton, Text = GetString("general.fullscreen"), OnClientClick = "ToogleFullScreen(this);return false;", ImageUrl = GetImageUrl("CMSModules/CMS_Newsletter/fullscreenoff.png"), CssClass = !isIssueVariant ? "MenuItemEdit Right" : "MenuItemEdit RightABVariant" }); // Init masterpage CurrentMaster.HeaderActions.ActionPerformed += HeaderActions_ActionPerformed; CurrentMaster.DisplayControlsPanel = isIssueVariant; CurrentMaster.PanelContent.Attributes.Add("onmouseout", "if (RememberFocusedRegion) {RememberFocusedRegion();}"); }
/// <summary> /// Initializes header action control. /// </summary> private void InitHeaderActions() { bool isNew = (IssueId == 0); bool isIssueVariant = !isNew && IssueInfoProvider.IsABTestIssue(IssueId); hdrActions.ActionsList.Clear(); // Init save button hdrActions.ActionsList.Add(new SaveAction(this) { OnClientClick = "if (GetContent != null) {return GetContent();} else {return false;}" }); // Ensure spell check action hdrActions.ActionsList.Add(new HeaderAction() { CssClass = "MenuItemEdit", Text = GetString("EditMenu.IconSpellCheck"), Tooltip = GetString("EditMenu.SpellCheck"), OnClientClick = "var frame = GetFrame(); if ((frame != null) && (frame.contentWindow.SpellCheck_" + ClientID + " != null)) {frame.contentWindow.SpellCheck_" + ClientID + "();} return false;", ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/spellcheck.png"), SmallImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/16/spellcheck.png"), }); // Init send draft button hdrActions.ActionsList.Add(new HeaderAction() { ControlType = HeaderActionTypeEnum.LinkButton, Text = GetString("newsletterissue_content.senddraft"), Tooltip = GetString("newsletterissue_content.senddraft"), OnClientClick = (isNew) ? "return false;" : string.Format(@"if (modalDialog) {{modalDialog('{0}?issueid={1}', 'SendDraft', '500', '300');}}", ResolveUrl(@"~/CMSModules/Newsletters/Tools/Newsletters/Newsletter_Issue_SendDraft.aspx"), IssueId) + " return false;", ImageUrl = (isNew) ? GetImageUrl("CMSModules/CMS_Newsletter/senddraft_disabled.png") : GetImageUrl("CMSModules/CMS_Newsletter/senddraft.png"), Enabled = !isNew }); // Init preview button hdrActions.ActionsList.Add(new HeaderAction() { ControlType = HeaderActionTypeEnum.Hyperlink, Text = GetString("general.preview"), Tooltip = GetString("general.preview"), OnClientClick = (isNew) ? "return false;" : string.Format(@"if (modalDialog) {{modalDialog('{0}?issueid={1}', 'Preview', '90%', '90%');}}", ResolveUrl(@"~/CMSModules/Newsletters/Tools/Newsletters/Newsletter_Issue_Preview.aspx"), IssueId) + " return false;", ImageUrl = (isNew) ? GetImageUrl("CMSModules/CMS_Newsletter/preview_disabled.png") : GetImageUrl("CMSModules/CMS_Newsletter/preview.png"), Enabled = !isNew }); int attachCount = 0; string metaFileDialogUrl = null; if (!isNew) { ScriptHelper.RegisterDialogScript(Page); // Get number of attachments InfoDataSet <MetaFileInfo> ds = MetaFileInfoProvider.GetMetaFiles(IssueId, (isIssueVariant ? NewsletterObjectType.NEWSLETTERISSUEVARIANT : NewsletterObjectType.NEWSLETTERISSUE), MetaFileInfoProvider.OBJECT_CATEGORY_ISSUE, null, null, "MetafileID", -1); 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); // Prepare metafile dialog URL metaFileDialogUrl = ResolveUrl(@"~/CMSModules/AdminControls/Controls/MetaFiles/MetaFileDialog.aspx"); string query = string.Format("?objectid={0}&objecttype={1}", IssueId, (isIssueVariant ? NewsletterObjectType.NEWSLETTERISSUEVARIANT : NewsletterObjectType.NEWSLETTERISSUE)); metaFileDialogUrl += string.Format("{0}&category={1}&hash={2}", query, MetaFileInfoProvider.OBJECT_CATEGORY_ISSUE, QueryHelper.GetHash(query)); } // Init attachment button hdrActions.ActionsList.Add(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 = (isNew) ? "return false;" : string.Format(@"if (modalDialog) {{modalDialog('{0}', 'Attachments', '700', '500');}}", metaFileDialogUrl) + " return false;", ImageUrl = (isNew) ? GetImageUrl("Objects/CMS_MetaFile/attachment_disabled.png") : GetImageUrl("Objects/CMS_MetaFile/attachment.png"), Enabled = !isNew }); // Init create A/B test button - online marketing, open email and click through tracking are required if (isNew || !isIssueVariant) { if (NewsletterHelper.IsABTestingAvailable()) { // Check that trackings are enabled NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(newsletterId); bool trackingsEnabled = (news != null) && news.NewsletterTrackOpenEmails && news.NewsletterTrackClickedLinks; hdrActions.ActionsList.Add(new HeaderAction() { ControlType = HeaderActionTypeEnum.LinkButton, Text = GetString("newsletterissue_content.createabtest"), Tooltip = trackingsEnabled ? GetString("newsletterissue_content.createabtest") : GetString("newsletterissue_content.abtesttooltip"), OnClientClick = (isNew || !trackingsEnabled) ? "return false;" : "ShowVariantDialog_" + ucVariantDialog.ClientID + "('addvariant', ''); return false;", ImageUrl = (isNew || !trackingsEnabled) ? GetImageUrl("CMSModules/CMS_Newsletter/abtest_disabled.png") : GetImageUrl("CMSModules/CMS_Newsletter/abtest.png"), Enabled = !isNew && trackingsEnabled }); ucVariantDialog.IssueID = IssueId; ucVariantDialog.OnAddVariant += new EventHandler(ucVariantSlider_OnVariantAdded); } } hdrActions.ActionPerformed += HeaderActions_ActionPerformed; hdrActions.ReloadData(); pnlActions.Attributes.Add("onmouseover", "if (RememberFocusedRegion) {RememberFocusedRegion();}"); }
/// <summary> /// Initializes header action control. /// </summary> /// <param name="templateId">Template ID</param> protected void InitHeaderActions(int templateId) { bool isAuthorized = CurrentUser.IsAuthorizedPerResource("CMS.Newsletter", "ManageTemplates") && (EditedObject != null); string script = null; // Init save button CurrentMaster.HeaderActions.ActionsList.Add(new SaveAction(this) { ImageUrl = !isAuthorized ? GetImageUrl("CMSModules/CMS_Content/EditMenu/savedisabled.png") : string.Empty, Enabled = isAuthorized }); // Init spellcheck button CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction() { ControlType = HeaderActionTypeEnum.LinkButton, Text = GetString("spellcheck.title"), Tooltip = GetString("spellcheck.title"), OnClientClick = "checkSpelling(spellURL); return false;", ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/spellcheck.png") }); int attachCount = 0; if (isAuthorized) { // Get number of attachments InfoDataSet <MetaFileInfo> ds = MetaFileInfoProvider.GetMetaFiles(templateId, NewsletterObjectType.NEWSLETTERTEMPLATE, MetaFileInfoProvider.OBJECT_CATEGORY_TEMPLATE, null, null, "MetafileID", -1); attachCount = ds.Items.Count; 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}", templateId, NewsletterObjectType.NEWSLETTERTEMPLATE); metaFileDialogUrl += string.Format("{0}&category={1}&hash={2}", query, MetaFileInfoProvider.OBJECT_CATEGORY_TEMPLATE, QueryHelper.GetHash(query)); // Init attachment button CurrentMaster.HeaderActions.ActionsList.Add(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 = isAuthorized ? GetImageUrl("Objects/CMS_MetaFile/attachment.png") : GetImageUrl("Objects/CMS_MetaFile/attachment_disabled.png"), Enabled = isAuthorized }); // Init fullscreen button string imageOff = ResolveUrl(GetImageUrl("CMSModules/CMS_Newsletter/fullscreenoff.png")); string imageOn = ResolveUrl(GetImageUrl("CMSModules/CMS_Newsletter/fullscreenon.png")); // Create fullscreen toogle function script = string.Format(@" function ToogleFullScreen(elem) {{ if (window.maximized) {{ window.maximized = false; $j(elem).find('img').attr('src','{0}'); MaximizeAll(top.window); }} else {{ window.maximized = true; $j(elem).find('img').attr('src','{1}'); MinimizeAll(top.window); }} }}", imageOff, imageOn); // Register fullscreen toogle function and necessary scripts ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ToogleFullScreen_" + ClientID, script, true); ScriptHelper.RegisterResizer(this); ScriptHelper.RegisterJQuery(this); CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction() { ControlType = HeaderActionTypeEnum.LinkButton, Text = GetString("general.fullscreen"), OnClientClick = "ToogleFullScreen(this);return false;", ImageUrl = GetImageUrl("CMSModules/CMS_Newsletter/fullscreenoff.png"), CssClass = "MenuItemEdit Right" }); CurrentMaster.HeaderActions.ActionPerformed += HeaderActions_ActionPerformed; }
/// <summary> /// Saves SKU data and returns created SKU object. /// </summary> public SKUInfo SaveData() { // Check permissions if (SiteID > 0) { if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyProducts")) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyProducts"); } } else { if (!ECommerceContext.IsUserAuthorizedForPermission("EcommerceGlobalModify")) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify"); } } if ((plcSKUControls.Visible) && (this.Node != null)) { // Create empty SKU object SKUInfo skuObj = new SKUInfo(); // Set SKU site id skuObj.SKUSiteID = SiteID; // Set SKU Name if (plcSKUName.Visible) { skuObj.SKUName = txtSKUName.Text.Trim(); } else { string skuNameField = GetDocumentMappedField("SKUName"); skuObj.SKUName = ValidationHelper.GetString(this.Node.GetValue(skuNameField), ""); } // Set SKU price if (plcSKUPrice.Visible) { skuObj.SKUPrice = txtSKUPrice.Value; } else { string skuPriceField = GetDocumentMappedField("SKUPrice"); skuObj.SKUPrice = ValidationHelper.GetDouble(this.Node.GetValue(skuPriceField), 0); } // Set SKU image path according to the document binding if (!plcMetaFile.Visible && !plcImagePath.Visible) { string skuImageField = GetDocumentMappedField("SKUImagePath"); skuObj.SKUImagePath = ValidationHelper.GetString(this.Node.GetValue(skuImageField), ""); } // Set SKU description if (plcSKUDescription.Visible) { skuObj.SKUDescription = htmlSKUDescription.Value; } else { string skuDescriptionField = GetDocumentMappedField("SKUDescription"); skuObj.SKUDescription = ValidationHelper.GetString(this.Node.GetValue(skuDescriptionField), ""); } // Set SKU department skuObj.SKUDepartmentID = departmentElem.DepartmentID; skuObj.SKUEnabled = true; // Create new SKU SKUInfoProvider.SetSKUInfo(skuObj); if ((plcImagePath.Visible || plcMetaFile.Visible) && (skuObj.SKUID > 0)) { if (ECommerceSettings.UseMetaFileForProductImage) { // Save meta file ucMetaFile.ObjectID = skuObj.SKUID; ucMetaFile.ObjectType = ECommerceObjectType.SKU; ucMetaFile.Category = MetaFileInfoProvider.OBJECT_CATEGORY_IMAGE; ucMetaFile.UploadFile(); // Update product image path according to its meta file DataSet ds = MetaFileInfoProvider.GetMetaFiles(ucMetaFile.ObjectID, skuObj.TypeInfo.ObjectType); if (!DataHelper.DataSourceIsEmpty(ds)) { // Set product image path MetaFileInfo metaFile = new MetaFileInfo(ds.Tables[0].Rows[0]); skuObj.SKUImagePath = MetaFileInfoProvider.GetMetaFileUrl(metaFile.MetaFileGUID, metaFile.MetaFileName); } } else { skuObj.SKUImagePath = this.imgSelect.Value; } // Update product SKUInfoProvider.SetSKUInfo(skuObj); } return(skuObj); } return(null); }
/// <summary> /// Initializes header action control. /// </summary> private void InitHeaderActions() { bool isNew = (IssueId == 0); var issue = IssueInfoProvider.GetIssueInfo(IssueId); bool isIssueVariant = !isNew && (issue != null) && issue.IssueIsABTest; hdrActions.ActionsList.Clear(); // Init save button hdrActions.ActionsList.Add(new SaveAction(this) { OnClientClick = "if (GetContent != null) {return GetContent();} else {return false;}" }); // Ensure spell check action hdrActions.ActionsList.Add(new HeaderAction { Text = GetString("EditMenu.IconSpellCheck"), Tooltip = GetString("EditMenu.SpellCheck"), OnClientClick = "var frame = GetFrame(); if ((frame != null) && (frame.contentWindow.SpellCheck_" + ClientID + " != null)) {frame.contentWindow.SpellCheck_" + ClientID + "();} return false;" }); // Init send draft button hdrActions.ActionsList.Add(new HeaderAction { Text = GetString("newsletterissue_content.senddraft"), Tooltip = (isNew) ? GetString("newsletterissue_new.issueunsaved") : GetString("newsletterissue_content.senddraft"), OnClientClick = (isNew) ? "return false;" : string.Format(@"if (modalDialog) {{modalDialog('{0}?objectid={1}', 'SendDraft', '700', '300');}}", ResolveUrl(@"~/CMSModules/Newsletters/Tools/Newsletters/Newsletter_Issue_SendDraft.aspx"), IssueId) + " return false;", Enabled = !isNew }); // Init preview button hdrActions.ActionsList.Add(new HeaderAction { Text = GetString("general.preview"), Tooltip = (isNew) ? GetString("newsletterissue_new.issueunsaved") : GetString("general.preview"), OnClientClick = (isNew) ? "return false;" : string.Format(@"if (modalDialog) {{modalDialog('{0}?objectid={1}', 'Preview', '90%', '90%');}}", ResolveUrl(@"~/CMSModules/Newsletters/Tools/Newsletters/Newsletter_Issue_Preview.aspx"), IssueId) + " return false;", Enabled = !isNew }); int attachCount = 0; string metaFileDialogUrl = null; if (!isNew) { ScriptHelper.RegisterDialogScript(Page); // Get number of attachments InfoDataSet <MetaFileInfo> ds = MetaFileInfoProvider.GetMetaFiles(IssueId, (isIssueVariant ? IssueInfo.OBJECT_TYPE_VARIANT : IssueInfo.OBJECT_TYPE), ObjectAttachmentsCategories.ISSUE, null, null, "MetafileID", -1); attachCount = ds.Items.Count; // Register attachments count update module ScriptHelper.RegisterModule(this, "CMS/AttachmentsCountUpdater", new { Selector = "." + mAttachmentsActionClass, Text = ResHelper.GetString("general.attachments") }); // Prepare metafile dialog URL metaFileDialogUrl = ResolveUrl(@"~/CMSModules/AdminControls/Controls/MetaFiles/MetaFileDialog.aspx"); string query = string.Format("?objectid={0}&objecttype={1}", IssueId, (isIssueVariant ? IssueInfo.OBJECT_TYPE_VARIANT : IssueInfo.OBJECT_TYPE)); metaFileDialogUrl += string.Format("{0}&category={1}&hash={2}", query, ObjectAttachmentsCategories.ISSUE, QueryHelper.GetHash(query)); } // Init attachment button hdrActions.ActionsList.Add(new HeaderAction { Text = GetString("general.attachments") + ((attachCount > 0) ? " (" + attachCount + ")" : string.Empty), Tooltip = (isNew) ? GetString("newsletterissue_new.issueunsaved") : GetString("general.attachments"), OnClientClick = (isNew) ? "return false;" : string.Format(@"if (modalDialog) {{modalDialog('{0}', 'Attachments', '700', '500');}}", metaFileDialogUrl) + " return false;", Enabled = !isNew, CssClass = mAttachmentsActionClass }); // Init create A/B test button - online marketing, open email and click through tracking are required if (isNew || !isIssueVariant) { if (NewsletterHelper.IsABTestingAvailable()) { // Check that trackings are enabled NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(newsletterId); bool trackingsEnabled = (news != null) && news.NewsletterTrackOpenEmails && news.NewsletterTrackClickedLinks; hdrActions.ActionsList.Add(new HeaderAction { Text = GetString("newsletterissue_content.createabtest"), Tooltip = (isNew) ? GetString("newsletterissue_new.issueunsaved") : (trackingsEnabled ? GetString("newsletterissue_content.createabtest") : GetString("newsletterissue_content.abtesttooltip")), OnClientClick = (isNew || !trackingsEnabled) ? "return false;" : "ShowVariantDialog_" + ucVariantDialog.ClientID + "('addvariant', ''); return false;", Enabled = !isNew && trackingsEnabled }); ucVariantDialog.IssueID = IssueId; ucVariantDialog.OnAddVariant += ucVariantSlider_OnVariantAdded; } } hdrActions.ActionPerformed += HeaderActions_ActionPerformed; hdrActions.ReloadData(); pnlActions.Attributes.Add("onmouseover", "if (RememberFocusedRegion) {RememberFocusedRegion();}"); }
/// <summary> /// Generate documentation page. /// </summary> protected override void OnInit(EventArgs e) { base.OnInit(e); // Get current resolver resolver = CMSContext.CurrentResolver.CreateContextChild(); plImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/plus.png"); minImg = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/minus.png"); webPartId = QueryHelper.GetString("webPartId", String.Empty); if (webPartId != String.Empty) { wpi = WebPartInfoProvider.GetWebPartInfo(webPartId); } string aliasPath = QueryHelper.GetString("aliaspath", String.Empty); // Ensure correct view mode if (String.IsNullOrEmpty(aliasPath)) { // Ensure the dashboard mode for the dialog if (QueryHelper.Contains("dashboard")) { PortalContext.SetRequestViewMode(ViewModeEnum.DashboardWidgets); PortalContext.DashboardName = QueryHelper.GetString("dashboard", String.Empty); PortalContext.DashboardSiteName = QueryHelper.GetString("sitename", String.Empty); } // Ensure the design mode for the dialog else { PortalContext.SetRequestViewMode(ViewModeEnum.Design); } } // If widgetId is in query create widget documentation widgetID = QueryHelper.GetString("widgetId", String.Empty); if (widgetID != String.Empty) { // Get widget from instance string zoneId = QueryHelper.GetString("zoneid", String.Empty); Guid instanceGuid = QueryHelper.GetGuid("instanceGuid", Guid.Empty); int templateID = QueryHelper.GetInteger("templateID", 0); bool newItem = QueryHelper.GetBoolean("isNew", false); bool isInline = QueryHelper.GetBoolean("Inline", false); PageInfo pi = null; try { // Load page info from alias path and page template pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateID); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi != null) { PageTemplateInstance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (templateInstance != null) { // Get the instance of widget WebPartInstance widgetInstance = templateInstance.GetWebPart(instanceGuid, widgetID); // Info for zone type WebPartZoneInstance zone = templateInstance.GetZone(zoneId); if (zone != null) { zoneType = zone.WidgetZoneType; } if (widgetInstance != null) { // Create widget from webpart instance wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } } } // If inline widget display columns as in editor zone if (isInline) { zoneType = WidgetZoneTypeEnum.Editor; } // If no zone set (only global admins allowed to continue) if (zoneType == WidgetZoneTypeEnum.None) { if (!CMSContext.CurrentUser.UserSiteManagerAdmin) { RedirectToAccessDenied(GetString("attach.actiondenied")); } } // If wi is still null (new item f.e.) if (wi == null) { // Try to get widget info directly by ID if (!newItem) { wi = WidgetInfoProvider.GetWidgetInfo(widgetID); } else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(widgetID, 0)); } } } String itemDescription = String.Empty; String itemType = String.Empty; String itemDisplayName = String.Empty; String itemDocumentation = String.Empty; int itemID = 0; // Check whether webpart was found if (wpi != null) { itemDescription = wpi.WebPartDescription; itemType = PortalObjectType.WEBPART; itemID = wpi.WebPartID; itemDisplayName = wpi.WebPartDisplayName; itemDocumentation = wpi.WebPartDocumentation; } // Or widget was found else if (wi != null) { itemDescription = wi.WidgetDescription; itemType = PortalObjectType.WIDGET; itemID = wi.WidgetID; itemDisplayName = wi.WidgetDisplayName; itemDocumentation = wi.WidgetDocumentation; } if ((wpi != null) || (wi != null)) { // Get WebPart (widget) image DataSet ds = MetaFileInfoProvider.GetMetaFiles(itemID, itemType); // Set image url of exists if (!DataHelper.DataSourceIsEmpty(ds)) { MetaFileInfo mtfi = new MetaFileInfo(ds.Tables[0].Rows[0]); if (mtfi != null) { if (mtfi.MetaFileImageWidth > 385) { imgTeaser.Width = 385; } imgTeaser.ImageUrl = ResolveUrl("~/CMSPages/GetMetaFile.aspx?fileguid=" + mtfi.MetaFileGUID.ToString()); } } else { // Set default image imgTeaser.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/WebpartProperties/imagenotavailable.png"); } // Additional image information imgTeaser.ToolTip = HTMLHelper.HTMLEncode(itemDisplayName); imgTeaser.AlternateText = HTMLHelper.HTMLEncode(itemDisplayName); // Set description of webpart ltlDescription.Text = HTMLHelper.HTMLEncode(itemDescription); // Get description from parent weboart if webpart is inherited if ((wpi != null) && ((wpi.WebPartDescription == null || wpi.WebPartDescription == "") && (wpi.WebPartParentID > 0))) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { ltlDescription.Text = HTMLHelper.HTMLEncode(pwpi.WebPartDescription); } } FormInfo fi = null; // Generate properties if (wpi != null) { // Get form info from parent if webpart is inherited if (wpi.WebPartParentID != 0) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { fi = GetWebPartProperties(pwpi); } } else { fi = GetWebPartProperties(wpi); } } else if (wi != null) { fi = GetWidgetProperties(wi); } // Generate properties if (fi != null) { GenerateProperties(fi); } // Generate documentation text if (itemDocumentation == null || itemDocumentation.Trim() == "") { if ((wpi != null) && (wpi.WebPartParentID != 0)) { WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null && pwpi.WebPartDocumentation.Trim() != "") { ltlContent.Text = HTMLHelper.ResolveUrls(pwpi.WebPartDocumentation, null); } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = "<br /><div style=\"padding-left:5px; font-weight: bold;\">" + GetString("WebPartDocumentation.DocumentationText") + "</div><br />"; } } else { ltlContent.Text = HTMLHelper.ResolveUrls(itemDocumentation, null); } } }