CommonEditorViewController.m 307 KB

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