Example #1
0
 public virtual string ReplaceStaticPlaceholder(string name, AttributeDictionary attributes, string defaultContent)
 {
     return null;
 }
Example #2
0
 protected virtual bool CreatePlaceholder(ControlCollection container, string placeholder, string defaultContent, AttributeDictionary attributes)
 {
     if (placeholder == "membership-bar")
     {
         var mb = new MembershipBar();
         mb.ID = "mb";
         if (attributes["data-display-remember-me"] == "false")
         	mb.DisplayRememberMe = false;
         if (attributes["data-remember-me-set"] == "true")
         	mb.RememberMeSet = true;
         if (attributes["data-display-password-recovery"] == "false")
         	mb.DisplayPasswordRecovery = false;
         if (attributes["data-display-sign-up"] == "false")
         	mb.DisplaySignUp = false;
         if (attributes["data-display-my-account"] == "false")
         	mb.DisplayMyAccount = false;
         if (attributes["data-display-help"] == "false")
         	mb.DisplayHelp = false;
         if (attributes["data-display-login"] == "false")
         	mb.DisplayLogin = false;
         if (!(string.IsNullOrEmpty(attributes["data-idle-user-timeout"])))
         	mb.IdleUserTimeout = Convert.ToInt32(attributes["data-idle-user-timeout"]);
         if (attributes["data-enable-history"] == "true")
         	mb.EnableHistory = true;
         if (attributes["data-enable-permalinks"] == "true")
         	mb.EnablePermalinks = true;
         container.Add(mb);
         return true;
     }
     if (placeholder == "menu-bar")
     {
         var menuDiv = new HtmlGenericControl();
         menuDiv.TagName = "div";
         menuDiv.ID = "PageMenuBar";
         menuDiv.Attributes["class"] = "PageMenuBar";
         container.Add(menuDiv);
         var menu = new MenuExtender();
         menu.ID = "Menu1";
         menu.DataSourceID = "SiteMapDataSource1";
         menu.TargetControlID = menuDiv.ID;
         menu.HoverStyle = ((MenuHoverStyle)(TypeDescriptor.GetConverter(typeof(MenuHoverStyle)).ConvertFromString(attributes.ValueOf("data-hover-style", "Auto"))));
         menu.PopupPosition = ((MenuPopupPosition)(TypeDescriptor.GetConverter(typeof(MenuPopupPosition)).ConvertFromString(attributes.ValueOf("data-popup-position", "Left"))));
         menu.ShowSiteActions = (attributes["data-show-site-actions"] == "true");
         menu.PresentationStyle = ((MenuPresentationStyle)(TypeDescriptor.GetConverter(typeof(MenuPresentationStyle)).ConvertFromString(attributes.ValueOf("data-presentation-style", "MultiLevel"))));
         container.Add(menu);
         return true;
     }
     if (placeholder == "site-map-path")
     {
         var siteMapPath1 = new SiteMapPath();
         siteMapPath1.ID = "SiteMapPath1";
         siteMapPath1.CssClass = "SiteMapPath";
         siteMapPath1.PathSeparatorStyle.CssClass = "PathSeparator";
         siteMapPath1.CurrentNodeStyle.CssClass = "CurrentNode";
         siteMapPath1.NodeStyle.CssClass = "Node";
         siteMapPath1.RootNodeStyle.CssClass = "RootNode";
         container.Add(siteMapPath1);
         return true;
     }
     return false;
 }
Example #3
0
 protected string PreparePrefetch(string content)
 {
     string output = null;
     if (!(string.IsNullOrEmpty(Request.Url.Query)) || (Request.Headers["X-Cot-Manifest-Request"] == "true"))
     	return output;
     var token = ApplicationServices.TryGetJsonProperty(ApplicationServices.Current.DefaultSettings, "ui.history.dataView");
     var supportGridPrefetch = ((token != null) && !(Regex.IsMatch(((string)(token)), "\\b(search|sort|group|filter)\\b")));
     var prefetches = new List<string>();
     var prefetch = false;
     var dataViews = new List<Tuple<string, AttributeDictionary>>();
     foreach (Match m in Regex.Matches(content, "<div\\s+(id=\"(?\'Id\'\\w+)\")\\s+(?\'Props\'data-controller.*?)>"))
     	dataViews.Add(new Tuple<string, AttributeDictionary>(m.Groups["Id"].Value, new AttributeDictionary(m.Groups["Props"].Value)));
     if (dataViews.Count == 1)
     	prefetch = true;
     else
     {
         // LEGACY MASTER DETAIL PAGE SUPPORT
         // 
         //                      
         // 1. convert text of containers into single container with single dataview referring to virtual dashboard controller
         //                      
         // <div data-flow="row">
         //   <div id="view1" data-controller="Dashboards" data-view="form1" data-show-action-buttons="none"></div> 
         //
         // </div>
         //
         // 2. produce response for this controller.
         // a. standalone data views become data view fields of the virtual controller
         // b. the layout of the page is optionally converted into form1 layout of the virtual controller
         // c. render json response of virtual controller with layout in it
         //                    
     }
     if (prefetch)
     	for (var i = 0; (i < dataViews.Count); i++)
         {
             var dataView = dataViews[i];
             var dataViewId = dataView.Item1;
             var attrs = dataView.Item2;
             foreach (var p in UnsupportedDataViewProperties)
             	if (attrs.ContainsKey(p))
                 	return output;
             var controllerName = attrs["data-controller"];
             string viewId = null;
             string tags = null;
             attrs.TryGetValue("data-tags", out tags);
             var c = Controller.CreateConfigurationInstance(GetType(), controllerName);
             if (!(attrs.TryGetValue("data-view", out viewId)))
             	viewId = ((string)(c.Evaluate("string(/c:dataController/c:views/c:view[1]/@id)")));
             var viewNav = c.SelectSingleNode("/c:dataController/c:views/c:view[@id=\'{0}\']", viewId);
             if (!Context.User.Identity.IsAuthenticated && !((viewNav.GetAttribute("access", string.Empty) == "Public")))
             	return output;
             string roles = null;
             if (attrs.TryGetValue("data-roles", out roles) && !(new ControllerUtilities().UserIsInRole(roles.Split(','))))
             	return output;
             tags = (tags 
                         + (" " + viewNav.GetAttribute("tags", string.Empty)));
             var isForm = (viewNav.GetAttribute("type", string.Empty) == "Form");
             if (isForm)
             	_summaryDisabled = true;
             if (!(Regex.IsMatch(tags, "\\bprefetch-data-none\\b")) && (supportGridPrefetch || isForm))
             {
                 var request = new PageRequest(-1, 30, null, null);
                 request.Controller = controllerName;
                 request.View = viewId;
                 request.Tag = tags;
                 request.ContextKey = dataViewId;
                 request.SupportsCaching = true;
                 if (attrs.ContainsKey("data-search-on-start"))
                 	request.DoesNotRequireData = true;
                 var response = ControllerFactory.CreateDataController().GetPage(request.Controller, request.View, request);
                 var result = string.Format("{{ \"d\": {0} }}", ApplicationServices.CompressViewPageJsonOutput(JsonConvert.SerializeObject(response)));
                 prefetches.Add(string.Format("<script type=\"application/json\" id=\"_{0}_prefetch\">{1}</script>", dataViewId, Regex.Replace(result, "(<(/?\\s*script)(\\s|>))", "]_[$2$3]^[", RegexOptions.IgnoreCase)));
                 if (isForm)
                 	foreach (var field in response.Fields)
                     	if (string.IsNullOrEmpty(field.DataViewFilterFields) && (field.Type == "DataView"))
                         {
                             var fieldAttr = new AttributeDictionary(string.Empty);
                             fieldAttr.Add("data-controller", field.DataViewController);
                             fieldAttr.Add("data-view", field.DataViewId);
                             fieldAttr.Add("data-tags", field.Tag);
                             if (field.DataViewSearchOnStart)
                             	fieldAttr.Add("data-search-on-start", "true");
                             dataViews.Add(new Tuple<string, AttributeDictionary>(string.Format("{0}_{1}", dataViewId, field.Name), fieldAttr));
                         }
             }
         }
     if (prefetches.Count > 0)
     	output = string.Join(string.Empty, prefetches);
     return output;
 }
Example #4
0
 protected virtual void InitializeSiteMaster()
 {
     _isTouchUI = ApplicationServices.IsTouchClient;
     var html = string.Empty;
     var siteMasterPath = "~/site.desktop.html";
     if (_isTouchUI)
     	siteMasterPath = "~/site.touch.html";
     siteMasterPath = Server.MapPath(siteMasterPath);
     if (!(File.Exists(siteMasterPath)))
     	siteMasterPath = Server.MapPath("~/site.html");
     if (File.Exists(siteMasterPath))
     	html = File.ReadAllText(siteMasterPath);
     else
     	throw new Exception("File site.html has not been found.");
     var htmlMatch = Regex.Match(html, "<html(?\'HtmlAttr\'[\\S\\s]*?)>\\s*<head(?\'HeadAttr\'[\\S\\s]*?)>\\s*(?\'Head\'[\\S\\s]*?)\\s*<" +
             "/head>\\s*<body(?\'BodyAttr\'[\\S\\s]*?)>\\s*(?\'Body\'[\\S\\s]*?)\\s*</body>\\s*</html>\\s*");
     if (!htmlMatch.Success)
     	throw new Exception("File site.html must contain \'head\' and \'body\' elements.");
     // instructions
     Controls.Add(new LiteralControl(html.Substring(0, htmlMatch.Index)));
     // html
     Controls.Add(new LiteralControl(string.Format("<html{0} xml:lang={1} lang=\"{1}\">\r\n", htmlMatch.Groups["HtmlAttr"].Value, CultureInfo.CurrentUICulture.IetfLanguageTag)));
     // head
     Controls.Add(new HtmlHead());
     if (_isTouchUI)
     	Header.Controls.Add(new LiteralControl("<meta charset=\"utf-8\">\r\n"));
     else
     	Header.Controls.Add(new LiteralControl("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n"));
     var headHtml = Regex.Replace(htmlMatch.Groups["Head"].Value, "\\s*<title([\\s\\S+]*?title>)\\s*", string.Empty);
     Header.Controls.Add(new LiteralControl(headHtml));
     _headContent = new LiteralContainer();
     Header.Controls.Add(_headContent);
     // body
     _bodyTag = new LiteralControl();
     _bodyAttributes = new AttributeDictionary(htmlMatch.Groups["BodyAttr"].Value);
     Controls.Add(_bodyTag);
     var themePath = Server.MapPath("~/App_Themes/MyCompany");
     if (Directory.Exists(themePath))
     	foreach (var stylesheetFileName in Directory.GetFiles(themePath, "*.css"))
         {
             var fileName = Path.GetFileName(stylesheetFileName);
             if (!(fileName.Equals("_Theme_Grapello.css")))
             {
                 var link = new HtmlLink();
                 link.Href = ("~/App_Themes/MyCompany/" + fileName);
                 link.Attributes["type"] = "text/css";
                 link.Attributes["rel"] = "stylesheet";
                 Header.Controls.Add(link);
             }
         }
     // form
     Controls.Add(new HtmlForm());
     Form.ID = "aspnetForm";
     // ScriptManager
     var sm = new ScriptManager();
     sm.ID = "sm";
     sm.AjaxFrameworkMode = AjaxFrameworkMode.Disabled;
     if (AquariumExtenderBase.EnableCombinedScript)
     	sm.EnableScriptLocalization = false;
     sm.ScriptMode = ScriptMode.Release;
     Form.Controls.Add(sm);
     // SiteMapDataSource
     var siteMapDataSource1 = new SiteMapDataSource();
     siteMapDataSource1.ID = "SiteMapDataSource1";
     siteMapDataSource1.ShowStartingNode = false;
     Form.Controls.Add(siteMapDataSource1);
     // parse and initialize placeholders
     var body = htmlMatch.Groups["Body"].Value;
     var placeholderMatch = Regex.Match(body, "<div\\s+data-role\\s*=\\s*\"placeholder\"(?\'Attributes\'[\\s\\S]+?)>\\s*(?\'DefaultContent\'" +
             "[\\s\\S]*?)\\s*</div>");
     var startPos = 0;
     while (placeholderMatch.Success)
     {
         var attributes = new AttributeDictionary(placeholderMatch.Groups["Attributes"].Value);
         // create placeholder content
         Form.Controls.Add(new LiteralControl(body.Substring(startPos, (placeholderMatch.Index - startPos))));
         var placeholder = attributes["data-placeholder"];
         var defaultContent = placeholderMatch.Groups["DefaultContent"].Value;
         if (!(CreatePlaceholder(Form.Controls, placeholder, defaultContent, attributes)))
         {
             var placeholderControl = new LiteralContainer();
             placeholderControl.Text = defaultContent;
             Form.Controls.Add(placeholderControl);
             if (placeholder == "page-header")
             	_pageHeaderContent = placeholderControl;
             if (placeholder == "page-title")
             	_pageTitleContent = placeholderControl;
             if (placeholder == "page-side-bar")
             	_pageSideBarContent = placeholderControl;
             if (placeholder == "page-content")
             	_pageContent = placeholderControl;
             if (placeholder == "page-footer")
             	_pageFooterContent = placeholderControl;
         }
         startPos = (placeholderMatch.Index + placeholderMatch.Length);
         placeholderMatch = placeholderMatch.NextMatch();
     }
     if (startPos < body.Length)
     	Form.Controls.Add(new LiteralControl(body.Substring(startPos)));
     // end body
     Controls.Add(new LiteralControl("\r\n</body>\r\n"));
     // end html
     Controls.Add(new LiteralControl("\r\n</html>\r\n"));
 }
Example #5
0
 protected virtual bool CreatePlaceholder(ControlCollection container, string placeholder, string defaultContent, AttributeDictionary attributes)
 {
     if (placeholder == "membership-bar")
     {
     }
     if (placeholder == "menu-bar")
     {
         HtmlGenericControl menuDiv = new HtmlGenericControl();
         menuDiv.TagName             = "div";
         menuDiv.ID                  = "PageMenuBar";
         menuDiv.Attributes["class"] = "PageMenuBar";
         container.Add(menuDiv);
         MenuExtender menu = new MenuExtender();
         menu.ID                = "Menu1";
         menu.DataSourceID      = "SiteMapDataSource1";
         menu.TargetControlID   = menuDiv.ID;
         menu.HoverStyle        = ((MenuHoverStyle)(TypeDescriptor.GetConverter(typeof(MenuHoverStyle)).ConvertFromString(attributes.ValueOf("data-hover-style", "Auto"))));
         menu.PopupPosition     = ((MenuPopupPosition)(TypeDescriptor.GetConverter(typeof(MenuPopupPosition)).ConvertFromString(attributes.ValueOf("data-popup-position", "Left"))));
         menu.ShowSiteActions   = (attributes["data-show-site-actions"] == "true");
         menu.PresentationStyle = ((MenuPresentationStyle)(TypeDescriptor.GetConverter(typeof(MenuPresentationStyle)).ConvertFromString(attributes.ValueOf("data-presentation-style", "MultiLevel"))));
         container.Add(menu);
         return(true);
     }
     if (placeholder == "site-map-path")
     {
         SiteMapPath siteMapPath1 = new SiteMapPath();
         siteMapPath1.ID       = "SiteMapPath1";
         siteMapPath1.CssClass = "SiteMapPath";
         siteMapPath1.PathSeparatorStyle.CssClass = "PathSeparator";
         siteMapPath1.CurrentNodeStyle.CssClass   = "CurrentNode";
         siteMapPath1.NodeStyle.CssClass          = "Node";
         siteMapPath1.RootNodeStyle.CssClass      = "RootNode";
         container.Add(siteMapPath1);
         return(true);
     }
     return(false);
 }