Ejemplo n.º 1
0
        private void HandleDocumentMoveOrCopy()
        {
            if (helper.Request("copyTo") != "" && helper.Request("id") != "")
            {
                // Check if the current node is allowed at new position
                var nodeAllowed = false;

                var currentNode = new cms.businesslogic.Content(int.Parse(helper.Request("id")));

				var newNode = new cms.businesslogic.Content(int.Parse(helper.Request("copyTo")));

                // Check on contenttypes
                if (int.Parse(helper.Request("copyTo")) == -1)
                {
                    nodeAllowed = true;
                }
                else
                {
                    if (newNode.ContentType.AllowedChildContentTypeIDs.Where(c => c == currentNode.ContentType.Id).Any())
                    {
                        nodeAllowed = true;
                    }

                    if (nodeAllowed == false)
                    {
                        feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", base.getUser());
                        feedback.type = uicontrols.Feedback.feedbacktype.error;
                    }
                    else
                    {
                        // Check on paths
                        if ((string.Format(",{0},", newNode.Path)).IndexOf(string.Format(",{0},", currentNode.Id)) > -1)
                        {
                            nodeAllowed = false;
                            feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", base.getUser());
                            feedback.type = uicontrols.Feedback.feedbacktype.error;
                        }
                    }
                }

                if (nodeAllowed)
                {
                    pane_form.Visible = false;
                    pane_form_notice.Visible = false;
                    panel_buttons.Visible = false;

                    var newNodeCaption = newNode.Id == -1 ? ui.Text(CurrentApp) : newNode.Text;

                    string[] nodes = { currentNode.Text, newNodeCaption };

                    if (Request["mode"] == "cut")
                    {
                        if (CurrentApp == "content")
                        {
                            //PPH changed this to document instead of cmsNode to handle republishing.
                            var documentId = int.Parse(helper.Request("id"));
                            var document = new Document(documentId);
                            document.Move(int.Parse(helper.Request("copyTo")));
                            library.RefreshContent();
                        }
                        else
                        {
                            var media = new Media(int.Parse(UmbracoContext.Current.Request["id"]));
                            media.Move(int.Parse(UmbracoContext.Current.Request["copyTo"]));
                            media = new Media(int.Parse(UmbracoContext.Current.Request["id"]));
                            media.XmlGenerate(new XmlDocument());
                            library.ClearLibraryCacheForMedia(media.Id);
                        }

                        feedback.Text = ui.Text("moveOrCopy", "moveDone", nodes, getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>";
                        feedback.type = uicontrols.Feedback.feedbacktype.success;

                        // refresh tree
                        ClientTools.MoveNode(currentNode.Id.ToString(), newNode.Path);
                    }
                    else
                    {
                        var document = new Document(int.Parse(helper.Request("id")));
                        document.Copy(int.Parse(helper.Request("copyTo")), this.getUser(), RelateDocuments.Checked);
                        feedback.Text = ui.Text("moveOrCopy", "copyDone", nodes, base.getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>";
                        feedback.type = uicontrols.Feedback.feedbacktype.success;
                        ClientTools.CopyNode(currentNode.Id.ToString(), newNode.Path);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void HandleDocumentMoveOrCopy() 
		{
			if (helper.Request("copyTo") != "" && helper.Request("id") != "") 
			{
				// Check if the current node is allowed at new position
				bool nodeAllowed = false;

				cms.businesslogic.Content currentNode = new cms.businesslogic.Content(int.Parse(helper.Request("id")));
                int oldParent = -1;
                if (currentNode.Level > 1)
                   oldParent = currentNode.Parent.Id;
				cms.businesslogic.Content newNode = new cms.businesslogic.Content(int.Parse(helper.Request("copyTo")));

				// Check on contenttypes
				if (int.Parse(helper.Request("copyTo")) == -1)
					nodeAllowed = true;
				else 
				{
					foreach (int i in newNode.ContentType.AllowedChildContentTypeIDs.ToList())
						if (i == currentNode.ContentType.Id) 
						{
							nodeAllowed = true;
							break;
						}
                    if (!nodeAllowed) {
                        feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", base.getUser());
                        feedback.type = umbraco.uicontrols.Feedback.feedbacktype.error;
                    } else {
                        // Check on paths
                        if (((string)("," + newNode.Path + ",")).IndexOf("," + currentNode.Id + ",") > -1) {
                            nodeAllowed = false;
                            feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", base.getUser());
                            feedback.type = umbraco.uicontrols.Feedback.feedbacktype.error;
                        }
                    }
				}


				if (nodeAllowed) 
				{
                    pane_form.Visible = false;
                    pane_form_notice.Visible = false;
                    panel_buttons.Visible = false;

                    string newNodeCaption = newNode.Id == -1 ? ui.Text(helper.Request("app")) : newNode.Text;

                    string[] nodes = {currentNode.Text, newNodeCaption };

                    if (UmbracoContext.Current.Request["mode"] == "cut")
                    {
                        if (UmbracoContext.Current.Request["app"] == "content")
                        {
                            //PPH changed this to document instead of cmsNode to handle republishing.
                            cms.businesslogic.web.Document d = new umbraco.cms.businesslogic.web.Document(int.Parse(helper.Request("id")));
                            d.Move(int.Parse(helper.Request("copyTo")));
                            if (d.Published)
                            {
                                d.Publish(new umbraco.BusinessLogic.User(0));
                                //using library.publish to support load balancing.
                                //umbraco.library.PublishSingleNode(d.Id);
                                umbraco.library.UpdateDocumentCache(d.Id);

                                //PPH added handling of load balanced moving of multiple nodes...
                                if (d.HasChildren)
                                {
                                    handleChildNodes(d);
                                }

                                //Using the general Refresh content method instead as it supports load balancing. 
                                //we only need to do this if the node is actually published.
                                library.RefreshContent();
                            }
                            d.Save(); //stub to save stuff to the db.
                        }
                        else
                        {
                            Media m = new Media(int.Parse(UmbracoContext.Current.Request["id"]));
                            m.Move(int.Parse(UmbracoContext.Current.Request["copyTo"]));
                            m.XmlGenerate(new XmlDocument());
                            library.ClearLibraryCacheForMedia(m.Id);
                        }                                 

                        feedback.Text = ui.Text("moveOrCopy", "moveDone", nodes, base.getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>";
                        feedback.type = umbraco.uicontrols.Feedback.feedbacktype.success;

                        // refresh tree
						ClientTools.MoveNode(currentNode.Id.ToString(), newNode.Path);

                    } 
					else 
					{
						cms.businesslogic.web.Document d = new cms.businesslogic.web.Document(int.Parse(helper.Request("id")));
						d.Copy(int.Parse(helper.Request("copyTo")), this.getUser(), RelateDocuments.Checked);
						feedback.Text = ui.Text("moveOrCopy", "copyDone", nodes, base.getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>";
                        feedback.type = umbraco.uicontrols.Feedback.feedbacktype.success;
						ClientTools.CopyNode(currentNode.Id.ToString(), newNode.Path);
                    }
				} 
			}
		}