PageRenderTime 122ms CodeModel.GetById 81ms app.highlight 1ms RepoModel.GetById 39ms app.codeStats 0ms

/SampleApplication/ColdBox3/handlers/artist.cfc

http://github.com/bobsilverberg/ValidateThisColdBoxPlugin
ColdFusion CFScript | 98 lines | 43 code | 20 blank | 35 comment | 1 complexity | ba46379217d363cec8aeb8d8eaf8edf5 MD5 | raw file
 1/**
 2* the artist handler
 3*/
 4component extends="model.abstract.AbstractHandler"
 5{
 6
 7	/*
 8	-------------------------------------------------------------------------
 9	dependancy injection
10	-------------------------------------------------------------------------
11	*/
12	property name="ArtistService" type="model:ArtistService" scope="instance";
13	
14	/*
15	-------------------------------------------------------------------------
16	public handlers
17	-------------------------------------------------------------------------
18	*/
19	
20	/**
21	* I am the default event
22	*/
23	void function index( event ) 
24	{
25		var rc = event.getCollection();
26		
27		// get all artists as an array
28		rc.artists = instance.ArtistService.getArtists();
29		// set view
30		arguments.Event.setView( "artist/index" );
31	}
32	
33	/**
34	* I delete artists
35	*/
36	void function delete( event ) 
37	{
38		var rc = event.getCollection();
39		
40		// delete the artist
41		instance.ArtistService.deleteArtistById( rc.artistid );
42		
43		// save message to flash memory
44		flash.put( "message", "Artist deleted" );
45		
46		// relocate
47		setNextEvent( "artist.index" );
48	}
49
50	/**
51	* I edit/add artists
52	*/
53	void function maintain( event ) 
54	{
55		var rc = arguments.Event.getCollection();
56		
57		// get artist by id. returns a new artist if id not found
58		arguments.event.paramValue( "artistid", "" );
59		rc.Artist = instance.ArtistService.getArtistById( rc.artistid );
60		
61		// need an empty validation result object for display
62		rc.ValidationResult = instance.ArtistService.newValidationResult();
63		
64		// get required fields
65		rc.RequiredFields = instance.ArtistService.getArtistRequiredFields();
66				
67		// set view
68		arguments.Event.setView( "artist/form" );
69	}
70
71	/**
72	* I save an artist
73	*/
74	void function save( event ) 
75	{
76		var rc = arguments.Event.getCollection();
77		
78		// note: using entityid instead of artistid so that populate() doesn't set the id to blank
79		var rc.Artist = instance.ArtistService.getArtistById( rc.entityid );
80
81		var SaveResult = instance.ArtistService.save( rc.Artist );
82		
83		if ( SaveResult.getIsSuccess() )
84		{
85			flash.put( "message", "Artist saved" );
86			setNextEvent( "artist.index" );
87		}
88		else
89		{
90			rc.ValidationResult = SaveResult;
91			rc.RequiredFields = instance.ArtistService.getArtistRequiredFields();
92			
93			arguments.Event.setView( "artist/form" );
94		}
95	
96	}
97
98}