CommonEditorViewController.m 303 KB

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