Albums CMS Design Principles: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
No edit summary
 
(30 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Project Documentation]] [[Category:Albums CMS]] [[Category:Littled Libraries]] [[Category:jQuery/AJAX]] [[Category:Web Development]]
== AJAX ==
== AJAX ==
When adding a new album-based CMS section, the following files may need to be updated with the new content type:
When adding a new album-based CMS section, the following files may need to be updated with the new content type:


Line 6: Line 8:
/_classes/content/resort_class.php
/_classes/content/resort_class.php
</syntaxhighlight>
</syntaxhighlight>
Obviously if a file includes the <code>cache_class</code> then the new content type will be available to that file.
Obviously if a file includes the <code>cache_class</code> then the new content type will be available to that file.


== PHP Classes ==
== PHP Classes ==
Classes derived from <code>album_class</code> and <code>album_xpost_class</code> that don’t have the same columns as those tables should set the <code>db_field property</code> value for those fields to FALSE in their class constructors.
Classes derived from <code>album_class</code> and <code>album_xpost_class</code> that don’t have the same columns as those tables should set the <code>db_field property</code> value for those fields to FALSE in their class constructors.
<syntaxhighlight lang="php">$this->layout->db_field = false;</syntaxhighlight>
<syntaxhighlight lang="php" highlight="4">
function __construct() {
parent::__construct();
/* any child class property initialization would go here */
$this->layout->db_field = false;
}
</syntaxhighlight>
 
== JavaScript/JQuery ==
 
=== Album listings ===


==Listings==
===JavaScript/JQuery handlers===
LITTLED.Gallery.bindAlbumListingsHandlers()
The routine above doesn’t handle content refreshes. The code below adds that, along with some filtering utilities. This can be rolled up into a routine available through the LITTLED.CMS library.
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
LITTLED.init({ setSortables: LITTLED.Gallery.bindAlbumListingsHandlers });
$('.album-listings').galleries('bindAlbumListingsHandlers');
LITTLED.Gallery.keywordAutocomplete();
LITTLED.setSortables();
$('.datepicker').datepicker();
$('.update-cache').click(LITTLED.updateCache);
</syntaxhighlight>
</syntaxhighlight>


===image rollovers===
`$.galleries('bindAlbumListingsHandlers')` binds
*Requires “poshytip” JavaScript library in addition to the JQuery libraries.
 
*JQuery handlers  
* Content refresh events
**<code>LITTLED.Gallery.bindAlbumListingsHandlers()</code>:
* Page navigation
* Toggling galleries
** Hides gallery containers to prime them to be expanded by the album's "toggle gallery" button.
* Image details lightbox dialogs
* Image preview tooltips
* Inline editing of images
* Initialize "operations" buttons for each album record (details, edit, toggle gallery, update cache, delete, etc.)
* Inline edits of things like titles, status, dates, etc.
* <strike>Persistent highlighting of line items within listings after being clicked</strike>
 
=== Album details ===
 
Typical handlers on album details pages:
 
* Load the gallery content.
* Bind overlay handlers for the album's thumbnail image.
* Bind handler to allow inline editing of album keywords.
* Bind "delete record" handler to links/buttons in the page header.
* Bind "update cache" handler to links/buttons in the page header.
 
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
$('.album-tn', $p).poshytip(LITTLED.Gallery.preview_tt_properties);
<script type="text/javascript">
$(document).ready(function() {
 
/* Load gallery content & bind handlers for the gallery listings content. */
$('.gallery-listings').galleries('retrieveGallery');
 
/* Album thumbnail handlers. */
$('.image-upload-container').galleries('bindImageOverlayHandlers');
 
/* Enable inline keyword editing. */
$('.metadata').keywords('bindListingsHandlers');
 
/* "delete record" link in the page header
  The default action is to refresh with listings content,
  which isn't appropriate on a details page. */
$('.hdr-delete-link').formDialog({
dialogClass: 'delete-confirmation',
callbacks: {update_content: function(data) {
data.settings = options;
methods.updatePageContentAfterDelete(data)
}}
});
 
/* "update cache" link in the page header */
$('.update-cache-btn').on('click', $.littled.updateCache);
});
</script>
</syntaxhighlight>
</syntaxhighlight>
**Surround IMG element in ANCHOR tags.
 
**IMG class="album-tn". This is the hook for JQuery handler.
=== Gallery listings ===
**<code>href="javascript:void(0)"</code>
 
**When no thumbnail is available for the record:
==== Retrieving listings content ====
<syntaxhighlight lang="html4strict"><div class="error" style="text-align:center;">no thumbnail</div>
 
`$.galleries('retrieveGallery')`
 
* Calls AJAX script to retrieve gallery content.
** Relies on `data-tid` property of the DOM container for section id.
** Relies on `site_section.listings_uri` in the database for the url of the AJAX script that delivers the listings content.
* Loads gallery listings content into the DOM container.
* Binds gallery listings handlers to the content.
 
 
==== Binding gallery listings handlers ====
 
`$.galleries('bindGalleryHandlers')` binds
 
* Image details lightbox
* Image preview rollovers
* Line-item edit operation buttons (details,edit,delete)
* Page navigation within the gallery
* Gallery filters interactivity
* Inline data edits
* Inline keyword edits
* Record sorting
* Calendar popups
 
This method is invoked automatically in `$.galleries('retrieveGallery')`.
 
=== Refreshing listings content ===
 
Listings content refreshes for either Album listings or Gallery listings is achieved with
 
<syntaxhighlight lang="javascript">
$([LISTINGS_SELECTOR]).trigger('contentRefresh');
</syntaxhighlight>
</syntaxhighlight>
**Follow the thumbnail IMG element with an IMG element containing the medium or full-sized image wrapped in SPAN tags, depending on which size should appear on rollover.
 
**SPAN class="tooltip-content"
=== Listings selectors ===
**The <code>tooltip-content</code> class will hide the full-sized image until a rollover event is captured by the thumbnail.
 
**The IMG element doesn’t require any class attributes.
==== Albums ====
===image lightbox===
 
*Surround IMG element in ANCHOR tags.
The default container for albums is `.album-listings`.
**<A> class="img-details-link". This is the hook for JQuery handlers.
 
**<code>href="javascript:void(0)"</code>
The default container can be overridden with the `dom.album_container` setting of the `$.galleries` library.  
**<A> attribute <code>data-id</code> stores the image_link record id
 
**<A> attribute <code>data-tid</code> Content type id. Make sure this is for the image and not its parent’s (the album record) content type.
<syntaxhighlight lang="javascript">
*Requires a handler to be set in the Content Sections CMS:
$(document).ready(function() {
**Details URI: <code>/_ajax/images/image_details.php</code>
$('.alt-album-container').galleries('bindAlbumListingsHandlers', {dom: {gallery_container: '.alt-album-container'}});
**<code>$('.img-details-link')</code> handler
});
</syntaxhighlight>
 
==== Galleries ====
 
The default container for galleries is `.gallery-listings`.
 
The default container can be overridden with the `dom.gallery_container` setting of the `$.galleries` library.
 
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
$('.img-details-link', $p).click(LITTLED.Gallery.detailsDialog('gallery-dialog'));
$(document).ready(function() {
$('.alt-pages-container').galleries('bindGalleryHandlers', {dom: {gallery_container: '.alt-pages-container'}});
});
</syntaxhighlight>
</syntaxhighlight>
The <code>$('.img-details-link')</code> handler is rolled into <code>LITTLED.Gallery.bindAlbumListingsHandlers()</code>
 
[[Category:Albums CMS]]
==== Sorting ====
[[Category:CMS Documentation]]
 
* If the parent element is a `<nowiki><table></nowiki>` the sortable elements are specified with `tr.page-row`.
* If the parent element is a `<nowiki><div></nowiki>` the sortable elements are marked with `.page-cell`.
 
== Refreshing listings content ==
 
See also [[Littled Library Pagination]]
 
=== Albums ===
 
Album content is refreshed after
 
* Following a link to a new page in the listings
* Deleting a record
 
=== Galleries ===
 
Gallery content is refreshed after
 
* The parent page's content is fully loaded
* Following a link to a new page in the listings
* Applying new filter values
* Deleting a page from the gallery
 
Gallery listings container properties
 
* `listings` and `gallery-listings` classes
** `.gallery-listings` is the default selector used to target the gallery listings in the DOM after an AJAX content edit has been performed.
* `data-tid` attribute holding the ''gallery's'' content id.
* `data-p` attributes holding the position of the first record on the current page of listings relative to the entire set of matching listings.
 
AJAX scripts pass back markup in the `content` property of a JSON collection.
 
The `$.galleries` jQuery library dumps the markup using its `dom.album_container` and `dom.gallery_container` properties.
 
Filter values applied to the listings content are passed to AJAX scripts using the `dom.filters_form` and `dom.gallery_filters` properties of the `$.galleries` library.
 
The content that is passed back to the page from the AJAX script is determined in the PHP `cache_class`.
 
* `cache_class::refresh_content_after_edit()`
* `cache_class::refresh_content_after_image_edit()`
** Typically this will load content from a template determined by the type of object being used to make the edit.
** The default gallery listings template is `CMS_COMMON_TEMPLATE_DIR."content/albums/gallery_listings.php"`.
 
<syntaxhighlight lang="php" highlight="7-12">
public static function refresh_content_after_edit( &$content, &$filters, &$json ) {
global $sParam;
switch(1) {
case ($content instanceof image_link_class):
cache_class::refresh_content_after_image_edit($content, $filters, $json);
break;
case ($content instanceof Book):
ob_start();
include (CMS_BASE_DIR."books/_templates/content/book_listings.php");
$json->content->value = ob_get_contents();
ob_end_clean();
break;
default:
ob_start();
include (CMS_COMMON_TEMPLATE_DIR."content/albums/album_listings.php");
$json->content->value = ob_get_contents();
ob_end_clean();
break;
    }
}
</syntaxhighlight>
 
== Toggling galleries within album listings ==
 
* `.gallery-listings` element
** `data-pid` album id
** `data-tid` content identifier for the gallery, as defined by the [[Littled_Content_Properties_CMS|Content Properties CMS]]
* PHP template
** `(CMS_COMMON_TEMPLATE_DIR)_content/albums/gallery_listings_container.php`
** album id: `$album->id->value`
** content type id: `$filters->gallery->site_section->id->value`
 
== See Also ==
 
* [[Gallery Listings|Album/Gallery Listings]]
* [http://littledamien.com/docs/?p=636|littledamien.com: albums cms specs & principles] (Littledamien docs)

Latest revision as of 17:00, 5 December 2015

AJAX[edit]

When adding a new album-based CMS section, the following files may need to be updated with the new content type:

/_classes/content/cache_class.php
/_classes/content/resort_class.php

Obviously if a file includes the cache_class then the new content type will be available to that file.

PHP Classes[edit]

Classes derived from album_class and album_xpost_class that don’t have the same columns as those tables should set the db_field property value for those fields to FALSE in their class constructors.

function __construct() {
	parent::__construct();
	/* any child class property initialization would go here */
	$this->layout->db_field = false;
}

JavaScript/JQuery[edit]

Album listings[edit]

$('.album-listings').galleries('bindAlbumListingsHandlers');

$.galleries('bindAlbumListingsHandlers') binds

  • Content refresh events
  • Page navigation
  • Toggling galleries
    • Hides gallery containers to prime them to be expanded by the album's "toggle gallery" button.
  • Image details lightbox dialogs
  • Image preview tooltips
  • Inline editing of images
  • Initialize "operations" buttons for each album record (details, edit, toggle gallery, update cache, delete, etc.)
  • Inline edits of things like titles, status, dates, etc.
  • Persistent highlighting of line items within listings after being clicked

Album details[edit]

Typical handlers on album details pages:

  • Load the gallery content.
  • Bind overlay handlers for the album's thumbnail image.
  • Bind handler to allow inline editing of album keywords.
  • Bind "delete record" handler to links/buttons in the page header.
  • Bind "update cache" handler to links/buttons in the page header.
<script type="text/javascript">
$(document).ready(function() {

	/* Load gallery content & bind handlers for the gallery listings content. */
	$('.gallery-listings').galleries('retrieveGallery');	

	/* Album thumbnail handlers. */
	$('.image-upload-container').galleries('bindImageOverlayHandlers');

	/* Enable inline keyword editing. */
	$('.metadata').keywords('bindListingsHandlers');

	/* "delete record" link in the page header 
	   The default action is to refresh with listings content, 
	   which isn't appropriate on a details page. */
	$('.hdr-delete-link').formDialog({
		dialogClass: 'delete-confirmation',
		callbacks: {update_content: function(data) {
				data.settings = options;
				methods.updatePageContentAfterDelete(data)
		}}
	});

	/* "update cache" link in the page header */
	$('.update-cache-btn').on('click', $.littled.updateCache);
});
</script>

Gallery listings[edit]

Retrieving listings content[edit]

$.galleries('retrieveGallery')

  • Calls AJAX script to retrieve gallery content.
    • Relies on data-tid property of the DOM container for section id.
    • Relies on site_section.listings_uri in the database for the url of the AJAX script that delivers the listings content.
  • Loads gallery listings content into the DOM container.
  • Binds gallery listings handlers to the content.


Binding gallery listings handlers[edit]

$.galleries('bindGalleryHandlers') binds

  • Image details lightbox
  • Image preview rollovers
  • Line-item edit operation buttons (details,edit,delete)
  • Page navigation within the gallery
  • Gallery filters interactivity
  • Inline data edits
  • Inline keyword edits
  • Record sorting
  • Calendar popups

This method is invoked automatically in $.galleries('retrieveGallery').

Refreshing listings content[edit]

Listings content refreshes for either Album listings or Gallery listings is achieved with

$([LISTINGS_SELECTOR]).trigger('contentRefresh');

Listings selectors[edit]

Albums[edit]

The default container for albums is .album-listings.

The default container can be overridden with the dom.album_container setting of the $.galleries library.

$(document).ready(function() {
	$('.alt-album-container').galleries('bindAlbumListingsHandlers', {dom: {gallery_container: '.alt-album-container'}});
});

Galleries[edit]

The default container for galleries is .gallery-listings.

The default container can be overridden with the dom.gallery_container setting of the $.galleries library.

$(document).ready(function() {
	$('.alt-pages-container').galleries('bindGalleryHandlers', {dom: {gallery_container: '.alt-pages-container'}});
});

Sorting[edit]

  • If the parent element is a `<table> the sortable elements are specified with tr.page-row.
  • If the parent element is a <div> the sortable elements are marked with .page-cell`.

Refreshing listings content[edit]

See also Littled Library Pagination

Albums[edit]

Album content is refreshed after

  • Following a link to a new page in the listings
  • Deleting a record

Galleries[edit]

Gallery content is refreshed after

  • The parent page's content is fully loaded
  • Following a link to a new page in the listings
  • Applying new filter values
  • Deleting a page from the gallery

Gallery listings container properties

  • listings and gallery-listings classes
    • .gallery-listings is the default selector used to target the gallery listings in the DOM after an AJAX content edit has been performed.
  • data-tid attribute holding the gallery's content id.
  • data-p attributes holding the position of the first record on the current page of listings relative to the entire set of matching listings.

AJAX scripts pass back markup in the content property of a JSON collection.

The $.galleries jQuery library dumps the markup using its dom.album_container and dom.gallery_container properties.

Filter values applied to the listings content are passed to AJAX scripts using the dom.filters_form and dom.gallery_filters properties of the $.galleries library.

The content that is passed back to the page from the AJAX script is determined in the PHP cache_class.

  • cache_class::refresh_content_after_edit()
  • cache_class::refresh_content_after_image_edit()
    • Typically this will load content from a template determined by the type of object being used to make the edit.
    • The default gallery listings template is CMS_COMMON_TEMPLATE_DIR."content/albums/gallery_listings.php".
public static function refresh_content_after_edit( &$content, &$filters, &$json ) {
	global $sParam;
	switch(1) {
		case ($content instanceof image_link_class):
			cache_class::refresh_content_after_image_edit($content, $filters, $json);
			break;
		case ($content instanceof Book):
			ob_start();
			include (CMS_BASE_DIR."books/_templates/content/book_listings.php");
			$json->content->value = ob_get_contents();
			ob_end_clean();
			break;			
		default:
			ob_start();
			include (CMS_COMMON_TEMPLATE_DIR."content/albums/album_listings.php");
			$json->content->value = ob_get_contents();
			ob_end_clean();
			break;
    }
}

Toggling galleries within album listings[edit]

  • .gallery-listings element
  • PHP template
    • (CMS_COMMON_TEMPLATE_DIR)_content/albums/gallery_listings_container.php
    • album id: $album->id->value
    • content type id: $filters->gallery->site_section->id->value

See Also[edit]