public static ScheduleItem Convert(DataRow dataRow) { if (dataRow == null) { return(null); } DataRowContainer row = new DataRowContainer(dataRow); ScheduleItem obj = new ScheduleItem(); obj.Id = row.String("ScheduleId"); //obj.UserId = row.String("UserId"); //obj.Username = row.String("Username"); obj.Title = row.String("Title"); obj.Enabled = row.Bool("Enabled", true); obj.TypeFullName = row.String("TypeFullName"); obj.CatchUpEnabled = row.Bool("CatchUpEnabled", false); obj.TimeLapse = row.Int("TimeLapse", 0); obj.TimeLapseMeasurement = row.String("TimeLapseMeasurement"); obj.RetryTimeLapse = row.Int("RetryTimeLapse", 0); obj.RetryTimeLapseMeasurement = row.String("RetryTimeLapseMeasurement"); obj.RetainHistoryNum = row.Int("RetainHistoryNum", 0); obj.AttachToEvent = row.String("AttachToEvent"); obj.ObjectDependencies = row.String("ObjectDependencies"); obj.Servers = row.String("Servers"); obj.NextStart = row.DateTime("NextStart"); obj.LastUpdateTime = row.DateTime("LastUpdateTime"); obj.Status = row.Int("Status", 2); obj.CreateTime = row.DateTime("CreateTime"); return(obj); }
/// <summary> /// Loads DataRow for BasicForm with data from FormFieldInfo settings and optionally with form control's default values. /// </summary> /// <param name="loadDefaultValues">Indicates if data container should be initialized with form control's default data</param> private DataRowContainer GetData(bool loadDefaultValues) { DataRowContainer result = new DataRowContainer(FormInfo.GetDataRow(loadDefaultValues)); if (loadDefaultValues) { // Load default values for visible properties (values of hidden form control properties shouldn't be stored in form definition) FormInfo.LoadDefaultValues(result, FormResolveTypeEnum.None, true); } if (Settings != null) { // Load settings of the existing field foreach (string columnName in Settings.Keys) { if (result.ContainsColumn(columnName)) { object value = Settings[columnName]; var settingField = FormInfo.GetFormField(columnName); if (!String.IsNullOrEmpty(Convert.ToString(value)) && IsDataTypeValid(value, settingField)) { result[columnName] = DataTypeManager.ConvertToSystemType(TypeEnum.Field, settingField.DataType, value, SystemContext.EnglishCulture); } } } } return(result); }
/// <summary> /// Loads DataRow container for BasicForm with widget properties. /// </summary> private DataRowContainer GetWidgetProperties() { var result = new DataRowContainer(widgetTypeFormInfo.GetDataRow()); foreach (var property in widgetInstance.Properties) { if (!String.IsNullOrEmpty(property.Value)) { result[property.Name] = property.Value; } } return(result); }
/// <summary> /// Loads DataRow for BasicForm with data from FormFieldInfo settings. /// </summary> private DataRowContainer GetData() { DataRowContainer result = new DataRowContainer(FormInfo.GetDataRow()); if (Settings != null) { foreach (string columnName in result.ColumnNames) { if (Settings.ContainsKey(columnName) && !String.IsNullOrEmpty(Convert.ToString(Settings[columnName]))) { result[columnName] = Settings[columnName]; } } } return(result); }
/// <summary> /// Loads DataRow for BasicForm with data from Parameters property. /// </summary> private DataRowContainer GetData() { DataRowContainer result = new DataRowContainer(FormInfo.GetDataRow()); if (Parameters != null) { foreach (DataColumn column in result.DataRow.Table.Columns) { string columnName = column.ColumnName; if (!String.IsNullOrEmpty(Convert.ToString(Parameters[columnName])) && ValidationHelper.IsType(column.DataType, Parameters[columnName])) { result[columnName] = Parameters[columnName]; } } } return(result); }
new public static ScheduleHistoryItem Convert(DataRow dataRow) { if (dataRow == null) { return(null); } DataRowContainer row = new DataRowContainer(dataRow); ScheduleHistoryItem obj = new ScheduleHistoryItem(); obj.ScheduleHistoryId = row.Int("ScheduleHistoryId"); obj.ScheduleId = row.Int("ScheduleId"); obj.Server = row.String("Server"); obj.StartTime = row.DateTime("StartTime"); obj.EndTime = row.DateTime("EndTime"); obj.Succeed = row.Bool("Succeed", false); obj.NextStart = row.DateTime("NextStart"); obj.LogNotes = row.String("LogNotes"); obj.Status = row.Int("Status", 2); obj.CreateTime = row.DateTime("CreateTime"); return(obj); }
/// <summary> /// Loads DataRow container for BasicForm with widget properties. /// </summary> private DataRowContainer GetWidgetProperties() { var result = new DataRowContainer(widgetTypeFormInfo.GetDataRow()); foreach (var property in widgetInstance.Properties) { if (property.Value == null) { continue; } var formField = widgetTypeFormInfo.GetFormField(property.Name); if (formField == null) { continue; } result[property.Name] = DataTypeManager.ConvertToSystemType(TypeEnum.Field, formField.DataType, property.Value, CultureHelper.EnglishCulture); } return(result); }
/// <summary> /// Returns correct ID for the item (for colorizing the item when selected). /// </summary> /// <param name="dataItem">Container.DataItem</param> protected string GetID(object dataItem) { DataRowView dr = dataItem as DataRowView; if (dr != null) { IDataContainer data = new DataRowContainer(dr); return GetColorizeID(data); } return ""; }
protected void ThumbnailsViewControl_ItemDataBound(object sender, RepeaterItemEventArgs e) { #region "Load the item data" var data = new DataRowContainer((DataRowView)e.Item.DataItem); string fileNameColumn = FileNameColumn; string className = ""; bool isContent = (SourceType == MediaSourceEnum.Content); bool isContentFile = isContent && data.GetValue("ClassName").ToString().EqualsCSafe("cms.file", true); bool notAttachment = isContent && !(isContentFile && (data.GetValue("AttachmentGUID") != DBNull.Value)); if (notAttachment) { className = DataClassInfoProvider.GetDataClassInfo((int)data.GetValue("NodeClassID")).ClassDisplayName; fileNameColumn = "DocumentName"; } // Get information on file string fileName = HTMLHelper.HTMLEncode(data.GetValue(fileNameColumn).ToString()); string ext = HTMLHelper.HTMLEncode(notAttachment ? className : data.GetValue(FileExtensionColumn).ToString().TrimStart('.')); string argument = RaiseOnGetArgumentSet(data); // Get full media library file name bool isInDatabase = true; string fullFileName = GetFileName(data); IDataContainer importedMediaData = null; if (SourceType == MediaSourceEnum.MediaLibraries) { importedMediaData = RaiseOnFileIsNotInDatabase(fullFileName); isInDatabase = (importedMediaData != null); } bool libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); bool libraryUiFolder = libraryFolder && !((DisplayMode == ControlDisplayModeEnum.Simple) && isInDatabase); int width = 0; int height = 0; // Get thumb preview image dimensions int[] thumbImgDimension = { 0, 0 }; if (ImageHelper.IsSupportedByImageEditor(ext)) { // Width & height if (data.ContainsColumn(FileWidthColumn)) { width = ValidationHelper.GetInteger(data.GetValue(FileWidthColumn), 0); } else if (isInDatabase && importedMediaData.ContainsColumn(FileWidthColumn)) { width = ValidationHelper.GetInteger(importedMediaData.GetValue(FileWidthColumn), 0); } if (data.ContainsColumn(FileHeightColumn)) { height = ValidationHelper.GetInteger(data.GetValue(FileHeightColumn), 0); } else if (isInDatabase && importedMediaData.ContainsColumn(FileHeightColumn)) { height = ValidationHelper.GetInteger(importedMediaData.GetValue(FileHeightColumn), 0); } thumbImgDimension = CMSDialogHelper.GetThumbImageDimensions(height, width, MaxThumbImgHeight, MaxThumbImgWidth); } // Preview parameters IconParameters previewParameters = null; if ((SourceType == MediaSourceEnum.MediaLibraries) && isInDatabase) { previewParameters = RaiseOnGetThumbsItemUrl(importedMediaData, true, thumbImgDimension[0], thumbImgDimension[1], 0, notAttachment); } else { previewParameters = RaiseOnGetThumbsItemUrl(data, true, thumbImgDimension[0], thumbImgDimension[1], 0, notAttachment); } // Item parameters IconParameters selectUrlParameters = RaiseOnGetThumbsItemUrl(data, false, 0, 0, 0, notAttachment); bool isSelectable = CMSDialogHelper.IsItemSelectable(SelectableContent, ext, isContentFile); #endregion #region "Standard controls and actions" // Load file name Label lblName = e.Item.FindControl("lblFileName") as Label; if (lblName != null) { lblName.Text = fileName; } // Initialize SELECT button var btnWarning = e.Item.FindControl("btnWarning") as CMSAccessibleButton; if (btnWarning != null) { // If media file not imported yet - display warning sign if (isSelectable && (SourceType == MediaSourceEnum.MediaLibraries) && ((DisplayMode == ControlDisplayModeEnum.Simple) && !isInDatabase && !libraryFolder && !libraryUiFolder)) { btnWarning.ToolTip = GetString("media.file.import"); btnWarning.OnClientClick = String.Format("ColorizeRow({0}); SetAction('importfile',{1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(fullFileName)); } else { PlaceHolder plcWarning = e.Item.FindControl("plcWarning") as PlaceHolder; if (plcWarning != null) { plcWarning.Visible = false; } } } // Initialize SELECTSUBDOCS button var btnSelectSubDocs = e.Item.FindControl("btnSelectSubDocs") as CMSAccessibleButton; if (btnSelectSubDocs != null) { if (IsFullListingMode && (SourceType == MediaSourceEnum.Content)) { int nodeId = ValidationHelper.GetInteger(data.GetValue("NodeID"), 0); btnSelectSubDocs.ToolTip = GetString("dialogs.list.actions.showsubdocuments"); // Check if item is selectable, if not remove select action button btnSelectSubDocs.OnClientClick = String.Format("SetParentAction('{0}'); return false;", nodeId); } else { PlaceHolder plcSelectSubDocs = e.Item.FindControl("plcSelectSubDocs") as PlaceHolder; if (plcSelectSubDocs != null) { plcSelectSubDocs.Visible = false; } } } // Initialize VIEW button var btnView = e.Item.FindControl("btnView") as CMSAccessibleButton; if (btnView != null) { if (!notAttachment && !libraryFolder) { if (String.IsNullOrEmpty(selectUrlParameters.Url)) { btnView.OnClientClick = "return false;"; btnView.Attributes["style"] = "cursor:default;"; btnView.Enabled = false; } else { btnView.ToolTip = GetString("dialogs.list.actions.view"); btnView.OnClientClick = String.Format("javascript: window.open({0}); return false;", ScriptHelper.GetString(URLHelper.ResolveUrl(selectUrlParameters.Url))); } } else { btnView.Visible = false; } } // Initialize EDIT button var btnContentEdit = e.Item.FindControl("btnContentEdit") as CMSAccessibleButton; if (btnContentEdit != null) { btnContentEdit.ToolTip = GetString("general.edit"); Guid guid = Guid.Empty; if (SourceType == MediaSourceEnum.MediaLibraries && !libraryFolder && !libraryUiFolder) { // Media files coming from FS if (!data.ContainsColumn("FileGUID")) { if ((DisplayMode == ControlDisplayModeEnum.Simple) && !isInDatabase) { btnContentEdit.Attributes["style"] = "cursor: default;"; btnContentEdit.Enabled = false; } else { btnContentEdit.OnClientClick = String.Format("$cmsj('#hdnFileOrigName').attr('value', {0}); SetAction('editlibraryui', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(EnsureFileName(fileName)), ScriptHelper.GetString(fileName)); } } else { guid = ValidationHelper.GetGuid(data.GetValue("FileGUID"), Guid.Empty); btnContentEdit.ScreenReaderDescription = String.Format("{0}|MediaFileGUID={1}&sitename={2}", ext, guid, GetSiteName(data, true)); btnContentEdit.PreRender += img_PreRender; } } else if (SourceType == MediaSourceEnum.MetaFile) { // If MetaFiles being displayed set EDIT action string metaExtension = ValidationHelper.GetString(data.GetValue("MetaFileExtension"), string.Empty).ToLowerCSafe(); Guid metaGuid = ValidationHelper.GetGuid(data.GetValue("MetaFileGUID"), Guid.Empty); btnContentEdit.ScreenReaderDescription = String.Format("{0}|metafileguid={1}", metaExtension, metaGuid); btnContentEdit.PreRender += img_PreRender; } else if (!notAttachment && !libraryFolder && !libraryUiFolder) { string nodeid = ""; if (SourceType == MediaSourceEnum.Content) { nodeid = "&nodeId=" + data.GetValue("NodeID"); // Get the node workflow VersionHistoryID = ValidationHelper.GetInteger(data.GetValue("DocumentCheckedOutVersionHistoryID"), 0); } guid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); btnContentEdit.ScreenReaderDescription = String.Format("{0}|AttachmentGUID={1}&sitename={2}{3}{4}", ext, guid, GetSiteName(data, false), nodeid, ((VersionHistoryID > 0) ? "&versionHistoryId=" + VersionHistoryID : "")); btnContentEdit.PreRender += img_PreRender; } else { btnContentEdit.Visible = false; } } #endregion #region "Special actions" // If attachments being displayed show additional actions if (SourceType == MediaSourceEnum.DocumentAttachments) { // Initialize EDIT button var btnEdit = e.Item.FindControl("btnEdit") as CMSAccessibleButton; if (btnEdit != null) { if (!notAttachment) { btnEdit.ToolTip = GetString("general.edit"); // Get file extension string extension = ValidationHelper.GetString(data.GetValue("AttachmentExtension"), "").ToLowerCSafe(); Guid guid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); btnEdit.ScreenReaderDescription = String.Format("{0}|AttachmentGUID={1}&sitename={2}&versionHistoryId={3}", extension, guid, GetSiteName(data, false), VersionHistoryID); btnEdit.PreRender += img_PreRender; } } // Initialize UPDATE button var dfuElem = e.Item.FindControl("dfuElem") as DirectFileUploader; if (dfuElem != null) { GetAttachmentUpdateControl(ref dfuElem, data); } // Setup external edit var ctrl = ExternalEditHelper.LoadExternalEditControl(e.Item.FindControl("plcExtEdit"), FileTypeEnum.Attachment, null, data, IsLiveSite, TreeNodeObj, true); if (ctrl != null) { ctrl.CssClass = null; } // Initialize DELETE button var btnDelete = e.Item.FindControl("btnDelete") as CMSAccessibleButton; if (btnDelete != null) { btnDelete.ToolTip = GetString("general.delete"); // Initialize command btnDelete.OnClientClick = String.Format("if(DeleteConfirmation() == false){{return false;}} SetAction('attachmentdelete','{0}'); RaiseHiddenPostBack(); return false;", data.GetValue("AttachmentGUID")); } var plcContentEdit = e.Item.FindControl("plcContentEdit") as PlaceHolder; if (plcContentEdit != null) { plcContentEdit.Visible = false; } } else if ((SourceType == MediaSourceEnum.MediaLibraries) && !data.ContainsColumn("FileGUID") && ((DisplayMode == ControlDisplayModeEnum.Simple) && !libraryFolder && !libraryUiFolder)) { // Initialize DELETE button var btnDelete = e.Item.FindControl("btnDelete") as CMSAccessibleButton; if (btnDelete != null) { btnDelete.ToolTip = GetString("general.delete"); btnDelete.OnClientClick = String.Format("if(DeleteMediaFileConfirmation() == false){{return false;}} SetAction('deletefile',{0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fullFileName)); } // Hide attachment specific actions PlaceHolder plcAttachmentUpdtAction = e.Item.FindControl("plcAttachmentUpdtAction") as PlaceHolder; if (plcAttachmentUpdtAction != null) { plcAttachmentUpdtAction.Visible = false; } } else { PlaceHolder plcAttachmentActions = e.Item.FindControl("plcAttachmentActions") as PlaceHolder; if (plcAttachmentActions != null) { plcAttachmentActions.Visible = false; } } #endregion #region "Library update action" if ((SourceType == MediaSourceEnum.MediaLibraries) && (DisplayMode == ControlDisplayModeEnum.Simple)) { // Initialize UPDATE button var dfuElemLib = e.Item.FindControl("dfuElemLib") as DirectFileUploader; if (dfuElemLib != null) { Panel pnlDisabledUpdate = (e.Item.FindControl("pnlDisabledUpdate") as Panel); if (pnlDisabledUpdate != null) { bool hasModifyPermission = RaiseOnGetModifyPermission(data); if (isInDatabase && hasModifyPermission) { GetLibraryUpdateControl(ref dfuElemLib, importedMediaData); pnlDisabledUpdate.Visible = false; } else { pnlDisabledUpdate.Controls.Clear(); var disabledIcon = new CMSAccessibleButton { EnableViewState = false, Enabled = false, IconCssClass = "icon-arrow-up-line", IconOnly = true }; pnlDisabledUpdate.Controls.Add(disabledIcon); dfuElemLib.Visible = false; } } } // Setup external edit if (isInDatabase) { ExternalEditHelper.LoadExternalEditControl(e.Item.FindControl("plcExtEditMfi"), FileTypeEnum.MediaFile, GetSiteName(data, true), importedMediaData, IsLiveSite, null, true); } } else if (((SourceType == MediaSourceEnum.Content) && (DisplayMode == ControlDisplayModeEnum.Default) && !notAttachment && !libraryFolder && !libraryUiFolder)) { // Setup external edit if (data.ContainsColumn("AttachmentGUID")) { LoadExternalEditControl(e.Item, FileTypeEnum.Attachment); } } else if (((SourceType == MediaSourceEnum.MediaLibraries) && (DisplayMode == ControlDisplayModeEnum.Default) && !libraryFolder && !libraryUiFolder)) { // Setup external edit if (data.ContainsColumn("FileGUID")) { LoadExternalEditControl(e.Item, FileTypeEnum.MediaFile); } } else { var plcLibraryUpdtAction = e.Item.FindControl("plcLibraryUpdtAction") as PlaceHolder; if (plcLibraryUpdtAction != null) { plcLibraryUpdtAction.Visible = false; } } if ((SourceType == MediaSourceEnum.MediaLibraries) && libraryFolder && IsFullListingMode) { // Initialize SELECT SUB-FOLDERS button var btn = e.Item.FindControl("imgSelectSubFolders") as CMSAccessibleButton; if (btn != null) { btn.Visible = true; btn.ToolTip = GetString("dialogs.list.actions.showsubfolders"); btn.OnClientClick = String.Format("SetLibParentAction({0}); return false;", ScriptHelper.GetString(fileName)); } } else { var plcSelectSubFolders = e.Item.FindControl("plcSelectSubFolders") as PlaceHolder; if (plcSelectSubFolders != null) { plcSelectSubFolders.Visible = false; } } #endregion #region "File image" // Selectable area Panel pnlItemInageContainer = e.Item.FindControl("pnlThumbnails") as Panel; if (pnlItemInageContainer != null) { if (isSelectable) { if ((DisplayMode == ControlDisplayModeEnum.Simple) && !isInDatabase) { if (libraryFolder || libraryUiFolder) { pnlItemInageContainer.Attributes["onclick"] = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } else { pnlItemInageContainer.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetAction('importfile', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(fullFileName)); } } else { pnlItemInageContainer.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(String.Format("{0}|URL|{1}", argument, selectUrlParameters.Url))); } pnlItemInageContainer.Attributes["style"] = "cursor:pointer;"; } else { pnlItemInageContainer.Attributes["style"] = "cursor:default;"; } } // Image area Image imgFile = e.Item.FindControl("imgFile") as Image; if (imgFile != null) { string chset = Guid.NewGuid().ToString(); var previewUrl = previewParameters.Url; previewUrl = URLHelper.AddParameterToUrl(previewUrl, "chset", chset); // Add latest version requirement for live site int versionHistoryId = VersionHistoryID; if (IsLiveSite && (versionHistoryId > 0)) { // Add requirement for latest version of files for current document string newparams = String.Format("latestforhistoryid={0}&hash={1}", versionHistoryId, ValidationHelper.GetHashString("h" + versionHistoryId)); previewUrl += "&" + newparams; } if (String.IsNullOrEmpty(previewParameters.IconClass)) { imgFile.ImageUrl = previewUrl; imgFile.AlternateText = TextHelper.LimitLength(fileName, 10); imgFile.Attributes["title"] = fileName.Replace("\"", "\\\""); // Ensure tooltip - only text description if (isInDatabase) { UIHelper.EnsureTooltip(imgFile, previewUrl, width, height, GetTitle(data, isContentFile), fileName, ext, GetDescription(data, isContentFile), null, 300); } } else { var imgIcon = e.Item.FindControl(("imgFileIcon")) as Label; if ((imgIcon != null) && imgIcon.Controls.Count < 1) { className = ValidationHelper.GetString(data.GetValue("ClassName"), String.Empty); var icon = UIHelper.GetDocumentTypeIcon(null, className, previewParameters.IconClass, previewParameters.IconSize); imgIcon.Controls.Add(new LiteralControl(icon)); // Ensure tooltip - only text description if (isInDatabase) { UIHelper.EnsureTooltip(imgIcon, previewUrl, width, height, GetTitle(data, isContentFile), fileName, ext, GetDescription(data, isContentFile), null, 300); } imgFile.Visible = false; } } } #endregion // Display only for ML UI if ((DisplayMode == ControlDisplayModeEnum.Simple) && !libraryFolder) { PlaceHolder plcSelectionBox = e.Item.FindControl("plcSelectionBox") as PlaceHolder; if (plcSelectionBox != null) { plcSelectionBox.Visible = true; // Multiple selection check-box CMSCheckBox chkSelected = e.Item.FindControl("chkSelected") as CMSCheckBox; if (chkSelected != null) { chkSelected.ToolTip = GetString("general.select"); chkSelected.InputAttributes["alt"] = fullFileName; HiddenField hdnItemName = e.Item.FindControl("hdnItemName") as HiddenField; if (hdnItemName != null) { hdnItemName.Value = fullFileName; } } } } }
/// <summary> /// Loads the external edit control and sets visibility of other controls /// </summary> /// <param name="repeaterItem">Repeater item</param> /// <param name="type">Source type</param> private void LoadExternalEditControl(RepeaterItem repeaterItem, FileTypeEnum type) { var plcAttachmentActions = repeaterItem.FindControl("plcAttachmentActions") as PlaceHolder; var plcAttachmentUpdtAction = repeaterItem.FindControl("plcAttachmentUpdtAction") as PlaceHolder; var plcLibraryUpdtAction = repeaterItem.FindControl("plcLibraryUpdtAction") as PlaceHolder; var plcExt = repeaterItem.FindControl("plcExtEdit") as PlaceHolder; var plcExtMfi = repeaterItem.FindControl("plcExtEditMfi") as PlaceHolder; var pnlDisabledUpdate = (repeaterItem.FindControl("pnlDisabledUpdate") as Panel); var dfuLib = repeaterItem.FindControl("dfuElemLib") as DirectFileUploader; var dfu = repeaterItem.FindControl("dfuElem") as DirectFileUploader; var btnEdit = repeaterItem.FindControl("btnEdit") as WebControl; var btnDelete = repeaterItem.FindControl("btnDelete") as WebControl; if ((plcAttachmentActions != null) && (plcLibraryUpdtAction != null) && (plcAttachmentUpdtAction != null) && (plcExt != null) && (plcExtMfi != null) && (pnlDisabledUpdate != null) && (dfuLib != null) && (dfu != null) && (btnEdit != null) && (btnDelete != null)) { var data = new DataRowContainer((DataRowView)repeaterItem.DataItem); plcAttachmentActions.Visible = true; plcAttachmentUpdtAction.Visible = false; pnlDisabledUpdate.Visible = false; dfuLib.Visible = false; dfu.Visible = false; btnEdit.Visible = false; btnDelete.Visible = false; plcExt.Visible = false; plcExtMfi.Visible = false; plcLibraryUpdtAction.Visible = (type == FileTypeEnum.MediaFile); ExternalEditHelper.LoadExternalEditControl(plcExt, type, null, data, IsLiveSite, TreeNodeObj, true); } }
/// <summary> /// External data binding handler. /// </summary> protected object gridDocuments_OnExternalDataBound(object sender, string sourceName, object parameter) { int currentNodeId = 0; sourceName = sourceName.ToLowerCSafe(); switch (sourceName) { case "view": { // Dialog view item DataRowView data = ((DataRowView)((GridViewRow)parameter).DataItem); ImageButton btn = ((ImageButton)sender); // Current row is the Root document isRootDocument = (ValidationHelper.GetInteger(data["NodeParentID"], 0) == 0); isCurrentDocument = (ValidationHelper.GetInteger(data["NodeID"], 0) == WOpenerNodeID); string url = string.Empty; string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); // Existing document culture if (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe()) { if (!isRootDocument) { url = ResolveUrl(DocumentURLProvider.GetUrl(Convert.ToString(data["NodeAliasPath"]))); } else { url = ResolveUrl("~/"); } btn.OnClientClick = "ViewItem(" + ScriptHelper.GetString(url) + "); return false;"; } // New culture version else { currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;"; } } break; case "edit": { DataRowView data = ((DataRowView)((GridViewRow)parameter).DataItem); ImageButton btn = ((ImageButton)sender); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0); if (!RequiresDialog || (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe())) { // Go to the selected document or create a new culture version when not used in a dialog btn.OnClientClick = "EditItem(" + currentNodeId + ", " + nodeParentId + "); return false;"; } else { // New culture version in a dialog btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;"; } } break; case "delete": { // Delete button ImageButton btn = ((ImageButton)sender); // Hide the delete button for the root document btn.Visible = !isRootDocument; } break; case "contextmenu": { // Dialog context menu item DataRowView data = ((DataRowView)((GridViewRow)parameter).DataItem); ImageButton btn = ((ImageButton)sender); // Hide the context menu for the root document btn.Visible = !isRootDocument; } break; case "published": { // Published state return UniGridFunctions.ColoredSpanYesNo(parameter); } case "versionnumber": { // Version number if (parameter == DBNull.Value) { parameter = "-"; } parameter = HTMLHelper.HTMLEncode(parameter.ToString()); return parameter; } case "documentname": { // Document name DataRowView data = (DataRowView)parameter; string className = ValidationHelper.GetString(data["ClassName"], string.Empty); string classDisplayName = ValidationHelper.GetString(data["classdisplayname"], null); string name = ValidationHelper.GetString(data["DocumentName"], string.Empty); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); string cultureString = null; currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0); if (isRootDocument) { // User site name for the root document name = CMSContext.CurrentSiteName; } // Default culture if (culture.ToLowerCSafe() != CultureCode.ToLowerCSafe()) { cultureString = " (" + culture + ")"; } string tooltip = UniGridFunctions.DocumentNameTooltip(data); StringBuilder sb = new StringBuilder(); if (ShowDocumentTypeIcon) { string imageUrl = null; if (className.EqualsCSafe("cms.file", true)) { string extension = ValidationHelper.GetString(data["DocumentType"], string.Empty); imageUrl = GetFileIconUrl(extension, "List"); } // Use class icons else { imageUrl = ResolveUrl(GetDocumentTypeIconUrl(className)); } // Prepare tooltip for document type icon string iconTooltip = ""; if (ShowDocumentTypeIconTooltip && (classDisplayName != null)) { iconTooltip = string.Format("onmouseout=\"UnTip()\" onmouseover=\"Tip('{0}')\"", HTMLHelper.HTMLEncode(ResHelper.LocalizeString(classDisplayName))); } sb.Append("<img src=\"", imageUrl, "\" class=\"UnigridActionButton\" alt=\"\" ", iconTooltip, "/> "); } string safeName = HTMLHelper.HTMLEncode(TextHelper.LimitLength(name, 50)); if (DocumentNameAsLink && !isRootDocument) { string selectFunction = SelectItemJSFunction + "(" + currentNodeId + ", " + nodeParentId + ");"; sb.Append("<a href=\"javascript: ", selectFunction, "\""); // Ensure onclick action on mobile devices. This is necessary due to Tip/UnTip functions. They block default click behavior on mobile devices. if (CMSContext.CurrentDevice.IsMobile) { sb.Append(" ontouchend=\"", selectFunction, "\""); } sb.Append(" onmouseout=\"UnTip()\" onmouseover=\"Tip('", tooltip, "')\">", safeName, cultureString, "</a>"); } else { sb.Append(safeName, cultureString); } if (ShowDocumentMarks) { // Prepare parameters int workflowStepId = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(data, "DocumentWorkflowStepID"), 0); WorkflowStepTypeEnum stepType = WorkflowStepTypeEnum.Undefined; if (workflowStepId > 0) { WorkflowStepInfo stepInfo = WorkflowStepInfoProvider.GetWorkflowStepInfo(workflowStepId); if (stepInfo != null) { stepType = stepInfo.StepType; } } // Create data container IDataContainer container = new DataRowContainer(data); // Add icons sb.Append(" ", UIHelper.GetDocumentMarks(Page, currentSiteName, CultureCode, stepType, container)); } return sb.ToString(); } case "documentculture": { DocumentFlagsControl ucDocFlags = null; if (OnDocumentFlagsCreating != null) { // Raise event for obtaining custom DocumentFlagControl object result = OnDocumentFlagsCreating(this, sourceName, parameter); ucDocFlags = result as DocumentFlagsControl; // Check if something other than DocumentFlagControl was returned if ((ucDocFlags == null) && (result != null)) { return result; } } // Dynamically load document flags control when not created if (ucDocFlags == null) { ucDocFlags = this.LoadUserControl("~/CMSAdminControls/UI/DocumentFlags.ascx") as DocumentFlagsControl; } // Set document flags properties if (ucDocFlags != null) { DataRowView data = (DataRowView)parameter; // Get node ID currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); if (!string.IsNullOrEmpty(SelectLanguageJSFunction)) { ucDocFlags.SelectJSFunction = SelectLanguageJSFunction; } ucDocFlags.ID = "docFlags" + currentNodeId; ucDocFlags.SiteCultures = SiteCultures; ucDocFlags.NodeID = currentNodeId; ucDocFlags.StopProcessing = true; ucDocFlags.ItemUrl = ResolveUrl(DocumentURLProvider.GetUrl(Convert.ToString(data["NodeAliasPath"]))); // Keep the control for later usage FlagsControls.Add(ucDocFlags); return ucDocFlags; } } break; case "modifiedwhen": case "modifiedwhentooltip": // Modified when if (string.IsNullOrEmpty(parameter.ToString())) { return string.Empty; } else { DateTime modifiedWhen = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME); currentUserInfo = currentUserInfo ?? CMSContext.CurrentUser; currentSiteInfo = currentSiteInfo ?? CMSContext.CurrentSite; bool displayGMT = (sourceName == "modifiedwhentooltip"); return TimeZoneHelper.ConvertToUserTimeZone(modifiedWhen, displayGMT, currentUserInfo, currentSiteInfo); } case "classdisplayname": case "classdisplaynametooltip": // Localize class display name if (!string.IsNullOrEmpty(parameter.ToString())) { return HTMLHelper.HTMLEncode(ResHelper.LocalizeString(parameter.ToString())); } return string.Empty; default: if (OnExternalAdditionalDataBound != null) { return OnExternalAdditionalDataBound(sender, sourceName, parameter); } break; } return parameter; }
/// <summary> /// Loads DataRow for BasicForm with data from FormFieldInfo settings and optionally with form control's default values. /// </summary> /// <param name="loadDefaultValues">Indicates if data container should be initialized with form control's default data</param> private DataRowContainer GetData(bool loadDefaultValues) { DataRowContainer result = new DataRowContainer(FormInfo.GetDataRow(loadDefaultValues)); if (loadDefaultValues) { // Load default values for visible properties (values of hidden form control properties shouldn't be stored in form definition) FormInfo.LoadDefaultValues(result, FormResolveTypeEnum.None, true); } if (Settings != null) { // Load settings of the existing field foreach (string columnName in Settings.Keys) { if (result.ContainsColumn(columnName)) { object value = Settings[columnName]; var settingField = FormInfo.GetFormField(columnName); if (!String.IsNullOrEmpty(Convert.ToString(value)) && IsDataTypeValid(value, settingField)) { result[columnName] = DataTypeManager.ConvertToSystemType(TypeEnum.Field, settingField.DataType, value, SystemContext.EnglishCulture); } } } } return result; }
/// <summary> /// Sets visibility of WebDAV edit control. /// </summary> /// <param name="repeaterItem">Repeater item</param> /// <param name="controlType">Control type</param> private void VisibleWebDAVEditControl(RepeaterItem repeaterItem, WebDAVControlTypeEnum controlType) { PlaceHolder plcAttachmentActions = repeaterItem.FindControl("plcAttachmentActions") as PlaceHolder; PlaceHolder plcAttachmentUpdtAction = repeaterItem.FindControl("plcAttachmentUpdtAction") as PlaceHolder; PlaceHolder plcLibraryUpdtAction = repeaterItem.FindControl("plcLibraryUpdtAction") as PlaceHolder; PlaceHolder plcWebDAV = repeaterItem.FindControl("plcWebDAV") as PlaceHolder; PlaceHolder plcWebDAVMfi = repeaterItem.FindControl("plcWebDAVMfi") as PlaceHolder; Panel pnlDisabledUpdate = (repeaterItem.FindControl("pnlDisabledUpdate") as Panel); DirectFileUploader dfuLib = repeaterItem.FindControl("dfuElemLib") as DirectFileUploader; DirectFileUploader dfu = repeaterItem.FindControl("dfuElem") as DirectFileUploader; ImageButton btnEdit = repeaterItem.FindControl("btnEdit") as ImageButton; ImageButton btnDelete = repeaterItem.FindControl("btnDelete") as ImageButton; if ((plcAttachmentActions != null) && (plcLibraryUpdtAction != null) && (plcAttachmentUpdtAction != null) && (plcWebDAV != null) && (plcWebDAVMfi != null) && (pnlDisabledUpdate != null) && (dfuLib != null) && (dfu != null) && (btnEdit != null) && (btnDelete != null)) { WebDAVEditControl webDAVElem = null; if (controlType == WebDAVControlTypeEnum.Media) { plcAttachmentActions.Visible = true; plcAttachmentUpdtAction.Visible = false; plcLibraryUpdtAction.Visible = true; pnlDisabledUpdate.Visible = false; dfuLib.Visible = false; dfu.Visible = false; btnEdit.Visible = false; btnDelete.Visible = false; plcWebDAV.Visible = false; webDAVElem = Page.LoadUserControl("~/CMSModules/MediaLibrary/Controls/WebDAV/MediaFileWebDAVEditControl.ascx") as WebDAVEditControl; if (webDAVElem != null) { plcWebDAVMfi.Controls.Clear(); plcWebDAVMfi.Controls.Add(webDAVElem); } } else if (controlType == WebDAVControlTypeEnum.Attachment) { plcAttachmentActions.Visible = true; plcAttachmentUpdtAction.Visible = false; plcLibraryUpdtAction.Visible = false; pnlDisabledUpdate.Visible = false; dfuLib.Visible = false; dfu.Visible = false; btnEdit.Visible = false; btnDelete.Visible = false; plcWebDAV.Visible = true; // Dynamically load control webDAVElem = Page.LoadUserControl("~/CMSModules/WebDAV/Controls/AttachmentWebDAVEditControl.ascx") as WebDAVEditControl; if (webDAVElem != null) { plcWebDAV.Controls.Clear(); plcWebDAV.Controls.Add(webDAVElem); } } if (webDAVElem != null) { webDAVElem.Visible = false; webDAVElem.CssClass = null; IDataContainer data = new DataRowContainer((DataRowView)repeaterItem.DataItem); string extension = data.GetValue(FileExtensionColumn).ToString(); // If the WebDAV is enabled and windows authentication and extension is allowed if (CMSContext.IsWebDAVEnabled(CMSContext.CurrentSiteName) && RequestHelper.IsWindowsAuthentication() && WebDAVSettings.IsExtensionAllowedForEditMode(extension, CMSContext.CurrentSiteName)) { // Set WebDAV edit control GetWebDAVEditControl(ref webDAVElem, data); } } } }
/// <summary> /// External data binding handler. /// </summary> protected object gridDocuments_OnExternalDataBound(object sender, string sourceName, object parameter) { int currentNodeId = 0; sourceName = sourceName.ToLower(); switch (sourceName) { case "published": { // Published state bool published = ValidationHelper.GetBoolean(parameter, true); if (published) { return "<span class=\"DocumentPublishedYes\">" + GetString("General.Yes") + "</span>"; } else { return "<span class=\"DocumentPublishedNo\">" + GetString("General.No") + "</span>"; } } case "versionnumber": { // Version number if (parameter == DBNull.Value) { parameter = "-"; } parameter = HTMLHelper.HTMLEncode(parameter.ToString()); return parameter; } case "documentname": { // Document name DataRowView data = (DataRowView)parameter; string className = ValidationHelper.GetString(data["ClassName"], string.Empty); string name = ValidationHelper.GetString(data["DocumentName"], string.Empty); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); string cultureString = null; currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0); string preferredCulture = CMSContext.PreferredCultureCode; // Default culture if (culture.ToLower() != preferredCulture.ToLower()) { cultureString = " (" + culture + ")"; } string tooltip = UniGridFunctions.DocumentNameTooltip(data); string imageUrl = null; if (className.Equals("cms.file", StringComparison.InvariantCultureIgnoreCase)) { string extension = ValidationHelper.GetString(data["DocumentType"], ""); imageUrl = GetFileIconUrl(extension, "List"); } // Use class icons else { imageUrl = ResolveUrl(GetDocumentTypeIconUrl(className)); } StringBuilder sb = new StringBuilder(); sb.Append( "<img src=\"", imageUrl, "\" class=\"UnigridActionButton\" /> ", "<a href=\"javascript: SelectItem(", currentNodeId, ", ", nodeParentId, ");\" ", "onmouseout=\"UnTip()\" onmouseover=\"Tip('", tooltip, "')\">", HTMLHelper.HTMLEncode(TextHelper.LimitLength(name, 50)), cultureString, "</a>" ); // Prepare parameters int workflowStepId = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(data, "DocumentWorkflowStepID"), 0); string stepName = null; if (workflowStepId > 0) { WorkflowStepInfo stepInfo = WorkflowStepInfoProvider.GetWorkflowStepInfo(workflowStepId); if (stepInfo != null) { stepName = stepInfo.StepName; } } // Create data container IDataContainer container = new DataRowContainer(data); // Add icons sb.Append(" ", UIHelper.GetDocumentMarks(Page, currentSiteName, preferredCulture, stepName, container)); return sb.ToString(); } case "documentculture": { // Dynamically load document flags control DocumentFlagsControl ucDocFlags = Page.LoadControl("~/CMSAdminControls/UI/DocumentFlags.ascx") as DocumentFlagsControl; // Set document flags properties if (ucDocFlags != null) { // Get node ID currentNodeId = ValidationHelper.GetInteger(parameter, 0); ucDocFlags.ID = "docFlags" + currentNodeId; ucDocFlags.SiteCultures = SiteCultures; ucDocFlags.NodeID = currentNodeId; ucDocFlags.StopProcessing = true; // Keep the control for later usage FlagsControls.Add(ucDocFlags); return ucDocFlags; } } break; case "modifiedwhen": case "modifiedwhentooltip": // Modified when if (string.IsNullOrEmpty(parameter.ToString())) { return ""; } else { DateTime modifiedWhen = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME); if (currentUserInfo == null) { currentUserInfo = CMSContext.CurrentUser; } if (currentSiteInfo == null) { currentSiteInfo = CMSContext.CurrentSite; } bool displayGMT = (sourceName == "modifiedwhentooltip"); return TimeZoneHelper.ConvertToUserTimeZone(modifiedWhen, displayGMT, currentUserInfo, currentSiteInfo); } case "classdisplayname": case "classdisplaynametooltip": // Localize class display name if (!string.IsNullOrEmpty(parameter.ToString())) { return HTMLHelper.HTMLEncode(ResHelper.LocalizeString(parameter.ToString())); } return ""; } return parameter; }
protected void TilesViewControl_ItemDataBound(object sender, RepeaterItemEventArgs e) { #region "Load item data" string className = ""; string fileNameColumn = FileNameColumn; IDataContainer data = new DataRowContainer((DataRowView)e.Item.DataItem); bool isContent = (SourceType == MediaSourceEnum.Content); bool isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; bool notAttachment = isContent && !(isContentFile && (data.GetValue("AttachmentGUID") != DBNull.Value)); if (notAttachment) { className = DataClassInfoProvider.GetDataClass((int)data.GetValue("NodeClassID")).ClassDisplayName; fileNameColumn = "DocumentName"; } else { fileNameColumn = "AttachmentName"; } // Get basic information on file (use field properties for CMS.File | attachment, document columns otherwise) string fileName = HTMLHelper.HTMLEncode((data.ContainsColumn(fileNameColumn) ? data.GetValue(fileNameColumn).ToString() : data.GetValue(FileNameColumn).ToString())); string ext = notAttachment ? className : data.GetValue(FileExtensionColumn).ToString().TrimStart('.'); string argument = RaiseOnGetArgumentSet(data); // Get full media library file name bool isInDatabase = true; string fullFileName = GetFileName(data); IDataContainer importedMediaData = null; if ((SourceType == MediaSourceEnum.MediaLibraries) && (DisplayMode == ControlDisplayModeEnum.Simple)) { importedMediaData = RaiseOnFileIsNotInDatabase(fullFileName); isInDatabase = (importedMediaData != null); } string selectUrl = RaiseOnGetTilesThumbsItemUrl(data, false, 0, 0, 0, notAttachment); bool isSelectable = CMSDialogHelper.IsItemSelectable(SelectableContent, ext, isContentFile); bool libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); bool libraryUiFolder = libraryFolder && !((DisplayMode == ControlDisplayModeEnum.Simple) && isInDatabase); int width = 0; int height = 0; // Width if (data.ContainsColumn(FileWidthColumn)) { width = ValidationHelper.GetInteger(data.GetValue(FileWidthColumn), 0); } else if (isInDatabase && (DisplayMode == ControlDisplayModeEnum.Simple) && importedMediaData.ContainsColumn(FileWidthColumn)) { width = ValidationHelper.GetInteger(importedMediaData.GetValue(FileWidthColumn), 0); } // Height if (data.ContainsColumn(FileHeightColumn)) { height = ValidationHelper.GetInteger(data.GetValue(FileHeightColumn), 0); } else if (isInDatabase && (DisplayMode == ControlDisplayModeEnum.Simple) && importedMediaData.ContainsColumn(FileHeightColumn)) { height = ValidationHelper.GetInteger(importedMediaData.GetValue(FileHeightColumn), 0); } // Get item image URL from the parent set string previewUrl = ""; if ((SourceType == MediaSourceEnum.MediaLibraries) && isInDatabase && (DisplayMode == ControlDisplayModeEnum.Simple)) { previewUrl = RaiseOnGetTilesThumbsItemUrl(importedMediaData, true, 0, 0, 48, notAttachment); } else { previewUrl = RaiseOnGetTilesThumbsItemUrl(data, true, 0, 0, 48, notAttachment); } #endregion #region "Standard controls and actions" bool hideDocName = false; Label lblDocumentName = null; if (isContent && !notAttachment) { string docName = Path.GetFileNameWithoutExtension(data.GetValue(FileNameColumn).ToString()); fileName = Path.GetFileNameWithoutExtension(fileName); hideDocName = (docName.ToLowerCSafe() == fileName.ToLowerCSafe()); if (!hideDocName) { fileName += "." + ext; lblDocumentName = e.Item.FindControl("lblDocumentName") as Label; if (lblDocumentName != null) { lblDocumentName.Attributes["class"] = "DialogTileTitleBold"; lblDocumentName.Text = HTMLHelper.HTMLEncode(docName); } } else { fileName = docName; } } // Do not display document name if the same as the file name if (hideDocName || (lblDocumentName == null) || string.IsNullOrEmpty(lblDocumentName.Text)) { PlaceHolder plcDocumentName = e.Item.FindControl("plcDocumentName") as PlaceHolder; if (plcDocumentName != null) { plcDocumentName.Visible = false; } } // Load file name Label lblFileName = e.Item.FindControl("lblFileName") as Label; if (lblFileName != null) { if (SourceType == MediaSourceEnum.DocumentAttachments) { fileName = Path.GetFileNameWithoutExtension(fileName); } lblFileName.Text = fileName; } // Load file type Label lblType = e.Item.FindControl("lblTypeValue") as Label; if (lblType != null) { lblType.Text = notAttachment ? ResHelper.LocalizeString(ext) : NormalizeExtenison(ext); } if (!notAttachment && !libraryFolder) { // Load file size Label lblSize = e.Item.FindControl("lblSizeValue") as Label; if (lblSize != null) { long size = 0; if (data.ContainsColumn(FileSizeColumn)) { size = ValidationHelper.GetLong(data.GetValue(FileSizeColumn), 0); } // Library files else if (data.ContainsColumn("Size")) { size = ValidationHelper.GetLong((importedMediaData != null) ? importedMediaData["FileSize"] : data.GetValue("Size"), 0); } lblSize.Text = DataHelper.GetSizeString(size); } } // Initialize SELECT button ImageButton btnSelect = e.Item.FindControl("btnSelect") as ImageButton; if (btnSelect != null) { // Check if item is selectable, if not remove select action button if (!isSelectable) { btnSelect.ImageUrl = ResolveUrl(ImagesPath + "transparent.png"); btnSelect.ToolTip = ""; btnSelect.Attributes.Remove("onclick"); btnSelect.Attributes["style"] = "cursor:default;"; btnSelect.Enabled = false; } else { // If media file not imported yet - display warning sign if ((SourceType == MediaSourceEnum.MediaLibraries) && ((DisplayMode == ControlDisplayModeEnum.Simple) && !isInDatabase && !libraryFolder)) { btnSelect.ImageUrl = ResolveUrl(ImagesPath + "warning.png"); btnSelect.ToolTip = GetString("media.file.import"); btnSelect.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetAction('importfile',{1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(fullFileName)); } else { // Initialize command if (libraryFolder) { btnSelect.ImageUrl = ResolveUrl(ImagesPath + "subdocument.png"); btnSelect.ToolTip = GetString("dialogs.list.actions.showsubfolders"); btnSelect.Attributes["onclick"] = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } else { btnSelect.ImageUrl = ResolveUrl(ImagesPath + "next.png"); btnSelect.ToolTip = GetString("dialogs.list.actions.select"); btnSelect.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(String.Format("{0}|URL|{1}", argument, selectUrl))); } } } } // Initialize SELECTSUBDOCS button ImageButton btnSelectSubDocs = e.Item.FindControl("btnSelectSubDocs") as ImageButton; if (btnSelectSubDocs != null) { btnSelectSubDocs.ToolTip = GetString("dialogs.list.actions.showsubdocuments"); if (IsFullListingMode && (SourceType == MediaSourceEnum.Content)) { int nodeId = ValidationHelper.GetInteger(data.GetValue("NodeID"), 0); // Check if item is selectable, if not remove select action button // Initialize command btnSelectSubDocs.Attributes["onclick"] = String.Format("SetParentAction('{0}'); return false;", nodeId); btnSelectSubDocs.ImageUrl = ResolveUrl(ImagesPath + "subdocument.png"); } else { PlaceHolder plcSelectSubDocs = e.Item.FindControl("plcSelectSubDocs") as PlaceHolder; if (plcSelectSubDocs != null) { plcSelectSubDocs.Visible = false; } } } // Initialize VIEW button // Get media file URL according system settings argument = RaiseOnGetArgumentSet(data); ImageButton btnView = e.Item.FindControl("btnView") as ImageButton; if (btnView != null) { if (!notAttachment && !libraryFolder && !libraryUiFolder) { if (String.IsNullOrEmpty(selectUrl)) { btnView.ImageUrl = ResolveUrl(ImagesPath + "viewdisabled.png"); btnView.OnClientClick = "return false;"; btnView.Attributes["style"] = "cursor:default;"; btnView.Enabled = false; } else { btnView.ImageUrl = ResolveUrl(ImagesPath + "view.png"); btnView.ToolTip = GetString("dialogs.list.actions.view"); btnView.OnClientClick = String.Format("javascript: window.open({0}); return false;", ScriptHelper.GetString(URLHelper.ResolveUrl(selectUrl))); } } else { btnView.Visible = false; } } // Initialize EDIT button ImageButton btnContentEdit = e.Item.FindControl("btnContentEdit") as ImageButton; if (btnContentEdit != null) { Guid guid = Guid.Empty; btnContentEdit.ToolTip = GetString("general.edit"); btnContentEdit.ImageUrl = ResolveUrl(ImagesPath + "edit.png"); if ((SourceType == MediaSourceEnum.MediaLibraries) && !libraryFolder && !libraryUiFolder) { // Media files coming from FS if (!data.ContainsColumn("FileGUID")) { // Get file name fileName = fullFileName; ext = data.ContainsColumn("FileExtension") ? data.GetValue("FileExtension").ToString() : data.GetValue("Extension").ToString(); if (!((DisplayMode == ControlDisplayModeEnum.Simple) && isInDatabase)) { btnContentEdit.ImageUrl = ResolveUrl(ImagesPath + "editdisabled.png"); btnContentEdit.Attributes["style"] = "cursor: default;"; btnContentEdit.Enabled = false; } else { btnContentEdit.OnClientClick = String.Format("$j('#hdnFileOrigName').attr('value', {0}); SetAction('editlibraryui', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(EnsureFileName(fileName)), ScriptHelper.GetString(fileName)); } } else { guid = ValidationHelper.GetGuid(data.GetValue("FileGUID"), Guid.Empty); btnContentEdit.AlternateText = String.Format("{0}|MediaFileGUID={1}&sitename={2}", ext, guid, GetSiteName(data, true)); btnContentEdit.PreRender += img_PreRender; } } else if (SourceType == MediaSourceEnum.MetaFile) { // If MetaFiles being displayed set EDIT action string metaExtension = ValidationHelper.GetString(data.GetValue("MetaFileExtension"), string.Empty).ToLowerCSafe(); Guid metaGuid = ValidationHelper.GetGuid(data.GetValue("MetaFileGUID"), Guid.Empty); btnContentEdit.AlternateText = String.Format("{0}|metafileguid={1}", metaExtension, metaGuid); btnContentEdit.PreRender += img_PreRender; } else if (!notAttachment && (SourceType != MediaSourceEnum.DocumentAttachments) && !libraryFolder && !libraryUiFolder) { string nodeid = ""; if (SourceType == MediaSourceEnum.Content) { nodeid = "&nodeId=" + data.GetValue("NodeID"); // Get the node workflow VersionHistoryID = ValidationHelper.GetInteger(data.GetValue("DocumentCheckedOutVersionHistoryID"), 0); } guid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); btnContentEdit.AlternateText = String.Format("{0}|AttachmentGUID={1}&sitename={2}{3}{4}", ext, guid, GetSiteName(data, false), nodeid, ((VersionHistoryID > 0) ? "&versionHistoryId=" + VersionHistoryID : "")); btnContentEdit.PreRender += img_PreRender; } else { btnContentEdit.Visible = false; } } #endregion #region "Special actions" // If attachments being displayed show additional actions if (SourceType == MediaSourceEnum.DocumentAttachments) { // Initialize UPDATE button DirectFileUploader dfuElem = e.Item.FindControl("dfuElem") as DirectFileUploader; if (dfuElem != null) { GetAttachmentUpdateControl(ref dfuElem, data); } string attExtension = data.GetValue("AttachmentExtension").ToString(); // If the WebDAV is enabled and windows authentication and extension is allowed if (CMSContext.IsWebDAVEnabled(CMSContext.CurrentSiteName) && RequestHelper.IsWindowsAuthentication() && WebDAVSettings.IsExtensionAllowedForEditMode(attExtension, CMSContext.CurrentSiteName)) { PlaceHolder plcWebDAV = e.Item.FindControl("plcWebDAV") as PlaceHolder; if (plcWebDAV != null) { // Dynamically load control WebDAVEditControl webDAVElem = Page.LoadUserControl("~/CMSModules/WebDAV/Controls/AttachmentWebDAVEditControl.ascx") as WebDAVEditControl; if (webDAVElem != null) { plcWebDAV.Controls.Clear(); plcWebDAV.Controls.Add(webDAVElem); webDAVElem.Visible = false; // Set WebDAV edit control GetWebDAVEditControl(ref webDAVElem, data); webDAVElem.CssClass = null; plcWebDAV.Visible = true; } } } // Initialize EDIT button ImageButton btnEdit = e.Item.FindControl("btnEdit") as ImageButton; if (btnEdit != null) { if (!notAttachment) { btnEdit.ToolTip = GetString("general.edit"); // Get file extension string extension = ValidationHelper.GetString(data.GetValue("AttachmentExtension"), "").ToLowerCSafe(); Guid guid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); btnEdit.ImageUrl = ResolveUrl(ImagesPath + "edit.png"); btnEdit.AlternateText = String.Format("{0}|AttachmentGUID={1}&sitename={2}&versionHistoryId={3}", extension, guid, GetSiteName(data, false), VersionHistoryID); btnEdit.PreRender += img_PreRender; } } // Initialize DELETE button ImageButton btnDelete = e.Item.FindControl("btnDelete") as ImageButton; if (btnDelete != null) { btnDelete.ImageUrl = ResolveUrl(ImagesPath + "delete.png"); btnDelete.ToolTip = GetString("general.delete"); // Initialize command btnDelete.Attributes["onclick"] = String.Format("if(DeleteConfirmation() == false){{return false;}} SetAction('attachmentdelete','{0}'); RaiseHiddenPostBack(); return false;", data.GetValue("AttachmentGUID")); } PlaceHolder plcContentEdit = e.Item.FindControl("plcContentEdit") as PlaceHolder; if (plcContentEdit != null) { plcContentEdit.Visible = false; } } else if ((SourceType == MediaSourceEnum.MediaLibraries) && !data.ContainsColumn("FileGUID") && !((DisplayMode == ControlDisplayModeEnum.Simple) && (libraryFolder || libraryUiFolder))) { // Initialize DELETE button ImageButton btnDelete = e.Item.FindControl("btnDelete") as ImageButton; if (btnDelete != null) { btnDelete.ImageUrl = ResolveUrl(ImagesPath + "Delete.png"); btnDelete.ToolTip = GetString("general.delete"); btnDelete.Attributes["onclick"] = String.Format("if(DeleteMediaFileConfirmation() == false){{return false;}} SetAction('deletefile',{0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fullFileName)); } // Hide attachment specific actions PlaceHolder plcAttachmentUpdtAction = e.Item.FindControl("plcAttachmentUpdtAction") as PlaceHolder; if (plcAttachmentUpdtAction != null) { plcAttachmentUpdtAction.Visible = false; } } else { PlaceHolder plcAttachmentActions = e.Item.FindControl("plcAttachmentActions") as PlaceHolder; if (plcAttachmentActions != null) { plcAttachmentActions.Visible = false; } } #endregion #region "Library action" if ((SourceType == MediaSourceEnum.MediaLibraries) && (DisplayMode == ControlDisplayModeEnum.Simple)) { // Initialize UPDATE button DirectFileUploader dfuElemLib = e.Item.FindControl("dfuElemLib") as DirectFileUploader; if (dfuElemLib != null) { Panel pnlDisabledUpdate = (e.Item.FindControl("pnlDisabledUpdate") as Panel); if (pnlDisabledUpdate != null) { bool hasModifyPermission = RaiseOnGetModifyPermission(data); if (isInDatabase && hasModifyPermission) { GetLibraryUpdateControl(ref dfuElemLib, importedMediaData); pnlDisabledUpdate.Visible = false; } else { pnlDisabledUpdate.Controls.Clear(); ImageButton imgBtn = new ImageButton() { Enabled = false, ImageUrl = ResolveUrl(GetImageUrl("Design/Controls/DirectUploader/uploaddisabled.png")) }; imgBtn.Attributes["style"] = "cursor: default;"; pnlDisabledUpdate.Controls.Add(imgBtn); dfuElemLib.Visible = false; } } } string siteName = GetSiteName(data, true); // If the WebDAV is enabled and windows authentication and extension is allowed and media file is in database if (CMSContext.IsWebDAVEnabled(siteName) && RequestHelper.IsWindowsAuthentication() && WebDAVSettings.IsExtensionAllowedForEditMode(ext, siteName) && isInDatabase) { PlaceHolder plcWebDAVMfi = e.Item.FindControl("plcWebDAVMfi") as PlaceHolder; if (plcWebDAVMfi != null) { // Dynamically load control WebDAVEditControl webDAVElem = Page.LoadUserControl("~/CMSModules/MediaLibrary/Controls/WebDAV/MediaFileWebDAVEditControl.ascx") as WebDAVEditControl; if (webDAVElem != null) { webDAVElem.Visible = false; plcWebDAVMfi.Controls.Clear(); plcWebDAVMfi.Controls.Add(webDAVElem); // Set WebDAV edit control GetWebDAVEditControl(ref webDAVElem, importedMediaData); } } } } else if ((SourceType == MediaSourceEnum.Content && (DisplayMode == ControlDisplayModeEnum.Default) && !notAttachment && !libraryFolder && !libraryUiFolder)) { // Initialize WebDAV edit button if (data.ContainsColumn("AttachmentGUID")) { VisibleWebDAVEditControl(e.Item, WebDAVControlTypeEnum.Attachment); } } else if ((SourceType == MediaSourceEnum.MediaLibraries && (DisplayMode == ControlDisplayModeEnum.Default) && !libraryFolder && !libraryUiFolder)) { // Initialize WebDAV edit button if (data.ContainsColumn("FileGUID")) { VisibleWebDAVEditControl(e.Item, WebDAVControlTypeEnum.Media); } } else { PlaceHolder plcLibraryUpdtAction = e.Item.FindControl("plcLibraryUpdtAction") as PlaceHolder; if (plcLibraryUpdtAction != null) { plcLibraryUpdtAction.Visible = false; } } if ((SourceType == MediaSourceEnum.MediaLibraries) && libraryFolder && IsFullListingMode) { // Initialize SELECT SUB-FOLDERS button ImageButton btn = e.Item.FindControl("imgSelectSubFolders") as ImageButton; if (btn != null) { btn.Visible = true; btn.ImageUrl = ResolveUrl(ImagesPath + "subdocument.png"); btn.ToolTip = GetString("dialogs.list.actions.showsubfolders"); btn.Attributes["onclick"] = String.Format("SetLibParentAction({0}); return false;", ScriptHelper.GetString(fileName)); } } else { PlaceHolder plcSelectSubFolders = e.Item.FindControl("plcSelectSubFolders") as PlaceHolder; if (plcSelectSubFolders != null) { plcSelectSubFolders.Visible = false; } } #endregion #region "Load file image" // Selectable area Panel pnlItemInageContainer = e.Item.FindControl("pnlTiles") as Panel; if (pnlItemInageContainer != null) { if (isSelectable) { if ((DisplayMode == ControlDisplayModeEnum.Simple) && !isInDatabase) { if (libraryFolder || libraryUiFolder) { pnlItemInageContainer.Attributes["onclick"] = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } else { pnlItemInageContainer.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetAction('importfile', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(fullFileName)); } } else { pnlItemInageContainer.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(String.Format("{0}|URL|{1}", argument, selectUrl))); } pnlItemInageContainer.Attributes["style"] = "cursor:pointer;"; } else { pnlItemInageContainer.Attributes["style"] = "cursor:default;"; } } // Image area Image fileImage = e.Item.FindControl("imgElem") as Image; if (fileImage != null) { string chset = Guid.NewGuid().ToString(); previewUrl = URLHelper.AddParameterToUrl(previewUrl, "chset", chset); // Add latest version requirement for live site int versionHistoryId = VersionHistoryID; if (IsLiveSite && (versionHistoryId > 0)) { // Add requirement for latest version of files for current document string newparams = "latestforhistoryid=" + versionHistoryId; newparams += "&hash=" + ValidationHelper.GetHashString("h" + versionHistoryId); previewUrl += "&" + newparams; } fileImage.ImageUrl = ResolveUrl(previewUrl); // Ensure tooltip if (isInDatabase) { UIHelper.EnsureTooltip(fileImage, previewUrl, width, height, GetTitle(data, isContentFile), fileName, ext, GetDescription(data, isContentFile), null, 300); } } #endregion // Display only for ML UI if ((DisplayMode == ControlDisplayModeEnum.Simple) && !libraryFolder) { PlaceHolder plcSelectionBox = e.Item.FindControl("plcSelectionBox") as PlaceHolder; if (plcSelectionBox != null) { plcSelectionBox.Visible = true; // Multiple selection check-box LocalizedCheckBox chkSelected = e.Item.FindControl("chkSelected") as LocalizedCheckBox; if (chkSelected != null) { chkSelected.ToolTip = GetString("general.select"); chkSelected.InputAttributes["alt"] = fullFileName; HiddenField hdnItemName = e.Item.FindControl("hdnItemName") as HiddenField; if (hdnItemName != null) { hdnItemName.Value = fullFileName; } } } } }
/// <summary> /// External data binding handler. /// </summary> protected object gridDocuments_OnExternalDataBound(object sender, string sourceName, object parameter) { int currentNodeId; sourceName = sourceName.ToLowerCSafe(); switch (sourceName) { case "view": { // Dialog view item DataRowView data = ((DataRowView)((GridViewRow)parameter).DataItem); CMSGridActionButton btn = ((CMSGridActionButton)sender); // Current row is the Root document isRootDocument = (ValidationHelper.GetInteger(data["NodeParentID"], 0) == 0); currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); isCurrentDocument = (currentNodeId == WOpenerNodeID); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); // Existing document culture if (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe()) { string className = ValidationHelper.GetString(data["ClassName"], string.Empty); if (DataClassInfoProvider.GetDataClassInfo(className).ClassHasURL) { var relativeUrl = isRootDocument ? "~/" : DocumentUIHelper.GetPageHandlerPreviewPath(currentNodeId, culture, CurrentUser.UserName); string url = ResolveUrl(relativeUrl); btn.OnClientClick = "ViewItem(" + ScriptHelper.GetString(url) + "); return false;"; } else { btn.Enabled = false; btn.Style.Add(HtmlTextWriterStyle.Cursor, "default"); } } // New culture version else { btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;"; } } break; case "edit": { CMSGridActionButton btn = ((CMSGridActionButton)sender); if (IsEditVisible) { DataRowView data = ((DataRowView)((GridViewRow)parameter).DataItem); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0); if (!RequiresDialog || (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe())) { // Go to the selected document or create a new culture version when not used in a dialog btn.OnClientClick = "EditItem(" + currentNodeId + ", " + nodeParentId + "); return false;"; } else { // New culture version in a dialog btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;"; } } else { btn.Visible = false; } } break; case "delete": { // Delete button CMSGridActionButton btn = ((CMSGridActionButton)sender); // Hide the delete button for the root document btn.Visible = !isRootDocument; } break; case "contextmenu": { // Dialog context menu item CMSGridActionButton btn = ((CMSGridActionButton)sender); // Hide the context menu for the root document btn.Visible = !isRootDocument && !ShowAllLevels; } break; case "versionnumber": { // Version number if (parameter == DBNull.Value) { parameter = "-"; } parameter = HTMLHelper.HTMLEncode(parameter.ToString()); return(parameter); } case "documentname": { // Document name DataRowView data = (DataRowView)parameter; string className = ValidationHelper.GetString(data["ClassName"], string.Empty); string classDisplayName = ValidationHelper.GetString(data["classdisplayname"], null); string name = ValidationHelper.GetString(data["DocumentName"], string.Empty); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); string cultureString = null; currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0); if (isRootDocument) { // User site name for the root document name = SiteContext.CurrentSiteName; } // Default culture if (culture.ToLowerCSafe() != CultureCode.ToLowerCSafe()) { cultureString = " (" + culture + ")"; } StringBuilder sb = new StringBuilder(); if (ShowDocumentTypeIcon) { // Prepare tooltip for document type icon string iconTooltip = ""; if (ShowDocumentTypeIconTooltip && (classDisplayName != null)) { string safeClassName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(classDisplayName)); iconTooltip = string.Format("onmouseout=\"UnTip()\" onmouseover=\"Tip('{0}')\"", HTMLHelper.EncodeForHtmlAttribute(safeClassName)); } var dataClass = DataClassInfoProvider.GetDataClassInfo(className); if (dataClass != null) { var iconClass = (string)dataClass.GetValue("ClassIconClass"); sb.Append(UIHelper.GetDocumentTypeIcon(Page, className, iconClass, additionalAttributes: iconTooltip)); } } string safeName = HTMLHelper.HTMLEncode(TextHelper.LimitLength(name, 50)); if (DocumentNameAsLink && !isRootDocument) { string tooltip = UniGridFunctions.DocumentNameTooltip(data); string selectFunction = SelectItemJSFunction + "(" + currentNodeId + ", " + nodeParentId + ");"; sb.Append("<a href=\"javascript: ", selectFunction, "\""); sb.Append(" onmouseout=\"UnTip()\" onmouseover=\"Tip('", HTMLHelper.EncodeForHtmlAttribute(tooltip), "')\">", safeName, cultureString, "</a>"); } else { sb.Append(safeName, cultureString); } // Show document marks only if method is not called from grid export and document marks are allowed if ((sender != null) && ShowDocumentMarks) { // Prepare parameters int workflowStepId = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(data, "DocumentWorkflowStepID"), 0); WorkflowStepTypeEnum stepType = WorkflowStepTypeEnum.Undefined; if (workflowStepId > 0) { WorkflowStepInfo stepInfo = WorkflowStepInfo.Provider.Get(workflowStepId); if (stepInfo != null) { stepType = stepInfo.StepType; } } // Create data container IDataContainer container = new DataRowContainer(data); // Add icons and use current culture of processed node because of 'Not translated document' icon sb.Append(" ", DocumentUIHelper.GetDocumentMarks(Page, currentSiteName, ValidationHelper.GetString(container.GetValue("DocumentCulture"), string.Empty), stepType, container)); } return(sb.ToString()); } case "documentculture": { DocumentFlagsControl ucDocFlags = null; if (OnDocumentFlagsCreating != null) { // Raise event for obtaining custom DocumentFlagControl object result = OnDocumentFlagsCreating(this, sourceName, parameter); ucDocFlags = result as DocumentFlagsControl; // Check if something other than DocumentFlagControl was returned if ((ucDocFlags == null) && (result != null)) { return(result); } } // Dynamically load document flags control when not created if (ucDocFlags == null) { ucDocFlags = LoadUserControl("~/CMSAdminControls/UI/DocumentFlags.ascx") as DocumentFlagsControl; } // Set document flags properties if (ucDocFlags != null) { DataRowView data = (DataRowView)parameter; // Get node ID currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); if (!string.IsNullOrEmpty(SelectLanguageJSFunction)) { ucDocFlags.SelectJSFunction = SelectLanguageJSFunction; } ucDocFlags.ID = "docFlags" + currentNodeId; ucDocFlags.SiteCultures = SiteCultures; ucDocFlags.NodeID = currentNodeId; ucDocFlags.StopProcessing = true; // Keep the control for later usage FlagsControls.Add(ucDocFlags); return(ucDocFlags); } } break; case "modifiedwhen": case "modifiedwhentooltip": // Modified when if (string.IsNullOrEmpty(parameter.ToString())) { return(string.Empty); } DateTime modifiedWhen = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME); currentUserInfo = currentUserInfo ?? MembershipContext.AuthenticatedUser; currentSiteInfo = currentSiteInfo ?? SiteContext.CurrentSite; return(sourceName.EqualsCSafe("modifiedwhen", StringComparison.InvariantCultureIgnoreCase) ? TimeZoneHelper.ConvertToUserTimeZone(modifiedWhen, true, currentUserInfo, currentSiteInfo) : TimeZoneHelper.GetUTCLongStringOffset(currentUserInfo, currentSiteInfo)); default: if (OnExternalAdditionalDataBound != null) { return(OnExternalAdditionalDataBound(sender, sourceName, parameter)); } break; } return(parameter); }
protected void ViewControl_ItemDataBound(object sender, RepeaterItemEventArgs e) { DataRowView drv = (DataRowView)e.Item.DataItem; IDataContainer data = new DataRowContainer(drv); string fileNameColumn = FileNameColumn; // Get information on file string fileName = HTMLHelper.HTMLEncode(data.GetValue(fileNameColumn).ToString()); string ext = HTMLHelper.HTMLEncode(data.GetValue(FileExtensionColumn).ToString()); // Load file type Label lblType = e.Item.FindControl("lblTypeValue") as Label; if (lblType != null) { fileName = fileName.Substring(0, fileName.Length - ext.Length); lblType.Text = ResHelper.LocalizeString(ext); } // Load file name Label lblName = e.Item.FindControl("lblFileName") as Label; if (lblName != null) { lblName.Text = fileName; } // Load file size Label lblSize = e.Item.FindControl("lblSizeValue") as Label; if (lblSize != null) { long size = ValidationHelper.GetLong(data.GetValue(FileSizeColumn), 0); lblSize.Text = DataHelper.GetSizeString(size); } string argument = RaiseOnGetArgumentSet(drv.Row); string selectAction = GetSelectScript(drv, argument); // Initialize EDIT button var btnEdit = e.Item.FindControl("btnEdit") as CMSAccessibleButton; if (btnEdit != null) { btnEdit.ToolTip = GetString("general.edit"); string path = data.GetValue("Path").ToString(); string editScript = GetEditScript(path, ext); if (!String.IsNullOrEmpty(editScript)) { btnEdit.OnClientClick = editScript; } else { btnEdit.Visible = false; } } // Initialize DELETE button var btnDelete = e.Item.FindControl("btnDelete") as CMSAccessibleButton; if (btnDelete != null) { btnDelete.ToolTip = GetString("general.delete"); btnDelete.OnClientClick = GetDeleteScript(argument); } // Image area Image fileImage = e.Item.FindControl("imgElem") as Image; if (fileImage != null) { string url; if (ImageHelper.IsImage(ext)) { url = URLHelper.UnMapPath(data.GetValue("Path").ToString()); // Generate new tooltip command if (!String.IsNullOrEmpty(url)) { url = String.Format("{0}?chset={1}", url, Guid.NewGuid()); UIHelper.EnsureTooltip(fileImage, ResolveUrl(url), 0, 0, null, null, ext, null, null, 300); } fileImage.ImageUrl = ResolveUrl(url); } else { fileImage.Visible = false; Literal literalImage = e.Item.FindControl("ltrImage") as Literal; if (literalImage != null) { literalImage.Text = UIHelper.GetFileIcon(Page, ext, FontIconSizeEnum.Dashboard); } } } // Selectable area Panel pnlItemInageContainer = e.Item.FindControl("pnlThumbnails") as Panel; if (pnlItemInageContainer != null) { pnlItemInageContainer.Attributes["onclick"] = selectAction; pnlItemInageContainer.Attributes["style"] = "cursor:pointer;"; } }
protected object ListViewControl_OnExternalDataBound(object sender, string sourceName, object parameter) { object result = null; string argument = ""; string url = ""; bool isContent = (SourceType == MediaSourceEnum.Content); bool notAttachment = false; bool isContentFile = false; bool isWebDAVEnabled = CMSContext.IsWebDAVEnabled(CMSContext.CurrentSiteName); bool isWindowsAuthentication = RequestHelper.IsWindowsAuthentication(); sourceName = sourceName.ToLowerCSafe(); // Prepare the data IDataContainer data = null; if (parameter is DataRowView) { data = new DataRowContainer((DataRowView)parameter); } else { // Get the data row view from parameter GridViewRow gvr = (parameter as GridViewRow); if (gvr != null) { DataRowView dr = (DataRowView)gvr.DataItem; if (dr != null) { data = new DataRowContainer(dr); } } } ImageButton btn = null; DirectFileUploader dfuElem = null; string ext = null; string fileName = null; bool libraryFolder = false; string className = ""; // Get site id int siteId = 0; if (data != null) { if (data.ContainsColumn("NodeSiteID")) { siteId = ValidationHelper.GetInteger(data.GetValue("NodeSiteID"), 0); } else if (data.ContainsColumn("AttachmentSiteID")) { siteId = ValidationHelper.GetInteger(data.GetValue("AttachmentSiteID"), 0); } else if (data.ContainsColumn("MetaFileSiteID")) { siteId = ValidationHelper.GetInteger(data.GetValue("MetaFileSiteID"), 0); } else { siteId = ValidationHelper.GetInteger(data.GetValue("FileSiteID"), 0); } } // Check if site is running bool siteIsRunning = true; SiteInfo siteInfo = CMSContext.CurrentSite; if (siteId > 0) { siteInfo = SiteInfoProvider.GetSiteInfo(siteId); if (siteInfo != null) { siteIsRunning = siteInfo.Status == SiteStatusEnum.Running; } } switch (sourceName) { #region "Select" case "select": if (sender is ImageButton) { btn = ((ImageButton)sender); // Is current item CMS.File or attachment ? isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); if (notAttachment) { className = DataClassInfoProvider.GetDataClass((int)data.GetValue("NodeClassID")).ClassDisplayName; } ext = HTMLHelper.HTMLEncode(notAttachment ? className : data.GetValue(FileExtensionColumn).ToString().TrimStart('.')); // Get file name fileName = GetFileName(data); libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); if ((SourceType == MediaSourceEnum.MediaLibraries) && ((RaiseOnFileIsNotInDatabase(fileName) == null) && (DisplayMode == ControlDisplayModeEnum.Simple))) { // If folders are displayed as well show SELECT button icon if (libraryFolder && !IsCopyMoveLinkDialog) { btn.ImageUrl = ResolveUrl(ImagesPath + "subdocument.png"); btn.ToolTip = GetString("dialogs.list.actions.showsubfolders"); btn.Attributes["onclick"] = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } else if (libraryFolder && IsCopyMoveLinkDialog) { btn.ImageUrl = ResolveUrl(ImagesPath + "next.png"); btn.ToolTip = GetString("general.select"); btn.Attributes["onclick"] = String.Format("SetAction('copymoveselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } else { // If media file not imported yet - display warning sign btn.ImageUrl = ResolveUrl(ImagesPath + "warning.png"); btn.ToolTip = GetString("media.file.import"); btn.Attributes["onclick"] = String.Format("SetAction('importfile', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(data.GetValue("FileName").ToString())); } } else { // Check if item is selectable, if not remove select action button bool isSelectable = CMSDialogHelper.IsItemSelectable(SelectableContent, ext, isContentFile); if (!isSelectable) { btn.ImageUrl = ResolveUrl(ImagesPath + "transparent.png"); btn.ToolTip = ""; btn.Attributes["style"] = "margin:0px 3px;cursor:default;"; btn.Enabled = false; } else { argument = RaiseOnGetArgumentSet(data); // Get item URL url = RaiseOnGetListItemUrl(data, false, notAttachment); // Initialize command btn.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(argument + "|URL|" + url)); result = btn; } } } break; #endregion #region "Select sub docs" case "selectsubdocs": if (sender is ImageButton) { btn = ((ImageButton)sender); int nodeId = ValidationHelper.GetInteger(data.GetValue("NodeID"), 0); if (IsFullListingMode) { // Check if item is selectable, if not remove select action button // Initialize command btn.Attributes["onclick"] = String.Format("SetParentAction('{0}'); return false;", nodeId); } else { btn.Visible = false; } } break; #endregion #region "Select sub folders" case "selectsubfolders": if (sender is ImageButton) { btn = ((ImageButton)sender); if (btn != null) { string folderName = ValidationHelper.GetString(data.GetValue("FileName"), ""); ext = ValidationHelper.GetString(data.GetValue(FileExtensionColumn), ""); if (IsCopyMoveLinkDialog || (IsFullListingMode && (DisplayMode == ControlDisplayModeEnum.Default) && (ext == "<dir>"))) { // Initialize command btn.Attributes["onclick"] = String.Format("SetLibParentAction({0}); return false;", ScriptHelper.GetString(folderName)); } else { btn.Visible = false; } } } break; #endregion #region "View" case "view": if (sender is ImageButton) { btn = ((ImageButton)sender); // Check if current item is library folder fileName = GetFileName(data); libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); // Is current item CMS.File or attachment ? isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); if (!notAttachment && !libraryFolder && siteIsRunning) { // Get item URL url = RaiseOnGetListItemUrl(data, false, false); if (String.IsNullOrEmpty(url)) { btn.ImageUrl = GetImageUrl("/Design/Controls/UniGrid/Actions/Viewdisabled.png"); btn.OnClientClick = "return false;"; btn.Attributes["style"] = "margin:0px 3px;cursor:default;"; btn.Enabled = false; } else { // Add latest version requirement for live site if (IsLiveSite) { // Check version history ID int versionHistoryId = VersionHistoryID; if (versionHistoryId > 0) { // Add requirement for latest version of files for current document string newparams = "latestforhistoryid=" + versionHistoryId; newparams += "&hash=" + ValidationHelper.GetHashString("h" + versionHistoryId); url = URLHelper.AppendQuery(url, newparams); } } string finalUrl = URLHelper.ResolveUrl(url); btn.OnClientClick = String.Format("javascript: window.open({0}); return false;", ScriptHelper.GetString(finalUrl)); } } else { btn.Visible = false; } } break; #endregion #region "Edit" case "edit": if (sender is ImageButton) { // Is current item CMS.File or attachment ? isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); // Get file extension ext = (notAttachment ? "" : data.GetValue(FileExtensionColumn).ToString().TrimStart('.')); Guid guid = Guid.Empty; ImageButton imgEdit = (ImageButton)sender; if ((SourceType == MediaSourceEnum.MediaLibraries) && siteIsRunning) { libraryFolder = (IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); if (!libraryFolder) { guid = ValidationHelper.GetGuid(data.GetValue("FileGUID"), Guid.Empty); imgEdit.AlternateText = String.Format("{0}|MediaFileGUID={1}&sitename={2}", ext, guid, GetSiteName(data, true)); imgEdit.PreRender += img_PreRender; imgEdit.ImageUrl = ResolveUrl(ImagesPath + "edit.png"); } else { imgEdit.Visible = false; } } else if (!notAttachment && siteIsRunning) { string nodeIdQuery = ""; if (SourceType == MediaSourceEnum.Content) { nodeIdQuery = "&nodeId=" + data.GetValue("NodeID"); } // Get the node workflow VersionHistoryID = ValidationHelper.GetInteger(data.GetValue("DocumentCheckedOutVersionHistoryID"), 0); guid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); imgEdit.AlternateText = String.Format("{0}|AttachmentGUID={1}&sitename={2}{3}&versionHistoryId={4}", ext, guid, GetSiteName(data, false), nodeIdQuery, VersionHistoryID); imgEdit.PreRender += img_PreRender; imgEdit.ImageUrl = ResolveUrl(ImagesPath + "edit.png"); } else { imgEdit.Visible = false; } } break; #endregion #region "WebDAV edit" case "webdavedit": { // Prepare the data DataRowView dr = parameter as DataRowView; if (dr != null) { data = new DataRowContainer(dr); } if ((SourceType == MediaSourceEnum.MediaLibraries) && siteIsRunning) { PlaceHolder plcUpd = new PlaceHolder(); plcUpd.ID = "plcUdateColumn"; Panel pnlBlock = new Panel(); pnlBlock.ID = "pnlBlock"; pnlBlock.CssClass = "TableCell"; plcUpd.Controls.Add(pnlBlock); string fileExtension = ValidationHelper.GetString(data.GetValue("FileExtension"), null); // If the WebDAV is enabled and windows authentication and extension is allowed if (isWebDAVEnabled && isWindowsAuthentication && WebDAVSettings.IsExtensionAllowedForEditMode(fileExtension, CMSContext.CurrentSiteName)) { // Dynamically load control WebDAVEditControl webDAVElem = Page.LoadUserControl("~/CMSModules/MediaLibrary/Controls/WebDAV/MediaFileWebDAVEditControl.ascx") as WebDAVEditControl; // Set editor's properties if (webDAVElem != null) { GetWebDAVEditControl(ref webDAVElem, data); // Add to panel pnlBlock.Controls.Add(webDAVElem); columnUpdateVisible = true; } } return plcUpd; } else if ((SourceType == MediaSourceEnum.Content) && (OutputFormat != OutputFormatEnum.Custom) && siteIsRunning) { PlaceHolder plcUpd = new PlaceHolder(); plcUpd.ID = "plcUdateColumn"; Panel pnlBlock = new Panel(); pnlBlock.ID = "pnlBlock"; pnlBlock.CssClass = "TableCell"; plcUpd.Controls.Add(pnlBlock); string fileExtension = ValidationHelper.GetString(data.GetValue("AttachmentExtension"), null); // If the WebDAV is enabled and windows authentication and extension is allowed if (isWebDAVEnabled && isWindowsAuthentication && WebDAVSettings.IsExtensionAllowedForEditMode(fileExtension, CMSContext.CurrentSiteName)) { // Dynamically load control WebDAVEditControl webDAVElem = Page.LoadUserControl("~/CMSModules/WebDAV/Controls/AttachmentWebDAVEditControl.ascx") as WebDAVEditControl; // Set editor's properties if (webDAVElem != null) { webDAVElem.Visible = false; GetWebDAVEditControl(ref webDAVElem, data); // Add to panel pnlBlock.Controls.Add(webDAVElem); columnUpdateVisible = true; } } return plcUpd; } } break; #endregion #region "Edit library ui" case "editlibraryui": if (sender is ImageButton) { ImageButton imgEdit = (ImageButton)sender; if (imgEdit != null) { // Get file name fileName = GetFileName(data); bool notInDatabase = ((RaiseOnFileIsNotInDatabase(fileName) == null) && (DisplayMode == ControlDisplayModeEnum.Simple)); // Check if current item is library folder libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && notInDatabase && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); ext = data.ContainsColumn("FileExtension") ? data.GetValue("FileExtension").ToString() : data.GetValue("Extension").ToString(); if (libraryFolder) { imgEdit.Visible = false; } else if (notInDatabase) { imgEdit.ImageUrl = ResolveUrl(ImagesPath + "editdisabled.png"); imgEdit.Attributes["style"] = "margin:0px 3px;cursor:default;"; imgEdit.Enabled = false; } else { imgEdit.OnClientClick = String.Format("$j('#hdnFileOrigName').attr('value', {0}); SetAction('editlibraryui', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(EnsureFileName(fileName)), ScriptHelper.GetString(fileName)); } } } break; #endregion #region "Delete" case "delete": if (sender is ImageButton) { // Get file name fileName = GetFileName(data); // Check if current item is library folder libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); ImageButton btnDelete = (ImageButton)sender; if (btnDelete != null) { //btnDelete.ImageUrl = ResolveUrl(ImagesPath + "Delete.png"); btnDelete.ToolTip = GetString("general.delete"); if (((RaiseOnFileIsNotInDatabase(fileName) == null) && (DisplayMode == ControlDisplayModeEnum.Simple))) { if (libraryFolder) { btnDelete.Visible = false; } else { btnDelete.Attributes["onclick"] = String.Format("if(DeleteMediaFileConfirmation() == false){{return false;}} SetAction('deletefile',{0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } } else { btnDelete.Attributes["onclick"] = String.Format("if(DeleteMediaFileConfirmation() == false){{return false;}} SetAction('deletefile',{0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } } } break; #endregion #region "Name" case "name": { // Is current item CMS.File or attachment ? isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); // Get name and extension string fileNameColumn = FileNameColumn; if (notAttachment) { fileNameColumn = "DocumentName"; } string name = HTMLHelper.HTMLEncode(data.GetValue(fileNameColumn).ToString()); ext = (notAttachment ? "" : data.GetValue(FileExtensionColumn).ToString().TrimStart('.')); if ((SourceType == MediaSourceEnum.DocumentAttachments) || (SourceType == MediaSourceEnum.MetaFile)) { name = Path.GetFileNameWithoutExtension(name); } // Width & height int width = (data.ContainsColumn(FileWidthColumn) ? ValidationHelper.GetInteger(data.GetValue(FileWidthColumn), 0) : 0); int height = (data.ContainsColumn(FileHeightColumn) ? ValidationHelper.GetInteger(data.GetValue(FileHeightColumn), 0) : 0); string cmpltExt = (notAttachment ? "" : "." + ext); fileName = (cmpltExt != "") ? name.Replace(cmpltExt, "") : name; if (isContent && !notAttachment) { string attachmentName = Path.GetFileNameWithoutExtension(data.GetValue("AttachmentName").ToString()); if (fileName.ToLowerCSafe() != attachmentName.ToLowerCSafe()) { fileName += String.Format(" ({0})", HTMLHelper.HTMLEncode(data.GetValue("AttachmentName").ToString())); } } className = isContent ? HTMLHelper.HTMLEncode(data.GetValue("ClassName").ToString().ToLowerCSafe()) : ""; isContentFile = (className == "cms.file"); // Check if item is selectable if (!CMSDialogHelper.IsItemSelectable(SelectableContent, ext, isContentFile)) { LiteralControl ltlName = new LiteralControl(fileName); // Get final panel result = GetListItem(ext, className, "", "", width, height, ltlName, false, false, GetTitle(data, isContentFile), GetDescription(data, isContentFile), name); } else { // Make a file name link LinkButton lnkBtn = new LinkButton() { ID = "n", Text = HTMLHelper.HTMLEncode(fileName) }; // Is current item CMS.File or attachment ? isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); fileName = GetFileName(data); // Try to get imported file row bool isImported = true; IDataContainer importedData = null; if (DisplayMode == ControlDisplayModeEnum.Simple) { importedData = RaiseOnFileIsNotInDatabase(fileName); isImported = (importedData != null); } else { importedData = data; } if (!isImported) { importedData = data; } else { // Update WIDTH if (importedData.ContainsColumn(FileWidthColumn)) { width = ValidationHelper.GetInteger(importedData[FileWidthColumn], 0); } // Update HEIGHT if (importedData.ContainsColumn(FileHeightColumn)) { height = ValidationHelper.GetInteger(importedData[FileHeightColumn], 0); } } argument = RaiseOnGetArgumentSet(data); url = RaiseOnGetListItemUrl(importedData, false, notAttachment); string previewUrl = RaiseOnGetListItemUrl(importedData, true, notAttachment); if (!String.IsNullOrEmpty(previewUrl)) { // Add chset string chset = Guid.NewGuid().ToString(); previewUrl = URLHelper.AddParameterToUrl(previewUrl, "chset", chset); } // Add latest version requirement for live site if (!String.IsNullOrEmpty(previewUrl) && IsLiveSite) { int versionHistoryId = VersionHistoryID; if (versionHistoryId > 0) { // Add requirement for latest version of files for current document string newparams = "latestforhistoryid=" + versionHistoryId; newparams += "&hash=" + ValidationHelper.GetHashString("h" + versionHistoryId); //url = URLHelper.AppendQuery(url, newparams); previewUrl = URLHelper.AppendQuery(previewUrl, newparams); } } // Check if current item is library folder libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); if ((SourceType == MediaSourceEnum.MediaLibraries) && (!isImported && (DisplayMode == ControlDisplayModeEnum.Simple))) { if (libraryFolder && !IsCopyMoveLinkDialog) { lnkBtn.Attributes["onclick"] = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } else if (libraryFolder && IsCopyMoveLinkDialog) { lnkBtn.Attributes["onclick"] = String.Format("SetAction('copymoveselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } else { lnkBtn.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetAction('importfile', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(fileName)); } } else { // Initialize command lnkBtn.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(String.Format("{0}|URL|{1}", argument, url))); } // Get final panel result = GetListItem(ext, className, url, previewUrl, width, height, lnkBtn, true, isImported && siteIsRunning, GetTitle(data, isContentFile), GetDescription(data, isContentFile), name); } } break; #endregion #region "Type" case "type": { if (isContent) { // Is current item CMS.File or attachment ? isContentFile = (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file"); notAttachment = !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); if (notAttachment || (OutputFormat == OutputFormatEnum.HTMLLink) || (OutputFormat == OutputFormatEnum.BBLink)) { return HTMLHelper.HTMLEncode(ResHelper.LocalizeString(data.GetValue("ClassDisplayName").ToString())); } } result = NormalizeExtenison(data.GetValue(FileExtensionColumn).ToString()); } break; #endregion #region "Size" case "size": { // Is current item CMS.File or attachment ? isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); if (!notAttachment) { long size = 0; if (data.GetValue(FileExtensionColumn).ToString() != "<dir>") { if (data.ContainsColumn(FileSizeColumn)) { size = ValidationHelper.GetLong(data.GetValue(FileSizeColumn), 0); } else if (data.ContainsColumn("Size")) { IDataContainer importedData = RaiseOnFileIsNotInDatabase(GetFileName(data)); size = ValidationHelper.GetLong((importedData != null) ? importedData["FileSize"] : data.GetValue("Size"), 0); } } else { return ""; } result = DataHelper.GetSizeString(size); } } break; #endregion #region "Attachment modified" case "attachmentmodified": case "attachmentmodifiedtooltip": { // If attachment is related to the workflow 'AttachmentLastModified' information isn't present if (!data.ContainsColumn("AttachmentLastModified")) { int attachmentDocumentId = ValidationHelper.GetInteger(data.GetValue("AttachmentDocumentID"), 0); result = GetLastModified(attachmentDocumentId); } else { result = data.GetValue("AttachmentLastModified").ToString(); } bool displayGMT = (sourceName == "attachmentmodifiedtooltip"); result = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(result, DataHelper.DATETIME_NOT_SELECTED), displayGMT, CMSContext.CurrentUser, siteInfo); } break; #endregion #region "Attachment update" case "attachmentupdate": { // Dynamically load uploader control dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; Panel updatePanel = new Panel() { ID = "updatePanel", Width = ((isWebDAVEnabled && isWindowsAuthentication) ? 32 : 16) }; updatePanel.Style.Add("margin", "0 auto"); // Initialize update control GetAttachmentUpdateControl(ref dfuElem, data); dfuElem.DisplayInline = true; updatePanel.Controls.Add(dfuElem); // Add Attachment WebDAV edit control string attachmentExtension = ValidationHelper.GetString(data.GetValue(FileExtensionColumn), null); Guid formGUID = ValidationHelper.GetGuid(data.GetValue("AttachmentFormGUID"), Guid.Empty); // If the WebDAV is enabled and windows authentication and extension is allowed and form GUID is empty if (isWebDAVEnabled && isWindowsAuthentication && (formGUID == Guid.Empty) && WebDAVSettings.IsExtensionAllowedForEditMode(attachmentExtension, CMSContext.CurrentSiteName)) { // Dynamically load control WebDAVEditControl webDAVElem = Page.LoadUserControl("~/CMSModules/WebDAV/Controls/AttachmentWebDAVEditControl.ascx") as WebDAVEditControl; GetWebDAVEditControl(ref webDAVElem, data); updatePanel.Controls.Add(webDAVElem); } result = updatePanel; } break; #endregion #region "Library update" case "libraryupdate": { Panel updatePanel = new Panel(); updatePanel.Style.Add("margin", "0 auto"); updatePanel.Width = ((isWebDAVEnabled && isWindowsAuthentication) ? 32 : 16); libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); // Get info on imported file fileName = GetFileName(data); IDataContainer existingData = RaiseOnFileIsNotInDatabase(fileName); bool hasModifyPermission = RaiseOnGetModifyPermission(data); ImageButton imgBtn = new ImageButton() { Enabled = false, ImageUrl = ResolveUrl(GetImageUrl("Design/Controls/DirectUploader/uploaddisabled.png")) }; imgBtn.Attributes["style"] = "cursor: default;"; updatePanel.Controls.Add(imgBtn); if (hasModifyPermission && (existingData != null)) { // Dynamically load uploader control dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; if (dfuElem != null) { // Initialize update control GetLibraryUpdateControl(ref dfuElem, existingData); updatePanel.Controls.Add(dfuElem); } imgBtn.Style.Add("display", "none"); } else { updatePanel.Visible = !libraryFolder || !hasModifyPermission; } // Add WebDAV icon if (existingData != null) { string siteName = GetSiteName(existingData, true); string extension = ValidationHelper.GetString(existingData["FileExtension"], null); // If the WebDAV is enabled and windows authentication and extension is allowed if (isWebDAVEnabled && isWindowsAuthentication && WebDAVSettings.IsExtensionAllowedForEditMode(extension, siteName)) { // Dynamically load control WebDAVEditControl webdavElem = Page.LoadUserControl("~/CMSModules/MediaLibrary/Controls/WebDAV/MediaFileWebDAVEditControl.ascx") as WebDAVEditControl; // Set editor's properties if (webdavElem != null) { // Initialize update control GetWebDAVEditControl(ref webdavElem, existingData); updatePanel.Controls.Add(webdavElem); } } } result = updatePanel; } break; #endregion #region "Attachment/MetaFile delete" case "metafiledelete": case "attachmentdelete": if (sender is ImageButton) { // Initialize DELETE button btn = ((ImageButton)sender); btn.OnClientClick = String.Format("if(DeleteConfirmation() == false){{return false;}} SetAction('{1}', '{0}'); RaiseHiddenPostBack(); return false;", data.GetValue(FileIdColumn), sourceName.ToLowerCSafe()); } break; #endregion #region "Attachment moveup" case "attachmentmoveup": if (sender is ImageButton) { // Initialize MOVE UP button btn = ((ImageButton)sender); // Get attachment ID Guid attachmentGuid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); btn.OnClientClick = String.Format("SetAction('attachmentmoveup', '{0}'); RaiseHiddenPostBack(); return false;", attachmentGuid); } break; #endregion #region "Attachment movedown" case "attachmentmovedown": if (sender is ImageButton) { // Initialize MOVE DOWN button btn = ((ImageButton)sender); // Get attachment ID Guid attachmentGuid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); btn.OnClientClick = String.Format("SetAction('attachmentmovedown', '{0}'); RaiseHiddenPostBack(); return false;", attachmentGuid); } break; #endregion #region "Attachment edit" case "attachmentedit": if (sender is ImageButton) { // Get file extension string attExtension = ValidationHelper.GetString(data.GetValue("AttachmentExtension"), "").ToLowerCSafe(); Guid attGuid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); ImageButton attImg = (ImageButton)sender; attImg.AlternateText = String.Format("{0}|AttachmentGUID={1}&sitename={2}&versionHistoryId={3}", attExtension, attGuid, GetSiteName(data, false), VersionHistoryID); attImg.PreRender += img_PreRender; } break; #endregion #region "Library extension" case "extension": { result = data.ContainsColumn("FileExtension") ? data.GetValue("FileExtension").ToString() : data.GetValue("Extension").ToString(); result = NormalizeExtenison(result.ToString()); } break; #endregion #region "Modified" case "modified": case "modifiedtooltip": { bool displayGMT = (sourceName == "attachmentmodifiedtooltip"); result = data.ContainsColumn("FileModifiedWhen") ? data.GetValue("FileModifiedWhen").ToString() : data.GetValue("Modified").ToString(); result = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(result, DataHelper.DATETIME_NOT_SELECTED), displayGMT, CMSContext.CurrentUser, siteInfo); } break; #endregion #region "Document modified when" case "documentmodifiedwhen": case "filemodifiedwhen": case "documentmodifiedwhentooltip": case "filemodifiedwhentooltip": { bool displayGMT = ((sourceName == "documentmodifiedwhentooltip") || (sourceName == "filemodifiedwhentooltip")); result = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(parameter, DataHelper.DATETIME_NOT_SELECTED), displayGMT, CMSContext.CurrentUser, siteInfo); } break; #endregion #region "MetaFile edit" case "metafileedit": if (sender is ImageButton) { // Get file extension string metaExtension = ValidationHelper.GetString(data.GetValue("MetaFileExtension"), string.Empty).ToLowerCSafe(); Guid metaGuid = ValidationHelper.GetGuid(data.GetValue("MetaFileGUID"), Guid.Empty); ImageButton attImg = (ImageButton)sender; attImg.AlternateText = String.Format("{0}|metafileguid={1}", metaExtension, metaGuid); attImg.PreRender += img_PreRender; } break; #endregion #region "MetaFile update" case "metafileupdate": { // Dynamically load uploader control dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; Panel updatePanel = new Panel() { ID = "updatePanel", Width = 16 }; updatePanel.Style.Add("margin", "0 auto"); // Initialize update control GetAttachmentUpdateControl(ref dfuElem, data); dfuElem.DisplayInline = true; updatePanel.Controls.Add(dfuElem); result = updatePanel; } break; #endregion #region "MetaFile modified" case "metafilemodified": case "metafilemodifiedtooltip": { result = data.GetValue("MetaFileLastModified").ToString(); bool displayGMT = (sourceName == "metafilemodifiedtooltip"); result = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(result, DataHelper.DATETIME_NOT_SELECTED), displayGMT, CMSContext.CurrentUser, siteInfo); } break; #endregion } return result; }
/// <summary> /// Loads DataRow for BasicForm with data from FormFieldInfo settings. /// </summary> private DataRowContainer GetData() { DataRowContainer result = new DataRowContainer(fi.GetDataRow()); if (this.Settings != null) { foreach (string columnName in result.ColumnNames) { if (Settings.ContainsKey(columnName) && !String.IsNullOrEmpty(Convert.ToString(Settings[columnName]))) { result[columnName] = Settings[columnName]; } } } return result; }
/// <summary> /// Gets the macros from the system /// </summary> /// <param name="startIndex">Start index</param> /// <param name="endIndex">End index</param> /// <param name="maxTotalRecords">Maximum number of total records to process</param> /// <param name="totalRecords">Returns the total number of records found</param> private IEnumerable <MacroExpr> GetMacros(int startIndex, int endIndex, int maxTotalRecords, ref int totalRecords) { var index = 0; IEnumerable <string> objectTypes = null; // Get object types to search var selectedType = ValidationHelper.GetString(selObjectType.Value, ""); if (!String.IsNullOrEmpty(selectedType)) { if (ObjectTypeManager.GetRegisteredTypeInfo(selectedType) != null) { objectTypes = new List <string> { selectedType }; } } if (objectTypes == null) { objectTypes = ObjectTypeManager.ObjectTypesWithMacros; } var result = new List <MacroExpr>(); var search = txtFilter.Text; var invalid = chkInvalid.Checked; var skipTesting = SystemContext.DevelopmentMode && chkSkipTesting.Checked; var type = drpType.Text; foreach (var objectType in objectTypes) { // Skip certain object types switch (objectType) { case ObjectVersionHistoryInfo.OBJECT_TYPE: case VersionHistoryInfo.OBJECT_TYPE: case StagingTaskInfo.OBJECT_TYPE: case IntegrationTaskInfo.OBJECT_TYPE: continue; } // Process all objects of the given type var infos = new ObjectQuery(objectType) .TopN(maxTotalRecords) .BinaryData(false); var typeInfo = infos.TypeInfo; if (skipTesting) { ExcludeTestingObjects(infos); } if (!String.IsNullOrEmpty(search)) { // Search particular expression infos.WhereAnyColumnContains(search); } else { // Search just type infos.WhereAnyColumnContains("{" + type); } Action <DataRow> collectMacros = dr => { var drc = new DataRowContainer(dr); // Process all expressions MacroProcessor.ProcessMacros(drc, (expression, colName) => { var originalExpression = expression; // Decode macro from XML if (MacroProcessor.IsXMLColumn(colName)) { expression = HTMLHelper.HTMLDecode(expression); } MacroExpr e = null; bool add = false; if (String.IsNullOrEmpty(search) || (expression.IndexOfCSafe(search, true) >= 0)) { // If not tracking errors, count immediately if (!invalid) { // Apply paging. Endindex is -1 when paging is off if ((endIndex < 0) || ((index >= startIndex) && (index <= endIndex))) { e = GetMacroExpr(expression); add = true; } index++; } else { e = GetMacroExpr(expression); // Filter invalid signature / syntax var pass = !e.SignatureValid || e.Error; if (pass) { // Apply paging. Endindex is -1 when paging is off if ((endIndex < 0) || ((index >= startIndex) && (index <= endIndex))) { add = true; } index++; } } } if (add) { // Fill in the object information e.ObjectType = objectType; e.ObjectID = (typeInfo.IDColumn == ObjectTypeInfo.COLUMN_NAME_UNKNOWN) ? 0 : ValidationHelper.GetInteger(dr[typeInfo.IDColumn], 0); e.Field = colName; result.Add(e); } return(originalExpression); }, new List <string> { type } ); if ((maxTotalRecords != -1) && (index >= maxTotalRecords)) { // Enough data - cancel enumeration throw new ActionCancelledException(); } }; using (var scope = new CMSConnectionScope()) { scope.Connection.CommandTimeout = ConnectionHelper.LongRunningCommandTimeout; infos.ForEachRow(collectMacros); } if (((maxTotalRecords != -1) && (index >= maxTotalRecords)) || !CMSHttpContext.Current.Response.IsClientConnected) { break; } } totalRecords = index; return(result); }
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView dr = (e.Row.DataItem as DataRowView); if (dr != null) { IDataContainer data = new DataRowContainer(dr); e.Row.Attributes["id"] = GetColorizeID(data); } } }
/// <summary> /// Handles actions occuring when some item in copy/move/link/select path dialog is selected. /// </summary> private void HandleDialogSelect() { if (TreeNodeObj != null) { string columns = SqlHelperClass.MergeColumns((IsLiveSite ? TreeProvider.SELECTNODES_REQUIRED_COLUMNS : DocumentHelper.GETDOCUMENTS_REQUIRED_COLUMNS), NODE_COLUMNS); // Get files TreeNodeObj.TreeProvider.SelectQueryName = "selectattachments"; DataSet nodeDetails = null; if (IsLiveSite) { // Get published files nodeDetails = TreeNodeObj.TreeProvider.SelectNodes(SiteName, TreeNodeObj.NodeAliasPath, CMSContext.CurrentUser.PreferredCultureCode, true, null, null, "DocumentName", 1, true, 1, columns); } else { // Get latest files nodeDetails = DocumentHelper.GetDocuments(SiteName, TreeNodeObj.NodeAliasPath, CMSContext.CurrentUser.PreferredCultureCode, true, null, null, "DocumentName", 1, false, 1, columns, TreeNodeObj.TreeProvider); } // If node details exists if (!DataHelper.IsEmpty(nodeDetails)) { IDataContainer data = new DataRowContainer(nodeDetails.Tables[0].Rows[0]); string argument = mediaView.GetArgumentSet(data); bool notAttachment = (SourceType == MediaSourceEnum.Content) && !((data.GetValue("ClassName").ToString().ToLower() == "cms.file") && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); string url = mediaView.GetItemUrl(argument, 0, 0, 0, notAttachment); SelectMediaItem(String.Format("{0}|URL|{1}", argument, url)); } ItemToColorize = TreeNodeObj.NodeGUID; } else { // Remove selected item ItemToColorize = Guid.Empty; } ClearColorizedRow(); // Forget recent action ClearActionElems(); }
protected object ListViewControl_OnExternalDataBound(object sender, string sourceName, object parameter) { object result = null; string argument = ""; string url = ""; bool isContent = (SourceType == MediaSourceEnum.Content); bool notAttachment; bool isContentFile; sourceName = sourceName.ToLowerCSafe(); // Prepare the data IDataContainer data = null; if (parameter is DataRowView) { data = new DataRowContainer((DataRowView)parameter); } else { // Get the data row view from parameter GridViewRow gvr = (parameter as GridViewRow); if (gvr != null) { DataRowView dr = (DataRowView)gvr.DataItem; if (dr != null) { data = new DataRowContainer(dr); } } } CMSGridActionButton btnAction; DirectFileUploader dfuElem; string ext = null; string fileName = null; bool libraryFolder = false; string className = ""; // Get site id int siteId = 0; if (data != null) { if (data.ContainsColumn("NodeSiteID")) { siteId = ValidationHelper.GetInteger(data.GetValue("NodeSiteID"), 0); } else if (data.ContainsColumn("AttachmentSiteID")) { siteId = ValidationHelper.GetInteger(data.GetValue("AttachmentSiteID"), 0); } else if (data.ContainsColumn("MetaFileSiteID")) { siteId = ValidationHelper.GetInteger(data.GetValue("MetaFileSiteID"), 0); } else { siteId = ValidationHelper.GetInteger(data.GetValue("FileSiteID"), 0); } } // Check if site is running bool siteIsRunning = true; SiteInfo siteInfo = SiteContext.CurrentSite; if (siteId > 0) { siteInfo = SiteInfoProvider.GetSiteInfo(siteId); if (siteInfo != null) { siteIsRunning = siteInfo.Status == SiteStatusEnum.Running; } } UserInfo userInfo = MembershipContext.AuthenticatedUser; switch (sourceName) { #region "Select" case "select": btnAction = sender as CMSGridActionButton; if (btnAction != null) { // Is current item CMS.File or attachment ? isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); if (notAttachment) { className = DataClassInfoProvider.GetClassName((int)data.GetValue("NodeClassID")); } ext = HTMLHelper.HTMLEncode(notAttachment ? className : data.GetValue(FileExtensionColumn).ToString().TrimStart('.')); // Get file name fileName = GetFileName(data); libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); if ((SourceType == MediaSourceEnum.MediaLibraries) && ((RaiseOnFileIsNotInDatabase(fileName) == null) && (DisplayMode == ControlDisplayModeEnum.Simple))) { // If folders are displayed as well show SELECT button icon if (libraryFolder && !IsCopyMoveLinkDialog) { btnAction.IconCssClass = "icon-arrow-crooked-right"; btnAction.ToolTip = GetString("dialogs.list.actions.showsubfolders"); btnAction.OnClientClick = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } else if (libraryFolder && IsCopyMoveLinkDialog) { btnAction.IconCssClass = "icon-chevron-right"; btnAction.ToolTip = GetString("general.select"); btnAction.OnClientClick = String.Format("SetAction('copymoveselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } else { // If media file not imported yet - display warning sign btnAction.IconCssClass = "icon-exclamation-triangle"; btnAction.IconStyle = GridIconStyle.Warning; btnAction.ToolTip = GetString("media.file.import"); btnAction.OnClientClick = String.Format("SetAction('importfile', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(data.GetValue("FileName").ToString())); } } else { // Check if item is selectable, if not remove select action button bool isSelectable = CMSDialogHelper.IsItemSelectable(SelectableContent, ext, isContentFile); if (!isSelectable) { btnAction.Enabled = false; } else { argument = RaiseOnGetArgumentSet(data); // Get item URL url = RaiseOnGetListItemUrl(data, false, notAttachment); // Initialize command btnAction.OnClientClick = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(argument + "|URL|" + url)); result = btnAction; } } } break; #endregion #region "Select sub docs" case "selectsubdocs": btnAction = sender as CMSGridActionButton; if (btnAction != null) { int nodeId = ValidationHelper.GetInteger(data.GetValue("NodeID"), 0); if (IsFullListingMode) { // Check if item is selectable, if not remove select action button // Initialize command btnAction.OnClientClick = String.Format("SetParentAction('{0}'); return false;", nodeId); } else { btnAction.Visible = false; } } break; #endregion #region "Select sub folders" case "selectsubfolders": btnAction = sender as CMSGridActionButton; if (btnAction != null) { string folderName = ValidationHelper.GetString(data.GetValue("FileName"), ""); ext = ValidationHelper.GetString(data.GetValue(FileExtensionColumn), ""); if (IsCopyMoveLinkDialog || (IsFullListingMode && (DisplayMode == ControlDisplayModeEnum.Default) && (ext == "<dir>"))) { // Initialize command btnAction.OnClientClick = String.Format("SetLibParentAction({0}); return false;", ScriptHelper.GetString(folderName)); } else { btnAction.Visible = false; } } break; #endregion #region "View" case "view": btnAction = sender as CMSGridActionButton; if (btnAction != null) { // Check if current item is library folder fileName = GetFileName(data); libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); // Is current item CMS.File or attachment ? isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); if (!notAttachment && !libraryFolder && siteIsRunning) { // Get item URL url = RaiseOnGetListItemUrl(data, false, false); if (String.IsNullOrEmpty(url)) { btnAction.Enabled = false; } else { // Add latest version requirement for live site if (IsLiveSite) { // Check version history ID int versionHistoryId = VersionHistoryID; if (versionHistoryId > 0) { // Add requirement for latest version of files for current document string newparams = "latestforhistoryid=" + versionHistoryId; newparams += "&hash=" + ValidationHelper.GetHashString("h" + versionHistoryId); url = URLHelper.AppendQuery(url, newparams); } } string finalUrl = URLHelper.ResolveUrl(url); btnAction.OnClientClick = String.Format("window.open({0}); return false;", ScriptHelper.GetString(finalUrl)); } } else { btnAction.Visible = false; } } break; #endregion #region "Edit" case "edit": btnAction = sender as CMSGridActionButton; if (btnAction != null) { // Is current item CMS.File or attachment ? isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); // Get file extension ext = (notAttachment ? "" : data.GetValue(FileExtensionColumn).ToString().TrimStart('.')); Guid guid = Guid.Empty; if ((SourceType == MediaSourceEnum.MediaLibraries) && siteIsRunning) { libraryFolder = (IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); if (!libraryFolder) { guid = ValidationHelper.GetGuid(data.GetValue("FileGUID"), Guid.Empty); btnAction.ScreenReaderDescription = String.Format("{0}|MediaFileGUID={1}&sitename={2}", ext, guid, GetSiteName(data, true)); btnAction.PreRender += img_PreRender; btnAction.IconCssClass = "icon-edit"; btnAction.IconStyle = GridIconStyle.Allow; } else { btnAction.Visible = false; } } else if (!notAttachment && siteIsRunning) { string nodeIdQuery = ""; if (SourceType == MediaSourceEnum.Content) { nodeIdQuery = "&nodeId=" + data.GetValue("NodeID"); } // Get the node workflow VersionHistoryID = ValidationHelper.GetInteger(data.GetValue("DocumentCheckedOutVersionHistoryID"), 0); guid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); btnAction.ScreenReaderDescription = String.Format("{0}|AttachmentGUID={1}&sitename={2}{3}&versionHistoryId={4}", ext, guid, GetSiteName(data, false), nodeIdQuery, VersionHistoryID); btnAction.PreRender += img_PreRender; btnAction.IconCssClass = "icon-edit"; btnAction.IconStyle = GridIconStyle.Allow; } else { btnAction.Visible = false; } } break; #endregion #region "External edit" case "extedit": { // Prepare the data DataRowView dr = parameter as DataRowView; if (dr != null) { data = new DataRowContainer(dr); } // Create placeholder PlaceHolder plcUpd = new PlaceHolder(); plcUpd.ID = "plcUdateColumn"; Panel pnlBlock = new Panel(); pnlBlock.ID = "pnlBlock"; pnlBlock.CssClass = "TableCell"; plcUpd.Controls.Add(pnlBlock); if (siteIsRunning) { if (ExternalEditHelper.LoadExternalEditControl(pnlBlock, GetFileType(SourceType), siteInfo != null ? siteInfo.SiteName : null, data, IsLiveSite, TreeNodeObj) != null) { columnUpdateVisible = true; } return plcUpd; } } break; #endregion #region "Edit library ui" case "editlibraryui": btnAction = sender as CMSGridActionButton; if (btnAction != null) { // Get file name fileName = GetFileName(data); bool notInDatabase = ((RaiseOnFileIsNotInDatabase(fileName) == null) && (DisplayMode == ControlDisplayModeEnum.Simple)); // Check if current item is library folder libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && notInDatabase && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); ext = data.ContainsColumn("FileExtension") ? data.GetValue("FileExtension").ToString() : data.GetValue("Extension").ToString(); if (libraryFolder) { btnAction.Visible = false; } else if (notInDatabase) { btnAction.Enabled = false; } else { btnAction.OnClientClick = String.Format("$cmsj('#hdnFileOrigName').attr('value', {0}); SetAction('editlibraryui', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(EnsureFileName(fileName)), ScriptHelper.GetString(fileName)); } } break; #endregion #region "Delete" case "delete": btnAction = sender as CMSGridActionButton; if (btnAction != null) { // Get file name fileName = GetFileName(data); // Check if current item is library folder libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); btnAction.ToolTip = GetString("general.delete"); if (((RaiseOnFileIsNotInDatabase(fileName) == null) && (DisplayMode == ControlDisplayModeEnum.Simple))) { if (libraryFolder) { btnAction.Visible = false; } else { btnAction.OnClientClick = String.Format("if(DeleteMediaFileConfirmation() == false){{return false;}} SetAction('deletefile',{0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } } else { btnAction.OnClientClick = String.Format("if(DeleteMediaFileConfirmation() == false){{return false;}} SetAction('deletefile',{0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } } break; #endregion #region "Name" case "name": { // Is current item CMS.File or attachment ? isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); // Get name and extension string fileNameColumn = FileNameColumn; if (notAttachment) { fileNameColumn = "DocumentName"; } string name = HTMLHelper.HTMLEncode(data.GetValue(fileNameColumn).ToString()); ext = (notAttachment ? "" : data.GetValue(FileExtensionColumn).ToString().TrimStart('.')); if ((SourceType == MediaSourceEnum.DocumentAttachments) || (SourceType == MediaSourceEnum.MetaFile)) { name = Path.GetFileNameWithoutExtension(name); } // Width & height int width = (data.ContainsColumn(FileWidthColumn) ? ValidationHelper.GetInteger(data.GetValue(FileWidthColumn), 0) : 0); int height = (data.ContainsColumn(FileHeightColumn) ? ValidationHelper.GetInteger(data.GetValue(FileHeightColumn), 0) : 0); string cmpltExt = (notAttachment ? "" : "." + ext); fileName = (cmpltExt != "") ? name.Replace(cmpltExt, "") : name; if (isContent && !notAttachment) { string attachmentName = Path.GetFileNameWithoutExtension(data.GetValue("AttachmentName").ToString()); if (fileName.ToLowerCSafe() != attachmentName.ToLowerCSafe()) { fileName += String.Format(" ({0})", HTMLHelper.HTMLEncode(data.GetValue("AttachmentName").ToString())); } } className = isContent ? HTMLHelper.HTMLEncode(data.GetValue("ClassName").ToString().ToLowerCSafe()) : ""; isContentFile = (className == "cms.file"); // Check if item is selectable if (!CMSDialogHelper.IsItemSelectable(SelectableContent, ext, isContentFile)) { LiteralControl ltlName = new LiteralControl(fileName); // Get final panel result = GetListItem(ext, className, "", "", width, height, ltlName, false, false, GetTitle(data, isContentFile), GetDescription(data, isContentFile), name); } else { // Make a file name link LinkButton lnkBtn = new LinkButton() { ID = "n", Text = HTMLHelper.HTMLEncode(fileName) }; // Is current item CMS.File or attachment ? isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); fileName = GetFileName(data); // Try to get imported file row bool isImported = true; IDataContainer importedData = null; if (DisplayMode == ControlDisplayModeEnum.Simple) { importedData = RaiseOnFileIsNotInDatabase(fileName); isImported = (importedData != null); } else { importedData = data; } if (!isImported) { importedData = data; } else { // Update WIDTH if (importedData.ContainsColumn(FileWidthColumn)) { width = ValidationHelper.GetInteger(importedData[FileWidthColumn], 0); } // Update HEIGHT if (importedData.ContainsColumn(FileHeightColumn)) { height = ValidationHelper.GetInteger(importedData[FileHeightColumn], 0); } } argument = RaiseOnGetArgumentSet(data); url = RaiseOnGetListItemUrl(importedData, false, notAttachment); string previewUrl = RaiseOnGetListItemUrl(importedData, true, notAttachment); if (!String.IsNullOrEmpty(previewUrl)) { // Add chset string chset = Guid.NewGuid().ToString(); previewUrl = URLHelper.AddParameterToUrl(previewUrl, "chset", chset); } // Add latest version requirement for live site if (!String.IsNullOrEmpty(previewUrl) && IsLiveSite) { int versionHistoryId = VersionHistoryID; if (versionHistoryId > 0) { // Add requirement for latest version of files for current document string newparams = "latestforhistoryid=" + versionHistoryId; newparams += "&hash=" + ValidationHelper.GetHashString("h" + versionHistoryId); //url = URLHelper.AppendQuery(url, newparams); previewUrl = URLHelper.AppendQuery(previewUrl, newparams); } } // Check if current item is library folder libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); if ((SourceType == MediaSourceEnum.MediaLibraries) && (!isImported && (DisplayMode == ControlDisplayModeEnum.Simple))) { if (libraryFolder && !IsCopyMoveLinkDialog) { lnkBtn.Attributes["onclick"] = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } else if (libraryFolder && IsCopyMoveLinkDialog) { lnkBtn.Attributes["onclick"] = String.Format("SetAction('copymoveselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName)); } else { lnkBtn.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetAction('importfile', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(fileName)); } } else { // Initialize command lnkBtn.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(String.Format("{0}|URL|{1}", argument, url))); } // Get final panel result = GetListItem(ext, className, url, previewUrl, width, height, lnkBtn, true, isImported && siteIsRunning, GetTitle(data, isContentFile), GetDescription(data, isContentFile), name); } } break; #endregion #region "Type" case "type": { if (isContent) { // Is current item CMS.File or attachment ? isContentFile = (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file"); notAttachment = !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); if (notAttachment || (OutputFormat == OutputFormatEnum.HTMLLink) || (OutputFormat == OutputFormatEnum.BBLink)) { return HTMLHelper.HTMLEncode(ResHelper.LocalizeString(data.GetValue("ClassDisplayName").ToString())); } } result = NormalizeExtenison(data.GetValue(FileExtensionColumn).ToString()); } break; #endregion #region "Size" case "size": { // Is current item CMS.File or attachment ? isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false; notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); if (!notAttachment) { long size = 0; if (data.GetValue(FileExtensionColumn).ToString() != "<dir>") { if (data.ContainsColumn(FileSizeColumn)) { size = ValidationHelper.GetLong(data.GetValue(FileSizeColumn), 0); } else if (data.ContainsColumn("Size")) { IDataContainer importedData = RaiseOnFileIsNotInDatabase(GetFileName(data)); size = ValidationHelper.GetLong((importedData != null) ? importedData["FileSize"] : data.GetValue("Size"), 0); } } else { return ""; } result = DataHelper.GetSizeString(size); } } break; #endregion #region "Attachment modified" case "attachmentmodified": case "attachmentmodifiedtooltip": { result = data.GetValue("AttachmentLastModified").ToString(); if (sourceName.EqualsCSafe("attachmentmodified", StringComparison.InvariantCultureIgnoreCase)) { result = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(result, DateTimeHelper.ZERO_TIME), true, userInfo, siteInfo); } else { result = GetGMTTooltipString(userInfo, siteInfo); } } break; #endregion #region "Attachment update" case "attachmentupdate": { // Dynamically load uploader control dfuElem = LoadDirectFileUploader(); var updatePanel = new Panel(); updatePanel.ID = "updatePanel"; updatePanel.PreRender += (senderObject, args) => updatePanel.Width = mUpdateIconPanelWidth; updatePanel.Style.Add("margin", "0 auto"); // Initialize update control GetAttachmentUpdateControl(ref dfuElem, data); dfuElem.DisplayInline = true; updatePanel.Controls.Add(dfuElem); Guid formGUID = ValidationHelper.GetGuid(data.GetValue("AttachmentFormGUID"), Guid.Empty); // Setup external edit if form GUID is empty if (formGUID == Guid.Empty) { ExternalEditHelper.LoadExternalEditControl(updatePanel, FileTypeEnum.Attachment, null, data, IsLiveSite, TreeNodeObj); mUpdateIconPanelWidth = 32; } result = updatePanel; } break; #endregion #region "Library update" case "libraryupdate": { Panel updatePanel = new Panel(); updatePanel.Style.Add("margin", "0 auto"); updatePanel.PreRender += (senderObject, args) => updatePanel.Width = mUpdateIconPanelWidth; libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == "<dir>")); // Get info on imported file fileName = GetFileName(data); IDataContainer existingData = RaiseOnFileIsNotInDatabase(fileName); bool hasModifyPermission = RaiseOnGetModifyPermission(data); // Dynamically load uploader control dfuElem = LoadDirectFileUploader(); if (dfuElem != null) { // Initialize update control GetLibraryUpdateControl(ref dfuElem, existingData); updatePanel.Controls.Add(dfuElem); } if (hasModifyPermission && (existingData != null)) { dfuElem.Enabled = true; } else { updatePanel.Visible = !libraryFolder || !hasModifyPermission; dfuElem.Enabled = false; } if (existingData != null) { string siteName = GetSiteName(existingData, true); // Setup external edit var ctrl = ExternalEditHelper.LoadExternalEditControl(updatePanel, FileTypeEnum.MediaFile, siteName, existingData, IsLiveSite); if (ctrl != null) { mUpdateIconPanelWidth = 32; } } result = updatePanel; } break; #endregion #region "Attachment/MetaFile delete" case "metafiledelete": case "attachmentdelete": btnAction = sender as CMSGridActionButton; if (btnAction != null) { // Initialize DELETE button btnAction.OnClientClick = String.Format("if(DeleteConfirmation() == false){{return false;}} SetAction('{1}', '{0}'); RaiseHiddenPostBack(); return false;", data.GetValue(FileIdColumn), sourceName.ToLowerCSafe()); } break; #endregion #region "Attachment moveup" case "attachmentmoveup": btnAction = sender as CMSGridActionButton; if (btnAction != null) { // Get attachment ID Guid attachmentGuid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); btnAction.OnClientClick = String.Format("SetAction('attachmentmoveup', '{0}'); RaiseHiddenPostBack(); return false;", attachmentGuid); } break; #endregion #region "Attachment movedown" case "attachmentmovedown": btnAction = sender as CMSGridActionButton; if (btnAction != null) { // Get attachment ID Guid attachmentGuid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); btnAction.OnClientClick = String.Format("SetAction('attachmentmovedown', '{0}'); RaiseHiddenPostBack(); return false;", attachmentGuid); } break; #endregion #region "Attachment edit" case "attachmentedit": btnAction = sender as CMSGridActionButton; if (btnAction != null) { // Get file extension string attExtension = ValidationHelper.GetString(data.GetValue("AttachmentExtension"), "").ToLowerCSafe(); Guid attGuid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); btnAction.ScreenReaderDescription = String.Format("{0}|AttachmentGUID={1}&sitename={2}&versionHistoryId={3}", attExtension, attGuid, GetSiteName(data, false), VersionHistoryID); btnAction.PreRender += img_PreRender; } break; #endregion #region "Library extension" case "extension": { result = data.ContainsColumn("FileExtension") ? data.GetValue("FileExtension").ToString() : data.GetValue("Extension").ToString(); result = NormalizeExtenison(result.ToString()); } break; #endregion #region "Modified" case "modified": case "modifiedtooltip": { if (sourceName.EqualsCSafe("modified", StringComparison.InvariantCultureIgnoreCase)) { result = data.ContainsColumn("FileModifiedWhen") ? data.GetValue("FileModifiedWhen").ToString() : data.GetValue("Modified").ToString(); result = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(result, DateTimeHelper.ZERO_TIME), true, userInfo, siteInfo); } else { result = GetGMTTooltipString(userInfo, siteInfo); } } break; #endregion #region "Document modified when" case "documentmodifiedwhen": case "filemodifiedwhen": case "documentmodifiedwhentooltip": case "filemodifiedwhentooltip": { if (sourceName.EqualsCSafe("documentmodifiedwhen", StringComparison.InvariantCultureIgnoreCase) || sourceName.EqualsCSafe("filemodifiedwhen", StringComparison.InvariantCultureIgnoreCase)) { result = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME), true, userInfo, siteInfo); } else { result = GetGMTTooltipString(userInfo, siteInfo); } } break; #endregion #region "MetaFile edit" case "metafileedit": btnAction = sender as CMSGridActionButton; if (btnAction != null) { // Get file extension string metaExtension = ValidationHelper.GetString(data.GetValue("MetaFileExtension"), string.Empty).ToLowerCSafe(); Guid metaGuid = ValidationHelper.GetGuid(data.GetValue("MetaFileGUID"), Guid.Empty); btnAction.ScreenReaderDescription = String.Format("{0}|metafileguid={1}", metaExtension, metaGuid); btnAction.PreRender += img_PreRender; } break; #endregion #region "MetaFile update" case "metafileupdate": { // Dynamically load uploader control dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; Panel updatePanel = new Panel(); updatePanel.ID = "updatePanel"; updatePanel.Width = mUpdateIconPanelWidth; updatePanel.Style.Add("margin", "0 auto"); // Initialize update control GetAttachmentUpdateControl(ref dfuElem, data); dfuElem.DisplayInline = true; updatePanel.Controls.Add(dfuElem); result = updatePanel; } break; #endregion #region "MetaFile modified" case "metafilemodified": case "metafilemodifiedtooltip": { if (sourceName.EqualsCSafe("metafilemodified", StringComparison.InvariantCultureIgnoreCase)) { result = data.GetValue("MetaFileLastModified").ToString(); result = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(result, DateTimeHelper.ZERO_TIME), true, userInfo, siteInfo); } else { result = GetGMTTooltipString(userInfo, siteInfo); } } break; #endregion } return result; }
/// <summary> /// Loads DataRow for BasicForm with data from Parameters property. /// </summary> private DataRowContainer GetData() { DataRowContainer result = new DataRowContainer(FormInfo.GetDataRow()); string columnName = null; if (Parameters != null) { foreach (DataColumn column in result.DataRow.Table.Columns) { columnName = column.ColumnName; if (!String.IsNullOrEmpty(Convert.ToString(Parameters[columnName])) && ValidationHelper.IsType(column.DataType, Parameters[columnName])) { result[columnName] = Parameters[columnName]; } } } return result; }
/// <summary> /// Loads DataRow for BasicForm with data from FormFieldInfo settings. /// </summary> private DataRowContainer GetData() { DataRowContainer result = new DataRowContainer(FormInfo.GetDataRow()); FormInfo.LoadDefaultValues(result); if (Settings != null) { foreach (string columnName in result.ColumnNames) { if (Settings.ContainsKey(columnName) && !String.IsNullOrEmpty(Convert.ToString(Settings[columnName]))) { result[columnName] = Settings[columnName]; } } } return result; }
/// <summary> /// External data binding handler. /// </summary> protected object gridDocuments_OnExternalDataBound(object sender, string sourceName, object parameter) { int currentNodeId = 0; sourceName = sourceName.ToLower(); switch (sourceName) { case "published": { // Published state bool published = ValidationHelper.GetBoolean(parameter, true); if (published) { return("<span class=\"DocumentPublishedYes\">" + GetString("General.Yes") + "</span>"); } else { return("<span class=\"DocumentPublishedNo\">" + GetString("General.No") + "</span>"); } } case "versionnumber": { // Version number if (parameter == DBNull.Value) { parameter = "-"; } parameter = HTMLHelper.HTMLEncode(parameter.ToString()); return(parameter); } case "documentname": { // Document name DataRowView data = (DataRowView)parameter; string className = ValidationHelper.GetString(data["ClassName"], string.Empty); string name = ValidationHelper.GetString(data["DocumentName"], string.Empty); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); string cultureString = null; currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0); string preferredCulture = CMSContext.PreferredCultureCode; // Default culture if (culture.ToLower() != preferredCulture.ToLower()) { cultureString = " (" + culture + ")"; } string tooltip = UniGridFunctions.DocumentNameTooltip(data); string imageUrl = null; if (className.Equals("cms.file", StringComparison.InvariantCultureIgnoreCase)) { string extension = ValidationHelper.GetString(data["DocumentType"], ""); imageUrl = GetFileIconUrl(extension, "List"); } // Use class icons else { imageUrl = ResolveUrl(GetDocumentTypeIconUrl(className)); } StringBuilder sb = new StringBuilder(); sb.Append( "<img src=\"", imageUrl, "\" class=\"UnigridActionButton\" /> ", "<a href=\"javascript: SelectItem(", currentNodeId, ", ", nodeParentId, ");\" ", "onmouseout=\"UnTip()\" onmouseover=\"Tip('", tooltip, "')\">", HTMLHelper.HTMLEncode(TextHelper.LimitLength(name, 50)), cultureString, "</a>" ); // Prepare parameters int workflowStepId = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(data, "DocumentWorkflowStepID"), 0); string stepName = null; if (workflowStepId > 0) { WorkflowStepInfo stepInfo = WorkflowStepInfoProvider.GetWorkflowStepInfo(workflowStepId); if (stepInfo != null) { stepName = stepInfo.StepName; } } // Create data container IDataContainer container = new DataRowContainer(data); // Add icons sb.Append(" ", UIHelper.GetDocumentMarks(Page, currentSiteName, preferredCulture, stepName, container)); return(sb.ToString()); } case "documentculture": { // Dynamically load document flags control DocumentFlagsControl ucDocFlags = Page.LoadControl("~/CMSAdminControls/UI/DocumentFlags.ascx") as DocumentFlagsControl; // Set document flags properties if (ucDocFlags != null) { // Get node ID currentNodeId = ValidationHelper.GetInteger(parameter, 0); ucDocFlags.ID = "docFlags" + currentNodeId; ucDocFlags.SiteCultures = SiteCultures; ucDocFlags.NodeID = currentNodeId; ucDocFlags.StopProcessing = true; // Keep the control for later usage FlagsControls.Add(ucDocFlags); return(ucDocFlags); } } break; case "modifiedwhen": case "modifiedwhentooltip": // Modified when if (string.IsNullOrEmpty(parameter.ToString())) { return(""); } else { DateTime modifiedWhen = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME); if (currentUserInfo == null) { currentUserInfo = CMSContext.CurrentUser; } if (currentSiteInfo == null) { currentSiteInfo = CMSContext.CurrentSite; } bool displayGMT = (sourceName == "modifiedwhentooltip"); return(TimeZoneHelper.ConvertToUserTimeZone(modifiedWhen, displayGMT, currentUserInfo, currentSiteInfo)); } case "classdisplayname": case "classdisplaynametooltip": // Localize class display name if (!string.IsNullOrEmpty(parameter.ToString())) { return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(parameter.ToString()))); } return(""); } return(parameter); }
/// <summary> /// Gets the macros from the system /// </summary> /// <param name="startIndex">Start index</param> /// <param name="endIndex">End index</param> /// <param name="maxTotalRecords">Maximum number of total records to process</param> /// <param name="totalRecords">Returns the total number of records found</param> private IEnumerable<MacroExpr> GetMacros(int startIndex, int endIndex, int maxTotalRecords, ref int totalRecords) { var index = 0; IEnumerable<string> objectTypes = null; // Get object types to search var selectedType = ValidationHelper.GetString(selObjectType.Value, ""); if (!String.IsNullOrEmpty(selectedType)) { if (ObjectTypeManager.GetRegisteredTypeInfo(selectedType) != null) { objectTypes = new List<string> { selectedType }; } } if (objectTypes == null) { objectTypes = ObjectTypeManager.ObjectTypesWithMacros; } var result = new List<MacroExpr>(); var search = txtFilter.Text; var invalid = chkInvalid.Checked; var skipTesting = SystemContext.DevelopmentMode && chkSkipTesting.Checked; var type = drpType.Text; foreach (var objectType in objectTypes) { // Skip certain object types switch (objectType) { case ObjectVersionHistoryInfo.OBJECT_TYPE: case VersionHistoryInfo.OBJECT_TYPE: case StagingTaskInfo.OBJECT_TYPE: case IntegrationTaskInfo.OBJECT_TYPE: continue; } // Process all objects of the given type var infos = new ObjectQuery(objectType) .TopN(maxTotalRecords) .BinaryData(false); var typeInfo = infos.TypeInfo; if (skipTesting) { ExcludeTestingObjects(infos); } if (!String.IsNullOrEmpty(search)) { // Search particular expression infos.WhereAnyColumnContains(search); } else { // Search just type infos.WhereAnyColumnContains("{" + type); } Action<DataRow> collectMacros = dr => { var drc = new DataRowContainer(dr); // Process all expressions MacroProcessor.ProcessMacros(drc, (expression, colName) => { var originalExpression = expression; // Decode macro from XML if (MacroProcessor.IsXMLColumn(colName)) { expression = HTMLHelper.HTMLDecode(expression); } MacroExpr e = null; bool add = false; if (String.IsNullOrEmpty(search) || (expression.IndexOfCSafe(search, true) >= 0)) { // If not tracking errors, count immediately if (!invalid) { // Apply paging. Endindex is -1 when paging is off if ((endIndex < 0) || ((index >= startIndex) && (index <= endIndex))) { e = GetMacroExpr(expression); add = true; } index++; } else { e = GetMacroExpr(expression); // Filter invalid signature / syntax var pass = !e.SignatureValid || e.Error; if (pass) { // Apply paging. Endindex is -1 when paging is off if ((endIndex < 0) || ((index >= startIndex) && (index <= endIndex))) { add = true; } index++; } } } if (add) { // Fill in the object information e.ObjectType = objectType; e.ObjectID = (typeInfo.IDColumn == ObjectTypeInfo.COLUMN_NAME_UNKNOWN) ? 0 : ValidationHelper.GetInteger(dr[typeInfo.IDColumn], 0); e.Field = colName; result.Add(e); } return originalExpression; }, new List<string> { type } ); if ((maxTotalRecords != -1) && (index >= maxTotalRecords)) { // Enough data - cancel enumeration throw new ActionCancelledException(); } }; using (var scope = new CMSConnectionScope()) { scope.Connection.CommandTimeout = ConnectionHelper.LongRunningCommandTimeout; infos.ForEachRow(collectMacros); } if (((maxTotalRecords != -1) && (index >= maxTotalRecords)) || !CMSHttpContext.Current.Response.IsClientConnected) { break; } } totalRecords = index; return result; }
/// <summary> /// External data binding handler. /// </summary> protected object gridDocuments_OnExternalDataBound(object sender, string sourceName, object parameter) { int currentNodeId; sourceName = sourceName.ToLowerCSafe(); switch (sourceName) { case "view": { // Dialog view item DataRowView data = ((DataRowView)((GridViewRow)parameter).DataItem); CMSGridActionButton btn = ((CMSGridActionButton)sender); // Current row is the Root document isRootDocument = (ValidationHelper.GetInteger(data["NodeParentID"], 0) == 0); currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); isCurrentDocument = (currentNodeId == WOpenerNodeID); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); // Existing document culture if (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe()) { // Force redirection to the root document in case of on-site editing (to ensure that user is not redirected to default alias path document) string url = ResolveUrl(!isRootDocument ? DocumentURLProvider.GetPresentationUrlHandlerPath(culture, currentNodeId) : "~/"); btn.OnClientClick = "ViewItem(" + ScriptHelper.GetString(url) + "); return false;"; } // New culture version else { btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;"; } } break; case "edit": { CMSGridActionButton btn = ((CMSGridActionButton)sender); if (IsEditVisible) { DataRowView data = ((DataRowView)((GridViewRow)parameter).DataItem); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0); if (!RequiresDialog || (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe())) { // Go to the selected document or create a new culture version when not used in a dialog btn.OnClientClick = "EditItem(" + currentNodeId + ", " + nodeParentId + "); return false;"; } else { // New culture version in a dialog btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;"; } } else { btn.Visible = false; } } break; case "delete": { // Delete button CMSGridActionButton btn = ((CMSGridActionButton)sender); // Hide the delete button for the root document btn.Visible = !isRootDocument; } break; case "contextmenu": { // Dialog context menu item CMSGridActionButton btn = ((CMSGridActionButton)sender); // Hide the context menu for the root document btn.Visible = !isRootDocument && !ShowAllLevels; } break; case "versionnumber": { // Version number if (parameter == DBNull.Value) { parameter = "-"; } parameter = HTMLHelper.HTMLEncode(parameter.ToString()); return parameter; } case "documentname": { // Document name DataRowView data = (DataRowView)parameter; string className = ValidationHelper.GetString(data["ClassName"], string.Empty); string classDisplayName = ValidationHelper.GetString(data["classdisplayname"], null); string name = ValidationHelper.GetString(data["DocumentName"], string.Empty); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); string cultureString = null; currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0); if (isRootDocument) { // User site name for the root document name = SiteContext.CurrentSiteName; } // Default culture if (culture.ToLowerCSafe() != CultureCode.ToLowerCSafe()) { cultureString = " (" + culture + ")"; } StringBuilder sb = new StringBuilder(); var isFile = className.EqualsCSafe(SystemDocumentTypes.File, true); string extension = isFile ? ValidationHelper.GetString(data["DocumentType"], String.Empty) : String.Empty; if (ShowDocumentTypeIcon) { // Prepare tooltip for document type icon string iconTooltip = ""; if (ShowDocumentTypeIconTooltip && (classDisplayName != null)) { iconTooltip = string.Format("onmouseout=\"UnTip()\" onmouseover=\"Tip('{0}')\"", HTMLHelper.HTMLEncode(ResHelper.LocalizeString(classDisplayName))); } if (isFile) { sb.Append(UIHelper.GetFileIcon(Page, extension, additionalAttributes: iconTooltip)); } // Use class icons else { var dataClass = DataClassInfoProvider.GetDataClassInfo(className); if (dataClass != null) { var iconClass = (string)dataClass.GetValue("ClassIconClass"); sb.Append(UIHelper.GetDocumentTypeIcon(Page, className, iconClass, additionalAttributes: iconTooltip)); } } } string safeName = HTMLHelper.HTMLEncode(TextHelper.LimitLength(name, 50)); if (DocumentNameAsLink && !isRootDocument) { string tooltip = UniGridFunctions.DocumentNameTooltip(data); string selectFunction = SelectItemJSFunction + "(" + currentNodeId + ", " + nodeParentId + ");"; sb.Append("<a href=\"javascript: ", selectFunction, "\""); // Ensure onclick action on mobile devices. This is necessary due to Tip/UnTip functions. They block default click behavior on mobile devices. if (DeviceContext.CurrentDevice.IsMobile) { sb.Append(" ontouchend=\"", selectFunction, "\""); } sb.Append(" onmouseout=\"UnTip()\" onmouseover=\"Tip('", tooltip, "')\">", safeName, cultureString, "</a>"); } else { sb.Append(safeName, cultureString); } // Show document marks only if method is not called from grid export and document marks are allowed if ((sender != null) && ShowDocumentMarks) { // Prepare parameters int workflowStepId = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(data, "DocumentWorkflowStepID"), 0); WorkflowStepTypeEnum stepType = WorkflowStepTypeEnum.Undefined; if (workflowStepId > 0) { WorkflowStepInfo stepInfo = WorkflowStepInfoProvider.GetWorkflowStepInfo(workflowStepId); if (stepInfo != null) { stepType = stepInfo.StepType; } } // Create data container IDataContainer container = new DataRowContainer(data); // Add icons and use current culture of processed node because of 'Not translated document' icon sb.Append(" ", DocumentUIHelper.GetDocumentMarks(Page, currentSiteName, ValidationHelper.GetString(container.GetValue("DocumentCulture"), string.Empty), stepType, container)); } return sb.ToString(); } case "documentculture": { DocumentFlagsControl ucDocFlags = null; if (OnDocumentFlagsCreating != null) { // Raise event for obtaining custom DocumentFlagControl object result = OnDocumentFlagsCreating(this, sourceName, parameter); ucDocFlags = result as DocumentFlagsControl; // Check if something other than DocumentFlagControl was returned if ((ucDocFlags == null) && (result != null)) { return result; } } // Dynamically load document flags control when not created if (ucDocFlags == null) { ucDocFlags = LoadUserControl("~/CMSAdminControls/UI/DocumentFlags.ascx") as DocumentFlagsControl; } // Set document flags properties if (ucDocFlags != null) { DataRowView data = (DataRowView)parameter; // Get node ID currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); if (!string.IsNullOrEmpty(SelectLanguageJSFunction)) { ucDocFlags.SelectJSFunction = SelectLanguageJSFunction; } ucDocFlags.ID = "docFlags" + currentNodeId; ucDocFlags.SiteCultures = SiteCultures; ucDocFlags.NodeID = currentNodeId; ucDocFlags.StopProcessing = true; // Keep the control for later usage FlagsControls.Add(ucDocFlags); return ucDocFlags; } } break; case "modifiedwhen": case "modifiedwhentooltip": // Modified when if (string.IsNullOrEmpty(parameter.ToString())) { return string.Empty; } DateTime modifiedWhen = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME); currentUserInfo = currentUserInfo ?? MembershipContext.AuthenticatedUser; currentSiteInfo = currentSiteInfo ?? SiteContext.CurrentSite; return sourceName.EqualsCSafe("modifiedwhen", StringComparison.InvariantCultureIgnoreCase) ? TimeZoneHelper.ConvertToUserTimeZone(modifiedWhen, true, currentUserInfo, currentSiteInfo) : TimeZoneHelper.GetUTCLongStringOffset(currentUserInfo, currentSiteInfo); case "classdisplayname": case "classdisplaynametooltip": // Localize class display name if (!string.IsNullOrEmpty(parameter.ToString())) { return HTMLHelper.HTMLEncode(ResHelper.LocalizeString(parameter.ToString())); } return string.Empty; default: if (OnExternalAdditionalDataBound != null) { return OnExternalAdditionalDataBound(sender, sourceName, parameter); } break; } return parameter; }