CommonEditorViewController.m 260 KB

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