CommonEditorViewController.m 283 KB

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