CommonEditorViewController.m 198 KB

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