| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- //
- // CustomerEditViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 11/4/15.
- // Copyright © 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "CustomerEditViewController.h"
- #import "RANetwork.h"
- #import "MainViewController.h"
- #import "JKTimerManager.h"
- @interface CustomerEditViewController ()
- @end
- @implementation CustomerEditViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.editable = YES;
-
- UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onBackClick:)];
- //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
- // closeButton.title = @"Close";
-
- self.navigationItem.leftBarButtonItem = closeButton;
-
-
-
- // NSMutableArray * items = [[NSMutableArray alloc]init];
-
-
- UIBarButtonItem *savebtn = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
-
- savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onSaveClick:)];
-
-
- self.navigationItem.rightBarButtonItem = savebtn;
-
- // UIBarButtonItem *btnCommit = nil;
- // btnCommit =[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
- // style:UIBarButtonItemStylePlain
- // target:self
- // action:@selector(onCommitOrderClick:)];
- //
- //
- //
- //
- // //savebtn setBackgroundImage:(nullable UIImage *) forState:<#(UIControlState)#> style:<#(UIBarButtonItemStyle)#> barMetrics:<#(UIBarMetrics)#>
- // //[savebtn setImage:[UIImage imageNamed:@"save"] ];
- //
- //
- // /*
- // UIBarMetricsDefault,
- // UIBarMetricsCompact,
- // UIBarMetricsDefaultPrompt = 101, // Applicable only in bars with the prompt property, such as UINavigationBar and UISearchBar
- // UIBarMetricsCompactPrompt
- //
- // */
- // // [savebtn setBackgroundImage:[UIImage imageNamed:@"save"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
- // // UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
- // // item1.title = @"item1";
- // //// item1.image = [UIImage imageNamed:@"rect_setting"];
- // // UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
- // //// item2.image = [UIImage imageNamed:@"rect_about"];
- // // item2.title = @"item2";
- //
- //
- // UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
- // fixedItem.width = 20.0f;
- //
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //
- // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
- // {
- // [items addObject:savebtn];
- //
- // [items addObject:fixedItem];
- // }
- // [items addObject:btnCommit];
- // // [items addObject:item2];
- // self.navigationItem.rightBarButtonItems=items;
-
-
- // Do any additional setup after loading the view.
- }
- - (void)onBackClick:(UIButton *)sender {
- [self.navigationController popViewControllerAnimated:false];
- if(self.returnValue)
- self.returnValue(nil);
- }
- - (void)onSaveClick:(UIButton *)sender {
- // add params check here.
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
-
- NSMutableDictionary* upparams = [self check_cancommit:true];
- if(self.cancommit==false)
- return;
-
-
- if(self.bolocustomer)
- {
- [self.navigationController popViewControllerAnimated:false];
- if(self.returnValue)
- self.returnValue(upparams);
-
- return;
- }
- __weak typeof(self) weakself = self;
- __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Contact" completion:^{
- resultHandler handler =^(NSMutableDictionary *result) {
- NSDictionary* editor_json = result;
- [waitalert dismissViewControllerAnimated:YES completion:^{
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
- // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
- //
- //
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // appDelegate.customerInfo = customerInfo;
- // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
- // // self.labelContact.text=appDelegate.contact_name;
- //
- // NSDictionary * customerinfo = appDelegate.customerInfo;
- [weakself prepareReturn:nil];
- if(weakself.bnewcustomer )
- [weakself.navigationController popViewControllerAnimated:false];
- else
- [weakself.navigationController popToRootViewControllerAnimated:false];
-
-
-
-
- #ifdef RA_NOTIFICATION
-
- [ActiveViewController Notify:@"ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
- #endif
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:weakself] ;
- }
- }];
-
-
-
-
-
-
- } ;
-
- if(self.bnewcustomer )
- [RANetwork request_add_customer:upparams completionHandler:handler];
- else
- [RANetwork request_update_customer:upparams completionHandler:handler];
- }];
-
-
-
-
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* editor_json = nil;
- // // NSString* contactId=[upparams valueForKey:@"contactId"];
- // if(self.bnewcustomer )
- // editor_json=[RANetwork save_newCustomer:upparams];
- // else
- // editor_json=[RANetwork update_Customer:upparams];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- //
- // if([[editor_json valueForKey:@"result"] intValue]==2)
- // {
- // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
- // //
- // //
- // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // // appDelegate.customerInfo = customerInfo;
- // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
- // // // self.labelContact.text=appDelegate.contact_name;
- // //
- // // NSDictionary * customerinfo = appDelegate.customerInfo;
- // [weakself prepareReturn:nil];
- // if(weakself.bnewcustomer )
- // [weakself.navigationController popViewControllerAnimated:false];
- // else
- // [weakself.navigationController popToRootViewControllerAnimated:false];
- //
- //
- //
- //
- //#ifdef RA_NOTIFICATION
- //
- // [ActiveViewController Notify:@"ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- //#else
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
- //#endif
- //
- // }
- // else
- // {
- // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:weakself] ;
- // }
- //
- //
- //
- //
- // });
- // });
-
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #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:appDelegate.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"];
-
- [urgencyDic setValue:@(weakSelf.bnewcustomer) forKey:@"new_customer"];
-
- if ([weakSelf.class_name isEqualToString:@"CustomerEditViewController"]) {
- // CustomerEditViewController
- __block NSString *contact_id = @"";
-
- [weakSelf.content_data_download enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
-
- // section_0
- if ([key isEqualToString:@"section_0"]) {
- NSDictionary *section_0 = (NSDictionary *)obj;
- [section_0 enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
-
- // Contact ID
- if ([obj isKindOfClass:[NSDictionary class]]) {
- if ([[obj objectForKey:@"aname"] isEqualToString:@"Contact ID"]) {
- contact_id = [obj objectForKey:@"value"];
- }
-
- }
-
- }];
- }
-
- }];
-
- [urgencyDic setValue:contact_id forKey:@"contact_id"];
-
-
- }
-
- [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
|