CommonEditorViewController.m 303 KB

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