CommonEditorViewController.m 306 KB

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