CommonEditorViewController.m 273 KB

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