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