CommonEditorViewController.m 309 KB

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