CommonEditorViewController.m 307 KB

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