TearSheetParamViewController.m 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  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. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" 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 dismissWithClickedButtonIndex:0 animated:FALSE];
  231. if([[editor_json valueForKey:@"result"] intValue]==2)
  232. {
  233. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  234. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  235. NSString* url = [editor_json valueForKey:@"pdf_path"];
  236. NSString* path = [editor_json valueForKey:@"pdf_real_path"];
  237. bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
  238. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  239. ViewController.url = url;
  240. ViewController.canSave = true;
  241. ViewController.isLocalfile=isLocalFile;
  242. // ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
  243. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
  244. ViewController.save_name =catelog_name;
  245. ViewController.save_note =internal_note;
  246. //ViewController.filename = catelog_name;
  247. NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
  248. if(company==nil)
  249. company=@"";
  250. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  251. // NSMutableArray* send_to = [[NSMutableArray alloc]init];
  252. // if(customer_email.length>0)
  253. // [send_to addObject:customer_email];
  254. // ViewController.mail_to = send_to;
  255. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  256. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  257. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  258. if(customer_email.length>0)
  259. {
  260. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  261. // customer_email compo
  262. // [send_to addObject:customer_email];
  263. }
  264. ViewController.mail_to = send_to;
  265. NSString* subject;
  266. // if (company.length==0) {
  267. // NSString* cur_time =[RAUtils current_date];
  268. subject =catelog_name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  269. // }
  270. // else
  271. // {
  272. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  273. // }
  274. // ViewController.attachment_name = [NSString stringWithFormat:@"%@.pdf",catelog_name];//[NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  275. ViewController.mail_subject = subject;
  276. // ViewController.onLoadSuccess =^(NSString* url)
  277. // {
  278. //
  279. // };
  280. ViewController.onSavePDF=^(NSString* name,NSString* file)
  281. {
  282. NSString* del_ids = nil;
  283. if(bremove)
  284. del_ids=[self.params valueForKey:@"item_ids"];
  285. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Saving..."];
  286. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  287. #ifdef OFFLINE_MODE
  288. if (appDelegate.offline_mode)
  289. {
  290. [upparams setValue:url forKey:@"pdfPath"];
  291. }
  292. else
  293. #endif
  294. {
  295. [upparams setValue:path forKey:@"pdfPath"];
  296. }
  297. [upparams setValue:name forKey:@"pdfName"];
  298. [upparams setValue:internal_note forKey:@"pdfNote"];
  299. [upparams setValue:del_ids forKey:@"itemIds"];
  300. [upparams setValue:pdf_url forKey:@"configureParams"];
  301. NSDictionary* json = [RANetwork save_TearSheet:upparams];
  302. dispatch_async(dispatch_get_main_queue(), ^{
  303. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  304. if([[json valueForKey:@"result"] intValue]==2)
  305. {
  306. [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
  307. [self.navigationController dismissViewControllerAnimated:true completion:^{
  308. #ifdef RA_NOTIFICATION
  309. [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  310. #else
  311. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  312. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  313. #endif
  314. // if(self.onDismiss)
  315. // self.onDismiss(catelog_name);
  316. }];
  317. }
  318. else
  319. {
  320. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
  321. }
  322. });
  323. });
  324. };
  325. // ViewController. = self.function_name;
  326. // ViewController.behavior =BEHAVIOR_SEARCH;
  327. ViewController.hidenavi = false;
  328. [self.navigationController pushViewController:ViewController animated:YES];
  329. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  330. /*
  331. if(self.return_url)
  332. self.return_url(url,path,bremove);
  333. [self.navigationController dismissViewControllerAnimated:true completion:^{
  334. if(self.onDismiss)
  335. self.onDismiss(catelog_name);
  336. }];
  337. */
  338. }
  339. else
  340. {
  341. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
  342. }
  343. });
  344. });
  345. }
  346. - (void)onSaveClick:(UIButton *)sender {
  347. // add params check here.
  348. [self.lastedit endEditing:true];
  349. [self.lasttextview endEditing:true];
  350. // self.cancommit=true;
  351. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  352. // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  353. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  354. // for(int i=0;i<section_count;i++)
  355. // {
  356. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  357. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  358. // for(int j=0;j<item_count;j++)
  359. // {
  360. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  361. // NSString* key = [itemjson valueForKey:@"name"];
  362. // if(key==nil || key.length==0)
  363. // continue;
  364. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  365. // {
  366. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  367. // if([single_select isEqualToString:@"true"])
  368. // {
  369. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  370. // int count = [[cadejson valueForKey:@"count"] intValue];
  371. // bool setvalue = false;
  372. // for(int cc=0;cc<count;cc++)
  373. // {
  374. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  375. // if([[valjson valueForKey:@"check"]intValue]==1)
  376. // {
  377. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  378. // setvalue=true;
  379. // break;
  380. // }
  381. // }
  382. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  383. // {
  384. // self.cancommit = false;
  385. // }
  386. // }
  387. // else
  388. // {
  389. // //not support multi select for now;
  390. // }
  391. // /*
  392. // upparams setValue:itemjson forKey:<#(NSString *)#>
  393. //
  394. // */
  395. // }else
  396. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  397. // {
  398. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  399. // self.cancommit = false;
  400. // }
  401. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  402. // {
  403. // NSString* valuestr = [itemjson valueForKey:@"value"];
  404. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  405. //
  406. // NSString* value = [itemjson valueForKey:@"value"];
  407. // NSMutableDictionary* boolitem=nil;
  408. // NSMutableDictionary* subjson=nil;
  409. // if([value isEqualToString:@"true"])
  410. // {
  411. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  412. //
  413. // }
  414. // else
  415. // {
  416. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  417. //
  418. // }
  419. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  420. // if( subjson!=nil /*&& !active*/)
  421. // {
  422. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  423. // for(int l=0;l<sub_count;l++)
  424. // {
  425. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  426. //
  427. //
  428. //
  429. //
  430. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  431. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  432. // else
  433. // {
  434. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  435. // self.cancommit = false;
  436. // }
  437. // }
  438. //
  439. //
  440. //
  441. // }
  442. // }
  443. // else
  444. // {
  445. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  446. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  447. // else
  448. // {
  449. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  450. // self.cancommit = false;
  451. // }
  452. // }
  453. // upparams= [self subitem_param:itemjson addto:upparams ];
  454. // }
  455. // }
  456. // if(self.cancommit==false)
  457. // {
  458. //// 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];
  459. //// //UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  460. //// [alert show];
  461. //
  462. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  463. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  464. // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  465. // //[self.editorTable reloadData ];
  466. // [self.editorTable reloadData];
  467. // return;
  468. // }
  469. NSMutableDictionary* upparams = [self check_cancommit:true];
  470. if(self.cancommit==false)
  471. return;
  472. NSMutableString* pdf_url = [[self.content_data_download valueForKey:@"pdf_url"] mutableCopy];
  473. // DebugLog([RAUtils dict2string:self.content_data_download]);
  474. bool bremove=false;
  475. NSString* catelog_name= nil;
  476. NSString* internal_note = nil;
  477. NSArray *keys= [upparams allKeys];
  478. //遍历keys
  479. for(int i=0;i<[keys count];i++)
  480. {
  481. //得到当前key
  482. NSString *key=[keys objectAtIndex:i];
  483. if([key isEqualToString:@"remove_item"])
  484. {
  485. bremove=[[upparams valueForKey:key]boolValue];
  486. continue;
  487. }
  488. if([key isEqualToString:@"catalog_name"])
  489. {
  490. catelog_name=[upparams valueForKey:key];
  491. }
  492. if([key isEqualToString:@"internal_note"])
  493. {
  494. internal_note=[upparams valueForKey:key];
  495. }
  496. [pdf_url appendString:@"&"];
  497. [pdf_url appendString:key];
  498. //如果key不是pic,说明value是字符类型,比如name:Boris
  499. NSString* valuefrom = [upparams valueForKey:key];
  500. valuefrom = [NSString stringWithFormat:@"%@",valuefrom];
  501. [pdf_url appendString:@"="];
  502. [pdf_url appendString:[valuefrom stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  503. // NSString* value=[self getValue:valuefrom];
  504. // [ret setValue:value forKey:valuefrom];
  505. }
  506. upparams[@"product_ids"]=self.product_ids;
  507. upparams[@"item_ids"]=self.item_ids;
  508. __block NSString* saveName = catelog_name;
  509. __block NSString* saveNote = internal_note;
  510. NSString* del_ids = nil;
  511. if(bremove)
  512. del_ids=[self.params valueForKey:@"item_ids"];
  513. // pdf_url=[pdf_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  514. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Save pdf" message:nil preferredStyle:UIAlertControllerStyleAlert];
  515. //block代码块取代了delegate
  516. [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  517. textField.text = saveName;
  518. }];
  519. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  520. UITextField *name = alertControl.textFields.firstObject;
  521. if(name.text.length==0)
  522. {
  523. [RAUtils message_alert:@"Cannot save without name. Save canceled." title:@"Name is missing" controller:self];
  524. }
  525. else
  526. {
  527. saveName = name.text;
  528. _savebtn.enabled =false;
  529. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Processing"];
  530. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  531. [upparams setValue:pdf_url forKey:@"pdfUrl"];
  532. [upparams setValue:saveName forKey:@"pdfName"];
  533. [upparams setValue:del_ids forKey:@"itemIds"];
  534. [upparams setValue:saveNote forKey:@"pdfNote"];
  535. NSDictionary* editor_json = [RANetwork direct_save_TearSheet:upparams];
  536. dispatch_async(dispatch_get_main_queue(), ^{
  537. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  538. if([[editor_json valueForKey:@"result"] intValue]==2)
  539. {
  540. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  541. // [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
  542. NSString* url = [editor_json valueForKey:@"pdf_path"];
  543. bool isLocalFile = [editor_json valueForKey:@"isLocalFile"];
  544. [self.navigationController dismissViewControllerAnimated:true completion:^{
  545. #ifdef RA_NOTIFICATION
  546. [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  547. #else
  548. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  549. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  550. #endif
  551. if(self.onSaved)
  552. self.onSaved(url,saveName,isLocalFile);
  553. }];
  554. }
  555. else
  556. {
  557. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
  558. }
  559. });
  560. });
  561. }
  562. }];
  563. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  564. DebugLog(@"Cancel");
  565. }];
  566. [alertControl addAction:actionOne];
  567. [alertControl addAction:alertthree];
  568. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  569. [self presentViewController:alertControl animated:YES completion:nil];
  570. }
  571. /*
  572. #pragma mark - Navigation
  573. // In a storyboard-based application, you will often want to do a little preparation before navigation
  574. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  575. // Get the new view controller using [segue destinationViewController].
  576. // Pass the selected object to the new view controller.
  577. }
  578. */
  579. #pragma mark - Urgency
  580. - (void)viewWillAppear:(BOOL)animated {
  581. [super viewWillAppear:animated];
  582. [self start_urgency_timer];
  583. }
  584. -(void) viewWillDisappear:(BOOL)animated
  585. {
  586. [super viewWillDisappear:animated];
  587. [self cancel_urgency_timer];
  588. }
  589. - (void)dealloc {
  590. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  591. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  592. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  593. }
  594. - (void)start_urgency_timer {
  595. if (!self.editable) {
  596. return;
  597. }
  598. __weak typeof(self) weakSelf = self;
  599. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  600. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  601. #ifdef OFFLINE_MODE
  602. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  603. #endif
  604. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  605. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  606. // DebugLog(@"timer start....");
  607. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  608. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  609. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  610. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  611. }];
  612. }
  613. - (void)cancel_urgency_timer {
  614. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  615. }
  616. @end