How do I save / update / delete on server from my AngularJS editor?
There are several tutorials online about how to make a custom editor using the new AngularJS editor system. None of them seem to explain how to do data operations on the serverside however. Or am I missing some really fundamental aspect of how Umbraco handles on the server - is it all wired up automatically?
I have a DocumentType, let's call it StandardPage, it has a DataType property, let's call that Address. Address has some strings, Line1, Line2, etc - so it's a complex object. I have an Angular editor that's supposed to edit Address. The editor posts data to an UmbracoAuthorizedJsonController which has a Save method. So far so good.
In my editor's .resource.js file, I have a save handler :
where data is some form data, and parentId is the id of the StandardPage I want to edit. Posting back works, I can retrieve the object I want to edit .... but now what?
This gets the StandardPage record I want to edit - how do I save the data I just sent to the server? How do I save a complex object to standardPage's Address property? How can I delete the address again? There's an UmbracoContext.Application.Services.DataTypeService, it has save and delete methods, but I don't see where or how I write to page properties with that.
After digging into this a bit more, I can see that it's pretty easy for me to update a custom property on a DocumentType or DataType as long as I write only string data to them.
How do I save / update / delete on server from my AngularJS editor?
There are several tutorials online about how to make a custom editor using the new AngularJS editor system. None of them seem to explain how to do data operations on the serverside however. Or am I missing some really fundamental aspect of how Umbraco handles on the server - is it all wired up automatically?
I have a DocumentType, let's call it StandardPage, it has a DataType property, let's call that Address. Address has some strings, Line1, Line2, etc - so it's a complex object. I have an Angular editor that's supposed to edit Address. The editor posts data to an UmbracoAuthorizedJsonController which has a Save method. So far so good.
In my editor's .resource.js file, I have a save handler :
save: function(data, parentId) {
return $http.post("backoffice/MySite/Editor/Save", angular.toJson(data, parentId));
},
where data is some form data, and parentId is the id of the StandardPage I want to edit. Posting back works, I can retrieve the object I want to edit .... but now what?
In my save method, I can do
IContent standardPage = UmbracoContext.Application.Services.ContentService.GetById(parentId);
This gets the StandardPage record I want to edit - how do I save the data I just sent to the server? How do I save a complex object to standardPage's Address property? How can I delete the address again? There's an UmbracoContext.Application.Services.DataTypeService, it has save and delete methods, but I don't see where or how I write to page properties with that.
Thanks.
Hi Shukri Adams,
Save / update / delete on server you have to write your own api controllers and manage your requests.
THanks
Any examples or documentation that explains what the server-side code should look like? I'm completely new to Umbraco so I don't have much to go on.
After digging into this a bit more, I can see that it's pretty easy for me to update a custom property on a DocumentType or DataType as long as I write only string data to them.
So my controller code looks like :
IContent doc= UmbracoContext.Application.Services.ContentService.GetById(parentId);
string serialized = myobject.serializeToJson();
doc.Properties["someProperty"].Value = serialized;
ApplicationContext.Services.ContentService.SaveAndPublishWithStatus(doc);
Is this the intented way to handle complex custom objects in Umbraco?
is working on a reply...