CommonEditorViewController.m 267 KB

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