<commit_before>component extends="super"
{
property name="tag"					inject="coldbox:myPlugin:tag@contentbox-gallerybuilder";

	function index(event,rc,prc)
	{
		checkGalleryPath();
		prc.galleries = galleryEntity.list(sortOrder="gallery_id ASC",asQuery=false);
		prc.moduleRoot = getModuleSettings( "contentbox-gallerybuilder" ).mapping;

		prc.myhtml = tag.span("nix drin");
		prc.myhtml = tag.span("<<", {class="gallery-builder-page-enabled"}, {lightbox="click here"});
		prc.myhtml = tag.span("<<", {class="gallery-builder-page-enabled"});

		event.setView(view="gallery/index", module="contentbox-gallerybuilder");
	}


	function editor(event, rc, prc)
	{
		prc.gallery = galleryEntity.get(event.getValue("gallery_id", 0));
		prc.images_in_table = "";
		for ( i = 1; i lte 10; i=i+1 )
			prc.images_in_table = ListAppend(prc.images_in_table, i, ",");
		prc.images_per_page = "";
		for ( i = 1; i lte 30; i=i+1 )
			prc.images_per_page = ListAppend(prc.images_per_page, i, ",");
		event.setView("gallery/editor");
	}


	function save(event,rc,prc)
	{
		var oGallery = populateModel( galleryEntity.get(id=rc.gallery_id) );
		if ( oGallery.getGallery_id() eq "" )
		{
			oGallery.setCreated_at(now());
		}
		else
		{
			oGallery.setUpdated_at(now());
		}
		if ( not event.valueExists("use_lightbox") )
		{
			oGallery.setUse_Lightbox(false);
		}
		var errors = oGallery.validate();
		if ( arrayLen(errors) eq 0 )
		{
			galleryEntity.save(oGallery);
			getPlugin("MessageBox").info("Gallery saved!");
			setNextEvent(event=prc.xehGallery,queryString="gallery_id=#oGallery.getGallery_id()#");
		}
		else
		{
			flash.persistRC(exclude="event");
			getPlugin("MessageBox").warn(messageArray=errors);
			setNextEvent(event=prc.xehGalleryEditor,queryString="gallery_id=#oGallery.getGallery_id()#");
		}
	}


	function delete(event,rc,prc)
	{
		var oGallery	= galleryEntity.get( rc.gallery_id );
		if( IsNull(oGallery) )
		{
			getPlugin("MessageBox").setMessage("warning", "Invalid Formular detected!");
		}
		else
		{
			// test for images in gallery
			oImages = imageEntity.list(criteria={gallery_id=oGallery});
			if ( IsNull(oImages) )
			{
				galleryEntity.delete( oGallery );
				getPlugin("MessageBox").setMessage("info", "Gallery Deleted!");
			}
			else
			{
				getPlugin("MessageBox").setMessage("error", "Error Deleting Gallery!&lt;br&gt;Gallery Contains Images!");
			}
		}
		setNextEvent(prc.xehGallery);
	}


	// installation check: ORM must be loaded (it's not clearly visible for user and though can cause crashes)
	function doORMReload(event, rc, prc)
	{
		event.setView(view="gallery/doORMReload",module="contentbox-gallerybuilder");
	}
}<commit_msg>delete check changed to len(), isnull() works only sometimes<commit_after>component extends="super"
{
property name="tag"					inject="coldbox:myPlugin:tag@contentbox-gallerybuilder";

	function index(event,rc,prc)
	{
		checkGalleryPath();
		prc.galleries = galleryEntity.list(sortOrder="gallery_id ASC",asQuery=false);
		prc.moduleRoot = getModuleSettings( "contentbox-gallerybuilder" ).mapping;

		prc.myhtml = tag.span("nix drin");
		prc.myhtml = tag.span("<<", {class="gallery-builder-page-enabled"}, {lightbox="click here"});
		prc.myhtml = tag.span("<<", {class="gallery-builder-page-enabled"});

		event.setView(view="gallery/index", module="contentbox-gallerybuilder");
	}


	function editor(event, rc, prc)
	{
		prc.gallery = galleryEntity.get(event.getValue("gallery_id", 0));
		prc.images_in_table = "";
		for ( i = 1; i lte 10; i=i+1 )
			prc.images_in_table = ListAppend(prc.images_in_table, i, ",");
		prc.images_per_page = "";
		for ( i = 1; i lte 30; i=i+1 )
			prc.images_per_page = ListAppend(prc.images_per_page, i, ",");
		event.setView("gallery/editor");
	}


	function save(event,rc,prc)
	{
		var oGallery = populateModel( galleryEntity.get(id=rc.gallery_id) );
		if ( oGallery.getGallery_id() eq "" )
		{
			oGallery.setCreated_at(now());
		}
		else
		{
			oGallery.setUpdated_at(now());
		}
		if ( not event.valueExists("use_lightbox") )
		{
			oGallery.setUse_Lightbox(false);
		}
		var errors = oGallery.validate();
		if ( arrayLen(errors) eq 0 )
		{
			galleryEntity.save(oGallery);
			getPlugin("MessageBox").info("Gallery saved!");
			setNextEvent(event=prc.xehGallery,queryString="gallery_id=#oGallery.getGallery_id()#");
		}
		else
		{
			flash.persistRC(exclude="event");
			getPlugin("MessageBox").warn(messageArray=errors);
			setNextEvent(event=prc.xehGalleryEditor,queryString="gallery_id=#oGallery.getGallery_id()#");
		}
	}


	function delete(event,rc,prc)
	{
		var oGallery	= galleryEntity.get( rc.gallery_id );
		if( IsNull(oGallery) )
		{
			getPlugin("MessageBox").setMessage("warning", "Invalid Formular detected!");
		}
		else
		{
			// test for images in gallery
			oImages = imageEntity.list(criteria={gallery_id=oGallery});
			if ( len(oImages) eq 0 )
			{
				galleryEntity.delete( oGallery );
				getPlugin("MessageBox").setMessage("info", "Gallery Deleted!");
			}
			else
			{
				getPlugin("MessageBox").setMessage("error", "Error Deleting Gallery! Gallery Contains Images!");
			}
		}
		setNextEvent(prc.xehGallery);
	}


	// installation check: ORM must be loaded (it's not clearly visible for user and though can cause crashes)
	function doORMReload(event, rc, prc)
	{
		event.setView(view="gallery/doORMReload",module="contentbox-gallerybuilder");
	}
}
{'fraction_non_alphanumeric': 0.1594715295868999, 'fraction_numerical': 0.003907703758838854, 'mean_word_length': 4.792025862068965, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4782730', 'n_tokens_mistral': 2202, 'n_tokens_neox': 1921, 'n_words': 303}