| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663 |
- //
- // CommonEditorViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 14-7-16.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "CommonEditorViewController.h"
- #import "CommonEditorCellEdit.h"
- #import "RANetwork.h"
- #import "CommonEditorCellEnum.h"
- #import "CommonEditorCellSwitch.h"
- #import "CommonEditorCellModel.h"
- #import "CommonEditorCellAction.h"
- #import "EnumSelectViewController.h"
- #import "DatePickerViewController.h"
- #import "SignatureViewController.h"
- #import "CommonEditorCellSignature.h"
- #import "CommonEditorCellLabel.h"
- //#import "AddressEditorViewController.h"
- //#import "CreditCardEditorViewController.h"
- #import "MonthPickerViewController.h"
- //#import "ContactListViewController.h"
- #import "CommonEditorCellMAction.h"
- #import "CommonEditorCellTextView.h"
- #import "RAUtils.h"
- #import "CommonEditorCellImg.h"
- #import "RAConvertor.h"
- //#import "AFHTTPSessionManager.h"
- //#import "NetworkUtils.h"
- #import "config.h"
- #import "CustomIOSAlertView.h"
- #import "DefaultAppearance.h"
- #import "DefaultTableHeaderView.h"
- #define INTNUMBERS @"0123456789\n"
- #define NUMBERS @"0123456789.\n"
- # ifdef OFFLINE_MODE
- #import "OLDataProvider.h"
- # endif
- #import <objc/objc.h>
- #import "MainViewController.h"
- #import "AppDelegate.h"
- #import "FileCache.h"
- //#import "RAConvertor.h"
- #import "EnumSelectAndSortViewController.h"
- #import "CommonEditorRangeCell.h"
- #import "CommonEditorWebCell.h"
- #import "CommonEditorBannerCell.h"
- #import "ContentPreviewController.h"
- #import "NetworkUtils.h"
- @interface subitem_data ()
- @end
- @implementation subitem_data
- @end
- @interface CommonEditorViewController ()<CommonEditorRangeDelegate,CommonEditorWebCellDelegate,CommonEditorBannerDelegate>
- @end
- @implementation CommonEditorViewController
- - (void)viewDidLayoutSubviews {
- [super viewDidLayoutSubviews];
- [self resize_tableHeader];
- }
- #pragma mark - Code TableView
- - (UIView*)get_tableHeader
- {
- return [UIView new];
- }
- -(void) resize_tableHeader
- {
- //利用systemLayoutSizeFittingSize:计算出真实高度
- CGFloat height = [self.editorTable.tableHeaderView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
- CGRect headerFrame = self.editorTable.tableHeaderView.frame;
- headerFrame.size.height = height;//20是留的上下边距
- //修改tableHeaderView的frame
- self.editorTable.tableHeaderView.frame = headerFrame;
- }
- - (void)initTableView {
-
- self.editorTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- self.editorTable.translatesAutoresizingMaskIntoConstraints = NO;
- [self.tableContainer addSubview:self.editorTable];
- [self.tableContainer sendSubviewToBack:self.editorTable];
-
- NSLayoutConstraint *top_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
- attribute:NSLayoutAttributeTop
- relatedBy:NSLayoutRelationEqual
- toItem:self.tableContainer
- attribute:NSLayoutAttributeTop
- multiplier:1
- constant:0];
- self.tb_top_constraint = top_constraint;
- [self.tableContainer addConstraint:top_constraint];
-
- NSLayoutConstraint *left_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
- attribute:NSLayoutAttributeLeft
- relatedBy:NSLayoutRelationEqual
- toItem:self.tableContainer
- attribute:NSLayoutAttributeLeft
- multiplier:1
- constant:0];
- self.tb_left_constraint = left_constraint;
- [self.tableContainer addConstraint:left_constraint];
-
- NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
- attribute:NSLayoutAttributeBottom
- relatedBy:NSLayoutRelationEqual
- toItem:self.tableContainer
- attribute:NSLayoutAttributeBottom
- multiplier:1
- constant:0];
- self.tb_bottom_constraint = bottom_constraint;
- [self.tableContainer addConstraint:bottom_constraint];
-
- NSLayoutConstraint *right_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
- attribute:NSLayoutAttributeRight
- relatedBy:NSLayoutRelationEqual
- toItem:self.tableContainer
- attribute:NSLayoutAttributeRight
- multiplier:1
- constant:0];
- self.tb_right_constraint = right_constraint;
- [self.tableContainer addConstraint:right_constraint];
-
-
-
- self.editorTable.delegate = self;
- self.editorTable.dataSource = self;
- self.editorTable.tableFooterView = [UIView new];
- // self.editorTable.tableHeaderView = [UIView new];
- self.editorTable.tableHeaderView = [self get_tableHeader];
- }
- - (void)registerPhoneCell {
-
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Action_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellAction"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Edit_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEdit"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Enum_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEnum"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Image_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellImg"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Label_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellLabel"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_MAction_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellMAction"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Model_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellModel"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Signature_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSignature"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Switch_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSwitch"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_TextView_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellTextView"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Range_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorRangeCell"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Web_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorWebCell"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Banner_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorBannerCell"];
- }
- - (void)registerPadCell {
-
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellAction" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellAction"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellEdit" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEdit"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellEnum" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEnum"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellImg" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellImg"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellLabel" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellLabel"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellMAction" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellMAction"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellModel" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellModel"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellSignature" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSignature"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellSwitch" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSwitch"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellTextView" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellTextView"];
- // [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorRangeCell" bundle:nil] forCellReuseIdentifier:@"CommonEditorRangeCell"];
- // [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorWebCell" bundle:nil] forCellReuseIdentifier:@"CommonEditorWebCell"];
- // [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorBannerCell" bundle:nil] forCellReuseIdentifier:@"CommonEditorBannerCell"];
- }
- - (void)setupEditorTable {
-
- [self initTableView];
- // Regist Nib Cell
- NSString *model = [UIDevice currentDevice].model;
- if ([model isEqualToString:@"iPhone"]) {
- [self registerPhoneCell];
- }
- else
- {
- [self registerPadCell];
- }
- }
- #pragma mark ==============
- -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json
- {
-
-
- NSAssert(true, ([NSString stringWithFormat:@"%@ commonAction not impl",[self class_name]]));
- }
- - (NSString *)class_name {
- if (!_class_name) {
- const char *class_name_ch = object_getClassName([self class]);
- _class_name = [NSString stringWithUTF8String:class_name_ch];
- }
- return _class_name;
- }
- - (NSString *)urgency_timer_name {
- if (!_urgency_timer_name) {
- _urgency_timer_name = [NSString stringWithFormat:@"%@_urgency_timer",self.class_name];
- }
- return _urgency_timer_name;
- }
- - (int)level {
- if (_level == -1) {
-
- __block AppDelegate *appDelegate = nil;
-
- dispatch_async(dispatch_get_main_queue(), ^{
- //some UI methods ej
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- });
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- NSDictionary *urgencyDic = [appDelegate globalParameterForKey:@"urgencyDic"];
-
- id count = [urgencyDic objectForKey:@"count"];
-
- _level = count == nil ? 0 : [count intValue];
- }
- return _level;
- }
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void) request_fill
- {
-
- }
- -(void) viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
-
- // 键盘高度变化通知,ios5.0新增的
- #ifdef __IPHONE_5_0
- float version = [[[UIDevice currentDevice] systemVersion] floatValue];
- if (version >= 5.0) {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
- }
- #endif
-
- }
- -(void) viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- -(void)manually_refresh
- {
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
-
- if ([self respondsToSelector:@selector(reload_data)])
- [self performSelector:@selector(reload_data) withObject:nil afterDelay:1];
- // DebugLog(@"refresh!!!!!!!!");
-
- }
- -(void)reload_data
- {
-
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-
- [reF endRefreshing];
-
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- [self refresh:nil];
- }
- - (void)alertMessage:(NSString *)msg {
-
-
- [RAUtils message_alert:msg title:nil controller:self] ;
-
- }
- -(void)dealloc
- {
-
- [self.autocompleteView removeFromSuperview];
- // [self.editorTable removeObserver:self forKeyPath:@"frame"];
-
- }
- //- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
- //{
- // // 方式1.匹配keypath
- // if ([keyPath isEqualToString:@"frame"]) {
- //
- // self.autocompleteView.frame = self.editorTable.frame;
- // }
- //
- //
- //}
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
-
-
-
- NSString *model = [UIDevice currentDevice].model;
- if ([model isEqualToString:@"iPhone"]||true) {
- [self setupEditorTable];
- } else {
- // 在键盘事件中,使用tableContainer计算frame 保证屏幕旋转后table height正确
- if (self.tableContainer == nil) {
- self.tableContainer = [[CommonEditorTableContainerView alloc] initWithFrame:self.editorTable.frame];
- self.tableContainer.autoresizingMask = self.editorTable.autoresizingMask;
- CGRect frame = self.editorTable.frame;
- frame.origin.x = 0;
- frame.origin.y = 0;
- [self.view addSubview:self.tableContainer];
- [self.view sendSubviewToBack:self.tableContainer];
- [self.tableContainer addSubview:self.editorTable];
- }
- }
-
-
- NSArray* nibView = [[NSBundle mainBundle] loadNibNamed:@"CommonEditorAutoCompleteView" owner:nil options:nil];
- self.autocompleteView = [nibView firstObject];
-
- self.autocompleteView.dataSource = self;
- // [self.tableContainer addSubview:self.autocompleteView];
- [self.navigationController.view addSubview:self.autocompleteView];
- self.autocompleteView.frame = self.navigationController.view.frame;
- // self.autocompleteView.frame = self.editorTable.frame;
- // [self.editorTable addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
- self.autocompleteView.hidden = true;
-
-
- // [self.view bringSubviewToFront:self.autocompleteView];
-
- //
-
-
- // self.switchlock = [[NSLock alloc] init];
-
-
- // [self.editorTable setExclusiveTouch:false];
-
- self.editable = NO;
-
- if(self.loading_msg==nil)
- self.loading_msg = @"Please Wait";
- if(self.loading_title==nil)
- self.loading_title = @"Loading...";
-
- UIRefreshControl *ref = [[UIRefreshControl alloc]init];
- ref.tag = 200 ;
- ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- // ref.hidden = true;
- [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
-
- if(!self.disable_dropdown_refresh)
- [self.editorTable addSubview:ref];
-
- self.level = -1;
-
- if (!self.changed_data) {
- self.changed_data = [[NSMutableDictionary alloc] init];
- }
-
- // UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
- // // closeButton.title = @"Close";
- //
- // self.navigationItem.leftBarButtonItem = closeButton;
- __weak typeof(self) weakself = self;
- if(self.url_type==URL_REMOTE)
- {
-
- UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
-
- [RANetwork request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* editor_json = result;
- DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
-
-
-
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- weakself.content_data_download = [editor_json mutableCopy];
-
- weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
-
- // self.content_data = [editor_json mutableCopy];
- // self.content_data = [self translate_json:editor_json];
-
- // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
-
- [weakself download_success];
-
- [weakself.editorTable reloadData];
-
- // NSString * ttt=[self.content_data valueForKey:@"title"] ;
-
- weakself.navigationItem.title = [weakself.content_data_download valueForKey:@"title"] ;
- }
- else
- {
- [weakself download_failed];
- [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
-
- }
-
-
-
- }];
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* editor_json = [weakself request_Editor:weakself.request_url params:weakself.params];
- // DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- //
- //
- // if([[editor_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // weakself.content_data_download = [editor_json mutableCopy];
- //
- // weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
- //
- // // self.content_data = [editor_json mutableCopy];
- // // self.content_data = [self translate_json:editor_json];
- //
- // // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
- //
- // [weakself download_success];
- //
- // [weakself.editorTable reloadData];
- //
- // // NSString * ttt=[self.content_data valueForKey:@"title"] ;
- //
- // weakself.navigationItem.title = [weakself.content_data_download valueForKey:@"title"] ;
- // }
- // else
- // {
- // [weakself download_failed];
- // [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
- //
- // }
- //
- //
- // });
- // });
- }
- else if(self.url_type== URL_LOCAL )
- {
-
- NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
- NSError *error=nil;
- self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
- self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
-
- self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- [self.editorTable reloadData];
-
- // NSString * ttt=[self.content_data valueForKey:@"title"] ;
-
- // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- }
- else
- {
-
- self.content_data_control=[self translate_json:self.content_data_download changed: self.changed_data];
- [self.editorTable reloadData];
-
- // NSString * ttt=[self.content_data valueForKey:@"title"] ;
-
- self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- }
-
-
- self.requried = [[NSMutableDictionary alloc] init];
-
- self.cancommit = true;
-
- // 恢复编辑后重置URL Type,避免刷新Crash
- if (self.url_type == URL_RESTORE) {
- self.url_type = URL_REMOTE;
- }
- }
- -(NSMutableDictionary*) check_cancommit :(bool) alert
- {
- [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
- // [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)];
-
-
- [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
-
- self.first_miss_pos = nil;
-
- self.cancommit=true;
- NSMutableArray* fields=[[NSMutableArray alloc] init];
- NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
- // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
- int section_count=(int)self.content_data_control.count;//[[self.content_data_download valueForKey:@"section_count"] intValue];
-
-
- // NSString* aaa = [RAUtils dict2string:self.content_data_control];
- for(int i=0;i<section_count;i++)
- {
- DebugLog(@"debug...section:%d",i);
- NSMutableArray * sectionjson = [self.content_data_control[i] mutableCopy];//[[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = (int)sectionjson.count;//[[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[sectionjson[j] mutableCopy];//[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- NSString* key = [itemjson valueForKey:@"name"];
- if(key==nil || key.length==0)
- continue;
- if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
- {
- NSString* single_select = [itemjson valueForKey:@"single_select"];
- if([single_select isEqualToString:@"true"])
- {
- NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- bool setvalue = false;
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
- [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
-
- setvalue=true;
- break;
- }
- }
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
-
- }
- }
- else //multiple select
- {
- NSMutableArray* checked = [[NSMutableArray alloc] init];
- NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
-
- // [checked addObject:[NSNumber numberWithInt:[[valjson valueForKey:@"value_id"] intValue]]];
- [checked addObject:[NSString stringWithFormat:@"%@",[valjson valueForKey:@"value_id"]]];
-
-
- }
- }
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"]&&checked.count==0)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- else
- {
- NSString * string = [checked componentsJoinedByString:@","];
- [upparams setValue:string forKey:[itemjson valueForKey:@"name"]];
- }
- }
- /*
- upparams setValue:itemjson forKey:<#(NSString *)#>
-
- */
- }else
- if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
-
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- NSString* valuestr = [itemjson valueForKey:@"value"];
- [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
- {
- NSString* valuestr = [itemjson valueForKey:@"value"];
- [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
-
- NSString* value = [itemjson valueForKey:@"value"];
- NSMutableDictionary* boolitem=nil;
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- {
- boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
-
- }
- else
- {
- boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
-
- }
- subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
- if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
- [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
- else
- {
- if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[modify_item valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- }
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"img"])
- {
- if([itemjson valueForKey:@"avalue"]!=nil && ![[itemjson valueForKey:@"avalue"]isEqualToString:@""])
- [upparams setValue:[itemjson valueForKey:@"avalue"] forKey:[itemjson valueForKey:@"name"]];
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"edit"])
- {
- int min_length = [[itemjson valueForKey:@"min_length"] intValue];
- NSString* check_len_val =itemjson[@"value"];
- if( check_len_val.length<min_length)
- {
- self.cancommit = false;
-
-
-
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is too short",fields.count+1,itemjson[@"aname"]];
-
-
- if(check_len_val.length==0 &&[[itemjson valueForKey:@"required"] isEqualToString: @"true"])
- mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- else if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""] )
- {
- NSString *keyboard_type = [itemjson objectForKey:@"keyboard"];
- BOOL check_max = [itemjson objectForKey:@"max_type"] != nil ? YES : NO;
- BOOL check_min = [itemjson objectForKey:@"min_type"] != nil ? YES : NO;
- if ([keyboard_type isEqualToString:@"number"] && (check_max || check_min)) {
- // 检查最大值最小值
- int max_type = [[itemjson objectForKey:@"max_type"] intValue];
- int min_type = [[itemjson objectForKey:@"min_type"] intValue];
-
- float max_value = MAXFLOAT;
- float min_value = 0;
-
- NSString *mfield = nil;
- float f_value = [check_len_val floatValue];
-
- if (check_max) {
-
- if (max_type > 0) {
- // key
- NSString *max_key = [itemjson objectForKey:@"max"];
- id max_obj = [self downloadValueForKey:max_key];
- if (max_obj) {
- max_value = [max_obj floatValue];
- }
-
- } else {
- // value
- id max_obj = [itemjson objectForKey:@"max"];
- if (max_obj != nil) {
- max_value = [max_obj floatValue];
- }
-
- }
-
- if (max_value < f_value) {
- mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not larger than %.2f",fields.count+1,itemjson[@"aname"],max_value];
- }
- }
-
- if (check_min) {
-
- if (min_type > 0) {
- // key
- NSString *min_key = [itemjson objectForKey:@"min"];
- id min_obj = [self downloadValueForKey:min_key];
- if (min_obj) {
- min_value = [min_obj floatValue];
- }
- } else {
- // value
- id min_obj = [itemjson objectForKey:@"min"];
- if (min_obj != nil) {
- min_value = [min_obj floatValue];
- }
- }
-
- if (min_value > f_value) {
- mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not smaller than %.2f",fields.count+1,itemjson[@"aname"],min_value];
- }
- }
-
-
- if (check_min && check_max) {
- if (f_value < min_value || f_value > max_value) {
- mfield =[NSString stringWithFormat:@"%ld. the value of %@ must between %.2f and %.2f",fields.count+1,itemjson[@"aname"],min_value,max_value];
- }
- }
-
- if (mfield != nil) {
- self.cancommit = false;
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- } else {
- [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- }
-
- } else {
- [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- }
-
- }
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- else if ([[itemjson valueForKey:@"control"] isEqualToString:@"range"])
- {
-
- if([itemjson valueForKey:@"min_value"]!=nil && ![[itemjson valueForKey:@"min_value"]isEqualToString:@""] &&[itemjson valueForKey:@"max_value"]!=nil && ![[itemjson valueForKey:@"max_value"]isEqualToString:@""])
- {
- NSMutableDictionary* valjson = [NSMutableDictionary new];
- if([itemjson valueForKey:@"min_value"]!=nil && ![[itemjson valueForKey:@"min_value"]isEqualToString:@""])
- valjson[@"min"] = itemjson[@"min_value"];
- if([itemjson valueForKey:@"max_value"]!=nil && ![[itemjson valueForKey:@"max_value"]isEqualToString:@""])
- valjson[@"max"] = itemjson[@"max_value"];
-
- NSString* val=[RAConvertor dict2string:valjson];
- // NSString *keyboard_type = [itemjson objectForKey:@"keyboard"];
- // BOOL check_max = [itemjson objectForKey:@"max_type"] != nil ? YES : NO;
- // BOOL check_min = [itemjson objectForKey:@"min_type"] != nil ? YES : NO;
- // if ([keyboard_type isEqualToString:@"number"] && (check_max || check_min)) {
- // // 检查最大值最小值
- // int max_type = [[itemjson objectForKey:@"max_type"] intValue];
- // int min_type = [[itemjson objectForKey:@"min_type"] intValue];
- //
- // float max_value = MAXFLOAT;
- // float min_value = 0;
- //
- // NSString *mfield = nil;
- //// float f_value = [check_len_val floatValue];
- ////
- //// if (check_max) {
- ////
- //// if (max_type > 0) {
- //// // key
- //// NSString *max_key = [itemjson objectForKey:@"max"];
- //// id max_obj = [self downloadValueForKey:max_key];
- //// if (max_obj) {
- //// max_value = [max_obj floatValue];
- //// }
- ////
- //// } else {
- //// // value
- //// id max_obj = [itemjson objectForKey:@"max"];
- //// if (max_obj != nil) {
- //// max_value = [max_obj floatValue];
- //// }
- ////
- //// }
- ////
- //// if (max_value < f_value) {
- //// mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not larger than %.2f",fields.count+1,itemjson[@"aname"],max_value];
- //// }
- //// }
- //
- //// if (check_min) {
- ////
- //// if (min_type > 0) {
- //// // key
- //// NSString *min_key = [itemjson objectForKey:@"min"];
- //// id min_obj = [self downloadValueForKey:min_key];
- //// if (min_obj) {
- //// min_value = [min_obj floatValue];
- //// }
- //// } else {
- //// // value
- //// id min_obj = [itemjson objectForKey:@"min"];
- //// if (min_obj != nil) {
- //// min_value = [min_obj floatValue];
- //// }
- //// }
- ////
- //// if (min_value > f_value) {
- //// mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not smaller than %.2f",fields.count+1,itemjson[@"aname"],min_value];
- //// }
- //// }
- //
- //
- //// if (check_min && check_max) {
- //// if (f_value < min_value || f_value > max_value) {
- //// mfield =[NSString stringWithFormat:@"%ld. the value of %@ must between %.2f and %.2f",fields.count+1,itemjson[@"aname"],min_value,max_value];
- //// }
- //// }
- //
- // if (mfield != nil) {
- // self.cancommit = false;
- // [fields addObject:mfield];
- // NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- // if(alert)
- // [self unhide_section:(int)indexpath.section];
- // if(fields.count==1)
- // {
- // self.first_miss_pos = indexpath;
- //
- // }
- // } else {
- // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- // }
- //
- // } else
- // {
- [upparams setValue:val forKey:[itemjson valueForKey:@"name"]];
- // }
-
- }
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%lu. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- else
- {
- if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
- [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- // subitem_data * data=[self subitem_param:itemjson addto:upparams alert:alert];
- // upparams= data.params;
- // fields=[[fields arrayByAddingObjectsFromArray:data.missingfields] mutableCopy];
- }
- }
- if(self.cancommit==false && alert)
- {
- NSString* missfields=[fields componentsJoinedByString:@"\n"];
- NSString* msg = [NSString stringWithFormat:@"%@",missfields];
-
- CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
-
-
-
-
- // Add some custom content to the alert view
- [alertView setContainerView:[self createDemoView:msg]];
-
- // Modify the parameters
-
-
-
- [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"OK", nil]];
- //[alertView setDelegate:self];
-
- // You may use a Block, rather than a delegate.
- [alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
- // DebugLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, (int)[alertView tag]);
- [alertView close];
- }];
-
- // [alertView setUseMotionEffects:true];
-
- // And launch the dialog
-
- [alertView sizeToFit];
- [alertView show];
-
- // [RAUtils alert_view:msg title:@"Please complete missing fields:"];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- [self.editorTable reloadData];
-
- [self.editorTable scrollToRowAtIndexPath:self.first_miss_pos atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
- return upparams;
- }
- else
- {
- self.cancommit=true;
- //[self.editorTable reloadData];
- }
-
- return upparams;
-
- }
- - (UIView *)createDemoView:(NSString*) msg
- {
- UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
-
- // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
- // [imageView setImage:[UIImage imageNamed:@"demo"]];
-
- UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
- titleLabel.font = [UIFont boldSystemFontOfSize:20];
- titleLabel.text=@"Please complete missing fields:";
- titleLabel.numberOfLines = 0;
- titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
- // titleLabel.textAlignment = NSTextAlignmentRight;
- titleLabel.textAlignment = NSTextAlignmentCenter;
- CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
- CGSize sizetitle = [@"Please complete missing fields:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- //[titleLabel sizeToFit];
- // titleLabel.center.x = demoView.center.x;
- titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
- [demoView addSubview:titleLabel];
-
- UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
- lineLabel.font = [UIFont boldSystemFontOfSize:17];
- lineLabel.text=msg;
- lineLabel.numberOfLines = 0;
- lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
-
- CGSize sizemsg = [msg sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
- //[lineLabel sizeToFit];
-
- [demoView addSubview:lineLabel];
- demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
- return demoView;
- }
- //- (void)willPresentAlertView:(UIAlertView *)alertView{
- //
- //
- // alertView set
- // for( UIView * view in alertView.subviews )
- //
- // { if( [view isKindOfClass:[UILabel class]] )
- //
- // { UILabel* label = (UILabel*) view;
- //
- // label.textAlignment = NSTextAlignmentLeft; }
- //
- // }
- //
- //}
- //-(bool) action_btn_passed_check:(NSDictionary* ) data;
- //{
- // if(data == nil)
- // return false;
- // int section_count=[[data valueForKey:@"section_count"] intValue];
- //
- // for(int sc=0;sc<section_count)
- //
- //}
- //-(NSString*) get_param:(NSString*)param_name content_item:(NSDictionary*)itemjson
- //{
- //
- // NSString * item_name = [itemjson valueForKey:@"name"];
- // NSDictionary* cadejson= [itemjson objectForKey:@"cadedate"];
- // int cade_count = [[cadejson valueForKey:@"count"] intValue];
- // if([item_name isEqualToString:param_name] )
- // {
- // NSString* param_val=nil;
- //
- // bool single_select =[[itemjson valueForKey:@"single_select"] boolValue];
- //
- // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
- //
- //
- // for(int cc=0;cc<cade_count;cc++)
- // {
- // NSDictionary * valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
- // if([[valjson valueForKey:@"check"] boolValue])
- // {
- // NSString * valueid=[valjson valueForKey:@"value_id"];
- // if(valueid!=nil)
- // [arr_val addObject: valueid];
- // if(single_select)
- // break;
- // }
- //
- // }
- //
- // param_val = [arr_val componentsJoinedByString:@","];
- //
- // return param_val;
- // //[self.params setValue:param_val forKey:param_name];
- //
- // }
- // else
- // {
- // for(int cc=0;cc<cade_count;cc++)
- // {
- // NSDictionary * valjson=[itemjson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
- // NSDictionary* subitems=[valjson objectForKey:@"sub_item"];
- // if(subitems==nil)
- // continue;
- // int subcount=[[subitems valueForKey:@"count"] intValue];
- // for(int sc=0;sc<subcount;sc++)
- // {
- // NSDictionary* subitem = [subitems objectForKey:[NSString stringWithFormat:@"item_%d",sc]];
- // NSString* subval=[self get_param:param_name content_item:subitem];
- // if(subval!=nil)
- // return subval;
- // }
- //
- //
- // }
- //
- //
- // }
- // return nil;
- //
- //}
- -(void) download_success
- {
- // 用于处理不同child,在成功去的数据后,需要附加的操作。
-
-
- }
- - (void)download_failed {
- // 用于不同Child 处理失败
- }
- -(NSDictionary*) get_refresh_param
- {
- NSMutableDictionary* params= [[NSMutableDictionary alloc]init];
-
- NSDictionary * param_names = [self.content_data_download objectForKey:@"up_params"];
-
- int param_count=[[param_names valueForKey:@"count"] intValue];
-
- for(int pc=0;pc<param_count;pc++)
- {
-
- NSString* param_name = [param_names valueForKey:[NSString stringWithFormat:@"val_%d",pc]];
- NSString* param_val = [self getValue:param_name];
- [self.params setValue:param_val forKey:param_name];
-
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- //
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- //
- // NSString * control_type = [itemjson valueForKey:@"control"];
- // // NSString * item_name = [itemjson valueForKey:@"name"];
- // if([control_type isEqualToString:@"enum"])
- // {
- // NSString* subval= [self get_param:param_name content_item:itemjson];
- // if(subval!=nil)
- // {
- // [self.params setValue:subval forKey:param_name];
- // break;
- // }
- // // if([item_name isEqualToString:param_name] )
- // // {
- // // NSString* param_val=nil;
- // //
- // // bool single_select =[[itemjson valueForKey:@"single_select"] boolValue];
- // //
- // // int cade_count = [[itemjson valueForKey:@"count"] intValue];
- // //
- // // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
- // //
- // //
- // // for(int cc=0;cc<cade_count;cc++)
- // // {
- // // NSDictionary * valjson=[itemjson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
- // // if([[valjson valueForKey:@"check"] boolValue])
- // // {
- // // [arr_val addObject: [valjson valueForKey:@"value_id"]];
- // // if(single_select)
- // // break;
- // // }
- // //
- // // }
- // //
- // // param_val = [arr_val componentsJoinedByString:@","];
- // //
- // // [self.params setValue:param_val forKey:param_name];
- // // break;
- // // }
- // // else
- // // {
- // // NSString* subval= [self get_param:param_name content_item:itemjson];
- // // if(subval!=nil)
- // // {
- // // [self.params setValue:subval forKey:param_name];
- // // break;
- // // }
- // // }
- // }
- // }
- // }
-
-
- }
- return params;
-
- // NSString* param_name=[item_json valueForKey:@"name"];
- // NSString* param_val=nil;
- //
- // bool single_select =[[item_json valueForKey:@"single_select"] boolValue];
- //
- // int cade_count = [[value valueForKey:@"count"] intValue];
- //
- // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
- //
- //
- // for(int cc=0;cc<cade_count;cc++)
- // {
- // NSDictionary * valjson=[value objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
- // if([[valjson valueForKey:@"check"] boolValue])
- // {
- // [arr_val addObject: [valjson valueForKey:@"value_id"]];
- // if(single_select)
- // break;
- // }
- //
- // }
- //
- // param_val = [arr_val componentsJoinedByString:@","];
- //
- // [self.changed_data setObject:param_val forKey:param_name];
- }
- -(NSMutableDictionary*) CopyDirty:(NSDictionary*) dirty to:(NSMutableDictionary*) to
- {
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
-
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"dirty"] isEqualToString:@"true"])
- {
- [to_sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [to setObject:to_sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
- return to;
- }
- -(void) refresh:(NSString*) trigger;
- {
-
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
- if(self.url_type==URL_REMOTE)
- {
-
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
-
- self.params[@"refresh_trigger"]=trigger;
- __weak typeof(self) weakself = self;
-
-
- NSDictionary* refresh_params=[self get_refresh_param];
-
- NSArray* changed_key=[refresh_params allKeys];
- for(int i=0;i<changed_key.count;i++)
- {
- NSString* obj_str=[NSString stringWithFormat:@"%@",[refresh_params valueForKey:(NSString*)changed_key[i]]];
- [self.params setObject:obj_str forKey:(NSString*)changed_key[i]];
- }
-
- [RANetwork request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* editor_json = result;
- DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
-
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
-
- weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
-
-
- [weakself download_success];
- [weakself.editorTable reloadData];
-
- }
- else
- {
- [weakself download_failed];
- [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
- }
-
-
-
-
-
- }];
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- //
- //
- // NSDictionary* refresh_params=[weakself get_refresh_param];
- //
- // NSArray* changed_key=[refresh_params allKeys];
- // for(int i=0;i<changed_key.count;i++)
- // {
- // NSString* obj_str=[NSString stringWithFormat:@"%@",[refresh_params valueForKey:(NSString*)changed_key[i]]];
- // [weakself.params setObject:obj_str forKey:(NSString*)changed_key[i]];
- // }
- //
- // NSDictionary* editor_json = [weakself request_Editor:weakself.request_url params:weakself.params];
- // DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- //
- //
- // if([[editor_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
- //
- // weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
- //
- //
- // [weakself download_success];
- // [weakself.editorTable reloadData];
- //
- // }
- // else
- // {
- // [weakself download_failed];
- // [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
- // }
- //
- //
- //
- //
- // });
- // });
- }
- else
- {
-
- // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
- NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
- NSError *error=nil;
- self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
- [self request_fill];
-
- self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
- [self.editorTable reloadData];
-
- // NSString * ttt=[self.content_data valueForKey:@"title"] ;
-
- // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- }
- }
- -(subitem_data*) subitem_param:(NSDictionary*) itemjson addto:(NSMutableDictionary*) upparam alert:(bool)alert
- {
-
- subitem_data * data = [[subitem_data alloc] init];
-
- NSMutableArray * fields = [[NSMutableArray alloc]init];
-
- NSString * control_type = [itemjson valueForKey:@"control"];
- bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
- if([control_type isEqual:@"enum"] && single_select)
- {
- NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
-
- int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
-
- for(int k=0;k<cade_count;k++)
- {
- NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
- int check=[[valjson valueForKey:@"check"] intValue];
-
- NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
- bool active =[[valjson valueForKey:@"active"] boolValue];
- if(check==1 && subjson!=nil && !active)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
-
- NSString* required = [addjson valueForKey:@"required"];
- NSString* key=[addjson valueForKey:@"name"];
- if(key==nil || key.length==0)
- continue;
-
- if([[addjson valueForKey:@"control"] isEqualToString:@"enum" ])
- {
- NSString* single_select = [addjson valueForKey:@"single_select"];
- if([single_select isEqualToString:@"true"])
- {
- NSDictionary* cadejson=[addjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- bool setvalue = false;
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
- [upparam setValue:[valjson valueForKey:@"value_id"] forKey:[addjson valueForKey:@"name"]];
- setvalue=true;
- break;
- }
- }
- if([[addjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
- {
- self.cancommit = false;
-
-
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,addjson[@"aname"]];
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- else
- {
- //not support multi select for now;
- }
- }
- else if([[addjson valueForKey:@"control"] isEqualToString:@"action" ])
- {
- NSMutableDictionary * action_data = [[addjson objectForKey:@"data"] mutableCopy];
- int section_count=[[action_data valueForKey:@"section_count"] intValue];
-
-
-
-
- if([required isEqualToString: @"true"] && action_data==nil)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,addjson[@"aname"]];
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
-
- for(int i=0;i<section_count;i++)
- {
-
-
- NSMutableDictionary * sectionjson = [[action_data objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- NSString* key = [itemjson valueForKey:@"name"];
-
- if(key==nil || key.length==0)
- continue;
-
- if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
- {
- NSString* single_select = [itemjson valueForKey:@"single_select"];
- if([single_select isEqualToString:@"true"])
- {
- NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- bool setvalue = false;
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
-
- [upparam setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
- setvalue=true;
- break;
- }
- }
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- else
- {
- //not support multi select for now;
- }
- /*
- upparams setValue:itemjson forKey:<#(NSString *)#>
-
- */
-
- }
- else
- {
- if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
- [upparam setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
-
- subitem_data * data1=[self subitem_param:itemjson addto:upparam alert:alert];
- upparam= data1.params;
- fields=[[fields arrayByAddingObjectsFromArray:data1.missingfields] mutableCopy];
- // upparam= [self subitem_param:itemjson addto:upparam ];
- }
-
- }
-
- }
- else
- {
-
- if([addjson valueForKey:@"value"]!=nil && ![[addjson valueForKey:@"value"]isEqualToString:@""])
- [upparam setValue:[addjson valueForKey:@"value"] forKey:key];
- else
- {
- if([[addjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,addjson[@"aname"]];
-
- [fields addObject:mfield];
-
- NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
-
- subitem_data * data2=[self subitem_param:addjson addto:upparam alert:alert];
- upparam= data2.params;
- fields=[[fields arrayByAddingObjectsFromArray:data2.missingfields] mutableCopy];
-
- //upparam=[self subitem_param:addjson addto:upparam];
- // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
- // item_count ++;
-
-
- // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
-
- }
-
- //break;
- }
-
-
-
- }
- }
-
- data.params = upparam;
- data.missingfields = fields;
- return data;
- }
- -(NSMutableArray*) add_subitem:(NSDictionary*) itemjson addto:(NSMutableArray*) sectionarr parent:(NSString*) parent
- {
- NSString * control_type = [itemjson valueForKey:@"control"];
- bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
- if([control_type isEqual:@"enum"] && single_select)
- {
- NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
-
- int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
-
- for(int k=0;k<cade_count;k++)
- {
- NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
- int check=[[valjson valueForKey:@"check"] intValue];
-
- NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
- bool active =[[valjson valueForKey:@"active"] boolValue];
- if(check==1 && subjson!=nil && !active)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
- NSString* subself=[NSString stringWithFormat:@"%@_%d_%d",parent,k,l ];
- [addjson setValue:subself forKey:@"subid"];
- [sectionarr addObject:addjson];
- [self add_subitem:addjson addto:sectionarr parent:subself];
- // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
- // item_count ++;
-
-
- // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
-
- }
- [valjson setValue:@"true" forKey:@"active"];
-
-
- [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
- //break;
- }
-
-
-
- }
- }
- else if([control_type isEqual:@"switch"])
- {
- NSString* value=[itemjson valueForKey:@"value"];
-
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- subjson=[[[itemjson objectForKey:@"true"] objectForKey:@"sub_item"] mutableCopy];// [ mutableCopy];
- else
- subjson=[[[itemjson objectForKey:@"false"] objectForKey:@"sub_item"] mutableCopy];
-
-
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
- NSString* subself=[NSString stringWithFormat:@"%@_%d",parent,l ];
- [addjson setValue:subself forKey:@"subid"];
- [sectionarr addObject:addjson];
- [self add_subitem:addjson addto:sectionarr parent:subself];
- // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
- // item_count ++;
-
-
- // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
-
- }
- // [valjson setValue:@"true" forKey:@"active"];
-
-
- // [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
- //break;
- }
-
- }
- return sectionarr;
- }
- -(NSMutableArray*) translate_json: (NSDictionary*) injson changed:(NSDictionary*) changed_value
- {
-
- @synchronized(self)
- {
- if(injson == nil)
- return nil;
-
- NSMutableArray * retarray= [[NSMutableArray alloc]init];
-
- int section_count=[[injson valueForKey:@"section_count"] intValue];
-
- for(int i=0;i<section_count;i++)
- {
- NSMutableArray * sectionarr= [[NSMutableArray alloc]init];
-
- NSMutableDictionary * sectionjson = [[injson objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- NSAssert(itemjson!=nil, @"Backend error, item is null section:%d item %d",i,item_count);
- [sectionarr addObject:itemjson];
- [self add_subitem:itemjson addto:sectionarr parent:[NSString stringWithFormat:@"%d_%d",i,j ]];
- // [itemjson setObject:cadedatejson forKey:@"cadedate"];
- // NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
-
- // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
-
- }
- // [sectionjson setValue:[NSString stringWithFormat:@"%d",item_count ] forKey:@"count"];
- // [retjson setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- [retarray addObject:sectionarr];
- }
-
- NSLog(@"content control count = %ld",retarray.count);
- return retarray;
- // retjson setObject:sec forKey:<#(id<NSCopying>)#>
- // return nil;
- }
-
- }
- /*
- -(NSMutableDictionary*) translate_json: (NSDictionary*) injson
- {
- if(injson == nil)
- return nil;
-
- NSMutableDictionary * retjson= [injson mutableCopy];
-
- int section_count=[[retjson valueForKey:@"section_count"] intValue];
-
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[retjson objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- NSString * control_type = [itemjson valueForKey:@"control"];
- bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
- if([control_type isEqual:@"enum"] && single_select)
- {
- NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
-
- int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
-
- for(int k=0;k<cade_count;k++)
- {
- NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
- int check=[[valjson valueForKey:@"check"] intValue];
-
- NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
- bool active =[[valjson valueForKey:@"active"] boolValue];
- if(check==1 && subjson!=nil && !active)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
- [addjson setValue:[NSString stringWithFormat:@"%d_%d_%d",i,j,k ] forKey:@"parent"];
- [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
- item_count ++;
-
-
- // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
-
- }
- [valjson setValue:@"true" forKey:@"active"];
-
-
- [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
- //break;
- }
- if(check==0 && subjson!=nil)
- {
- int total_remove=0;
- for(int r=0;r<item_count;r++)
- {
- NSMutableDictionary * removejson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",r ]] mutableCopy];
- if(removejson==nil)
- continue;
- if([[removejson valueForKey:@"parent"] isEqualToString: [NSString stringWithFormat:@"%d_%d_%d",i,j,k ]])
- {
- [sectionjson removeObjectForKey:[NSString stringWithFormat:@"item_%d",r ]];
- total_remove++;
- // item_count--;
- // r--;
- }
- else
- {
- [sectionjson removeObjectForKey:[NSString stringWithFormat:@"item_%d",r ]];
- [sectionjson setObject:removejson forKey:[NSString stringWithFormat:@"item_%d",r-total_remove ]];
- }
-
-
- }
- [valjson setValue:@"false" forKey:@"active"];
-
-
- [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
- item_count-=total_remove;
- // remove sub item
-
- //break;
- }
-
-
- }
- [itemjson setObject:cadedatejson forKey:@"cadedate"];
- // NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
- }
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
-
- }
- [sectionjson setValue:[NSString stringWithFormat:@"%d",item_count ] forKey:@"count"];
- [retjson setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
-
- }
- return retjson;
- // retjson setObject:sec forKey:<#(id<NSCopying>)#>
- return nil;
- }*/
- //- (void)onCloseClick:(UIButton *)sender {
- // [self.navigationController dismissViewControllerAnimated:true completion:^{
- // ;
- // }];
- //}
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void) prepareReturn:(NSMutableDictionary*) value
- {
-
- if(value==nil)
- value=[[NSMutableDictionary alloc]init];
- value[@"is_subaction"] = self.params[@"is_subaction"];
- value[@"subaction_tag"] = self.params[@"subaction_tag"];
-
- if (self.delegate && [self.delegate respondsToSelector:@selector(returnValue:indexPath:)]) {
- [self.delegate returnValue:value indexPath:self.from];
- }
- if(self.returnValue)
- self.returnValue(nil);
- }
- -(void) handle_action_return:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath action:(int) action_code
- {
- DebugLog(@"commoneditor return %ld_%ld",(long)indexPath.section,(long)indexPath.row);
- NSMutableDictionary* section_json=nil;
-
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- bool is_subaction = [value[@"is_subaction"] boolValue];
- int subaction_tag= [value[@"subaction_tag"] intValue];
- [value removeObjectForKey:@"is_subaction"];
- [value removeObjectForKey:@"subaction_tag"];
- if(is_subaction)
- {
- NSMutableDictionary* sub_action = [[item_json objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy];
- int refresh = [[sub_action valueForKey:@"refresh"] intValue];
- NSString* refresh_trigger = [sub_action valueForKey:@"name"];
- NSDictionary * restore_json=[sub_action objectForKeyedSubscript:@"restore"];
-
-
-
- NSString* subid=[sub_action valueForKey:@"subid"];
-
- UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
-
- NSString* required = [sub_action valueForKey:@"required"];
- if([required isEqualToString:@"true"] && value.count==0)
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- if(value.count!=0)
- {
-
- if(action_code==ACTION_SAVE_DATA)
- {
- [sub_action setObject:value forKey:@"data"];
-
-
- if(subid==nil)
- {
- [sub_action setValue:@"true" forKey:@"dirty"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[sub_action valueForKey:@"name" ]])
- {
- // sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
- [item_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
- }
-
- }
- }
- else
- {
-
- assert(@"not impl");
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- sub_action= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:sub_action step:2];
- [sub_action setValue:@"true" forKey:@"dirty"];
-
- [item_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
- }
- else if(action_code==ACTION_FILL_SECTION)
- {
-
- if(subid==nil)
- {
- NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int icount=[[section_json valueForKey:@"count"] intValue];
- for (int ic=0;ic<icount;ic++)
- {
- NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
-
- NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
-
- NSString* valuestr= [value valueForKey:valuefrom];
-
- if(valuestr !=nil)
- {
-
- [modify_item setValue:valuestr forKey:@"value"];
-
- [modify_item setValue:@"true" forKey:@"dirty"];
- [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
- }
- }
- }
- else
- {
-
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
- NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
- NSMutableDictionary* olditem_sub_action = [[olditem objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy];
-
- olditem_sub_action= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
-
-
- [olditem_sub_action setValue:@"true" forKey:@"dirty"];
- [olditem setObject:olditem_sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
- [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
-
-
-
- }
-
-
-
- // [section_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- }
-
- DebugLog(@"CONTENT UPDATE:%@",[RAConvertor DataTOjsonString:self.content_data_download]);
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
-
-
- if(refresh==1)
- {
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger] ;
- return ;
- }
-
-
-
- // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- [self.editorTable reloadData ];
-
- }
- else
- {
-
-
-
- int refresh = [[item_json valueForKey:@"refresh"] intValue];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
-
-
-
- NSString* subid=[item_json valueForKey:@"subid"];
-
- UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
-
- NSString* required = [item_json valueForKey:@"required"];
- if([required isEqualToString:@"true"] && value.count==0)
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- if(value.count!=0)
- {
-
- if(action_code==ACTION_SAVE_DATA)
- {
- [item_json setObject:value forKey:@"data"];
-
-
- if(subid==nil)
- {
- [item_json setValue:@"true" forKey:@"dirty"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
- }
- else
- {
-
- assert(@"not impl");
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
- }
- else if(action_code==ACTION_FILL_SECTION)
- {
-
- if(subid==nil)
- {
- NSDictionary* jsonmap=[item_json valueForKey:@"key_map"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int icount=[[section_json valueForKey:@"count"] intValue];
- for (int ic=0;ic<icount;ic++)
- {
- NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
-
- NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
-
- NSString* valuestr= [value valueForKey:valuefrom];
-
- if(valuestr !=nil)
- {
-
- [modify_item setValue:valuestr forKey:@"value"];
-
- [modify_item setValue:@"true" forKey:@"dirty"];
- [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
- }
- }
- }
- else
- {
-
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
- NSDictionary* jsonmap=[item_json valueForKey:@"key_map"];
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
-
- olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
-
-
- [olditem setValue:@"true" forKey:@"dirty"];
- [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
-
-
-
- }
-
-
-
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- }
-
- DebugLog(@"CONTENT UPDATE:%@",[RAConvertor DataTOjsonString:self.content_data_download]);
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
-
-
- if(refresh==1)
- {
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger] ;
- return ;
- }
-
-
-
- // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- [self.editorTable reloadData ];
- }
- }
- -(NSString*) getValue:(NSString*)name
- {
- NSString* ret=nil;
- for(int i=0;i<self.content_data_control.count;i++)
- {
- NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
- for(int j=0;j<items.count;j++)
- {
- NSDictionary* item=items[j];
- NSString* item_name=[item valueForKey:@"name"];
- if([item_name isEqualToString:name])
- {
- NSString* control = [item valueForKey:@"control"];
-
- if([control isEqualToString:@"enum"])
- {
- NSDictionary* cadedate = [item objectForKey:@"cadedate"];
- int cc = [[cadedate valueForKey:@"count"] intValue];
- for(int l=0;l<cc;l++)
- {
- NSDictionary* val_json=[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]];
- if([[val_json valueForKey:@"check"]intValue]==1)
- return [val_json valueForKey:@"value_id"];
- }
-
- }
- else
-
- return [item valueForKey:@"value"];
- }
- }
- }
- return ret;
- }
- - (id)downloadValueForKey:(NSString *)key_name {
- __block id ret=nil;
- [self.content_data_download enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
-
- if (![key isEqualToString:@"section_count"] && [key hasPrefix:@"section_"]) {
-
- NSDictionary *section = (NSDictionary *)obj;
-
- [section enumerateKeysAndObjectsUsingBlock:^(id _Nonnull item_key, id _Nonnull item_obj, BOOL * _Nonnull stop) {
-
- if ([item_key hasPrefix:@"item_"]) {
-
- NSDictionary* item= (NSDictionary *)item_obj;
- NSString* item_name=[item valueForKey:@"name"];
- if([item_name isEqualToString:key_name])
- {
- NSString* control = [item valueForKey:@"control"];
-
- if([control isEqualToString:@"enum"])
- {
- NSDictionary* cadedate = [item objectForKey:@"cadedate"];
- int cc = [[cadedate valueForKey:@"count"] intValue];
- for(int l=0;l<cc;l++)
- {
- NSDictionary* val_json=[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]];
- if([[val_json valueForKey:@"check"]intValue]==1)
- ret = [val_json valueForKey:@"value_id"];
- }
-
- }
- else
-
- ret = [item valueForKey:@"value"];
- }
-
- }
-
- }];
-
- }
-
- }];
- return ret;
- }
- -(void) setValue:(NSString*)key value:(NSString*)val
- {
- // NSString* ret=nil;
- for(int i=0;i<self.content_data_control.count;i++)
- {
- NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
- for(int j=0;j<items.count;j++)
- {
- NSMutableDictionary* item=[items[j] mutableCopy];
- NSString* item_name=[item valueForKey:@"name"];
-
- NSUInteger ii[2] = {i,j};
- NSIndexPath * indexPath= [NSIndexPath indexPathWithIndexes:ii length:2];
- if([item_name isEqualToString:key])
- {
- NSString* control = [item valueForKey:@"control"];
-
- if([control isEqualToString:@"enum"])
- {
- NSMutableDictionary* cadedate = [[item objectForKey:@"cadedate"] mutableCopy];
- int cc = [[cadedate valueForKey:@"count"] intValue];
- for(int l=0;l<cc;l++)
- {
- NSMutableDictionary* val_json=[[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]] mutableCopy];
- if([[val_json valueForKey:@"value_id"] isEqualToString:val])
- {
- val_json[@"check"]=[NSNumber numberWithInt:1];
- }
- else
- {
- val_json[@"check"]=[NSNumber numberWithInt:0];
- }
- cadedate[[NSString stringWithFormat:@"val_%d",l]] = val_json;
-
- // return [val_json valueForKey:@"value_id"];
- }
- // item[@"cadedate"] = cadedate;
-
-
- [self setEnumValue:cadedate indexPath:indexPath];
-
- }
- else if([control isEqualToString:@"edit"])
- {
-
- [self textfieldSetValue:indexPath value:val];
- }
- }
- }
- }
- [self.editorTable reloadData ];
- // return ret;
- }
- -(void) textfieldSetValue:(NSIndexPath*) indexPath value:(NSString*) val
- {
-
- //用于会填 textfield 的值,textViewDidEndEditing 和 partial refresh 会调用。
-
-
- // DebugLog(@"textFieldDidEndEditing");
- // // UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
- // NSIndexPath * indexPath = self.lastedit_from;
- //
-
- NSMutableDictionary* section_json=nil;
-
-
-
- val = [val stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- NSString* subid=[item_json valueForKey:@"subid"];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
-
- [item_json setValue:@"true" forKey:@"dirty"];
- [item_json setValue:val forKey:@"value"];
- if([[item_json valueForKey:@"keyboard"] isEqualToString:@"number"])
- {
- float f = [ val floatValue];
- [item_json setValue:[NSString stringWithFormat:@"%.2f",f] forKey:@"value"];
-
- }
-
- // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
- int refresh = [[item_json valueForKey:@"refresh"] intValue];
-
- NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
- if(refresh==1)
- {
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger] ;
-
- }
- else if(partial_refresh)
- {
- NSString* name = [item_json valueForKey:@"name"] ;
- NSString* url = [item_json valueForKey:@"data_interface"] ;
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
- [params setValue:val forKey:name];
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
- __weak typeof(self) weakself = self;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* editor_json = [RANetwork commoneditor_partialrefresh:params url:url];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- int prcount = [[editor_json valueForKey:@"count"] intValue];
- for(int ipr=0;ipr<prcount;ipr++)
- {
- NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
- NSString* name = [pr_item valueForKey:@"name"];
- NSString* value = [pr_item valueForKey:@"value"];
-
- [weakself setValue:name value:value];
- }
-
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
- }
-
-
- });
- });
-
-
-
- }
- self.lastedit = nil;
- self.lastedit_from=nil;
- return ;
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- NSString* control_type= [olditem valueForKey:@"control"];
- NSMutableDictionary* new_item=nil;
- [item_json setValue:@"true" forKey:@"dirty"];
- if([control_type isEqualToString:@"enum"])
- new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- else if([control_type isEqualToString:@"switch"])
- new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
-
- [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
- int refresh = [[item_json valueForKey:@"refresh"] intValue];
-
- NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
- if(refresh==1)
- {
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger] ;
-
- }
- else if(partial_refresh)
- {
- NSString* name = [item_json valueForKey:@"name"] ;
- NSString* url = [item_json valueForKey:@"data_interface"] ;
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
- [params setValue:val forKey:name];
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
- __weak typeof(self) weakself = self;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* editor_json = [RANetwork commoneditor_partialrefresh:params url:url];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- int prcount = [[editor_json valueForKey:@"count"] intValue];
- for(int ipr=0;ipr<prcount;ipr++)
- {
- NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
- NSString* name = [pr_item valueForKey:@"name"];
- NSString* value = [pr_item valueForKey:@"value"];
-
- [weakself setValue:name value:value];
- }
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
- }
-
-
- });
- });
-
-
-
- }
- self.lastedit = nil;
- self.lastedit_from=nil;
-
- return;
- }
-
-
-
-
- // return [item valueForKey:@"value"];
-
- }
- -(void) unhide_section:(int)isection
- {
-
-
- NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",isection]] mutableCopy];
- [section setValue:@"false" forKey:@"hide"];
- [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%d",isection]];
-
- }
- -(NSIndexPath*) get_indexpath1:(NSString*)name
- {
- if(self.first_miss_pos!=nil)
- return self.first_miss_pos;
- NSIndexPath* ret=nil;
- for(int i=0;i<self.content_data_control.count;i++)
- {
- NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
- for(int j=0;j<items.count;j++)
- {
- NSDictionary* item=items[j];
- NSString* item_name=[item valueForKey:@"name"];
- if([item_name isEqualToString:name])
- {
- NSUInteger ii[2] = {i,j};
- return [NSIndexPath indexPathWithIndexes:ii length:2];
- }
- }
- }
- return ret;
- }
- #pragma mark - hide section button clicked
- - (void)HideSction:(UIButton *)sender {
-
- NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]] mutableCopy];
- bool hide = [[section valueForKey:@"hide"]boolValue];
- if(hide)
- {
- [section setValue:@"false" forKey:@"hide"];
- [sender setTitle:@"Show" forState:UIControlStateNormal];
- }
- else{
- [section setValue:@"true" forKey:@"hide"];
- [sender setTitle:@"Hide" forState:UIControlStateNormal];
- }
-
- [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- NSRange range = NSMakeRange(sender.tag, 1);
- NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
- [self.editorTable reloadData];
-
-
- }
- #pragma mark - commoneditor delegate
- -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
- {
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_SAVE_DATA];
- // DebugLog(@"commoneditor return %d_%d",indexPath.section,indexPath.row);
- //
- // NSMutableDictionary* section_json=nil;
- //
- // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
- //
- //
- //
- // int refresh = [[item_json valueForKey:@"refresh"] intValue];
- //
- // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- //
- //
- //
- // NSString* subid=[item_json valueForKey:@"subid"];
- //
- // UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
- //
- // NSString* required = [item_json valueForKey:@"required"];
- // if([required isEqualToString:@"true"] && value==nil)
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor redColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- // else
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor clearColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- // if(value!=nil)
- // {
- // [item_json setObject:value forKey:@"data"];
- //
- //
- // if(subid==nil)
- // {
- // [item_json setValue:@"true" forKey:@"dirty"];
- // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- // int count=0;
- //
- // count=[[section_json valueForKey:@"count"] intValue];
- //
- // for(int i=0;i<count;i++)
- // {
- // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
- //
- //
- // }
- // }
- // else
- // {
- // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- // int section = [(NSString*)idarr[0] intValue];
- // int item=[(NSString*)idarr[1] intValue];
- //
- //
- // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- // item_json= [self subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- // [item_json setValue:@"true" forKey:@"dirty"];
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- //
- // }
- //
- //
- // // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
- //
- // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // }
- //
- // if(refresh==1)
- // {
- //
- // if(restore_json!=nil)
- // {
- // int rc=[[restore_json valueForKey:@"count"] intValue];
- // for(int ir=0;ir<rc;ir++)
- // {
- // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
- //
- //
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- //
- // if([[itemjson valueForKey:@"name"] isEqualToString:name])
- // {
- // [itemjson removeObjectForKey:@"dirty"];
- // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- // }
- //
- // }
- // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- // }
- //
- //
- // }
- //
- // }
- // [self refresh] ;
- // return ;
- // }
- //
- //
- // DebugLog(@"CONTENT UPDATE:%@",[iSalesNetwork DataTOjsonString:self.content_data_download]);
- // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- //
- //
- // // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- // [self.editorTable reloadData ];
-
- }
- #pragma mark - Table view data source
- //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- //{
- // return 0;
- //}
- //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- //{
- // return 0;
- //}
- //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // return myView;
- //
- //}
- //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 20, 10)];
- //// titleLabel.textColor=[UIColor whiteColor];
- //// titleLabel.backgroundColor = [UIColor clearColor];
- //// if(section==0)
- //// titleLabel.text=NSLocalizedString(@"display_items", nil);
- //// else
- //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
- //// [titleLabel sizeToFit];
- //// [myView addSubview:titleLabel];
- ////
- // return myView;
- //}
- //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- //
- // switch (section) {
- // case 0:
- // {
- // NSDictionary * section_json = [self.content_data objectForKey:@"info_section"];
- // return [section_json valueForKey:@"title"] ;
- // }
- // case 1:
- // {
- // NSDictionary * section_json = [self.content_data objectForKey:@"model_section"];
- // return [section_json valueForKey:@"title"] ;
- // }
- // default:
- // return nil;
- // }
- //
- //
- //}
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
-
- NSMutableDictionary* section_json = [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]];
- return [section_json valueForKey:@"title"];
-
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
-
- NSLog(@"numberOfSectionsInTableView = %ld",self.content_data_control.count);
-
- // if(self.content_data_control.count>0)
- // return 1;
- return self.content_data_control.count;
- // int section_count =[[self.content_data valueForKey:@"section_count"] intValue];
- // return section_count;
- }
- //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
- //{
- // DebugLog(@"canMoveRowAtIndexPath");
- //
- // if([tableView numberOfRowsInSection:indexPath.section]>1)
- // return true;
- // else
- // return false;
- //}
- //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
- //{
- // NSMutableArray * from;
- // NSMutableArray * to ;
- // if(fromIndexPath.section==0)
- // from = self.displayfields;
- // else
- // from = self.hidefields;
- // if(toIndexPath.section==0)
- // to = self.displayfields;
- // else
- // to = self.hidefields;
- // id content=from[fromIndexPath.row];
- // [from removeObjectAtIndex:fromIndexPath.row];
- // [to insertObject:content atIndex:toIndexPath.row];
- //
- // [tableView reloadData];
- //
- //}
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- // if(self.content_data_control.count>0)
- // return 1;
-
-
-
- NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy];
- bool hide = [[sectionjson valueForKey:@"hide"]boolValue];
- if(hide)
- {
- return 0;
- // [sectionjson setValue:@"false" forKey:@"hide"];
- // [sender setTitle:@"Show" forState:UIControlStateNormal];
- }
- else{
- return ((NSMutableArray*)self.content_data_control[section]).count;
-
- // [sectionjson setValue:@"true" forKey:@"hide"];
- // [sender setTitle:@"Hide" forState:UIControlStateNormal];
- }
- // return 0;
-
- // if(section==4)
- // return 1;
- // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]];
- //
- // return [[section_json valueForKey:@"count" ] intValue];
-
-
-
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- if(section==0)
- return 44;
- return 33;
- }
- //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- //{
- // return 0.5;
- //}
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- {
-
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
-
- NSString* control = [item_json valueForKey:@"control"];
- NSString *model = [UIDevice currentDevice].model;
- if ([model isEqualToString:@"iPhone"]) {
- if([control isEqualToString:@"model"])
- return 140;
- else if([control isEqualToString:@"signature"])
- return 200;
- else if([control isEqualToString:@"text_view"])
- return 180;
- else if([control isEqualToString:@"img"])
- return 240;
- else if ([control isEqualToString:@"action"])
- return 44;
- else if ([control isEqualToString:@"text"])
- return 80;
- else if ([control isEqualToString:@"enum"])
- return 80;
- else if ([control isEqualToString:@"edit"])
- return 80;
- else if ([control isEqualToString:@"switch"])
- return 80;
- else if([control isEqualToString:@"multi_action"])
- {
- int count = [[item_json valueForKey:@"count"]intValue];
- if (count <= 2) {
- return 50;
- } else {
- return 100;
- }
- }
- else if ([control isEqualToString:@"webview"]) {
- id h_obj = [item_json objectForKey:@"height"];
- CGFloat height = [h_obj floatValue];
-
- if(height<44)
- height=44;
- return height;
- }
- else if ([control isEqualToString:@"banner"]) {
- return 200;
- }
- return 80;
- } else {
- if([control isEqualToString:@"model"])
- return 140;
- else if([control isEqualToString:@"signature"])
- return 140;
- else if([control isEqualToString:@"text_view"])
- return 140;
-
- else if([control isEqualToString:@"img"])
- return 123;
- return 44;
- }
-
-
- }
- //
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue];
- // int d=0;
- // if(indexPath.section==4)
- // d=0;
-
- // DebugLog(@"%d,%d",indexPath.section,indexPath.row);
- // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- NSString* control = [item_json valueForKey:@"control"];
-
- NSString* required = [item_json valueForKey:@"required"];
- NSString *CellIdentifier = @"";
-
-
-
- if([control isEqualToString:@"text_view"])
- {
- CellIdentifier = @"CommonEditorCellTextView";
- CommonEditorCellTextView * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- NSString* value =[item_json valueForKey:@"value"];
- NSString* align =[item_json valueForKey:@"align"];
- if([align isEqualToString:@"right"])
- cell.textview.textAlignment= kCTRightTextAlignment;
- else
- cell.textview.textAlignment =kCTLeftTextAlignment;
-
- int capital =[[item_json valueForKey:@"capital"] intValue];
- switch (capital) {
- case 1:
- cell.textview.autocapitalizationType=UITextAutocapitalizationTypeWords;
- break;
- case 2:
- cell.textview.autocapitalizationType=UITextAutocapitalizationTypeSentences;
- break;
- case 3:
- cell.textview.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;
- break;
- default:
- cell.textview.autocapitalizationType=UITextAutocapitalizationTypeWords;//UITextAutocapitalizationTypeNone;
- break;
- }
-
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
- cell.textview.editable=NO;
- // cell.textfield.backgroundColor = [UIColor lightGrayColor];
- cell.textview.textColor= [UIColor lightGrayColor];
-
- }
- else
- {
- cell.textview.editable=YES;
- cell.textview.textColor= [UIColor blackColor];
- // cell.textfield.backgroundColor = [UIColor whiteColor];
- }
-
-
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
-
-
- cell.label_name.text=title;
-
- if([required isEqualToString:@"true"])
- {
- [cell.label_name sizeToFit];
- CGRect frame =cell.label_name.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.label_name sizeToFit];
- cell.starMark.hidden=true;
- }
-
-
- cell.textview.text = value;
- cell.textview.delegate = self;
- cell.accessoryType = UITableViewCellAccessoryNone;
-
-
-
-
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }else
- if([control isEqualToString:@"img"])
- {
- CellIdentifier = @"CommonEditorCellImg";
- CommonEditorCellImg * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.touchImageView0.contentMode = UIViewContentModeScaleAspectFit;
- cell.touchImageView1.contentMode = UIViewContentModeScaleAspectFit;
- cell.touchImageView2.contentMode = UIViewContentModeScaleAspectFit;
-
- NSString* title = [item_json valueForKey:@"aname"] ;
- NSString* value =[item_json valueForKey:@"value"];
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
- cell.editable=false;
- }
- else
- cell.editable=true;
- cell.labelTitle.text = title;
- cell.labelDescription.text = value;
- __weak typeof(self) weakself = self;
- cell.imgChanged = ^(NSString* url_down,NSString* url_up,int index ,NSString* url_index)
- {
- // NSMutableDictionary* editjson = [item_json mutableCopy];
- // editjson[@"img_url"]=url;
- [weakself imgIsChanged:url_down url_up:url_up indexPath:indexPath index:index url_index:url_index];
-
-
- };
-
- {
- NSString* img_url0 = [item_json valueForKey:@"img_url_0"];
- if(img_url0.length>0)
- {
- NSString* img_url_up=[item_json valueForKey:@"img_url_aname_0"];
- if(img_url_up.length==0)
- img_url_up=@"";
- cell.imgs[0]=img_url_up;
- NSString* file_name=[img_url0 lastPathComponent];
- NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url0];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
-
- cell.touchImageView0.image=img;
-
- cell.img_validate = true;
- // [cell.touchImageView setImage:img forState:UIControlStateNormal];
- }
- else
- {
- __weak typeof(self) weakself = self;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url0]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url0];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.touchImageView0.image=img;
- cell.img_validate = true;
- }
- else
- {
- cell.touchImageView0.image=[UIImage imageNamed:@"notfound_s"];
-
- cell.img_validate = false;
- }
-
- });
- });
-
-
- }
- }
- else
- {
- cell.touchImageView0.image=nil;
- cell.imgs[0]=@"";
- }
- }
-
- {
- NSString* img_url1 = [item_json valueForKey:@"img_url_1"];
- if(img_url1.length>0)
- {
- NSString* img_url_up=[item_json valueForKey:@"img_url_aname_1"];
- if(img_url_up.length==0)
- img_url_up=@"";
-
- cell.imgs[1]=img_url_up;
- NSString* file_name=[img_url1 lastPathComponent];
- NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url1];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
-
-
- cell.touchImageView1.image=img;
-
- cell.img_validate = true;
- // [cell.touchImageView setImage:img forState:UIControlStateNormal];
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url1]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url1];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.touchImageView1.image=img;
- cell.img_validate = true;
- }
- else
- {
- cell.touchImageView1.image=[UIImage imageNamed:@"notfound_s"] ;
- cell.img_validate = false;
- }
-
- });
- });
-
-
- }
- }
- else
- {
- cell.touchImageView1.image=nil;
- cell.imgs[1]=@"";
- }
- }
- {
- NSString* img_url2 = [item_json valueForKey:@"img_url_2"];
- if(img_url2.length>0)
- {
- NSString* img_url_up=[item_json valueForKey:@"img_url_aname_2"];
- if(img_url_up.length==0)
- img_url_up=@"";
- cell.imgs[2]=img_url_up;
- NSString* file_name=[img_url2 lastPathComponent];
- NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url2];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
-
- cell.touchImageView2.image=img;
-
- cell.img_validate = true;
- // [cell.touchImageView setImage:img forState:UIControlStateNormal];
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url2]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url2];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.touchImageView2.image=img;
- cell.img_validate = true;
- }
- else
- {
- cell.touchImageView2.image=[UIImage imageNamed:@"notfound_s"] ;
- cell.img_validate = false;
- }
-
- });
- });
-
-
- }}
- else
- {
- cell.touchImageView2.image=nil;
- cell.imgs[2]=@"";
- }
- }
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- }else
- if([control isEqualToString:@"edit"])
- {
- CellIdentifier = @"CommonEditorCellEdit";
- CommonEditorCellEdit * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
-
- // title =[[NSString stringWithFormat:@"<font size=\"5\" face=\"Helvetica\">%@</font>",title] mutableCopy];
- NSString* value =[item_json valueForKey:@"value"];
-
- NSString* align =[item_json valueForKey:@"align"];
-
- if([align isEqualToString:@"right"])
- cell.textfield.textAlignment= NSTextAlignmentRight;
- else
- cell.textfield.textAlignment =NSTextAlignmentLeft;
-
- int capital =[[item_json valueForKey:@"capital"] intValue];
- switch (capital) {
- case 1:
- cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeWords;
- break;
- case 2:
- cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeSentences;
- break;
- case 3:
- cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;
- break;
- default:
- cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeWords;//UITextAutocapitalizationTypeNone;
- break;
- }
-
-
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
-
- cell.textfield.enabled=NO;
- // cell.textfield.backgroundColor = [UIColor lightGrayColor];
- cell.textfield.textColor= [UIColor lightGrayColor];
-
- }
- else
- {
- cell.textfield.enabled=YES;
- cell.textfield.textColor= [UIColor blackColor];
- // cell.textfield.backgroundColor = [UIColor whiteColor];
- }
-
- NSString* keyboard = [item_json valueForKey:@"keyboard"];
-
- if([keyboard isEqualToString:@"number"])
- {
-
- // float f = [value floatValue];
-
- // value = [NSString stringWithFormat:@"%.2f",f];
-
-
- cell.textfield.keyboardType=UIKeyboardTypeDecimalPad;
- // cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
-
-
-
- }
- else if([keyboard isEqualToString:@"int"])
- {
-
- // float f = [value floatValue];
-
- // value = [NSString stringWithFormat:@"%.2f",f];
-
-
- cell.textfield.keyboardType=UIKeyboardTypeNumberPad;
- // cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
-
-
-
- }
- else if([keyboard isEqualToString:@"email"])
- {
- cell.textfield.keyboardType=UIKeyboardTypeEmailAddress;
- }
- else if([keyboard isEqualToString:@"phone"])
- {
- cell.textfield.keyboardType=UIKeyboardTypePhonePad;
- }
- else
- {
- cell.textfield.keyboardType=UIKeyboardTypeDefault;
- }
-
-
- // UIKIT_EXTERN NSString * const NSPlainTextDocumentType NS_AVAILABLE(10_0, 7_0);
- // UIKIT_EXTERN NSString * const NSRTFTextDocumentType NS_AVAILABLE(10_0, 7_0);
- // UIKIT_EXTERN NSString * const NSRTFDTextDocumentType NS_AVAILABLE(10_0, 7_0);
- // UIKIT_EXTERN NSString * const NSHTMLTextDocumentType NS_AVAILABLE(10_0, 7_0);
- //
-
- // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[title dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
- // UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];
- // myLabel.attributedText = attrStr;
-
- // cell.labelTitle.attributedText = attrStr;
- cell.labelTitle.text=title;
-
-
-
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
- cell.textfield.text = value;
- cell.textfield.delegate = self;
- cell.accessoryType = UITableViewCellAccessoryNone;
-
-
-
-
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
-
-
-
-
-
-
- CALayer *layer = cell.labelTitle.layer;
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
-
-
- layer = cell.starMark.layer;
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
-
-
- //UIImageView * iv =
- cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_attention_24"]];
- cell.textfield.rightViewMode=UITextFieldViewModeUnlessEditing;
- cell.textfield.layer.cornerRadius=8.0f;
- cell.textfield.layer.borderWidth= 1.0f;
- cell.textfield.layer.masksToBounds=YES;
- cell.textfield.layer.borderColor=[[UIColor redColor]CGColor];
- }
- else
- {
- CALayer *layer = cell.labelTitle.layer;//[cell.contentView layer];
-
-
-
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
-
-
- layer = cell.starMark.layer;//[cell.contentView layer];
-
-
-
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
-
-
- cell.textfield.rightViewMode=UITextFieldViewModeNever;
- //cell.textfield.layer.borderColor= [[UIColor lightGrayColor] CGColor];
- cell.textfield.rightView = nil;
- cell.textfield.layer.cornerRadius=8.0f;
- cell.textfield.layer.borderWidth= 1.0f;
- cell.textfield.layer.masksToBounds=YES;
- cell.textfield.layer.borderColor=[[UIColor lightGrayColor]CGColor];
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else
- if([control isEqualToString:@"text"])
- {
- CellIdentifier = @"CommonEditorCellLabel";
- CommonEditorCellLabel * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
- //CGRect titleframe = cell.labelTitle.frame;
-
- NSString* title = [item_json valueForKey:@"aname"] ;
- NSString* value =[item_json valueForKey:@"value"];
- NSString* color =[item_json valueForKey:@"color"];
- cell.labelValue.textColor = [RAUtils strColor:color];
- NSString* align =[item_json valueForKey:@"align"];
- if([align isEqualToString:@"right"])
- {
- cell.labelTitle.frame =CGRectMake(15,11,350,21);
- cell.labelValue.textAlignment= NSTextAlignmentRight;
- }
- else
- {
- cell.labelTitle.frame =CGRectMake(15,11,150,21);
- cell.labelValue.textAlignment =NSTextAlignmentLeft;
- }
-
- NSString* type=[item_json valueForKey:@"type"] ;
-
- if([type isEqualToString:@"price"])
- {
- BOOL can_see_price = [[appDelegate globalParameterForKey:@"can_see_price"] boolValue];
- BOOL price_hidden = [[appDelegate globalParameterForKey:@"price_hidden"] boolValue];
-
- if(can_see_price&&price_hidden==false)
- {
-
- }
- else
- {
- value=nil;
- }
- }
-
-
-
- cell.labelTitle.text=title;
- cell.labelValue.text = value;
-
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else
- if([control isEqualToString:@"action"])
- {
- CellIdentifier = @"CommonEditorCellAction";
- CommonEditorCellAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- NSString* value =[item_json valueForKey:@"value"];
- if([required isEqualToString:@"true"])
- {
- [title appendString:@"*"];
- }
- NSDictionary* data = [item_json objectForKey:@"data"];
-
- cell.labelAction.text=title;
- cell.action_code = value;
-
-
- //cell.labelValue.text = value;
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- if([control isEqualToString:@"multi_action"])
- {
- CellIdentifier = @"CommonEditorCellMAction";
- CommonEditorCellMAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
- int count = [[item_json valueForKey:@"count"]intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary* sub_action= [item_json objectForKey:[NSString stringWithFormat:@"item_%d",i]];
- NSString * title = [sub_action valueForKey:@"aname"];
- switch (i) {
- case 0:
- [cell.btn_action0 setTitle:title forState:UIControlStateNormal];
- [cell.btn_action0 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
- cell.btn_action0.hidden = NO;
- break;
- case 1:
- [cell.btn_action1 setTitle:title forState:UIControlStateNormal];
- [cell.btn_action1 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
- cell.btn_action1.hidden = NO;
- break;
- case 2:
- [cell.btn_action2 setTitle:title forState:UIControlStateNormal];
- [cell.btn_action2 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
- cell.btn_action2.hidden = NO;
- break;
- case 3:
- [cell.btn_action3 setTitle:title forState:UIControlStateNormal];
- [cell.btn_action3 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
- cell.btn_action3.hidden = NO;
- break;
- default:
- break;
- }
- }
-
- if (count<4)
- cell.btn_action3.hidden=YES;
- if (count<3)
- cell.btn_action2.hidden=YES;
- if (count<2)
- cell.btn_action1.hidden=YES;
- if (count<1)
- cell.btn_action0.hidden=YES;
-
- // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- // NSString* value =[item_json valueForKey:@"value"];
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
- // NSDictionary* data = [item_json objectForKey:@"data"];
- //
- // cell.labelAction.text=title;
- // cell.action_code = value;
- //
- //
- // //cell.labelValue.text = value;
- //
- // if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil))
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor redColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else
- if([control isEqualToString:@"switch"])
- {
- CellIdentifier = @"CommonEditorCellSwitch";
- CommonEditorCellSwitch * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSString* title = [item_json valueForKey:@"aname"];
- NSString* value =[item_json valueForKey:@"value"];
-
-
- cell.labelTitle.text=title;
-
- int disabble = [[item_json objectForKey:@"disable"] intValue];
- if (disabble==1 || readonly) {
- cell.switchCtrl.enabled = NO;
- } else {
- cell.switchCtrl.enabled = YES;
- }
-
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
-
-
- // CGSize asize=[cell.labelTitle sizeThatFits:cell.labelTitle.frame.size];
- //
- // cell.starMark.frame = CGRectMake(cell.labelTitle.frame.origin.x+asize.width, cell.labelTitle.frame.origin.y, 10, 21);
- // cell.starMark.hidden=false;
-
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
- [cell.switchCtrl addTarget:self
- action:@selector(switchIsChanged:)
- forControlEvents:UIControlEventValueChanged];
- if([[value lowercaseString] isEqualToString:@"true"])
- cell.switchCtrl.on = true;
- else
- cell.switchCtrl.on = false;
- cell.accessoryType = UITableViewCellAccessoryNone;
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- } else if([control isEqualToString:@"enum"])
- {
-
-
-
- CellIdentifier = @"CommonEditorCellEnum";
- CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- NSDictionary* cadedate_json =[item_json objectForKey:@"cadedate"];
-
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
- cell.labelValue.textColor= [UIColor lightGrayColor];
-
- }
- else
- {
- cell.labelValue.textColor= [UIColor blackColor];
- // cell.textfield.backgroundColor = [UIColor whiteColor];
- }
-
- NSString* align =[item_json valueForKey:@"align"];
- if([align isEqualToString:@"right"])
- cell.labelValue.textAlignment= NSTextAlignmentRight;
- else
- cell.labelValue.textAlignment =NSTextAlignmentLeft;
-
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
-
-
- NSString* value =@"";
- int count = [[cadedate_json valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSDictionary* val_json =[cadedate_json objectForKey:[NSString stringWithFormat:@"val_%d",i]];
- int check = [[val_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- value = [value stringByAppendingString:[val_json valueForKey:@"value"]];
- value = [value stringByAppendingString:@"|"];
- }
- }
- if(value.length>=1)
- value=[value substringToIndex:value.length-1];
- cell.labelTitle.text=title;
-
-
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
- cell.labelValue.text = value;
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- } else if([control isEqualToString:@"model"])
- {
- CommonEditorCellModel * cell= [tableView dequeueReusableCellWithIdentifier:@"CommonEditorCellModel" forIndexPath:indexPath];
-
- int count = [[item_json valueForKey:@"count"] intValue];
- NSDictionary * combine_json =[item_json objectForKey:@"combine"];
- cell.bundle_item=combine_json;
-
- NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
- if (cell.masterBtn != nil) {
- if (master_json == nil) {
- cell.masterBtn.hidden = YES;
- } else{
- cell.masterBtn.hidden = NO;
- cell.master_items = master_json;
- }
- }
-
- double dprice=0.0;
-
- if(cell.bundle_item!=nil)
- {
- int citem=0;
-
- int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
- for(int bc=0;bc<bcount;bc++)
- {
- NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
- int modulus= [[bitem valueForKey:@"modulus"] intValue];
- citem+= modulus;
- double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
- dprice+= uprice*modulus;
-
- }
- if(citem==1)
- [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
- else
- [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
-
- cell.buttonBundle.hidden = NO;
- }
- else
- {
- cell.buttonBundle.hidden = YES;
-
- }
-
- NSString *availability = [item_json objectForKey:@"quantity_available"];
- NSString *available_str = @"Available Now";
- if ([availability integerValue] > 0) {
- available_str = [NSString stringWithFormat:@"Available: %@",availability];
- } else {
- // available_str = @"Available: In Production";
- available_str = @"Available: Out of Stock";
- }
- cell.avalibilityLabel.text = available_str;
-
- NSString* img_url = [item_json valueForKey:@"img_url"];
- NSString* description = [item_json valueForKey:@"description"];
- // NSString* identifier = [item_json valueForKey:@"identifier"];
- // NSString* attribute = [item_json valueForKey:@"attribute"];
-
- // NSString* total_price = [item_json valueForKey:@"total_price"] ;
- // NSString* unit_price = [item_json valueForKey:@"unit_price"] ;
-
- // NSString* mp = [item_json valueForKey:@"stockUom"];
- double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
- int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
- double discount =[[item_json valueForKey:@"discount"] doubleValue];
- NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
-
-
- NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice];
- NSString* newunitprice=@"";
- if(dprice>0)
- newunitprice = [NSString stringWithFormat:@"%.2f+%.2f",unitprice* (1.0-discount/100),dprice];
- else
- newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
- NSString* totalprice = [NSString stringWithFormat:@"%.2f",(unitprice* (1.0-discount/100)+dprice)*count];
-
-
- BOOL can_see_price = [[appDelegate globalParameterForKey:@"can_see_price"] boolValue];
- BOOL price_hidden = [[appDelegate globalParameterForKey:@"price_hidden"] boolValue];
-
- if(can_see_price&&price_hidden==false)
- {
-
- }
- else
- {
- oldprice=nil;
- newunitprice=nil;
- totalprice=nil;
- }
-
-
- cell.labelDiscount.text = discountstr;
- cell.labelOldPrice.text = oldprice;
- cell.labelMasterPack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
-
- bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
-
-
-
- if(isfree)
- {
- cell.labelOldPrice.hidden = false;
- cell.labelOldPrice.textColor = [UIColor redColor];
- cell.labelOldPrice.text=@"Free";
- cell.labelOldPrice.hideline = true;
-
- cell.labelDiscount.hidden = true;
- }
- else
- {
- cell.labelOldPrice.textColor = [UIColor blackColor];
- cell.labelOldPrice.hideline = false;
- if(discount==0)
- {
- cell.labelOldPrice.hidden = true;
- cell.labelDiscount.hidden = true;
-
- }
- else
- {
- cell.labelOldPrice.hidden = false;
- cell.labelDiscount.hidden = false;
- }
- }
- // if(discount==0)
- // {
- // cell.labelOldPrice.hidden = true;
- // cell.labelDiscount.hidden = true;
- //
- // }
- // else
- // {
- // cell.labelOldPrice.hidden = false;
- // cell.labelDiscount.hidden = false;
- // }
-
- // NSString* currency = [item_json valueForKey:@"currency"];
- // int count =[[item_json valueForKey:@"count"] intValue];
-
- cell.labelDescription.text = description;
- cell.labelCount.text = [NSString stringWithFormat:@"x %d",count];
- // cell.labelID.text = identifier;
- // cell.labelSubtype.text = attribute;
- cell.labelTotalPrice.text= totalprice;
- // cell.labelUnitPrice.text=unit_price;
-
- cell.labelUnitPrice.text = newunitprice;
- cell.imgModel.image = [UIImage imageNamed:@"loading_s"];
- cell.imgModel.contentMode = UIViewContentModeScaleAspectFit;
-
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- cell.imgModel.image = img;
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.imgModel.image = img;
- }
- else
- cell.imgModel.image = [UIImage imageNamed:@"notfound_s"];
-
- });
- });
-
-
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- }else if([control isEqualToString:@"datepicker"])
- {
-
- CellIdentifier = @"CommonEditorCellEnum";
- CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
-
- NSString* value =[item_json valueForKey:@"value"];
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
- cell.labelTitle.text=title;
-
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
- cell.labelValue.text = value;
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else if([control isEqualToString:@"monthpicker"])
- {
-
- CellIdentifier = @"CommonEditorCellEnum";
- CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
-
- NSString* value =[item_json valueForKey:@"value"];
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
- cell.labelTitle.text=title;
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
- cell.labelValue.text = value;
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else if([control isEqualToString:@"signature"])
- {
-
- CellIdentifier = @"CommonEditorCellSignature";
- CommonEditorCellSignature * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.imageviewSignature.contentMode = UIViewContentModeScaleAspectFit;
-
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
-
- int disabble = [[item_json objectForKey:@"disable"] intValue];
- if (disabble==1 || readonly) {
- cell.imageviewSignature.userInteractionEnabled = NO;
- } else {
- cell.imageviewSignature.userInteractionEnabled = YES;
- }
-
-
- cell.labelTitle.text = title;
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
-
- NSString* img_url = [item_json valueForKey:@"avalue"];
-
-
-
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- cell.imageviewSignature.image=img ;
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.imageviewSignature.image=img ;
- }
- else
- cell.imageviewSignature.image=[UIImage imageNamed:@"taptosign_s"];
-
-
- });
- });
-
-
- } cell.backgroundColor = [UIColor whiteColor];
-
- return cell;
- // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- //cell.imageviewSignature.image = image;
- }
- else if ([control isEqualToString:@"range"]) {
-
- NSString *type = [item_json objectForKey:@"type"];
- NSString *keyboard = [item_json objectForKey:@"keyboard"];
- NSString *title = [item_json objectForKey:@"aname"];
- NSString *min = [item_json objectForKey:@"min_value"];
- NSString *max = [item_json objectForKey:@"max_value"];
-
- CommonEditorRangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorRangeCell" forIndexPath:indexPath];
- cell.indexPath = indexPath;
- cell.delegate = self;
- [cell setTitle:title];
- [cell setMinValue:min maxValue:max];
- if ([type isEqualToString:@"date"]) {
- [cell setType:CommonEditorRangeTypeDate];
- } else {
- [cell setType:CommonEditorRangeTypeDefault];
- }
- if([keyboard isEqualToString:@"number"]) {
- [cell setKeyboardType:UIKeyboardTypeDecimalPad];
- } else {
- [cell setKeyboardType:UIKeyboardTypeDefault];
- }
- return cell;
- }
- else if ([control isEqualToString:@"webview"]) {
-
- // CommonEditorWebCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorWebCell" forIndexPath:indexPath];
-
- CommonEditorWebCell * cell = [[NSBundle mainBundle] loadNibNamed:@"Phone_Web_Cell" owner:nil options:nil].firstObject;
-
- cell.webDelegate = self;
- NSString *html_str = [item_json objectForKey:@"value"];
-
-
- // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[html_str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
- //
- // cell.htmlLabel.attributedText = attrStr;
-
- // [cell.webview stopLoading];
- [cell.webview loadHTMLString:html_str baseURL:nil];
- // [cell.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com/"]]];
-
- return cell;
- }
- else if ([control isEqualToString:@"banner"]) {
- CommonEditorBannerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorBannerCell" forIndexPath:indexPath];
-
- // NSDictionary *item_json = @{
- // @"control" : @"banner",
- // @"item_4": @{
- // @"type" : @"image",
- // @"s": @"http://127.0.0.1/s2.jpg",
- // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7528.jpg"
- // },
- // @"count": @(5),
- // @"item_2": @{
- // @"type" : @"image",
- // @"s": @"http://127.0.0.1/s3.jpg",
- // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7526.jpg"
- // },
- // @"item_3": @{
- // @"type" : @"image",
- // @"s": @"http://127.0.0.1/s4.jpg",
- // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7527.jpg"
- // },
- // @"item_0": @{
- // @"type" : @"image",
- // @"s": @"http://127.0.0.1/s1.jpg",
- // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7524.jpg"
- // },
- // @"item_1": @{
- // @"type" : @"image",
- // @"s": @"http://127.0.0.1/s5.jpg",
- // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7525.jpg"
- // }
- // };
-
- [cell setContent:item_json];
- cell.delegate = self;
-
- return cell;
- }
- else
- {
- CellIdentifier = @"CommonEditorCellEdit";
- UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- }
- - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
-
- NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
- if(value==nil)
- value=@"";
- unsigned long color = strtoul([value UTF8String],0,16);
-
-
- NSString* btntitle=nil ;
- NSString*labeltitle = nil;
- NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy];
-
- labeltitle= [sectionjson valueForKey:@"title"];
-
- bool hide = [[sectionjson valueForKey:@"hide"]boolValue];
- if(hide)
- {
- btntitle=@"Show";
- // [section setValue:@"false" forKey:@"hide"];
- // [sender setTitle:@"Show" forState:UIControlStateNormal];
- }
- else{
- btntitle=@"Hide";
- }
-
- DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // myView.backgroundColor = [UIColor whiteColor];//UIColorFromRGB(0x996633);;
- myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
- myView.layer.shadowColor = [UIColor blackColor].CGColor;
- myView.layer.shadowOffset = CGSizeMake(0, 0);
- myView.layer.shadowOpacity = 0.5;
- myView.layer.shadowRadius = 2.0;
-
- int linespace=0;
- if(section==0)
- linespace=11;
-
- UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0+linespace, 50, 33)];
- btn.tag=section;
- // [btn setTitleColor:UIColorFromRGB(0x996633) forState:UIControlStateNormal];
- [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
- [btn setTitle:btntitle forState:UIControlStateNormal];
- [myView addSubview:btn];
-
-
- btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
- myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
-
-
- UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5+linespace, 200, 20)];
- titlelabel.textColor=UIColorFromRGB(color);//[UIColor whiteColor];
- titlelabel.backgroundColor = [UIColor clearColor];
- titlelabel.text=NSLocalizedString(labeltitle, nil);
- titlelabel.font = [UIFont boldSystemFontOfSize:20];
- [titlelabel sizeToFit];
- [myView addSubview:titlelabel];
- //
- // UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 0, 90, 22)];
- // contactlabel.textColor=[UIColor whiteColor];
- // contactlabel.backgroundColor = [UIColor clearColor];
- // contactlabel.text=NSLocalizedString(@"Contact", nil);
- // [contactlabel sizeToFit];
- // [myView addSubview:contactlabel];
- //
- //
- // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 0, 90, 22)];
- // modellabel.textColor=[UIColor whiteColor];
- // modellabel.backgroundColor = [UIColor clearColor];
- // modellabel.text=NSLocalizedString(@"Model", nil);
- // [modellabel sizeToFit];
- // [myView addSubview:modellabel];
- //
- // UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(500, 0, 90, 22)];
- // pricelabel.textColor=[UIColor whiteColor];
- // pricelabel.backgroundColor = [UIColor clearColor];
- // pricelabel.text=NSLocalizedString(@"Price", nil);
- // [pricelabel sizeToFit];
- // [myView addSubview:pricelabel];
- //
- //
- //
- // UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(630, 0, 90, 22)];
- // timelabel.textColor=[UIColor whiteColor];
- // timelabel.backgroundColor = [UIColor clearColor];
- // timelabel.text=NSLocalizedString(@"Create time", nil);
- // [timelabel sizeToFit];
- // [myView addSubview:timelabel];
- //
- //
- //
- // UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 60, 22)];
- // statuslabel.textColor=[UIColor whiteColor];
- // statuslabel.backgroundColor = [UIColor clearColor];
- // statuslabel.text=NSLocalizedString(@"Status", nil);
- // [statuslabel sizeToFit];
- // [myView addSubview:statuslabel];
- //
- return myView;
- }
- //
- -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue];
- int disable = [[item_json valueForKey:@"disable"] intValue];
-
- DebugLog(@"tableView willSelectRowAtIndexPath");
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString* control = [item_json valueForKey:@"control"];
- if([control isEqualToString:@"enum"])//||[control isEqualToString:@"ui"])
- {
- // int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- return nil;
- // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
- NSDictionary* cadedate_json = [item_json objectForKey:@"cadedate"];
- // NSDictionary* value_json = [item_json objectForKey:@"value"];
- NSString* single_select = [item_json valueForKey:@"single_select"];
- // NSString* required =[item_json valueForKey:@"required"];
- NSString* title = [item_json valueForKey:@"aname"];
-
- BOOL sort = [[item_json objectForKey:@"sort"] boolValue];
- if (sort) {
-
- EnumSelectAndSortViewController *vc = [[UIStoryboard storyboardWithName:@"EnumSelectAndSort" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectAndSortViewController"];
- vc.title = title;
- [vc setEnumDataSource:cadedate_json];
- vc.indexPath = indexPath;
- __weak typeof(self) weakSelf = self;
- vc.returnBlock = ^(NSDictionary *returnValue, NSIndexPath *idxPath) {
- [weakSelf EnumValueChanged:[returnValue mutableCopy] indexPath:idxPath];
- };
-
- [self.navigationController pushViewController:vc animated:YES];
-
- return nil;
- }
-
- int max_select = [[item_json valueForKey:@"max"] intValue];
-
- EnumSelectViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
- enumvc.delegate = self;
- enumvc.max_select = max_select;
- enumvc.updatePosition = indexPath;
- // if([[required lowercaseString] isEqualToString:@"true"])
- // enumvc.canbeEmpty = false;
- // else
- // enumvc.canbeEmpty =true;
- enumvc.cadedate = [cadedate_json mutableCopy];
- enumvc.title = title;
- // enumvc.value = [value_json mutableCopy];
- enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"];
-
- [self.navigationController pushViewController:enumvc animated:true];
-
- }else if([control isEqualToString:@"action"])
- {
- if (disable || readonly) {
- return nil;
- }
- NSString* value = [item_json valueForKey:@"value"];
- [self commonAction:value index:indexPath data:item_json];
- }
- else if([control isEqualToString:@"datepicker"])
- {
- if (disable || readonly) {
- return nil;
- }
-
- // NSString* title = [item_json valueForKey:@"aname"];
-
- NSString* value =[item_json valueForKey:@"value"];
- NSString* type =[item_json valueForKey:@"type"];
-
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
-
-
-
-
- DatePickerViewController* dpvc =[ [UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"DatePickerViewController"];
- if([[type lowercaseString] isEqualToString:@"date"])
- {
- dpvc.pickerMode = UIDatePickerModeDate;
- [dateFormatter setDateFormat:@"yyyy/MM/dd"];
- }
- else if([[type lowercaseString] isEqualToString:@"time"])
- {
- dpvc.pickerMode = UIDatePickerModeTime;
- [dateFormatter setDateFormat:@"HH:mm:ss"];
- }
- else
- {
- dpvc.pickerMode = UIDatePickerModeDateAndTime;
- [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
- }
- NSDate *date = [dateFormatter dateFromString:value];
- dpvc.date = date;
- dpvc.formatter = dateFormatter;
- dpvc.labelTime.text = value;
- [self.navigationController pushViewController:dpvc animated:true];
-
- }else if([control isEqualToString:@"monthpicker"])
- {
- if (disable || readonly) {
- return nil;
- }
-
- // NSString* title = [item_json valueForKey:@"aname"];
-
- NSString* value =[item_json valueForKey:@"value"];
- if (value==nil || value.length==0)
- {
- value=@"1/2015";
- }
- // NSString* type =[item_json valueForKey:@"type"];
-
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
-
-
-
-
- MonthPickerViewController* mpvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"MonthPickerViewController"];
- // if([[type lowercaseString] isEqualToString:@"date"])
- // {
- // dpvc.pickerMode = UIDatePickerModeDate;
- [dateFormatter setDateFormat:@"MM/yyyy"];
- NSDate *date = [dateFormatter dateFromString:value];
-
- mpvc.current_date =date;
- mpvc.updatePosition = indexPath;
- mpvc.delegate = self;
- // }
- // else if([[type lowercaseString] isEqualToString:@"time"])
- // {
- // dpvc.pickerMode = UIDatePickerModeTime;
- // [dateFormatter setDateFormat:@"HH:mm:ss"];
- // }
- // else
- // {
- // dpvc.pickerMode = UIDatePickerModeDateAndTime;
- // [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
- // }
- // NSDate *date = [dateFormatter dateFromString:value];
- // dpvc.date = date;
- // dpvc.formatter = dateFormatter;
- // dpvc.labelTime.text = value;
- [self.navigationController pushViewController:mpvc animated:true];
-
- }
- else if([control isEqualToString:@"signature"])
- {
- // SignatureViewController * signvc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
- // signvc.title = [item_json valueForKey:@"aname"];
- // signvc.indexPath = indexPath;
- // // signvc.delegate = self;
- // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- //
- // signvc.existSignature = cell.imageviewSignature.image ;
- //
- //
- //
- // [self.navigationController pushViewController:signvc animated:true];
-
- if (disable || readonly) {
- return nil;
- }
- __block UIImage* signimg=nil;
- SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
- __weak typeof(self) weakself = self;
- vc.onReturnImg = ^(UIImage* img)
- {
- signimg = img;
-
- if(signimg!=nil)
- {
- #ifdef OFFLINE_MODE
- BOOL offline_mode = [[appDelegate globalParameterForKey:@"offline_mode"] boolValue];
- if(offline_mode)
- {
-
-
-
- NSData *data = [OLDataProvider offline_saveBusinesscard:UIImagePNGRepresentation(img)];
-
- // 再将NSData转为字符串
- NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-
- // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-
- DebugLog(@"data string: %@",jsonStr);
- NSError *error=nil;
- NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
-
-
-
-
-
-
- //NSMutableArray* arr_ret = [[NSMutableArray alloc] init];
- if([[json valueForKey:@"result"] intValue]==2)
- {
- NSString* img_url_down = json[@"img_url_aname"];
- // if(img_url_down.length==0)
- // img_url_down=@"";
- NSString* img_url_up = json[@"img_url"];
- // if(img_url_up.length==0)
- // img_url_up=@"";
-
- NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
-
- [item_json setValue:img_url_down forKey:@"avalue"];
- [item_json setValue:img_url_up forKey:@"value"];
- [item_json setValue:@"true" forKey:@"dirty"];
- NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
-
- [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
-
-
- CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
-
- cell.imageviewSignature.image = signimg;
-
-
- }
- else
- {
- [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ;
- }
- }
- else
- #endif
- {
- NSData *imageData = UIImagePNGRepresentation(img);
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString *user = [appDelegate globalParameterForKey:@"user"];
- NSString *password = [appDelegate globalParameterForKey:@"password"];
-
- if(user!=nil)
- [params setValue:user forKey:@"user"];
- if(password!=nil)
- [params setValue:password forKey:@"password"];
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Upload Signature"];
-
- [NetworkUtils upload:imageData FileName:@"test.jpg" Params:params ToHost:URL_UPLOAD_IMG Result:^(NSMutableDictionary *json) {
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
- if([[json valueForKey:@"result"] intValue]==2)
- {
- NSString* img_url_down = json[@"img_url_aname"];
- NSString* img_url_up = json[@"img_url"];
-
- NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
-
- [item_json setValue:img_url_down forKey:@"avalue"];
- [item_json setValue:img_url_up forKey:@"value"];
- [item_json setValue:@"true" forKey:@"dirty"];
- NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
-
- [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
-
-
- CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
-
- cell.imageviewSignature.image = signimg;
-
-
- }
- else
- {
- [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ;
- }
-
- });
-
- } Progress:nil DecryptHandler:nil];
-
-
-
- // AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
- //
- // NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_IMG parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
- // [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test.jpg" mimeType:@"image/png"];
- // } error:nil];
- //
- //
- //
- // AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
- //
- //
- //
- //
- // NSProgress *progress = nil;
- // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Upload Signature"];
- // NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
- //
- // // [progress removeObserver:self forKeyPath:@"fractionCompleted"];
- //
- //
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- //
- // if (error) {
- //
- // NSString* err_msg = [error localizedDescription];
- // DebugLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
- //
- //
- // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
- //
- // DebugLog(@"data string: %@",str);
- //
- // [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:weakself] ;
- //
- // } else {
- // DebugLog(@"response ");
- //
- //
- //
- // NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
- //
- // // 再将NSData转为字符串
- // NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- //
- // // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
- //
- // DebugLog(@"data string: %@",jsonStr);
- //
- // NSDictionary* json = responseObject;
- //
- //
- // //NSMutableArray* arr_ret = [[NSMutableArray alloc] init];
- // if([[json valueForKey:@"result"] intValue]==2)
- // {
- // NSString* img_url_down = json[@"img_url_aname"];
- // // if(img_url_down.length==0)
- // // img_url_down=@"";
- // NSString* img_url_up = json[@"img_url"];
- // // if(img_url_up.length==0)
- // // img_url_up=@"";
- //
- // NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
- //
- // [item_json setValue:img_url_down forKey:@"avalue"];
- // [item_json setValue:img_url_up forKey:@"value"];
- // [item_json setValue:@"true" forKey:@"dirty"];
- // NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
- //
- // [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
- //
- //
- // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
- //
- // cell.imageviewSignature.image = signimg;
- //
- //
- // }
- // else
- // {
- // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ;
- // }
- //
- //
- //
- //
- //
- //
- // }
- // //
- // }];
- //
- // [uploadTask resume];
- }
- }
-
-
- };
-
-
- [self.navigationController pushViewController:vc animated:NO];
- }
- // else if([control isEqualToString:@"action "])
- // {
- //
- // DebugLog(@"action push");
- // // SignatureViewController * signvc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
- // // signvc.title = [item_json valueForKey:@"aname"];
- // // signvc.indexPath = indexPath;
- // // signvc.delegate = self;
- // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- // //
- // // signvc.existSignature = cell.imageviewSignature.image ;
- // //
- // //
- // //
- // // [self.navigationController pushViewController:signvc animated:true];
- // }
- return nil;
- }
- //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- //{
- //
- // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
- //
- // NSString* orderid = [item_json valueForKey:@"id"];
- //
- // // if (self.delegate && [self.delegate respondsToSelector:@selector(SelectOrder:)]) {
- // // [self.delegate SelectOrder:orderid];
- // // }
- // //
- // // [self dismissViewControllerAnimated:YES
- // // completion:^{
- // // //一定要移除手势 否则下次 没有子视图的时候 点击 会崩溃拉
- // // AppDelegate *app = [[UIApplication sharedApplication] delegate];
- // // [app.window removeGestureRecognizer:self.tapGesture];
- // // }];
- // // [pvc categoryMenuSelected:indexPath.row];
- //}
- #pragma mark monthpicker ViewControllerDelegate
- -(void) MPValueChanged:(NSString *)value indexPath :(NSIndexPath*) indexPath
- {
- CommonEditorCellEnum * cell= (CommonEditorCellEnum*) [self.editorTable cellForRowAtIndexPath:indexPath];
-
- cell.labelValue.text = value;
-
-
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
-
-
- // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- // UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview;
- // NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
-
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- // NSString* check=@"false";
- // if([paramSender isOn])
- // check=@"true";
- // [item_json setValue:value forKey:@"dirty"];
-
-
-
- NSString* subid=[item_json valueForKey:@"subid"];
- [item_json setValue:value forKey:@"value"];
-
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- NSString* control_type= [olditem valueForKey:@"control"];
- if([control_type isEqualToString:@"enum"])
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- else if([control_type isEqualToString:@"switch"])
- item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- [self.editorTable reloadData ];
- }
- #pragma mark EnumSelectViewControllerDelegate
- -(void) setEnumValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
- {
- NSMutableDictionary* section_json=nil;
-
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
-
-
-
- int refresh = [[item_json valueForKey:@"refresh"] intValue];
-
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSString* subid=[item_json valueForKey:@"subid"];
-
- [item_json setObject:value forKey:@"cadedate"];
-
-
- if(subid==nil)
- {
- [item_json setValue:@"true" forKey:@"dirty"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
-
-
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
-
-
- if(refresh==1)
- {
-
-
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger] ;
- return ;
- }
-
-
- DebugLog(@"CONTENT UPDATE:%@",[RAConvertor DataTOjsonString:self.content_data_download]);
-
-
-
- // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- [self.editorTable reloadData ];
- }
- -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
- {
-
-
- UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
-
-
- // if(/*self.cancommit==false &&*/ string.length==0 && (textField.text.length<=1|| textField.text==nil))
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor redColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- // else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
-
- DebugLog(@"enum changed %ld_%ld",(long)indexPath.section,(long)indexPath.row);
-
- [self setEnumValue:value indexPath:indexPath];
-
- }
- -(NSMutableDictionary*) enum_subitem_changed:(NSMutableDictionary *) item subid:(NSArray*) subid value:(NSMutableDictionary*)value step:(int) step
- {
- int index = [(NSString*)subid[step] intValue];
- NSMutableDictionary * cadedate= [[item objectForKey:@"cadedate"] mutableCopy];
- NSMutableDictionary * subitem= [[item objectForKey:@"sub_item"] mutableCopy];
- if(cadedate!=nil)
- {
- NSMutableDictionary * valjson=[[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",index]]mutableCopy];
- valjson= [self enum_subitem_changed:valjson subid:subid value:value step:step+1];
-
-
- [cadedate setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",index]];
- [item setObject:cadedate forKey:@"cadedate"];
- return item;
- }
- else if(subitem!=nil)
- {
- NSMutableDictionary * itemjson=[[subitem objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy];
- if(step==subid.count-1)
- {
- itemjson =value;
-
- }
- else
- itemjson =[self enum_subitem_changed:itemjson subid:subid value:value step:step+1];
-
- [subitem setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]];
- [item setObject:subitem forKey:@"sub_item"];
- return item;
- }
- return nil;
-
- }
- //#pragma mark SignatureViewControllerDelegate
- ////-(void)SignatureVCReturnData:(NSData *)imagedata indexPath:(NSIndexPath *)indexPath
- ////{
- ////
- ////}
- //-(void)SignatureVCReturnImage:(UIImage *)image indexPath:(NSIndexPath *)indexPath
- //{
- //
- // // NSMutableDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- // //
- // // if(image==nil)
- // // [item_json removeObjectForKey:@"signature"];
- // // else
- // // [item_json setObject:image forKey:@"signature"];
- // // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // // [self.content_data setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // //
- // //
- // //
- // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- // // cell.imageviewSignature.image = image;
- //}
- #pragma mark textView delegate
- //- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
- //- (BOOL)textViewShouldEndEditing:(UITextView *)textView;
- - (BOOL)textViewShouldBeginEditing:(UITextView *)textView
- {
-
- DebugLog(@"textViewShouldBeginEditing");
-
- self.editingcell = (UITableViewCell*)textView.superview.superview;
- return textView.editable;
- }
- - (void)textViewDidBeginEditing:(UITextView *)textView
- {
- self.lasttextview = textView;
-
- UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
- self.lasttextview_from = [self.editorTable indexPathForCell:cell];
-
-
-
- }
- - (void)textViewDidEndEditing:(UITextView *)textView
- {
- // UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
- NSIndexPath * indexPath = self.lasttextview_from;//[self.editorTable indexPathForCell:cell];
-
-
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- NSString* subid=[item_json valueForKey:@"subid"];
-
-
- [item_json setValue:@"true" forKey:@"dirty"];
- [item_json setValue:textView.text forKey:@"value"];
-
-
- // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- NSString* control_type= [olditem valueForKey:@"control"];
- if([control_type isEqualToString:@"enum"])
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- else if([control_type isEqualToString:@"switch"])
- item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
- self.lasttextview = nil;
- self.lasttextview_from=nil;
- // if(self.resize)
- // {
- // NSTimeInterval animationDuration = 0.30f;
- // CGRect frame = self.view.frame;
- // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
- // // { //还原界面
- // // moveY = prewMoveY;
- // frame.origin.y +=self.ioffset;
- // frame.size. height -=self.ioffset;
- // self.view.frame = frame;
- // // }
- // //self.view移回原位置
- // [UIView beginAnimations:@"ResizeView" context:nil];
- // [UIView setAnimationDuration:animationDuration];
- // self.view.frame = frame;
- // [UIView commitAnimations];
- // //[textField resignFirstResponder];
- // self.ioffset=0;
- // }
-
- }
- - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
- {
-
-
-
-
- UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
-
- NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
- // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
-
- NSString* required = [item_json valueForKey:@"required"];
-
- if([required isEqualToString:@"true"] && text.length==0 && (textView.text.length<=1|| textView.text==nil))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
-
-
- return YES;
- }
- //- (void)textViewDidChange:(UITextView *)textView;
- //
- //- (void)textViewDidChangeSelection:(UITextView *)textView;
- //
- //- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
- //- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
- #pragma mark textField delegate
- -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
-
- DebugLog(@"textField shouldChangeCharactersInRange");
- DebugLog(@"text:%@",textField.text);
-
-
-
-
-
- CommonEditorCellEdit *cell = (CommonEditorCellEdit *) textField.superview.superview;
-
- NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
- // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
-
- NSString* required = [item_json valueForKey:@"required"];
-
-
-
- if([required isEqualToString:@"true"] && string.length==0 && (textField.text.length<=1|| textField.text==nil))
- {
-
-
-
-
-
-
- CALayer *layer = cell.labelTitle.layer;
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
-
- layer = cell.starMark.layer;
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- //UIImageView * iv =
- cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_attention_24"]];
- cell.textfield.rightViewMode=UITextFieldViewModeUnlessEditing;
- textField.layer.cornerRadius=8.0f;
- textField.layer.borderWidth= 1.0f;
- textField.layer.masksToBounds=YES;
- textField.layer.borderColor=[[UIColor redColor]CGColor];
- }
- else
- {
- CALayer *layer = cell.labelTitle.layer;//[cell.contentView layer];
-
-
-
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
-
-
- layer = cell.starMark.layer;//[cell.contentView layer];
-
-
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
-
- //cell.textfield.layer.borderColor= [[UIColor lightGrayColor] CGColor];
- //UIImageView * iv =
- // cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_wish_16"]];
- cell.textfield.rightViewMode=UITextFieldViewModeNever;
- textField.layer.cornerRadius=8.0f;
- textField.layer.borderWidth= 1.0f;
- textField.layer.masksToBounds=YES;
- textField.layer.borderColor=[[UIColor lightGrayColor]CGColor];
- }
-
- //
- // if([required isEqualToString:@"true"] && string.length==0 && (textField.text.length<=1|| textField.text==nil))
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor redColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- // else
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor clearColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
-
-
- NSString* keyboard = [item_json valueForKey:@"keyboard"];
- if(![keyboard isEqualToString:@"number"] && ![keyboard isEqualToString:@"int"])
- return TRUE;
- NSCharacterSet *cs;
- if([keyboard isEqualToString:@"number"])
- cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
- else
- cs = [[NSCharacterSet characterSetWithCharactersInString:INTNUMBERS]invertedSet];
-
- NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
-
- BOOL canChange = [string isEqualToString:filtered];
-
- int lenth = [[item_json valueForKey:@"length"] intValue];
- if(lenth==0)
- return canChange;
- else
- {
- return canChange&& (lenth>textField.text.length ||[string isEqualToString:@""]);
- }
- }
- - (void)textFieldDidEndEditing:(UITextField *)textField
- {
-
- DebugLog(@"textFieldDidEndEditing");
- // UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
- NSIndexPath * indexPath = self.lastedit_from;
-
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- if ([item_json objectForKey:@"fill"]) {
- NSString *fillText = [item_json objectForKey:@"fill"];
-
- if (fillText && textField.text.length == 0) {
- textField.text = fillText;
- }
- }
-
- [self textfieldSetValue:indexPath value:textField.text];
- // NSMutableDictionary* section_json=nil;
- //
- //
- //
- // textField.text = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
- //
- // // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
- //
- // NSString* subid=[item_json valueForKey:@"subid"];
- // NSString* refresh_trigger = [item_json valueForKey:@"name"];
- //
- // [item_json setValue:@"true" forKey:@"dirty"];
- // [item_json setValue:textField.text forKey:@"value"];
- // if([[item_json valueForKey:@"keyboard"] isEqualToString:@"number"])
- // {
- // float f = [ textField.text floatValue];
- // [item_json setValue:[NSString stringWithFormat:@"%.2f",f] forKey:@"value"];
- //
- // }
- //
- // // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
- // if(subid==nil)
- // {
- // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- // int count=0;
- //
- // count=[[section_json valueForKey:@"count"] intValue];
- //
- // for(int i=0;i<count;i++)
- // {
- // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
- //
- //
- // }
- //
- //
- // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- //
- // int refresh = [[item_json valueForKey:@"refresh"] intValue];
- //
- // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- // bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
- // if(refresh==1)
- // {
- //
- // if(restore_json!=nil)
- // {
- // int rc=[[restore_json valueForKey:@"count"] intValue];
- // for(int ir=0;ir<rc;ir++)
- // {
- // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
- //
- //
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- //
- // if([[itemjson valueForKey:@"name"] isEqualToString:name])
- // {
- // [itemjson removeObjectForKey:@"dirty"];
- // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- // }
- //
- // }
- // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- // }
- //
- //
- // }
- //
- // }
- // [self refresh:refresh_trigger] ;
- //
- // }
- // else if(partial_refresh)
- // {
- // NSString* name = [item_json valueForKey:@"name"] ;
- // NSString* url = [item_json valueForKey:@"data_interface"] ;
- //
- //
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- //
- // [params setValue:textField.text forKey:name];
- //
- //
- // UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* editor_json = [iSalesNetwork commoneditor_partialrefresh:params url:url];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- //
- //
- // if([[editor_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // int prcount = [[editor_json valueForKey:@"count"] intValue];
- // for(int ipr=0;ipr<prcount;ipr++)
- // {
- // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
- // NSString* name = [pr_item valueForKey:@"name"];
- // NSString* value = [pr_item valueForKey:@"value"];
- //
- // [self setValue:name value:value];
- // }
- //
- //
- // }
- // else
- // {
- // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
- // }
- //
- //
- // });
- // });
- //
- //
- //
- // }
- // self.lastedit = nil;
- // self.lastedit_from=nil;
- // return ;
- // }
- // else
- // {
- // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- // int section = [(NSString*)idarr[0] intValue];
- // int item=[(NSString*)idarr[1] intValue];
- //
- //
- // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- //
- // NSString* control_type= [olditem valueForKey:@"control"];
- // NSMutableDictionary* new_item=nil;
- // [item_json setValue:@"true" forKey:@"dirty"];
- // if([control_type isEqualToString:@"enum"])
- // new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- // else if([control_type isEqualToString:@"switch"])
- // new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- //
- // [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
- //
- //
- // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- //
- // int refresh = [[item_json valueForKey:@"refresh"] intValue];
- //
- // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- // bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
- // if(refresh==1)
- // {
- //
- // if(restore_json!=nil)
- // {
- // int rc=[[restore_json valueForKey:@"count"] intValue];
- // for(int ir=0;ir<rc;ir++)
- // {
- // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
- //
- //
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- //
- // if([[itemjson valueForKey:@"name"] isEqualToString:name])
- // {
- // [itemjson removeObjectForKey:@"dirty"];
- // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- // }
- //
- // }
- // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- // }
- //
- //
- // }
- //
- // }
- // [self refresh:refresh_trigger] ;
- //
- // }
- // else if(partial_refresh)
- // {
- // NSString* name = [item_json valueForKey:@"name"] ;
- // NSString* url = [item_json valueForKey:@"data_interface"] ;
- //
- //
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- //
- // [params setValue:textField.text forKey:name];
- //
- //
- // UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* editor_json = [iSalesNetwork commoneditor_partialrefresh:params url:url];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- //
- //
- // if([[editor_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // int prcount = [[editor_json valueForKey:@"count"] intValue];
- // for(int ipr=0;ipr<prcount;ipr++)
- // {
- // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
- // NSString* name = [pr_item valueForKey:@"name"];
- // NSString* value = [pr_item valueForKey:@"value"];
- //
- // [self setValue:name value:value];
- // }
- //
- // }
- // else
- // {
- // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
- // }
- //
- //
- // });
- // });
- //
- //
- //
- // }
- // self.lastedit = nil;
- // self.lastedit_from=nil;
- //
- // return;
- // }
- //
-
-
- }
- - (void)textFieldDidBeginEditing:(UITextField *)textField
- {
- DebugLog(@"textField shouldChangeCharactersInRange");
-
- self.lastedit = textField;
- UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
- self.lastedit_from = [self.editorTable indexPathForCell:cell];
-
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[self.lastedit_from.section])[self.lastedit_from.row];
-
- if ([item_json valueForKey:@"clear"]) {
- //开始编辑时清掉旧内容
- BOOL clear = [[item_json valueForKey:@"clear"] doubleValue] == [textField.text doubleValue];
-
- if (clear) {
- textField.text = nil;
- }
- }
- }
- - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
-
- self.editingcell = (UITableViewCell*)textField.superview.superview;
-
- NSIndexPath* indexPath=[self.editorTable indexPathForCell:self.editingcell];
- // NSMutableDictionary* section_json=nil;
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
- if([item_json[@"autocomplete"] boolValue]==true)
- {
- // [textField endEditing:true];
- self.lastedit_from = [self.editorTable indexPathForCell:(UITableViewCell*) textField.superview.superview];
- self.autocompleteView.active_field = textField;
- self.autocompleteView.hidden = false;
- self.autocompleteView.searchInput.keyboardType=textField.keyboardType;
- self.autocompleteView.searchInput.text= textField.text;
- [self.autocompleteView.searchInput becomeFirstResponder];
- __weak typeof(self) weakself = self;
- self.autocompleteView.returnValue = ^(NSString *str) {
- //textField = true;
- // [textField endEditing:false];
- textField.text=str;
- // [textField endEditing:true];
-
- [weakself textFieldDidEndEditing:textField];
- };
- return false;
- }
-
- return YES;
- }
- #pragma mark- autocomplete //自动完成填空内容需要实现此协议
- -(nullable NSArray*)sync_loadCadidate:(nonnull NSString*)str
- {
-
- NSMutableArray* ret = [NSMutableArray new];
- [ret addObject:@"autocomplete"];
- [ret addObject:@"datasource"];
- [ret addObject:@"loadCadidate"];
- [ret addObject:@"does"];
- [ret addObject:@"not"];
- [ret addObject:@"impl"];
- return ret;
- }
- #pragma mark- img changed
- // image 改变时执行
- - (void) imgIsChanged:(NSString *)url_down url_up:(NSString *)url_up indexPath: (NSIndexPath *) indexPath index:(int)index url_index:(NSString* )url_index{
- // DebugLog(@"Sender is = %@", url);
-
-
-
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- int refresh = [[item_json valueForKey:@"refresh"] intValue];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSString* subid=[item_json valueForKey:@"subid"];
-
-
- // NSArray* imgs=[RAUtils string2arr:url_up separator:@","];
-
-
- // imgs[index];
- item_json[ [NSString stringWithFormat:@"img_url_%d",index]]=url_down;
- item_json[@"avalue"]=url_up;
- item_json[[NSString stringWithFormat:@"img_url_aname_%d",index]]=url_index;
- [item_json setValue:@"true" forKey:@"dirty"];
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
-
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
- self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
-
- // NSRange range = NSMakeRange(indexPath.section, 1);
- // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
-
-
- if(refresh==1)
- {
- [self refresh:refresh_trigger];
- }
- }
- #pragma mark- switch changed
- - (void) switchIsChanged:(UISwitch *)paramSender{
-
-
- // [self.switchlock lock];
- // DebugLog(@"switch lock");
-
-
- UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview;
- NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
- if(indexPath==nil)
- {
- [paramSender setOn:!paramSender.isOn];
- return ;
- }
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- int refresh = [[item_json valueForKey:@"refresh"] intValue];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSString* subid=[item_json valueForKey:@"subid"];
- NSString* check=@"false";
- if([paramSender isOn])
- check=@"true";
- [item_json setValue:@"true" forKey:@"dirty"];
- [item_json setValue:check forKey:@"value"];
-
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
-
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
- self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
-
- NSRange range = NSMakeRange(indexPath.section, 1);
- NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
-
-
- if(refresh==1)
- {
- [self refresh:refresh_trigger];
- }
- DebugLog(@"switch unlock");
- // [self.switchlock unlock];
- }
- -(NSMutableDictionary*) fill_switch_subitem:(NSMutableDictionary *) switch_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step
- {
- NSString* value = [switch_item valueForKey:@"value"];
- NSMutableDictionary* boolitem=nil;
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- {
- boolitem =[[switch_item objectForKey:@"true"] mutableCopy];
-
- }
- else
- {
- boolitem =[[switch_item objectForKey:@"false"] mutableCopy];
-
- }
- subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
-
-
-
- // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
- NSString* mapto = [modify_item valueForKey:@"name"];
- if(mapto.length==0)
- continue;
- NSString* valuefrom= [mapping valueForKey:[modify_item valueForKey:@"name"]];
- if(valuefrom==nil)
- continue;
- NSString* valuestr= [source valueForKey:valuefrom];
-
- if(TRUE)
- {
-
- if(valuestr.length>0)
- [modify_item setValue:valuestr forKey:@"value"];
- else
- [modify_item setValue:@"" forKey:@"value"];
-
- [modify_item setValue:@"true" forKey:@"dirty"];
- [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]];
- }
- }
-
- [boolitem setObject:subjson forKey:@"sub_item"];
-
- if([value isEqualToString:@"true"])
-
- [switch_item setObject:boolitem forKey:@"true"];
-
- else
- [switch_item setObject:boolitem forKey:@"false"];
-
- }
- return switch_item;
-
- }
- -(NSMutableDictionary*) fill_enum_subitem:(NSMutableDictionary *) enum_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step
- {
- NSMutableDictionary* cadedatejson = [[enum_item objectForKey:@"cadedate"] mutableCopy];
- int count = [[cadedatejson valueForKey:@"count"]intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* val_json = [[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",i]] mutableCopy];
- int check = [[val_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- NSMutableDictionary* subjson=[[val_json objectForKey:@"sub_item"] mutableCopy];
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
- // NSString* subid=[modify_item valueForKey:@"subid"];
- //
- //
- // NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
-
- NSString* control_type = [modify_item valueForKey:@"control"];
- if([control_type isEqualToString:@"switch"])
- modify_item= [self fill_switch_subitem:modify_item subid:nil source:source mapping:mapping ];
- else if([control_type isEqualToString:@"enum"])
- {
- modify_item= [self fill_enum_subitem:modify_item subid:nil source:source mapping:mapping ];
-
- }
- else
- {
- NSString* mapto = [modify_item valueForKey:@"name"];
- if(mapto.length==0)
- continue;
- NSString* valuefrom= [mapping valueForKey:[modify_item valueForKey:@"name"]];
- if(valuefrom==nil)
- continue;
- NSString* valuestr= [source valueForKey:valuefrom];
-
- if(true)
- {
- if(valuestr.length>0)
- [modify_item setValue:valuestr forKey:@"value"];
- else
- [modify_item setValue:@"" forKey:@"value"];
- //[modify_item setValue:valuestr forKey:@"value"];
-
- // [modify_item setValue:@"true" forKey:@"dirty"];
-
- }
- }
-
- [modify_item setValue:@"true" forKey:@"dirty"];
- [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]];
- // [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
-
-
- // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
-
-
- }
- [val_json setObject:subjson forKey:@"sub_item"];
- }
-
-
- }
- [cadedatejson setObject:val_json forKey:[NSString stringWithFormat:@"val_%d",i]];
-
- }
- [enum_item setObject:cadedatejson forKey:@"cadedate"];
- return enum_item;
-
- }
- -(NSMutableDictionary*) switch_subitem_changed:(NSMutableDictionary *) switch_item subid:(NSArray*) subid value:(NSMutableDictionary*)valuejson step:(int) step
- {
- int index = [(NSString*)subid[step] intValue];
- NSString* value = [switch_item valueForKey:@"value"];
-
- NSMutableDictionary* boolitem=nil;
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- {
- boolitem =[[switch_item objectForKey:@"true"] mutableCopy];
-
- }
- else
- {
- boolitem =[[switch_item objectForKey:@"false"] mutableCopy];
-
- }
- subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
-
-
-
- if(subjson!=nil)
- {
- NSMutableDictionary * itemjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy];
- if(step==subid.count-1)
- {
- itemjson =valuejson;
-
- }
- [subjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]];
- [boolitem setObject:subjson forKey:@"sub_item"];
-
- if([value isEqualToString:@"true"])
-
- [switch_item setObject:boolitem forKey:@"true"];
-
- else
- [switch_item setObject:boolitem forKey:@"false"];
-
-
- return switch_item;
- }
- return nil;
-
- }
- //#pragma mark Request Editor
- //-(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
- //{
- // return [RANetwork request_Editor:request_url params:params];
- //}
- #pragma mark - Responding to keyboard events
- - (void)keyboardWillChangeFrame:(NSNotification *)notification {
- DebugLog(@"keyboardWillChangeFrame");
-
- // 使用tableContainer计算frame 保证屏幕旋转后table height正确
- CGRect table_origin_screen_frame = [self.tableContainer convertRect:self.tableContainer.bounds toView:self.view.window];
-
- // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
- // duration *= 0.0;
- CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
- CGFloat end_y = end.origin.y;
-
- CGRect screenframe=[[UIScreen mainScreen] bounds];
- self.autocompleteView.frame= CGRectMake(screenframe.origin.x, screenframe.origin.y, screenframe.size.width, end_y);
-
- NSIndexPath *indexPath = [self.editorTable indexPathForCell:self.editingcell];
-
- CGRect table_frame = self.editorTable.frame;
- // table底部距离键盘顶部偏移
- CGFloat offset = CGRectGetMaxY(table_origin_screen_frame) - end_y;
- if (offset > 0) {
-
- // table -> top > offset: table.y = -offset
- // 事实上top:topLayoutGuide
- CGFloat topAvailableHeight = (CGRectGetMinY(table_origin_screen_frame) - self.topLayoutGuide.length);
- if (topAvailableHeight > 0) {
- if (topAvailableHeight > offset) {
- table_frame.origin.y = -offset;
- } else {
- // 向上移动到topLayoutGuide,不足部分通过缩减高度到达keyboard顶部
- table_frame.origin.y = -topAvailableHeight;
- table_frame.size.height = (end_y - self.topLayoutGuide.length);
- }
- } else {
- // contentInset = (top = 64, left = 0, bottom = 0, right = 0),topAvailableHeight = -64
- table_frame.size.height = table_origin_screen_frame.size.height - offset;
- }
-
- // table_frame.size.height = CGRectGetHeight(table_origin_screen_frame) - (CGRectGetMaxY(table_origin_screen_frame) - end_y);
- } else {
- // table_frame.size.height = CGRectGetHeight(table_origin_screen_frame);
- table_frame = self.tableContainer.bounds;
- }
- self.editorTable.frame = table_frame;
-
- CGRect cell_screen_frame = [self.editingcell convertRect:self.editingcell.bounds toView:self.view.window];
- if (CGRectGetMaxY(cell_screen_frame) > end_y) {
- // Cell 被键盘遮挡后才滚动
- [self.editorTable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:NO];
- }
- // ===============================================
- if (end_y >= [UIScreen mainScreen].bounds.size.height) {
- self.keyboard_show = NO;
- } else {
- self.keyboard_show = YES;
- }
-
- }
- //static float table_origin_h = 0;
- - (void)keyboardWillShow:(NSNotification *)notification {
- DebugLog(@"keyboardWillShow");
- //
- // if(self.keyboard_show)
- // return;
- //
- // self.keyboard_show=true;
- // /*
- // Reduce the size of the text view so that it's not obscured by the keyboard.
- // Animate the resize so that it's in sync with the appearance of the keyboard.
- // */
- //
- // NSDictionary *userInfo = [notification userInfo];
- //
- // // Get the origin of the keyboard when it's displayed.
- // NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
- //
- // // 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.
- // // CGRect keyboardRect = [aValue CGRectValue];
- // CGSize keyboardSize = [aValue CGRectValue].size;
- // DebugLog(@"keyboard height:%f",keyboardSize.height);
- // // Get the duration of the animation.
- // NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
- // NSTimeInterval animationDuration;
- // [animationDurationValue getValue:&animationDuration];
- //
- //
- // // if(self.keyboard_h==0)
- // // {
- // self.keyboard_h =keyboardSize.height;
- // CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:self.editingcell];
- // CGRect rect_screen = [ UIScreen mainScreen ].bounds;
- //
- // // int vpos =self.view.frame.origin.y+self.view.frame.size.height;
- // // int loginpos = self.editingcell.frame.origin.y+self.editingcell.frame.size.height;
- // //
- // int cellpos = cellrect_screen.origin.y+cellrect_screen.size.height;
- // // screen.size.height-keyboardSize.height-(cellpos_screen.origin.x+cellpos_screen.size.height);
- // 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);
- // if(self.ioffset>0)
- // {
- // // self.resize = true;
- //
- //
- // CGPoint contentOffsetPoint = self.editorTable.contentOffset;
- //
- //
- // contentOffsetPoint.y+=self.ioffset;
- //
- // self.editorTable.contentOffset=contentOffsetPoint;
- //
- //
- // // NSTimeInterval animationDuration = 0.30f;
- // // CGRect frame = self.view.frame;
- // // frame.origin.y -=self.ioffset;//view的Y轴上移
- // // frame.size.height +=self.ioffset; //View的高度增加
- // // self.view.frame = frame;
- // // [UIView beginAnimations:@"ResizeView" context:nil];
- // // [UIView setAnimationDuration:animationDuration];
- // // self.view.frame = frame;
- // // [UIView commitAnimations];//设置调整界面的动画效果
- // }
- //
- // table_origin_h = self.editorTable.frame.size.height;
- // self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, self.editorTable.frame.size.height-self.keyboard_h);
- //
- // // CGSize tablecontent =self.editorTable.contentSize;
- // // tablecontent.height=tablecontent.height+self.keyboard_h;
- // // self.editorTable.contentSize=tablecontent;
- // // }
- // // Animate the resize of the text view's frame in sync with the keyboard's appearance.
- // // [self moveInputBarWithKeyboardHeight:keyboardRect.size.height withDuration:animationDuration];
- }
- - (void)keyboardWillHide:(NSNotification *)notification {
- DebugLog(@"keyboardWillHide");
- // self.keyboard_show=false;
- // NSDictionary* userInfo = [notification userInfo];
- //
- // /*
- // Restore the size of the text view (fill self's view).
- // Animate the resize so that it's in sync with the disappearance of the keyboard.
- // */
- // NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
- // NSTimeInterval animationDuration;
- // [animationDurationValue getValue:&animationDuration];
- // CGSize tablecontent =self.editorTable.contentSize;
- // tablecontent.height=tablecontent.height-self.keyboard_h;
- // // self.editorTable.contentSize=tablecontent;
- //
- // self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, table_origin_h);
- //
- // self.keyboard_h= 0;
- // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
- //
- //
- // // if(self.resize)
- // // {
- // // NSTimeInterval animationDuration = 0.30f;
- // // CGRect frame = self.view.frame;
- // // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
- // // // { //还原界面
- // // // moveY = prewMoveY;
- // // frame.origin.y +=self.ioffset;
- // // frame.size. height -=self.ioffset;
- // // self.view.frame = frame;
- // // // }
- // // //self.view移回原位置
- // // [UIView beginAnimations:@"ResizeView" context:nil];
- // // [UIView setAnimationDuration:animationDuration];
- // // self.view.frame = frame;
- // // [UIView commitAnimations];
- // // //[textField resignFirstResponder];
- // // self.ioffset=0;
- // // }
- //
- //
- // // [self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration];
- }
- #pragma mark - RageCell Delegate
- - (void)commonEditorRangeCell:(CommonEditorRangeCell *)cell didChangeMinValue:(NSString *)minValue maxValue:(NSString *)maxValue atIndexPath:(NSIndexPath *)indexPath{
- if (indexPath == nil) {
- if (cell != nil) {
- indexPath = [self.editorTable indexPathForCell:cell];
- } else {
- return;
- }
-
- }
-
- if (indexPath == nil) {
- return;
- }
- NSString *section_key = [NSString stringWithFormat:@"section_%ld",indexPath.section];
- NSString *item_key = [NSString stringWithFormat:@"item_%ld",indexPath.row];
-
- NSMutableDictionary *section_json = [[self.content_data_download objectForKey:section_key] mutableCopy];
- NSMutableDictionary *item_json = [((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- [item_json setObject:minValue forKey:@"min_value"];
- [item_json setObject:maxValue forKey:@"max_value"];
-
- [section_json setObject:item_json forKey:item_key];
- [self.content_data_download setObject:section_json forKey:section_key];
- self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
-
- }
- #pragma mark - WebCell Delegate
- - (void)commonEditorWebCell:(CommonEditorWebCell *)cell didChangeContentHeight:(CGFloat)contentHeight {
-
- // return;
-
- NSIndexPath *indexPath = [self.editorTable indexPathForCell:cell];
- if (indexPath == nil) {
- return;
- }
-
-
- NSMutableDictionary* section_json=nil;
-
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- NSString* subid=[item_json valueForKey:@"subid"];
-
- NSString* control = [item_json valueForKey:@"control"];
- id height_obj = [item_json objectForKey:@"height"];
-
- // NSLog(@"indexPath: %@ origin height: %@ currentHeight: %f",indexPath,height_obj,contentHeight);
-
- if ([control isEqualToString:@"webview"] && [height_obj floatValue] != contentHeight)
- {
- [item_json setValue:@(contentHeight) forKey:@"height"];
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- }
- // else
- // {
- // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- // int section = [(NSString*)idarr[0] intValue];
- // int item=[(NSString*)idarr[1] intValue];
- //
- //
- // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- //
- // NSString* control_type= [olditem valueForKey:@"control"];
- // NSMutableDictionary* new_item=nil;
- //// [item_json setValue:@"true" forKey:@"dirty"];
- // if([control_type isEqualToString:@"enum"])
- // new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- // else if([control_type isEqualToString:@"switch"])
- // new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- //
- // [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
- //
- //
- // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- // }
-
- // // 更新数据
- // [item_json setObject:@(contentHeight) forKey:@"height"];
- //
- // NSMutableDictionary *section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
- // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
- //
- // // 调用 tableView 的 beginUpdates 和 endUpdates,更新 cell 的高度
- // [self.editorTable beginUpdates];
- // [self.editorTable endUpdates];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- // UI更新代码
- [self.editorTable reloadData];
- //[self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
- });
-
- }
-
- }
- #pragma mark - Banner Delegate
- - (void)commonEditorBannerCell:(CommonEditorBannerCell *)cell didClickItemAtIndexPath:(NSIndexPath *)indexPath {
- if ([[[cell content] objectForKey:@"count"] integerValue] == 0) {
- return;
- }
- ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
- preVC.content = [cell content];
- [preVC setOffset:indexPath.row];
- if (self.navigationController) {
- [self.navigationController pushViewController:preVC animated:YES];
- } else {
- [self presentViewController:preVC animated:true completion:nil];
- }
- }
- @end
|