- Tags: Some more admin, renaming/deleting/bulk delete ...

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042090
This commit is contained in:
suhacan
2009-11-24 20:53:21 +00:00
parent f989285dd2
commit 40d51e7b22
6 changed files with 79 additions and 1 deletions

View File

@@ -99,6 +99,39 @@ namespace Orchard.Tags.Controllers {
}
}
public ActionResult Edit(int id) {
try {
Tag tag = _tagService.GetTag(id);
var viewModel = new TagsAdminEditViewModel {
Id = tag.Id,
TagName = tag.TagName,
};
return View(viewModel);
}
catch (Exception exception) {
_notifier.Error(T("Editing tag failed: " + exception.Message));
return Index();
}
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(FormCollection input) {
var viewModel = new TagsAdminEditViewModel();
try {
UpdateModel(viewModel, input.ToValueProvider());
if (!_authorizer.Authorize(Permissions.RenameTag, T("Couldn't edit tag")))
return new HttpUnauthorizedResult();
_tagService.UpdateTag(viewModel.Id, viewModel.TagName);
return RedirectToAction("Index");
}
catch (Exception exception) {
_notifier.Error(T("Editing Comment failed: " + exception.Message));
return View(viewModel);
}
}
private static TagEntry CreateTagEntry(Tag tag) {
return new TagEntry {
Tag = tag,

View File

@@ -71,6 +71,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\TagService.cs" />
<Compile Include="ViewModels\TagsAdminCreateViewModel.cs" />
<Compile Include="ViewModels\TagsAdminEditViewModel.cs" />
<Compile Include="ViewModels\TagsAdminIndexViewModel.cs" />
<Compile Include="ViewModels\TagsCreateViewModel.cs" />
<Compile Include="ViewModels\TagsIndexViewModel.cs" />
@@ -78,6 +79,7 @@
<ItemGroup>
<Content Include="Package.txt" />
<Content Include="Views\Admin\Create.aspx" />
<Content Include="Views\Admin\Edit.aspx" />
<Content Include="Views\Admin\Index.aspx" />
<Content Include="Views\Models\DisplayTemplates\HasTags.ascx" />
<Content Include="Views\Models\EditorTemplates\TagSettingsRecord.ascx" />

View File

@@ -6,6 +6,7 @@ namespace Orchard.Tags {
public static readonly Permission CreateTag = new Permission { Description = "Creating a Tag", Name = "CreateTag" };
public static readonly Permission ApplyTag = new Permission { Description = "Applying a Tag", Name = "ApplyTag" };
public static readonly Permission DeleteTag = new Permission { Description = "Deleting a Tag", Name = "DeleteTag" };
public static readonly Permission RenameTag = new Permission { Description = "Renaming a Tag", Name = "RenameTag" };
public string PackageName {
get {
@@ -18,6 +19,7 @@ namespace Orchard.Tags {
CreateTag,
ApplyTag,
DeleteTag,
RenameTag,
};
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.Data;
using Orchard.Localization;
@@ -14,6 +15,7 @@ namespace Orchard.Tags.Services {
Tag GetTagByName(string tagName);
void CreateTag(string tagName);
void DeleteTag(int id);
void UpdateTag(int id, string tagName);
void TagContentItem(int contentItemId, string tagName);
void UpdateTagsForContentItem(int contentItemId, IEnumerable<int> tagsForContentItem);
}
@@ -69,6 +71,15 @@ namespace Orchard.Tags.Services {
}
}
public void UpdateTag(int id, string tagName) {
Tag tag = _tagRepository.Get(id);
if (String.IsNullOrEmpty(tagName)) {
_notifier.Warning(T("Couldn't rename tag: name was empty"));
return;
}
tag.TagName = tagName;
}
public void TagContentItem(int contentItemId, string tagName) {
Tag tag = GetTagByName(tagName);
TagsContentItems tagsContentItems = new TagsContentItems { ContentItemId = contentItemId, TagId = tag.Id };

View File

@@ -0,0 +1,8 @@
using Orchard.Mvc.ViewModels;
namespace Orchard.Tags.ViewModels {
public class TagsAdminEditViewModel : AdminViewModel {
public int Id { get; set; }
public string TagName { get; set; }
}
}

View File

@@ -0,0 +1,22 @@
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<TagsAdminEditViewModel>" %>
<%@ Import Namespace="Orchard.Tags.ViewModels"%>
<%@ Import Namespace="Orchard.Mvc.Html" %>
<% Html.Include("Header"); %>
<% Html.BeginForm(); %>
<%= Html.ValidationSummary() %>
<div class="yui-g">
<h2 class="separator">Edit a Tag</h2>
<h3>Information</h3>
<ol>
<li>
<label for="Name">Name:</label>
<input id="Id" name="Id" type="hidden" value="<%=Model.Id %>" />
<input id="TagName" class="inputText inputTextLarge" name="TagName" type="text" value="<%= Model.TagName %>" />
</li>
<li>
<input type="submit" class="button" value="Save" />
</li>
</ol>
</div>
<% Html.EndForm(); %>
<% Html.Include("Footer"); %>