added editGroup endpoint.

added goToMenuOption function to enable navigation and posting (edit, create etc, on the homepage).
created submitGroupEdit function to post the changed/new object to the server.
#30
This commit is contained in:
chris.watts90@outlook.com 2017-03-15 23:16:17 +00:00
parent f27a124751
commit 3945789ee6

View File

@ -8,11 +8,19 @@
home: function () { return this.overview; } home: function () { return this.overview; }
}; };
self.apiEndpoints = { self.apiEndpoints = {
getGroups:"/api/groups" getGroups: "/api/groups",
editGroup: "/api/groups/edit"
}; };
self.goToMenuOption = function (menu) { location.hash = menu; console.log("goToMenuOption: " + menu); };
self.clearGroupForm = function(data, event) { self.clearGroupForm = function(data, event) {
self.groupEditItem({ Id: -1, Name: "" }); self.groupEditItem({ Id: -1, Name: "" });
}; };
self.hideGroupForm = function(data, event) {
self.groupEditItem(null);
};
self.groupFormHidden = ko.computed(function () {
return self.groupEditItem() == null;
}, self);
self.editGroupClick = function(data, event) { self.editGroupClick = function(data, event) {
self.groupEditItem(data); self.groupEditItem(data);
}; };
@ -28,27 +36,24 @@
//self.goToMenuOption(self.uiPages.home()); //self.goToMenuOption(self.uiPages.home());
}); });
}; };
self.submitGroupEdit = function(group) {
var url = self.helpers.createRequestUrl(self.apiEndpoints.editGroup, null, false);
$.post(url, group, function () {
}, "json")
.done(function () {
self.groupEditItem(null);
self.goToMenuOption(self.uiPages.home());
})
.fail(function (resp, status, error) {
self.goToMenuOption(self.uiPages.home());
});
};
Sammy(function () { Sammy(function () {
this.get("#overview", function () { this.get("#overview", function () {
self.getGroups(); self.getGroups();
}); });
this.post("#editgroup", function () { this.post("#editgroup", function () {
self.submitGroupEdit(self.groupEditItem());
return false;
});
this.post("#edituser", function () {
$.each(self.chosenUserDetails().AssociatedIdentifiers,
function (k, v) {
if (v.IsAssociatedToUser !== true) {
self.chosenUserDetails().AssociatedIdentifiers.splice(k, 1);
}
});
$.each(self.unassignedCardData().data, function (k, v) {
if (v.IsAssociatedToUser === true) {
self.chosenUserDetails().AssociatedIdentifiers.push(v);
}
});
self.submitChangedUser(self.chosenUserDetails());
return false; return false;
}); });
//default route (home page) //default route (home page)