CommonEditorViewController.m 283 KB

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