public static string GetMenuActionScript(MetricBase model, MetricAction action, string moreActionDivId, string contextValues) { const string dynamicFormat = "closeMoreMenu(); showDynamicContent('#{0}','{1}{2}','#{3}', '{4}', '{5}');"; const string linkFormat = "closeMoreMenu(); NavigateToPage('{1}');"; if (action == null) throw new ArgumentNullException("action", "Action cannot be null."); if (action.Url == null) throw new ApplicationException("Action does not have it's Url property set. Metric Variant Id: " + action.MetricVariantId + " Title: " + action.Title); if (action == null) throw new ArgumentNullException("action", "Action cannot be null."); if (action.Url == null) throw new ApplicationException("Action does not have it's Url property set. Metric Variant Id: " + action.MetricVariantId + " Title: " + action.Title); if (action == null) throw new ArgumentNullException("action", "Action cannot be null."); if (action.Url == null) throw new ApplicationException("Action does not have it's Url property set. Metric Variant Id: " + action.MetricVariantId + " Title: " + action.Title); string parameterValues; if (!action.Url.Contains(".aspx"))//converted resources { parameterValues = action.Url.Resolve() + "?" + DateTime.Now.Ticks; string subjectArea = GetSubjectArea(model.MetricVariantId); if (!string.IsNullOrEmpty(subjectArea)) { parameterValues += ("&subjectArea=" + subjectArea.Replace(" ", "%20")); } if (action.ActionType == MetricActionType.DynamicContent || action.ActionType == MetricActionType.AlwaysDisplayedDynamicContent) { string divId = "DynamicContentDiv" + GetDynamicContentNameFromAction(action); return String.Format(dynamicFormat, divId, parameterValues + "&Title=" + action.GetTitleSafeForHtmlId(), "", moreActionDivId, action.GetTitleSafeForHtmlId() + action.MetricVariantId, model.Parent == null ? model.MetricVariantId : model.Parent.MetricVariantId); } else { return String.Format(linkFormat, moreActionDivId, parameterValues); } } else { parameterValues = ReplaceParametersWithValues(action.Url, contextValues); if (action.Url.Contains("{schoolId}") && !action.Url.Contains("{localEducationAgencyId}")) parameterValues = parameterValues.AppendParameters("localEducationAgencyId=" + EdFiDashboardContext.Current.LocalEducationAgencyId); if (action.ActionType == MetricActionType.DynamicContent || action.ActionType == MetricActionType.AlwaysDisplayedDynamicContent) { string divId = "DynamicContentDiv" + action.MetricVariantId + action.GetTitleSafeForHtmlId(); string additionalQstrings = "&" + DateTime.Now.Ticks + "&divId=" + divId + "&moreImageId=" + moreActionDivId + "&metricActionTitle=" + action.Title.Replace(" ", "%20") + "&blueHeaderSpan=blueHeaderSpan" + model.MetricVariantId + action.GetTitleSafeForHtmlId(); return String.Format(dynamicFormat, divId, parameterValues, additionalQstrings, moreActionDivId, action.GetTitleSafeForHtmlId() + action.MetricVariantId, model.Parent == null ? model.MetricVariantId : model.Parent.MetricVariantId); } else { return String.Format(linkFormat, moreActionDivId, parameterValues); } } }
/// <summary> /// Returns a string that represents the MetricAction suitable for use in a HTML id. /// </summary> /// <param name="action"></param> /// <returns></returns> public static string GetDynamicContentNameFromAction(MetricAction action) { return action.MetricVariantId + action.GetTitleSafeForHtmlId(); }