TearSheetParamViewController.m 32 KB

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