CommonEditorViewController.m 269 KB

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