// Change any AnimationTarget references from server control IDs into the ClientIDs // that the animation scripts are expecting. protected void ResolveControlIDs(Animation animation) { if(animation == null) { return; } // See if the animation had a target string id; if(animation.Properties.TryGetValue("AnimationTarget", out id) && !String.IsNullOrEmpty(id)) { // Try to find a control with the target's id by walking up the NamingContainer tree Control control = null; var container = NamingContainer; while((container != null) && ((control = container.FindControl(id)) == null)) { container = container.Parent; } // If we found a control if(control != null) { // Map the server ID to the client ID animation.Properties["AnimationTarget"] = control.ClientID; } } // Resolve any server control IDs in the animation's children foreach(var child in animation.Children) ResolveControlIDs(child); }
/// <summary> /// Replace any statically defined AnimationTarget properties with a corresponding /// TargetScript dynamic animation property /// </summary> /// <param name="animation">Animation</param> private void ReplaceStaticAnimationTargets(Animation animation) { if (animation == null) { return; } // Check if the Animation has an AnimationTarget property, but not AnimationTargetScript // or TargetScript properties string id; string script; if ((animation.Properties.TryGetValue("AnimationTarget", out id) && !string.IsNullOrEmpty(id)) && (!animation.Properties.TryGetValue("AnimationTargetScript", out script) || string.IsNullOrEmpty(script)) && (!animation.Properties.TryGetValue("TargetScript", out script) || string.IsNullOrEmpty(script))) { // Remove the AnimationTarget property and replace it with a dynamic wrapper animation.Properties.Remove("AnimationTarget"); animation.Properties["TargetScript"] = string.Format(CultureInfo.InvariantCulture, "$get('{0}')", id); } // Replace any static animation targets on this Animation's children foreach (Animation child in animation.Children) { ReplaceStaticAnimationTargets(child); } }
// Recursively convert the JavaScriptSerializer's representation into an Animation static Animation Deserialize(IDictionary<string, object> obj) { if(obj == null) throw new ArgumentNullException("obj"); var animation = new Animation(); if(!obj.ContainsKey("AnimationName")) throw new InvalidOperationException("Cannot deserialize an Animation without an AnimationName property"); animation.Name = obj["AnimationName"] as string; // Deserialize the animation's properties (ignoring any special properties) foreach(var pair in obj) { if(String.Compare(pair.Key, "AnimationName", StringComparison.OrdinalIgnoreCase) != 0 && String.Compare(pair.Key, "AnimationChildren", StringComparison.OrdinalIgnoreCase) != 0) animation.Properties.Add(pair.Key, pair.Value != null ? pair.Value.ToString() : null); } if(obj.ContainsKey("AnimationChildren")) { var children = obj["AnimationChildren"] as ArrayList; if(children != null) foreach(var c in children) { var child = c as IDictionary<string, object>; if(child != null) animation.Children.Add(Deserialize(child)); } } return animation; }
protected void gvAuditoriaActual_SelectedIndexChanged(object sender, EventArgs e) { if (gvAuditoriaActual.SelectedRow != null) { foreach (GridViewRow row in gvAuditoriaActual.Rows) { foreach (Control ctr in row.Cells[7].Controls) { if (ctr.ID == "btnComponentes") { ((Button)ctr).Enabled = false; row.Attributes.Clear(); InicializarRow(sender, row); } } } foreach (Control ctr in gvAuditoriaActual.SelectedRow.Cells[7].Controls) { if (ctr.ID == "btnComponentes") { ((Button)ctr).Enabled = true; AEDetalle.TargetControlID = ctr.UniqueID; AEDetalle.OnClick.Children.RemoveAt(0); AjaxControlToolkit.Animation a = new AjaxControlToolkit.Animation(); a.Name = "ScriptAction"; a.Properties.Add("Script", "Cover($get('" + ctr.UniqueID + "'), $get('flyout'));"); AEDetalle.OnClick.Children.Insert(0, a); gvAuditoriaActual.SelectedRow.Attributes.Clear(); break; } } string identificador = gvAuditoriaActual.SelectedRow.Cells[6].Text + gvAuditoriaActual.SelectedRow.Cells[2].Text; string IdsCalculo = (string)((IList)_ContadoresMesActual[identificador])[1]; DSConosudTableAdapters.CabeceraHojasDeRutaTableAdapter DACabecera = new DSConosudTableAdapters.CabeceraHojasDeRutaTableAdapter(); DSConosud.CabeceraHojasDeRutaDataTable DTCabecera = DACabecera.GetDataByCabeceras(IdsCalculo); gvDetalle.DataSource = DTCabecera; gvDetalle.DataBind(); } }
/// <summary> /// Recursively onvert an Animation to a representation understood by the JavaScriptSerializer /// </summary> /// <param name="animation">Animation</param> /// <returns>Converted representation of the Animation</returns> private static IDictionary<string, object> Serialize(Animation animation) { if (animation == null) throw new ArgumentNullException("animation"); // Create the representation Dictionary<string, object> obj = new Dictionary<string, object>(); obj["AnimationName"] = animation.Name; // Add the properties foreach (KeyValuePair<string, string> pair in animation.Properties) obj[pair.Key] = pair.Value; // Recursively add the children List<IDictionary<string, object>> children = new List<IDictionary<string, object>>(); foreach (Animation child in animation.Children) children.Add(Serialize(child)); obj["AnimationChildren"] = children.ToArray(); return obj; }
/// <summary> /// Recursively convert the JavaScriptSerializer's representation into an Animation /// </summary> /// <param name="obj">Representation of the Animation</param> /// <returns>Animation</returns> private static Animation Deserialize(IDictionary<string, object> obj) { if (obj == null) throw new ArgumentNullException("obj"); // Create the instance to deserialize into Animation animation = new Animation(); // Get the animation's name if (!obj.ContainsKey("AnimationName")) throw new InvalidOperationException("Cannot deserialize an Animation without an AnimationName property"); animation.Name = obj["AnimationName"] as string; // Deserialize the animation's properties (ignoring any special properties) foreach (KeyValuePair<string, object> pair in obj) { if (string.Compare(pair.Key, "AnimationName", StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(pair.Key, "AnimationChildren", StringComparison.OrdinalIgnoreCase) != 0) animation.Properties.Add(pair.Key, pair.Value != null ? pair.Value.ToString() : null); } // Get any children and recursively deserialize them if (obj.ContainsKey("AnimationChildren")) { ArrayList children = obj["AnimationChildren"] as ArrayList; if (children != null) foreach (object c in children) { IDictionary<string, object> child = c as IDictionary<string, object>; if (c != null) animation.Children.Add(Deserialize(child)); } } return animation; }
public static Animation Deserialize(XmlNode node) { if (node == null) throw new ArgumentNullException("node"); // Create the new animation Animation animation = new Animation(); animation.Name = node.Name; // Set the properties of the animation foreach (XmlAttribute attribute in node.Attributes) animation.Properties.Add(attribute.Name, attribute.Value); // Add any children (recursively) if (node.HasChildNodes) foreach (XmlNode child in node.ChildNodes) animation.Children.Add(Animation.Deserialize(child)); return animation; }
/// <summary> /// Convert an animation into its JSON description /// </summary> /// <param name="animation">Animation to convert</param> /// <returns>JSON description of the animation</returns> public static string Serialize(Animation animation) { return _serializer.Serialize(animation); }
// Set an animation (which is a helper for Animation properties in other extenders) // param "animation" is the Animation instance // param "name" is the name of the property // param "value" is the new value protected void SetAnimation(ref Animation animation, string name, Animation value) { animation = value; SetPropertyValue(name, animation != null ? animation.ToString() : String.Empty); }
// Get an animation (which is a helper for Animation properties in other extenders) // param "animation" is the Animation instance // param "name" is the name of the property // returns Animation instance protected Animation GetAnimation(ref Animation animation, string name) { if(animation == null) animation = Animation.Deserialize(GetPropertyValue(name, "")); return animation; }