Ejemplo n.º 1
0
 protected PageRequest lostPageRequest()
 {
     //if session is lost, reload the page
     PageRequest response = new PageRequest();
     response.js = "R.lostSession();";
     return response;
 }
Ejemplo n.º 2
0
Archivo: Page.cs Proyecto: nhtera/Home
        public void LoadPage(string pageFile, int ptype, int pid, string pname, bool saveInterface = true, bool noloadLayers = false, bool keepPreviousPageLoaded = false, XmlDocument pageLoadedXml = null)
        {
            string myJs = "";

            if (pid <= 0) { return; }
            if (string.IsNullOrEmpty(pname)) { return; }

            if (pageUsersOnly == 1 & R.User.userId > 1 & ptype == 1)
            {
                //check to see if this user is a user of the web site
                if (R.User.Website(websiteId).getWebsiteSecurityItem("dashboard/pages", 4) == false)
                {
                    //user doesn't have permission
                    LoadPage("Access Denied");
                    return;
                }
            }
            else if (pageUsersOnly == 1 & ptype == 1)
            {
                //user not logged in
                LoadPage("Access Denied");
                return;
            }

            if (ptype == 2)
            {
                if (!string.IsNullOrEmpty(R.Request.Query["noload"]))
                {
                    string[] nl = R.Request.Query["noload"].ToLower().Split('\"');
                    for (int x = 0; x <= nl.Length - 1; x++)
                    {
                        //don't load this content layer, since the querystring says not to
                        if (nl[x] == pname.ToLower())
                            return;
                    }
                }
            }

            //check to see if page is already loaded
            if ((Layers == null) == false)
            {
                for (var x = 0; x <= Layers.Count - 1; x++)
                {
                    if (Layers[x].Id == pid)
                    {
                        return; //page already loaded
                    }
                }
            }

            if (ptype == 1 & R.isWebService == true)
            {
                //setup page request for web service
                PageRequest = new PageRequest();
            }

            //////////////////////////////////////////////////////
            //update  page settings
            string pFolder = pageFile.Replace("page.xml", "");
            if (ptype == 1)
            {
                string pt = R.Util.Str.GetPageTitle(pageTitle).Replace("-", " ");
                string wt = R.Util.Str.GetWebsiteTitle(pageTitle);
                pageId = pid;
                pageFolder = pFolder;
                pageTitle = wt + " - " + pt;
                Url.path = pt.Trim().ToLower();
                myJs += "R.page.title = \"" + pt.ToLower() + "\"; R.page.id=" + pageId + ";";
                myJs += "R.website.title = \"" + wt.ToLower() + "\"; R.website.id=" + websiteId + ";";
                myJs += "$('#divPageLoad').hide();_docLoaded=true;";
                //hide page loading div
                string newTitle = pageTitle;
                if (isEditable == true)
                {
                    newTitle = pageEditorTitle + pageTitle + pageEditorTitleEnd;
                }
                if (R.isWebService == true)
                {
                    PageRequest.pageTitle = pageTitle;
                }
                else
                {
                    R.App.scaffold.Data["title"] = pageTitle;
                }

            }

            //////////////////////////////////////////////////////
            //initialize page editor (rare occurance)
            if (isEditable == true)
            {
                if (isEditorLoaded == false)
                {
                    if (R.isWebService == true)
                    {
                        Editor editor = new Editor(R);
                        string[] result = editor.LoadEditor();
                        PageRequest.editor = result[0];
                        PageRequest.js += result[1];
                    }
                }
            }

            //////////////////////////////////////////////////////
            //Load XML page
            XmlDocument myXmlPage = LoadPageXml(pid, pFolder);

            if (myXmlPage == null)
            {
                //page.xml does not exist, wipe the page clean
                if (ptype == 1)
                    CleanLayers(null, pid);
            }

            //////////////////////////////////////////////////////
            //load custom CSS onto the page
            if (ptype == 1)
            {
                if (!string.IsNullOrEmpty(googleWebPropertyId))
                {
                    //GoogleLogPageRequest()
                }
                string myCSS = "";
                XmlNode nodeCSS = myXmlPage.SelectSingleNode("//CSS");
                if ((nodeCSS == null) == false)
                {
                    myCSS = "<style type=\"text/css\">" + nodeCSS.FirstChild.InnerText + "</style>";

                    if (R.isWebService == true)
                    {
                        PageRequest.css += myCSS;
                    }
                    else
                    {
                        R.App.scaffold.Data["custom-css"] = myCSS;
                    }

                }

                //reset undo redo engine
                if (isEditable == true)
                {
                    //myJs &= "undoRedo = [];AddUndoRedoAction('','all');"
                    //ClearUndoRedo()
                }

                RegisterJS("layersreset", "R.layers.cache = [];");
                RegisterJS("layer" + pid, "R.layers.add(" + pid + ",'" + pageTitle.Split(new char[] { '-', ' ', '\"' })[1] + "'," + ptype + ");");
            }

            //////////////////////////////////////////////////////
            //add page to the list of layers
            if (saveInterface == true)
            {
                string newtitle = pageTitle.Split(new char[] { '-', ' ', '\"' })[1];
                if (string.IsNullOrEmpty(pname) & ptype == 2 & isEditable == true)
                {
                    //get the lost layer name
                    newtitle = R.Sql.ExecuteScalar("SELECT title from pageinterfaces WHERE interfaceid=" + pid).ToString().Split(new char[] { '-', ' ', '\"' })[1];
                }
                else if (!string.IsNullOrEmpty(pname) & ptype == 2)
                {
                    newtitle = pname;
                }
                Layer newItem = new Layer();
                newItem.Id = pid;
                newItem.Title = newtitle;
                if ((Layers == null) == true) { Layers = new List<Layer>(); }
                Layers.Add(newItem);
            }

            ////////////////////////////////////////////////////
            //Load Layers from page.xml
            XmlNodeList myLayers = myXmlPage.SelectNodes("//layer");
            if (noloadLayers == false)
            {
                int intId = 0;
                bool doesExist = false;
                string newtitle = "";
                if (myLayers.Count > 0)
                {
                    for (int i = 0; i <= myLayers.Count - 1; i++)
                    {
                        intId = int.Parse(myLayers[i].Attributes["id"].Value);
                        doesExist = false;
                        if (Layers.Count > 0)
                        {
                            for (int x = 0; x <= Layers.Count - 1; x++)
                            {
                                if (intId == Layers[x].Id)
                                    doesExist = true;
                            }
                        }
                        newtitle = R.Util.Str.Capitalize(myLayers[i].Attributes["name"].Value.Replace("-", " "));
                        RegisterJS("layer" + intId, "R.layers.add(" + intId + ",'" + newtitle + "',2);");
                        if (doesExist == false)
                        {
                            LoadLayer(intId, newtitle);
                        }
                    }
                }
            }

            ////////////////////////////////////////////////////
            //Next, Load Components for each  Panel from page.xml
            XmlNodeList myPanels = myXmlPage.SelectNodes("//panel");
            if (myPanels.Count >= 0)
            {
                //Load components for this page
                for (int i = 0; i <= myPanels.Count - 1; i++)
                {
                    LoadPageComponents(myPanels[i], i + 1, myXmlPage, pageFile, ptype, 1, pid);
                }
            }
            else if (myPanels.Count >= 0)
            {
                //refresh components already loaded on this page
                //RefreshComponents(pid);
            }

            if (ptype == 2)
            {
                //add interface to the log
                //R.Log.AddInterface();
            }

            ////////////////////////////////////////////////////
            //Remove Unused Layers
            //if any components are loaded from an interface that isn't a part of this page,
            //remove those components immediately, and clean up the interface array
            if (ptype == 1)
            {
                CleanLayers(myLayers, pid);
                isPageLoaded = true;
                pageLoaded = true;
                //inform any components that were NOT just loaded
                GetAllComponents();
                if (Components.Count >= 0)
                {
                    for (int x = 0; x <= Components.Count - 1; x++)
                    {
                        if ((Components[x] == null) == false)
                        {
                            if (Components[x].justLoaded == false)
                            {
                                Components[x].LoadedNewPage();
                            }
                        }
                    }
                }
            }

            //////////////////////////////////////////////////////
            //update the  Editor
            if (ptype == 1 & R.isWebService == false)
            {
                if (string.IsNullOrEmpty(Url.hash))
                {
                    string eh = Url.path.Replace(" ", "-").ToLower();
                    if (eh == "home")
                        eh = "";
                    if (!string.IsNullOrEmpty(Url.hash))
                        myJs += "R.hash.last = '" + eh + "';";
                }
                else
                {
                    if (!string.IsNullOrEmpty(Url.hash))
                        myJs += "R.hash.last = '" + Url.hash.Replace(" ", "-").ToLower() + "';";
                }
                myJs += "R.editor.selectedLayerId = '" + pageId + "', R.page.useAjax=" + useAJAX.ToString().ToLower();
            }

            if (!string.IsNullOrEmpty(myJs))
            {
                RegisterJS("loadpage" + pageId, myJs);
            }

            if (ptype == 1)
            {
                //execute Page Load Complete event for all components
                GetAllComponents();
                foreach (Component c in Components)
                {
                    if ((c == null) == false)
                        c.PageLoadComplete();
                }
            }
        }