Edit model for the content record.
示例#1
0
        /// <summary>
        /// Gets the edit model for the content with the given id.
        /// </summary>
        /// <param name="id">The content id</param>
        /// <returns>The model</returns>
        public static EditModel GetById(Guid id)
        {
            EditModel em = new EditModel() ;
            em.Content = Piranha.Models.Content.GetSingle(id) ;

            return em ;
        }
示例#2
0
 public ActionResult Edit(bool draft, EditModel m)
 {
     if (m.SaveAll(draft)) {
         ViewBag.Folder = m.Content.IsFolder ;
         if (m.Content.IsImage) {
             ViewBag.Title = Piranha.Resources.Content.EditTitleExistingImage ;
             if (draft)
                 SuccessMessage(Piranha.Resources.Content.MessageImageSaved, true) ;
             else SuccessMessage(Piranha.Resources.Content.MessageImagePublished, true) ;
         } else if (m.Content.IsFolder) {
             ViewBag.Title = Piranha.Resources.Content.EditTitleExistingFolder ;
             if (draft)
                 SuccessMessage(Piranha.Resources.Content.MessageFolderSaved, true) ;
             else SuccessMessage(Piranha.Resources.Content.MessageFolderPublished, true) ;
         } else {
             ViewBag.Title = Piranha.Resources.Content.EditTitleExistingDocument ;
             if (draft)
                 SuccessMessage(Piranha.Resources.Content.MessageDocumentSaved, true) ;
             else SuccessMessage(Piranha.Resources.Content.MessageDocumentPublished, true) ;
         }
         // ModelState.Clear() ;
         // m.Refresh() ;
         // return View("Edit", m) ;
         return RedirectToAction("edit", new { id = m.Content.Id, returl = ViewBag.ReturnUrl }) ;
     } else {
         ViewBag.Title = Piranha.Resources.Content.EditTitleNew ;
         ErrorMessage(Piranha.Resources.Content.MessageNotSaved) ;
         return View("Edit", m) ;
     }
 }
示例#3
0
            /// <summary>
            /// Extend the default binder so that html strings can be fetched from the post.
            /// </summary>
            /// <param name="controllerContext">Controller context</param>
            /// <param name="bindingContext">Binding context</param>
            /// <returns>The page edit model</returns>
            public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
            {
                EditModel model = (EditModel)base.BindModel(controllerContext, bindingContext);

                // Allow HtmlString extensions
                model.Extensions.Each((i, m) => {
                    if (m.Body is HtmlString)
                    {
                        bindingContext.ModelState.Remove("Extensions[" + i + "].Body");
                        m.Body = ExtensionManager.Current.CreateInstance(m.Type,
                                                                         bindingContext.ValueProvider.GetUnvalidatedValue("Extensions[" + i + "].Body").AttemptedValue);
                    }
                });
                return(model);
            }
示例#4
0
 public ActionResult Edit(EditModel m)
 {
     if (m.SaveAll()) {
         if (m.Content.IsImage) {
             ViewBag.Title = "Ändra bild" ;
             ViewBag.Message = "Din bild har sparats." ;
         } else {
             ViewBag.Title = "Ändra dokument" ;
             ViewBag.Message = "Ditt dokument har sparats." ;
         }
         return View("Edit", m) ;
     } else {
         ViewBag.Title = "Lägg till bild eller dokument" ;
         ViewBag.Message = "Din bild eller ditt dokument kunde inte sparas." ;
         return View("Edit", m) ;
     }
 }
示例#5
0
        /// <summary>
        /// Gets the edit model for the content with the given id.
        /// </summary>
        /// <param name="id">The content id</param>
        /// <returns>The model</returns>
        public static EditModel GetById(Guid id)
        {
            EditModel em = new EditModel();

            em.Content = Piranha.Models.Content.GetSingle(id, true);
            Relation.GetFieldsByDataId("relation_related_id", id, false).ForEach(r => em.ContentCategories.Add(r.RelatedId));
            em.Categories = new MultiSelectList(Category.GetFields("category_id, category_name",
                                                                   new Params()
            {
                OrderBy = "category_name"
            }), "Id", "Name", em.ContentCategories);
            var folders = Content.GetFields("content_id, content_name", "content_folder=1 AND content_draft=1 AND content_id != @0", id, new Params()
            {
                OrderBy = "content_name"
            });

            folders.Insert(0, new Content());
            em.Extensions = em.Content.GetExtensions(true);

            return(em);
        }
示例#6
0
 public ActionResult Edit(EditModel m)
 {
     if (m.SaveAll()) {
         ViewBag.Folder = m.Content.IsFolder ;
         if (m.Content.IsImage) {
             ViewBag.Title = Piranha.Resources.Content.EditTitleExistingImage ;
             SuccessMessage(Piranha.Resources.Content.MessageImageSaved) ;
         } else if (m.Content.IsFolder) {
             ViewBag.Title = Piranha.Resources.Content.EditTitleExistingFolder ;
             SuccessMessage(Piranha.Resources.Content.MessageFolderSaved) ;
         } else {
             ViewBag.Title = Piranha.Resources.Content.EditTitleExistingDocument ;
             SuccessMessage(Piranha.Resources.Content.MessageDocumentSaved) ;
         }
         ModelState.Clear() ;
         m.Refresh() ;
         return View("Edit", m) ;
     } else {
         ViewBag.Title = Piranha.Resources.Content.EditTitleNew ;
         ErrorMessage(Piranha.Resources.Content.MessageNotSaved) ;
         return View("Edit", m) ;
     }
 }
示例#7
0
		/// <summary>
		/// Gets the edit model for the content with the given id.
		/// </summary>
		/// <param name="id">The content id</param>
		/// <returns>The model</returns>
		public static EditModel GetById(Guid id) {
			EditModel em = new EditModel();
			em.Content = Piranha.Models.Content.GetSingle(id, true);
			if (!em.Content.IsFolder) {
				// Don't get permalinks for folders
				if (em.Content.PermalinkId != Guid.Empty)
					em.Permalink = Models.Permalink.GetSingle(em.Content.PermalinkId);
				else em.Content.PermalinkId = em.Permalink.Id;
			}
			Relation.GetFieldsByDataId("relation_related_id", id, false).ForEach(r => em.ContentCategories.Add(r.RelatedId));
			em.Categories = new MultiSelectList(Category.GetFields("category_id, category_name",
				new Params() { OrderBy = "category_name" }), "Id", "Name", em.ContentCategories);
			em.Extensions = em.Content.GetExtensions(true);

			return em;
		}
示例#8
0
        /// <summary>
        /// Insert or update of a media object.
        /// </summary>
        /// <param name="m">The new or existing model</param>
        /// <param name="insert">Weather to insert or update</param>
        /// <returns></returns>
        private ActionResult EditInternal(EditModel m, bool insert = false)
        {
            ViewBag.Folder = m.Content.IsFolder ;

            if (insert)
                ViewBag.Title = Piranha.Resources.Content.EditTitleNew ;
            else if (m.Content.IsImage)
                ViewBag.Title = Piranha.Resources.Content.EditTitleExistingImage ;
            else if (m.Content.IsFolder)
                ViewBag.Title = Piranha.Resources.Content.EditTitleExistingFolder ;
            else ViewBag.Title = Piranha.Resources.Content.EditTitleExistingDocument ;

            return View("Edit", m) ;
        }
示例#9
0
		/// <summary>
		/// Insert or update of a media object.
		/// </summary>
		/// <param name="m">The new or existing model</param>
		/// <param name="insert">Whether to insert or update</param>
		/// <returns></returns>
		private ActionResult EditInternal(EditModel m, bool insert = false) {
			ViewBag.Folder = m.Content.IsFolder ;

			if (insert) 
				ViewBag.Title = Piranha.Resources.Content.EditTitleNew ;
			else if (m.Content.IsImage)
				ViewBag.Title = Piranha.Resources.Content.EditTitleExistingImage ;
			else if (m.Content.IsFolder)
				ViewBag.Title = Piranha.Resources.Content.EditTitleExistingFolder ;
			else ViewBag.Title = Piranha.Resources.Content.EditTitleExistingDocument ;

			// Executes the media edit loaded hook, if registered
			if (Hooks.Manager.Media.Model.OnLoad != null)
				Hooks.Manager.Media.Model.OnLoad(this, WebPages.Manager.GetActiveMenuItem(), m) ;

			return View("Edit", m) ;
		}
示例#10
0
		public ActionResult Edit(bool draft, EditModel m) {
			try {
			    // Executes the media edit before save hook, if registered
			    if (Hooks.Manager.Media.Model.OnBeforeSave != null)
				    Hooks.Manager.Media.Model.OnBeforeSave(this, WebPages.Manager.GetActiveMenuItem(), m) ;

                if (m.SaveAll(draft)) {
                    // Executes the media edit after save hook, if registered
			        if (Hooks.Manager.Media.Model.OnAfterSave != null)
				        Hooks.Manager.Media.Model.OnAfterSave(this, WebPages.Manager.GetActiveMenuItem(), m) ;

                    ViewBag.Folder = m.Content.IsFolder ;
					if (m.Content.IsImage) {
						ViewBag.Title = Piranha.Resources.Content.EditTitleExistingImage ;
						if (draft) {
							SuccessMessage(Piranha.Resources.Content.MessageImageSaved, true) ;
						} else {
							if (m.Content.Published == m.Content.LastPublished)
								SuccessMessage(Piranha.Resources.Content.MessageImagePublished, true) ;
							else SuccessMessage(Piranha.Resources.Content.MessageUpdated, true) ;
						}
					} else if (m.Content.IsFolder) {
						ViewBag.Title = Piranha.Resources.Content.EditTitleExistingFolder ;
						if (draft) {
							SuccessMessage(Piranha.Resources.Content.MessageFolderSaved, true) ;
						} else { 
							if (m.Content.Published == m.Content.LastPublished)
								SuccessMessage(Piranha.Resources.Content.MessageFolderPublished, true) ;
							else SuccessMessage(Piranha.Resources.Content.MessageUpdated, true) ;
						}
					} else {
						ViewBag.Title = Piranha.Resources.Content.EditTitleExistingDocument ;
						if (draft) {
							SuccessMessage(Piranha.Resources.Content.MessageDocumentSaved, true) ;
						} else {
							if (m.Content.Published == m.Content.LastPublished)
								SuccessMessage(Piranha.Resources.Content.MessageDocumentPublished, true) ;
							else SuccessMessage(Piranha.Resources.Content.MessageUpdated, true) ;
						}
					}
					return RedirectToAction("edit", new { id = m.Content.Id, returl = ViewBag.ReturnUrl }) ;
				} else {
					ViewBag.Title = Piranha.Resources.Content.EditTitleNew ;
					ErrorMessage(Piranha.Resources.Content.MessageNotSaved) ;
					return View("Edit", m) ;
				}
			} catch (DuplicatePermalinkException) {
				// Manually set the duplicate error.
				ModelState.AddModelError("Permalink", @Piranha.Resources.Global.PermalinkDuplicate) ;
			} catch (Exception e) {
				ErrorMessage(e.ToString()) ;
			}
			m.Refresh() ;
			ViewBag.Folder = m.Content.IsFolder ;
			return View("Edit", m) ;
		}
示例#11
0
		/// <summary>
		/// Gets the edit model for the content with the given id.
		/// </summary>
		/// <param name="id">The content id</param>
		/// <returns>The model</returns>
		public static EditModel GetById(Guid id) {
			EditModel em = new EditModel() ;
			em.Content = Piranha.Models.Content.GetSingle(id, true) ;
			Relation.GetFieldsByDataId("relation_related_id", id, false).ForEach(r => em.ContentCategories.Add(r.RelatedId)) ;
			em.Categories = new MultiSelectList(Category.GetFields("category_id, category_name", 
				new Params() { OrderBy = "category_name" }), "Id", "Name", em.ContentCategories) ;
			var folders = Content.GetFields("content_id, content_name", "content_folder=1 AND content_draft=1 AND content_id != @0", id, new Params() { OrderBy = "content_name" }) ;
			folders.Insert(0, new Content()) ;
			em.Extensions = em.Content.GetExtensions(true) ;

			return em ;
		}
示例#12
0
		public ActionResult Edit(bool draft, EditModel m) {
			try {
				if (m.SaveAll(draft)) {
					ViewBag.Folder = m.Content.IsFolder ;
					if (m.Content.IsImage) {
						ViewBag.Title = Piranha.Resources.Content.EditTitleExistingImage ;
						if (draft) {
							SuccessMessage(Piranha.Resources.Content.MessageImageSaved, true) ;
						} else {
							if (m.Content.Published == m.Content.LastPublished)
								SuccessMessage(Piranha.Resources.Content.MessageImagePublished, true) ;
							else SuccessMessage(Piranha.Resources.Content.MessageUpdated, true) ;
						}
					} else if (m.Content.IsFolder) {
						ViewBag.Title = Piranha.Resources.Content.EditTitleExistingFolder ;
						if (draft) {
							SuccessMessage(Piranha.Resources.Content.MessageFolderSaved, true) ;
						} else { 
							if (m.Content.Published == m.Content.LastPublished)
								SuccessMessage(Piranha.Resources.Content.MessageFolderPublished, true) ;
							else SuccessMessage(Piranha.Resources.Content.MessageUpdated, true) ;
						}
					} else {
						ViewBag.Title = Piranha.Resources.Content.EditTitleExistingDocument ;
						if (draft) {
							SuccessMessage(Piranha.Resources.Content.MessageDocumentSaved, true) ;
						} else {
							if (m.Content.Published == m.Content.LastPublished)
								SuccessMessage(Piranha.Resources.Content.MessageDocumentPublished, true) ;
							else SuccessMessage(Piranha.Resources.Content.MessageUpdated, true) ;
						}
					}
					return RedirectToAction("edit", new { id = m.Content.Id, returl = ViewBag.ReturnUrl }) ;
				} else {
					ViewBag.Title = Piranha.Resources.Content.EditTitleNew ;
					ErrorMessage(Piranha.Resources.Content.MessageNotSaved) ;
					return View("Edit", m) ;
				}
			} catch (DuplicatePermalinkException) {
				// Manually set the duplicate error.
				ModelState.AddModelError("Permalink", @Piranha.Resources.Global.PermalinkDuplicate) ;
			} catch (Exception e) {
				ErrorMessage(e.ToString()) ;
			}
			m.Refresh() ;
			ViewBag.Folder = m.Content.IsFolder ;
			return View("Edit", m) ;
		}
示例#13
0
        public JsonResult Popup(PopupModel m)
        {
            if (ModelState.IsValid) {
                EditModel em = new EditModel() ;
                em.Content = m.NewContent ;
                em.FileUrl = m.FileUrl ;
                em.UploadedFile = m.UploadedFile ;

                if (em.SaveAll(false))
                    return new JsonResult() { Data = true } ;
            }
            return new JsonResult() { Data = false } ;
        }