CommonEditorViewController.m 292 KB

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