CommonEditorViewController.m 289 KB

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