ContactAdvanceSearchViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. [self fillData];
  40. // Do any additional setup after loading the view.
  41. }
  42. - (void)didReceiveMemoryWarning {
  43. [super didReceiveMemoryWarning];
  44. // Dispose of any resources that can be recreated.
  45. }
  46. - (void)onBackClick:(UIButton *)sender {
  47. [self.navigationController popViewControllerAnimated:(false)];
  48. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  49. // ;
  50. // }];
  51. }
  52. - (IBAction)onCloseClick:(id)sender {
  53. [self dismissViewControllerAnimated:true completion:nil];
  54. }
  55. -(void) request_fill
  56. {
  57. }
  58. - (void) fillData
  59. {
  60. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  61. // NSDictionary* data = [self.data_init objectForKey:@"customerInfo"];
  62. for(int i=0;i<section_count;i++)
  63. {
  64. NSMutableDictionary * sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  65. int count = [[sectionjson valueForKey:@"count"] intValue];
  66. for(int j=0;j<count;j++)
  67. {
  68. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  69. NSString* control=[itemjson valueForKey:@"control"];
  70. NSString* name = [itemjson valueForKey:@"name"];
  71. NSString* value = [self.data_init valueForKey:name];
  72. [itemjson setValue:value forKey:@"value"];
  73. if([control isEqualToString:@"img"])
  74. {
  75. {
  76. NSString* img_url = [itemjson valueForKey:@"img_url_0"];
  77. NSString* url_value = [self.data_init valueForKey:img_url];
  78. [itemjson setValue:url_value forKey:@"img_url_0"];
  79. }
  80. {
  81. NSString* img_url = [itemjson valueForKey:@"img_url_1"];
  82. NSString* url_value = [self.data_init valueForKey:img_url];
  83. [itemjson setValue:url_value forKey:@"img_url_1"];
  84. }
  85. {
  86. NSString* img_url = [itemjson valueForKey:@"img_url_2"];
  87. NSString* url_value = [self.data_init valueForKey:img_url];
  88. [itemjson setValue:url_value forKey:@"img_url_2"];
  89. }
  90. }
  91. else if([control isEqualToString:@"enum"])
  92. {
  93. // NSMutableDictionary * cadedate = [itemjson objectForKey:@"cadedate"];
  94. NSArray* checked = [value componentsSeparatedByString:NSLocalizedString(@",", nil)];
  95. NSMutableDictionary* cadejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
  96. int count = [[cadejson valueForKey:@"count"] intValue];
  97. // bool setvalue = false;
  98. for(int cc=0;cc<count;cc++)
  99. {
  100. NSMutableDictionary* valjson=[[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]] mutableCopy];
  101. NSString* value_id=[NSString stringWithFormat:@"%@",[valjson valueForKey:@"value_id"]];
  102. int index=(int)[checked indexOfObject:value_id];
  103. if(NSNotFound!=index&& checked!=nil)
  104. {
  105. valjson[@"check"]=[NSNumber numberWithInt:1];
  106. cadejson[[NSString stringWithFormat:@"val_%d",cc]]=valjson;
  107. }
  108. }
  109. itemjson [@"cadedate"]= cadejson;
  110. }
  111. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j]];
  112. }
  113. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i]];
  114. }
  115. self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
  116. // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  117. [self.editorTable reloadData];
  118. }
  119. - (IBAction)onSearchClick:(id)sender {
  120. // add params check here.
  121. [self.lastedit endEditing:true];
  122. [self.lasttextview endEditing:true];
  123. // self.cancommit=true;
  124. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  125. // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  126. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  127. // for(int i=0;i<section_count;i++)
  128. // {
  129. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  130. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  131. // for(int j=0;j<item_count;j++)
  132. // {
  133. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  134. // NSString* key = [itemjson valueForKey:@"name"];
  135. // if(key==nil || key.length==0)
  136. // continue;
  137. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  138. // {
  139. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  140. // if([single_select isEqualToString:@"true"])
  141. // {
  142. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  143. // int count = [[cadejson valueForKey:@"count"] intValue];
  144. // bool setvalue = false;
  145. // for(int cc=0;cc<count;cc++)
  146. // {
  147. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  148. // if([[valjson valueForKey:@"check"]intValue]==1)
  149. // {
  150. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  151. // setvalue=true;
  152. // break;
  153. // }
  154. // }
  155. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  156. // {
  157. // self.cancommit = false;
  158. // }
  159. // }
  160. // else
  161. // {
  162. //
  163. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  164. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  165. // int count = [[cadejson valueForKey:@"count"] intValue];
  166. // // bool setvalue = false;
  167. // for(int cc=0;cc<count;cc++)
  168. // {
  169. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  170. // if([[valjson valueForKey:@"check"]intValue]==1)
  171. // {
  172. //
  173. // [checked addObject:[NSNumber numberWithInt:[[valjson valueForKey:@"value_id"] intValue]]];
  174. // // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  175. // // setvalue=true;
  176. // // break;
  177. // }
  178. // }
  179. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"]&&checked.count==0)
  180. // {
  181. // self.cancommit = false;
  182. // }
  183. // else
  184. // {
  185. // NSString * string = [checked componentsJoinedByString:@","];
  186. // [upparams setValue:string forKey:[itemjson valueForKey:@"name"]];
  187. // }
  188. // }
  189. // /*
  190. // upparams setValue:itemjson forKey:<#(NSString *)#>
  191. //
  192. // */
  193. // }else
  194. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  195. // {
  196. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  197. // self.cancommit = false;
  198. // }
  199. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  200. // {
  201. // NSString* valuestr = [itemjson valueForKey:@"value"];
  202. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  203. //
  204. // NSString* value = [itemjson valueForKey:@"value"];
  205. // NSMutableDictionary* boolitem=nil;
  206. // NSMutableDictionary* subjson=nil;
  207. // if([value isEqualToString:@"true"])
  208. // {
  209. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  210. //
  211. // }
  212. // else
  213. // {
  214. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  215. //
  216. // }
  217. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  218. // if( subjson!=nil /*&& !active*/)
  219. // {
  220. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  221. // for(int l=0;l<sub_count;l++)
  222. // {
  223. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  224. //
  225. //
  226. //
  227. //
  228. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  229. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  230. // else
  231. // {
  232. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  233. // self.cancommit = false;
  234. // }
  235. // }
  236. //
  237. //
  238. //
  239. // }
  240. // }
  241. // else
  242. // if([[itemjson valueForKey:@"control"] isEqualToString:@"img"])
  243. // {
  244. // if([itemjson valueForKey:@"avalue"]!=nil && ![[itemjson valueForKey:@"avalue"]isEqualToString:@""])
  245. // [upparams setValue:[itemjson valueForKey:@"avalue"] forKey:[itemjson valueForKey:@"name"]];
  246. // else
  247. // {
  248. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  249. // self.cancommit = false;
  250. // }
  251. // }
  252. // else
  253. // {
  254. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  255. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  256. // else
  257. // {
  258. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  259. // self.cancommit = false;
  260. // }
  261. // }
  262. // upparams= [self subitem_param:itemjson addto:upparams ];
  263. // }
  264. // }
  265. // if(self.cancommit==false)
  266. // {
  267. //// 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];
  268. //
  269. //// [alert show];
  270. //
  271. //
  272. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  273. //
  274. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  275. // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  276. // //[self.editorTable reloadData ];
  277. // [self.editorTable reloadData];
  278. // return;
  279. // }
  280. NSMutableDictionary* upparams = [self check_cancommit:true];
  281. if(self.cancommit==false)
  282. return;
  283. if(self.returnValue)
  284. self.returnValue(upparams);
  285. [self.navigationController popViewControllerAnimated:false];
  286. }
  287. /*
  288. #pragma mark - Navigation
  289. // In a storyboard-based application, you will often want to do a little preparation before navigation
  290. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  291. // Get the new view controller using [segue destinationViewController].
  292. // Pass the selected object to the new view controller.
  293. }
  294. */
  295. #pragma mark - Urgency
  296. -(void) viewWillDisappear:(BOOL)animated
  297. {
  298. [super viewWillDisappear:animated];
  299. [self cancel_urgency_timer];
  300. }
  301. - (void)dealloc {
  302. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  303. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  304. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  305. }
  306. - (void)start_urgency_timer {
  307. if (!self.editable) {
  308. return;
  309. }
  310. __weak typeof(self) weakSelf = self;
  311. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  312. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  313. #ifdef OFFLINE_MODE
  314. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  315. #endif
  316. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  317. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  318. // DebugLog(@"timer start....");
  319. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  320. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  321. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  322. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  323. }];
  324. }
  325. - (void)cancel_urgency_timer {
  326. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  327. }
  328. @end