CommonEditorViewController.m 255 KB

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