CommonEditorViewController.m 249 KB

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