CommonEditorViewController.m 311 KB

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