CommonEditorViewController.m 314 KB

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