TearSheetParamViewController.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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. [upparams setValue:url forKey:@"pdfPath"];
  285. [upparams setValue:name forKey:@"pdfName"];
  286. [upparams setValue:internal_note forKey:@"pdfNote"];
  287. [upparams setValue:del_ids forKey:@"itemIds"];
  288. [upparams setValue:pdf_url forKey:@"configureParams"];
  289. NSDictionary* json = [iSalesNetwork save_TearSheet:upparams];
  290. dispatch_async(dispatch_get_main_queue(), ^{
  291. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  292. if([[json valueForKey:@"result"] intValue]==2)
  293. {
  294. [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
  295. [self.navigationController dismissViewControllerAnimated:true completion:^{
  296. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  297. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  298. // if(self.onDismiss)
  299. // self.onDismiss(catelog_name);
  300. }];
  301. }
  302. else
  303. {
  304. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
  305. }
  306. });
  307. });
  308. };
  309. // ViewController. = self.function_name;
  310. // ViewController.behavior =BEHAVIOR_SEARCH;
  311. ViewController.hidenavi = false;
  312. [self.navigationController pushViewController:ViewController animated:YES];
  313. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  314. /*
  315. if(self.return_url)
  316. self.return_url(url,path,bremove);
  317. [self.navigationController dismissViewControllerAnimated:true completion:^{
  318. if(self.onDismiss)
  319. self.onDismiss(catelog_name);
  320. }];
  321. */
  322. }
  323. else
  324. {
  325. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
  326. }
  327. });
  328. });
  329. }
  330. - (void)onSaveClick:(UIButton *)sender {
  331. // add params check here.
  332. [self.lastedit endEditing:true];
  333. [self.lasttextview endEditing:true];
  334. // self.cancommit=true;
  335. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  336. // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  337. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  338. // for(int i=0;i<section_count;i++)
  339. // {
  340. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  341. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  342. // for(int j=0;j<item_count;j++)
  343. // {
  344. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  345. // NSString* key = [itemjson valueForKey:@"name"];
  346. // if(key==nil || key.length==0)
  347. // continue;
  348. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  349. // {
  350. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  351. // if([single_select isEqualToString:@"true"])
  352. // {
  353. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  354. // int count = [[cadejson valueForKey:@"count"] intValue];
  355. // bool setvalue = false;
  356. // for(int cc=0;cc<count;cc++)
  357. // {
  358. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  359. // if([[valjson valueForKey:@"check"]intValue]==1)
  360. // {
  361. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  362. // setvalue=true;
  363. // break;
  364. // }
  365. // }
  366. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  367. // {
  368. // self.cancommit = false;
  369. // }
  370. // }
  371. // else
  372. // {
  373. // //not support multi select for now;
  374. // }
  375. // /*
  376. // upparams setValue:itemjson forKey:<#(NSString *)#>
  377. //
  378. // */
  379. // }else
  380. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  381. // {
  382. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  383. // self.cancommit = false;
  384. // }
  385. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  386. // {
  387. // NSString* valuestr = [itemjson valueForKey:@"value"];
  388. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  389. //
  390. // NSString* value = [itemjson valueForKey:@"value"];
  391. // NSMutableDictionary* boolitem=nil;
  392. // NSMutableDictionary* subjson=nil;
  393. // if([value isEqualToString:@"true"])
  394. // {
  395. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  396. //
  397. // }
  398. // else
  399. // {
  400. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  401. //
  402. // }
  403. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  404. // if( subjson!=nil /*&& !active*/)
  405. // {
  406. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  407. // for(int l=0;l<sub_count;l++)
  408. // {
  409. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  410. //
  411. //
  412. //
  413. //
  414. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  415. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  416. // else
  417. // {
  418. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  419. // self.cancommit = false;
  420. // }
  421. // }
  422. //
  423. //
  424. //
  425. // }
  426. // }
  427. // else
  428. // {
  429. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  430. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  431. // else
  432. // {
  433. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  434. // self.cancommit = false;
  435. // }
  436. // }
  437. // upparams= [self subitem_param:itemjson addto:upparams ];
  438. // }
  439. // }
  440. // if(self.cancommit==false)
  441. // {
  442. //// 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];
  443. //// //UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  444. //// [alert show];
  445. //
  446. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  447. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  448. // //NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  449. // //[self.editorTable reloadData ];
  450. // [self.editorTable reloadData];
  451. // return;
  452. // }
  453. NSMutableDictionary* upparams = [self check_cancommit:true];
  454. if(self.cancommit==false)
  455. return;
  456. NSMutableString* pdf_url = [[self.content_data_download valueForKey:@"pdf_url"] mutableCopy];
  457. // NSLog([RAUtils dict2string:self.content_data_download]);
  458. bool bremove=false;
  459. NSString* catelog_name= nil;
  460. NSString* internal_note = nil;
  461. NSArray *keys= [upparams allKeys];
  462. //遍历keys
  463. for(int i=0;i<[keys count];i++)
  464. {
  465. //得到当前key
  466. NSString *key=[keys objectAtIndex:i];
  467. if([key isEqualToString:@"remove_item"])
  468. {
  469. bremove=[[upparams valueForKey:key]boolValue];
  470. continue;
  471. }
  472. if([key isEqualToString:@"catalog_name"])
  473. {
  474. catelog_name=[upparams valueForKey:key];
  475. }
  476. if([key isEqualToString:@"internal_note"])
  477. {
  478. internal_note=[upparams valueForKey:key];
  479. }
  480. [pdf_url appendString:@"&"];
  481. [pdf_url appendString:key];
  482. //如果key不是pic,说明value是字符类型,比如name:Boris
  483. NSString* valuefrom = [upparams valueForKey:key];
  484. valuefrom = [NSString stringWithFormat:@"%@",valuefrom];
  485. [pdf_url appendString:@"="];
  486. [pdf_url appendString:[valuefrom stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  487. // NSString* value=[self getValue:valuefrom];
  488. // [ret setValue:value forKey:valuefrom];
  489. }
  490. upparams[@"product_ids"]=self.product_ids;
  491. upparams[@"item_ids"]=self.item_ids;
  492. __block NSString* saveName = catelog_name;
  493. __block NSString* saveNote = internal_note;
  494. NSString* del_ids = nil;
  495. if(bremove)
  496. del_ids=[self.params valueForKey:@"item_ids"];
  497. // pdf_url=[pdf_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  498. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Save pdf" message:nil preferredStyle:UIAlertControllerStyleAlert];
  499. //block代码块取代了delegate
  500. [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  501. textField.text = saveName;
  502. }];
  503. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  504. UITextField *name = alertControl.textFields.firstObject;
  505. if(name.text.length==0)
  506. {
  507. [RAUtils message_alert:@"Cannot save without name. Save canceled." title:@"Name is missing" controller:self];
  508. }
  509. else
  510. {
  511. saveName = name.text;
  512. _savebtn.enabled =false;
  513. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Processing"];
  514. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  515. [upparams setValue:pdf_url forKey:@"pdfUrl"];
  516. [upparams setValue:saveName forKey:@"pdfName"];
  517. [upparams setValue:del_ids forKey:@"itemIds"];
  518. [upparams setValue:saveNote forKey:@"pdfNote"];
  519. NSDictionary* editor_json = [iSalesNetwork direct_save_TearSheet:upparams];
  520. dispatch_async(dispatch_get_main_queue(), ^{
  521. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  522. if([[editor_json valueForKey:@"result"] intValue]==2)
  523. {
  524. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  525. // [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
  526. NSString* url = [editor_json valueForKey:@"pdf_path"];
  527. bool isLocalFile = [editor_json valueForKey:@"isLocalFile"];
  528. [self.navigationController dismissViewControllerAnimated:true completion:^{
  529. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  530. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  531. if(self.onSaved)
  532. self.onSaved(url,saveName,isLocalFile);
  533. }];
  534. }
  535. else
  536. {
  537. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
  538. }
  539. });
  540. });
  541. }
  542. }];
  543. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  544. NSLog(@"Cancel");
  545. }];
  546. [alertControl addAction:actionOne];
  547. [alertControl addAction:alertthree];
  548. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  549. [self presentViewController:alertControl animated:YES completion:nil];
  550. }
  551. /*
  552. #pragma mark - Navigation
  553. // In a storyboard-based application, you will often want to do a little preparation before navigation
  554. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  555. // Get the new view controller using [segue destinationViewController].
  556. // Pass the selected object to the new view controller.
  557. }
  558. */
  559. @end