| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383 |
- //
- // CommonEditorViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 14-7-16.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "CommonEditorViewController.h"
- #import "CommonEditorCellEdit.h"
- #import "iSalesNetwork.h"
- #import "CommonEditorCellEnum.h"
- #import "CommonEditorCellSwitch.h"
- #import "CommonEditorCellModel.h"
- #import "CommonEditorCellAction.h"
- #import "EnumSelectViewController.h"
- #import "DatePickerViewController.h"
- #import "SignatureViewController.h"
- #import "CommonEditorCellSignature.h"
- #import "CommonEditorCellLabel.h"
- #import "AddressEditorViewController.h"
- #import "CreditCardEditorViewController.h"
- #import "MonthPickerViewController.h"
- #import "ContactListViewController.h"
- #import "CommonEditorCellMAction.h"
- #import "CommonEditorCellTextView.h"
- #import "RAUtils.h"
- #import "CommonEditorCellImg.h"
- #import "AFHTTPSessionManager.h"
- #import "CustomIOSAlertView.h"
- #import "DefaultAppearance.h"
- #import "DefaultTableHeaderView.h"
- #define INTNUMBERS @"0123456789\n"
- #define NUMBERS @"0123456789.\n"
- #import "OLDataProvider.h"
- #import <objc/objc.h>
- @interface subitem_data ()
- @end
- @implementation subitem_data
- @end
- @interface CommonEditorViewController ()
- @property (nonatomic,copy) NSString *urgency_timer_name;
- @property (nonatomic,assign) int level;///<CommonEditor窗口层级
- @end
- @implementation CommonEditorViewController
- - (void)dealloc {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
- [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
- }
- - (NSString *)class_name {
- if (!_class_name) {
- const char *class_name_ch = object_getClassName([self class]);
- _class_name = [NSString stringWithUTF8String:class_name_ch];
- }
- return _class_name;
- }
- - (NSString *)urgency_timer_name {
- if (!_urgency_timer_name) {
- _urgency_timer_name = [NSString stringWithFormat:@"%@_urgency_timer",self.class_name];
- }
- return _urgency_timer_name;
- }
- - (int)level {
- if (_level == -1) {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- id count = [appDelegate.urgencyDic objectForKey:@"count"];
-
- _level = count == nil ? 0 : [count integerValue];
- }
- return _level;
- }
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void) request_fill
- {
-
- }
- -(void) viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self start_urgency_timer];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
-
- // 键盘高度变化通知,ios5.0新增的
- #ifdef __IPHONE_5_0
- float version = [[[UIDevice currentDevice] systemVersion] floatValue];
- if (version >= 5.0) {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
- }
- #endif
-
- }
- -(void) viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [self cancel_urgency_timer];
- }
- -(void)manually_refresh
- {
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
-
- if ([self respondsToSelector:@selector(reload_data)])
- [self performSelector:@selector(reload_data) withObject:nil afterDelay:1];
- // DebugLog(@"refresh!!!!!!!!");
-
- }
- -(void)reload_data
- {
-
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-
- [reF endRefreshing];
-
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- [self refresh:nil];
- }
- - (void)start_urgency_timer {
-
- if (!self.editable) {
- return;
- }
-
- __weak typeof(self) weakSelf = self;
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
- [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
-
- [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
-
- NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
- // DebugLog(@"timer start....");
-
- [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
-
- [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
-
-
- if ([weakSelf.class_name isEqualToString:@"CustomerEditViewController"]) {
- // CustomerEditViewController
- __block NSString *contact_id = @"";
-
- [weakSelf.content_data_download enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
-
- // section_0
- if ([key isEqualToString:@"section_0"]) {
- NSDictionary *section_0 = (NSDictionary *)obj;
- [section_0 enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
-
- // Contact ID
- if ([obj isKindOfClass:[NSDictionary class]]) {
- if ([[obj objectForKey:@"aname"] isEqualToString:@"Contact ID"]) {
- contact_id = [obj objectForKey:@"value"];
- }
-
- }
-
- }];
- }
- }];
- [urgencyDic setValue:contact_id forKey:@"contact_id"];
-
-
- } else if ([weakSelf.class_name isEqualToString:@"CreateOrderViewController"]) {
- // CreateOrderViewController
-
- [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
- [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
-
- [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
-
- } else if ([weakSelf.class_name isEqualToString:@"AddressEditorViewController"]) {
- // AddressEditorViewController
-
- }
-
- [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
- [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
-
- }];
- }
- - (void)cancel_urgency_timer {
- [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
-
- // self.switchlock = [[NSLock alloc] init];
-
-
- // [self.editorTable setExclusiveTouch:false];
-
- self.editable = NO;
-
- if(self.loading_msg==nil)
- self.loading_msg = @"Please Wait";
- if(self.loading_title==nil)
- self.loading_title = @"Loading...";
-
- UIRefreshControl *ref = [[UIRefreshControl alloc]init];
- ref.tag = 200 ;
- ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- // ref.hidden = true;
- [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
-
- if(!self.disable_dropdown_refresh)
- [self.editorTable addSubview:ref];
-
- self.level = -1;
-
- if (!self.changed_data) {
- self.changed_data = [[NSMutableDictionary alloc] init];
- }
-
- // UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
- // // closeButton.title = @"Close";
- //
- // self.navigationItem.leftBarButtonItem = closeButton;
-
- if(self.url_type==URL_REMOTE)
- {
-
- UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* editor_json = [iSalesNetwork request_Editor:self.request_url params:self.params];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- self.content_data_download = [editor_json mutableCopy];
-
- self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
-
- // self.content_data = [editor_json mutableCopy];
- // self.content_data = [self translate_json:editor_json];
-
- // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
-
- [self download_success];
-
- [self.editorTable reloadData];
-
- // NSString * ttt=[self.content_data valueForKey:@"title"] ;
-
- self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
- }
-
-
- });
- });
- }
- else if(self.url_type== URL_LOCAL )
- {
-
- NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
- NSError *error=nil;
- self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
- self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
-
- self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- [self.editorTable reloadData];
-
- // NSString * ttt=[self.content_data valueForKey:@"title"] ;
-
- // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- }
- else
- {
-
- self.content_data_control=[self translate_json:self.content_data_download changed: self.changed_data];
- [self.editorTable reloadData];
-
- // NSString * ttt=[self.content_data valueForKey:@"title"] ;
-
- self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- }
-
-
- self.requried = [[NSMutableDictionary alloc] init];
-
- self.cancommit = true;
-
-
- }
- -(NSMutableDictionary*) check_cancommit :(bool) alert
- {
- [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
- // [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)];
-
-
- [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
-
- self.first_miss_pos = nil;
-
- self.cancommit=true;
- NSMutableArray* fields=[[NSMutableArray alloc] init];
- NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
- // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
- int section_count=self.content_data_control.count;//[[self.content_data_download valueForKey:@"section_count"] intValue];
-
-
- // NSString* aaa = [RAUtils dict2string:self.content_data_control];
- for(int i=0;i<section_count;i++)
- {
- DebugLog(@"debug...section:%d",i);
- NSMutableArray * sectionjson = [self.content_data_control[i] mutableCopy];//[[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = sectionjson.count;//[[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[sectionjson[j] mutableCopy];//[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- NSString* key = [itemjson valueForKey:@"name"];
- if(key==nil || key.length==0)
- continue;
- if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
- {
- NSString* single_select = [itemjson valueForKey:@"single_select"];
- if([single_select isEqualToString:@"true"])
- {
- NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- bool setvalue = false;
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
- [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
-
- setvalue=true;
- break;
- }
- }
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
-
- }
- }
- else //multiple select
- {
- NSMutableArray* checked = [[NSMutableArray alloc] init];
- NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
-
- // [checked addObject:[NSNumber numberWithInt:[[valjson valueForKey:@"value_id"] intValue]]];
- [checked addObject:[NSString stringWithFormat:@"%@",[valjson valueForKey:@"value_id"]]];
-
-
- }
- }
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"]&&checked.count==0)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- else
- {
- NSString * string = [checked componentsJoinedByString:@","];
- [upparams setValue:string forKey:[itemjson valueForKey:@"name"]];
- }
- }
- /*
- upparams setValue:itemjson forKey:<#(NSString *)#>
-
- */
- }else
- if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
-
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- NSString* valuestr = [itemjson valueForKey:@"value"];
- [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
- {
- NSString* valuestr = [itemjson valueForKey:@"value"];
- [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
-
- NSString* value = [itemjson valueForKey:@"value"];
- NSMutableDictionary* boolitem=nil;
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- {
- boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
-
- }
- else
- {
- boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
-
- }
- subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
- if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
- [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
- else
- {
- if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[modify_item valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- }
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"img"])
- {
- if([itemjson valueForKey:@"avalue"]!=nil && ![[itemjson valueForKey:@"avalue"]isEqualToString:@""])
- [upparams setValue:[itemjson valueForKey:@"avalue"] forKey:[itemjson valueForKey:@"name"]];
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"edit"])
- {
- int min_length = [[itemjson valueForKey:@"min_length"] intValue];
- NSString* check_len_val =itemjson[@"value"];
- if( check_len_val.length<min_length)
- {
- self.cancommit = false;
-
-
-
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is too short",fields.count+1,itemjson[@"aname"]];
-
-
- if(check_len_val.length==0 &&[[itemjson valueForKey:@"required"] isEqualToString: @"true"])
- mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- else if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""] )
- [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
-
- else
- {
- if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
- [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- // subitem_data * data=[self subitem_param:itemjson addto:upparams alert:alert];
- // upparams= data.params;
- // fields=[[fields arrayByAddingObjectsFromArray:data.missingfields] mutableCopy];
- }
- }
- if(self.cancommit==false && alert)
- {
- NSString* missfields=[fields componentsJoinedByString:@"\n"];
- NSString* msg = [NSString stringWithFormat:@"%@",missfields];
-
- CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
-
-
-
-
- // Add some custom content to the alert view
- [alertView setContainerView:[self createDemoView:msg]];
-
- // Modify the parameters
-
-
-
- [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"OK", nil]];
- //[alertView setDelegate:self];
-
- // You may use a Block, rather than a delegate.
- [alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
- // DebugLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, (int)[alertView tag]);
- [alertView close];
- }];
-
- // [alertView setUseMotionEffects:true];
-
- // And launch the dialog
-
- [alertView sizeToFit];
- [alertView show];
-
- // [RAUtils alert_view:msg title:@"Please complete missing fields:"];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- [self.editorTable reloadData];
-
- [self.editorTable scrollToRowAtIndexPath:self.first_miss_pos atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
- return upparams;
- }
- else
- {
- self.cancommit=true;
- //[self.editorTable reloadData];
- }
-
- return upparams;
-
- }
- - (UIView *)createDemoView:(NSString*) msg
- {
- UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
-
- // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
- // [imageView setImage:[UIImage imageNamed:@"demo"]];
-
- UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
- titleLabel.font = [UIFont boldSystemFontOfSize:20];
- titleLabel.text=@"Please complete missing fields:";
- titleLabel.numberOfLines = 0;
- titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
- // titleLabel.textAlignment = NSTextAlignmentRight;
- titleLabel.textAlignment = NSTextAlignmentCenter;
- CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
- CGSize sizetitle = [@"Please complete missing fields:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- //[titleLabel sizeToFit];
- // titleLabel.center.x = demoView.center.x;
- titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
- [demoView addSubview:titleLabel];
-
- UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
- lineLabel.font = [UIFont boldSystemFontOfSize:17];
- lineLabel.text=msg;
- lineLabel.numberOfLines = 0;
- lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
-
- CGSize sizemsg = [msg sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
- //[lineLabel sizeToFit];
-
- [demoView addSubview:lineLabel];
- demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
- return demoView;
- }
- //- (void)willPresentAlertView:(UIAlertView *)alertView{
- //
- //
- // alertView set
- // for( UIView * view in alertView.subviews )
- //
- // { if( [view isKindOfClass:[UILabel class]] )
- //
- // { UILabel* label = (UILabel*) view;
- //
- // label.textAlignment = NSTextAlignmentLeft; }
- //
- // }
- //
- //}
- //-(bool) action_btn_passed_check:(NSDictionary* ) data;
- //{
- // if(data == nil)
- // return false;
- // int section_count=[[data valueForKey:@"section_count"] intValue];
- //
- // for(int sc=0;sc<section_count)
- //
- //}
- //-(NSString*) get_param:(NSString*)param_name content_item:(NSDictionary*)itemjson
- //{
- //
- // NSString * item_name = [itemjson valueForKey:@"name"];
- // NSDictionary* cadejson= [itemjson objectForKey:@"cadedate"];
- // int cade_count = [[cadejson valueForKey:@"count"] intValue];
- // if([item_name isEqualToString:param_name] )
- // {
- // NSString* param_val=nil;
- //
- // bool single_select =[[itemjson valueForKey:@"single_select"] boolValue];
- //
- // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
- //
- //
- // for(int cc=0;cc<cade_count;cc++)
- // {
- // NSDictionary * valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
- // if([[valjson valueForKey:@"check"] boolValue])
- // {
- // NSString * valueid=[valjson valueForKey:@"value_id"];
- // if(valueid!=nil)
- // [arr_val addObject: valueid];
- // if(single_select)
- // break;
- // }
- //
- // }
- //
- // param_val = [arr_val componentsJoinedByString:@","];
- //
- // return param_val;
- // //[self.params setValue:param_val forKey:param_name];
- //
- // }
- // else
- // {
- // for(int cc=0;cc<cade_count;cc++)
- // {
- // NSDictionary * valjson=[itemjson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
- // NSDictionary* subitems=[valjson objectForKey:@"sub_item"];
- // if(subitems==nil)
- // continue;
- // int subcount=[[subitems valueForKey:@"count"] intValue];
- // for(int sc=0;sc<subcount;sc++)
- // {
- // NSDictionary* subitem = [subitems objectForKey:[NSString stringWithFormat:@"item_%d",sc]];
- // NSString* subval=[self get_param:param_name content_item:subitem];
- // if(subval!=nil)
- // return subval;
- // }
- //
- //
- // }
- //
- //
- // }
- // return nil;
- //
- //}
- -(void) download_success
- {
- // 用于处理不同child,在成功去的数据后,需要附加的操作。
-
-
- }
- -(NSDictionary*) get_refresh_param
- {
- NSMutableDictionary* params= [[NSMutableDictionary alloc]init];
-
- NSDictionary * param_names = [self.content_data_download objectForKey:@"up_params"];
-
- int param_count=[[param_names valueForKey:@"count"] intValue];
-
- for(int pc=0;pc<param_count;pc++)
- {
-
- NSString* param_name = [param_names valueForKey:[NSString stringWithFormat:@"val_%d",pc]];
- NSString* param_val = [self getValue:param_name];
- [self.params setValue:param_val forKey:param_name];
-
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- //
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- //
- // NSString * control_type = [itemjson valueForKey:@"control"];
- // // NSString * item_name = [itemjson valueForKey:@"name"];
- // if([control_type isEqualToString:@"enum"])
- // {
- // NSString* subval= [self get_param:param_name content_item:itemjson];
- // if(subval!=nil)
- // {
- // [self.params setValue:subval forKey:param_name];
- // break;
- // }
- // // if([item_name isEqualToString:param_name] )
- // // {
- // // NSString* param_val=nil;
- // //
- // // bool single_select =[[itemjson valueForKey:@"single_select"] boolValue];
- // //
- // // int cade_count = [[itemjson valueForKey:@"count"] intValue];
- // //
- // // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
- // //
- // //
- // // for(int cc=0;cc<cade_count;cc++)
- // // {
- // // NSDictionary * valjson=[itemjson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
- // // if([[valjson valueForKey:@"check"] boolValue])
- // // {
- // // [arr_val addObject: [valjson valueForKey:@"value_id"]];
- // // if(single_select)
- // // break;
- // // }
- // //
- // // }
- // //
- // // param_val = [arr_val componentsJoinedByString:@","];
- // //
- // // [self.params setValue:param_val forKey:param_name];
- // // break;
- // // }
- // // else
- // // {
- // // NSString* subval= [self get_param:param_name content_item:itemjson];
- // // if(subval!=nil)
- // // {
- // // [self.params setValue:subval forKey:param_name];
- // // break;
- // // }
- // // }
- // }
- // }
- // }
-
-
- }
- return params;
-
- // NSString* param_name=[item_json valueForKey:@"name"];
- // NSString* param_val=nil;
- //
- // bool single_select =[[item_json valueForKey:@"single_select"] boolValue];
- //
- // int cade_count = [[value valueForKey:@"count"] intValue];
- //
- // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
- //
- //
- // for(int cc=0;cc<cade_count;cc++)
- // {
- // NSDictionary * valjson=[value objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
- // if([[valjson valueForKey:@"check"] boolValue])
- // {
- // [arr_val addObject: [valjson valueForKey:@"value_id"]];
- // if(single_select)
- // break;
- // }
- //
- // }
- //
- // param_val = [arr_val componentsJoinedByString:@","];
- //
- // [self.changed_data setObject:param_val forKey:param_name];
- }
- -(NSMutableDictionary*) CopyDirty:(NSDictionary*) dirty to:(NSMutableDictionary*) to
- {
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
-
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"dirty"] isEqualToString:@"true"])
- {
- [to_sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [to setObject:to_sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
- return to;
- }
- -(void) refresh:(NSString*) trigger;
- {
-
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
- if(self.url_type==URL_REMOTE)
- {
-
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
-
- self.params[@"refresh_trigger"]=trigger;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
-
-
- NSDictionary* refresh_params=[self get_refresh_param];
-
- NSArray* changed_key=[refresh_params allKeys];
- for(int i=0;i<changed_key.count;i++)
- {
- NSString* obj_str=[NSString stringWithFormat:@"%@",[refresh_params valueForKey:(NSString*)changed_key[i]]];
- [self.params setObject:obj_str forKey:(NSString*)changed_key[i]];
- }
-
- NSDictionary* editor_json = [iSalesNetwork request_Editor:self.request_url params:self.params];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- self.content_data_download = [self CopyDirty:self.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
-
- self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
-
-
- [self download_success];
- [self.editorTable reloadData];
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
- }
-
-
-
-
- });
- });
- }
- else
- {
-
- // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
- NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
- NSError *error=nil;
- self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
- [self request_fill];
-
- self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
- [self.editorTable reloadData];
-
- // NSString * ttt=[self.content_data valueForKey:@"title"] ;
-
- // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- }
- }
- -(subitem_data*) subitem_param:(NSDictionary*) itemjson addto:(NSMutableDictionary*) upparam alert:(bool)alert
- {
-
- subitem_data * data = [[subitem_data alloc] init];
-
- NSMutableArray * fields = [[NSMutableArray alloc]init];
-
- NSString * control_type = [itemjson valueForKey:@"control"];
- bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
- if([control_type isEqual:@"enum"] && single_select)
- {
- NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
-
- int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
-
- for(int k=0;k<cade_count;k++)
- {
- NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
- int check=[[valjson valueForKey:@"check"] intValue];
-
- NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
- bool active =[[valjson valueForKey:@"active"] boolValue];
- if(check==1 && subjson!=nil && !active)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
-
- NSString* required = [addjson valueForKey:@"required"];
- NSString* key=[addjson valueForKey:@"name"];
- if(key==nil || key.length==0)
- continue;
-
- if([[addjson valueForKey:@"control"] isEqualToString:@"enum" ])
- {
- NSString* single_select = [addjson valueForKey:@"single_select"];
- if([single_select isEqualToString:@"true"])
- {
- NSDictionary* cadejson=[addjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- bool setvalue = false;
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
- [upparam setValue:[valjson valueForKey:@"value_id"] forKey:[addjson valueForKey:@"name"]];
- setvalue=true;
- break;
- }
- }
- if([[addjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
- {
- self.cancommit = false;
-
-
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,addjson[@"aname"]];
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- else
- {
- //not support multi select for now;
- }
- }
- else if([[addjson valueForKey:@"control"] isEqualToString:@"action" ])
- {
- NSMutableDictionary * action_data = [[addjson objectForKey:@"data"] mutableCopy];
- int section_count=[[action_data valueForKey:@"section_count"] intValue];
-
-
-
-
- if([required isEqualToString: @"true"] && action_data==nil)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,addjson[@"aname"]];
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
-
- for(int i=0;i<section_count;i++)
- {
-
-
- NSMutableDictionary * sectionjson = [[action_data objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- NSString* key = [itemjson valueForKey:@"name"];
-
- if(key==nil || key.length==0)
- continue;
-
- if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
- {
- NSString* single_select = [itemjson valueForKey:@"single_select"];
- if([single_select isEqualToString:@"true"])
- {
- NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- bool setvalue = false;
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
-
- [upparam setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
- setvalue=true;
- break;
- }
- }
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- else
- {
- //not support multi select for now;
- }
- /*
- upparams setValue:itemjson forKey:<#(NSString *)#>
-
- */
-
- }
- else
- {
- if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
- [upparam setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
-
- subitem_data * data1=[self subitem_param:itemjson addto:upparam alert:alert];
- upparam= data1.params;
- fields=[[fields arrayByAddingObjectsFromArray:data1.missingfields] mutableCopy];
- // upparam= [self subitem_param:itemjson addto:upparam ];
- }
-
- }
-
- }
- else
- {
-
- if([addjson valueForKey:@"value"]!=nil && ![[addjson valueForKey:@"value"]isEqualToString:@""])
- [upparam setValue:[addjson valueForKey:@"value"] forKey:key];
- else
- {
- if([[addjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%d. %@ is missing",fields.count+1,addjson[@"aname"]];
-
- [fields addObject:mfield];
-
- NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
-
- subitem_data * data2=[self subitem_param:addjson addto:upparam alert:alert];
- upparam= data2.params;
- fields=[[fields arrayByAddingObjectsFromArray:data2.missingfields] mutableCopy];
-
- //upparam=[self subitem_param:addjson addto:upparam];
- // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
- // item_count ++;
-
-
- // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
-
- }
-
- //break;
- }
-
-
-
- }
- }
-
- data.params = upparam;
- data.missingfields = fields;
- return data;
- }
- -(NSMutableArray*) add_subitem:(NSDictionary*) itemjson addto:(NSMutableArray*) sectionarr parent:(NSString*) parent
- {
- NSString * control_type = [itemjson valueForKey:@"control"];
- bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
- if([control_type isEqual:@"enum"] && single_select)
- {
- NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
-
- int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
-
- for(int k=0;k<cade_count;k++)
- {
- NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
- int check=[[valjson valueForKey:@"check"] intValue];
-
- NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
- bool active =[[valjson valueForKey:@"active"] boolValue];
- if(check==1 && subjson!=nil && !active)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
- NSString* subself=[NSString stringWithFormat:@"%@_%d_%d",parent,k,l ];
- [addjson setValue:subself forKey:@"subid"];
- [sectionarr addObject:addjson];
- [self add_subitem:addjson addto:sectionarr parent:subself];
- // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
- // item_count ++;
-
-
- // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
-
- }
- [valjson setValue:@"true" forKey:@"active"];
-
-
- [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
- //break;
- }
-
-
-
- }
- }
- else if([control_type isEqual:@"switch"])
- {
- NSString* value=[itemjson valueForKey:@"value"];
-
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- subjson=[[[itemjson objectForKey:@"true"] objectForKey:@"sub_item"] mutableCopy];// [ mutableCopy];
- else
- subjson=[[[itemjson objectForKey:@"false"] objectForKey:@"sub_item"] mutableCopy];
-
-
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
- NSString* subself=[NSString stringWithFormat:@"%@_%d",parent,l ];
- [addjson setValue:subself forKey:@"subid"];
- [sectionarr addObject:addjson];
- [self add_subitem:addjson addto:sectionarr parent:subself];
- // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
- // item_count ++;
-
-
- // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
-
- }
- // [valjson setValue:@"true" forKey:@"active"];
-
-
- // [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
- //break;
- }
-
- }
- return sectionarr;
- }
- -(NSMutableArray*) translate_json: (NSDictionary*) injson changed:(NSDictionary*) changed_value
- {
- if(injson == nil)
- return nil;
-
- NSMutableArray * retarray= [[NSMutableArray alloc]init];
-
- int section_count=[[injson valueForKey:@"section_count"] intValue];
-
- for(int i=0;i<section_count;i++)
- {
- NSMutableArray * sectionarr= [[NSMutableArray alloc]init];
-
- NSMutableDictionary * sectionjson = [[injson objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- [sectionarr addObject:itemjson];
- [self add_subitem:itemjson addto:sectionarr parent:[NSString stringWithFormat:@"%d_%d",i,j ]];
- // [itemjson setObject:cadedatejson forKey:@"cadedate"];
- // NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
-
- // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
-
- }
- // [sectionjson setValue:[NSString stringWithFormat:@"%d",item_count ] forKey:@"count"];
- // [retjson setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- [retarray addObject:sectionarr];
- }
- return retarray;
- // retjson setObject:sec forKey:<#(id<NSCopying>)#>
- // return nil;
- }
- /*
- -(NSMutableDictionary*) translate_json: (NSDictionary*) injson
- {
- if(injson == nil)
- return nil;
-
- NSMutableDictionary * retjson= [injson mutableCopy];
-
- int section_count=[[retjson valueForKey:@"section_count"] intValue];
-
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[retjson objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- NSString * control_type = [itemjson valueForKey:@"control"];
- bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
- if([control_type isEqual:@"enum"] && single_select)
- {
- NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
-
- int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
-
- for(int k=0;k<cade_count;k++)
- {
- NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
- int check=[[valjson valueForKey:@"check"] intValue];
-
- NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
- bool active =[[valjson valueForKey:@"active"] boolValue];
- if(check==1 && subjson!=nil && !active)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
- [addjson setValue:[NSString stringWithFormat:@"%d_%d_%d",i,j,k ] forKey:@"parent"];
- [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
- item_count ++;
-
-
- // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
-
- }
- [valjson setValue:@"true" forKey:@"active"];
-
-
- [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
- //break;
- }
- if(check==0 && subjson!=nil)
- {
- int total_remove=0;
- for(int r=0;r<item_count;r++)
- {
- NSMutableDictionary * removejson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",r ]] mutableCopy];
- if(removejson==nil)
- continue;
- if([[removejson valueForKey:@"parent"] isEqualToString: [NSString stringWithFormat:@"%d_%d_%d",i,j,k ]])
- {
- [sectionjson removeObjectForKey:[NSString stringWithFormat:@"item_%d",r ]];
- total_remove++;
- // item_count--;
- // r--;
- }
- else
- {
- [sectionjson removeObjectForKey:[NSString stringWithFormat:@"item_%d",r ]];
- [sectionjson setObject:removejson forKey:[NSString stringWithFormat:@"item_%d",r-total_remove ]];
- }
-
-
- }
- [valjson setValue:@"false" forKey:@"active"];
-
-
- [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
- item_count-=total_remove;
- // remove sub item
-
- //break;
- }
-
-
- }
- [itemjson setObject:cadedatejson forKey:@"cadedate"];
- // NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
- }
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
-
- }
- [sectionjson setValue:[NSString stringWithFormat:@"%d",item_count ] forKey:@"count"];
- [retjson setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
-
- }
- return retjson;
- // retjson setObject:sec forKey:<#(id<NSCopying>)#>
- return nil;
- }*/
- //- (void)onCloseClick:(UIButton *)sender {
- // [self.navigationController dismissViewControllerAnimated:true completion:^{
- // ;
- // }];
- //}
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void) prepareReturn:(NSMutableDictionary*) value
- {
-
- if(value==nil)
- value=[[NSMutableDictionary alloc]init];
- value[@"is_subaction"] = self.params[@"is_subaction"];
- value[@"subaction_tag"] = self.params[@"subaction_tag"];
-
- if (self.delegate && [self.delegate respondsToSelector:@selector(returnValue:indexPath:)]) {
- [self.delegate returnValue:value indexPath:self.from];
- }
- if(self.returnValue)
- self.returnValue(nil);
- }
- -(void) handle_action_return:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath action:(int) action_code
- {
- DebugLog(@"commoneditor return %ld_%ld",(long)indexPath.section,(long)indexPath.row);
- NSMutableDictionary* section_json=nil;
-
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- bool is_subaction = [value[@"is_subaction"] boolValue];
- int subaction_tag= [value[@"subaction_tag"] intValue];
- [value removeObjectForKey:@"is_subaction"];
- [value removeObjectForKey:@"subaction_tag"];
- if(is_subaction)
- {
- NSMutableDictionary* sub_action = [[item_json objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy];
- int refresh = [[sub_action valueForKey:@"refresh"] intValue];
- NSString* refresh_trigger = [sub_action valueForKey:@"name"];
- NSDictionary * restore_json=[sub_action objectForKeyedSubscript:@"restore"];
-
-
-
- NSString* subid=[sub_action valueForKey:@"subid"];
-
- UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
-
- NSString* required = [sub_action valueForKey:@"required"];
- if([required isEqualToString:@"true"] && value.count==0)
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- if(value.count!=0)
- {
-
- if(action_code==ACTION_SAVE_DATA)
- {
- [sub_action setObject:value forKey:@"data"];
-
-
- if(subid==nil)
- {
- [sub_action setValue:@"true" forKey:@"dirty"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[sub_action valueForKey:@"name" ]])
- {
- // sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
- [item_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
- }
-
- }
- }
- else
- {
-
- assert(@"not impl");
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- sub_action= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:sub_action step:2];
- [sub_action setValue:@"true" forKey:@"dirty"];
-
- [item_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
- }
- else if(action_code==ACTION_FILL_SECTION)
- {
-
- if(subid==nil)
- {
- NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int icount=[[section_json valueForKey:@"count"] intValue];
- for (int ic=0;ic<icount;ic++)
- {
- NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
-
- NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
-
- NSString* valuestr= [value valueForKey:valuefrom];
-
- if(valuestr !=nil)
- {
-
- [modify_item setValue:valuestr forKey:@"value"];
-
- [modify_item setValue:@"true" forKey:@"dirty"];
- [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
- }
- }
- }
- else
- {
-
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
- NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
- NSMutableDictionary* olditem_sub_action = [[olditem objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy];
-
- olditem_sub_action= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
-
-
- [olditem_sub_action setValue:@"true" forKey:@"dirty"];
- [olditem setObject:olditem_sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
- [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
-
-
-
- }
-
-
-
- // [section_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- }
-
- DebugLog(@"CONTENT UPDATE:%@",[iSalesNetwork DataTOjsonString:self.content_data_download]);
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
-
-
- if(refresh==1)
- {
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger] ;
- return ;
- }
-
-
-
- // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- [self.editorTable reloadData ];
-
- }
- else
- {
-
-
-
- int refresh = [[item_json valueForKey:@"refresh"] intValue];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
-
-
-
- NSString* subid=[item_json valueForKey:@"subid"];
-
- UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
-
- NSString* required = [item_json valueForKey:@"required"];
- if([required isEqualToString:@"true"] && value.count==0)
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- if(value.count!=0)
- {
-
- if(action_code==ACTION_SAVE_DATA)
- {
- [item_json setObject:value forKey:@"data"];
-
-
- if(subid==nil)
- {
- [item_json setValue:@"true" forKey:@"dirty"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
- }
- else
- {
-
- assert(@"not impl");
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
- }
- else if(action_code==ACTION_FILL_SECTION)
- {
-
- if(subid==nil)
- {
- NSDictionary* jsonmap=[item_json valueForKey:@"key_map"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int icount=[[section_json valueForKey:@"count"] intValue];
- for (int ic=0;ic<icount;ic++)
- {
- NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
-
- NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
-
- NSString* valuestr= [value valueForKey:valuefrom];
-
- if(valuestr !=nil)
- {
-
- [modify_item setValue:valuestr forKey:@"value"];
-
- [modify_item setValue:@"true" forKey:@"dirty"];
- [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
- }
- }
- }
- else
- {
-
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
- NSDictionary* jsonmap=[item_json valueForKey:@"key_map"];
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
-
- olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
-
-
- [olditem setValue:@"true" forKey:@"dirty"];
- [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
-
-
-
- }
-
-
-
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- }
-
- DebugLog(@"CONTENT UPDATE:%@",[iSalesNetwork DataTOjsonString:self.content_data_download]);
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
-
-
- if(refresh==1)
- {
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger] ;
- return ;
- }
-
-
-
- // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- [self.editorTable reloadData ];
- }
- }
- -(NSString*) getValue:(NSString*)name
- {
- NSString* ret=nil;
- for(int i=0;i<self.content_data_control.count;i++)
- {
- NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
- for(int j=0;j<items.count;j++)
- {
- NSDictionary* item=items[j];
- NSString* item_name=[item valueForKey:@"name"];
- if([item_name isEqualToString:name])
- {
- NSString* control = [item valueForKey:@"control"];
-
- if([control isEqualToString:@"enum"])
- {
- NSDictionary* cadedate = [item objectForKey:@"cadedate"];
- int cc = [[cadedate valueForKey:@"count"] intValue];
- for(int l=0;l<cc;l++)
- {
- NSDictionary* val_json=[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]];
- if([[val_json valueForKey:@"check"]intValue]==1)
- return [val_json valueForKey:@"value_id"];
- }
-
- }
- else
-
- return [item valueForKey:@"value"];
- }
- }
- }
- return ret;
- }
- -(void) setValue:(NSString*)key value:(NSString*)val
- {
- // NSString* ret=nil;
- for(int i=0;i<self.content_data_control.count;i++)
- {
- NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
- for(int j=0;j<items.count;j++)
- {
- NSMutableDictionary* item=[items[j] mutableCopy];
- NSString* item_name=[item valueForKey:@"name"];
-
- NSUInteger ii[2] = {i,j};
- NSIndexPath * indexPath= [NSIndexPath indexPathWithIndexes:ii length:2];
- if([item_name isEqualToString:key])
- {
- NSString* control = [item valueForKey:@"control"];
-
- if([control isEqualToString:@"enum"])
- {
- NSMutableDictionary* cadedate = [[item objectForKey:@"cadedate"] mutableCopy];
- int cc = [[cadedate valueForKey:@"count"] intValue];
- for(int l=0;l<cc;l++)
- {
- NSMutableDictionary* val_json=[[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]] mutableCopy];
- if([[val_json valueForKey:@"value_id"] isEqualToString:val])
- {
- val_json[@"check"]=[NSNumber numberWithInt:1];
- }
- else
- {
- val_json[@"check"]=[NSNumber numberWithInt:0];
- }
- cadedate[[NSString stringWithFormat:@"val_%d",l]] = val_json;
-
- // return [val_json valueForKey:@"value_id"];
- }
- // item[@"cadedate"] = cadedate;
-
-
- [self setEnumValue:cadedate indexPath:indexPath];
-
- }
- else if([control isEqualToString:@"edit"])
- {
-
- [self textfieldSetValue:indexPath value:val];
- }
- }
- }
- }
- [self.editorTable reloadData ];
- // return ret;
- }
- -(void) textfieldSetValue:(NSIndexPath*) indexPath value:(NSString*) val
- {
-
- //用于会填 textfield 的值,textViewDidEndEditing 和 partial refresh 会调用。
-
-
- // DebugLog(@"textFieldDidEndEditing");
- // // UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
- // NSIndexPath * indexPath = self.lastedit_from;
- //
-
- NSMutableDictionary* section_json=nil;
-
-
-
- val = [val stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- NSString* subid=[item_json valueForKey:@"subid"];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
-
- [item_json setValue:@"true" forKey:@"dirty"];
- [item_json setValue:val forKey:@"value"];
- if([[item_json valueForKey:@"keyboard"] isEqualToString:@"number"])
- {
- float f = [ val floatValue];
- [item_json setValue:[NSString stringWithFormat:@"%.2f",f] forKey:@"value"];
-
- }
-
- // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
- int refresh = [[item_json valueForKey:@"refresh"] intValue];
-
- NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
- if(refresh==1)
- {
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger] ;
-
- }
- else if(partial_refresh)
- {
- NSString* name = [item_json valueForKey:@"name"] ;
- NSString* url = [item_json valueForKey:@"data_interface"] ;
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
- [params setValue:val forKey:name];
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* editor_json = [iSalesNetwork commoneditor_partialrefresh:params url:url];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- int prcount = [[editor_json valueForKey:@"count"] intValue];
- for(int ipr=0;ipr<prcount;ipr++)
- {
- NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
- NSString* name = [pr_item valueForKey:@"name"];
- NSString* value = [pr_item valueForKey:@"value"];
-
- [self setValue:name value:value];
- }
-
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
- }
-
-
- });
- });
-
-
-
- }
- self.lastedit = nil;
- self.lastedit_from=nil;
- return ;
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- NSString* control_type= [olditem valueForKey:@"control"];
- NSMutableDictionary* new_item=nil;
- [item_json setValue:@"true" forKey:@"dirty"];
- if([control_type isEqualToString:@"enum"])
- new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- else if([control_type isEqualToString:@"switch"])
- new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
-
- [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
- int refresh = [[item_json valueForKey:@"refresh"] intValue];
-
- NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
- if(refresh==1)
- {
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger] ;
-
- }
- else if(partial_refresh)
- {
- NSString* name = [item_json valueForKey:@"name"] ;
- NSString* url = [item_json valueForKey:@"data_interface"] ;
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
- [params setValue:val forKey:name];
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* editor_json = [iSalesNetwork commoneditor_partialrefresh:params url:url];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- int prcount = [[editor_json valueForKey:@"count"] intValue];
- for(int ipr=0;ipr<prcount;ipr++)
- {
- NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
- NSString* name = [pr_item valueForKey:@"name"];
- NSString* value = [pr_item valueForKey:@"value"];
-
- [self setValue:name value:value];
- }
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
- }
-
-
- });
- });
-
-
-
- }
- self.lastedit = nil;
- self.lastedit_from=nil;
-
- return;
- }
-
-
-
-
- // return [item valueForKey:@"value"];
-
- }
- -(void) unhide_section:(int)isection
- {
-
-
- NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",isection]] mutableCopy];
- [section setValue:@"false" forKey:@"hide"];
- [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%d",isection]];
-
- }
- -(NSIndexPath*) get_indexpath1:(NSString*)name
- {
- if(self.first_miss_pos!=nil)
- return self.first_miss_pos;
- NSIndexPath* ret=nil;
- for(int i=0;i<self.content_data_control.count;i++)
- {
- NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
- for(int j=0;j<items.count;j++)
- {
- NSDictionary* item=items[j];
- NSString* item_name=[item valueForKey:@"name"];
- if([item_name isEqualToString:name])
- {
- NSUInteger ii[2] = {i,j};
- return [NSIndexPath indexPathWithIndexes:ii length:2];
- }
- }
- }
- return ret;
- }
- -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
- {
- NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
- NSArray *keys= [key_map allKeys];
- //遍历keys
- for(int i=0;i<[keys count];i++)
- {
- //得到当前key
- NSString *key=[keys objectAtIndex:i];
- //如果key不是pic,说明value是字符类型,比如name:Boris
- NSString* valuefrom = [key_map valueForKey:key];
-
- if(valuefrom.length==0)
- continue;
- NSString* value=[self getValue:valuefrom];
-
- [ret setValue:value forKey:valuefrom];
- }
- NSDictionary * customerinfo =[self create_cusromer_info_from_table];
- [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
- [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
- [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // // self.labelContact.text=appDelegate.contact_name;
- //
- // NSDictionary * customerinfo = appDelegate.customerInfo;
- //
- //
- // keys= [customerinfo allKeys];
- // //遍历keys
- // for(int i=0;i<[keys count];i++)
- // {
- // //得到当前key
- // NSString *key=[keys objectAtIndex:i];
- // //如果key不是pic,说明value是字符类型,比如name:Boris
- // NSString* valuefrom = key;
- // NSString* value=[customerinfo valueForKey:key];
- //
- // [ret setValue:value forKey:valuefrom];
- // }
- //// add customer_contact_ext
- // [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
-
- // NSString *string = [array componentsJoinedByString:@" "];
- return ret;
- }
- -(NSMutableDictionary*)create_cusromer_info_from_table
- {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
-
- [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
- [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
- [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
- [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
- [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
- [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
- [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
- [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
- [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
- [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
- [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
- [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
- [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
- [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
- [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
-
- NSString * firstname =nil;
-
- NSString* lastname = nil;
- NSString* contact_name = [self getValue:@"customer_contact"];
- if(contact_name!=nil)
- {
- NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
-
-
-
- if(_arr.count>=1)
- {
- firstname =_arr[0];
- if(_arr.count>1)
- {
-
- lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
- }
- }
- }
- [ret setValue:firstname forKey:@"customer_first_name"];
- [ret setValue:lastname forKey:@"customer_last_name"];
-
- // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
-
- return ret;
- }
- -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
- {
- NSString* ret=nil;
- NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
- NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
- NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
- NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
-
- NSMutableArray* arraddr = [[NSMutableArray alloc] init];
- if(customer_address1.length>0)
- [arraddr addObject:customer_address1];
- if(customer_address2.length>0)
- [arraddr addObject:customer_address2];
- if(customer_address3.length>0)
- [arraddr addObject:customer_address3];
- if(customer_address4.length>0)
- [arraddr addObject:customer_address4];
- NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
-
-
- NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
- NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
- NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
- NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
-
- NSMutableArray* arrcty = [[NSMutableArray alloc] init];
- if(customer_city.length>0)
- [arrcty addObject:customer_city];
- if(customer_state.length>0)
- [arrcty addObject:customer_state];
- if(customer_zipcode.length>0)
- [arrcty addObject:customer_zipcode];
- if(customer_country.length>0)
- [arrcty addObject:customer_country];
- NSString *cty_string = [arrcty componentsJoinedByString:@", "];
-
-
- // NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"];
- // NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"];
- //
- // NSMutableArray* arrpho = [[NSMutableArray alloc] init];
- // if(customer_phone.length>0)
- // {
- // customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone];
- // [arrpho addObject:customer_phone];
- // }
- // if(customer_fax.length>0)
- // {
- // customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax];
- // [arrpho addObject:customer_fax];
- // }
- // NSString *phone_string = [arrpho componentsJoinedByString:@", "];
- //
- //
- // NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"];
- // if(customer_contact.length>0)
- // {
- // customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact];
- //
- // }
- // NSString *contact_string = customer_contact;
- //
- //
- // NSString* customer_email= [customerinfo valueForKey:@"customer_email"];
- // if(customer_email.length>0)
- // {
- // customer_email = [NSString stringWithFormat:@"Email: %@",customer_email];
- //
- // }
- // NSString *email_string = customer_email;
-
-
- NSMutableArray* arrext = [[NSMutableArray alloc] init];
- if(addr_string.length>0)
- [arrext addObject:addr_string];
- if(cty_string.length>0)
- [arrext addObject:cty_string];
- // if(phone_string.length>0)
- // [arrext addObject:phone_string];
- // if(contact_string.length>0)
- // [arrext addObject:contact_string];
- // if(email_string.length>0)
- // [arrext addObject:email_string];
-
- ret = [arrext componentsJoinedByString:@"\r\n"];
-
- // NSString *string = [array componentsJoinedByString:@" "];
-
- // NSString* customer_name= [customerinfo valueForKey:@"customer_name"];
-
-
- return ret;
- }
- #pragma mark - hide section button clicked
- - (void)HideSction:(UIButton *)sender {
-
- NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]] mutableCopy];
- bool hide = [[section valueForKey:@"hide"]boolValue];
- if(hide)
- {
- [section setValue:@"false" forKey:@"hide"];
- [sender setTitle:@"Show" forState:UIControlStateNormal];
- }
- else{
- [section setValue:@"true" forKey:@"hide"];
- [sender setTitle:@"Hide" forState:UIControlStateNormal];
- }
-
- [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- NSRange range = NSMakeRange(sender.tag, 1);
- NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
-
-
-
- }
- #pragma mark - multi_action sub action clicked
- - (IBAction)MActionClicked:(UIButton *)sender {
- UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
- NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
- int refresh =0;
- NSMutableDictionary* section_json=nil;
-
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
- NSString* subid=[item_json valueForKey:@"subid"];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
- NSString* type = [sub_action valueForKey:@"type"];
- if([type isEqualToString:@"pull"])
- {
-
- [self.lastedit endEditing:true];
-
- refresh = [[sub_action valueForKey:@"refresh"] intValue];
- NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
-
- NSMutableDictionary* value=[self create_value_map:keymap];
-
- if(subid==nil)
- {
- NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int icount=[[section_json valueForKey:@"count"] intValue];
- for (int ic=0;ic<icount;ic++)
- {
- NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
-
-
- NSString* mapto = [modify_item valueForKey:@"name"];
- if(mapto.length==0)
- continue;
- NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
- if(valuefrom==nil)
- continue;
- NSString* valuestr=[value valueForKey:valuefrom];
-
-
-
-
-
- // valuestr = [self getValue:valuefrom];
- if(true)
- {
- if(valuestr.length>0)
- [modify_item setValue:valuestr forKey:@"value"];
- else
- [modify_item setValue:@"" forKey:@"value"];
- [modify_item setValue:@"true" forKey:@"dirty"];
- [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
- }
- }
- }
- else
- {
-
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
- NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
-
- NSString* control_type = [olditem valueForKey:@"control"];
- if([control_type isEqualToString:@"switch"])
- olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
- else if([control_type isEqualToString:@"enum"])
- {
- olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
-
- }
- else
- {
- [RAUtils alert_view:@"" title:@"not impl"];
- }
-
- [olditem setValue:@"true" forKey:@"dirty"];
- [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
-
- if(refresh==1)
- {
-
- // if(restore_json!=nil)
- // {
- // int rc=[[restore_json valueForKey:@"count"] intValue];
- // for(int ir=0;ir<rc;ir++)
- // {
- // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
- //
- //
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- //
- // if([[itemjson valueForKey:@"name"] isEqualToString:name])
- // {
- // [itemjson removeObjectForKey:@"dirty"];
- // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- // }
- //
- // }
- // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- // }
- //
- //
- // }
- //
- // }
- [self refresh:refresh_trigger] ;
- return ;
- }
-
- // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- [self.editorTable reloadData ];
-
-
- }
- else
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSDictionary * item_json = sub_action;
- NSString* value = [item_json valueForKey:@"value"];
- if([value isEqualToString:@"new_addr"])
- {
- AddressEditorViewController * addressVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AddressEditorViewController"];
-
- addressVC.url_type = URL_REMOTE;
-
- addressVC.request_url=URL_ADDRESS_EDOTOR;
-
-
-
-
- NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
- // NSString * string = [checked componentsJoinedByString:@","];
- // [params setValue:string forKey:@"cart2Checkbox"];
-
-
- params[@"is_subaction"]=@"true";
- params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
- addressVC.params = params;
-
-
- addressVC.delegate = self;
-
- addressVC.from = indexPath;
- // orderinfoVC.params = params;
-
- [self.navigationController pushViewController:addressVC animated:true];
-
- }else if([value isEqualToString:@"credit_card"])
- {
- CreditCardEditorViewController * cardVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreditCardEditorViewController"];
-
-
- NSDictionary *data = [item_json objectForKey:@"data"];
-
- if(data!=nil)
- {
-
- cardVC.content_data_download = [data mutableCopy];
- cardVC.url_type = URL_NONE;
-
- cardVC.request_url=nil;
- }
- else
- {
- cardVC.url_type = URL_REMOTE;
-
- cardVC.request_url=URL_CREDITCARD_EDOTOR;
- }
- NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
-
- params[@"orderCode"]=appDelegate.order_code;
-
- params[@"is_subaction"]=@"true";
- params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
- cardVC.params = params;
-
- cardVC.delegate = self;
-
- cardVC.from = indexPath;
-
-
- // orderinfoVC.params = params;
-
- [self.navigationController pushViewController:cardVC animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
- {
-
-
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- cvc.is_subaction = @"true";
- cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
-
-
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Ship_From"])
- {
-
-
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- cvc.is_subaction = @"true";
- cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
-
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Customer"])
- {
-
-
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.is_subaction = @"true";
- cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
- cvc.showNavibar = true;
- cvc.contact_type = value;
-
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
- {
-
-
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- cvc.is_subaction = @"true";
- cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
-
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Contact_Return_To"])
- {
-
-
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.is_subaction = @"true";
- cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
- cvc.showNavibar = true;
- cvc.contact_type = value;
-
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Ship_To"])
- {
-
-
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.is_subaction = @"true";
- cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
- cvc.showNavibar = true;
- cvc.contact_type = value;
-
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
-
-
- }
- }
- #pragma mark - commoneditor delegate
- -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
- {
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_SAVE_DATA];
- // DebugLog(@"commoneditor return %d_%d",indexPath.section,indexPath.row);
- //
- // NSMutableDictionary* section_json=nil;
- //
- // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
- //
- //
- //
- // int refresh = [[item_json valueForKey:@"refresh"] intValue];
- //
- // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- //
- //
- //
- // NSString* subid=[item_json valueForKey:@"subid"];
- //
- // UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
- //
- // NSString* required = [item_json valueForKey:@"required"];
- // if([required isEqualToString:@"true"] && value==nil)
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor redColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- // else
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor clearColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- // if(value!=nil)
- // {
- // [item_json setObject:value forKey:@"data"];
- //
- //
- // if(subid==nil)
- // {
- // [item_json setValue:@"true" forKey:@"dirty"];
- // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- // int count=0;
- //
- // count=[[section_json valueForKey:@"count"] intValue];
- //
- // for(int i=0;i<count;i++)
- // {
- // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
- //
- //
- // }
- // }
- // else
- // {
- // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- // int section = [(NSString*)idarr[0] intValue];
- // int item=[(NSString*)idarr[1] intValue];
- //
- //
- // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- // item_json= [self subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- // [item_json setValue:@"true" forKey:@"dirty"];
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- //
- // }
- //
- //
- // // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
- //
- // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // }
- //
- // if(refresh==1)
- // {
- //
- // if(restore_json!=nil)
- // {
- // int rc=[[restore_json valueForKey:@"count"] intValue];
- // for(int ir=0;ir<rc;ir++)
- // {
- // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
- //
- //
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- //
- // if([[itemjson valueForKey:@"name"] isEqualToString:name])
- // {
- // [itemjson removeObjectForKey:@"dirty"];
- // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- // }
- //
- // }
- // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- // }
- //
- //
- // }
- //
- // }
- // [self refresh] ;
- // return ;
- // }
- //
- //
- // DebugLog(@"CONTENT UPDATE:%@",[iSalesNetwork DataTOjsonString:self.content_data_download]);
- // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- //
- //
- // // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- // [self.editorTable reloadData ];
-
- }
- #pragma mark - Table view data source
- //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- //{
- // return 0;
- //}
- //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- //{
- // return 0;
- //}
- //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // return myView;
- //
- //}
- //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 20, 10)];
- //// titleLabel.textColor=[UIColor whiteColor];
- //// titleLabel.backgroundColor = [UIColor clearColor];
- //// if(section==0)
- //// titleLabel.text=NSLocalizedString(@"display_items", nil);
- //// else
- //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
- //// [titleLabel sizeToFit];
- //// [myView addSubview:titleLabel];
- ////
- // return myView;
- //}
- //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- //
- // switch (section) {
- // case 0:
- // {
- // NSDictionary * section_json = [self.content_data objectForKey:@"info_section"];
- // return [section_json valueForKey:@"title"] ;
- // }
- // case 1:
- // {
- // NSDictionary * section_json = [self.content_data objectForKey:@"model_section"];
- // return [section_json valueForKey:@"title"] ;
- // }
- // default:
- // return nil;
- // }
- //
- //
- //}
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
-
- NSMutableDictionary* section_json = [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]];
- return [section_json valueForKey:@"title"];
-
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
-
- // if(self.content_data_control.count>0)
- // return 1;
- return self.content_data_control.count;
- // int section_count =[[self.content_data valueForKey:@"section_count"] intValue];
- // return section_count;
- }
- //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
- //{
- // DebugLog(@"canMoveRowAtIndexPath");
- //
- // if([tableView numberOfRowsInSection:indexPath.section]>1)
- // return true;
- // else
- // return false;
- //}
- //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
- //{
- // NSMutableArray * from;
- // NSMutableArray * to ;
- // if(fromIndexPath.section==0)
- // from = self.displayfields;
- // else
- // from = self.hidefields;
- // if(toIndexPath.section==0)
- // to = self.displayfields;
- // else
- // to = self.hidefields;
- // id content=from[fromIndexPath.row];
- // [from removeObjectAtIndex:fromIndexPath.row];
- // [to insertObject:content atIndex:toIndexPath.row];
- //
- // [tableView reloadData];
- //
- //}
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- // if(self.content_data_control.count>0)
- // return 1;
-
-
-
- NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy];
- bool hide = [[sectionjson valueForKey:@"hide"]boolValue];
- if(hide)
- {
- return 0;
- // [sectionjson setValue:@"false" forKey:@"hide"];
- // [sender setTitle:@"Show" forState:UIControlStateNormal];
- }
- else{
- return ((NSMutableArray*)self.content_data_control[section]).count;
-
- // [sectionjson setValue:@"true" forKey:@"hide"];
- // [sender setTitle:@"Hide" forState:UIControlStateNormal];
- }
- // return 0;
-
- // if(section==4)
- // return 1;
- // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]];
- //
- // return [[section_json valueForKey:@"count" ] intValue];
-
-
-
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- if(section==0)
- return 44;
- return 33;
- }
- //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- //{
- // return 0.5;
- //}
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- {
-
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
-
- NSString* control = [item_json valueForKey:@"control"];
- if([control isEqualToString:@"model"])
- return 140;
- else if([control isEqualToString:@"signature"])
- return 140;
- else if([control isEqualToString:@"text_view"])
- return 140;
-
- else if([control isEqualToString:@"img"])
- return 123;
- return 44;
-
-
- }
- //
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue];
- // int d=0;
- // if(indexPath.section==4)
- // d=0;
-
- // DebugLog(@"%d,%d",indexPath.section,indexPath.row);
- // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- NSString* control = [item_json valueForKey:@"control"];
-
- NSString* required = [item_json valueForKey:@"required"];
- NSString *CellIdentifier = @"";
-
-
-
- if([control isEqualToString:@"text_view"])
- {
- CellIdentifier = @"CommonEditorCellTextView";
- CommonEditorCellTextView * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- NSString* value =[item_json valueForKey:@"value"];
- NSString* align =[item_json valueForKey:@"align"];
- if([align isEqualToString:@"right"])
- cell.textview.textAlignment= kCTRightTextAlignment;
- else
- cell.textview.textAlignment =kCTLeftTextAlignment;
-
- int capital =[[item_json valueForKey:@"capital"] intValue];
- switch (capital) {
- case 1:
- cell.textview.autocapitalizationType=UITextAutocapitalizationTypeWords;
- break;
- case 2:
- cell.textview.autocapitalizationType=UITextAutocapitalizationTypeSentences;
- break;
- case 3:
- cell.textview.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;
- break;
- default:
- cell.textview.autocapitalizationType=UITextAutocapitalizationTypeWords;//UITextAutocapitalizationTypeNone;
- break;
- }
-
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
- cell.textview.editable=NO;
- // cell.textfield.backgroundColor = [UIColor lightGrayColor];
- cell.textview.textColor= [UIColor lightGrayColor];
-
- }
- else
- {
- cell.textview.editable=YES;
- cell.textview.textColor= [UIColor blackColor];
- // cell.textfield.backgroundColor = [UIColor whiteColor];
- }
-
-
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
-
-
- cell.label_name.text=title;
-
- if([required isEqualToString:@"true"])
- {
- [cell.label_name sizeToFit];
- CGRect frame =cell.label_name.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.label_name sizeToFit];
- cell.starMark.hidden=true;
- }
-
-
- cell.textview.text = value;
- cell.textview.delegate = self;
- cell.accessoryType = UITableViewCellAccessoryNone;
-
-
-
-
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }else
- if([control isEqualToString:@"img"])
- {
- CellIdentifier = @"CommonEditorCellImg";
- CommonEditorCellImg * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSString* title = [item_json valueForKey:@"aname"] ;
- NSString* value =[item_json valueForKey:@"value"];
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
- cell.editable=false;
- }
- else
- cell.editable=true;
- cell.labelTitle.text = title;
- cell.labelDescription.text = value;
-
- cell.imgChanged = ^(NSString* url_down,NSString* url_up,int index ,NSString* url_index)
- {
- // NSMutableDictionary* editjson = [item_json mutableCopy];
- // editjson[@"img_url"]=url;
- [self imgIsChanged:url_down url_up:url_up indexPath:indexPath index:index url_index:url_index];
-
-
- };
-
- {
- NSString* img_url0 = [item_json valueForKey:@"img_url_0"];
- if(img_url0.length>0)
- {
- NSString* img_url_up=[item_json valueForKey:@"img_url_aname_0"];
- if(img_url_up.length==0)
- img_url_up=@"";
- cell.imgs[0]=img_url_up;
- NSString* file_name=[img_url0 lastPathComponent];
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url0];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
-
- cell.touchImageView0.image=img;
-
- cell.img_validate = true;
- // [cell.touchImageView setImage:img forState:UIControlStateNormal];
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url0]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url0];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.touchImageView0.image=img;
- cell.img_validate = true;
- }
- else
- {
- cell.touchImageView0.image=[UIImage imageNamed:@"notfound_s"];
-
- cell.img_validate = false;
- }
-
- });
- });
-
-
- }
- }
- else
- {
- cell.touchImageView0.image=nil;
- cell.imgs[0]=@"";
- }
- }
-
- {
- NSString* img_url1 = [item_json valueForKey:@"img_url_1"];
- if(img_url1.length>0)
- {
- NSString* img_url_up=[item_json valueForKey:@"img_url_aname_1"];
- if(img_url_up.length==0)
- img_url_up=@"";
-
- cell.imgs[1]=img_url_up;
- NSString* file_name=[img_url1 lastPathComponent];
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url1];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
-
-
- cell.touchImageView1.image=img;
-
- cell.img_validate = true;
- // [cell.touchImageView setImage:img forState:UIControlStateNormal];
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url1]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url1];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.touchImageView1.image=img;
- cell.img_validate = true;
- }
- else
- {
- cell.touchImageView1.image=[UIImage imageNamed:@"notfound_s"] ;
- cell.img_validate = false;
- }
-
- });
- });
-
-
- }
- }
- else
- {
- cell.touchImageView1.image=nil;
- cell.imgs[1]=@"";
- }
- }
- {
- NSString* img_url2 = [item_json valueForKey:@"img_url_2"];
- if(img_url2.length>0)
- {
- NSString* img_url_up=[item_json valueForKey:@"img_url_aname_2"];
- if(img_url_up.length==0)
- img_url_up=@"";
- cell.imgs[2]=img_url_up;
- NSString* file_name=[img_url2 lastPathComponent];
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url2];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
-
- cell.touchImageView2.image=img;
-
- cell.img_validate = true;
- // [cell.touchImageView setImage:img forState:UIControlStateNormal];
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url2]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url2];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.touchImageView2.image=img;
- cell.img_validate = true;
- }
- else
- {
- cell.touchImageView2.image=[UIImage imageNamed:@"notfound_s"] ;
- cell.img_validate = false;
- }
-
- });
- });
-
-
- }}
- else
- {
- cell.touchImageView2.image=nil;
- cell.imgs[2]=@"";
- }
- }
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- }else
- if([control isEqualToString:@"edit"])
- {
- CellIdentifier = @"CommonEditorCellEdit";
- CommonEditorCellEdit * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
-
- // title =[[NSString stringWithFormat:@"<font size=\"5\" face=\"Helvetica\">%@</font>",title] mutableCopy];
- NSString* value =[item_json valueForKey:@"value"];
-
- NSString* align =[item_json valueForKey:@"align"];
-
- if([align isEqualToString:@"right"])
- cell.textfield.textAlignment= NSTextAlignmentRight;
- else
- cell.textfield.textAlignment =NSTextAlignmentLeft;
-
- int capital =[[item_json valueForKey:@"capital"] intValue];
- switch (capital) {
- case 1:
- cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeWords;
- break;
- case 2:
- cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeSentences;
- break;
- case 3:
- cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;
- break;
- default:
- cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeWords;//UITextAutocapitalizationTypeNone;
- break;
- }
-
-
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
-
- cell.textfield.enabled=NO;
- // cell.textfield.backgroundColor = [UIColor lightGrayColor];
- cell.textfield.textColor= [UIColor lightGrayColor];
-
- }
- else
- {
- cell.textfield.enabled=YES;
- cell.textfield.textColor= [UIColor blackColor];
- // cell.textfield.backgroundColor = [UIColor whiteColor];
- }
-
- NSString* keyboard = [item_json valueForKey:@"keyboard"];
-
- if([keyboard isEqualToString:@"number"])
- {
-
- // float f = [value floatValue];
-
- // value = [NSString stringWithFormat:@"%.2f",f];
-
-
- cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
-
-
-
- }
- else if([keyboard isEqualToString:@"email"])
- {
- cell.textfield.keyboardType=UIKeyboardTypeEmailAddress;
- }
- else if([keyboard isEqualToString:@"phone"])
- {
- cell.textfield.keyboardType=UIKeyboardTypePhonePad;
- }
- else
- {
- cell.textfield.keyboardType=UIKeyboardTypeDefault;
- }
-
-
- // UIKIT_EXTERN NSString * const NSPlainTextDocumentType NS_AVAILABLE(10_0, 7_0);
- // UIKIT_EXTERN NSString * const NSRTFTextDocumentType NS_AVAILABLE(10_0, 7_0);
- // UIKIT_EXTERN NSString * const NSRTFDTextDocumentType NS_AVAILABLE(10_0, 7_0);
- // UIKIT_EXTERN NSString * const NSHTMLTextDocumentType NS_AVAILABLE(10_0, 7_0);
- //
-
- // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[title dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
- // UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];
- // myLabel.attributedText = attrStr;
-
- // cell.labelTitle.attributedText = attrStr;
- cell.labelTitle.text=title;
-
-
-
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
- cell.textfield.text = value;
- cell.textfield.delegate = self;
- cell.accessoryType = UITableViewCellAccessoryNone;
-
-
-
-
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
-
-
-
-
-
-
- CALayer *layer = cell.labelTitle.layer;
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
-
-
- layer = cell.starMark.layer;
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
-
-
- //UIImageView * iv =
- cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_attention_24"]];
- cell.textfield.rightViewMode=UITextFieldViewModeUnlessEditing;
- cell.textfield.layer.cornerRadius=8.0f;
- cell.textfield.layer.borderWidth= 1.0f;
- cell.textfield.layer.masksToBounds=YES;
- cell.textfield.layer.borderColor=[[UIColor redColor]CGColor];
- }
- else
- {
- CALayer *layer = cell.labelTitle.layer;//[cell.contentView layer];
-
-
-
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
-
-
- layer = cell.starMark.layer;//[cell.contentView layer];
-
-
-
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
-
-
- cell.textfield.rightViewMode=UITextFieldViewModeNever;
- //cell.textfield.layer.borderColor= [[UIColor lightGrayColor] CGColor];
- cell.textfield.rightView = nil;
- cell.textfield.layer.cornerRadius=8.0f;
- cell.textfield.layer.borderWidth= 1.0f;
- cell.textfield.layer.masksToBounds=YES;
- cell.textfield.layer.borderColor=[[UIColor lightGrayColor]CGColor];
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else
- if([control isEqualToString:@"text"])
- {
- CellIdentifier = @"CommonEditorCellLabel";
- CommonEditorCellLabel * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
- //CGRect titleframe = cell.labelTitle.frame;
-
- NSString* title = [item_json valueForKey:@"aname"] ;
- NSString* value =[item_json valueForKey:@"value"];
- NSString* color =[item_json valueForKey:@"color"];
- cell.labelValue.textColor = [RAUtils strColor:color];
- NSString* align =[item_json valueForKey:@"align"];
- if([align isEqualToString:@"right"])
- {
- cell.labelTitle.frame =CGRectMake(15,11,350,21);
- cell.labelValue.textAlignment= NSTextAlignmentRight;
- }
- else
- {
- cell.labelTitle.frame =CGRectMake(15,11,150,21);
- cell.labelValue.textAlignment =NSTextAlignmentLeft;
- }
-
- NSString* type=[item_json valueForKey:@"type"] ;
-
- if([type isEqualToString:@"price"])
- {
-
- if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
- {
-
- }
- else
- {
- value=nil;
- }
- }
-
-
-
- cell.labelTitle.text=title;
- cell.labelValue.text = value;
-
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else
- if([control isEqualToString:@"action"])
- {
- CellIdentifier = @"CommonEditorCellAction";
- CommonEditorCellAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- NSString* value =[item_json valueForKey:@"value"];
- if([required isEqualToString:@"true"])
- {
- [title appendString:@"*"];
- }
- NSDictionary* data = [item_json objectForKey:@"data"];
-
- cell.labelAction.text=title;
- cell.action_code = value;
-
-
- //cell.labelValue.text = value;
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- if([control isEqualToString:@"multi_action"])
- {
- CellIdentifier = @"CommonEditorCellMAction";
- CommonEditorCellMAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
- int count = [[item_json valueForKey:@"count"]intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary* sub_action= [item_json objectForKey:[NSString stringWithFormat:@"item_%d",i]];
- NSString * title = [sub_action valueForKey:@"aname"];
- switch (i) {
- case 0:
- [cell.btn_action0 setTitle:title forState:UIControlStateNormal];
- [cell.btn_action0 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
- cell.btn_action0.hidden = NO;
- break;
- case 1:
- [cell.btn_action1 setTitle:title forState:UIControlStateNormal];
- [cell.btn_action1 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
- cell.btn_action1.hidden = NO;
- break;
- case 2:
- [cell.btn_action2 setTitle:title forState:UIControlStateNormal];
- [cell.btn_action2 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
- cell.btn_action2.hidden = NO;
- break;
- case 3:
- [cell.btn_action3 setTitle:title forState:UIControlStateNormal];
- [cell.btn_action3 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
- cell.btn_action3.hidden = NO;
- break;
- default:
- break;
- }
- }
-
- if (count<4)
- cell.btn_action3.hidden=YES;
- if (count<3)
- cell.btn_action2.hidden=YES;
- if (count<2)
- cell.btn_action1.hidden=YES;
- if (count<1)
- cell.btn_action0.hidden=YES;
-
- // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- // NSString* value =[item_json valueForKey:@"value"];
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
- // NSDictionary* data = [item_json objectForKey:@"data"];
- //
- // cell.labelAction.text=title;
- // cell.action_code = value;
- //
- //
- // //cell.labelValue.text = value;
- //
- // if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil))
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor redColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else
- if([control isEqualToString:@"switch"])
- {
- CellIdentifier = @"CommonEditorCellSwitch";
- CommonEditorCellSwitch * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSString* title = [item_json valueForKey:@"aname"];
- NSString* value =[item_json valueForKey:@"value"];
-
-
- cell.labelTitle.text=title;
-
-
-
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
-
-
- // CGSize asize=[cell.labelTitle sizeThatFits:cell.labelTitle.frame.size];
- //
- // cell.starMark.frame = CGRectMake(cell.labelTitle.frame.origin.x+asize.width, cell.labelTitle.frame.origin.y, 10, 21);
- // cell.starMark.hidden=false;
-
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
- [cell.switchCtrl addTarget:self
- action:@selector(switchIsChanged:)
- forControlEvents:UIControlEventValueChanged];
- if([[value lowercaseString] isEqualToString:@"true"])
- cell.switchCtrl.on = true;
- else
- cell.switchCtrl.on = false;
- cell.accessoryType = UITableViewCellAccessoryNone;
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- } else if([control isEqualToString:@"enum"])
- {
-
-
-
- CellIdentifier = @"CommonEditorCellEnum";
- CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- NSDictionary* cadedate_json =[item_json objectForKey:@"cadedate"];
-
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
- cell.labelValue.textColor= [UIColor lightGrayColor];
-
- }
- else
- {
- cell.labelValue.textColor= [UIColor blackColor];
- // cell.textfield.backgroundColor = [UIColor whiteColor];
- }
-
- NSString* align =[item_json valueForKey:@"align"];
- if([align isEqualToString:@"right"])
- cell.labelValue.textAlignment= NSTextAlignmentRight;
- else
- cell.labelValue.textAlignment =NSTextAlignmentLeft;
-
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
-
-
- NSString* value =@"";
- int count = [[cadedate_json valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSDictionary* val_json =[cadedate_json objectForKey:[NSString stringWithFormat:@"val_%d",i]];
- int check = [[val_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- value = [value stringByAppendingString:[val_json valueForKey:@"value"]];
- value = [value stringByAppendingString:@"|"];
- }
- }
- if(value.length>=1)
- value=[value substringToIndex:value.length-1];
- cell.labelTitle.text=title;
-
-
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
- cell.labelValue.text = value;
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- } else if([control isEqualToString:@"model"])
- {
- CommonEditorCellModel * cell= [tableView dequeueReusableCellWithIdentifier:@"CommonEditorCellModel" forIndexPath:indexPath];
-
- int count = [[item_json valueForKey:@"count"] intValue];
- NSDictionary * combine_json =[item_json objectForKey:@"combine"];
- cell.bundle_item=combine_json;
-
- double dprice=0.0;
-
- if(cell.bundle_item!=nil)
- {
- int citem=0;
-
- int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
- for(int bc=0;bc<bcount;bc++)
- {
- NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
- int modulus= [[bitem valueForKey:@"modulus"] intValue];
- citem+= modulus;
- double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
- dprice+= uprice*modulus;
-
- }
- if(citem==1)
- [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
- else
- [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
-
- cell.buttonBundle.hidden = NO;
- }
- else
- {
- cell.buttonBundle.hidden = YES;
-
- }
-
- NSString *availability = [item_json objectForKey:@"quantity_available"];
- NSString *available_str = @"Available Now";
- if ([availability integerValue] > 0) {
- available_str = [NSString stringWithFormat:@"Available: %@",availability];
- } else {
- available_str = @"Available: In Production";
- }
- cell.avalibilityLabel.text = available_str;
-
- NSString* img_url = [item_json valueForKey:@"img_url"];
- NSString* description = [item_json valueForKey:@"description"];
- // NSString* identifier = [item_json valueForKey:@"identifier"];
- // NSString* attribute = [item_json valueForKey:@"attribute"];
-
- // NSString* total_price = [item_json valueForKey:@"total_price"] ;
- // NSString* unit_price = [item_json valueForKey:@"unit_price"] ;
-
- // NSString* mp = [item_json valueForKey:@"stockUom"];
- double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
- int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
- double discount =[[item_json valueForKey:@"discount"] doubleValue];
- NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
-
-
- NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice];
- NSString* newunitprice=@"";
- if(dprice>0)
- newunitprice = [NSString stringWithFormat:@"%.2f+%.2f",unitprice* (1.0-discount/100),dprice];
- else
- newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
- NSString* totalprice = [NSString stringWithFormat:@"%.2f",(unitprice* (1.0-discount/100)+dprice)*count];
-
-
-
- if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
- {
-
- }
- else
- {
- oldprice=nil;
- newunitprice=nil;
- totalprice=nil;
- }
-
-
- cell.labelDiscount.text = discountstr;
- cell.labelOldPrice.text = oldprice;
- cell.labelMasterPack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
-
- bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
-
-
-
- if(isfree)
- {
- cell.labelOldPrice.hidden = false;
- cell.labelOldPrice.textColor = [UIColor redColor];
- cell.labelOldPrice.text=@"Free";
- cell.labelOldPrice.hideline = true;
-
- cell.labelDiscount.hidden = true;
- }
- else
- {
- cell.labelOldPrice.textColor = [UIColor blackColor];
- cell.labelOldPrice.hideline = false;
- if(discount==0)
- {
- cell.labelOldPrice.hidden = true;
- cell.labelDiscount.hidden = true;
-
- }
- else
- {
- cell.labelOldPrice.hidden = false;
- cell.labelDiscount.hidden = false;
- }
- }
- // if(discount==0)
- // {
- // cell.labelOldPrice.hidden = true;
- // cell.labelDiscount.hidden = true;
- //
- // }
- // else
- // {
- // cell.labelOldPrice.hidden = false;
- // cell.labelDiscount.hidden = false;
- // }
-
- // NSString* currency = [item_json valueForKey:@"currency"];
- // int count =[[item_json valueForKey:@"count"] intValue];
-
- cell.labelDescription.text = description;
- cell.labelCount.text = [NSString stringWithFormat:@"x %d",count];
- // cell.labelID.text = identifier;
- // cell.labelSubtype.text = attribute;
- cell.labelTotalPrice.text= totalprice;
- // cell.labelUnitPrice.text=unit_price;
-
- cell.labelUnitPrice.text = newunitprice;
- cell.imgModel.image = [UIImage imageNamed:@"loading_s"];
-
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- cell.imgModel.image = img;
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.imgModel.image = img;
- }
- else
- cell.imgModel.image = [UIImage imageNamed:@"notfound_s"];
-
- });
- });
-
-
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- }else if([control isEqualToString:@"datepicker"])
- {
-
- CellIdentifier = @"CommonEditorCellEnum";
- CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
-
- NSString* value =[item_json valueForKey:@"value"];
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
- cell.labelTitle.text=title;
-
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
- cell.labelValue.text = value;
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else if([control isEqualToString:@"monthpicker"])
- {
-
- CellIdentifier = @"CommonEditorCellEnum";
- CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
-
- NSString* value =[item_json valueForKey:@"value"];
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
- cell.labelTitle.text=title;
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
- cell.labelValue.text = value;
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else if([control isEqualToString:@"signature"])
- {
-
- CellIdentifier = @"CommonEditorCellSignature";
- CommonEditorCellSignature * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
-
-
-
- cell.labelTitle.text = title;
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
-
- NSString* img_url = [item_json valueForKey:@"avalue"];
-
-
-
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- cell.imageviewSignature.image=img ;
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.imageviewSignature.image=img ;
- }
- else
- cell.imageviewSignature.image=[UIImage imageNamed:@"taptosign_s"];
-
-
- });
- });
-
-
- } cell.backgroundColor = [UIColor whiteColor];
- return cell;
- // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- //cell.imageviewSignature.image = image;
- }
- else
- {
- CellIdentifier = @"CommonEditorCellEdit";
- UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- }
- - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
-
- NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
- if(value==nil)
- value=@"";
- unsigned long color = strtoul([value UTF8String],0,16);
-
-
- NSString* btntitle=nil ;
- NSString*labeltitle = nil;
- NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy];
-
- labeltitle= [sectionjson valueForKey:@"title"];
-
- bool hide = [[sectionjson valueForKey:@"hide"]boolValue];
- if(hide)
- {
- btntitle=@"Show";
- // [section setValue:@"false" forKey:@"hide"];
- // [sender setTitle:@"Show" forState:UIControlStateNormal];
- }
- else{
- btntitle=@"Hide";
- }
-
- DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // myView.backgroundColor = [UIColor whiteColor];//UIColorFromRGB(0x996633);;
- myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
- myView.layer.shadowColor = [UIColor blackColor].CGColor;
- myView.layer.shadowOffset = CGSizeMake(0, 0);
- myView.layer.shadowOpacity = 0.5;
- myView.layer.shadowRadius = 2.0;
-
- int linespace=0;
- if(section==0)
- linespace=11;
-
- UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0+linespace, 50, 33)];
- btn.tag=section;
- // [btn setTitleColor:UIColorFromRGB(0x996633) forState:UIControlStateNormal];
- [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
- [btn setTitle:btntitle forState:UIControlStateNormal];
- [myView addSubview:btn];
-
-
- btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
- myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
-
-
- UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5+linespace, 200, 20)];
- titlelabel.textColor=UIColorFromRGB(color);//[UIColor whiteColor];
- titlelabel.backgroundColor = [UIColor clearColor];
- titlelabel.text=NSLocalizedString(labeltitle, nil);
- titlelabel.font = [UIFont boldSystemFontOfSize:20];
- [titlelabel sizeToFit];
- [myView addSubview:titlelabel];
- //
- // UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 0, 90, 22)];
- // contactlabel.textColor=[UIColor whiteColor];
- // contactlabel.backgroundColor = [UIColor clearColor];
- // contactlabel.text=NSLocalizedString(@"Contact", nil);
- // [contactlabel sizeToFit];
- // [myView addSubview:contactlabel];
- //
- //
- // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 0, 90, 22)];
- // modellabel.textColor=[UIColor whiteColor];
- // modellabel.backgroundColor = [UIColor clearColor];
- // modellabel.text=NSLocalizedString(@"Model", nil);
- // [modellabel sizeToFit];
- // [myView addSubview:modellabel];
- //
- // UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(500, 0, 90, 22)];
- // pricelabel.textColor=[UIColor whiteColor];
- // pricelabel.backgroundColor = [UIColor clearColor];
- // pricelabel.text=NSLocalizedString(@"Price", nil);
- // [pricelabel sizeToFit];
- // [myView addSubview:pricelabel];
- //
- //
- //
- // UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(630, 0, 90, 22)];
- // timelabel.textColor=[UIColor whiteColor];
- // timelabel.backgroundColor = [UIColor clearColor];
- // timelabel.text=NSLocalizedString(@"Create time", nil);
- // [timelabel sizeToFit];
- // [myView addSubview:timelabel];
- //
- //
- //
- // UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 60, 22)];
- // statuslabel.textColor=[UIColor whiteColor];
- // statuslabel.backgroundColor = [UIColor clearColor];
- // statuslabel.text=NSLocalizedString(@"Status", nil);
- // [statuslabel sizeToFit];
- // [myView addSubview:statuslabel];
- //
- return myView;
- }
- //
- -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue];
- DebugLog(@"tableView willSelectRowAtIndexPath");
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString* control = [item_json valueForKey:@"control"];
- if([control isEqualToString:@"enum"])//||[control isEqualToString:@"ui"])
- {
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- return nil;
- // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
- NSDictionary* cadedate_json = [item_json objectForKey:@"cadedate"];
- // NSDictionary* value_json = [item_json objectForKey:@"value"];
- NSString* single_select = [item_json valueForKey:@"single_select"];
- // NSString* required =[item_json valueForKey:@"required"];
- NSString* title = [item_json valueForKey:@"aname"];
-
-
- int max_select = [[item_json valueForKey:@"max"] intValue];
-
- EnumSelectViewController* enumvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
- enumvc.delegate = self;
- enumvc.max_select = max_select;
- enumvc.updatePosition = indexPath;
- // if([[required lowercaseString] isEqualToString:@"true"])
- // enumvc.canbeEmpty = false;
- // else
- // enumvc.canbeEmpty =true;
- enumvc.cadedate = [cadedate_json mutableCopy];
- enumvc.title = title;
- // enumvc.value = [value_json mutableCopy];
- enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"];
-
- [self.navigationController pushViewController:enumvc animated:true];
-
- }else if([control isEqualToString:@"action"])
- {
- NSString* value = [item_json valueForKey:@"value"];
- if([value isEqualToString:@"new_addr"])
- {
- AddressEditorViewController * addressVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AddressEditorViewController"];
-
- addressVC.url_type = URL_REMOTE;
-
- addressVC.request_url=URL_ADDRESS_EDOTOR;
-
-
-
-
- NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
- // NSString * string = [checked componentsJoinedByString:@","];
- // [params setValue:string forKey:@"cart2Checkbox"];
-
-
-
-
- addressVC.params = params;
-
-
- addressVC.delegate = self;
-
- addressVC.from = indexPath;
- // orderinfoVC.params = params;
-
- [self.navigationController pushViewController:addressVC animated:true];
-
- }else if([value isEqualToString:@"credit_card"])
- {
- CreditCardEditorViewController * cardVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreditCardEditorViewController"];
-
-
- NSDictionary *data = [item_json objectForKey:@"data"];
-
- if(data!=nil)
- {
-
- cardVC.content_data_download = [data mutableCopy];
- cardVC.url_type = URL_NONE;
-
- cardVC.request_url=nil;
- }
- else
- {
- cardVC.url_type = URL_REMOTE;
-
- cardVC.request_url=URL_CREDITCARD_EDOTOR;
- }
- NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
-
- params[@"orderCode"]=appDelegate.order_code;
- cardVC.params = params;
-
- cardVC.delegate = self;
-
- cardVC.from = indexPath;
-
-
- // orderinfoVC.params = params;
-
- [self.navigationController pushViewController:cardVC animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
- {
-
-
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Ship_From"])
- {
-
-
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
-
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Customer"])
- {
-
-
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
-
- cvc.contact_type = value;
- cvc.showNavibar = true;
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
- {
-
-
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
-
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Contact_Return_To"])
- {
-
-
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
-
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Ship_To"])
- {
-
-
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
-
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
-
- }
- else if([control isEqualToString:@"datepicker"])
- {
-
-
- // NSString* title = [item_json valueForKey:@"aname"];
-
- NSString* value =[item_json valueForKey:@"value"];
- NSString* type =[item_json valueForKey:@"type"];
-
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
-
-
-
-
- DatePickerViewController* dpvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"DatePickerViewController"];
- if([[type lowercaseString] isEqualToString:@"date"])
- {
- dpvc.pickerMode = UIDatePickerModeDate;
- [dateFormatter setDateFormat:@"yyyy/MM/dd"];
- }
- else if([[type lowercaseString] isEqualToString:@"time"])
- {
- dpvc.pickerMode = UIDatePickerModeTime;
- [dateFormatter setDateFormat:@"HH:mm:ss"];
- }
- else
- {
- dpvc.pickerMode = UIDatePickerModeDateAndTime;
- [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
- }
- NSDate *date = [dateFormatter dateFromString:value];
- dpvc.date = date;
- dpvc.formatter = dateFormatter;
- dpvc.labelTime.text = value;
- [self.navigationController pushViewController:dpvc animated:true];
-
- }else if([control isEqualToString:@"monthpicker"])
- {
-
-
- // NSString* title = [item_json valueForKey:@"aname"];
-
- NSString* value =[item_json valueForKey:@"value"];
- if (value==nil || value.length==0)
- {
- value=@"1/2015";
- }
- // NSString* type =[item_json valueForKey:@"type"];
-
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
-
-
-
-
- MonthPickerViewController* mpvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"MonthPickerViewController"];
- // if([[type lowercaseString] isEqualToString:@"date"])
- // {
- // dpvc.pickerMode = UIDatePickerModeDate;
- [dateFormatter setDateFormat:@"MM/yyyy"];
- NSDate *date = [dateFormatter dateFromString:value];
-
- mpvc.current_date =date;
- mpvc.updatePosition = indexPath;
- mpvc.delegate = self;
- // }
- // else if([[type lowercaseString] isEqualToString:@"time"])
- // {
- // dpvc.pickerMode = UIDatePickerModeTime;
- // [dateFormatter setDateFormat:@"HH:mm:ss"];
- // }
- // else
- // {
- // dpvc.pickerMode = UIDatePickerModeDateAndTime;
- // [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
- // }
- // NSDate *date = [dateFormatter dateFromString:value];
- // dpvc.date = date;
- // dpvc.formatter = dateFormatter;
- // dpvc.labelTime.text = value;
- [self.navigationController pushViewController:mpvc animated:true];
-
- }
- else if([control isEqualToString:@"signature"])
- {
- // SignatureViewController * signvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"SignatureViewController"];
- // signvc.title = [item_json valueForKey:@"aname"];
- // signvc.indexPath = indexPath;
- // // signvc.delegate = self;
- // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- //
- // signvc.existSignature = cell.imageviewSignature.image ;
- //
- //
- //
- // [self.navigationController pushViewController:signvc animated:true];
-
-
- __block UIImage* signimg=nil;
- SignatureViewController * vc =[ self.storyboard instantiateViewControllerWithIdentifier:@"SignatureViewController"];
-
- vc.onReturnImg = ^(UIImage* img)
- {
- signimg = img;
-
- if(signimg!=nil)
- {
- if(appDelegate.offline_mode)
- {
-
-
-
- NSData *data = [OLDataProvider offline_saveBusinesscard:UIImagePNGRepresentation(img)];;
-
- // 再将NSData转为字符串
- NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-
- // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-
- DebugLog(@"data string: %@",jsonStr);
- NSError *error=nil;
- NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
-
-
-
-
-
-
- //NSMutableArray* arr_ret = [[NSMutableArray alloc] init];
- if([[json valueForKey:@"result"] intValue]==2)
- {
- NSString* img_url_down = json[@"img_url_aname"];
- // if(img_url_down.length==0)
- // img_url_down=@"";
- NSString* img_url_up = json[@"img_url"];
- // if(img_url_up.length==0)
- // img_url_up=@"";
-
- NSMutableDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
-
- [item_json setValue:img_url_down forKey:@"avalue"];
- [item_json setValue:img_url_up forKey:@"value"];
- [item_json setValue:@"true" forKey:@"dirty"];
- NSMutableDictionary* section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
-
- CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
-
- cell.imageviewSignature.image = signimg;
-
-
- }
- else
- {
- [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
- }
- }
- else
- {
- NSData *imageData = UIImagePNGRepresentation(img);
-
- AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
-
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.user!=nil)
- [params setValue:appDelegate.user forKey:@"user"];
- // if(appDelegate.contact_id!=nil)
- // [params setValue:appDelegate.contact_id forKey:@"contactId"];
- if(appDelegate.password!=nil)
- [params setValue:appDelegate.password forKey:@"password"];
-
-
- NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_IMG parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
- [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test.jpg" mimeType:@"image/png"];
- } error:nil];
-
-
-
- AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
-
-
-
-
- NSProgress *progress = nil;
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Upload Signature"];
- NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
-
- // [progress removeObserver:self forKeyPath:@"fractionCompleted"];
-
-
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
- if (error) {
-
- NSString* err_msg = [error localizedDescription];
- DebugLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
-
-
- NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-
- DebugLog(@"data string: %@",str);
-
- [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:self] ;
-
- } else {
- DebugLog(@"response ");
-
-
-
- NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
-
- // 再将NSData转为字符串
- NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-
- // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-
- DebugLog(@"data string: %@",jsonStr);
-
- NSDictionary* json = responseObject;
-
-
- //NSMutableArray* arr_ret = [[NSMutableArray alloc] init];
- if([[json valueForKey:@"result"] intValue]==2)
- {
- NSString* img_url_down = json[@"img_url_aname"];
- // if(img_url_down.length==0)
- // img_url_down=@"";
- NSString* img_url_up = json[@"img_url"];
- // if(img_url_up.length==0)
- // img_url_up=@"";
-
- NSMutableDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
-
- [item_json setValue:img_url_down forKey:@"avalue"];
- [item_json setValue:img_url_up forKey:@"value"];
- [item_json setValue:@"true" forKey:@"dirty"];
- NSMutableDictionary* section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
-
- CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
-
- cell.imageviewSignature.image = signimg;
-
-
- }
- else
- {
- [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
- }
-
-
-
-
-
-
- }
- //
- }];
-
- [uploadTask resume];
- }
- }
-
-
- };
-
-
- [self.navigationController pushViewController:vc animated:true];
- }
- // else if([control isEqualToString:@"action "])
- // {
- //
- // DebugLog(@"action push");
- // // SignatureViewController * signvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"SignatureViewController"];
- // // signvc.title = [item_json valueForKey:@"aname"];
- // // signvc.indexPath = indexPath;
- // // signvc.delegate = self;
- // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- // //
- // // signvc.existSignature = cell.imageviewSignature.image ;
- // //
- // //
- // //
- // // [self.navigationController pushViewController:signvc animated:true];
- // }
- return nil;
- }
- //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- //{
- //
- // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
- //
- // NSString* orderid = [item_json valueForKey:@"id"];
- //
- // // if (self.delegate && [self.delegate respondsToSelector:@selector(SelectOrder:)]) {
- // // [self.delegate SelectOrder:orderid];
- // // }
- // //
- // // [self dismissViewControllerAnimated:YES
- // // completion:^{
- // // //一定要移除手势 否则下次 没有子视图的时候 点击 会崩溃拉
- // // AppDelegate *app = [[UIApplication sharedApplication] delegate];
- // // [app.window removeGestureRecognizer:self.tapGesture];
- // // }];
- // // [pvc categoryMenuSelected:indexPath.row];
- //}
- #pragma mark monthpicker ViewControllerDelegate
- -(void) MPValueChanged:(NSString *)value indexPath :(NSIndexPath*) indexPath
- {
- CommonEditorCellEnum * cell= (CommonEditorCellEnum*) [self.editorTable cellForRowAtIndexPath:indexPath];
-
- cell.labelValue.text = value;
-
-
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
-
-
- // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- // UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview;
- // NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
-
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- // NSString* check=@"false";
- // if([paramSender isOn])
- // check=@"true";
- // [item_json setValue:value forKey:@"dirty"];
-
-
-
- NSString* subid=[item_json valueForKey:@"subid"];
- [item_json setValue:value forKey:@"value"];
-
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- NSString* control_type= [olditem valueForKey:@"control"];
- if([control_type isEqualToString:@"enum"])
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- else if([control_type isEqualToString:@"switch"])
- item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- [self.editorTable reloadData ];
- }
- #pragma mark EnumSelectViewControllerDelegate
- -(void) setEnumValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
- {
- NSMutableDictionary* section_json=nil;
-
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
-
-
-
- int refresh = [[item_json valueForKey:@"refresh"] intValue];
-
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSString* subid=[item_json valueForKey:@"subid"];
-
- [item_json setObject:value forKey:@"cadedate"];
-
-
- if(subid==nil)
- {
- [item_json setValue:@"true" forKey:@"dirty"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
-
-
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
-
-
- if(refresh==1)
- {
-
-
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger] ;
- return ;
- }
-
-
- DebugLog(@"CONTENT UPDATE:%@",[iSalesNetwork DataTOjsonString:self.content_data_download]);
-
-
-
- // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- [self.editorTable reloadData ];
- }
- -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
- {
-
-
- UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
-
-
- // if(/*self.cancommit==false &&*/ string.length==0 && (textField.text.length<=1|| textField.text==nil))
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor redColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- // else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
-
- DebugLog(@"enum changed %ld_%ld",(long)indexPath.section,(long)indexPath.row);
-
- [self setEnumValue:value indexPath:indexPath];
-
- }
- -(NSMutableDictionary*) enum_subitem_changed:(NSMutableDictionary *) item subid:(NSArray*) subid value:(NSMutableDictionary*)value step:(int) step
- {
- int index = [(NSString*)subid[step] intValue];
- NSMutableDictionary * cadedate= [[item objectForKey:@"cadedate"] mutableCopy];
- NSMutableDictionary * subitem= [[item objectForKey:@"sub_item"] mutableCopy];
- if(cadedate!=nil)
- {
- NSMutableDictionary * valjson=[[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",index]]mutableCopy];
- valjson= [self enum_subitem_changed:valjson subid:subid value:value step:step+1];
-
-
- [cadedate setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",index]];
- [item setObject:cadedate forKey:@"cadedate"];
- return item;
- }
- else if(subitem!=nil)
- {
- NSMutableDictionary * itemjson=[[subitem objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy];
- if(step==subid.count-1)
- {
- itemjson =value;
-
- }
- else
- itemjson =[self enum_subitem_changed:itemjson subid:subid value:value step:step+1];
-
- [subitem setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]];
- [item setObject:subitem forKey:@"sub_item"];
- return item;
- }
- return nil;
-
- }
- //#pragma mark SignatureViewControllerDelegate
- ////-(void)SignatureVCReturnData:(NSData *)imagedata indexPath:(NSIndexPath *)indexPath
- ////{
- ////
- ////}
- //-(void)SignatureVCReturnImage:(UIImage *)image indexPath:(NSIndexPath *)indexPath
- //{
- //
- // // NSMutableDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- // //
- // // if(image==nil)
- // // [item_json removeObjectForKey:@"signature"];
- // // else
- // // [item_json setObject:image forKey:@"signature"];
- // // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // // [self.content_data setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // //
- // //
- // //
- // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- // // cell.imageviewSignature.image = image;
- //}
- #pragma mark textView delegate
- //- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
- //- (BOOL)textViewShouldEndEditing:(UITextView *)textView;
- - (BOOL)textViewShouldBeginEditing:(UITextView *)textView
- {
-
- DebugLog(@"textViewShouldBeginEditing");
-
- self.editingcell = (UITableViewCell*)textView.superview.superview;
- return textView.editable;
- }
- - (void)textViewDidBeginEditing:(UITextView *)textView
- {
- self.lasttextview = textView;
-
- UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
- self.lasttextview_from = [self.editorTable indexPathForCell:cell];
-
-
-
- }
- - (void)textViewDidEndEditing:(UITextView *)textView
- {
- // UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
- NSIndexPath * indexPath = self.lasttextview_from;//[self.editorTable indexPathForCell:cell];
-
-
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- NSString* subid=[item_json valueForKey:@"subid"];
-
-
- [item_json setValue:@"true" forKey:@"dirty"];
- [item_json setValue:textView.text forKey:@"value"];
-
-
- // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- NSString* control_type= [olditem valueForKey:@"control"];
- if([control_type isEqualToString:@"enum"])
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- else if([control_type isEqualToString:@"switch"])
- item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
- self.lasttextview = nil;
- self.lasttextview_from=nil;
- // if(self.resize)
- // {
- // NSTimeInterval animationDuration = 0.30f;
- // CGRect frame = self.view.frame;
- // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
- // // { //还原界面
- // // moveY = prewMoveY;
- // frame.origin.y +=self.ioffset;
- // frame.size. height -=self.ioffset;
- // self.view.frame = frame;
- // // }
- // //self.view移回原位置
- // [UIView beginAnimations:@"ResizeView" context:nil];
- // [UIView setAnimationDuration:animationDuration];
- // self.view.frame = frame;
- // [UIView commitAnimations];
- // //[textField resignFirstResponder];
- // self.ioffset=0;
- // }
-
- }
- - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
- {
-
-
-
-
- UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
-
- NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
- // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
-
- NSString* required = [item_json valueForKey:@"required"];
-
- if([required isEqualToString:@"true"] && text.length==0 && (textView.text.length<=1|| textView.text==nil))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
-
-
- return YES;
- }
- //- (void)textViewDidChange:(UITextView *)textView;
- //
- //- (void)textViewDidChangeSelection:(UITextView *)textView;
- //
- //- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
- //- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
- #pragma mark textField delegate
- -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
-
- DebugLog(@"textField shouldChangeCharactersInRange");
- DebugLog(@"text:%@",textField.text);
-
-
-
-
-
- CommonEditorCellEdit *cell = (CommonEditorCellEdit *) textField.superview.superview;
-
- NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
- // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
-
- NSString* required = [item_json valueForKey:@"required"];
-
-
-
- if([required isEqualToString:@"true"] && string.length==0 && (textField.text.length<=1|| textField.text==nil))
- {
-
-
-
-
-
-
- CALayer *layer = cell.labelTitle.layer;
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
-
- layer = cell.starMark.layer;
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- //UIImageView * iv =
- cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_attention_24"]];
- cell.textfield.rightViewMode=UITextFieldViewModeUnlessEditing;
- textField.layer.cornerRadius=8.0f;
- textField.layer.borderWidth= 1.0f;
- textField.layer.masksToBounds=YES;
- textField.layer.borderColor=[[UIColor redColor]CGColor];
- }
- else
- {
- CALayer *layer = cell.labelTitle.layer;//[cell.contentView layer];
-
-
-
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
-
-
- layer = cell.starMark.layer;//[cell.contentView layer];
-
-
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
-
- //cell.textfield.layer.borderColor= [[UIColor lightGrayColor] CGColor];
- //UIImageView * iv =
- // cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_wish_16"]];
- cell.textfield.rightViewMode=UITextFieldViewModeNever;
- textField.layer.cornerRadius=8.0f;
- textField.layer.borderWidth= 1.0f;
- textField.layer.masksToBounds=YES;
- textField.layer.borderColor=[[UIColor lightGrayColor]CGColor];
- }
-
- //
- // if([required isEqualToString:@"true"] && string.length==0 && (textField.text.length<=1|| textField.text==nil))
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor redColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- // else
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor clearColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
-
-
- NSString* keyboard = [item_json valueForKey:@"keyboard"];
- if(![keyboard isEqualToString:@"number"] && ![keyboard isEqualToString:@"int"])
- return TRUE;
- NSCharacterSet *cs;
- if([keyboard isEqualToString:@"number"])
- cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
- else
- cs = [[NSCharacterSet characterSetWithCharactersInString:INTNUMBERS]invertedSet];
-
- NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
-
- BOOL canChange = [string isEqualToString:filtered];
-
- int lenth = [[item_json valueForKey:@"length"] intValue];
- if(lenth==0)
- return canChange;
- else
- {
- return canChange&& (lenth>textField.text.length ||[string isEqualToString:@""]);
- }
- }
- - (void)textFieldDidEndEditing:(UITextField *)textField
- {
-
- DebugLog(@"textFieldDidEndEditing");
- // UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
- NSIndexPath * indexPath = self.lastedit_from;
-
- [self textfieldSetValue:indexPath value:textField.text];
- // NSMutableDictionary* section_json=nil;
- //
- //
- //
- // textField.text = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
- //
- // // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
- //
- // NSString* subid=[item_json valueForKey:@"subid"];
- // NSString* refresh_trigger = [item_json valueForKey:@"name"];
- //
- // [item_json setValue:@"true" forKey:@"dirty"];
- // [item_json setValue:textField.text forKey:@"value"];
- // if([[item_json valueForKey:@"keyboard"] isEqualToString:@"number"])
- // {
- // float f = [ textField.text floatValue];
- // [item_json setValue:[NSString stringWithFormat:@"%.2f",f] forKey:@"value"];
- //
- // }
- //
- // // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
- // if(subid==nil)
- // {
- // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- // int count=0;
- //
- // count=[[section_json valueForKey:@"count"] intValue];
- //
- // for(int i=0;i<count;i++)
- // {
- // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
- //
- //
- // }
- //
- //
- // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- //
- // int refresh = [[item_json valueForKey:@"refresh"] intValue];
- //
- // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- // bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
- // if(refresh==1)
- // {
- //
- // if(restore_json!=nil)
- // {
- // int rc=[[restore_json valueForKey:@"count"] intValue];
- // for(int ir=0;ir<rc;ir++)
- // {
- // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
- //
- //
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- //
- // if([[itemjson valueForKey:@"name"] isEqualToString:name])
- // {
- // [itemjson removeObjectForKey:@"dirty"];
- // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- // }
- //
- // }
- // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- // }
- //
- //
- // }
- //
- // }
- // [self refresh:refresh_trigger] ;
- //
- // }
- // else if(partial_refresh)
- // {
- // NSString* name = [item_json valueForKey:@"name"] ;
- // NSString* url = [item_json valueForKey:@"data_interface"] ;
- //
- //
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- //
- // [params setValue:textField.text forKey:name];
- //
- //
- // UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* editor_json = [iSalesNetwork commoneditor_partialrefresh:params url:url];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- //
- //
- // if([[editor_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // int prcount = [[editor_json valueForKey:@"count"] intValue];
- // for(int ipr=0;ipr<prcount;ipr++)
- // {
- // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
- // NSString* name = [pr_item valueForKey:@"name"];
- // NSString* value = [pr_item valueForKey:@"value"];
- //
- // [self setValue:name value:value];
- // }
- //
- //
- // }
- // else
- // {
- // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
- // }
- //
- //
- // });
- // });
- //
- //
- //
- // }
- // self.lastedit = nil;
- // self.lastedit_from=nil;
- // return ;
- // }
- // else
- // {
- // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- // int section = [(NSString*)idarr[0] intValue];
- // int item=[(NSString*)idarr[1] intValue];
- //
- //
- // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- //
- // NSString* control_type= [olditem valueForKey:@"control"];
- // NSMutableDictionary* new_item=nil;
- // [item_json setValue:@"true" forKey:@"dirty"];
- // if([control_type isEqualToString:@"enum"])
- // new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- // else if([control_type isEqualToString:@"switch"])
- // new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- //
- // [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
- //
- //
- // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- //
- // int refresh = [[item_json valueForKey:@"refresh"] intValue];
- //
- // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- // bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
- // if(refresh==1)
- // {
- //
- // if(restore_json!=nil)
- // {
- // int rc=[[restore_json valueForKey:@"count"] intValue];
- // for(int ir=0;ir<rc;ir++)
- // {
- // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
- //
- //
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- //
- // if([[itemjson valueForKey:@"name"] isEqualToString:name])
- // {
- // [itemjson removeObjectForKey:@"dirty"];
- // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- // }
- //
- // }
- // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- // }
- //
- //
- // }
- //
- // }
- // [self refresh:refresh_trigger] ;
- //
- // }
- // else if(partial_refresh)
- // {
- // NSString* name = [item_json valueForKey:@"name"] ;
- // NSString* url = [item_json valueForKey:@"data_interface"] ;
- //
- //
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- //
- // [params setValue:textField.text forKey:name];
- //
- //
- // UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* editor_json = [iSalesNetwork commoneditor_partialrefresh:params url:url];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- //
- //
- // if([[editor_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // int prcount = [[editor_json valueForKey:@"count"] intValue];
- // for(int ipr=0;ipr<prcount;ipr++)
- // {
- // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
- // NSString* name = [pr_item valueForKey:@"name"];
- // NSString* value = [pr_item valueForKey:@"value"];
- //
- // [self setValue:name value:value];
- // }
- //
- // }
- // else
- // {
- // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
- // }
- //
- //
- // });
- // });
- //
- //
- //
- // }
- // self.lastedit = nil;
- // self.lastedit_from=nil;
- //
- // return;
- // }
- //
-
-
- }
- - (void)textFieldDidBeginEditing:(UITextField *)textField
- {
- DebugLog(@"textField shouldChangeCharactersInRange");
-
- self.lastedit = textField;
- UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
- self.lastedit_from = [self.editorTable indexPathForCell:cell];
- }
- #pragma mark- img changed
- // image 改变时执行
- - (void) imgIsChanged:(NSString *)url_down url_up:(NSString *)url_up indexPath: (NSIndexPath *) indexPath index:(int)index url_index:(NSString* )url_index{
- // DebugLog(@"Sender is = %@", url);
-
-
-
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- int refresh = [[item_json valueForKey:@"refresh"] intValue];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSString* subid=[item_json valueForKey:@"subid"];
-
-
- // NSArray* imgs=[RAUtils string2arr:url_up separator:@","];
-
-
- // imgs[index];
- item_json[ [NSString stringWithFormat:@"img_url_%d",index]]=url_down;
- item_json[@"avalue"]=url_up;
- item_json[[NSString stringWithFormat:@"img_url_aname_%d",index]]=url_index;
- [item_json setValue:@"true" forKey:@"dirty"];
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
-
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
- self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
-
- // NSRange range = NSMakeRange(indexPath.section, 1);
- // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
-
-
- if(refresh==1)
- {
- [self refresh:refresh_trigger];
- }
- }
- #pragma mark- switch changed
- - (void) switchIsChanged:(UISwitch *)paramSender{
-
-
- // [self.switchlock lock];
- // DebugLog(@"switch lock");
-
-
- UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview;
- NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
- if(indexPath==nil)
- {
- [paramSender setOn:!paramSender.isOn];
- return ;
- }
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- int refresh = [[item_json valueForKey:@"refresh"] intValue];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSString* subid=[item_json valueForKey:@"subid"];
- NSString* check=@"false";
- if([paramSender isOn])
- check=@"true";
- [item_json setValue:@"true" forKey:@"dirty"];
- [item_json setValue:check forKey:@"value"];
-
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
-
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
- self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
-
- NSRange range = NSMakeRange(indexPath.section, 1);
- NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
-
-
- if(refresh==1)
- {
- [self refresh:refresh_trigger];
- }
- DebugLog(@"switch unlock");
- // [self.switchlock unlock];
- }
- -(NSMutableDictionary*) fill_switch_subitem:(NSMutableDictionary *) switch_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step
- {
- NSString* value = [switch_item valueForKey:@"value"];
- NSMutableDictionary* boolitem=nil;
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- {
- boolitem =[[switch_item objectForKey:@"true"] mutableCopy];
-
- }
- else
- {
- boolitem =[[switch_item objectForKey:@"false"] mutableCopy];
-
- }
- subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
-
-
-
- // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
- NSString* mapto = [modify_item valueForKey:@"name"];
- if(mapto.length==0)
- continue;
- NSString* valuefrom= [mapping valueForKey:[modify_item valueForKey:@"name"]];
- if(valuefrom==nil)
- continue;
- NSString* valuestr= [source valueForKey:valuefrom];
-
- if(TRUE)
- {
-
- if(valuestr.length>0)
- [modify_item setValue:valuestr forKey:@"value"];
- else
- [modify_item setValue:@"" forKey:@"value"];
-
- [modify_item setValue:@"true" forKey:@"dirty"];
- [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]];
- }
- }
-
- [boolitem setObject:subjson forKey:@"sub_item"];
-
- if([value isEqualToString:@"true"])
-
- [switch_item setObject:boolitem forKey:@"true"];
-
- else
- [switch_item setObject:boolitem forKey:@"false"];
-
- }
- return switch_item;
-
- }
- -(NSMutableDictionary*) fill_enum_subitem:(NSMutableDictionary *) enum_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step
- {
- NSMutableDictionary* cadedatejson = [[enum_item objectForKey:@"cadedate"] mutableCopy];
- int count = [[cadedatejson valueForKey:@"count"]intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* val_json = [[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",i]] mutableCopy];
- int check = [[val_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- NSMutableDictionary* subjson=[[val_json objectForKey:@"sub_item"] mutableCopy];
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
- // NSString* subid=[modify_item valueForKey:@"subid"];
- //
- //
- // NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
-
- NSString* control_type = [modify_item valueForKey:@"control"];
- if([control_type isEqualToString:@"switch"])
- modify_item= [self fill_switch_subitem:modify_item subid:nil source:source mapping:mapping ];
- else if([control_type isEqualToString:@"enum"])
- {
- modify_item= [self fill_enum_subitem:modify_item subid:nil source:source mapping:mapping ];
-
- }
- else
- {
- NSString* mapto = [modify_item valueForKey:@"name"];
- if(mapto.length==0)
- continue;
- NSString* valuefrom= [mapping valueForKey:[modify_item valueForKey:@"name"]];
- if(valuefrom==nil)
- continue;
- NSString* valuestr= [source valueForKey:valuefrom];
-
- if(true)
- {
- if(valuestr.length>0)
- [modify_item setValue:valuestr forKey:@"value"];
- else
- [modify_item setValue:@"" forKey:@"value"];
- //[modify_item setValue:valuestr forKey:@"value"];
-
- // [modify_item setValue:@"true" forKey:@"dirty"];
-
- }
- }
-
- [modify_item setValue:@"true" forKey:@"dirty"];
- [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]];
- // [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
-
-
- // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
-
-
- }
- [val_json setObject:subjson forKey:@"sub_item"];
- }
-
-
- }
- [cadedatejson setObject:val_json forKey:[NSString stringWithFormat:@"val_%d",i]];
-
- }
- [enum_item setObject:cadedatejson forKey:@"cadedate"];
- return enum_item;
-
- }
- -(NSMutableDictionary*) switch_subitem_changed:(NSMutableDictionary *) switch_item subid:(NSArray*) subid value:(NSMutableDictionary*)valuejson step:(int) step
- {
- int index = [(NSString*)subid[step] intValue];
- NSString* value = [switch_item valueForKey:@"value"];
-
- NSMutableDictionary* boolitem=nil;
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- {
- boolitem =[[switch_item objectForKey:@"true"] mutableCopy];
-
- }
- else
- {
- boolitem =[[switch_item objectForKey:@"false"] mutableCopy];
-
- }
- subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
-
-
-
- if(subjson!=nil)
- {
- NSMutableDictionary * itemjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy];
- if(step==subid.count-1)
- {
- itemjson =valuejson;
-
- }
- [subjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]];
- [boolitem setObject:subjson forKey:@"sub_item"];
-
- if([value isEqualToString:@"true"])
-
- [switch_item setObject:boolitem forKey:@"true"];
-
- else
- [switch_item setObject:boolitem forKey:@"false"];
-
-
- return switch_item;
- }
- return nil;
-
- }
- #pragma mark -
- #pragma mark Responding to keyboard events
- - (void)keyboardWillChangeFrame:(NSNotification *)notification {
- DebugLog(@"keyboardWillChangeFrame");
- }
- - (void)keyboardWillShow:(NSNotification *)notification {
- DebugLog(@"keyboardWillShow");
-
- if(self.keyboard_show)
- return;
-
- self.keyboard_show=true;
- /*
- Reduce the size of the text view so that it's not obscured by the keyboard.
- Animate the resize so that it's in sync with the appearance of the keyboard.
- */
-
- NSDictionary *userInfo = [notification userInfo];
-
- // Get the origin of the keyboard when it's displayed.
- NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
-
- // 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.
- // CGRect keyboardRect = [aValue CGRectValue];
- CGSize keyboardSize = [aValue CGRectValue].size;
- DebugLog(@"keyboard height:%f",keyboardSize.height);
- // Get the duration of the animation.
- NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
- NSTimeInterval animationDuration;
- [animationDurationValue getValue:&animationDuration];
-
-
- // if(self.keyboard_h==0)
- // {
- self.keyboard_h =keyboardSize.height;
- CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:self.editingcell];
- CGRect rect_screen = [ UIScreen mainScreen ].bounds;
-
- // int vpos =self.view.frame.origin.y+self.view.frame.size.height;
- // int loginpos = self.editingcell.frame.origin.y+self.editingcell.frame.size.height;
- //
- int cellpos = cellrect_screen.origin.y+cellrect_screen.size.height;
- // screen.size.height-keyboardSize.height-(cellpos_screen.origin.x+cellpos_screen.size.height);
- 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);
- if(self.ioffset>0)
- {
- // self.resize = true;
-
-
- CGPoint contentOffsetPoint = self.editorTable.contentOffset;
-
-
- contentOffsetPoint.y+=self.ioffset;
-
- self.editorTable.contentOffset=contentOffsetPoint;
-
-
- // NSTimeInterval animationDuration = 0.30f;
- // CGRect frame = self.view.frame;
- // frame.origin.y -=self.ioffset;//view的Y轴上移
- // frame.size.height +=self.ioffset; //View的高度增加
- // self.view.frame = frame;
- // [UIView beginAnimations:@"ResizeView" context:nil];
- // [UIView setAnimationDuration:animationDuration];
- // self.view.frame = frame;
- // [UIView commitAnimations];//设置调整界面的动画效果
- }
-
-
- self.editorTable.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-self.keyboard_h);
-
- // CGSize tablecontent =self.editorTable.contentSize;
- // tablecontent.height=tablecontent.height+self.keyboard_h;
- // self.editorTable.contentSize=tablecontent;
- // }
- // Animate the resize of the text view's frame in sync with the keyboard's appearance.
- // [self moveInputBarWithKeyboardHeight:keyboardRect.size.height withDuration:animationDuration];
- }
- - (void)keyboardWillHide:(NSNotification *)notification {
- DebugLog(@"keyboardWillHide");
-
- self.keyboard_show=false;
- NSDictionary* userInfo = [notification userInfo];
-
- /*
- Restore the size of the text view (fill self's view).
- Animate the resize so that it's in sync with the disappearance of the keyboard.
- */
- NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
- NSTimeInterval animationDuration;
- [animationDurationValue getValue:&animationDuration];
- CGSize tablecontent =self.editorTable.contentSize;
- tablecontent.height=tablecontent.height-self.keyboard_h;
- // self.editorTable.contentSize=tablecontent;
-
- self.editorTable.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
-
- self.keyboard_h= 0;
- DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
-
-
- // if(self.resize)
- // {
- // NSTimeInterval animationDuration = 0.30f;
- // CGRect frame = self.view.frame;
- // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
- // // { //还原界面
- // // moveY = prewMoveY;
- // frame.origin.y +=self.ioffset;
- // frame.size. height -=self.ioffset;
- // self.view.frame = frame;
- // // }
- // //self.view移回原位置
- // [UIView beginAnimations:@"ResizeView" context:nil];
- // [UIView setAnimationDuration:animationDuration];
- // self.view.frame = frame;
- // [UIView commitAnimations];
- // //[textField resignFirstResponder];
- // self.ioffset=0;
- // }
-
-
- // [self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration];
- }
- @end
|