AddressEditorViewController.m 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 "MainViewController.h"
  10. #import "RANetwork.h"
  11. #import "JKTimerManager.h"
  12. @interface AddressEditorViewController ()
  13. @end
  14. @implementation AddressEditorViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. self.editable = YES;
  18. UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  19. style:UIBarButtonItemStylePlain
  20. target:self
  21. action:@selector( onBackClick:)];
  22. // [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onBackClick:)];
  23. self.navigationItem.leftBarButtonItem = backButton;
  24. // UIBarButtonItem *closeButton =
  25. UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  26. style:UIBarButtonItemStylePlain
  27. target:self
  28. action:@selector(onSaveClick:)];
  29. self.navigationItem.rightBarButtonItem = saveButton;
  30. // Do any additional setup after loading the view.
  31. }
  32. - (void)didReceiveMemoryWarning {
  33. [super didReceiveMemoryWarning];
  34. // Dispose of any resources that can be recreated.
  35. }
  36. - (void)onBackClick:(UIButton *)sender {
  37. [self.navigationController popViewControllerAnimated:(false)];
  38. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  39. // ;
  40. // }];
  41. }
  42. - (IBAction)onSaveClick:(id)sender {
  43. // add params check here.
  44. [self.lastedit endEditing:true];
  45. [self.lasttextview endEditing:true];
  46. // self.cancommit=true;
  47. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  48. // //[upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  49. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  50. // for(int i=0;i<section_count;i++)
  51. // {
  52. //
  53. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  54. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  55. // for(int j=0;j<item_count;j++)
  56. // {
  57. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  58. // NSString* key = [itemjson valueForKey:@"name"];
  59. // if(key==nil || key.length==0)
  60. // continue;
  61. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  62. // {
  63. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  64. // if([single_select isEqualToString:@"true"])
  65. // {
  66. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  67. // int count = [[cadejson valueForKey:@"count"] intValue];
  68. // bool setvalue = false;
  69. // for(int cc=0;cc<count;cc++)
  70. // {
  71. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  72. // if([[valjson valueForKey:@"check"]intValue]==1)
  73. // {
  74. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  75. // setvalue=true;
  76. // break;
  77. // }
  78. // }
  79. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  80. // {
  81. // self.cancommit = false;
  82. // }
  83. // }
  84. // else
  85. // {
  86. // //not support multi select for now;
  87. // }
  88. // /*
  89. // upparams setValue:itemjson forKey:<#(NSString *)#>
  90. //
  91. // */
  92. // }
  93. // else
  94. // {
  95. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  96. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  97. // else
  98. // {
  99. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  100. // self.cancommit = false;
  101. // }
  102. // }
  103. //
  104. // upparams= [self subitem_param:itemjson addto:upparams ];
  105. // }
  106. // }
  107. //
  108. //
  109. // if(self.cancommit==false)
  110. // {
  111. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Some requried field is missing" message:@"Fields with * mark cannot be empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  112. //// // UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  113. //// [alert show];
  114. //
  115. //
  116. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  117. //
  118. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  119. //
  120. //
  121. // // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  122. //// [self.editorTable reloadData ];
  123. //
  124. // [self.editorTable reloadData];
  125. // return;
  126. //
  127. // }
  128. NSMutableDictionary* upparams = [self check_cancommit:true];
  129. if(self.cancommit==false)
  130. return;
  131. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  132. NSDictionary* editor_json = [RANetwork create_Address:upparams];
  133. dispatch_async(dispatch_get_main_queue(), ^{
  134. if([[editor_json valueForKey:@"result"] intValue]==2)
  135. {
  136. // int result = [[editor_json valueForKey:@"result"] intValue];
  137. // if(result==2)
  138. {
  139. [self prepareReturn: nil];
  140. [self.navigationController popViewControllerAnimated:true];
  141. }
  142. }
  143. else
  144. {
  145. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Address" controller:self] ;
  146. }
  147. });
  148. });
  149. }
  150. /*
  151. #pragma mark - Navigation
  152. // In a storyboard-based application, you will often want to do a little preparation before navigation
  153. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  154. // Get the new view controller using [segue destinationViewController].
  155. // Pass the selected object to the new view controller.
  156. }
  157. */
  158. #pragma mark - Urgency
  159. - (void)viewWillAppear:(BOOL)animated {
  160. [super viewWillAppear:animated];
  161. [self start_urgency_timer];
  162. }
  163. -(void) viewWillDisappear:(BOOL)animated
  164. {
  165. [super viewWillDisappear:animated];
  166. [self cancel_urgency_timer];
  167. }
  168. - (void)dealloc {
  169. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  170. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  171. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  172. }
  173. - (void)start_urgency_timer {
  174. if (!self.editable) {
  175. return;
  176. }
  177. __weak typeof(self) weakSelf = self;
  178. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  179. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  180. #ifdef OFFLINE_MODE
  181. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  182. #endif
  183. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  184. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  185. // DebugLog(@"timer start....");
  186. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  187. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  188. if ([weakSelf.class_name isEqualToString:@"AddressEditorViewController"]) {
  189. // AddressEditorViewController
  190. }
  191. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  192. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  193. }];
  194. }
  195. - (void)cancel_urgency_timer {
  196. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  197. }
  198. @end