TearSheetParamViewController.m 31 KB

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