CommonEditorViewController.m 191 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635
  1. //
  2. // CommonEditorViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-7-16.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CommonEditorViewController.h"
  9. #import "CommonEditorCellEdit.h"
  10. #import "iSalesNetwork.h"
  11. #import "CommonEditorCellEnum.h"
  12. #import "CommonEditorCellSwitch.h"
  13. #import "CommonEditorCellModel.h"
  14. #import "CommonEditorCellAction.h"
  15. #import "EnumSelectViewController.h"
  16. #import "DatePickerViewController.h"
  17. #import "SignatureViewController.h"
  18. #import "CommonEditorCellSignature.h"
  19. #import "CommonEditorCellLabel.h"
  20. #import "AddressEditorViewController.h"
  21. #import "CreditCardEditorViewController.h"
  22. #import "MonthPickerViewController.h"
  23. #import "ContactListViewController.h"
  24. #import "CommonEditorCellMAction.h"
  25. #import "CommonEditorCellTextView.h"
  26. #import "RAUtils.h"
  27. #import "CommonEditorCellImg.h"
  28. #define NUMBERS @"0123456789\n"
  29. @interface CommonEditorViewController ()
  30. @end
  31. @implementation CommonEditorViewController
  32. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  33. {
  34. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  35. if (self) {
  36. // Custom initialization
  37. }
  38. return self;
  39. }
  40. -(void) viewWillAppear:(BOOL)animated
  41. {
  42. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  43. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  44. // 键盘高度变化通知,ios5.0新增的
  45. #ifdef __IPHONE_5_0
  46. float version = [[[UIDevice currentDevice] systemVersion] floatValue];
  47. if (version >= 5.0) {
  48. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
  49. }
  50. #endif
  51. }
  52. -(void) viewWillDisappear:(BOOL)animated
  53. {
  54. [[NSNotificationCenter defaultCenter] removeObserver:self];
  55. }
  56. -(void)manually_refresh
  57. {
  58. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  59. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  60. if ([self respondsToSelector:@selector(reload_data)])
  61. [self performSelector:@selector(reload_data) withObject:nil afterDelay:1];
  62. // DebugLog(@"refresh!!!!!!!!");
  63. }
  64. -(void)reload_data
  65. {
  66. [self.lastedit endEditing:true];
  67. [self.lasttextview endEditing:true];
  68. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  69. [reF endRefreshing];
  70. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  71. [self refresh:nil];
  72. }
  73. - (void)viewDidLoad
  74. {
  75. [super viewDidLoad];
  76. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  77. ref.tag = 200 ;
  78. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  79. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  80. // ref.hidden = true;
  81. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  82. [self.editorTable addSubview:ref];
  83. self.changed_data = [[NSMutableDictionary alloc] init];
  84. // UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  85. // // closeButton.title = @"Close";
  86. //
  87. // self.navigationItem.leftBarButtonItem = closeButton;
  88. if(self.url_type==URL_REMOTE)
  89. {
  90. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  91. NSDictionary* editor_json = [iSalesNetwork request_Editor:self.request_url params:self.params];
  92. dispatch_async(dispatch_get_main_queue(), ^{
  93. if([[editor_json valueForKey:@"result"] intValue]==2)
  94. {
  95. self.content_data_download = [editor_json mutableCopy];
  96. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  97. // self.content_data = [editor_json mutableCopy];
  98. // self.content_data = [self translate_json:editor_json];
  99. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  100. [self download_success];
  101. [self.editorTable reloadData];
  102. // NSString * ttt=[self.content_data valueForKey:@"title"] ;
  103. self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  104. }
  105. else
  106. {
  107. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
  108. }
  109. });
  110. });
  111. }
  112. else if(self.url_type== URL_LOCAL )
  113. {
  114. NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
  115. NSError *error=nil;
  116. self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  117. self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
  118. self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  119. [self.editorTable reloadData];
  120. // NSString * ttt=[self.content_data valueForKey:@"title"] ;
  121. // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  122. }
  123. else
  124. {
  125. self.content_data_control=[self translate_json:self.content_data_download changed: self.changed_data];
  126. [self.editorTable reloadData];
  127. // NSString * ttt=[self.content_data valueForKey:@"title"] ;
  128. self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  129. }
  130. self.requried = [[NSMutableDictionary alloc] init];
  131. self.cancommit = true;
  132. }
  133. //-(bool) action_btn_passed_check:(NSDictionary* ) data;
  134. //{
  135. // if(data == nil)
  136. // return false;
  137. // int section_count=[[data valueForKey:@"section_count"] intValue];
  138. //
  139. // for(int sc=0;sc<section_count)
  140. //
  141. //}
  142. //-(NSString*) get_param:(NSString*)param_name content_item:(NSDictionary*)itemjson
  143. //{
  144. //
  145. // NSString * item_name = [itemjson valueForKey:@"name"];
  146. // NSDictionary* cadejson= [itemjson objectForKey:@"cadedate"];
  147. // int cade_count = [[cadejson valueForKey:@"count"] intValue];
  148. // if([item_name isEqualToString:param_name] )
  149. // {
  150. // NSString* param_val=nil;
  151. //
  152. // bool single_select =[[itemjson valueForKey:@"single_select"] boolValue];
  153. //
  154. // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
  155. //
  156. //
  157. // for(int cc=0;cc<cade_count;cc++)
  158. // {
  159. // NSDictionary * valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
  160. // if([[valjson valueForKey:@"check"] boolValue])
  161. // {
  162. // NSString * valueid=[valjson valueForKey:@"value_id"];
  163. // if(valueid!=nil)
  164. // [arr_val addObject: valueid];
  165. // if(single_select)
  166. // break;
  167. // }
  168. //
  169. // }
  170. //
  171. // param_val = [arr_val componentsJoinedByString:@","];
  172. //
  173. // return param_val;
  174. // //[self.params setValue:param_val forKey:param_name];
  175. //
  176. // }
  177. // else
  178. // {
  179. // for(int cc=0;cc<cade_count;cc++)
  180. // {
  181. // NSDictionary * valjson=[itemjson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
  182. // NSDictionary* subitems=[valjson objectForKey:@"sub_item"];
  183. // if(subitems==nil)
  184. // continue;
  185. // int subcount=[[subitems valueForKey:@"count"] intValue];
  186. // for(int sc=0;sc<subcount;sc++)
  187. // {
  188. // NSDictionary* subitem = [subitems objectForKey:[NSString stringWithFormat:@"item_%d",sc]];
  189. // NSString* subval=[self get_param:param_name content_item:subitem];
  190. // if(subval!=nil)
  191. // return subval;
  192. // }
  193. //
  194. //
  195. // }
  196. //
  197. //
  198. // }
  199. // return nil;
  200. //
  201. //}
  202. -(void) download_success
  203. {
  204. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  205. }
  206. -(NSDictionary*) get_refresh_param
  207. {
  208. NSMutableDictionary* params= [[NSMutableDictionary alloc]init];
  209. NSDictionary * param_names = [self.content_data_download objectForKey:@"up_params"];
  210. int param_count=[[param_names valueForKey:@"count"] intValue];
  211. for(int pc=0;pc<param_count;pc++)
  212. {
  213. NSString* param_name = [param_names valueForKey:[NSString stringWithFormat:@"val_%d",pc]];
  214. NSString* param_val = [self getValue:param_name];
  215. [self.params setValue:param_val forKey:param_name];
  216. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  217. //
  218. // for(int i=0;i<section_count;i++)
  219. // {
  220. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  221. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  222. // for(int j=0;j<item_count;j++)
  223. // {
  224. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  225. //
  226. // NSString * control_type = [itemjson valueForKey:@"control"];
  227. // // NSString * item_name = [itemjson valueForKey:@"name"];
  228. // if([control_type isEqualToString:@"enum"])
  229. // {
  230. // NSString* subval= [self get_param:param_name content_item:itemjson];
  231. // if(subval!=nil)
  232. // {
  233. // [self.params setValue:subval forKey:param_name];
  234. // break;
  235. // }
  236. // // if([item_name isEqualToString:param_name] )
  237. // // {
  238. // // NSString* param_val=nil;
  239. // //
  240. // // bool single_select =[[itemjson valueForKey:@"single_select"] boolValue];
  241. // //
  242. // // int cade_count = [[itemjson valueForKey:@"count"] intValue];
  243. // //
  244. // // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
  245. // //
  246. // //
  247. // // for(int cc=0;cc<cade_count;cc++)
  248. // // {
  249. // // NSDictionary * valjson=[itemjson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
  250. // // if([[valjson valueForKey:@"check"] boolValue])
  251. // // {
  252. // // [arr_val addObject: [valjson valueForKey:@"value_id"]];
  253. // // if(single_select)
  254. // // break;
  255. // // }
  256. // //
  257. // // }
  258. // //
  259. // // param_val = [arr_val componentsJoinedByString:@","];
  260. // //
  261. // // [self.params setValue:param_val forKey:param_name];
  262. // // break;
  263. // // }
  264. // // else
  265. // // {
  266. // // NSString* subval= [self get_param:param_name content_item:itemjson];
  267. // // if(subval!=nil)
  268. // // {
  269. // // [self.params setValue:subval forKey:param_name];
  270. // // break;
  271. // // }
  272. // // }
  273. // }
  274. // }
  275. // }
  276. }
  277. return params;
  278. // NSString* param_name=[item_json valueForKey:@"name"];
  279. // NSString* param_val=nil;
  280. //
  281. // bool single_select =[[item_json valueForKey:@"single_select"] boolValue];
  282. //
  283. // int cade_count = [[value valueForKey:@"count"] intValue];
  284. //
  285. // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
  286. //
  287. //
  288. // for(int cc=0;cc<cade_count;cc++)
  289. // {
  290. // NSDictionary * valjson=[value objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
  291. // if([[valjson valueForKey:@"check"] boolValue])
  292. // {
  293. // [arr_val addObject: [valjson valueForKey:@"value_id"]];
  294. // if(single_select)
  295. // break;
  296. // }
  297. //
  298. // }
  299. //
  300. // param_val = [arr_val componentsJoinedByString:@","];
  301. //
  302. // [self.changed_data setObject:param_val forKey:param_name];
  303. }
  304. -(NSMutableDictionary*) CopyDirty:(NSDictionary*) dirty to:(NSMutableDictionary*) to
  305. {
  306. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  307. for(int i=0;i<section_count;i++)
  308. {
  309. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  310. NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  311. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  312. for(int j=0;j<item_count;j++)
  313. {
  314. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  315. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  316. if([[itemjson valueForKey:@"dirty"] isEqualToString:@"true"])
  317. {
  318. [to_sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  319. }
  320. }
  321. [to setObject:to_sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  322. }
  323. return to;
  324. }
  325. -(void) refresh:(NSString*) trigger;
  326. {
  327. [self.lastedit endEditing:true];
  328. [self.lasttextview endEditing:true];
  329. if(self.url_type==URL_REMOTE)
  330. {
  331. self.params[@"refresh_trigger"]=trigger;
  332. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  333. NSDictionary* refresh_params=[self get_refresh_param];
  334. NSArray* changed_key=[refresh_params allKeys];
  335. for(int i=0;i<changed_key.count;i++)
  336. {
  337. NSString* obj_str=[NSString stringWithFormat:@"%@",[refresh_params valueForKey:(NSString*)changed_key[i]]];
  338. [self.params setObject:obj_str forKey:(NSString*)changed_key[i]];
  339. }
  340. NSDictionary* editor_json = [iSalesNetwork request_Editor:self.request_url params:self.params];
  341. dispatch_async(dispatch_get_main_queue(), ^{
  342. if([[editor_json valueForKey:@"result"] intValue]==2)
  343. {
  344. self.content_data_download = [self CopyDirty:self.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
  345. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  346. [self download_success];
  347. [self.editorTable reloadData];
  348. }
  349. else
  350. {
  351. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
  352. }
  353. });
  354. });
  355. }
  356. else
  357. {
  358. NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
  359. NSError *error=nil;
  360. self.content_data_control=[self translate_json:[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] changed:self.changed_data];
  361. [self.editorTable reloadData];
  362. // NSString * ttt=[self.content_data valueForKey:@"title"] ;
  363. // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  364. }
  365. }
  366. -(NSMutableDictionary*) subitem_param:(NSDictionary*) itemjson addto:(NSMutableDictionary*) upparam
  367. {
  368. NSString * control_type = [itemjson valueForKey:@"control"];
  369. bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
  370. if([control_type isEqual:@"enum"] && single_select)
  371. {
  372. NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
  373. int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
  374. for(int k=0;k<cade_count;k++)
  375. {
  376. NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
  377. int check=[[valjson valueForKey:@"check"] intValue];
  378. NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
  379. bool active =[[valjson valueForKey:@"active"] boolValue];
  380. if(check==1 && subjson!=nil && !active)
  381. {
  382. int sub_count = [[subjson valueForKey:@"count"] intValue];
  383. for(int l=0;l<sub_count;l++)
  384. {
  385. NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  386. NSString* required = [addjson valueForKey:@"required"];
  387. NSString* key=[addjson valueForKey:@"name"];
  388. if(key==nil || key.length==0)
  389. continue;
  390. if([[addjson valueForKey:@"control"] isEqualToString:@"enum" ])
  391. {
  392. NSString* single_select = [addjson valueForKey:@"single_select"];
  393. if([single_select isEqualToString:@"true"])
  394. {
  395. NSDictionary* cadejson=[addjson objectForKey:@"cadedate"];
  396. int count = [[cadejson valueForKey:@"count"] intValue];
  397. bool setvalue = false;
  398. for(int cc=0;cc<count;cc++)
  399. {
  400. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  401. if([[valjson valueForKey:@"check"]intValue]==1)
  402. {
  403. [upparam setValue:[valjson valueForKey:@"value_id"] forKey:[addjson valueForKey:@"name"]];
  404. setvalue=true;
  405. break;
  406. }
  407. }
  408. if([[addjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  409. {
  410. self.cancommit = false;
  411. }
  412. }
  413. else
  414. {
  415. //not support multi select for now;
  416. }
  417. }
  418. else if([[addjson valueForKey:@"control"] isEqualToString:@"action" ])
  419. {
  420. NSMutableDictionary * action_data = [[addjson objectForKey:@"data"] mutableCopy];
  421. int section_count=[[action_data valueForKey:@"section_count"] intValue];
  422. if([required isEqualToString: @"true"] && action_data==nil)
  423. self.cancommit = false;
  424. for(int i=0;i<section_count;i++)
  425. {
  426. NSMutableDictionary * sectionjson = [[action_data objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  427. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  428. for(int j=0;j<item_count;j++)
  429. {
  430. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  431. NSString* key = [itemjson valueForKey:@"name"];
  432. if(key==nil || key.length==0)
  433. continue;
  434. if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  435. {
  436. NSString* single_select = [itemjson valueForKey:@"single_select"];
  437. if([single_select isEqualToString:@"true"])
  438. {
  439. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  440. int count = [[cadejson valueForKey:@"count"] intValue];
  441. bool setvalue = false;
  442. for(int cc=0;cc<count;cc++)
  443. {
  444. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  445. if([[valjson valueForKey:@"check"]intValue]==1)
  446. {
  447. [upparam setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  448. setvalue=true;
  449. break;
  450. }
  451. }
  452. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  453. {
  454. self.cancommit = false;
  455. }
  456. }
  457. else
  458. {
  459. //not support multi select for now;
  460. }
  461. /*
  462. upparams setValue:itemjson forKey:<#(NSString *)#>
  463. */
  464. }
  465. else
  466. {
  467. if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  468. [upparam setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  469. else
  470. {
  471. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  472. self.cancommit = false;
  473. }
  474. }
  475. upparam= [self subitem_param:itemjson addto:upparam ];
  476. }
  477. }
  478. }
  479. else
  480. {
  481. if([addjson valueForKey:@"value"]!=nil && ![[addjson valueForKey:@"value"]isEqualToString:@""])
  482. [upparam setValue:[addjson valueForKey:@"value"] forKey:key];
  483. else
  484. {
  485. if([[addjson valueForKey:@"required"] isEqualToString: @"true"] )
  486. self.cancommit = false;
  487. }
  488. }
  489. upparam=[self subitem_param:addjson addto:upparam];
  490. // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
  491. // item_count ++;
  492. // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
  493. }
  494. //break;
  495. }
  496. }
  497. }
  498. return upparam;
  499. }
  500. -(NSMutableArray*) add_subitem:(NSDictionary*) itemjson addto:(NSMutableArray*) sectionarr parent:(NSString*) parent
  501. {
  502. NSString * control_type = [itemjson valueForKey:@"control"];
  503. bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
  504. if([control_type isEqual:@"enum"] && single_select)
  505. {
  506. NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
  507. int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
  508. for(int k=0;k<cade_count;k++)
  509. {
  510. NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
  511. int check=[[valjson valueForKey:@"check"] intValue];
  512. NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
  513. bool active =[[valjson valueForKey:@"active"] boolValue];
  514. if(check==1 && subjson!=nil && !active)
  515. {
  516. int sub_count = [[subjson valueForKey:@"count"] intValue];
  517. for(int l=0;l<sub_count;l++)
  518. {
  519. NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  520. NSString* subself=[NSString stringWithFormat:@"%@_%d_%d",parent,k,l ];
  521. [addjson setValue:subself forKey:@"subid"];
  522. [sectionarr addObject:addjson];
  523. [self add_subitem:addjson addto:sectionarr parent:subself];
  524. // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
  525. // item_count ++;
  526. // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
  527. }
  528. [valjson setValue:@"true" forKey:@"active"];
  529. [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
  530. //break;
  531. }
  532. }
  533. }
  534. else if([control_type isEqual:@"switch"])
  535. {
  536. NSString* value=[itemjson valueForKey:@"value"];
  537. NSMutableDictionary* subjson=nil;
  538. if([value isEqualToString:@"true"])
  539. subjson=[[[itemjson objectForKey:@"true"] objectForKey:@"sub_item"] mutableCopy];// [ mutableCopy];
  540. else
  541. subjson=[[[itemjson objectForKey:@"false"] objectForKey:@"sub_item"] mutableCopy];
  542. if( subjson!=nil /*&& !active*/)
  543. {
  544. int sub_count = [[subjson valueForKey:@"count"] intValue];
  545. for(int l=0;l<sub_count;l++)
  546. {
  547. NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  548. NSString* subself=[NSString stringWithFormat:@"%@_%d",parent,l ];
  549. [addjson setValue:subself forKey:@"subid"];
  550. [sectionarr addObject:addjson];
  551. [self add_subitem:addjson addto:sectionarr parent:subself];
  552. // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
  553. // item_count ++;
  554. // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
  555. }
  556. // [valjson setValue:@"true" forKey:@"active"];
  557. // [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
  558. //break;
  559. }
  560. }
  561. return sectionarr;
  562. }
  563. -(NSMutableArray*) translate_json: (NSDictionary*) injson changed:(NSDictionary*) changed_value
  564. {
  565. if(injson == nil)
  566. return nil;
  567. NSMutableArray * retarray= [[NSMutableArray alloc]init];
  568. int section_count=[[injson valueForKey:@"section_count"] intValue];
  569. for(int i=0;i<section_count;i++)
  570. {
  571. NSMutableArray * sectionarr= [[NSMutableArray alloc]init];
  572. NSMutableDictionary * sectionjson = [[injson objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  573. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  574. for(int j=0;j<item_count;j++)
  575. {
  576. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  577. [sectionarr addObject:itemjson];
  578. [self add_subitem:itemjson addto:sectionarr parent:[NSString stringWithFormat:@"%d_%d",i,j ]];
  579. // [itemjson setObject:cadedatejson forKey:@"cadedate"];
  580. // NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
  581. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  582. }
  583. // [sectionjson setValue:[NSString stringWithFormat:@"%d",item_count ] forKey:@"count"];
  584. // [retjson setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  585. [retarray addObject:sectionarr];
  586. }
  587. return retarray;
  588. // retjson setObject:sec forKey:<#(id<NSCopying>)#>
  589. // return nil;
  590. }
  591. /*
  592. -(NSMutableDictionary*) translate_json: (NSDictionary*) injson
  593. {
  594. if(injson == nil)
  595. return nil;
  596. NSMutableDictionary * retjson= [injson mutableCopy];
  597. int section_count=[[retjson valueForKey:@"section_count"] intValue];
  598. for(int i=0;i<section_count;i++)
  599. {
  600. NSMutableDictionary * sectionjson = [[retjson objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  601. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  602. for(int j=0;j<item_count;j++)
  603. {
  604. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  605. NSString * control_type = [itemjson valueForKey:@"control"];
  606. bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
  607. if([control_type isEqual:@"enum"] && single_select)
  608. {
  609. NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
  610. int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
  611. for(int k=0;k<cade_count;k++)
  612. {
  613. NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
  614. int check=[[valjson valueForKey:@"check"] intValue];
  615. NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
  616. bool active =[[valjson valueForKey:@"active"] boolValue];
  617. if(check==1 && subjson!=nil && !active)
  618. {
  619. int sub_count = [[subjson valueForKey:@"count"] intValue];
  620. for(int l=0;l<sub_count;l++)
  621. {
  622. NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  623. [addjson setValue:[NSString stringWithFormat:@"%d_%d_%d",i,j,k ] forKey:@"parent"];
  624. [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
  625. item_count ++;
  626. // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
  627. }
  628. [valjson setValue:@"true" forKey:@"active"];
  629. [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
  630. //break;
  631. }
  632. if(check==0 && subjson!=nil)
  633. {
  634. int total_remove=0;
  635. for(int r=0;r<item_count;r++)
  636. {
  637. NSMutableDictionary * removejson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",r ]] mutableCopy];
  638. if(removejson==nil)
  639. continue;
  640. if([[removejson valueForKey:@"parent"] isEqualToString: [NSString stringWithFormat:@"%d_%d_%d",i,j,k ]])
  641. {
  642. [sectionjson removeObjectForKey:[NSString stringWithFormat:@"item_%d",r ]];
  643. total_remove++;
  644. // item_count--;
  645. // r--;
  646. }
  647. else
  648. {
  649. [sectionjson removeObjectForKey:[NSString stringWithFormat:@"item_%d",r ]];
  650. [sectionjson setObject:removejson forKey:[NSString stringWithFormat:@"item_%d",r-total_remove ]];
  651. }
  652. }
  653. [valjson setValue:@"false" forKey:@"active"];
  654. [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
  655. item_count-=total_remove;
  656. // remove sub item
  657. //break;
  658. }
  659. }
  660. [itemjson setObject:cadedatejson forKey:@"cadedate"];
  661. // NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
  662. }
  663. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  664. }
  665. [sectionjson setValue:[NSString stringWithFormat:@"%d",item_count ] forKey:@"count"];
  666. [retjson setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  667. }
  668. return retjson;
  669. // retjson setObject:sec forKey:<#(id<NSCopying>)#>
  670. return nil;
  671. }*/
  672. //- (void)onCloseClick:(UIButton *)sender {
  673. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  674. // ;
  675. // }];
  676. //}
  677. - (void)didReceiveMemoryWarning
  678. {
  679. [super didReceiveMemoryWarning];
  680. // Dispose of any resources that can be recreated.
  681. }
  682. -(void) prepareReturn:(NSMutableDictionary*) value
  683. {
  684. if(value==nil)
  685. value=[[NSMutableDictionary alloc]init];
  686. value[@"is_subaction"] = self.params[@"is_subaction"];
  687. value[@"subaction_tag"] = self.params[@"subaction_tag"];
  688. if (self.delegate && [self.delegate respondsToSelector:@selector(returnValue:indexPath:)]) {
  689. [self.delegate returnValue:value indexPath:self.from];
  690. }
  691. if(self.returnValue)
  692. self.returnValue(nil);
  693. }
  694. -(void) handle_action_return:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath action:(int) action_code
  695. {
  696. NSLog(@"commoneditor return %ld_%ld",(long)indexPath.section,(long)indexPath.row);
  697. NSMutableDictionary* section_json=nil;
  698. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  699. bool is_subaction = [value[@"is_subaction"] boolValue];
  700. int subaction_tag= [value[@"subaction_tag"] intValue];
  701. [value removeObjectForKey:@"is_subaction"];
  702. [value removeObjectForKey:@"subaction_tag"];
  703. if(is_subaction)
  704. {
  705. NSMutableDictionary* sub_action = [[item_json objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy];
  706. int refresh = [[sub_action valueForKey:@"refresh"] intValue];
  707. NSString* refresh_trigger = [sub_action valueForKey:@"name"];
  708. NSDictionary * restore_json=[sub_action objectForKeyedSubscript:@"restore"];
  709. NSString* subid=[sub_action valueForKey:@"subid"];
  710. UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
  711. NSString* required = [sub_action valueForKey:@"required"];
  712. if([required isEqualToString:@"true"] && value.count==0)
  713. {
  714. CALayer *layer = [cell.contentView layer];
  715. // layer.borderColor = [[UIColor redColor] CGColor];
  716. // layer.borderWidth = 1.0;
  717. layer.shadowColor = [UIColor redColor].CGColor;
  718. layer.shadowOffset = CGSizeMake(0, 0);
  719. layer.shadowOpacity = 1;
  720. layer.shadowRadius = 2.0;
  721. }
  722. else
  723. {
  724. CALayer *layer = [cell.contentView layer];
  725. // layer.borderColor = [[UIColor redColor] CGColor];
  726. // layer.borderWidth = 1.0;
  727. layer.shadowColor = [UIColor clearColor].CGColor;
  728. layer.shadowOffset = CGSizeMake(0, 0);
  729. layer.shadowOpacity = 1;
  730. layer.shadowRadius = 2.0;
  731. }
  732. if(value.count!=0)
  733. {
  734. if(action_code==ACTION_SAVE_DATA)
  735. {
  736. [sub_action setObject:value forKey:@"data"];
  737. if(subid==nil)
  738. {
  739. [sub_action setValue:@"true" forKey:@"dirty"];
  740. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  741. int count=0;
  742. count=[[section_json valueForKey:@"count"] intValue];
  743. for(int i=0;i<count;i++)
  744. {
  745. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  746. if([[olditem valueForKey:@"name"] isEqualToString:[sub_action valueForKey:@"name" ]])
  747. {
  748. // sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
  749. [item_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
  750. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  751. }
  752. }
  753. }
  754. else
  755. {
  756. assert(@"not impl");
  757. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  758. int section = [(NSString*)idarr[0] intValue];
  759. int item=[(NSString*)idarr[1] intValue];
  760. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  761. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  762. sub_action= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:sub_action step:2];
  763. [sub_action setValue:@"true" forKey:@"dirty"];
  764. [item_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
  765. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  766. }
  767. }
  768. else if(action_code==ACTION_FILL_SECTION)
  769. {
  770. if(subid==nil)
  771. {
  772. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  773. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  774. int icount=[[section_json valueForKey:@"count"] intValue];
  775. for (int ic=0;ic<icount;ic++)
  776. {
  777. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  778. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  779. NSString* valuestr= [value valueForKey:valuefrom];
  780. if(valuestr !=nil)
  781. {
  782. [modify_item setValue:valuestr forKey:@"value"];
  783. [modify_item setValue:@"true" forKey:@"dirty"];
  784. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  785. }
  786. }
  787. }
  788. else
  789. {
  790. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  791. int section = [(NSString*)idarr[0] intValue];
  792. int item=[(NSString*)idarr[1] intValue];
  793. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  794. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  795. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  796. NSMutableDictionary* olditem_sub_action = [[olditem objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy];
  797. olditem_sub_action= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  798. [olditem_sub_action setValue:@"true" forKey:@"dirty"];
  799. [olditem setObject:olditem_sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
  800. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  801. }
  802. }
  803. // [section_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  804. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  805. }
  806. NSLog(@"CONTENT UPDATE:%@",[iSalesNetwork DataTOjsonString:self.content_data_download]);
  807. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  808. if(refresh==1)
  809. {
  810. if(restore_json!=nil)
  811. {
  812. int rc=[[restore_json valueForKey:@"count"] intValue];
  813. for(int ir=0;ir<rc;ir++)
  814. {
  815. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  816. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  817. for(int i=0;i<section_count;i++)
  818. {
  819. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  820. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  821. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  822. for(int j=0;j<item_count;j++)
  823. {
  824. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  825. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  826. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  827. {
  828. [itemjson removeObjectForKey:@"dirty"];
  829. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  830. }
  831. }
  832. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  833. }
  834. }
  835. }
  836. [self refresh:refresh_trigger] ;
  837. return ;
  838. }
  839. // NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  840. [self.editorTable reloadData ];
  841. }
  842. else
  843. {
  844. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  845. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  846. NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  847. NSString* subid=[item_json valueForKey:@"subid"];
  848. UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
  849. NSString* required = [item_json valueForKey:@"required"];
  850. if([required isEqualToString:@"true"] && value.count==0)
  851. {
  852. CALayer *layer = [cell.contentView layer];
  853. // layer.borderColor = [[UIColor redColor] CGColor];
  854. // layer.borderWidth = 1.0;
  855. layer.shadowColor = [UIColor redColor].CGColor;
  856. layer.shadowOffset = CGSizeMake(0, 0);
  857. layer.shadowOpacity = 1;
  858. layer.shadowRadius = 2.0;
  859. }
  860. else
  861. {
  862. CALayer *layer = [cell.contentView layer];
  863. // layer.borderColor = [[UIColor redColor] CGColor];
  864. // layer.borderWidth = 1.0;
  865. layer.shadowColor = [UIColor clearColor].CGColor;
  866. layer.shadowOffset = CGSizeMake(0, 0);
  867. layer.shadowOpacity = 1;
  868. layer.shadowRadius = 2.0;
  869. }
  870. if(value.count!=0)
  871. {
  872. if(action_code==ACTION_SAVE_DATA)
  873. {
  874. [item_json setObject:value forKey:@"data"];
  875. if(subid==nil)
  876. {
  877. [item_json setValue:@"true" forKey:@"dirty"];
  878. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  879. int count=0;
  880. count=[[section_json valueForKey:@"count"] intValue];
  881. for(int i=0;i<count;i++)
  882. {
  883. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  884. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  885. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  886. }
  887. }
  888. else
  889. {
  890. assert(@"not impl");
  891. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  892. int section = [(NSString*)idarr[0] intValue];
  893. int item=[(NSString*)idarr[1] intValue];
  894. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  895. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  896. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  897. [item_json setValue:@"true" forKey:@"dirty"];
  898. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  899. }
  900. }
  901. else if(action_code==ACTION_FILL_SECTION)
  902. {
  903. if(subid==nil)
  904. {
  905. NSDictionary* jsonmap=[item_json valueForKey:@"key_map"];
  906. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  907. int icount=[[section_json valueForKey:@"count"] intValue];
  908. for (int ic=0;ic<icount;ic++)
  909. {
  910. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  911. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  912. NSString* valuestr= [value valueForKey:valuefrom];
  913. if(valuestr !=nil)
  914. {
  915. [modify_item setValue:valuestr forKey:@"value"];
  916. [modify_item setValue:@"true" forKey:@"dirty"];
  917. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  918. }
  919. }
  920. }
  921. else
  922. {
  923. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  924. int section = [(NSString*)idarr[0] intValue];
  925. int item=[(NSString*)idarr[1] intValue];
  926. NSDictionary* jsonmap=[item_json valueForKey:@"key_map"];
  927. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  928. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  929. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  930. [olditem setValue:@"true" forKey:@"dirty"];
  931. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  932. }
  933. }
  934. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  935. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  936. }
  937. NSLog(@"CONTENT UPDATE:%@",[iSalesNetwork DataTOjsonString:self.content_data_download]);
  938. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  939. if(refresh==1)
  940. {
  941. if(restore_json!=nil)
  942. {
  943. int rc=[[restore_json valueForKey:@"count"] intValue];
  944. for(int ir=0;ir<rc;ir++)
  945. {
  946. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  947. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  948. for(int i=0;i<section_count;i++)
  949. {
  950. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  951. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  952. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  953. for(int j=0;j<item_count;j++)
  954. {
  955. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  956. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  957. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  958. {
  959. [itemjson removeObjectForKey:@"dirty"];
  960. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  961. }
  962. }
  963. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  964. }
  965. }
  966. }
  967. [self refresh:refresh_trigger] ;
  968. return ;
  969. }
  970. // NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  971. [self.editorTable reloadData ];
  972. }
  973. }
  974. -(NSString*) getValue:(NSString*)name
  975. {
  976. NSString* ret=nil;
  977. for(int i=0;i<self.content_data_control.count;i++)
  978. {
  979. NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
  980. for(int j=0;j<items.count;j++)
  981. {
  982. NSDictionary* item=items[j];
  983. NSString* item_name=[item valueForKey:@"name"];
  984. if([item_name isEqualToString:name])
  985. {
  986. NSString* control = [item valueForKey:@"control"];
  987. if([control isEqualToString:@"enum"])
  988. {
  989. NSDictionary* cadedate = [item objectForKey:@"cadedate"];
  990. int cc = [[cadedate valueForKey:@"count"] intValue];
  991. for(int l=0;l<cc;l++)
  992. {
  993. NSDictionary* val_json=[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]];
  994. if([[val_json valueForKey:@"check"]intValue]==1)
  995. return [val_json valueForKey:@"value_id"];
  996. }
  997. }
  998. else
  999. return [item valueForKey:@"value"];
  1000. }
  1001. }
  1002. }
  1003. return ret;
  1004. }
  1005. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  1006. {
  1007. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  1008. NSArray *keys= [key_map allKeys];
  1009. //遍历keys
  1010. for(int i=0;i<[keys count];i++)
  1011. {
  1012. //得到当前key
  1013. NSString *key=[keys objectAtIndex:i];
  1014. //如果key不是pic,说明value是字符类型,比如name:Boris
  1015. NSString* valuefrom = [key_map valueForKey:key];
  1016. if(valuefrom.length==0)
  1017. continue;
  1018. NSString* value=[self getValue:valuefrom];
  1019. [ret setValue:value forKey:valuefrom];
  1020. }
  1021. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  1022. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  1023. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  1024. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  1025. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1026. // // self.labelContact.text=appDelegate.contact_name;
  1027. //
  1028. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1029. //
  1030. //
  1031. // keys= [customerinfo allKeys];
  1032. // //遍历keys
  1033. // for(int i=0;i<[keys count];i++)
  1034. // {
  1035. // //得到当前key
  1036. // NSString *key=[keys objectAtIndex:i];
  1037. // //如果key不是pic,说明value是字符类型,比如name:Boris
  1038. // NSString* valuefrom = key;
  1039. // NSString* value=[customerinfo valueForKey:key];
  1040. //
  1041. // [ret setValue:value forKey:valuefrom];
  1042. // }
  1043. //// add customer_contact_ext
  1044. // [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  1045. // NSString *string = [array componentsJoinedByString:@" "];
  1046. return ret;
  1047. }
  1048. -(NSMutableDictionary*)create_cusromer_info_from_table
  1049. {
  1050. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1051. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  1052. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  1053. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  1054. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  1055. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  1056. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  1057. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  1058. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  1059. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  1060. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  1061. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  1062. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1063. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  1064. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1065. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  1066. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  1067. NSString * firstname =nil;
  1068. NSString* lastname = nil;
  1069. NSString* contact_name = [self getValue:@"customer_contact"];
  1070. if(contact_name!=nil)
  1071. {
  1072. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  1073. if(_arr.count>=1)
  1074. {
  1075. firstname =_arr[0];
  1076. if(_arr.count>1)
  1077. {
  1078. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  1079. }
  1080. }
  1081. }
  1082. [ret setValue:firstname forKey:@"customer_first_name"];
  1083. [ret setValue:lastname forKey:@"customer_last_name"];
  1084. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  1085. return ret;
  1086. }
  1087. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  1088. {
  1089. NSString* ret=nil;
  1090. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  1091. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  1092. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  1093. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  1094. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  1095. if(customer_address1.length>0)
  1096. [arraddr addObject:customer_address1];
  1097. if(customer_address2.length>0)
  1098. [arraddr addObject:customer_address2];
  1099. if(customer_address3.length>0)
  1100. [arraddr addObject:customer_address3];
  1101. if(customer_address4.length>0)
  1102. [arraddr addObject:customer_address4];
  1103. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  1104. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  1105. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  1106. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  1107. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  1108. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  1109. if(customer_city.length>0)
  1110. [arrcty addObject:customer_city];
  1111. if(customer_state.length>0)
  1112. [arrcty addObject:customer_state];
  1113. if(customer_zipcode.length>0)
  1114. [arrcty addObject:customer_zipcode];
  1115. if(customer_country.length>0)
  1116. [arrcty addObject:customer_country];
  1117. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  1118. NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"];
  1119. NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"];
  1120. NSMutableArray* arrpho = [[NSMutableArray alloc] init];
  1121. if(customer_phone.length>0)
  1122. {
  1123. customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone];
  1124. [arrpho addObject:customer_phone];
  1125. }
  1126. if(customer_fax.length>0)
  1127. {
  1128. customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax];
  1129. [arrpho addObject:customer_fax];
  1130. }
  1131. NSString *phone_string = [arrpho componentsJoinedByString:@", "];
  1132. NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"];
  1133. if(customer_contact.length>0)
  1134. {
  1135. customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact];
  1136. }
  1137. NSString *contact_string = customer_contact;
  1138. NSString* customer_email= [customerinfo valueForKey:@"customer_email"];
  1139. if(customer_email.length>0)
  1140. {
  1141. customer_email = [NSString stringWithFormat:@"Email: %@",customer_email];
  1142. }
  1143. NSString *email_string = customer_email;
  1144. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  1145. if(addr_string.length>0)
  1146. [arrext addObject:addr_string];
  1147. if(cty_string.length>0)
  1148. [arrext addObject:cty_string];
  1149. if(phone_string.length>0)
  1150. [arrext addObject:phone_string];
  1151. if(contact_string.length>0)
  1152. [arrext addObject:contact_string];
  1153. if(email_string.length>0)
  1154. [arrext addObject:email_string];
  1155. ret = [arrext componentsJoinedByString:@"\r\n"];
  1156. // NSString *string = [array componentsJoinedByString:@" "];
  1157. // NSString* customer_name= [customerinfo valueForKey:@"customer_name"];
  1158. return ret;
  1159. }
  1160. #pragma mark - hide section button clicked
  1161. - (void)HideSction:(UIButton *)sender {
  1162. NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]] mutableCopy];
  1163. bool hide = [[section valueForKey:@"hide"]boolValue];
  1164. if(hide)
  1165. {
  1166. [section setValue:@"false" forKey:@"hide"];
  1167. [sender setTitle:@"Show" forState:UIControlStateNormal];
  1168. }
  1169. else{
  1170. [section setValue:@"true" forKey:@"hide"];
  1171. [sender setTitle:@"Hide" forState:UIControlStateNormal];
  1172. }
  1173. [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]];
  1174. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1175. NSRange range = NSMakeRange(sender.tag, 1);
  1176. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1177. [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1178. }
  1179. #pragma mark - multi_action sub action clicked
  1180. - (IBAction)MActionClicked:(UIButton *)sender {
  1181. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  1182. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1183. int refresh =0;
  1184. NSMutableDictionary* section_json=nil;
  1185. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1186. NSString* subid=[item_json valueForKey:@"subid"];
  1187. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  1188. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  1189. NSString* type = [sub_action valueForKey:@"type"];
  1190. if([type isEqualToString:@"pull"])
  1191. {
  1192. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  1193. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  1194. NSMutableDictionary* value=[self create_value_map:keymap];
  1195. if(subid==nil)
  1196. {
  1197. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1198. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1199. int icount=[[section_json valueForKey:@"count"] intValue];
  1200. for (int ic=0;ic<icount;ic++)
  1201. {
  1202. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  1203. NSString* mapto = [modify_item valueForKey:@"name"];
  1204. if(mapto.length==0)
  1205. continue;
  1206. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  1207. if(valuefrom==nil)
  1208. continue;
  1209. NSString* valuestr=[value valueForKey:valuefrom];
  1210. // valuestr = [self getValue:valuefrom];
  1211. if(true)
  1212. {
  1213. if(valuestr.length>0)
  1214. [modify_item setValue:valuestr forKey:@"value"];
  1215. else
  1216. [modify_item setValue:@"" forKey:@"value"];
  1217. [modify_item setValue:@"true" forKey:@"dirty"];
  1218. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  1219. }
  1220. }
  1221. }
  1222. else
  1223. {
  1224. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  1225. int section = [(NSString*)idarr[0] intValue];
  1226. int item=[(NSString*)idarr[1] intValue];
  1227. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1228. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  1229. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  1230. NSString* control_type = [olditem valueForKey:@"control"];
  1231. if([control_type isEqualToString:@"switch"])
  1232. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1233. else if([control_type isEqualToString:@"enum"])
  1234. {
  1235. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1236. }
  1237. else
  1238. {
  1239. [RAUtils alert_view:@"" title:@"not impl"];
  1240. }
  1241. [olditem setValue:@"true" forKey:@"dirty"];
  1242. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  1243. }
  1244. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1245. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1246. if(refresh==1)
  1247. {
  1248. // if(restore_json!=nil)
  1249. // {
  1250. // int rc=[[restore_json valueForKey:@"count"] intValue];
  1251. // for(int ir=0;ir<rc;ir++)
  1252. // {
  1253. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  1254. //
  1255. //
  1256. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  1257. // for(int i=0;i<section_count;i++)
  1258. // {
  1259. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1260. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1261. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1262. // for(int j=0;j<item_count;j++)
  1263. // {
  1264. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1265. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1266. //
  1267. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  1268. // {
  1269. // [itemjson removeObjectForKey:@"dirty"];
  1270. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  1271. // }
  1272. //
  1273. // }
  1274. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  1275. // }
  1276. //
  1277. //
  1278. // }
  1279. //
  1280. // }
  1281. [self refresh:refresh_trigger] ;
  1282. return ;
  1283. }
  1284. // NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  1285. [self.editorTable reloadData ];
  1286. }
  1287. else
  1288. {
  1289. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1290. NSDictionary * item_json = sub_action;
  1291. NSString* value = [item_json valueForKey:@"value"];
  1292. if([value isEqualToString:@"new_addr"])
  1293. {
  1294. AddressEditorViewController * addressVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AddressEditorViewController"];
  1295. addressVC.url_type = URL_REMOTE;
  1296. addressVC.request_url=URL_ADDRESS_EDOTOR;
  1297. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1298. // NSString * string = [checked componentsJoinedByString:@","];
  1299. // [params setValue:string forKey:@"cart2Checkbox"];
  1300. params[@"is_subaction"]=@"true";
  1301. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  1302. addressVC.params = params;
  1303. addressVC.delegate = self;
  1304. addressVC.from = indexPath;
  1305. // orderinfoVC.params = params;
  1306. [self.navigationController pushViewController:addressVC animated:true];
  1307. }else if([value isEqualToString:@"credit_card"])
  1308. {
  1309. CreditCardEditorViewController * cardVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreditCardEditorViewController"];
  1310. NSDictionary *data = [item_json objectForKey:@"data"];
  1311. if(data!=nil)
  1312. {
  1313. cardVC.content_data_download = [data mutableCopy];
  1314. cardVC.url_type = URL_NONE;
  1315. cardVC.request_url=nil;
  1316. }
  1317. else
  1318. {
  1319. cardVC.url_type = URL_REMOTE;
  1320. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  1321. }
  1322. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1323. params[@"orderCode"]=appDelegate.order_code;
  1324. params[@"is_subaction"]=@"true";
  1325. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  1326. cardVC.params = params;
  1327. cardVC.delegate = self;
  1328. cardVC.from = indexPath;
  1329. // orderinfoVC.params = params;
  1330. [self.navigationController pushViewController:cardVC animated:true];
  1331. }
  1332. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  1333. {
  1334. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1335. cvc.showNavibar = true;
  1336. cvc.contact_type = value;
  1337. cvc.is_subaction = @"true";
  1338. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1339. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1340. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1341. //
  1342. // if(self.returnValue)
  1343. // self.returnValue(value);
  1344. };
  1345. [self.navigationController pushViewController:cvc animated:true];
  1346. }
  1347. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  1348. {
  1349. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1350. cvc.showNavibar = true;
  1351. cvc.contact_type = value;
  1352. cvc.is_subaction = @"true";
  1353. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1354. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1355. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1356. //
  1357. // if(self.returnValue)
  1358. // self.returnValue(value);
  1359. };
  1360. [self.navigationController pushViewController:cvc animated:true];
  1361. }
  1362. else if([value isEqualToString:@"Sales_Order_Customer"])
  1363. {
  1364. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1365. cvc.is_subaction = @"true";
  1366. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1367. cvc.showNavibar = true;
  1368. cvc.contact_type = value;
  1369. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1370. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1371. //
  1372. // if(self.returnValue)
  1373. // self.returnValue(value);
  1374. };
  1375. [self.navigationController pushViewController:cvc animated:true];
  1376. }
  1377. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  1378. {
  1379. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1380. cvc.showNavibar = true;
  1381. cvc.contact_type = value;
  1382. cvc.is_subaction = @"true";
  1383. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1384. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1385. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1386. //
  1387. // if(self.returnValue)
  1388. // self.returnValue(value);
  1389. };
  1390. [self.navigationController pushViewController:cvc animated:true];
  1391. }
  1392. else if([value isEqualToString:@"Contact_Return_To"])
  1393. {
  1394. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1395. cvc.is_subaction = @"true";
  1396. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1397. cvc.showNavibar = true;
  1398. cvc.contact_type = value;
  1399. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1400. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1401. //
  1402. // if(self.returnValue)
  1403. // self.returnValue(value);
  1404. };
  1405. [self.navigationController pushViewController:cvc animated:true];
  1406. }
  1407. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  1408. {
  1409. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1410. cvc.is_subaction = @"true";
  1411. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1412. cvc.showNavibar = true;
  1413. cvc.contact_type = value;
  1414. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1415. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1416. //
  1417. // if(self.returnValue)
  1418. // self.returnValue(value);
  1419. };
  1420. [self.navigationController pushViewController:cvc animated:true];
  1421. }
  1422. }
  1423. }
  1424. #pragma mark - commoneditor delegate
  1425. -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  1426. {
  1427. [self handle_action_return:value indexPath:indexPath action:ACTION_SAVE_DATA];
  1428. // NSLog(@"commoneditor return %d_%d",indexPath.section,indexPath.row);
  1429. //
  1430. // NSMutableDictionary* section_json=nil;
  1431. //
  1432. // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1433. //
  1434. //
  1435. //
  1436. // int refresh = [[item_json valueForKey:@"refresh"] intValue];
  1437. //
  1438. // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  1439. //
  1440. //
  1441. //
  1442. // NSString* subid=[item_json valueForKey:@"subid"];
  1443. //
  1444. // UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
  1445. //
  1446. // NSString* required = [item_json valueForKey:@"required"];
  1447. // if([required isEqualToString:@"true"] && value==nil)
  1448. // {
  1449. // CALayer *layer = [cell.contentView layer];
  1450. // // layer.borderColor = [[UIColor redColor] CGColor];
  1451. // // layer.borderWidth = 1.0;
  1452. //
  1453. // layer.shadowColor = [UIColor redColor].CGColor;
  1454. // layer.shadowOffset = CGSizeMake(0, 0);
  1455. // layer.shadowOpacity = 1;
  1456. // layer.shadowRadius = 2.0;
  1457. // }
  1458. // else
  1459. // {
  1460. // CALayer *layer = [cell.contentView layer];
  1461. // // layer.borderColor = [[UIColor redColor] CGColor];
  1462. // // layer.borderWidth = 1.0;
  1463. //
  1464. // layer.shadowColor = [UIColor clearColor].CGColor;
  1465. // layer.shadowOffset = CGSizeMake(0, 0);
  1466. // layer.shadowOpacity = 1;
  1467. // layer.shadowRadius = 2.0;
  1468. // }
  1469. // if(value!=nil)
  1470. // {
  1471. // [item_json setObject:value forKey:@"data"];
  1472. //
  1473. //
  1474. // if(subid==nil)
  1475. // {
  1476. // [item_json setValue:@"true" forKey:@"dirty"];
  1477. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1478. // int count=0;
  1479. //
  1480. // count=[[section_json valueForKey:@"count"] intValue];
  1481. //
  1482. // for(int i=0;i<count;i++)
  1483. // {
  1484. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  1485. // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  1486. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  1487. //
  1488. //
  1489. // }
  1490. // }
  1491. // else
  1492. // {
  1493. // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  1494. // int section = [(NSString*)idarr[0] intValue];
  1495. // int item=[(NSString*)idarr[1] intValue];
  1496. //
  1497. //
  1498. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  1499. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  1500. // item_json= [self subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  1501. // [item_json setValue:@"true" forKey:@"dirty"];
  1502. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  1503. //
  1504. // }
  1505. //
  1506. //
  1507. // // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  1508. //
  1509. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1510. // }
  1511. //
  1512. // if(refresh==1)
  1513. // {
  1514. //
  1515. // if(restore_json!=nil)
  1516. // {
  1517. // int rc=[[restore_json valueForKey:@"count"] intValue];
  1518. // for(int ir=0;ir<rc;ir++)
  1519. // {
  1520. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  1521. //
  1522. //
  1523. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  1524. // for(int i=0;i<section_count;i++)
  1525. // {
  1526. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1527. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1528. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1529. // for(int j=0;j<item_count;j++)
  1530. // {
  1531. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1532. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1533. //
  1534. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  1535. // {
  1536. // [itemjson removeObjectForKey:@"dirty"];
  1537. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  1538. // }
  1539. //
  1540. // }
  1541. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  1542. // }
  1543. //
  1544. //
  1545. // }
  1546. //
  1547. // }
  1548. // [self refresh] ;
  1549. // return ;
  1550. // }
  1551. //
  1552. //
  1553. // NSLog(@"CONTENT UPDATE:%@",[iSalesNetwork DataTOjsonString:self.content_data_download]);
  1554. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1555. //
  1556. //
  1557. // // NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  1558. // [self.editorTable reloadData ];
  1559. }
  1560. #pragma mark - Table view data source
  1561. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1562. //{
  1563. // return 0;
  1564. //}
  1565. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  1566. //{
  1567. // return 0;
  1568. //}
  1569. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  1570. //{
  1571. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1572. // return myView;
  1573. //
  1574. //}
  1575. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1576. //{
  1577. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1578. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  1579. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  1580. //// titleLabel.textColor=[UIColor whiteColor];
  1581. //// titleLabel.backgroundColor = [UIColor clearColor];
  1582. //// if(section==0)
  1583. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  1584. //// else
  1585. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  1586. //// [titleLabel sizeToFit];
  1587. //// [myView addSubview:titleLabel];
  1588. ////
  1589. // return myView;
  1590. //}
  1591. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  1592. //
  1593. // switch (section) {
  1594. // case 0:
  1595. // {
  1596. // NSDictionary * section_json = [self.content_data objectForKey:@"info_section"];
  1597. // return [section_json valueForKey:@"title"] ;
  1598. // }
  1599. // case 1:
  1600. // {
  1601. // NSDictionary * section_json = [self.content_data objectForKey:@"model_section"];
  1602. // return [section_json valueForKey:@"title"] ;
  1603. // }
  1604. // default:
  1605. // return nil;
  1606. // }
  1607. //
  1608. //
  1609. //}
  1610. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  1611. NSMutableDictionary* section_json = [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]];
  1612. return [section_json valueForKey:@"title"];
  1613. }
  1614. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1615. {
  1616. // if(self.content_data_control.count>0)
  1617. // return 1;
  1618. return self.content_data_control.count;
  1619. // int section_count =[[self.content_data valueForKey:@"section_count"] intValue];
  1620. // return section_count;
  1621. }
  1622. //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  1623. //{
  1624. // DebugLog(@"canMoveRowAtIndexPath");
  1625. //
  1626. // if([tableView numberOfRowsInSection:indexPath.section]>1)
  1627. // return true;
  1628. // else
  1629. // return false;
  1630. //}
  1631. //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
  1632. //{
  1633. // NSMutableArray * from;
  1634. // NSMutableArray * to ;
  1635. // if(fromIndexPath.section==0)
  1636. // from = self.displayfields;
  1637. // else
  1638. // from = self.hidefields;
  1639. // if(toIndexPath.section==0)
  1640. // to = self.displayfields;
  1641. // else
  1642. // to = self.hidefields;
  1643. // id content=from[fromIndexPath.row];
  1644. // [from removeObjectAtIndex:fromIndexPath.row];
  1645. // [to insertObject:content atIndex:toIndexPath.row];
  1646. //
  1647. // [tableView reloadData];
  1648. //
  1649. //}
  1650. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1651. {
  1652. // if(self.content_data_control.count>0)
  1653. // return 1;
  1654. NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy];
  1655. bool hide = [[sectionjson valueForKey:@"hide"]boolValue];
  1656. if(hide)
  1657. {
  1658. return 0;
  1659. // [sectionjson setValue:@"false" forKey:@"hide"];
  1660. // [sender setTitle:@"Show" forState:UIControlStateNormal];
  1661. }
  1662. else{
  1663. return ((NSMutableArray*)self.content_data_control[section]).count;
  1664. // [sectionjson setValue:@"true" forKey:@"hide"];
  1665. // [sender setTitle:@"Hide" forState:UIControlStateNormal];
  1666. }
  1667. // return 0;
  1668. // if(section==4)
  1669. // return 1;
  1670. // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]];
  1671. //
  1672. // return [[section_json valueForKey:@"count" ] intValue];
  1673. }
  1674. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1675. {
  1676. return 33;
  1677. }
  1678. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  1679. //{
  1680. // return 0.5;
  1681. //}
  1682. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  1683. {
  1684. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  1685. NSString* control = [item_json valueForKey:@"control"];
  1686. if([control isEqualToString:@"model"])
  1687. return 140;
  1688. else if([control isEqualToString:@"signature"])
  1689. return 140;
  1690. else if([control isEqualToString:@"text_view"])
  1691. return 140;
  1692. else if([control isEqualToString:@"img"])
  1693. return 123;
  1694. return 44;
  1695. }
  1696. //
  1697. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1698. {
  1699. bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue];
  1700. // int d=0;
  1701. // if(indexPath.section==4)
  1702. // d=0;
  1703. // NSLog(@"%d,%d",indexPath.section,indexPath.row);
  1704. // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1705. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1706. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  1707. NSString* control = [item_json valueForKey:@"control"];
  1708. NSString* required = [item_json valueForKey:@"required"];
  1709. NSString *CellIdentifier = @"";
  1710. if([control isEqualToString:@"text_view"])
  1711. {
  1712. CellIdentifier = @"CommonEditorCellTextView";
  1713. CommonEditorCellTextView * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1714. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  1715. NSString* value =[item_json valueForKey:@"value"];
  1716. NSString* align =[item_json valueForKey:@"align"];
  1717. if([align isEqualToString:@"right"])
  1718. cell.textview.textAlignment= kCTRightTextAlignment;
  1719. else
  1720. cell.textview.textAlignment =kCTLeftTextAlignment;
  1721. int disable = [[item_json valueForKey:@"disable"] intValue];
  1722. if(disable==1||readonly)
  1723. {
  1724. cell.textview.editable=NO;
  1725. // cell.textfield.backgroundColor = [UIColor lightGrayColor];
  1726. cell.textview.textColor= [UIColor lightGrayColor];
  1727. }
  1728. else
  1729. {
  1730. cell.textview.editable=YES;
  1731. cell.textview.textColor= [UIColor blackColor];
  1732. // cell.textfield.backgroundColor = [UIColor whiteColor];
  1733. }
  1734. if([required isEqualToString:@"true"])
  1735. {
  1736. [title appendString:@"*"];
  1737. }
  1738. cell.label_name.text=title;
  1739. cell.textview.text = value;
  1740. cell.textview.delegate = self;
  1741. cell.accessoryType = UITableViewCellAccessoryNone;
  1742. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  1743. {
  1744. CALayer *layer = [cell.contentView layer];
  1745. // layer.borderColor = [[UIColor redColor] CGColor];
  1746. // layer.borderWidth = 1.0;
  1747. layer.shadowColor = [UIColor redColor].CGColor;
  1748. layer.shadowOffset = CGSizeMake(0, 0);
  1749. layer.shadowOpacity = 1;
  1750. layer.shadowRadius = 2.0;
  1751. }
  1752. else
  1753. {
  1754. CALayer *layer = [cell.contentView layer];
  1755. // layer.borderColor = [[UIColor redColor] CGColor];
  1756. // layer.borderWidth = 1.0;
  1757. layer.shadowColor = [UIColor clearColor].CGColor;
  1758. layer.shadowOffset = CGSizeMake(0, 0);
  1759. layer.shadowOpacity = 1;
  1760. }
  1761. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  1762. return cell;
  1763. }else
  1764. if([control isEqualToString:@"img"])
  1765. {
  1766. CellIdentifier = @"CommonEditorCellImg";
  1767. CommonEditorCellImg * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1768. NSString* title = [item_json valueForKey:@"aname"] ;
  1769. NSString* value =[item_json valueForKey:@"value"];
  1770. int disable = [[item_json valueForKey:@"disable"] intValue];
  1771. if(disable==1||readonly)
  1772. {
  1773. cell.editable=false;
  1774. }
  1775. else
  1776. cell.editable=true;
  1777. cell.labelTitle.text = title;
  1778. cell.labelDescription.text = value;
  1779. cell.imgChanged = ^(NSString* url_down,NSString* url_up,int index ,NSString* url_index)
  1780. {
  1781. // NSMutableDictionary* editjson = [item_json mutableCopy];
  1782. // editjson[@"img_url"]=url;
  1783. [self imgIsChanged:url_down url_up:url_up indexPath:indexPath index:index url_index:url_index];
  1784. };
  1785. {
  1786. NSString* img_url0 = [item_json valueForKey:@"img_url_0"];
  1787. if(img_url0.length>0)
  1788. {
  1789. NSString* img_url_up=[item_json valueForKey:@"img_url_aname_0"];
  1790. if(img_url_up.length==0)
  1791. img_url_up=@"";
  1792. cell.imgs[0]=img_url_up;
  1793. NSString* file_name=[img_url0 lastPathComponent];
  1794. NSData* img_data=[iSalesDB load_cached_img:file_name];
  1795. if(img_data!=nil)
  1796. {
  1797. UIImage * img =[UIImage imageWithData:img_data];
  1798. cell.touchImageView0.image=img;
  1799. cell.img_validate = true;
  1800. // [cell.touchImageView setImage:img forState:UIControlStateNormal];
  1801. }
  1802. else
  1803. {
  1804. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1805. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url0]];
  1806. dispatch_async(dispatch_get_main_queue(), ^{
  1807. if(downloadimg_data!=nil)
  1808. {
  1809. [iSalesDB cache_img:downloadimg_data :file_name ];
  1810. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1811. cell.touchImageView0.image=img;
  1812. cell.img_validate = true;
  1813. }
  1814. else
  1815. {
  1816. cell.touchImageView0.image=[UIImage imageNamed:@"notfound_s"];
  1817. cell.img_validate = false;
  1818. }
  1819. });
  1820. });
  1821. }
  1822. }
  1823. else
  1824. {
  1825. cell.touchImageView0.image=nil;
  1826. cell.imgs[0]=@"";
  1827. }
  1828. }
  1829. {
  1830. NSString* img_url1 = [item_json valueForKey:@"img_url_1"];
  1831. if(img_url1.length>0)
  1832. {
  1833. NSString* img_url_up=[item_json valueForKey:@"img_url_aname_1"];
  1834. if(img_url_up.length==0)
  1835. img_url_up=@"";
  1836. cell.imgs[1]=img_url_up;
  1837. NSString* file_name=[img_url1 lastPathComponent];
  1838. NSData* img_data=[iSalesDB load_cached_img:file_name];
  1839. if(img_data!=nil)
  1840. {
  1841. UIImage * img =[UIImage imageWithData:img_data];
  1842. cell.touchImageView1.image=img;
  1843. cell.img_validate = true;
  1844. // [cell.touchImageView setImage:img forState:UIControlStateNormal];
  1845. }
  1846. else
  1847. {
  1848. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1849. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url1]];
  1850. dispatch_async(dispatch_get_main_queue(), ^{
  1851. if(downloadimg_data!=nil)
  1852. {
  1853. [iSalesDB cache_img:downloadimg_data :file_name ];
  1854. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1855. cell.touchImageView1.image=img;
  1856. cell.img_validate = true;
  1857. }
  1858. else
  1859. {
  1860. cell.touchImageView1.image=[UIImage imageNamed:@"notfound_s"] ;
  1861. cell.img_validate = false;
  1862. }
  1863. });
  1864. });
  1865. }
  1866. }
  1867. else
  1868. {
  1869. cell.touchImageView1.image=nil;
  1870. cell.imgs[1]=@"";
  1871. }
  1872. }
  1873. {
  1874. NSString* img_url2 = [item_json valueForKey:@"img_url_2"];
  1875. if(img_url2.length>0)
  1876. {
  1877. NSString* img_url_up=[item_json valueForKey:@"img_url_aname_2"];
  1878. if(img_url_up.length==0)
  1879. img_url_up=@"";
  1880. cell.imgs[2]=img_url_up;
  1881. NSString* file_name=[img_url2 lastPathComponent];
  1882. NSData* img_data=[iSalesDB load_cached_img:file_name];
  1883. if(img_data!=nil)
  1884. {
  1885. UIImage * img =[UIImage imageWithData:img_data];
  1886. cell.touchImageView2.image=img;
  1887. cell.img_validate = true;
  1888. // [cell.touchImageView setImage:img forState:UIControlStateNormal];
  1889. }
  1890. else
  1891. {
  1892. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1893. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url2]];
  1894. dispatch_async(dispatch_get_main_queue(), ^{
  1895. if(downloadimg_data!=nil)
  1896. {
  1897. [iSalesDB cache_img:downloadimg_data :file_name ];
  1898. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1899. cell.touchImageView2.image=img;
  1900. cell.img_validate = true;
  1901. }
  1902. else
  1903. {
  1904. cell.touchImageView2.image=[UIImage imageNamed:@"notfound_s"] ;
  1905. cell.img_validate = false;
  1906. }
  1907. });
  1908. });
  1909. }}
  1910. else
  1911. {
  1912. cell.touchImageView2.image=nil;
  1913. cell.imgs[2]=@"";
  1914. }
  1915. }
  1916. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  1917. return cell;
  1918. }else
  1919. if([control isEqualToString:@"edit"])
  1920. {
  1921. CellIdentifier = @"CommonEditorCellEdit";
  1922. CommonEditorCellEdit * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1923. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  1924. NSString* value =[item_json valueForKey:@"value"];
  1925. NSString* align =[item_json valueForKey:@"align"];
  1926. if([align isEqualToString:@"right"])
  1927. cell.textfield.textAlignment= NSTextAlignmentRight;
  1928. else
  1929. cell.textfield.textAlignment =NSTextAlignmentLeft;
  1930. int disable = [[item_json valueForKey:@"disable"] intValue];
  1931. if(disable==1||readonly)
  1932. {
  1933. cell.textfield.enabled=NO;
  1934. // cell.textfield.backgroundColor = [UIColor lightGrayColor];
  1935. cell.textfield.textColor= [UIColor lightGrayColor];
  1936. }
  1937. else
  1938. {
  1939. cell.textfield.enabled=YES;
  1940. cell.textfield.textColor= [UIColor blackColor];
  1941. // cell.textfield.backgroundColor = [UIColor whiteColor];
  1942. }
  1943. if([required isEqualToString:@"true"])
  1944. {
  1945. [title appendString:@"*"];
  1946. }
  1947. NSString* keyboard = [item_json valueForKey:@"keyboard"];
  1948. if([keyboard isEqualToString:@"number"])
  1949. {
  1950. // float f = [value floatValue];
  1951. // value = [NSString stringWithFormat:@"%.2f",f];
  1952. cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
  1953. }
  1954. else if([keyboard isEqualToString:@"email"])
  1955. {
  1956. cell.textfield.keyboardType=UIKeyboardTypeEmailAddress;
  1957. }
  1958. else if([keyboard isEqualToString:@"phone"])
  1959. {
  1960. cell.textfield.keyboardType=UIKeyboardTypePhonePad;
  1961. }
  1962. else
  1963. {
  1964. cell.textfield.keyboardType=UIKeyboardTypeDefault;
  1965. }
  1966. cell.labelTitle.text=title;
  1967. cell.textfield.text = value;
  1968. cell.textfield.delegate = self;
  1969. cell.accessoryType = UITableViewCellAccessoryNone;
  1970. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  1971. {
  1972. CALayer *layer = [cell.contentView layer];
  1973. // layer.borderColor = [[UIColor redColor] CGColor];
  1974. // layer.borderWidth = 1.0;
  1975. layer.shadowColor = [UIColor redColor].CGColor;
  1976. layer.shadowOffset = CGSizeMake(0, 0);
  1977. layer.shadowOpacity = 1;
  1978. layer.shadowRadius = 2.0;
  1979. }
  1980. else
  1981. {
  1982. CALayer *layer = [cell.contentView layer];
  1983. // layer.borderColor = [[UIColor redColor] CGColor];
  1984. // layer.borderWidth = 1.0;
  1985. layer.shadowColor = [UIColor clearColor].CGColor;
  1986. layer.shadowOffset = CGSizeMake(0, 0);
  1987. layer.shadowOpacity = 1;
  1988. }
  1989. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  1990. return cell;
  1991. }
  1992. else
  1993. if([control isEqualToString:@"text"])
  1994. {
  1995. CellIdentifier = @"CommonEditorCellLabel";
  1996. CommonEditorCellLabel * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1997. NSString* title = [item_json valueForKey:@"aname"] ;
  1998. NSString* value =[item_json valueForKey:@"value"];
  1999. NSString* align =[item_json valueForKey:@"align"];
  2000. if([align isEqualToString:@"right"])
  2001. cell.labelValue.textAlignment= NSTextAlignmentRight;
  2002. else
  2003. cell.labelValue.textAlignment =NSTextAlignmentLeft;
  2004. NSString* type=[item_json valueForKey:@"type"] ;
  2005. if([type isEqualToString:@"price"])
  2006. {
  2007. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2008. {
  2009. }
  2010. else
  2011. {
  2012. value=nil;
  2013. }
  2014. }
  2015. cell.labelTitle.text=title;
  2016. cell.labelValue.text = value;
  2017. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  2018. return cell;
  2019. }
  2020. else
  2021. if([control isEqualToString:@"action"])
  2022. {
  2023. CellIdentifier = @"CommonEditorCellAction";
  2024. CommonEditorCellAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2025. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  2026. NSString* value =[item_json valueForKey:@"value"];
  2027. if([required isEqualToString:@"true"])
  2028. {
  2029. [title appendString:@"*"];
  2030. }
  2031. NSDictionary* data = [item_json objectForKey:@"data"];
  2032. cell.labelAction.text=title;
  2033. cell.action_code = value;
  2034. //cell.labelValue.text = value;
  2035. if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil))
  2036. {
  2037. CALayer *layer = [cell.contentView layer];
  2038. // layer.borderColor = [[UIColor redColor] CGColor];
  2039. // layer.borderWidth = 1.0;
  2040. layer.shadowColor = [UIColor redColor].CGColor;
  2041. layer.shadowOffset = CGSizeMake(0, 0);
  2042. layer.shadowOpacity = 1;
  2043. layer.shadowRadius = 2.0;
  2044. }
  2045. else
  2046. {
  2047. CALayer *layer = [cell.contentView layer];
  2048. // layer.borderColor = [[UIColor redColor] CGColor];
  2049. // layer.borderWidth = 1.0;
  2050. layer.shadowColor = [UIColor clearColor].CGColor;
  2051. layer.shadowOffset = CGSizeMake(0, 0);
  2052. layer.shadowOpacity = 1;
  2053. }
  2054. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  2055. return cell;
  2056. }
  2057. if([control isEqualToString:@"multi_action"])
  2058. {
  2059. CellIdentifier = @"CommonEditorCellMAction";
  2060. CommonEditorCellMAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2061. int count = [[item_json valueForKey:@"count"]intValue];
  2062. for(int i=0;i<count;i++)
  2063. {
  2064. NSDictionary* sub_action= [item_json objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  2065. NSString * title = [sub_action valueForKey:@"aname"];
  2066. switch (i) {
  2067. case 0:
  2068. [cell.btn_action0 setTitle:title forState:UIControlStateNormal];
  2069. [cell.btn_action0 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
  2070. cell.btn_action0.hidden = NO;
  2071. break;
  2072. case 1:
  2073. [cell.btn_action1 setTitle:title forState:UIControlStateNormal];
  2074. [cell.btn_action1 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
  2075. cell.btn_action1.hidden = NO;
  2076. break;
  2077. case 2:
  2078. [cell.btn_action2 setTitle:title forState:UIControlStateNormal];
  2079. [cell.btn_action2 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
  2080. cell.btn_action2.hidden = NO;
  2081. break;
  2082. case 3:
  2083. [cell.btn_action3 setTitle:title forState:UIControlStateNormal];
  2084. [cell.btn_action3 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
  2085. cell.btn_action3.hidden = NO;
  2086. break;
  2087. default:
  2088. break;
  2089. }
  2090. }
  2091. if (count<4)
  2092. cell.btn_action3.hidden=YES;
  2093. if (count<3)
  2094. cell.btn_action2.hidden=YES;
  2095. if (count<2)
  2096. cell.btn_action1.hidden=YES;
  2097. if (count<1)
  2098. cell.btn_action0.hidden=YES;
  2099. // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  2100. // NSString* value =[item_json valueForKey:@"value"];
  2101. // if([required isEqualToString:@"true"])
  2102. // {
  2103. // [title appendString:@"*"];
  2104. // }
  2105. // NSDictionary* data = [item_json objectForKey:@"data"];
  2106. //
  2107. // cell.labelAction.text=title;
  2108. // cell.action_code = value;
  2109. //
  2110. //
  2111. // //cell.labelValue.text = value;
  2112. //
  2113. // if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil))
  2114. // {
  2115. // CALayer *layer = [cell.contentView layer];
  2116. // // layer.borderColor = [[UIColor redColor] CGColor];
  2117. // // layer.borderWidth = 1.0;
  2118. //
  2119. // layer.shadowColor = [UIColor redColor].CGColor;
  2120. // layer.shadowOffset = CGSizeMake(0, 0);
  2121. // layer.shadowOpacity = 1;
  2122. // layer.shadowRadius = 2.0;
  2123. // }
  2124. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  2125. return cell;
  2126. }
  2127. else
  2128. if([control isEqualToString:@"switch"])
  2129. {
  2130. CellIdentifier = @"CommonEditorCellSwitch";
  2131. CommonEditorCellSwitch * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2132. NSString* title = [item_json valueForKey:@"aname"];
  2133. NSString* value =[item_json valueForKey:@"value"];
  2134. cell.labelTitle.text=title;
  2135. [cell.switchCtrl addTarget:self
  2136. action:@selector(switchIsChanged:)
  2137. forControlEvents:UIControlEventValueChanged];
  2138. if([[value lowercaseString] isEqualToString:@"true"])
  2139. cell.switchCtrl.on = true;
  2140. else
  2141. cell.switchCtrl.on = false;
  2142. cell.accessoryType = UITableViewCellAccessoryNone;
  2143. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  2144. return cell;
  2145. } else if([control isEqualToString:@"enum"])
  2146. {
  2147. CellIdentifier = @"CommonEditorCellEnum";
  2148. CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2149. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  2150. NSDictionary* cadedate_json =[item_json objectForKey:@"cadedate"];
  2151. int disable = [[item_json valueForKey:@"disable"] intValue];
  2152. if(disable==1||readonly)
  2153. {
  2154. cell.labelValue.textColor= [UIColor lightGrayColor];
  2155. }
  2156. else
  2157. {
  2158. cell.labelValue.textColor= [UIColor blackColor];
  2159. // cell.textfield.backgroundColor = [UIColor whiteColor];
  2160. }
  2161. NSString* align =[item_json valueForKey:@"align"];
  2162. if([align isEqualToString:@"right"])
  2163. cell.labelValue.textAlignment= NSTextAlignmentRight;
  2164. else
  2165. cell.labelValue.textAlignment =NSTextAlignmentLeft;
  2166. if([required isEqualToString:@"true"])
  2167. {
  2168. [title appendString:@"*"];
  2169. }
  2170. NSString* value =@"";
  2171. int count = [[cadedate_json valueForKey:@"count"] intValue];
  2172. for(int i=0;i<count;i++)
  2173. {
  2174. NSDictionary* val_json =[cadedate_json objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  2175. int check = [[val_json valueForKey:@"check"] intValue];
  2176. if(check==1)
  2177. {
  2178. value = [value stringByAppendingString:[val_json valueForKey:@"value"]];
  2179. value = [value stringByAppendingString:@"|"];
  2180. }
  2181. }
  2182. if(value.length>=1)
  2183. value=[value substringToIndex:value.length-1];
  2184. cell.labelTitle.text=title;
  2185. cell.labelValue.text = value;
  2186. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  2187. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  2188. {
  2189. CALayer *layer = [cell.contentView layer];
  2190. // layer.borderColor = [[UIColor redColor] CGColor];
  2191. // layer.borderWidth = 1.0;
  2192. layer.shadowColor = [UIColor redColor].CGColor;
  2193. layer.shadowOffset = CGSizeMake(0, 0);
  2194. layer.shadowOpacity = 1;
  2195. layer.shadowRadius = 2.0;
  2196. }
  2197. else
  2198. {
  2199. CALayer *layer = [cell.contentView layer];
  2200. // layer.borderColor = [[UIColor redColor] CGColor];
  2201. // layer.borderWidth = 1.0;
  2202. layer.shadowColor = [UIColor clearColor].CGColor;
  2203. layer.shadowOffset = CGSizeMake(0, 0);
  2204. layer.shadowOpacity = 1;
  2205. }
  2206. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  2207. return cell;
  2208. } else if([control isEqualToString:@"model"])
  2209. {
  2210. CommonEditorCellModel * cell= [tableView dequeueReusableCellWithIdentifier:@"CommonEditorCellModel" forIndexPath:indexPath];
  2211. int count = [[item_json valueForKey:@"count"] intValue];
  2212. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2213. cell.bundle_item=combine_json;
  2214. double dprice=0.0;
  2215. if(cell.bundle_item!=nil)
  2216. {
  2217. int citem=0;
  2218. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  2219. for(int bc=0;bc<bcount;bc++)
  2220. {
  2221. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2222. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2223. citem+= modulus;
  2224. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2225. dprice+= uprice*modulus*count;
  2226. }
  2227. if(citem==1)
  2228. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2229. else
  2230. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2231. cell.buttonBundle.hidden = NO;
  2232. }
  2233. else
  2234. {
  2235. cell.buttonBundle.hidden = YES;
  2236. }
  2237. NSString* img_url = [item_json valueForKey:@"img_url"];
  2238. NSString* description = [item_json valueForKey:@"description"];
  2239. // NSString* identifier = [item_json valueForKey:@"identifier"];
  2240. // NSString* attribute = [item_json valueForKey:@"attribute"];
  2241. // NSString* total_price = [item_json valueForKey:@"total_price"] ;
  2242. // NSString* unit_price = [item_json valueForKey:@"unit_price"] ;
  2243. // NSString* mp = [item_json valueForKey:@"stockUom"];
  2244. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  2245. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  2246. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  2247. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  2248. NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice];
  2249. NSString* newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
  2250. NSString* totalprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)*count];
  2251. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2252. {
  2253. }
  2254. else
  2255. {
  2256. oldprice=nil;
  2257. newunitprice=nil;
  2258. totalprice=nil;
  2259. }
  2260. cell.labelDiscount.text = discountstr;
  2261. cell.labelOldPrice.text = oldprice;
  2262. cell.labelMasterPack.text =[NSString stringWithFormat:@"Master pack:%d", stockUom];
  2263. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2264. if(isfree)
  2265. {
  2266. cell.labelOldPrice.hidden = false;
  2267. cell.labelOldPrice.textColor = [UIColor redColor];
  2268. cell.labelOldPrice.text=@"Free";
  2269. cell.labelOldPrice.hideline = true;
  2270. cell.labelDiscount.hidden = true;
  2271. }
  2272. else
  2273. {
  2274. cell.labelOldPrice.textColor = [UIColor blackColor];
  2275. cell.labelOldPrice.hideline = false;
  2276. if(discount==0)
  2277. {
  2278. cell.labelOldPrice.hidden = true;
  2279. cell.labelDiscount.hidden = true;
  2280. }
  2281. else
  2282. {
  2283. cell.labelOldPrice.hidden = false;
  2284. cell.labelDiscount.hidden = false;
  2285. }
  2286. }
  2287. // if(discount==0)
  2288. // {
  2289. // cell.labelOldPrice.hidden = true;
  2290. // cell.labelDiscount.hidden = true;
  2291. //
  2292. // }
  2293. // else
  2294. // {
  2295. // cell.labelOldPrice.hidden = false;
  2296. // cell.labelDiscount.hidden = false;
  2297. // }
  2298. // NSString* currency = [item_json valueForKey:@"currency"];
  2299. // int count =[[item_json valueForKey:@"count"] intValue];
  2300. cell.labelDescription.text = description;
  2301. cell.labelCount.text = [NSString stringWithFormat:@"x %d",count];
  2302. // cell.labelID.text = identifier;
  2303. // cell.labelSubtype.text = attribute;
  2304. cell.labelTotalPrice.text= totalprice;
  2305. // cell.labelUnitPrice.text=unit_price;
  2306. cell.labelUnitPrice.text = newunitprice;
  2307. cell.imgModel.image = [UIImage imageNamed:@"loading_s"];
  2308. NSString* file_name=[img_url lastPathComponent];
  2309. NSData* img_data=[iSalesDB load_cached_img:file_name];
  2310. if(img_data!=nil)
  2311. {
  2312. UIImage * img =[UIImage imageWithData:img_data];
  2313. cell.imgModel.image = img;
  2314. }
  2315. else
  2316. {
  2317. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2318. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2319. dispatch_async(dispatch_get_main_queue(), ^{
  2320. if(downloadimg_data!=nil)
  2321. {
  2322. [iSalesDB cache_img:downloadimg_data :file_name ];
  2323. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2324. cell.imgModel.image = img;
  2325. }
  2326. else
  2327. cell.imgModel.image = [UIImage imageNamed:@"notfound_s"];
  2328. });
  2329. });
  2330. }
  2331. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  2332. return cell;
  2333. }else if([control isEqualToString:@"datepicker"])
  2334. {
  2335. CellIdentifier = @"CommonEditorCellEnum";
  2336. CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2337. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  2338. NSString* value =[item_json valueForKey:@"value"];
  2339. if([required isEqualToString:@"true"])
  2340. {
  2341. [title appendString:@"*"];
  2342. }
  2343. cell.labelTitle.text=title;
  2344. cell.labelValue.text = value;
  2345. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  2346. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  2347. {
  2348. CALayer *layer = [cell.contentView layer];
  2349. // layer.borderColor = [[UIColor redColor] CGColor];
  2350. // layer.borderWidth = 1.0;
  2351. layer.shadowColor = [UIColor redColor].CGColor;
  2352. layer.shadowOffset = CGSizeMake(0, 0);
  2353. layer.shadowOpacity = 1;
  2354. layer.shadowRadius = 2.0;
  2355. }
  2356. else
  2357. {
  2358. CALayer *layer = [cell.contentView layer];
  2359. // layer.borderColor = [[UIColor redColor] CGColor];
  2360. // layer.borderWidth = 1.0;
  2361. layer.shadowColor = [UIColor clearColor].CGColor;
  2362. layer.shadowOffset = CGSizeMake(0, 0);
  2363. layer.shadowOpacity = 1;
  2364. }
  2365. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  2366. return cell;
  2367. }
  2368. else if([control isEqualToString:@"monthpicker"])
  2369. {
  2370. CellIdentifier = @"CommonEditorCellEnum";
  2371. CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2372. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  2373. NSString* value =[item_json valueForKey:@"value"];
  2374. if([required isEqualToString:@"true"])
  2375. {
  2376. [title appendString:@"*"];
  2377. }
  2378. cell.labelTitle.text=title;
  2379. cell.labelValue.text = value;
  2380. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  2381. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  2382. {
  2383. CALayer *layer = [cell.contentView layer];
  2384. // layer.borderColor = [[UIColor redColor] CGColor];
  2385. // layer.borderWidth = 1.0;
  2386. layer.shadowColor = [UIColor redColor].CGColor;
  2387. layer.shadowOffset = CGSizeMake(0, 0);
  2388. layer.shadowOpacity = 1;
  2389. layer.shadowRadius = 2.0;
  2390. }
  2391. else
  2392. {
  2393. CALayer *layer = [cell.contentView layer];
  2394. // layer.borderColor = [[UIColor redColor] CGColor];
  2395. // layer.borderWidth = 1.0;
  2396. layer.shadowColor = [UIColor clearColor].CGColor;
  2397. layer.shadowOffset = CGSizeMake(0, 0);
  2398. layer.shadowOpacity = 1;
  2399. }
  2400. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  2401. return cell;
  2402. }
  2403. else if([control isEqualToString:@"signature"])
  2404. {
  2405. CellIdentifier = @"CommonEditorCellSignature";
  2406. CommonEditorCellSignature * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2407. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  2408. UIImage* signature = [item_json valueForKey:@"signature"];
  2409. if([required isEqualToString:@"true"])
  2410. {
  2411. [title appendString:@"*"];
  2412. }
  2413. cell.labelTitle.text = title;
  2414. if(signature!=nil)
  2415. {
  2416. cell.imageviewSignature.image=signature;
  2417. }
  2418. else
  2419. {
  2420. NSString* img_url = [item_json valueForKey:@"img_url"];
  2421. NSString* file_name=[img_url lastPathComponent];
  2422. NSData* img_data=[iSalesDB load_cached_img:file_name];
  2423. if(img_data!=nil)
  2424. {
  2425. UIImage * img =[UIImage imageWithData:img_data];
  2426. cell.imageviewSignature.image = img;
  2427. }
  2428. else
  2429. {
  2430. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2431. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2432. dispatch_async(dispatch_get_main_queue(), ^{
  2433. if(downloadimg_data!=nil)
  2434. {
  2435. [iSalesDB cache_img:downloadimg_data :file_name ];
  2436. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2437. cell.imageviewSignature.image = img;
  2438. }
  2439. });
  2440. });
  2441. }
  2442. }
  2443. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  2444. return cell;
  2445. // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
  2446. //cell.imageviewSignature.image = image;
  2447. }
  2448. else
  2449. {
  2450. CellIdentifier = @"CommonEditorCellEdit";
  2451. UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2452. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  2453. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  2454. return cell;
  2455. }
  2456. }
  2457. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  2458. {
  2459. NSString* btntitle=nil ;
  2460. NSString*labeltitle = nil;
  2461. NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy];
  2462. labeltitle= [sectionjson valueForKey:@"title"];
  2463. bool hide = [[sectionjson valueForKey:@"hide"]boolValue];
  2464. if(hide)
  2465. {
  2466. btntitle=@"Show";
  2467. // [section setValue:@"false" forKey:@"hide"];
  2468. // [sender setTitle:@"Show" forState:UIControlStateNormal];
  2469. }
  2470. else{
  2471. btntitle=@"Hide";
  2472. }
  2473. UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  2474. myView.backgroundColor = UIColorFromRGB(0x996633);;
  2475. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  2476. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  2477. myView.layer.shadowOffset = CGSizeMake(0, 0);
  2478. myView.layer.shadowOpacity = 0.5;
  2479. myView.layer.shadowRadius = 2.0;
  2480. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  2481. btn.tag=section;
  2482. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  2483. [btn setTitle:btntitle forState:UIControlStateNormal];
  2484. [myView addSubview:btn];
  2485. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  2486. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2487. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5, 200, 20)];
  2488. titlelabel.textColor=[UIColor whiteColor];
  2489. titlelabel.backgroundColor = [UIColor clearColor];
  2490. titlelabel.text=NSLocalizedString(labeltitle, nil);
  2491. [titlelabel sizeToFit];
  2492. [myView addSubview:titlelabel];
  2493. //
  2494. // UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 0, 90, 22)];
  2495. // contactlabel.textColor=[UIColor whiteColor];
  2496. // contactlabel.backgroundColor = [UIColor clearColor];
  2497. // contactlabel.text=NSLocalizedString(@"Contact", nil);
  2498. // [contactlabel sizeToFit];
  2499. // [myView addSubview:contactlabel];
  2500. //
  2501. //
  2502. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 0, 90, 22)];
  2503. // modellabel.textColor=[UIColor whiteColor];
  2504. // modellabel.backgroundColor = [UIColor clearColor];
  2505. // modellabel.text=NSLocalizedString(@"Model", nil);
  2506. // [modellabel sizeToFit];
  2507. // [myView addSubview:modellabel];
  2508. //
  2509. // UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(500, 0, 90, 22)];
  2510. // pricelabel.textColor=[UIColor whiteColor];
  2511. // pricelabel.backgroundColor = [UIColor clearColor];
  2512. // pricelabel.text=NSLocalizedString(@"Price", nil);
  2513. // [pricelabel sizeToFit];
  2514. // [myView addSubview:pricelabel];
  2515. //
  2516. //
  2517. //
  2518. // UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(630, 0, 90, 22)];
  2519. // timelabel.textColor=[UIColor whiteColor];
  2520. // timelabel.backgroundColor = [UIColor clearColor];
  2521. // timelabel.text=NSLocalizedString(@"Create time", nil);
  2522. // [timelabel sizeToFit];
  2523. // [myView addSubview:timelabel];
  2524. //
  2525. //
  2526. //
  2527. // UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 60, 22)];
  2528. // statuslabel.textColor=[UIColor whiteColor];
  2529. // statuslabel.backgroundColor = [UIColor clearColor];
  2530. // statuslabel.text=NSLocalizedString(@"Status", nil);
  2531. // [statuslabel sizeToFit];
  2532. // [myView addSubview:statuslabel];
  2533. //
  2534. return myView;
  2535. }
  2536. //
  2537. -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2538. {
  2539. bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue];
  2540. NSLog(@"tableView willSelectRowAtIndexPath");
  2541. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  2542. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2543. NSString* control = [item_json valueForKey:@"control"];
  2544. if([control isEqualToString:@"enum"])//||[control isEqualToString:@"ui"])
  2545. {
  2546. int disable = [[item_json valueForKey:@"disable"] intValue];
  2547. if(disable==1||readonly)
  2548. return nil;
  2549. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
  2550. NSDictionary* cadedate_json = [item_json objectForKey:@"cadedate"];
  2551. // NSDictionary* value_json = [item_json objectForKey:@"value"];
  2552. NSString* single_select = [item_json valueForKey:@"single_select"];
  2553. // NSString* required =[item_json valueForKey:@"required"];
  2554. NSString* title = [item_json valueForKey:@"aname"];
  2555. int max_select = [[item_json valueForKey:@"max"] intValue];
  2556. EnumSelectViewController* enumvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
  2557. enumvc.delegate = self;
  2558. enumvc.max_select = max_select;
  2559. enumvc.updatePosition = indexPath;
  2560. // if([[required lowercaseString] isEqualToString:@"true"])
  2561. // enumvc.canbeEmpty = false;
  2562. // else
  2563. // enumvc.canbeEmpty =true;
  2564. enumvc.cadedate = [cadedate_json mutableCopy];
  2565. enumvc.title = title;
  2566. // enumvc.value = [value_json mutableCopy];
  2567. enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"];
  2568. [self.navigationController pushViewController:enumvc animated:true];
  2569. }else if([control isEqualToString:@"action"])
  2570. {
  2571. NSString* value = [item_json valueForKey:@"value"];
  2572. if([value isEqualToString:@"new_addr"])
  2573. {
  2574. AddressEditorViewController * addressVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AddressEditorViewController"];
  2575. addressVC.url_type = URL_REMOTE;
  2576. addressVC.request_url=URL_ADDRESS_EDOTOR;
  2577. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2578. // NSString * string = [checked componentsJoinedByString:@","];
  2579. // [params setValue:string forKey:@"cart2Checkbox"];
  2580. addressVC.params = params;
  2581. addressVC.delegate = self;
  2582. addressVC.from = indexPath;
  2583. // orderinfoVC.params = params;
  2584. [self.navigationController pushViewController:addressVC animated:true];
  2585. }else if([value isEqualToString:@"credit_card"])
  2586. {
  2587. CreditCardEditorViewController * cardVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreditCardEditorViewController"];
  2588. NSDictionary *data = [item_json objectForKey:@"data"];
  2589. if(data!=nil)
  2590. {
  2591. cardVC.content_data_download = [data mutableCopy];
  2592. cardVC.url_type = URL_NONE;
  2593. cardVC.request_url=nil;
  2594. }
  2595. else
  2596. {
  2597. cardVC.url_type = URL_REMOTE;
  2598. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  2599. }
  2600. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2601. params[@"orderCode"]=appDelegate.order_code;
  2602. cardVC.params = params;
  2603. cardVC.delegate = self;
  2604. cardVC.from = indexPath;
  2605. // orderinfoVC.params = params;
  2606. [self.navigationController pushViewController:cardVC animated:true];
  2607. }
  2608. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  2609. {
  2610. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2611. cvc.showNavibar = true;
  2612. cvc.contact_type = value;
  2613. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2614. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2615. //
  2616. // if(self.returnValue)
  2617. // self.returnValue(value);
  2618. };
  2619. [self.navigationController pushViewController:cvc animated:true];
  2620. }
  2621. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  2622. {
  2623. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2624. cvc.showNavibar = true;
  2625. cvc.contact_type = value;
  2626. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2627. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2628. //
  2629. // if(self.returnValue)
  2630. // self.returnValue(value);
  2631. };
  2632. [self.navigationController pushViewController:cvc animated:true];
  2633. }
  2634. else if([value isEqualToString:@"Sales_Order_Customer"])
  2635. {
  2636. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2637. cvc.contact_type = value;
  2638. cvc.showNavibar = true;
  2639. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2640. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2641. //
  2642. // if(self.returnValue)
  2643. // self.returnValue(value);
  2644. };
  2645. [self.navigationController pushViewController:cvc animated:true];
  2646. }
  2647. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  2648. {
  2649. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2650. cvc.showNavibar = true;
  2651. cvc.contact_type = value;
  2652. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2653. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2654. //
  2655. // if(self.returnValue)
  2656. // self.returnValue(value);
  2657. };
  2658. [self.navigationController pushViewController:cvc animated:true];
  2659. }
  2660. else if([value isEqualToString:@"Contact_Return_To"])
  2661. {
  2662. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2663. cvc.showNavibar = true;
  2664. cvc.contact_type = value;
  2665. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2666. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2667. //
  2668. // if(self.returnValue)
  2669. // self.returnValue(value);
  2670. };
  2671. [self.navigationController pushViewController:cvc animated:true];
  2672. }
  2673. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  2674. {
  2675. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2676. cvc.showNavibar = true;
  2677. cvc.contact_type = value;
  2678. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2679. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2680. //
  2681. // if(self.returnValue)
  2682. // self.returnValue(value);
  2683. };
  2684. [self.navigationController pushViewController:cvc animated:true];
  2685. }
  2686. }
  2687. else if([control isEqualToString:@"datepicker"])
  2688. {
  2689. // NSString* title = [item_json valueForKey:@"aname"];
  2690. NSString* value =[item_json valueForKey:@"value"];
  2691. NSString* type =[item_json valueForKey:@"type"];
  2692. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  2693. DatePickerViewController* dpvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"DatePickerViewController"];
  2694. if([[type lowercaseString] isEqualToString:@"date"])
  2695. {
  2696. dpvc.pickerMode = UIDatePickerModeDate;
  2697. [dateFormatter setDateFormat:@"yyyy/MM/dd"];
  2698. }
  2699. else if([[type lowercaseString] isEqualToString:@"time"])
  2700. {
  2701. dpvc.pickerMode = UIDatePickerModeTime;
  2702. [dateFormatter setDateFormat:@"HH:mm:ss"];
  2703. }
  2704. else
  2705. {
  2706. dpvc.pickerMode = UIDatePickerModeDateAndTime;
  2707. [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
  2708. }
  2709. NSDate *date = [dateFormatter dateFromString:value];
  2710. dpvc.date = date;
  2711. dpvc.formatter = dateFormatter;
  2712. dpvc.labelTime.text = value;
  2713. [self.navigationController pushViewController:dpvc animated:true];
  2714. }else if([control isEqualToString:@"monthpicker"])
  2715. {
  2716. // NSString* title = [item_json valueForKey:@"aname"];
  2717. NSString* value =[item_json valueForKey:@"value"];
  2718. if (value==nil || value.length==0)
  2719. {
  2720. value=@"1/2015";
  2721. }
  2722. // NSString* type =[item_json valueForKey:@"type"];
  2723. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  2724. MonthPickerViewController* mpvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"MonthPickerViewController"];
  2725. // if([[type lowercaseString] isEqualToString:@"date"])
  2726. // {
  2727. // dpvc.pickerMode = UIDatePickerModeDate;
  2728. [dateFormatter setDateFormat:@"MM/yyyy"];
  2729. NSDate *date = [dateFormatter dateFromString:value];
  2730. mpvc.current_date =date;
  2731. mpvc.updatePosition = indexPath;
  2732. mpvc.delegate = self;
  2733. // }
  2734. // else if([[type lowercaseString] isEqualToString:@"time"])
  2735. // {
  2736. // dpvc.pickerMode = UIDatePickerModeTime;
  2737. // [dateFormatter setDateFormat:@"HH:mm:ss"];
  2738. // }
  2739. // else
  2740. // {
  2741. // dpvc.pickerMode = UIDatePickerModeDateAndTime;
  2742. // [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
  2743. // }
  2744. // NSDate *date = [dateFormatter dateFromString:value];
  2745. // dpvc.date = date;
  2746. // dpvc.formatter = dateFormatter;
  2747. // dpvc.labelTime.text = value;
  2748. [self.navigationController pushViewController:mpvc animated:true];
  2749. }
  2750. else if([control isEqualToString:@"signature"])
  2751. {
  2752. SignatureViewController * signvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  2753. signvc.title = [item_json valueForKey:@"aname"];
  2754. signvc.indexPath = indexPath;
  2755. // signvc.delegate = self;
  2756. CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
  2757. signvc.existSignature = cell.imageviewSignature.image ;
  2758. [self.navigationController pushViewController:signvc animated:true];
  2759. }
  2760. // else if([control isEqualToString:@"action "])
  2761. // {
  2762. //
  2763. // NSLog(@"action push");
  2764. // // SignatureViewController * signvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  2765. // // signvc.title = [item_json valueForKey:@"aname"];
  2766. // // signvc.indexPath = indexPath;
  2767. // // signvc.delegate = self;
  2768. // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
  2769. // //
  2770. // // signvc.existSignature = cell.imageviewSignature.image ;
  2771. // //
  2772. // //
  2773. // //
  2774. // // [self.navigationController pushViewController:signvc animated:true];
  2775. // }
  2776. return nil;
  2777. }
  2778. //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2779. //{
  2780. //
  2781. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
  2782. //
  2783. // NSString* orderid = [item_json valueForKey:@"id"];
  2784. //
  2785. // // if (self.delegate && [self.delegate respondsToSelector:@selector(SelectOrder:)]) {
  2786. // // [self.delegate SelectOrder:orderid];
  2787. // // }
  2788. // //
  2789. // // [self dismissViewControllerAnimated:YES
  2790. // // completion:^{
  2791. // // //一定要移除手势 否则下次 没有子视图的时候 点击 会崩溃拉
  2792. // // AppDelegate *app = [[UIApplication sharedApplication] delegate];
  2793. // // [app.window removeGestureRecognizer:self.tapGesture];
  2794. // // }];
  2795. // // [pvc categoryMenuSelected:indexPath.row];
  2796. //}
  2797. -(NSMutableDictionary*) enum_subitem_changed:(NSMutableDictionary *) item subid:(NSArray*) subid value:(NSMutableDictionary*)value step:(int) step
  2798. {
  2799. int index = [(NSString*)subid[step] intValue];
  2800. NSMutableDictionary * cadedate= [[item objectForKey:@"cadedate"] mutableCopy];
  2801. NSMutableDictionary * subitem= [[item objectForKey:@"sub_item"] mutableCopy];
  2802. if(cadedate!=nil)
  2803. {
  2804. NSMutableDictionary * valjson=[[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",index]]mutableCopy];
  2805. valjson= [self enum_subitem_changed:valjson subid:subid value:value step:step+1];
  2806. [cadedate setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",index]];
  2807. [item setObject:cadedate forKey:@"cadedate"];
  2808. return item;
  2809. }
  2810. else if(subitem!=nil)
  2811. {
  2812. NSMutableDictionary * itemjson=[[subitem objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy];
  2813. if(step==subid.count-1)
  2814. {
  2815. itemjson =value;
  2816. }
  2817. else
  2818. itemjson =[self enum_subitem_changed:itemjson subid:subid value:value step:step+1];
  2819. [subitem setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]];
  2820. [item setObject:subitem forKey:@"sub_item"];
  2821. return item;
  2822. }
  2823. return nil;
  2824. }
  2825. #pragma mark monthpicker ViewControllerDelegate
  2826. -(void) MPValueChanged:(NSString *)value indexPath :(NSIndexPath*) indexPath
  2827. {
  2828. CommonEditorCellEnum * cell= (CommonEditorCellEnum*) [self.editorTable cellForRowAtIndexPath:indexPath];
  2829. cell.labelValue.text = value;
  2830. // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  2831. // UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview;
  2832. // NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  2833. NSMutableDictionary* section_json=nil;
  2834. // NSLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  2835. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  2836. // NSString* check=@"false";
  2837. // if([paramSender isOn])
  2838. // check=@"true";
  2839. // [item_json setValue:value forKey:@"dirty"];
  2840. NSString* subid=[item_json valueForKey:@"subid"];
  2841. [item_json setValue:value forKey:@"value"];
  2842. if(subid==nil)
  2843. {
  2844. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  2845. int count=0;
  2846. count=[[section_json valueForKey:@"count"] intValue];
  2847. for(int i=0;i<count;i++)
  2848. {
  2849. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  2850. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  2851. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  2852. }
  2853. }
  2854. else
  2855. {
  2856. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  2857. int section = [(NSString*)idarr[0] intValue];
  2858. int item=[(NSString*)idarr[1] intValue];
  2859. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  2860. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  2861. NSString* control_type= [olditem valueForKey:@"control"];
  2862. if([control_type isEqualToString:@"enum"])
  2863. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  2864. else if([control_type isEqualToString:@"switch"])
  2865. item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  2866. [item_json setValue:@"true" forKey:@"dirty"];
  2867. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  2868. }
  2869. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  2870. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  2871. }
  2872. #pragma mark EnumSelectViewControllerDelegate
  2873. -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  2874. {
  2875. UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
  2876. // if(/*self.cancommit==false &&*/ string.length==0 && (textField.text.length<=1|| textField.text==nil))
  2877. // {
  2878. // CALayer *layer = [cell.contentView layer];
  2879. // // layer.borderColor = [[UIColor redColor] CGColor];
  2880. // // layer.borderWidth = 1.0;
  2881. //
  2882. // layer.shadowColor = [UIColor redColor].CGColor;
  2883. // layer.shadowOffset = CGSizeMake(0, 0);
  2884. // layer.shadowOpacity = 1;
  2885. // layer.shadowRadius = 2.0;
  2886. // }
  2887. // else
  2888. {
  2889. CALayer *layer = [cell.contentView layer];
  2890. // layer.borderColor = [[UIColor redColor] CGColor];
  2891. // layer.borderWidth = 1.0;
  2892. layer.shadowColor = [UIColor clearColor].CGColor;
  2893. layer.shadowOffset = CGSizeMake(0, 0);
  2894. layer.shadowOpacity = 1;
  2895. layer.shadowRadius = 2.0;
  2896. }
  2897. NSLog(@"enum changed %ld_%ld",(long)indexPath.section,(long)indexPath.row);
  2898. NSMutableDictionary* section_json=nil;
  2899. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  2900. // NSString* param_name=[item_json valueForKey:@"name"];
  2901. // NSString* param_val=nil;
  2902. //
  2903. // bool single_select =[[item_json valueForKey:@"single_select"] boolValue];
  2904. //
  2905. // int cade_count = [[value valueForKey:@"count"] intValue];
  2906. //
  2907. // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
  2908. //
  2909. //
  2910. // for(int cc=0;cc<cade_count;cc++)
  2911. // {
  2912. // NSDictionary * valjson=[value objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
  2913. // if([[valjson valueForKey:@"check"] boolValue])
  2914. // {
  2915. // [arr_val addObject: [valjson valueForKey:@"value_id"]];
  2916. // if(single_select)
  2917. // break;
  2918. // }
  2919. //
  2920. // }
  2921. //
  2922. // param_val = [arr_val componentsJoinedByString:@","];
  2923. //
  2924. // [self.changed_data setObject:param_val forKey:param_name];
  2925. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  2926. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  2927. NSString* subid=[item_json valueForKey:@"subid"];
  2928. [item_json setObject:value forKey:@"cadedate"];
  2929. if(subid==nil)
  2930. {
  2931. [item_json setValue:@"true" forKey:@"dirty"];
  2932. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  2933. int count=0;
  2934. count=[[section_json valueForKey:@"count"] intValue];
  2935. for(int i=0;i<count;i++)
  2936. {
  2937. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  2938. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  2939. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  2940. }
  2941. }
  2942. else
  2943. {
  2944. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  2945. int section = [(NSString*)idarr[0] intValue];
  2946. int item=[(NSString*)idarr[1] intValue];
  2947. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  2948. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  2949. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  2950. [item_json setValue:@"true" forKey:@"dirty"];
  2951. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  2952. }
  2953. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  2954. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  2955. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  2956. NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  2957. if(refresh==1)
  2958. {
  2959. if(restore_json!=nil)
  2960. {
  2961. int rc=[[restore_json valueForKey:@"count"] intValue];
  2962. for(int ir=0;ir<rc;ir++)
  2963. {
  2964. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  2965. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  2966. for(int i=0;i<section_count;i++)
  2967. {
  2968. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2969. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2970. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  2971. for(int j=0;j<item_count;j++)
  2972. {
  2973. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2974. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2975. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  2976. {
  2977. [itemjson removeObjectForKey:@"dirty"];
  2978. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  2979. }
  2980. }
  2981. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  2982. }
  2983. }
  2984. }
  2985. [self refresh:refresh_trigger] ;
  2986. return ;
  2987. }
  2988. NSLog(@"CONTENT UPDATE:%@",[iSalesNetwork DataTOjsonString:self.content_data_download]);
  2989. // NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  2990. [self.editorTable reloadData ];
  2991. }
  2992. #pragma mark SignatureViewControllerDelegate
  2993. //-(void)SignatureVCReturnData:(NSData *)imagedata indexPath:(NSIndexPath *)indexPath
  2994. //{
  2995. //
  2996. //}
  2997. -(void)SignatureVCReturnImage:(UIImage *)image indexPath:(NSIndexPath *)indexPath
  2998. {
  2999. // NSMutableDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  3000. //
  3001. // if(image==nil)
  3002. // [item_json removeObjectForKey:@"signature"];
  3003. // else
  3004. // [item_json setObject:image forKey:@"signature"];
  3005. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  3006. // [self.content_data setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  3007. //
  3008. //
  3009. //
  3010. // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
  3011. // cell.imageviewSignature.image = image;
  3012. }
  3013. #pragma mark textView delegate
  3014. //- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
  3015. //- (BOOL)textViewShouldEndEditing:(UITextView *)textView;
  3016. - (BOOL)textViewShouldBeginEditing:(UITextView *)textView
  3017. {
  3018. NSLog(@"textViewShouldBeginEditing");
  3019. self.editingcell = (UITableViewCell*)textView.superview.superview;
  3020. return textView.editable;
  3021. }
  3022. - (void)textViewDidBeginEditing:(UITextView *)textView
  3023. {
  3024. self.lasttextview = textView;
  3025. UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
  3026. self.lasttextview_from = [self.editorTable indexPathForCell:cell];
  3027. }
  3028. - (void)textViewDidEndEditing:(UITextView *)textView
  3029. {
  3030. UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
  3031. NSIndexPath * indexPath = self.lasttextview_from;//[self.editorTable indexPathForCell:cell];
  3032. NSMutableDictionary* section_json=nil;
  3033. // NSLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  3034. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  3035. NSString* subid=[item_json valueForKey:@"subid"];
  3036. [item_json setValue:@"true" forKey:@"dirty"];
  3037. [item_json setValue:textView.text forKey:@"value"];
  3038. // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
  3039. if(subid==nil)
  3040. {
  3041. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  3042. int count=0;
  3043. count=[[section_json valueForKey:@"count"] intValue];
  3044. for(int i=0;i<count;i++)
  3045. {
  3046. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  3047. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  3048. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  3049. }
  3050. }
  3051. else
  3052. {
  3053. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  3054. int section = [(NSString*)idarr[0] intValue];
  3055. int item=[(NSString*)idarr[1] intValue];
  3056. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  3057. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  3058. NSString* control_type= [olditem valueForKey:@"control"];
  3059. if([control_type isEqualToString:@"enum"])
  3060. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  3061. else if([control_type isEqualToString:@"switch"])
  3062. item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  3063. [item_json setValue:@"true" forKey:@"dirty"];
  3064. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  3065. }
  3066. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  3067. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  3068. self.lasttextview = nil;
  3069. self.lasttextview_from=nil;
  3070. // if(self.resize)
  3071. // {
  3072. // NSTimeInterval animationDuration = 0.30f;
  3073. // CGRect frame = self.view.frame;
  3074. // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
  3075. // // { //还原界面
  3076. // // moveY = prewMoveY;
  3077. // frame.origin.y +=self.ioffset;
  3078. // frame.size. height -=self.ioffset;
  3079. // self.view.frame = frame;
  3080. // // }
  3081. // //self.view移回原位置
  3082. // [UIView beginAnimations:@"ResizeView" context:nil];
  3083. // [UIView setAnimationDuration:animationDuration];
  3084. // self.view.frame = frame;
  3085. // [UIView commitAnimations];
  3086. // //[textField resignFirstResponder];
  3087. // self.ioffset=0;
  3088. // }
  3089. }
  3090. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  3091. {
  3092. UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
  3093. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  3094. // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  3095. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  3096. NSString* required = [item_json valueForKey:@"required"];
  3097. if([required isEqualToString:@"true"] && text.length==0 && (textView.text.length<=1|| textView.text==nil))
  3098. {
  3099. CALayer *layer = [cell.contentView layer];
  3100. // layer.borderColor = [[UIColor redColor] CGColor];
  3101. // layer.borderWidth = 1.0;
  3102. layer.shadowColor = [UIColor redColor].CGColor;
  3103. layer.shadowOffset = CGSizeMake(0, 0);
  3104. layer.shadowOpacity = 1;
  3105. layer.shadowRadius = 2.0;
  3106. }
  3107. else
  3108. {
  3109. CALayer *layer = [cell.contentView layer];
  3110. // layer.borderColor = [[UIColor redColor] CGColor];
  3111. // layer.borderWidth = 1.0;
  3112. layer.shadowColor = [UIColor clearColor].CGColor;
  3113. layer.shadowOffset = CGSizeMake(0, 0);
  3114. layer.shadowOpacity = 1;
  3115. layer.shadowRadius = 2.0;
  3116. }
  3117. return YES;
  3118. }
  3119. //- (void)textViewDidChange:(UITextView *)textView;
  3120. //
  3121. //- (void)textViewDidChangeSelection:(UITextView *)textView;
  3122. //
  3123. //- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
  3124. //- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
  3125. #pragma mark textField delegate
  3126. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  3127. NSLog(@"textField shouldChangeCharactersInRange");
  3128. NSLog(@"text:%@",textField.text);
  3129. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  3130. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  3131. // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  3132. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  3133. NSString* required = [item_json valueForKey:@"required"];
  3134. if([required isEqualToString:@"true"] && string.length==0 && (textField.text.length<=1|| textField.text==nil))
  3135. {
  3136. CALayer *layer = [cell.contentView layer];
  3137. // layer.borderColor = [[UIColor redColor] CGColor];
  3138. // layer.borderWidth = 1.0;
  3139. layer.shadowColor = [UIColor redColor].CGColor;
  3140. layer.shadowOffset = CGSizeMake(0, 0);
  3141. layer.shadowOpacity = 1;
  3142. layer.shadowRadius = 2.0;
  3143. }
  3144. else
  3145. {
  3146. CALayer *layer = [cell.contentView layer];
  3147. // layer.borderColor = [[UIColor redColor] CGColor];
  3148. // layer.borderWidth = 1.0;
  3149. layer.shadowColor = [UIColor clearColor].CGColor;
  3150. layer.shadowOffset = CGSizeMake(0, 0);
  3151. layer.shadowOpacity = 1;
  3152. layer.shadowRadius = 2.0;
  3153. }
  3154. NSString* keyboard = [item_json valueForKey:@"keyboard"];
  3155. if(![keyboard isEqualToString:@"number"] && ![keyboard isEqualToString:@"int"])
  3156. return TRUE;
  3157. NSCharacterSet *cs;
  3158. cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
  3159. NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
  3160. BOOL canChange = [string isEqualToString:filtered];
  3161. return canChange;
  3162. }
  3163. - (void)textFieldDidEndEditing:(UITextField *)textField
  3164. {
  3165. NSLog(@"textFieldDidEndEditing");
  3166. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  3167. NSIndexPath * indexPath = self.lastedit_from;
  3168. NSMutableDictionary* section_json=nil;
  3169. // NSLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  3170. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  3171. NSString* subid=[item_json valueForKey:@"subid"];
  3172. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  3173. [item_json setValue:@"true" forKey:@"dirty"];
  3174. [item_json setValue:textField.text forKey:@"value"];
  3175. if([[item_json valueForKey:@"keyboard"] isEqualToString:@"number"])
  3176. {
  3177. float f = [ textField.text floatValue];
  3178. [item_json setValue:[NSString stringWithFormat:@"%.2f",f] forKey:@"value"];
  3179. }
  3180. // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
  3181. if(subid==nil)
  3182. {
  3183. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  3184. int count=0;
  3185. count=[[section_json valueForKey:@"count"] intValue];
  3186. for(int i=0;i<count;i++)
  3187. {
  3188. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  3189. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  3190. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  3191. }
  3192. }
  3193. else
  3194. {
  3195. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  3196. int section = [(NSString*)idarr[0] intValue];
  3197. int item=[(NSString*)idarr[1] intValue];
  3198. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  3199. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  3200. NSString* control_type= [olditem valueForKey:@"control"];
  3201. if([control_type isEqualToString:@"enum"])
  3202. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  3203. else if([control_type isEqualToString:@"switch"])
  3204. item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  3205. [item_json setValue:@"true" forKey:@"dirty"];
  3206. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  3207. }
  3208. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  3209. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  3210. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  3211. NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  3212. if(refresh==1)
  3213. {
  3214. if(restore_json!=nil)
  3215. {
  3216. int rc=[[restore_json valueForKey:@"count"] intValue];
  3217. for(int ir=0;ir<rc;ir++)
  3218. {
  3219. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  3220. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  3221. for(int i=0;i<section_count;i++)
  3222. {
  3223. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  3224. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  3225. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  3226. for(int j=0;j<item_count;j++)
  3227. {
  3228. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  3229. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  3230. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  3231. {
  3232. [itemjson removeObjectForKey:@"dirty"];
  3233. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  3234. }
  3235. }
  3236. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  3237. }
  3238. }
  3239. }
  3240. [self refresh:refresh_trigger] ;
  3241. return ;
  3242. }
  3243. self.lastedit = nil;
  3244. self.lastedit_from=nil;
  3245. }
  3246. - (void)textFieldDidBeginEditing:(UITextField *)textField
  3247. {
  3248. NSLog(@"textField shouldChangeCharactersInRange");
  3249. self.lastedit = textField;
  3250. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  3251. self.lastedit_from = [self.editorTable indexPathForCell:cell];
  3252. }
  3253. #pragma mark- img changed
  3254. // image 改变时执行
  3255. - (void) imgIsChanged:(NSString *)url_down url_up:(NSString *)url_up indexPath: (NSIndexPath *) indexPath index:(int)index url_index:(NSString* )url_index{
  3256. // NSLog(@"Sender is = %@", url);
  3257. NSMutableDictionary* section_json=nil;
  3258. // NSLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  3259. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  3260. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  3261. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  3262. NSString* subid=[item_json valueForKey:@"subid"];
  3263. // NSArray* imgs=[RAUtils string2arr:url_up separator:@","];
  3264. // imgs[index];
  3265. item_json[ [NSString stringWithFormat:@"img_url_%d",index]]=url_down;
  3266. item_json[@"avalue"]=url_up;
  3267. item_json[[NSString stringWithFormat:@"img_url_aname_%d",index]]=url_index;
  3268. [item_json setValue:@"true" forKey:@"dirty"];
  3269. if(subid==nil)
  3270. {
  3271. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  3272. int count=0;
  3273. count=[[section_json valueForKey:@"count"] intValue];
  3274. for(int i=0;i<count;i++)
  3275. {
  3276. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  3277. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  3278. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  3279. }
  3280. }
  3281. else
  3282. {
  3283. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  3284. int section = [(NSString*)idarr[0] intValue];
  3285. int item=[(NSString*)idarr[1] intValue];
  3286. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  3287. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  3288. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  3289. [item_json setValue:@"true" forKey:@"dirty"];
  3290. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  3291. }
  3292. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  3293. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  3294. // NSRange range = NSMakeRange(indexPath.section, 1);
  3295. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  3296. // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  3297. if(refresh==1)
  3298. {
  3299. [self refresh:refresh_trigger];
  3300. }
  3301. }
  3302. #pragma mark- switch changed
  3303. - (void) switchIsChanged:(UISwitch *)paramSender{
  3304. NSLog(@"Sender is = %@", paramSender);
  3305. UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview;
  3306. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  3307. NSMutableDictionary* section_json=nil;
  3308. // NSLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  3309. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  3310. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  3311. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  3312. NSString* subid=[item_json valueForKey:@"subid"];
  3313. NSString* check=@"false";
  3314. if([paramSender isOn])
  3315. check=@"true";
  3316. [item_json setValue:@"true" forKey:@"dirty"];
  3317. [item_json setValue:check forKey:@"value"];
  3318. if(subid==nil)
  3319. {
  3320. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  3321. int count=0;
  3322. count=[[section_json valueForKey:@"count"] intValue];
  3323. for(int i=0;i<count;i++)
  3324. {
  3325. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  3326. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  3327. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  3328. }
  3329. }
  3330. else
  3331. {
  3332. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  3333. int section = [(NSString*)idarr[0] intValue];
  3334. int item=[(NSString*)idarr[1] intValue];
  3335. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  3336. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  3337. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  3338. [item_json setValue:@"true" forKey:@"dirty"];
  3339. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  3340. }
  3341. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  3342. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  3343. NSRange range = NSMakeRange(indexPath.section, 1);
  3344. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  3345. [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  3346. if(refresh==1)
  3347. {
  3348. [self refresh:refresh_trigger];
  3349. }
  3350. }
  3351. -(NSMutableDictionary*) fill_switch_subitem:(NSMutableDictionary *) switch_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step
  3352. {
  3353. NSString* value = [switch_item valueForKey:@"value"];
  3354. NSMutableDictionary* boolitem=nil;
  3355. NSMutableDictionary* subjson=nil;
  3356. if([value isEqualToString:@"true"])
  3357. {
  3358. boolitem =[[switch_item objectForKey:@"true"] mutableCopy];
  3359. }
  3360. else
  3361. {
  3362. boolitem =[[switch_item objectForKey:@"false"] mutableCopy];
  3363. }
  3364. subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  3365. if( subjson!=nil /*&& !active*/)
  3366. {
  3367. int sub_count = [[subjson valueForKey:@"count"] intValue];
  3368. for(int l=0;l<sub_count;l++)
  3369. {
  3370. NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  3371. // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  3372. NSString* mapto = [modify_item valueForKey:@"name"];
  3373. if(mapto.length==0)
  3374. continue;
  3375. NSString* valuefrom= [mapping valueForKey:[modify_item valueForKey:@"name"]];
  3376. if(valuefrom==nil)
  3377. continue;
  3378. NSString* valuestr= [source valueForKey:valuefrom];
  3379. if(TRUE)
  3380. {
  3381. if(valuestr.length>0)
  3382. [modify_item setValue:valuestr forKey:@"value"];
  3383. else
  3384. [modify_item setValue:@"" forKey:@"value"];
  3385. [modify_item setValue:@"true" forKey:@"dirty"];
  3386. [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]];
  3387. }
  3388. }
  3389. [boolitem setObject:subjson forKey:@"sub_item"];
  3390. if([value isEqualToString:@"true"])
  3391. [switch_item setObject:boolitem forKey:@"true"];
  3392. else
  3393. [switch_item setObject:boolitem forKey:@"false"];
  3394. }
  3395. return switch_item;
  3396. }
  3397. -(NSMutableDictionary*) fill_enum_subitem:(NSMutableDictionary *) enum_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step
  3398. {
  3399. NSMutableDictionary* cadedatejson = [[enum_item objectForKey:@"cadedate"] mutableCopy];
  3400. int count = [[cadedatejson valueForKey:@"count"]intValue];
  3401. for(int i=0;i<count;i++)
  3402. {
  3403. NSMutableDictionary* val_json = [[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",i]] mutableCopy];
  3404. int check = [[val_json valueForKey:@"check"] intValue];
  3405. if(check==1)
  3406. {
  3407. NSMutableDictionary* subjson=[[val_json objectForKey:@"sub_item"] mutableCopy];
  3408. if( subjson!=nil /*&& !active*/)
  3409. {
  3410. int sub_count = [[subjson valueForKey:@"count"] intValue];
  3411. for(int l=0;l<sub_count;l++)
  3412. {
  3413. NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  3414. // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  3415. NSString* mapto = [modify_item valueForKey:@"name"];
  3416. if(mapto.length==0)
  3417. continue;
  3418. NSString* valuefrom= [mapping valueForKey:[modify_item valueForKey:@"name"]];
  3419. if(valuefrom==nil)
  3420. continue;
  3421. NSString* valuestr= [source valueForKey:valuefrom];
  3422. if(true)
  3423. {
  3424. if(valuestr.length>0)
  3425. [modify_item setValue:valuestr forKey:@"value"];
  3426. else
  3427. [modify_item setValue:@"" forKey:@"value"];
  3428. //[modify_item setValue:valuestr forKey:@"value"];
  3429. [modify_item setValue:@"true" forKey:@"dirty"];
  3430. [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]];
  3431. }
  3432. }
  3433. }
  3434. [val_json setObject:subjson forKey:@"sub_item"];
  3435. }
  3436. [cadedatejson setObject:val_json forKey:[NSString stringWithFormat:@"val_%d",i]];
  3437. }
  3438. [enum_item setObject:cadedatejson forKey:@"cadedate"];
  3439. return enum_item;
  3440. }
  3441. -(NSMutableDictionary*) switch_subitem_changed:(NSMutableDictionary *) switch_item subid:(NSArray*) subid value:(NSMutableDictionary*)valuejson step:(int) step
  3442. {
  3443. int index = [(NSString*)subid[step] intValue];
  3444. NSString* value = [switch_item valueForKey:@"value"];
  3445. NSMutableDictionary* boolitem=nil;
  3446. NSMutableDictionary* subjson=nil;
  3447. if([value isEqualToString:@"true"])
  3448. {
  3449. boolitem =[[switch_item objectForKey:@"true"] mutableCopy];
  3450. }
  3451. else
  3452. {
  3453. boolitem =[[switch_item objectForKey:@"false"] mutableCopy];
  3454. }
  3455. subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  3456. if(subjson!=nil)
  3457. {
  3458. NSMutableDictionary * itemjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy];
  3459. if(step==subid.count-1)
  3460. {
  3461. itemjson =valuejson;
  3462. }
  3463. [subjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]];
  3464. [boolitem setObject:subjson forKey:@"sub_item"];
  3465. if([value isEqualToString:@"true"])
  3466. [switch_item setObject:boolitem forKey:@"true"];
  3467. else
  3468. [switch_item setObject:boolitem forKey:@"false"];
  3469. return switch_item;
  3470. }
  3471. return nil;
  3472. }
  3473. #pragma mark -
  3474. #pragma mark Responding to keyboard events
  3475. - (void)keyboardWillChangeFrame:(NSNotification *)notification {
  3476. NSLog(@"keyboardWillChangeFrame");
  3477. }
  3478. - (void)keyboardWillShow:(NSNotification *)notification {
  3479. NSLog(@"keyboardWillShow");
  3480. if(self.keyboard_show)
  3481. return;
  3482. self.keyboard_show=true;
  3483. /*
  3484. Reduce the size of the text view so that it's not obscured by the keyboard.
  3485. Animate the resize so that it's in sync with the appearance of the keyboard.
  3486. */
  3487. NSDictionary *userInfo = [notification userInfo];
  3488. // Get the origin of the keyboard when it's displayed.
  3489. NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  3490. // Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position.
  3491. // CGRect keyboardRect = [aValue CGRectValue];
  3492. CGSize keyboardSize = [aValue CGRectValue].size;
  3493. NSLog(@"keyboard height:%f",keyboardSize.height);
  3494. // Get the duration of the animation.
  3495. NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
  3496. NSTimeInterval animationDuration;
  3497. [animationDurationValue getValue:&animationDuration];
  3498. // if(self.keyboard_h==0)
  3499. // {
  3500. self.keyboard_h =keyboardSize.height;
  3501. CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:self.editingcell];
  3502. CGRect rect_screen = [ UIScreen mainScreen ].bounds;
  3503. // int vpos =self.view.frame.origin.y+self.view.frame.size.height;
  3504. // int loginpos = self.editingcell.frame.origin.y+self.editingcell.frame.size.height;
  3505. //
  3506. int cellpos = cellrect_screen.origin.y+cellrect_screen.size.height;
  3507. // screen.size.height-keyboardSize.height-(cellpos_screen.origin.x+cellpos_screen.size.height);
  3508. self.ioffset = cellpos-(rect_screen.size.height-keyboardSize.height);//rect_screen.size.height-keyboardSize.height-(rect_screen.origin.y+rect_screen.size.height);//keyboardSize.height -(self.view.frame.size.height-loginpos);
  3509. if(self.ioffset>0)
  3510. {
  3511. // self.resize = true;
  3512. CGPoint contentOffsetPoint = self.editorTable.contentOffset;
  3513. contentOffsetPoint.y+=self.ioffset;
  3514. self.editorTable.contentOffset=contentOffsetPoint;
  3515. // NSTimeInterval animationDuration = 0.30f;
  3516. // CGRect frame = self.view.frame;
  3517. // frame.origin.y -=self.ioffset;//view的Y轴上移
  3518. // frame.size.height +=self.ioffset; //View的高度增加
  3519. // self.view.frame = frame;
  3520. // [UIView beginAnimations:@"ResizeView" context:nil];
  3521. // [UIView setAnimationDuration:animationDuration];
  3522. // self.view.frame = frame;
  3523. // [UIView commitAnimations];//设置调整界面的动画效果
  3524. }
  3525. self.editorTable.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-self.keyboard_h);
  3526. // CGSize tablecontent =self.editorTable.contentSize;
  3527. // tablecontent.height=tablecontent.height+self.keyboard_h;
  3528. // self.editorTable.contentSize=tablecontent;
  3529. // }
  3530. // Animate the resize of the text view's frame in sync with the keyboard's appearance.
  3531. // [self moveInputBarWithKeyboardHeight:keyboardRect.size.height withDuration:animationDuration];
  3532. }
  3533. - (void)keyboardWillHide:(NSNotification *)notification {
  3534. NSLog(@"keyboardWillHide");
  3535. self.keyboard_show=false;
  3536. NSDictionary* userInfo = [notification userInfo];
  3537. /*
  3538. Restore the size of the text view (fill self's view).
  3539. Animate the resize so that it's in sync with the disappearance of the keyboard.
  3540. */
  3541. NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
  3542. NSTimeInterval animationDuration;
  3543. [animationDurationValue getValue:&animationDuration];
  3544. CGSize tablecontent =self.editorTable.contentSize;
  3545. tablecontent.height=tablecontent.height-self.keyboard_h;
  3546. // self.editorTable.contentSize=tablecontent;
  3547. self.editorTable.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
  3548. self.keyboard_h= 0;
  3549. NSLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  3550. // if(self.resize)
  3551. // {
  3552. // NSTimeInterval animationDuration = 0.30f;
  3553. // CGRect frame = self.view.frame;
  3554. // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
  3555. // // { //还原界面
  3556. // // moveY = prewMoveY;
  3557. // frame.origin.y +=self.ioffset;
  3558. // frame.size. height -=self.ioffset;
  3559. // self.view.frame = frame;
  3560. // // }
  3561. // //self.view移回原位置
  3562. // [UIView beginAnimations:@"ResizeView" context:nil];
  3563. // [UIView setAnimationDuration:animationDuration];
  3564. // self.view.frame = frame;
  3565. // [UIView commitAnimations];
  3566. // //[textField resignFirstResponder];
  3567. // self.ioffset=0;
  3568. // }
  3569. // [self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration];
  3570. }
  3571. @end