TearSheetParamViewController.m 30 KB

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