CommonEditorViewController.m 273 KB

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