CustomerInfoViewController.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. //
  2. // CustomerInfoViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 9/10/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CustomerInfoViewController.h"
  9. #import "RANetwork.h"
  10. #import "CustomerEditViewController.h"
  11. #import "MainViewController.h"
  12. #import "JKTimerManager.h"
  13. @interface CustomerInfoViewController ()
  14. @end
  15. @implementation CustomerInfoViewController
  16. - (void)onEditClick:(id)sender {
  17. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  18. [params setValue:self.contactId forKey:@"contact_id"];
  19. CustomerEditViewController * cuseditVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CustomerEditViewController"];
  20. cuseditVC.bnewcustomer=false;
  21. cuseditVC.url_type = URL_REMOTE;
  22. cuseditVC.request_url=URL_EDIT_CUSTOMER;
  23. cuseditVC.params = params;
  24. cuseditVC.delegate=self;
  25. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  26. [self.navigationController pushViewController:cuseditVC animated:false];
  27. }
  28. - (void)onAssignClick:(id)sender {
  29. [self.lastedit endEditing:true];
  30. [self.lasttextview endEditing:true];
  31. // [self.navigationController popViewControllerAnimated:(false)];
  32. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  33. // NSMutableDictionary* data = [[self.data_init objectForKey:@"customerInfo"] mutableCopy];
  34. for(int i=0;i<section_count;i++)
  35. {
  36. NSDictionary * sectionjson= [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] ;
  37. int count = [[sectionjson valueForKey:@"count"] intValue];
  38. for(int j=0;j<count;j++)
  39. {
  40. NSDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]];
  41. //NSObject* obj=[itemjson valueForKey:@"name"];
  42. NSString* name = itemjson[@"name"];//[[ valueForKey:@"name"] stringValue];
  43. // DebugLog(@"%@",name.class);
  44. // DebugLog(@"%@",self.data_init.class);
  45. // DebugLog(@"%@",NSDictionary.class);
  46. NSString* value = itemjson[@"value"];//[[itemjson valueForKey:@""] stringValue];
  47. //[self.data_init setValue:value forKey:name];
  48. self.data_init[name]=value;
  49. }
  50. }
  51. //---------------- construct customer_contact----------------------
  52. NSString* customer_first_name = [self.data_init valueForKey:@"customer_first_name"];
  53. if(customer_first_name==nil)
  54. customer_first_name=@"";
  55. NSString* customer_last_name= [self.data_init valueForKey:@"customer_last_name"];
  56. if(customer_last_name==nil)
  57. customer_last_name=@"";
  58. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  59. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  60. [self.data_init setValue:customer_contact forKey:@"customer_contact"];
  61. //---------------- finish construct customer_contact----------------------
  62. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  63. if(self.update_order && appDelegate.order_code!=nil)
  64. {
  65. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  66. NSDictionary* editor_json = [RANetwork update_OrderCustomer:appDelegate.order_code customerinfo:self.data_init];
  67. dispatch_async(dispatch_get_main_queue(), ^{
  68. if([[editor_json valueForKey:@"result"] intValue]==2)
  69. {
  70. [self.navigationController popViewControllerAnimated:false];
  71. if(self.returnValue)
  72. {
  73. self.returnValue(self.data_init);
  74. }
  75. }
  76. else
  77. {
  78. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Update Order Customer Infomation" controller:self] ;
  79. }
  80. });
  81. });
  82. }
  83. else
  84. {
  85. [self.navigationController popViewControllerAnimated:false];
  86. if(self.returnValue)
  87. {
  88. self.returnValue(self.data_init);
  89. }
  90. }
  91. }
  92. - (void)onResetClick:(id)sender {
  93. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  94. if(appDelegate.order_code.length>0)
  95. {
  96. //当前已打开订单则关闭订单。
  97. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to release order and reset contact?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  98. //block代码块取代了delegate
  99. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  100. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  101. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  102. NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:ScreenCodeCustomerInfo];
  103. dispatch_async(dispatch_get_main_queue(), ^{
  104. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  105. if([[order_json valueForKey:@"result"] intValue]==2)
  106. {
  107. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  108. // appDelegate.order_code = nil;
  109. [appDelegate closeOrder];
  110. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  111. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  112. [((MainViewController*)appDelegate.main_vc) reloadContact:false immediately:false];
  113. [self.navigationController popToRootViewControllerAnimated:false];
  114. }
  115. else
  116. {
  117. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:self] ;
  118. }
  119. });
  120. });
  121. }];
  122. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  123. DebugLog(@"Cancel");
  124. }];
  125. [alertControl addAction:actionOne];
  126. [alertControl addAction:alertthree];
  127. [self presentViewController:alertControl animated:YES completion:nil];
  128. }
  129. else
  130. {
  131. //询问并清空当前的全局contact_id、customer
  132. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to reset contact?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  133. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  134. if(appDelegate.user_type!=USER_ROLE_CUSTOMER)
  135. {
  136. appDelegate.contact_id=nil;
  137. appDelegate.customerInfo = nil;
  138. }
  139. [self.navigationController popViewControllerAnimated:(false)];
  140. }];
  141. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  142. DebugLog(@"Cancel");
  143. }];
  144. [alertControl addAction:actionOne];
  145. [alertControl addAction:alertthree];
  146. [self presentViewController:alertControl animated:YES completion:nil];
  147. }
  148. }
  149. - (void)viewDidLoad {
  150. [super viewDidLoad];
  151. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  152. if(self.rightbtn_title!=nil)
  153. [ self.right_btn setTitle:self.rightbtn_title];
  154. // UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onBackClick:)];
  155. // // closeButton.title = @"Close";
  156. UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  157. style:UIBarButtonItemStylePlain
  158. target:self
  159. action:@selector( onBackClick:)];
  160. self.navigationItem.leftBarButtonItem = backButton;
  161. NSMutableArray * items = [[NSMutableArray alloc]init];
  162. self.btn_edit = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  163. style:UIBarButtonItemStylePlain
  164. target:self
  165. action:@selector(onEditClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
  166. // self.btn_edit.tintColor = UIColorFromRGB(0x996633);
  167. self.btn_assign = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"assign"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  168. style:UIBarButtonItemStylePlain
  169. target:self
  170. action:@selector(onAssignClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
  171. // self.btn_assign.tintColor = UIColorFromRGB(0x996633);
  172. self.btn_reset = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"reset"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  173. style:UIBarButtonItemStylePlain
  174. target:self
  175. action:@selector(onResetClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
  176. // self.btn_reset.tintColor = UIColorFromRGB(0x996633);
  177. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  178. if(self.edit_icon)
  179. [items addObject:self.btn_edit];
  180. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.order_code.length > 0 && ![Singleton sharedInstance].currentOrderIsMerged) {
  181. // shop order 隐藏assign
  182. } else {
  183. if(self.assig_icon)
  184. [items addObject:self.btn_assign];
  185. }
  186. if(self.reset_icon)
  187. [items addObject:self.btn_reset];
  188. self.navigationItem.rightBarButtonItems=items;
  189. if (self.data_init==nil) {
  190. [self request_fill];
  191. }
  192. else
  193. {
  194. [self fillData];
  195. }
  196. // Do any additional setup after loading the view.
  197. }
  198. - (void)onBackClick:(UIButton *)sender {
  199. [self.lastedit endEditing:true];
  200. [self.lasttextview endEditing:true];
  201. NSMutableDictionary* back_data = [self.data_init mutableCopy];
  202. // [self.navigationController popViewControllerAnimated:(false)];
  203. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  204. // NSMutableDictionary* data = [[self.data_init objectForKey:@"customerInfo"] mutableCopy];
  205. for(int i=0;i<section_count;i++)
  206. {
  207. NSDictionary * sectionjson= [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] ;
  208. int count = [[sectionjson valueForKey:@"count"] intValue];
  209. for(int j=0;j<count;j++)
  210. {
  211. NSDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]];
  212. NSString* name = [itemjson valueForKey:@"name"];
  213. NSString* value = [itemjson valueForKey:@"value"];
  214. [back_data setValue:value forKey:name];
  215. }
  216. }
  217. //---------------- construct customer_contact----------------------
  218. NSString* customer_first_name = [back_data valueForKey:@"customer_first_name"];
  219. if(customer_first_name==nil)
  220. customer_first_name=@"";
  221. NSString* customer_last_name= [back_data valueForKey:@"customer_last_name"];
  222. if(customer_last_name==nil)
  223. customer_last_name=@"";
  224. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  225. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  226. [back_data setValue:customer_contact forKey:@"customer_contact"];
  227. if(self.onClose)
  228. {
  229. self.onClose(back_data);
  230. }
  231. [self.navigationController popViewControllerAnimated:(false)];
  232. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  233. // ;
  234. // }];
  235. }
  236. -(void) request_fill
  237. {
  238. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Loading Contact information"];
  239. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  240. NSDictionary* editor_json = [RANetwork request_CustomerInfo:self.contactId];
  241. dispatch_async(dispatch_get_main_queue(), ^{
  242. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  243. if([[editor_json valueForKey:@"result"] intValue]==2)
  244. {
  245. self.data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
  246. [self fillData];
  247. self.btn_assign.enabled=true;
  248. }
  249. else
  250. {
  251. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
  252. self.btn_assign.enabled=false;
  253. }
  254. });
  255. });
  256. }
  257. - (void) fillData
  258. {
  259. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  260. // NSDictionary* data = [self.data_init objectForKey:@"customerInfo"];
  261. for(int i=0;i<section_count;i++)
  262. {
  263. NSMutableDictionary * sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  264. int count = [[sectionjson valueForKey:@"count"] intValue];
  265. for(int j=0;j<count;j++)
  266. {
  267. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  268. NSString* control=[itemjson valueForKey:@"control"];
  269. NSString* name = [itemjson valueForKey:@"name"];
  270. NSString* value = [self.data_init valueForKey:name];
  271. [itemjson setValue:value forKey:@"value"];
  272. if([control isEqualToString:@"img"])
  273. {
  274. {
  275. NSString* img_url = [itemjson valueForKey:@"img_url_0"];
  276. NSString* url_value = [self.data_init valueForKey:img_url];
  277. [itemjson setValue:url_value forKey:@"img_url_0"];
  278. }
  279. {
  280. NSString* img_url = [itemjson valueForKey:@"img_url_1"];
  281. NSString* url_value = [self.data_init valueForKey:img_url];
  282. [itemjson setValue:url_value forKey:@"img_url_1"];
  283. }
  284. {
  285. NSString* img_url = [itemjson valueForKey:@"img_url_2"];
  286. NSString* url_value = [self.data_init valueForKey:img_url];
  287. [itemjson setValue:url_value forKey:@"img_url_2"];
  288. }
  289. }
  290. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j]];
  291. }
  292. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i]];
  293. }
  294. self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
  295. // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  296. [self.editorTable reloadData];
  297. }
  298. //- (IBAction)onEditClick:(id)sender {
  299. //
  300. //
  301. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  302. //
  303. //
  304. // [params setValue:self.contactId forKey:@"contactId"];
  305. // CustomerEditViewController * cuseditVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CustomerEditViewController"];
  306. //
  307. // cuseditVC.bnewcustomer=false;
  308. // cuseditVC.url_type = URL_REMOTE;
  309. // cuseditVC.request_url=URL_EDIT_CUSTOMER;
  310. //
  311. // cuseditVC.params = params;
  312. //
  313. // cuseditVC.delegate=self;
  314. // //
  315. // // if(checked.count==count)
  316. // // {
  317. // // orderinfoVC.have_tail = true
  318. // // }
  319. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  320. // [self.navigationController pushViewController:cuseditVC animated:false];
  321. //
  322. //}
  323. //- (IBAction)onSetClick:(id)sender {
  324. //
  325. // [self.lastedit endEditing:true];
  326. // [self.lasttextview endEditing:true];
  327. //
  328. //
  329. //
  330. //
  331. //
  332. // // [self.navigationController popViewControllerAnimated:(false)];
  333. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  334. //// NSMutableDictionary* data = [[self.data_init objectForKey:@"customerInfo"] mutableCopy];
  335. //
  336. // for(int i=0;i<section_count;i++)
  337. // {
  338. // NSDictionary * sectionjson= [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] ;
  339. // int count = [[sectionjson valueForKey:@"count"] intValue];
  340. // for(int j=0;j<count;j++)
  341. // {
  342. // NSDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]];
  343. //
  344. // NSString* name = [itemjson valueForKey:@"name"];
  345. //
  346. // NSString* value = [itemjson valueForKey:@"value"];
  347. //
  348. // [self.data_init setValue:value forKey:name];
  349. //
  350. //
  351. //
  352. // }
  353. //
  354. // }
  355. // //---------------- construct customer_contact----------------------
  356. // NSString* customer_first_name = [self.data_init valueForKey:@"customer_first_name"];
  357. // if(customer_first_name==nil)
  358. // customer_first_name=@"";
  359. //
  360. // NSString* customer_last_name= [self.data_init valueForKey:@"customer_last_name"];
  361. // if(customer_last_name==nil)
  362. // customer_last_name=@"";
  363. // NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  364. // customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  365. // [self.data_init setValue:customer_contact forKey:@"customer_contact"];
  366. // //---------------- finish construct customer_contact----------------------
  367. //
  368. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  369. // if(self.update_order && appDelegate.order_code!=nil)
  370. // {
  371. //
  372. //
  373. //
  374. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  375. //
  376. // NSDictionary* editor_json = [iSalesNetwork update_OrderCustomer:appDelegate.order_code customerinfo:self.data_init];
  377. //
  378. // dispatch_async(dispatch_get_main_queue(), ^{
  379. //
  380. //
  381. // if([[editor_json valueForKey:@"result"] intValue]==2)
  382. // {
  383. //
  384. // [self.navigationController popViewControllerAnimated:false];
  385. // if(self.returnValue)
  386. // {
  387. //
  388. // self.returnValue(self.data_init);
  389. // }
  390. //
  391. //
  392. //
  393. // }
  394. // else
  395. // {
  396. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Update Order Customer Infomation" controller:self] ;
  397. // }
  398. //
  399. //
  400. //
  401. // });
  402. // });
  403. //
  404. //
  405. // }
  406. // else
  407. // {
  408. //
  409. // [self.navigationController popViewControllerAnimated:false];
  410. // if(self.returnValue)
  411. // {
  412. // self.returnValue(self.data_init);
  413. //
  414. // }
  415. // // [self.data_init setObject:data forKey:@"customerInfo"];
  416. //
  417. //
  418. // /*
  419. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  420. // appDelegate.contact_id=self.contactId;
  421. // appDelegate.customerInfo = self.data_init;
  422. // */
  423. //
  424. //// [self.navigationController popToRootViewControllerAnimated:false];
  425. // }
  426. //
  427. //
  428. //
  429. //}
  430. #pragma mark- img changed
  431. // image 改变时执行
  432. - (void) imgIsChanged:(NSString *)url_down url_up:(NSString *)url_up indexPath: (NSIndexPath *) indexPath{
  433. // int aaa = 0;
  434. // NSDictionary* aaa = self.content_data_download;
  435. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  436. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  437. NSString* cid=[self getValue:@"customer_cid"];
  438. NSDictionary* return_json = [RANetwork update_customer_img:cid img_url:url_up];
  439. dispatch_async(dispatch_get_main_queue(), ^{
  440. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  441. if([[return_json valueForKey:@"result"] intValue]==2)
  442. {
  443. int result=[[return_json valueForKey:@"result"] intValue];
  444. if(result==2)
  445. {
  446. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Upload successful." message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  447. [alert show];
  448. }
  449. }
  450. else
  451. {
  452. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  453. }
  454. });
  455. });
  456. // // DebugLog(@"Sender is = %@", url);
  457. //
  458. //
  459. //
  460. //
  461. // NSMutableDictionary* section_json=nil;
  462. //
  463. //
  464. // // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  465. // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  466. //
  467. // int refresh = [[item_json valueForKey:@"refresh"] intValue];
  468. //
  469. // NSString* subid=[item_json valueForKey:@"subid"];
  470. //
  471. // item_json[@"img_url"]=url_down;
  472. // item_json[@"avalue"]=url_up;
  473. //
  474. // if(subid==nil)
  475. // {
  476. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  477. // int count=0;
  478. //
  479. // count=[[section_json valueForKey:@"count"] intValue];
  480. //
  481. // for(int i=0;i<count;i++)
  482. // {
  483. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  484. // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  485. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  486. //
  487. //
  488. // }
  489. //
  490. // }
  491. // else
  492. // {
  493. // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  494. // int section = [(NSString*)idarr[0] intValue];
  495. // int item=[(NSString*)idarr[1] intValue];
  496. //
  497. //
  498. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  499. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  500. // item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  501. // [item_json setValue:@"true" forKey:@"dirty"];
  502. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  503. // }
  504. //
  505. //
  506. //
  507. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  508. //
  509. // self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  510. //
  511. // NSRange range = NSMakeRange(indexPath.section, 1);
  512. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  513. // // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  514. //
  515. //
  516. // if(refresh==1)
  517. // {
  518. // [self refresh];
  519. // }
  520. }
  521. - (void)didReceiveMemoryWarning {
  522. [super didReceiveMemoryWarning];
  523. // Dispose of any resources that can be recreated.
  524. }
  525. /*
  526. #pragma mark - Navigation
  527. // In a storyboard-based application, you will often want to do a little preparation before navigation
  528. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  529. // Get the new view controller using [segue destinationViewController].
  530. // Pass the selected object to the new view controller.
  531. }
  532. */
  533. #pragma mark - Urgency
  534. - (void)viewWillAppear:(BOOL)animated {
  535. [super viewWillAppear:animated];
  536. [self start_urgency_timer];
  537. }
  538. -(void) viewWillDisappear:(BOOL)animated
  539. {
  540. [super viewWillDisappear:animated];
  541. [self cancel_urgency_timer];
  542. }
  543. - (void)dealloc {
  544. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  545. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  546. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  547. }
  548. - (void)start_urgency_timer {
  549. if (!self.editable) {
  550. return;
  551. }
  552. __weak typeof(self) weakSelf = self;
  553. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  554. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  555. #ifdef OFFLINE_MODE
  556. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  557. #endif
  558. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  559. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  560. // DebugLog(@"timer start....");
  561. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  562. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  563. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  564. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  565. }];
  566. }
  567. - (void)cancel_urgency_timer {
  568. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  569. }
  570. @end