CommonEditorViewController.m 314 KB

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