1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-27 10:07:10 +00:00

RootDir Adds/Deletes update the database when the action occurs, no more awkward saving tactic.

This commit is contained in:
Mark McDowall 2011-04-27 08:34:53 -07:00
parent fbdc752f77
commit 3a6cf56db1
4 changed files with 62 additions and 49 deletions

View file

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using SubSonic.Repository; using SubSonic.Repository;
@ -21,9 +22,9 @@ public virtual List<RootDir> GetAll()
return _sonioRepo.All<RootDir>().ToList(); return _sonioRepo.All<RootDir>().ToList();
} }
public virtual void Add(RootDir rootDir) public virtual int Add(RootDir rootDir)
{ {
_sonioRepo.Add(rootDir); return Convert.ToInt32(_sonioRepo.Add(rootDir));
} }
public virtual void Remove(int rootDirId) public virtual void Remove(int rootDirId)

View file

@ -234,7 +234,36 @@ public ActionResult GetQualityProfileView(QualityProfile profile)
public ViewResult AddRootDir() public ViewResult AddRootDir()
{ {
return View("RootDir", new RootDir()); var rootDir = new RootDir { Path = String.Empty };
var id = _rootDirProvider.Add(rootDir);
rootDir.Id = id;
ViewData["RootDirId"] = id;
return View("RootDir", rootDir);
}
public ActionResult GetRootDirView(RootDir rootDir)
{
ViewData["RootDirId"] = rootDir.Id;
return PartialView("RootDir", rootDir);
}
public JsonResult DeleteRootDir(int rootDirId)
{
try
{
_rootDirProvider.Remove(rootDirId);
}
catch (Exception)
{
return new JsonResult { Data = "failed" };
}
return new JsonResult { Data = "ok" };
} }
public ActionResult SubMenu() public ActionResult SubMenu()
@ -292,37 +321,21 @@ public JsonResult AutoConfigureSab(string username, string password)
[HttpPost] [HttpPost]
public ActionResult SaveGeneral(SettingsModel data) public ActionResult SaveGeneral(SettingsModel data)
{ {
if (data.Directories != null && data.Directories.Count > 0) try
{ {
//If the Javascript was beaten we need to return an error
/*
* Kay.one: I can't see what its doing, all it does it dooesn't let me s.
* if (!data.Directories.Exists(d => d.Default))
return Content(SETTINGS_FAILED);*/
var currentRootDirs = _rootDirProvider.GetAll();
foreach (var currentRootDir in currentRootDirs)
{
var closureRootDir = currentRootDir;
if (!data.Directories.Exists(d => d.Id == closureRootDir.Id))
_rootDirProvider.Remove(closureRootDir.Id);
}
foreach (var dir in data.Directories) foreach (var dir in data.Directories)
{ {
if (dir.Id == 0) _rootDirProvider.Update(dir);
_rootDirProvider.Add(dir);
else
_rootDirProvider.Update(dir);
} }
}
return Content(SETTINGS_SAVED); catch (Exception ex)
{
Logger.Debug("Failed to save Root Dirs");
Logger.DebugException(ex.Message, ex);
return Content(SETTINGS_FAILED);
} }
return Content(SETTINGS_FAILED); return Content(SETTINGS_SAVED);
} }
[HttpPost] [HttpPost]

View file

@ -40,7 +40,7 @@
<div id="root-dirs"> <div id="root-dirs">
@foreach (var item in Model.Directories) @foreach (var item in Model.Directories)
{ {
Html.RenderPartial("RootDir", item); Html.RenderAction("GetRootDirView", item);
} }
</div> </div>
</div> </div>
@ -63,23 +63,21 @@
return false; return false;
}); });
$("a.deleteRow").live("click", function () { var deleteRootDirUrl = '@Url.Action("DeleteRootDir", "Settings")';
$(this).parents("div.rootDirSection:first").remove();
return false;
});
$(".defaultCheckbox").live("change", function () { function deleteRootDir(id) {
var checked = $(this).attr('checked'); sendToServer(id);
$("#div_" + id).remove();
}
if (checked) { function sendToServer(id) {
var thisOne = this; $.ajax({
$(".defaultCheckbox").attr('checked', false); type: "POST",
$(this).attr('checked', true); url: deleteRootDirUrl,
} data: jQuery.param({ rootDirId: id }),
error: function (req, status, error) {
//Don't let the user uncheck a checkbox (Like a radio button) alert("Sorry! We could not delete your Root Directory at this time. " + error);
else { }
$(this).attr('checked', true); });
} }
});
</script> </script>

View file

@ -16,11 +16,12 @@
{ {
var idClean = ViewData.TemplateInfo.HtmlFieldPrefix.Replace('[', '_').Replace(']', '_'); var idClean = ViewData.TemplateInfo.HtmlFieldPrefix.Replace('[', '_').Replace(']', '_');
<div class="rootDirSection">
<div class="rootDirSection" id="div_@(ViewData["RootDirId"])">
<fieldset> <fieldset>
<div> <div>
@Html.TextBoxFor(m => m.Path, new { @class = "root_dir_text" }) @Html.TextBoxFor(m => m.Path, new { @class = "root_dir_text" })
<a href="#" class="deleteRow"> <a href="#" class="deleteRow" onclick="deleteRootDir('@ViewData["RootDirId"]')">
<img src="../../Content/Images/X.png" alt="Delete" /></a> <img src="../../Content/Images/X.png" alt="Delete" /></a>
</div> </div>
<div> <div>