CommonEditorViewController.m 289 KB

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