CommonEditorViewController.m 289 KB

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