ContactAdvanceSearchViewController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. //
  2. // ContactAdvanceSearchViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 12/7/15.
  6. // Copyright © 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ContactAdvanceSearchViewController.h"
  9. #import "MainViewController.h"
  10. #import "RANetwork.h"
  11. #import "JKTimerManager.h"
  12. @interface ContactAdvanceSearchViewController ()
  13. @end
  14. @implementation ContactAdvanceSearchViewController
  15. -(void) viewWillAppear:(BOOL)animated
  16. {
  17. [super viewWillAppear:animated];
  18. [self start_urgency_timer];
  19. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  20. // self.offset = 0;
  21. // [self.content_data removeAllObjects];
  22. // [self loadpage];
  23. // [[self navigationController] setNavigationBarHidden:!self.showNavibar animated:NO];
  24. }
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  28. style:UIBarButtonItemStylePlain
  29. target:self
  30. action:@selector( onBackClick:)];
  31. // closeButton.tintColor = UIColorFromRGB(0x996633);
  32. self.navigationItem.leftBarButtonItem = closeButton;
  33. UIBarButtonItem *searchButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"search_bar_button"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  34. style:UIBarButtonItemStylePlain
  35. target:self
  36. action:@selector( onSearchClick:)];
  37. // searchButton.tintColor = UIColorFromRGB(0x996633);
  38. self.navigationItem.rightBarButtonItem = searchButton;
  39. // if (self.data_init==nil) {
  40. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  41. //
  42. // NSDictionary* editor_json = [iSalesNetwork request_CustomerInfo:self.contactId];
  43. //
  44. // dispatch_async(dispatch_get_main_queue(), ^{
  45. //
  46. //
  47. //
  48. // if([[editor_json valueForKey:@"result"] intValue]==2)
  49. // {
  50. // self.data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
  51. //
  52. // [self fillData];
  53. //
  54. //
  55. // }
  56. // else
  57. // {
  58. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Info Failed." controller:self] ;
  59. // }
  60. //
  61. //
  62. // });
  63. // });
  64. // }
  65. // else
  66. // {
  67. [self fillData];
  68. // }
  69. // Do any additional setup after loading the view.
  70. }
  71. - (void)didReceiveMemoryWarning {
  72. [super didReceiveMemoryWarning];
  73. // Dispose of any resources that can be recreated.
  74. }
  75. - (void)onBackClick:(UIButton *)sender {
  76. [self.navigationController popViewControllerAnimated:(false)];
  77. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  78. // ;
  79. // }];
  80. }
  81. - (IBAction)onCloseClick:(id)sender {
  82. [self dismissViewControllerAnimated:true completion:nil];
  83. }
  84. -(void) request_fill
  85. {
  86. }
  87. - (void) fillData
  88. {
  89. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  90. // NSDictionary* data = [self.data_init objectForKey:@"customerInfo"];
  91. for(int i=0;i<section_count;i++)
  92. {
  93. NSMutableDictionary * sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  94. int count = [[sectionjson valueForKey:@"count"] intValue];
  95. for(int j=0;j<count;j++)
  96. {
  97. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  98. NSString* control=[itemjson valueForKey:@"control"];
  99. NSString* name = [itemjson valueForKey:@"name"];
  100. NSString* value = [self.data_init valueForKey:name];
  101. [itemjson setValue:value forKey:@"value"];
  102. if([control isEqualToString:@"img"])
  103. {
  104. {
  105. NSString* img_url = [itemjson valueForKey:@"img_url_0"];
  106. NSString* url_value = [self.data_init valueForKey:img_url];
  107. [itemjson setValue:url_value forKey:@"img_url_0"];
  108. }
  109. {
  110. NSString* img_url = [itemjson valueForKey:@"img_url_1"];
  111. NSString* url_value = [self.data_init valueForKey:img_url];
  112. [itemjson setValue:url_value forKey:@"img_url_1"];
  113. }
  114. {
  115. NSString* img_url = [itemjson valueForKey:@"img_url_2"];
  116. NSString* url_value = [self.data_init valueForKey:img_url];
  117. [itemjson setValue:url_value forKey:@"img_url_2"];
  118. }
  119. }
  120. else if([control isEqualToString:@"enum"])
  121. {
  122. // NSMutableDictionary * cadedate = [itemjson objectForKey:@"cadedate"];
  123. NSArray* checked = [value componentsSeparatedByString:NSLocalizedString(@",", nil)];
  124. NSMutableDictionary* cadejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
  125. int count = [[cadejson valueForKey:@"count"] intValue];
  126. // bool setvalue = false;
  127. for(int cc=0;cc<count;cc++)
  128. {
  129. NSMutableDictionary* valjson=[[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]] mutableCopy];
  130. NSString* value_id=[NSString stringWithFormat:@"%@",[valjson valueForKey:@"value_id"]];
  131. int index=[checked indexOfObject:value_id];
  132. if(NSNotFound!=index&& checked!=nil)
  133. {
  134. valjson[@"check"]=[NSNumber numberWithInt:1];
  135. cadejson[[NSString stringWithFormat:@"val_%d",cc]]=valjson;
  136. }
  137. }
  138. itemjson [@"cadedate"]= cadejson;
  139. }
  140. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j]];
  141. }
  142. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i]];
  143. }
  144. self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
  145. // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  146. [self.editorTable reloadData];
  147. }
  148. - (IBAction)onSearchClick:(id)sender {
  149. // add params check here.
  150. [self.lastedit endEditing:true];
  151. [self.lasttextview endEditing:true];
  152. // self.cancommit=true;
  153. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  154. // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  155. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  156. // for(int i=0;i<section_count;i++)
  157. // {
  158. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  159. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  160. // for(int j=0;j<item_count;j++)
  161. // {
  162. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  163. // NSString* key = [itemjson valueForKey:@"name"];
  164. // if(key==nil || key.length==0)
  165. // continue;
  166. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  167. // {
  168. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  169. // if([single_select isEqualToString:@"true"])
  170. // {
  171. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  172. // int count = [[cadejson valueForKey:@"count"] intValue];
  173. // bool setvalue = false;
  174. // for(int cc=0;cc<count;cc++)
  175. // {
  176. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  177. // if([[valjson valueForKey:@"check"]intValue]==1)
  178. // {
  179. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  180. // setvalue=true;
  181. // break;
  182. // }
  183. // }
  184. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  185. // {
  186. // self.cancommit = false;
  187. // }
  188. // }
  189. // else
  190. // {
  191. //
  192. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  193. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  194. // int count = [[cadejson valueForKey:@"count"] intValue];
  195. // // bool setvalue = false;
  196. // for(int cc=0;cc<count;cc++)
  197. // {
  198. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  199. // if([[valjson valueForKey:@"check"]intValue]==1)
  200. // {
  201. //
  202. // [checked addObject:[NSNumber numberWithInt:[[valjson valueForKey:@"value_id"] intValue]]];
  203. // // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  204. // // setvalue=true;
  205. // // break;
  206. // }
  207. // }
  208. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"]&&checked.count==0)
  209. // {
  210. // self.cancommit = false;
  211. // }
  212. // else
  213. // {
  214. // NSString * string = [checked componentsJoinedByString:@","];
  215. // [upparams setValue:string forKey:[itemjson valueForKey:@"name"]];
  216. // }
  217. // }
  218. // /*
  219. // upparams setValue:itemjson forKey:<#(NSString *)#>
  220. //
  221. // */
  222. // }else
  223. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  224. // {
  225. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  226. // self.cancommit = false;
  227. // }
  228. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  229. // {
  230. // NSString* valuestr = [itemjson valueForKey:@"value"];
  231. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  232. //
  233. // NSString* value = [itemjson valueForKey:@"value"];
  234. // NSMutableDictionary* boolitem=nil;
  235. // NSMutableDictionary* subjson=nil;
  236. // if([value isEqualToString:@"true"])
  237. // {
  238. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  239. //
  240. // }
  241. // else
  242. // {
  243. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  244. //
  245. // }
  246. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  247. // if( subjson!=nil /*&& !active*/)
  248. // {
  249. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  250. // for(int l=0;l<sub_count;l++)
  251. // {
  252. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  253. //
  254. //
  255. //
  256. //
  257. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  258. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  259. // else
  260. // {
  261. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  262. // self.cancommit = false;
  263. // }
  264. // }
  265. //
  266. //
  267. //
  268. // }
  269. // }
  270. // else
  271. // if([[itemjson valueForKey:@"control"] isEqualToString:@"img"])
  272. // {
  273. // if([itemjson valueForKey:@"avalue"]!=nil && ![[itemjson valueForKey:@"avalue"]isEqualToString:@""])
  274. // [upparams setValue:[itemjson valueForKey:@"avalue"] forKey:[itemjson valueForKey:@"name"]];
  275. // else
  276. // {
  277. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  278. // self.cancommit = false;
  279. // }
  280. // }
  281. // else
  282. // {
  283. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  284. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  285. // else
  286. // {
  287. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  288. // self.cancommit = false;
  289. // }
  290. // }
  291. // upparams= [self subitem_param:itemjson addto:upparams ];
  292. // }
  293. // }
  294. // if(self.cancommit==false)
  295. // {
  296. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Some requried field is missing" message:@"Fields with * mark can not be empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  297. //
  298. //// [alert show];
  299. //
  300. //
  301. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  302. //
  303. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  304. // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  305. // //[self.editorTable reloadData ];
  306. // [self.editorTable reloadData];
  307. // return;
  308. // }
  309. NSMutableDictionary* upparams = [self check_cancommit:true];
  310. if(self.cancommit==false)
  311. return;
  312. if(self.returnValue)
  313. self.returnValue(upparams);
  314. [self.navigationController popViewControllerAnimated:false];
  315. }
  316. /*
  317. #pragma mark - Navigation
  318. // In a storyboard-based application, you will often want to do a little preparation before navigation
  319. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  320. // Get the new view controller using [segue destinationViewController].
  321. // Pass the selected object to the new view controller.
  322. }
  323. */
  324. #pragma mark - Urgency
  325. -(void) viewWillDisappear:(BOOL)animated
  326. {
  327. [super viewWillDisappear:animated];
  328. [self cancel_urgency_timer];
  329. }
  330. - (void)dealloc {
  331. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  332. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  333. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  334. }
  335. - (void)start_urgency_timer {
  336. if (!self.editable) {
  337. return;
  338. }
  339. __weak typeof(self) weakSelf = self;
  340. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  341. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  342. #ifdef OFFLINE_MODE
  343. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  344. #endif
  345. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  346. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  347. // DebugLog(@"timer start....");
  348. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  349. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  350. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  351. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  352. }];
  353. }
  354. - (void)cancel_urgency_timer {
  355. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  356. }
  357. @end