AddressEditorViewController.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. NSMutableDictionary* upparams = [self check_cancommit:true];
  47. if(self.cancommit==false)
  48. return;
  49. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Save Address" completion:^{
  50. PopWaitAlert* pop = [RAUtils waiting_pop:@"Save Address" completion:nil];
  51. [RANetwork request_add_address:upparams completionHandler:^(NSMutableDictionary *result) {
  52. // [waitalert dismissViewControllerAnimated:YES completion:^{
  53. [pop hide];
  54. NSDictionary* editor_json = result;
  55. if([[editor_json valueForKey:@"result"] intValue]==2)
  56. {
  57. // int result = [[editor_json valueForKey:@"result"] intValue];
  58. // if(result==2)
  59. {
  60. [self.navigationController popViewControllerAnimated:true];
  61. [self prepareReturn: nil];
  62. }
  63. }
  64. else
  65. {
  66. [RAUtils message_box:@"Create Address" message:[editor_json valueForKey:@"err_msg"] completion:nil] ;
  67. }
  68. // }];
  69. }];
  70. // }];
  71. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  72. //
  73. // NSDictionary* editor_json = [RANetwork create_Address:upparams];
  74. //
  75. // dispatch_async(dispatch_get_main_queue(), ^{
  76. //
  77. //
  78. //
  79. // if([[editor_json valueForKey:@"result"] intValue]==2)
  80. // {
  81. //
  82. //// int result = [[editor_json valueForKey:@"result"] intValue];
  83. //
  84. //// if(result==2)
  85. // {
  86. // [self prepareReturn: nil];
  87. // [self.navigationController popViewControllerAnimated:true];
  88. // }
  89. //
  90. //
  91. // }
  92. // else
  93. // {
  94. // [RAUtils message_box:@"Create Address" message:[editor_json valueForKey:@"err_msg"] completion:nil] ;
  95. // }
  96. //
  97. //
  98. //
  99. // });
  100. // });
  101. }
  102. /*
  103. #pragma mark - Navigation
  104. // In a storyboard-based application, you will often want to do a little preparation before navigation
  105. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  106. // Get the new view controller using [segue destinationViewController].
  107. // Pass the selected object to the new view controller.
  108. }
  109. */
  110. #pragma mark - Urgency
  111. - (void)viewWillAppear:(BOOL)animated {
  112. [super viewWillAppear:animated];
  113. [self start_urgency_timer];
  114. }
  115. -(void) viewWillDisappear:(BOOL)animated
  116. {
  117. [super viewWillDisappear:animated];
  118. [self cancel_urgency_timer];
  119. }
  120. - (void)dealloc {
  121. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  122. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  123. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  124. }
  125. - (void)start_urgency_timer {
  126. if (!self.editable) {
  127. return;
  128. }
  129. __weak typeof(self) weakSelf = self;
  130. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  131. [appDelegate.urgencyDic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  132. #ifdef OFFLINE_MODE
  133. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  134. #endif
  135. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  136. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  137. // DebugLog(@"timer start....");
  138. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  139. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  140. if ([weakSelf.class_name isEqualToString:@"AddressEditorViewController"]) {
  141. // AddressEditorViewController
  142. }
  143. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  144. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  145. }];
  146. }
  147. - (void)cancel_urgency_timer {
  148. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  149. }
  150. @end