Ejemplo n.º 1
0
        /// <summary>
        /// Starts UpdatePanel container
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="config">Optional configuration</param>
        /// <returns></returns>
        public static UpdatePanelScope BeginUpdatePanel(this AjaxHelper helper, Action <UpdatePanelSettings> config = null)
        {
            if (!IsFilterRegistered())
            {
                throw new InvalidOperationException("UpdatePanelFilter must be registered in GlobalFilters");
            }
            //throw new NotImplementedException();
            var settings = new UpdatePanelSettings();

            if (config != null)
            {
                config(settings);
            }
            var panel = new UpdatePanelScope(helper.GetViewPage(), settings);

            panel.Page.UpdatePanelsStack().Push(panel);
            var siblings = panel.SiblingsList();

            siblings.Add(panel);

            var html = _UpdatePanelTemplate_cshtml.BeginUpdatePanel(panel);

            html.WriteTo(panel.Page.Output);

            panel.PushContext();

            return(panel);
        }
Ejemplo n.º 2
0
        public static UpdatePanelRequestType Requested(this UpdatePanelScope panel)
        {
            return(panel.Data().AddOrGetExisting("UpdatePanelRequestType", () =>
            {
                var actionContext = panel.ActionContext();
                var currentId = panel.Id();
                var requestedId = actionContext.UpdatePanelRequestedId();

                if (string.IsNullOrEmpty(requestedId))
                {
                    return UpdatePanelRequestType.EntireView;
                }
                if (requestedId == currentId)
                {
                    return UpdatePanelRequestType.CurrentPanel;
                }
                if (requestedId.StartsWith(currentId))
                {
                    return UpdatePanelRequestType.ChildPanel;
                }
                if (currentId.StartsWith(requestedId))
                {
                    return UpdatePanelRequestType.Parent;
                }
                return UpdatePanelRequestType.OtherPanel;
            }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns Data dictionary from Parent update panel or from Root
        /// </summary>
        /// <param name="panel"></param>
        /// <returns></returns>
        public static IDictionary <string, object> ParentData(this UpdatePanelScope panel)
        {
            var parent = panel.Parent();
            var res    = parent != null?parent.Data() : panel.Page.ActionData();

            return(res);
        }
Ejemplo n.º 4
0
        public static StringWriter RootWriter(this UpdatePanelScope scope, bool createIfNotExists = true)
        {
            var writer =
                createIfNotExists ?
                scope.ActionData(true).AddOrGetExisting("UpdatePanels.Renderer", () => new StringWriter())
                    : scope.ActionData(true).TryGetValue("UpdatePanels.Renderer", null as StringWriter)
            ;

            return(writer);
        }
Ejemplo n.º 5
0
        public static bool ShouldRenderParent(this UpdatePanelScope scope)
        {
            var parent = scope.Parent();

            if (parent != null)
            {
                return(parent.ShouldRender());
            }
            return(scope.Requested() == UpdatePanelRequestType.EntireView);
        }
Ejemplo n.º 6
0
        public static void EndUpdatePanel(this UpdatePanelScope panel)
        {
            panel.PopContext();

            var html = _UpdatePanelTemplate_cshtml.EndUpdatePanel(panel);

            html.WriteTo(panel.Page.Output);

            panel.Page.UpdatePanelsStack().Pop();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Retrieve call back URL
        /// </summary>
        /// <param name="panel"></param>
        /// <returns></returns>
        public static string GetCallbackUrl(this UpdatePanelScope panel)
        {
            var ctx         = panel.Page.ActionContextsStack().Last();
            var originalUrl = new Uri(ctx.HttpContext.Request.RawUrl, UriKind.Relative);
            var url         = originalUrl.ExtendQuery(new Dictionary <string, string> {
                { UpdatePanelUrlParameterName, panel.Id() }
            });

            return(url.ToString());
        }
Ejemplo n.º 8
0
        public static string Id(this UpdatePanelScope panel, bool recursive = true)
        {
            if (!recursive)
            {
                return(panel.Data().AddOrGetExisting("Id", () => panel.Settings.Id ?? ((panel.IndexInParent() + 1).ToString())));
            }

            var parents = panel.Parents().Reverse();

            return(string.Join("/", parents.Concat(new[] { panel }).Select(p => p.Id(false))));
        }
Ejemplo n.º 9
0
        public static void PushContext(this UpdatePanelScope scope)
        {
            var panelShouldRender  = scope.ShouldRender();
            var parentShouldRender = scope.ShouldRenderParent();

            var startRendering = parentShouldRender == false && panelShouldRender == true;
            var endRendering   = parentShouldRender == true && panelShouldRender == false;

            if (startRendering)
            {
                scope.Page.PushWriter(scope.RootWriter());
            }
            else if (endRendering)
            {
                scope.Page.PushWriter(TextWriter.Null);
            }
        }
        /// <summary>
        /// Starts UpdatePanel container
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="config">Optional configuration</param>
        /// <returns></returns>
        public static UpdatePanelScope BeginUpdatePanel(this AjaxHelper helper, Action<UpdatePanelSettings> config = null)
        {
            if (!IsFilterRegistered())
                throw new InvalidOperationException("UpdatePanelFilter must be registered in GlobalFilters");
            //throw new NotImplementedException();
            var settings = new UpdatePanelSettings();
            if (config != null)
                config(settings);
            var panel = new UpdatePanelScope(helper.GetViewPage(), settings);
            panel.Page.UpdatePanelsStack().Push(panel);
            var siblings = panel.SiblingsList();
            siblings.Add(panel);

            var html = _UpdatePanelTemplate_cshtml.BeginUpdatePanel(panel);
            html.WriteTo(panel.Page.Output);

            panel.PushContext();

            return panel;
        }
Ejemplo n.º 11
0
        public static void PopContext(this UpdatePanelScope scope)
        {
            var panelShouldRender  = scope.ShouldRender();
            var parentShouldRender = scope.ShouldRenderParent();

            var startRendering = parentShouldRender == false && panelShouldRender == true;
            var endRendering   = parentShouldRender == true && panelShouldRender == false;

            if (startRendering || endRendering)
            {
                //var rootWriter = scope.RootWriter(false);
                var writer = scope.Page.PopWriter();
                //if (writer == rootWriter)
                //{
                //    scope.Page.Context.Response.ClearContent();
                //    scope.Page.Context.Response.Output.Write(rootWriter.GetStringBuilder().ToString());
                //    scope.Page.Context.Response.Output = TextWriter.Null;
                //}
            }
        }
Ejemplo n.º 12
0
        public static bool ShouldRender(this UpdatePanelScope panel)
        {
            var parent             = panel.Parent();
            var parentShouldRender = parent != null?parent.ShouldRender() : true;   //root is true

            switch (panel.Requested())
            {
            case UpdatePanelRequestType.CurrentPanel:
                return(true);

            case UpdatePanelRequestType.EntireView:
            case UpdatePanelRequestType.Parent:
                return(parentShouldRender && panel.Settings.LoadMode == UpdatePanelLoadMode.RenderWithParent);

            case UpdatePanelRequestType.OtherPanel:
            case UpdatePanelRequestType.ChildPanel:
            default:
                return(false);
            }
        }
Ejemplo n.º 13
0
        public static System.Web.WebPages.HelperResult EndUpdatePanel(UpdatePanelScope updatePanel)
        {
#line default
#line hidden
            return(new System.Web.WebPages.HelperResult(__razor_helper_writer => {
#line 24 "..\..\UpdatePanelTemplate.cshtml"

                var elementId = updatePanel.Data()["ElementId"] as string;
                var id = updatePanel.Id();



#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "        </div>\r\n");

                WriteLiteralTo(__razor_helper_writer, "        <script>\r\n                (function()\r\n                {\r\n               " +
                               "     //DisableLinePragmas: true\r\n                    var id = ");


#line 34 "..\..\UpdatePanelTemplate.cshtml"
                WriteTo(__razor_helper_writer, J(id));


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, ";\r\n                    var elementId = ");


#line 35 "..\..\UpdatePanelTemplate.cshtml"
                WriteTo(__razor_helper_writer, J(elementId));


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, ";\r\n                    var callbackUrl = ");


#line 36 "..\..\UpdatePanelTemplate.cshtml"
                WriteTo(__razor_helper_writer, J(updatePanel.GetCallbackUrl()));


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, ";\r\n                    var settings = ");


#line 37 "..\..\UpdatePanelTemplate.cshtml"
                WriteTo(__razor_helper_writer, J(updatePanel.Settings));


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, ";\r\n                    settings.elementId = elementId;\r\n                    var p" +
                               "anel = UpdatePanels.CreateUpdatePanel(id, callbackUrl, settings);\r\n");


#line 40 "..\..\UpdatePanelTemplate.cshtml"


#line default
#line hidden

#line 40 "..\..\UpdatePanelTemplate.cshtml"
                if (!string.IsNullOrEmpty(updatePanel.Settings.JSInit))
                {
#line default
#line hidden
                    WriteLiteralTo(__razor_helper_writer, "                        ");

                    WriteLiteralTo(__razor_helper_writer, "(");


#line 42 "..\..\UpdatePanelTemplate.cshtml"
                    WriteTo(__razor_helper_writer, updatePanel.Settings.JSInit);


#line default
#line hidden
                    WriteLiteralTo(__razor_helper_writer, ")(panel);\r\n");


#line 43 "..\..\UpdatePanelTemplate.cshtml"
                }


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "                })();\r\n        </script>\r\n");

                WriteLiteralTo(__razor_helper_writer, "    </div>\r\n");


#line 47 "..\..\UpdatePanelTemplate.cshtml"


#line default
#line hidden
            }));

#line 47 "..\..\UpdatePanelTemplate.cshtml"
        }
Ejemplo n.º 14
0
 public static IEnumerable <UpdatePanelScope> Parents(this UpdatePanelScope panel)
 {
     return(panel.Page.UpdatePanelsStack().SkipWhile(p => p != panel).Skip(1));
 }
public static System.Web.WebPages.HelperResult EndUpdatePanel(UpdatePanelScope updatePanel)
{
#line default
#line hidden
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {

#line 24 "..\..\UpdatePanelTemplate.cshtml"
 
    var elementId = updatePanel.Data()["ElementId"] as string;
    var id = updatePanel.Id();




#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "        </div>\r\n");

WriteLiteralTo(__razor_helper_writer, "        <script>\r\n                (function()\r\n                {\r\n               " +
"     //DisableLinePragmas: true\r\n                    var id = ");


#line 34 "..\..\UpdatePanelTemplate.cshtml"
WriteTo(__razor_helper_writer, J(id));


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, ";\r\n                    var elementId = ");


#line 35 "..\..\UpdatePanelTemplate.cshtml"
      WriteTo(__razor_helper_writer, J(elementId));


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, ";\r\n                    var callbackUrl = ");


#line 36 "..\..\UpdatePanelTemplate.cshtml"
        WriteTo(__razor_helper_writer, J(updatePanel.GetCallbackUrl()));


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, ";\r\n                    var settings = ");


#line 37 "..\..\UpdatePanelTemplate.cshtml"
     WriteTo(__razor_helper_writer, J(updatePanel.Settings));


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, ";\r\n                    settings.elementId = elementId;\r\n                    var p" +
"anel = UpdatePanels.CreateUpdatePanel(id, callbackUrl, settings);\r\n");


#line 40 "..\..\UpdatePanelTemplate.cshtml"
                    

#line default
#line hidden

#line 40 "..\..\UpdatePanelTemplate.cshtml"
                     if (!string.IsNullOrEmpty(updatePanel.Settings.JSInit))
                    {


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "                        ");

WriteLiteralTo(__razor_helper_writer, "(");


#line 42 "..\..\UpdatePanelTemplate.cshtml"
WriteTo(__razor_helper_writer, updatePanel.Settings.JSInit);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, ")(panel);\r\n");


#line 43 "..\..\UpdatePanelTemplate.cshtml"
                    }


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "                })();\r\n        </script>\r\n");

WriteLiteralTo(__razor_helper_writer, "    </div>\r\n");


#line 47 "..\..\UpdatePanelTemplate.cshtml"


#line default
#line hidden
});

#line 47 "..\..\UpdatePanelTemplate.cshtml"
}
Ejemplo n.º 16
0
 public static UpdatePanelScope Parent(this UpdatePanelScope panel)
 {
     return(panel.Parents().FirstOrDefault());
 }
public static System.Web.WebPages.HelperResult BeginUpdatePanel(UpdatePanelScope updatePanel)
{
#line default
#line hidden
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {

#line 7 "..\..\UpdatePanelTemplate.cshtml"
 
var elementId = updatePanel.Data().AddOrGetExisting("ElementId", ()=>Guid.NewGuid().ToString("N"));
var id = updatePanel.Id();


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "  <div class=\"updatePanel\" id=\"");


#line 10 "..\..\UpdatePanelTemplate.cshtml"
   WriteTo(__razor_helper_writer, elementId);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "\" data-updatePanel=\"");


#line 10 "..\..\UpdatePanelTemplate.cshtml"
                                 WriteTo(__razor_helper_writer, id);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "\">\r\n");

WriteLiteralTo(__razor_helper_writer, "        <div");

WriteLiteralTo(__razor_helper_writer, " class=\"updatePanel-loading\"");

WriteLiteralTo(__razor_helper_writer, " data-updatePanel=\"");


#line 11 "..\..\UpdatePanelTemplate.cshtml"
                             WriteTo(__razor_helper_writer, id);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "\"");

WriteLiteralTo(__razor_helper_writer, ">\r\n");


#line 12 "..\..\UpdatePanelTemplate.cshtml"
            

#line default
#line hidden

#line 12 "..\..\UpdatePanelTemplate.cshtml"
             if (updatePanel.Settings.RenderLoadingDiv != null)
            {
                

#line default
#line hidden

#line 14 "..\..\UpdatePanelTemplate.cshtml"
WriteTo(__razor_helper_writer, updatePanel.Settings.RenderLoadingDiv(updatePanel));


#line default
#line hidden

#line 14 "..\..\UpdatePanelTemplate.cshtml"
                                                                   ;
            }
            else
            {


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "                ");

WriteLiteralTo(__razor_helper_writer, "Loading...please wait\r\n");


#line 19 "..\..\UpdatePanelTemplate.cshtml"
            }


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "        </div>\r\n");

WriteLiteralTo(__razor_helper_writer, "        ");

WriteLiteralTo(__razor_helper_writer, "<div class=\"updatePanel-content\" data-updatePanel=\"");


#line 21 "..\..\UpdatePanelTemplate.cshtml"
                               WriteTo(__razor_helper_writer, id);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "\">\r\n");


#line 22 "..\..\UpdatePanelTemplate.cshtml"


#line default
#line hidden
});

#line 22 "..\..\UpdatePanelTemplate.cshtml"
}
Ejemplo n.º 18
0
 public static ControllerContext ActionContext(this UpdatePanelScope panel)
 {
     return(panel.Page.ActionContextsStack().Last());
 }
Ejemplo n.º 19
0
 public static IDictionary <string, object> ActionData(this UpdatePanelScope panel, bool rootNotCurrent = true)
 {
     return(panel.Page.ActionData());
 }
Ejemplo n.º 20
0
        public static System.Web.WebPages.HelperResult BeginUpdatePanel(UpdatePanelScope updatePanel)
        {
#line default
#line hidden
            return(new System.Web.WebPages.HelperResult(__razor_helper_writer => {
#line 7 "..\..\UpdatePanelTemplate.cshtml"

                var elementId = updatePanel.Data().AddOrGetExisting("ElementId", () => Guid.NewGuid().ToString("N"));
                var id = updatePanel.Id();


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "  <div class=\"updatePanel\" id=\"");


#line 10 "..\..\UpdatePanelTemplate.cshtml"
                WriteTo(__razor_helper_writer, elementId);


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "\" data-updatePanel=\"");


#line 10 "..\..\UpdatePanelTemplate.cshtml"
                WriteTo(__razor_helper_writer, id);


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "\">\r\n");

                WriteLiteralTo(__razor_helper_writer, "        <div");

                WriteLiteralTo(__razor_helper_writer, " class=\"updatePanel-loading\"");

                WriteLiteralTo(__razor_helper_writer, " data-updatePanel=\"");


#line 11 "..\..\UpdatePanelTemplate.cshtml"
                WriteTo(__razor_helper_writer, id);


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "\"");

                WriteLiteralTo(__razor_helper_writer, ">\r\n");


#line 12 "..\..\UpdatePanelTemplate.cshtml"


#line default
#line hidden

#line 12 "..\..\UpdatePanelTemplate.cshtml"
                if (updatePanel.Settings.RenderLoadingDiv != null)
                {
#line default
#line hidden

#line 14 "..\..\UpdatePanelTemplate.cshtml"
                    WriteTo(__razor_helper_writer, updatePanel.Settings.RenderLoadingDiv(updatePanel));


#line default
#line hidden

#line 14 "..\..\UpdatePanelTemplate.cshtml"
                    ;
                }
                else
                {
#line default
#line hidden
                    WriteLiteralTo(__razor_helper_writer, "                ");

                    WriteLiteralTo(__razor_helper_writer, "Loading...please wait\r\n");


#line 19 "..\..\UpdatePanelTemplate.cshtml"
                }


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "        </div>\r\n");

                WriteLiteralTo(__razor_helper_writer, "        ");

                WriteLiteralTo(__razor_helper_writer, "<div class=\"updatePanel-content\" data-updatePanel=\"");


#line 21 "..\..\UpdatePanelTemplate.cshtml"
                WriteTo(__razor_helper_writer, id);


#line default
#line hidden
                WriteLiteralTo(__razor_helper_writer, "\">\r\n");


#line 22 "..\..\UpdatePanelTemplate.cshtml"


#line default
#line hidden
            }));

#line 22 "..\..\UpdatePanelTemplate.cshtml"
        }
Ejemplo n.º 21
0
 public static int IndexInParent(this UpdatePanelScope panel)
 {
     return(panel.SiblingsList().IndexOf(panel));
 }
Ejemplo n.º 22
0
 public static List <UpdatePanelScope> SiblingsList(this UpdatePanelScope panel)
 {
     return(panel.ParentData().AddOrGetExisting("UpdatePanel.Children", () => new List <UpdatePanelScope>()));
 }