AddressEditorViewController.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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:UIImageRenderingModeAutomatic]
  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:UIImageRenderingModeAutomatic]
  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. //
  50. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  51. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  52. // for(int j=0;j<item_count;j++)
  53. // {
  54. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  55. // NSString* key = [itemjson valueForKey:@"name"];
  56. // if(key==nil || key.length==0)
  57. // continue;
  58. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  59. // {
  60. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  61. // if([single_select isEqualToString:@"true"])
  62. // {
  63. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  64. // int count = [[cadejson valueForKey:@"count"] intValue];
  65. // bool setvalue = false;
  66. // for(int cc=0;cc<count;cc++)
  67. // {
  68. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  69. // if([[valjson valueForKey:@"check"]intValue]==1)
  70. // {
  71. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  72. // setvalue=true;
  73. // break;
  74. // }
  75. // }
  76. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  77. // {
  78. // self.cancommit = false;
  79. // }
  80. // }
  81. // else
  82. // {
  83. // //not support multi select for now;
  84. // }
  85. // /*
  86. // upparams setValue:itemjson forKey:<#(NSString *)#>
  87. //
  88. // */
  89. // }
  90. // else
  91. // {
  92. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  93. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  94. // else
  95. // {
  96. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  97. // self.cancommit = false;
  98. // }
  99. // }
  100. //
  101. // upparams= [self subitem_param:itemjson addto:upparams ];
  102. // }
  103. // }
  104. //
  105. //
  106. // if(self.cancommit==false)
  107. // {
  108. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Some requried field is missing" message:@"Fields with * mark cannot be empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  109. //// // UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  110. //// [alert show];
  111. //
  112. //
  113. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  114. //
  115. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  116. //
  117. //
  118. // // NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  119. //// [self.editorTable reloadData ];
  120. //
  121. // [self.editorTable reloadData];
  122. // return;
  123. //
  124. // }
  125. NSMutableDictionary* upparams = [self check_cancommit:true];
  126. if(self.cancommit==false)
  127. return;
  128. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  129. NSDictionary* editor_json = [iSalesNetwork create_Address:upparams];
  130. dispatch_async(dispatch_get_main_queue(), ^{
  131. if([[editor_json valueForKey:@"result"] intValue]==2)
  132. {
  133. // int result = [[editor_json valueForKey:@"result"] intValue];
  134. // if(result==2)
  135. {
  136. [self prepareReturn: nil];
  137. [self.navigationController popViewControllerAnimated:true];
  138. }
  139. }
  140. else
  141. {
  142. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Address" controller:self] ;
  143. }
  144. });
  145. });
  146. }
  147. /*
  148. #pragma mark - Navigation
  149. // In a storyboard-based application, you will often want to do a little preparation before navigation
  150. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  151. // Get the new view controller using [segue destinationViewController].
  152. // Pass the selected object to the new view controller.
  153. }
  154. */
  155. @end