CustomerInfoViewController.m 28 KB

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