CommonEditorViewController.m 289 KB

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