TearSheetParamViewController.m 32 KB

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