/// <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); }
/// <summary> /// External data binding handler. /// </summary> protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter) { // Prepare variables string culture; DataRowView data; sourceName = sourceName.ToLowerCSafe(); SiteInfo site; switch (sourceName) { // Edit button case EXTERNALSOURCE_EDIT: if (sender is CMSGridActionButton) { var editButton = (CMSGridActionButton)sender; data = UniGridFunctions.GetDataRowView(editButton.Parent as DataControlFieldCell); site = GetSiteFromRow(data); int nodeId = ValidationHelper.GetInteger(data[SOURCE_NODEID], 0); culture = ValidationHelper.GetString(data[SOURCE_DOCUMENTCULTURE], string.Empty); string type = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(data, SOURCE_TYPE), string.Empty); // Check permissions if ((site.Status != SiteStatusEnum.Running) || (!CMSPage.IsUserAuthorizedPerContent(site.SiteName) || ((ListingType == ListingTypeEnum.All) && (type == LISTINGTYPE_RECYCLEBIN)))) { editButton.Enabled = false; editButton.Style.Add(HtmlTextWriterStyle.Cursor, "default"); } else { editButton.Attributes.Add("data-site-url", ResolveSiteUrl(site)); editButton.Attributes.Add("data-node-id", nodeId.ToString()); editButton.Attributes.Add("data-document-culture", culture); } editButton.OnClientClick = "return false"; return(editButton); } return(sender); // Preview button case EXTERNALSOURCE_PREVIEW: if (sender is CMSGridActionButton) { var previewButton = (CMSGridActionButton)sender; data = UniGridFunctions.GetDataRowView(previewButton.Parent as DataControlFieldCell); site = GetSiteFromRow(data); string type = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(data, SOURCE_TYPE), string.Empty); string className = ValidationHelper.GetString(data[SOURCE_CLASSNAME], string.Empty); if ((site.Status != SiteStatusEnum.Running) || ((ListingType == ListingTypeEnum.All) && (type == LISTINGTYPE_RECYCLEBIN)) || !DataClassInfoProvider.GetDataClassInfo(className).ClassHasURL) { previewButton.Enabled = false; previewButton.Style.Add(HtmlTextWriterStyle.Cursor, "default"); } else { culture = ValidationHelper.GetString(data[SOURCE_DOCUMENTCULTURE], string.Empty); var nodeId = ValidationHelper.GetInteger(data[SOURCE_NODEID], 0); var url = DocumentUIHelper.GetPageHandlerPreviewPath(nodeId, culture, CurrentUser.UserName); previewButton.Attributes.Add("data-preview-url", URLHelper.GetAbsoluteUrl(url, site.DomainName)); } previewButton.OnClientClick = "return false"; return(previewButton); } return(sender); // Document name column case EXTERNALSOURCE_DOCUMENTNAME: { data = (DataRowView)parameter; string name = ValidationHelper.GetString(data[SOURCE_DOCUMENTNAME], string.Empty); string className = ValidationHelper.GetString(data[SOURCE_CLASSNAME], string.Empty); if (name == string.Empty) { name = GetString("general.root"); } // Add document type icon string result = string.Empty; switch (ListingType) { case ListingTypeEnum.DocTypeDocuments: break; default: var dataClass = DataClassInfoProvider.GetDataClassInfo(className); if (dataClass != null) { var iconClass = (string)dataClass.GetValue(SOURCE_CLASSICONCLASS); result = UIHelper.GetDocumentTypeIcon(Page, className, iconClass); } break; } result += "<span>" + HTMLHelper.HTMLEncode(TextHelper.LimitLength(name, 50)) + "</span>"; // Show document marks only if method is not called from grid export if ((sender != null) && (ListingType != ListingTypeEnum.All)) { bool isLink = (data.Row.Table.Columns.Contains(SOURCE_NODELINKEDNODEID) && (data[SOURCE_NODELINKEDNODEID] != DBNull.Value)); if (isLink) { // Add link icon result += DocumentUIHelper.GetDocumentMarkImage(Parent.Page, DocumentMarkEnum.Link); } } return(result); } // Class name column case EXTERNALSOURCE_CLASSDISPLAYNAME: string displayName = ValidationHelper.GetString(parameter, string.Empty); if (sourceName.ToLowerCSafe() == EXTERNALSOURCE_CLASSDISPLAYNAMETOOLTIP) { displayName = TextHelper.LimitLength(displayName, 50); } if (displayName == string.Empty) { displayName = "-"; } return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(displayName))); case EXTERNALSOURCE_DOCUMENTNAMETOOLTIP: data = (DataRowView)parameter; return(UniGridFunctions.DocumentNameTooltip(data)); case EXTERNALSOURCE_STEPDISPLAYNAME: // Step display name int stepId = ValidationHelper.GetInteger(parameter, 0); if (stepId > 0) { return(new ObjectTransformation(WorkflowStepInfo.OBJECT_TYPE, stepId) { Transformation = "{%stepdisplayname|(encode)%}" }); } return("-"); // Version column case EXTERNALSOURCE_VERSION: if (parameter == DBNull.Value) { parameter = "-"; } parameter = HTMLHelper.HTMLEncode(parameter.ToString()); return(parameter); // Document timestamp column case EXTERNALSOURCE_MODIFIEDWHEN: case EXTERNALSOURCE_MODIFIEDWHENTOOLTIP: if (String.IsNullOrEmpty(parameter.ToString())) { return(String.Empty); } if (currentSiteInfo == null) { currentSiteInfo = SiteContext.CurrentSite; } if (sourceName.EqualsCSafe(EXTERNALSOURCE_MODIFIEDWHEN, StringComparison.InvariantCultureIgnoreCase)) { DateTime time = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME); return(TimeZoneHelper.ConvertToUserTimeZone(time, true, currentUserInfo, currentSiteInfo)); } return(mGMTTooltip ?? (mGMTTooltip = TimeZoneHelper.GetUTCLongStringOffset(currentUserInfo, currentSiteInfo))); } return(parameter); }