CommonEditorViewController.m 301 KB

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