CommonEditorViewController.m 272 KB

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