CommonEditorViewController.m 272 KB

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