CommonEditorViewController.m 276 KB

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