CommonEditorViewController.m 273 KB

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