AddressEditorViewController.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // AddressEditorViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 8/18/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "AddressEditorViewController.h"
  9. #import "iSalesNetwork.h"
  10. @interface AddressEditorViewController ()
  11. @end
  12. @implementation AddressEditorViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
  16. style:UIBarButtonItemStylePlain
  17. target:self
  18. action:@selector( onBackClick:)];
  19. // [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onBackClick:)];
  20. self.navigationItem.leftBarButtonItem = backButton;
  21. // UIBarButtonItem *closeButton =
  22. UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
  23. style:UIBarButtonItemStylePlain
  24. target:self
  25. action:@selector(onSaveClick:)];
  26. self.navigationItem.rightBarButtonItem = saveButton;
  27. // Do any additional setup after loading the view.
  28. }
  29. - (void)didReceiveMemoryWarning {
  30. [super didReceiveMemoryWarning];
  31. // Dispose of any resources that can be recreated.
  32. }
  33. - (void)onBackClick:(UIButton *)sender {
  34. [self.navigationController popViewControllerAnimated:(false)];
  35. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  36. // ;
  37. // }];
  38. }
  39. - (IBAction)onSaveClick:(id)sender {
  40. // add params check here.
  41. [self.lastedit endEditing:true];
  42. [self.lasttextview endEditing:true];
  43. self.cancommit=true;
  44. NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  45. //[upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  46. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  47. for(int i=0;i<section_count;i++)
  48. {
  49. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  50. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  51. for(int j=0;j<item_count;j++)
  52. {
  53. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  54. NSString* key = [itemjson valueForKey:@"name"];
  55. if(key==nil || key.length==0)
  56. continue;
  57. if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  58. {
  59. NSString* single_select = [itemjson valueForKey:@"single_select"];
  60. if([single_select isEqualToString:@"true"])
  61. {
  62. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  63. int count = [[cadejson valueForKey:@"count"] intValue];
  64. bool setvalue = false;
  65. for(int cc=0;cc<count;cc++)
  66. {
  67. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  68. if([[valjson valueForKey:@"check"]intValue]==1)
  69. {
  70. [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  71. setvalue=true;
  72. break;
  73. }
  74. }
  75. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  76. {
  77. self.cancommit = false;
  78. }
  79. }
  80. else
  81. {
  82. //not support multi select for now;
  83. }
  84. /*
  85. upparams setValue:itemjson forKey:<#(NSString *)#>
  86. */
  87. }
  88. else
  89. {
  90. if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  91. [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  92. else
  93. {
  94. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  95. self.cancommit = false;
  96. }
  97. }
  98. upparams= [self subitem_param:itemjson addto:upparams ];
  99. }
  100. }
  101. if(self.cancommit==false)
  102. {
  103. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Some requried field is missing" message:@"Fields with * mark cannot be empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  104. // // UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  105. // [alert show];
  106. [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  107. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  108. // NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  109. // [self.editorTable reloadData ];
  110. [self.editorTable reloadData];
  111. return;
  112. }
  113. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  114. NSDictionary* editor_json = [iSalesNetwork create_Address:upparams];
  115. dispatch_async(dispatch_get_main_queue(), ^{
  116. if([[editor_json valueForKey:@"result"] intValue]==2)
  117. {
  118. // int result = [[editor_json valueForKey:@"result"] intValue];
  119. // if(result==2)
  120. {
  121. [self prepareReturn: nil];
  122. [self.navigationController popViewControllerAnimated:true];
  123. }
  124. }
  125. else
  126. {
  127. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Address" controller:self] ;
  128. }
  129. });
  130. });
  131. }
  132. /*
  133. #pragma mark - Navigation
  134. // In a storyboard-based application, you will often want to do a little preparation before navigation
  135. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  136. // Get the new view controller using [segue destinationViewController].
  137. // Pass the selected object to the new view controller.
  138. }
  139. */
  140. @end