#pragma mark - data validation
-(MKAddNPAddressViewControllerFormFields)emptyFields
{
//checking for empty data fields
MKAddNPAddressViewControllerFormFields emptyFields=MKAddNPAddressViewControllerFormFieldNone;
if ((self.departmentAddress.name==nil) || ([self.departmentAddress.name isEqualToString:@""]))
{
emptyFields=emptyFields | (MKAddNPAddressViewControllerFormFieldName);
};
if ((self.departmentAddress.surname==nil) || ([self.departmentAddress.surname isEqualToString:@""]))
{
emptyFields=emptyFields | (MKAddNPAddressViewControllerFormFieldSurname);
};
if ((self.departmentAddress.phoneNumber==nil) || ([self.departmentAddress.phoneNumber isEqualToString:@""]))
{
emptyFields=emptyFields | (MKAddNPAddressViewControllerFormFieldPhone);
};
if ((self.departmentAddress.regionID==nil) || (self.departmentAddress.regionName==nil) || ([self.departmentAddress.regionName isEqualToString:@""]))
{
emptyFields=emptyFields | (MKAddNPAddressViewControllerFormFieldRegion);
};
if ((self.departmentAddress.cityID==nil) || (self.departmentAddress.cityName==nil) || ([self.departmentAddress.cityName isEqualToString:@""]))
{
emptyFields=emptyFields | (MKAddNPAddressViewControllerFormFieldCity);
};
if ((self.departmentAddress.departmentID==nil) || (self.departmentAddress.departmentName==nil) || ([self.departmentAddress.departmentName isEqualToString:@""]))
{
emptyFields=emptyFields | (MKAddNPAddressViewControllerFormFieldDepartment);
};
return emptyFields;
}
#pragma mark - Actions
-(IBAction)doneButtonDidPress:(id)sender
{
MK_Log;
MKAddNPAddressViewControllerFormFields emptyFields=[self emptyFields];
if (emptyFields!=MKAddNPAddressViewControllerFormFieldNone)
{
NSLog(@"%@: %@ called. emptyFields: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), [NSString stringWithBitMask:(emptyFields)]);
NSString *messageStr=@"Необходимо заполнить ";
if (emptyFields & MKAddNPAddressViewControllerFormFieldName)
{
messageStr=[messageStr stringByAppendingString:@"имя, "];
};
if (emptyFields & MKAddNPAddressViewControllerFormFieldSurname)
{
messageStr=[messageStr stringByAppendingString:@"фамилию, "];
};
if (emptyFields & MKAddNPAddressViewControllerFormFieldPhone)
{
messageStr=[messageStr stringByAppendingString:@"телефон, "];
};
if (emptyFields & MKAddNPAddressViewControllerFormFieldRegion)
{
messageStr=[messageStr stringByAppendingString:@"регион, "];
};
if (emptyFields & MKAddNPAddressViewControllerFormFieldCity)
{
messageStr=[messageStr stringByAppendingString:@"город, "];
};
if (emptyFields & MKAddNPAddressViewControllerFormFieldDepartment)
{
messageStr=[messageStr stringByAppendingString:@"отделение, "];
};
messageStr=[messageStr stringByPaddingToLength:(messageStr.length-2) withString:@"" startingAtIndex:0];
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Внимание" message:messageStr delegate:nil cancelButtonTitle:@"Ок" otherButtonTitles: nil];
[alert show];
}
else
{
[self saveData];
};
}