mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-26 17:47:08 +00:00
RootDir Adds/Deletes update the database when the action occurs, no more awkward saving tactic.
This commit is contained in:
parent
fbdc752f77
commit
3a6cf56db1
4 changed files with 62 additions and 49 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Repository;
|
||||
using SubSonic.Repository;
|
||||
|
@ -21,9 +22,9 @@ public virtual List<RootDir> GetAll()
|
|||
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)
|
||||
|
|
|
@ -234,7 +234,36 @@ public ActionResult GetQualityProfileView(QualityProfile profile)
|
|||
|
||||
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()
|
||||
|
@ -292,37 +321,21 @@ public JsonResult AutoConfigureSab(string username, string password)
|
|||
[HttpPost]
|
||||
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)
|
||||
{
|
||||
if (dir.Id == 0)
|
||||
_rootDirProvider.Add(dir);
|
||||
|
||||
else
|
||||
_rootDirProvider.Update(dir);
|
||||
_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]
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<div id="root-dirs">
|
||||
@foreach (var item in Model.Directories)
|
||||
{
|
||||
Html.RenderPartial("RootDir", item);
|
||||
Html.RenderAction("GetRootDirView", item);
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -63,23 +63,21 @@
|
|||
return false;
|
||||
});
|
||||
|
||||
$("a.deleteRow").live("click", function () {
|
||||
$(this).parents("div.rootDirSection:first").remove();
|
||||
return false;
|
||||
});
|
||||
var deleteRootDirUrl = '@Url.Action("DeleteRootDir", "Settings")';
|
||||
|
||||
$(".defaultCheckbox").live("change", function () {
|
||||
var checked = $(this).attr('checked');
|
||||
function deleteRootDir(id) {
|
||||
sendToServer(id);
|
||||
$("#div_" + id).remove();
|
||||
}
|
||||
|
||||
if (checked) {
|
||||
var thisOne = this;
|
||||
$(".defaultCheckbox").attr('checked', false);
|
||||
$(this).attr('checked', true);
|
||||
}
|
||||
|
||||
//Don't let the user uncheck a checkbox (Like a radio button)
|
||||
else {
|
||||
$(this).attr('checked', true);
|
||||
}
|
||||
});
|
||||
function sendToServer(id) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: deleteRootDirUrl,
|
||||
data: jQuery.param({ rootDirId: id }),
|
||||
error: function (req, status, error) {
|
||||
alert("Sorry! We could not delete your Root Directory at this time. " + error);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
|
@ -16,11 +16,12 @@
|
|||
{
|
||||
var idClean = ViewData.TemplateInfo.HtmlFieldPrefix.Replace('[', '_').Replace(']', '_');
|
||||
|
||||
<div class="rootDirSection">
|
||||
|
||||
<div class="rootDirSection" id="div_@(ViewData["RootDirId"])">
|
||||
<fieldset>
|
||||
<div>
|
||||
@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>
|
||||
</div>
|
||||
<div>
|
||||
|
|
Loading…
Reference in a new issue