CommonEditorViewController.m 316 KB

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