CommonEditorViewController.m 289 KB

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