CommonEditorViewController.m 266 KB

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