CommonEditorViewController.m 253 KB

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