CommonEditorViewController.m 265 KB

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