TearSheetParamViewController.m 34 KB

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