CommonEditorViewControlleriPad.m 286 KB

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