ContactAdvanceSearchViewController.m 16 KB

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