| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- //
- // AddressEditorViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 8/18/15.
- // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "AddressEditorViewController.h"
- #import "MainViewController.h"
- #import "RANetwork.h"
- #import "JKTimerManager.h"
- @interface AddressEditorViewController ()
- @end
- @implementation AddressEditorViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.editable = YES;
-
- UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector( onBackClick:)];
- // [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onBackClick:)];
-
- self.navigationItem.leftBarButtonItem = backButton;
-
-
- // UIBarButtonItem *closeButton =
-
-
- UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onSaveClick:)];
- self.navigationItem.rightBarButtonItem = saveButton;
- // Do any additional setup after loading the view.
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)onBackClick:(UIButton *)sender {
-
-
- [self.navigationController popViewControllerAnimated:(false)];
- // [self.navigationController dismissViewControllerAnimated:true completion:^{
- // ;
- // }];
- }
- - (IBAction)onSaveClick:(id)sender {
- // add params check here.
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
-
- NSMutableDictionary* upparams = [self check_cancommit:true];
- if(self.cancommit==false)
- return;
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Save Address" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Save Address" completion:nil];
- [RANetwork request_add_address:upparams completionHandler:^(NSMutableDictionary *result) {
-
- // [waitalert dismissViewControllerAnimated:YES completion:^{
-
- [pop hide];
- NSDictionary* editor_json = result;
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- // int result = [[editor_json valueForKey:@"result"] intValue];
-
- // if(result==2)
- {
-
- [self.navigationController popViewControllerAnimated:true];
- [self prepareReturn: nil];
- }
-
-
- }
- else
- {
- [RAUtils message_box:@"Create Address" message:[editor_json valueForKey:@"err_msg"] completion:nil] ;
-
- }
- // }];
-
-
-
-
- }];
- // }];
-
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* editor_json = [RANetwork create_Address:upparams];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- //
- //
- // if([[editor_json valueForKey:@"result"] intValue]==2)
- // {
- //
- //// int result = [[editor_json valueForKey:@"result"] intValue];
- //
- //// if(result==2)
- // {
- // [self prepareReturn: nil];
- // [self.navigationController popViewControllerAnimated:true];
- // }
- //
- //
- // }
- // else
- // {
- // [RAUtils message_box:@"Create Address" message:[editor_json valueForKey:@"err_msg"] completion:nil] ;
- // }
- //
- //
- //
- // });
- // });
-
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- #pragma mark - Urgency
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self start_urgency_timer];
- }
- -(void) viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self cancel_urgency_timer];
- }
- - (void)dealloc {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
- [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
-
- }
- - (void)start_urgency_timer {
-
- if (!self.editable) {
- return;
- }
-
- __weak typeof(self) weakSelf = self;
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- [appDelegate.urgencyDic setValue:RASingleton.sharedInstance.user forKey:@"user"];
- #ifdef OFFLINE_MODE
- [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
- #endif
- [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
-
- NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
-
- // DebugLog(@"timer start....");
-
- [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
-
- [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
-
-
-
- if ([weakSelf.class_name isEqualToString:@"AddressEditorViewController"]) {
- // AddressEditorViewController
-
- }
-
- [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
- [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
-
- }];
- }
- - (void)cancel_urgency_timer {
- [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
- }
- @end
|