Adding a root dir will not add it to the DB until after it is saved, also will not save if the path is blank.

pull/3113/head
Mark McDowall 13 years ago
parent 1fbf9a1416
commit c3d4732baa

@ -187,9 +187,16 @@ namespace NzbDrone.Web.Controllers
[HttpPost] [HttpPost]
public JsonResult SaveRootDir(int id, string path) public JsonResult SaveRootDir(int id, string path)
{ {
if (String.IsNullOrWhiteSpace(path))
return new JsonResult { Data = "failed" };
try try
{ {
_rootFolderProvider.Update(new RootDir { Id = id, Path = path }); if (id == 0)
id = _rootFolderProvider.Add(new RootDir { Path = path });
else
_rootFolderProvider.Update(new RootDir { Id = id, Path = path });
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -199,30 +206,33 @@ namespace NzbDrone.Web.Controllers
return new JsonResult { Data = "failed" }; return new JsonResult { Data = "failed" };
} }
return new JsonResult { Data = "ok" }; return new JsonResult { Data = id };
} }
public PartialViewResult AddRootDir() public PartialViewResult AddRootDir()
{ {
var rootDir = new RootDir { Path = String.Empty }; var model = new RootDirModel
{
Id = 0,
Path = "",
SelectList = new SelectList(new List<string> { "" }, "")
};
var id = _rootFolderProvider.Add(rootDir); ViewData["guid"] = Guid.NewGuid();
rootDir.Id = id;
var model = new RootDirModel();
model.Id = rootDir.Id;
model.Path = rootDir.Path;
model.SelectList = new SelectList(new List<string> { rootDir.Path }, rootDir.Path);
return PartialView("RootDir", model); return PartialView("RootDir", model);
} }
public ActionResult GetRootDirView(RootDir rootDir) public ActionResult GetRootDirView(RootDir rootDir)
{ {
var model = new RootDirModel(); var model = new RootDirModel
model.Id = rootDir.Id; {
model.Path = rootDir.Path; Id = rootDir.Id,
model.SelectList = new SelectList(new List<string> { rootDir.Path }, rootDir.Path); Path = rootDir.Path,
SelectList = new SelectList(new List<string> { rootDir.Path }, rootDir.Path)
};
ViewData["guid"] = Guid.NewGuid();
return PartialView("RootDir", model); return PartialView("RootDir", model);
} }

@ -132,11 +132,12 @@
var deleteRootDirUrl = '@Url.Action("DeleteRootDir", "AddSeries")'; var deleteRootDirUrl = '@Url.Action("DeleteRootDir", "AddSeries")';
function deleteRootDir(id) { function deleteRootDir(guid) {
sendDeleteToServer(id); var id = $('#id_' + guid).val();
sendDeleteToServer(id, guid);
} }
function sendDeleteToServer(id) { function sendDeleteToServer(id, guid) {
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: deleteRootDirUrl, url: deleteRootDirUrl,
@ -145,15 +146,16 @@
alert("Sorry! We could not delete your Root Directory at this time. " + error); alert("Sorry! We could not delete your Root Directory at this time. " + error);
}, },
success: function () { success: function () {
$("#rootDir_" + id).remove(); $("#rootDir_" + guid).remove();
} }
}); });
} }
var saveRootDirUrl = '@Url.Action("SaveRootDir", "AddSeries")'; var saveRootDirUrl = '@Url.Action("SaveRootDir", "AddSeries")';
function saveRootDir(id) { function saveRootDir(guid) {
var path = $("#path_" + id).data("tComboBox").value(); var path = $("#path_" + guid).data("tComboBox").value();
var id = $("#id_" + guid).val();
$.ajax({ $.ajax({
type: "POST", type: "POST",
@ -163,8 +165,11 @@
alert("Sorry! We could not save " + path + " at this time. " + error); alert("Sorry! We could not save " + path + " at this time. " + error);
}, },
success: function (data, textStatus, jqXHR) { success: function (data, textStatus, jqXHR) {
if (data != 'ok') if (data == 'failed')
alert("An error occurred while saving Root Directory: " + path); alert("An error occurred while saving Root Directory: " + path);
else {
$("#id_" + guid).val(data);
}
} }
}); });
} }

@ -4,10 +4,10 @@
Layout = null; Layout = null;
} }
<div class="rootDirSection" id="rootDir_@(Model.Id)" style="padding: 7px; padding-left: 3px;"> <div class="rootDirSection" id="rootDir_@(ViewData["guid"])" style="padding: 7px; padding-left: 3px;">
<fieldset style="padding: 5px; height: 40px;"> <fieldset style="padding: 5px; height: 40px;">
@{Html.Telerik().ComboBox() @{Html.Telerik().ComboBox()
.Name("path_" + Model.Id) .Name("path_" + ViewData["guid"])
.BindTo(Model.SelectList) .BindTo(Model.SelectList)
.DataBinding(binding => binding.Ajax().Select("_autoCompletePath", "Directory").Delay(400).Cache(false)) .DataBinding(binding => binding.Ajax().Select("_autoCompletePath", "Directory").Delay(400).Cache(false))
.Filterable(f => f.FilterMode(AutoCompleteFilterMode.StartsWith)) .Filterable(f => f.FilterMode(AutoCompleteFilterMode.StartsWith))
@ -16,10 +16,10 @@
.Render();} .Render();}
<a href="#RemoveRootDir" class="deleteRow" onclick="deleteRootDir(@Model.Id); return false;"> <a href="#RemoveRootDir" class="deleteRow" onclick="deleteRootDir('@ViewData["guid"]'); return false;">
<img src="../../Content/Images/X.png" alt="Delete" width="20px" height="20px" style="vertical-align: middle; margin-top: 7px;"/></a> <img src="../../Content/Images/X.png" alt="Delete" width="20px" height="20px" style="vertical-align: middle; margin-top: 7px;"/></a>
<button style="padding: 2px 10px 2px 10px; vertical-align: middle; margin: 0px; margin-top: 7px;" onclick="saveRootDir(@Model.Id)">Save</button> <button style="padding: 2px 10px 2px 10px; vertical-align: middle; margin: 0px; margin-top: 7px;" onclick="saveRootDir('@ViewData["guid"]')">Save</button>
@Html.HiddenFor(x => x.Id, new { id = "id_" + Model.Id }) @Html.HiddenFor(x => x.Id, new { id = "id_" + ViewData["guid"] })
</fieldset> </fieldset>
</div> </div>
Loading…
Cancel
Save