CommonEditorViewController.m 257 KB

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