TearSheetParamViewController.m 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. //
  2. // TearSeetParamViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 11/11/15.
  6. // Copyright © 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "TearSheetParamViewController.h"
  9. #import "RANetwork.h"
  10. #import "RAPDFViewController.h"
  11. #import "MainViewController.h"
  12. #import "RASingleton.h"
  13. #import "TextUtils.h"
  14. #import "JKTimerManager.h"
  15. @interface TearSheetParamViewController ()
  16. @end
  17. @implementation TearSheetParamViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  22. style:UIBarButtonItemStylePlain
  23. target:self
  24. action:@selector(onCloseClick:)];
  25. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  26. // closeButton.title = @"Close";
  27. // closeButton.tintColor = UIColorFromRGB(0x996633);
  28. self.navigationItem.leftBarButtonItem = closeButton;
  29. UIBarButtonItem *previewbtn = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
  30. previewbtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"preview"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  31. style:UIBarButtonItemStylePlain
  32. target:self
  33. action:@selector(onPreviewClick:)];
  34. // previewbtn.tintColor = UIColorFromRGB(0x996633);
  35. UIBarButtonItem *savebtn = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
  36. savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  37. style:UIBarButtonItemStylePlain
  38. target:self
  39. action:@selector(onSaveClick:)];
  40. // savebtn.tintColor = UIColorFromRGB(0x996633);
  41. _savebtn = savebtn;
  42. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  43. fixedItem.width = 0.0f;
  44. NSMutableArray * items = [[NSMutableArray alloc]init];
  45. [items addObject:previewbtn];
  46. [items addObject:fixedItem];
  47. [items addObject:savebtn];
  48. // [items addObject:item2];
  49. self.navigationItem.rightBarButtonItems=items;
  50. // self.navigationItem.rightBarButtonItem = previewbtn;
  51. }
  52. - (void)didReceiveMemoryWarning {
  53. [super didReceiveMemoryWarning];
  54. // Dispose of any resources that can be recreated.
  55. }
  56. - (void)onCloseClick:(UIButton *)sender {
  57. [self.navigationController dismissViewControllerAnimated:true completion:^{
  58. ;
  59. }];
  60. }
  61. - (void)onPreviewClick:(UIButton *)sender {
  62. // add params check here.
  63. [self.lastedit endEditing:true];
  64. [self.lasttextview endEditing:true];
  65. // self.cancommit=true;
  66. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  67. // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  68. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  69. // for(int i=0;i<section_count;i++)
  70. // {
  71. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  72. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  73. // for(int j=0;j<item_count;j++)
  74. // {
  75. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  76. // NSString* key = [itemjson valueForKey:@"name"];
  77. // if(key==nil || key.length==0)
  78. // continue;
  79. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  80. // {
  81. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  82. // if([single_select isEqualToString:@"true"])
  83. // {
  84. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  85. // int count = [[cadejson valueForKey:@"count"] intValue];
  86. // bool setvalue = false;
  87. // for(int cc=0;cc<count;cc++)
  88. // {
  89. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  90. // if([[valjson valueForKey:@"check"]intValue]==1)
  91. // {
  92. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  93. // setvalue=true;
  94. // break;
  95. // }
  96. // }
  97. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  98. // {
  99. // self.cancommit = false;
  100. // }
  101. // }
  102. // else
  103. // {
  104. // //not support multi select for now;
  105. // }
  106. // /*
  107. // upparams setValue:itemjson forKey:<#(NSString *)#>
  108. //
  109. // */
  110. // }else
  111. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  112. // {
  113. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  114. // self.cancommit = false;
  115. // }
  116. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  117. // {
  118. // NSString* valuestr = [itemjson valueForKey:@"value"];
  119. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  120. //
  121. // NSString* value = [itemjson valueForKey:@"value"];
  122. // NSMutableDictionary* boolitem=nil;
  123. // NSMutableDictionary* subjson=nil;
  124. // if([value isEqualToString:@"true"])
  125. // {
  126. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  127. //
  128. // }
  129. // else
  130. // {
  131. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  132. //
  133. // }
  134. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  135. // if( subjson!=nil /*&& !active*/)
  136. // {
  137. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  138. // for(int l=0;l<sub_count;l++)
  139. // {
  140. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  141. //
  142. //
  143. //
  144. //
  145. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  146. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  147. // else
  148. // {
  149. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  150. // self.cancommit = false;
  151. // }
  152. // }
  153. //
  154. //
  155. //
  156. // }
  157. // }
  158. // else
  159. // {
  160. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  161. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  162. // else
  163. // {
  164. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  165. // self.cancommit = false;
  166. // }
  167. // }
  168. // upparams= [self subitem_param:itemjson addto:upparams ];
  169. // }
  170. // }
  171. // if(self.cancommit==false)
  172. // {
  173. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Some requried field is missing" message:@"Fields with * mark cannot be empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  174. //// //UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  175. //// [alert show];
  176. //
  177. //
  178. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  179. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  180. // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  181. // //[self.editorTable reloadData ];
  182. // [self.editorTable reloadData];
  183. // return;
  184. // }
  185. NSMutableDictionary* upparams = [self check_cancommit:true];
  186. if(self.cancommit==false)
  187. return;
  188. NSMutableString* pdf_url = [[self.content_data_download valueForKey:@"pdf_url"] mutableCopy];
  189. // DebugLog([RAUtils dict2string:self.content_data_download]);
  190. bool bremove=false;
  191. NSString* catelog_name= nil;
  192. NSString* internal_note= nil;
  193. NSArray *keys= [upparams allKeys];
  194. //遍历keys
  195. for(int i=0;i<[keys count];i++)
  196. {
  197. //得到当前key
  198. NSString *key=[keys objectAtIndex:i];
  199. if([key isEqualToString:@"remove_item"])
  200. {
  201. bremove=[[upparams valueForKey:key]boolValue];
  202. continue;
  203. }
  204. if([key isEqualToString:@"catalog_name"])
  205. {
  206. catelog_name=[upparams valueForKey:key];
  207. }
  208. if([key isEqualToString:@"internal_note"])
  209. {
  210. internal_note=[upparams valueForKey:key];
  211. }
  212. [pdf_url appendString:@"&"];
  213. [pdf_url appendString:key];
  214. //如果key不是pic,说明value是字符类型,比如name:Boris
  215. NSString* valuefrom = [upparams valueForKey:key];
  216. valuefrom = [NSString stringWithFormat:@"%@",valuefrom];
  217. [pdf_url appendString:@"="];
  218. // [pdf_url appendString:[valuefrom stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  219. // [pdf_url appendString:[valuefrom stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"`#%^{}\"[]|\\<> "]]];
  220. [pdf_url appendString:[valuefrom stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
  221. // NSString* value=[self getValue:valuefrom];
  222. // [ret setValue:value forKey:valuefrom];
  223. }
  224. upparams[@"pdfUrl"]=pdf_url;
  225. upparams[@"product_ids"]=self.product_ids;
  226. upparams[@"item_ids"]=self.item_ids;
  227. // pdf_url=[pdf_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  228. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
  229. PopWaitAlert * pop = [RAUtils waiting_pop:@"Processing" completion:nil];
  230. [RANetwork request_portfoliopreview:upparams completionHandler:^(NSMutableDictionary *result) {
  231. NSDictionary* editor_json = result;
  232. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  233. // [waitalert dismissViewControllerAnimated:YES completion:^{
  234. [pop hide];
  235. if([[editor_json valueForKey:@"result"] intValue]==2)
  236. {
  237. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  238. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  239. NSString* url = [editor_json valueForKey:@"pdf_path"];
  240. NSString* path = [editor_json valueForKey:@"pdf_real_path"];
  241. bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
  242. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  243. ViewController.url = url;
  244. ViewController.canSave = true;
  245. ViewController.isLocalfile=isLocalFile;
  246. // ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
  247. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
  248. ViewController.save_name =catelog_name;
  249. ViewController.save_note =internal_note;
  250. //ViewController.filename = catelog_name;
  251. NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
  252. if(company==nil)
  253. company=@"";
  254. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  255. // NSMutableArray* send_to = [[NSMutableArray alloc]init];
  256. // if(customer_email.length>0)
  257. // [send_to addObject:customer_email];
  258. // ViewController.mail_to = send_to;
  259. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  260. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  261. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  262. if(customer_email.length>0)
  263. {
  264. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  265. // customer_email compo
  266. // [send_to addObject:customer_email];
  267. }
  268. ViewController.mail_to = send_to;
  269. NSString* subject;
  270. // if (company.length==0) {
  271. // NSString* cur_time =[RAUtils current_date];
  272. subject =catelog_name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  273. // }
  274. // else
  275. // {
  276. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  277. // }
  278. // ViewController.attachment_name = [NSString stringWithFormat:@"%@.pdf",catelog_name];//[NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  279. ViewController.mail_subject = subject;
  280. // ViewController.onLoadSuccess =^(NSString* url)
  281. // {
  282. //
  283. // };
  284. ViewController.onSavePDF=^(NSString* name,NSString* file)
  285. {
  286. NSString* del_ids = nil;
  287. if(bremove)
  288. del_ids=[self.params valueForKey:@"item_ids"];
  289. #ifdef OFFLINE_MODE
  290. if (appDelegate.offline_mode)
  291. {
  292. [upparams setValue:url forKey:@"pdfPath"];
  293. }
  294. else
  295. #endif
  296. {
  297. [upparams setValue:path forKey:@"pdfPath"];
  298. }
  299. [upparams setValue:name forKey:@"pdfName"];
  300. [upparams setValue:internal_note forKey:@"pdfNote"];
  301. [upparams setValue:del_ids forKey:@"itemIds"];
  302. [upparams setValue:pdf_url forKey:@"configureParams"];
  303. // __block UIAlertController * waitalert_save = [RAUtils waiting_alert:self title:@"Saving..." completion:^{
  304. PopWaitAlert * pop = [RAUtils waiting_pop:@"Saving..." completion:nil];
  305. [RANetwork request_save_portfolio:upparams completionHandler:^(NSMutableDictionary *result) {
  306. NSDictionary* json =result;
  307. // [waitalert_save dismissViewControllerAnimated:YES completion:^{
  308. [pop hide];
  309. if([[json valueForKey:@"result"] intValue]==2)
  310. {
  311. [RAUtils message_box:@"Portfolio" message:@"Portfolio saved. You can find it from View Portfolios" completion:nil];
  312. // [RAUtils alert_view:nil title: ] ;
  313. [self.navigationController dismissViewControllerAnimated:true completion:^{
  314. #ifdef RA_NOTIFICATION
  315. [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  316. #else
  317. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  318. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  319. #endif
  320. // if(self.onDismiss)
  321. // self.onDismiss(catelog_name);
  322. }];
  323. }
  324. else
  325. {
  326. [RAUtils message_box:@"Save Portfolio" message:[json valueForKey:@"err_msg"] completion:nil];
  327. }
  328. // }];
  329. }];
  330. // }];
  331. };
  332. // ViewController. = self.function_name;
  333. // ViewController.behavior =BEHAVIOR_SEARCH;
  334. ViewController.hidenavi = false;
  335. [self.navigationController pushViewController:ViewController animated:YES];
  336. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  337. /*
  338. if(self.return_url)
  339. self.return_url(url,path,bremove);
  340. [self.navigationController dismissViewControllerAnimated:true completion:^{
  341. if(self.onDismiss)
  342. self.onDismiss(catelog_name);
  343. }];
  344. */
  345. }
  346. else
  347. {
  348. [RAUtils message_box:@"Create Portfolio" message:[editor_json valueForKey:@"err_msg"] completion:nil];
  349. }
  350. // }];
  351. }];
  352. }
  353. - (void)onSaveClick:(UIButton *)sender {
  354. // add params check here.
  355. [self.lastedit endEditing:true];
  356. [self.lasttextview endEditing:true];
  357. NSMutableDictionary* upparams = [self check_cancommit:true];
  358. if(self.cancommit==false)
  359. return;
  360. NSMutableString* pdf_url = [[self.content_data_download valueForKey:@"pdf_url"] mutableCopy];
  361. // DebugLog([RAUtils dict2string:self.content_data_download]);
  362. bool bremove=false;
  363. NSString* catelog_name= nil;
  364. NSString* internal_note = nil;
  365. NSArray *keys= [upparams allKeys];
  366. //遍历keys
  367. for(int i=0;i<[keys count];i++)
  368. {
  369. //得到当前key
  370. NSString *key=[keys objectAtIndex:i];
  371. if([key isEqualToString:@"remove_item"])
  372. {
  373. bremove=[[upparams valueForKey:key]boolValue];
  374. continue;
  375. }
  376. if([key isEqualToString:@"catalog_name"])
  377. {
  378. catelog_name=[upparams valueForKey:key];
  379. }
  380. if([key isEqualToString:@"internal_note"])
  381. {
  382. internal_note=[upparams valueForKey:key];
  383. }
  384. [pdf_url appendString:@"&"];
  385. [pdf_url appendString:key];
  386. //如果key不是pic,说明value是字符类型,比如name:Boris
  387. NSString* valuefrom = [upparams valueForKey:key];
  388. valuefrom = [NSString stringWithFormat:@"%@",valuefrom];
  389. [pdf_url appendString:@"="];
  390. // [pdf_url appendString:[valuefrom stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  391. //
  392. [pdf_url appendString:[valuefrom stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
  393. // NSString* value=[self getValue:valuefrom];
  394. // [ret setValue:value forKey:valuefrom];
  395. }
  396. upparams[@"product_ids"]=self.product_ids;
  397. upparams[@"item_ids"]=self.item_ids;
  398. __block NSString* saveName = catelog_name;
  399. __block NSString* saveNote = internal_note;
  400. NSString* del_ids = nil;
  401. if(bremove)
  402. del_ids=[self.params valueForKey:@"item_ids"];
  403. // pdf_url=[pdf_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  404. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Save pdf" message:nil preferredStyle:UIAlertControllerStyleAlert];
  405. //block代码块取代了delegate
  406. [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  407. textField.text = saveName;
  408. }];
  409. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  410. UITextField *name = alertControl.textFields.firstObject;
  411. if(name.text.length==0)
  412. {
  413. [RAUtils message_box:@"Name is missing" message:@"Cannot save without name. Save canceled." completion:nil];
  414. }
  415. else
  416. {
  417. saveName = name.text;
  418. self.savebtn.enabled =false;
  419. [upparams setValue:pdf_url forKey:@"pdfUrl"];
  420. [upparams setValue:saveName forKey:@"pdfName"];
  421. [upparams setValue:del_ids forKey:@"itemIds"];
  422. [upparams setValue:saveNote forKey:@"pdfNote"];
  423. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
  424. PopWaitAlert * pop = [RAUtils waiting_pop:@"Processing" completion:nil];
  425. [RANetwork request_save_portfoliodirectly:upparams completionHandler:^(NSMutableDictionary *result) {
  426. NSDictionary* editor_json =result;
  427. // [waitalert dismissViewControllerAnimated:YES completion:^{
  428. [pop hide];
  429. if([[editor_json valueForKey:@"result"] intValue]==2)
  430. {
  431. // [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
  432. NSString* url = [editor_json valueForKey:@"pdf_path"];
  433. bool isLocalFile = [editor_json valueForKey:@"isLocalFile"];
  434. [self.navigationController dismissViewControllerAnimated:true completion:^{
  435. #ifdef RA_NOTIFICATION
  436. [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  437. #else
  438. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  439. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  440. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  441. #endif
  442. if(self.onSaved)
  443. self.onSaved(url,saveName,isLocalFile);
  444. }];
  445. }
  446. else
  447. {
  448. [RAUtils message_box:@"Create Portfolio" message:[editor_json valueForKey:@"err_msg"] completion:nil];
  449. }
  450. // }];
  451. }];
  452. // }];
  453. }
  454. }];
  455. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  456. DebugLog(@"Cancel");
  457. }];
  458. [alertControl addAction:actionOne];
  459. [alertControl addAction:alertthree];
  460. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  461. [self presentViewController:alertControl animated:YES completion:nil];
  462. }
  463. /*
  464. #pragma mark - Navigation
  465. // In a storyboard-based application, you will often want to do a little preparation before navigation
  466. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  467. // Get the new view controller using [segue destinationViewController].
  468. // Pass the selected object to the new view controller.
  469. }
  470. */
  471. #pragma mark - Urgency
  472. - (void)viewWillAppear:(BOOL)animated {
  473. [super viewWillAppear:animated];
  474. [self start_urgency_timer];
  475. }
  476. -(void) viewWillDisappear:(BOOL)animated
  477. {
  478. [super viewWillDisappear:animated];
  479. [self cancel_urgency_timer];
  480. }
  481. - (void)dealloc {
  482. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  483. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  484. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  485. }
  486. - (void)start_urgency_timer {
  487. if (!self.editable) {
  488. return;
  489. }
  490. __weak typeof(self) weakSelf = self;
  491. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  492. [appDelegate.urgencyDic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  493. #ifdef OFFLINE_MODE
  494. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  495. #endif
  496. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  497. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  498. // DebugLog(@"timer start....");
  499. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  500. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  501. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  502. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  503. }];
  504. }
  505. - (void)cancel_urgency_timer {
  506. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  507. }
  508. @end