CommonEditorViewController.m 269 KB

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