CommonEditorViewController.m 322 KB

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