Rollbacks when saving records via Javascript

I am currently in a similar situation where I need to update a field to ‘shipped’ but it requires all items to have a quantity entered first. Both these things need to be saved in one transaction otherwise it should save neither. Could we call a controller class in apex to handle this logic? Can someone point me to the right direction?