CommonEditorViewController.m 282 KB

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