TearSheetParamViewController.m 29 KB

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