CommonEditorViewController.m 251 KB

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