Hi,
Thanks Willr for the response. I have created a round about solution for this and I thought I would share how I did it. It doesn't replace the page icon but adds a new class to the list items on a site tree if a checkbox on this particular page class is ticked allowing you to add styling to make it stand out on the site tree.
Here is the code:
1) Add to config file details of custom extension, js and css to be included on CMS Main page.
mysite/_config.php
//Change icon background if copy category
LeftAndMain::require_javascript('mysite/javascript/treeaddclass.js');
LeftAndMain::require_css('mysite/css/treeicon.css');
//custom extension
LeftAndMain::add_extension('LeftAndMain', 'ActsLeftAndMain');
2) Custom extension to do a database query and return all page id's where the checkbox has been checked.
mysite/code/ActsLeftAndMain.php
class ActsLeftAndMain extends Extension {
function getData(){
$records = DB::query ("SELECT `CategoryPage`.`ID` FROM `CategoryPage` WHERE `CategoryPage`.`CategoryPageCopy` = 1");
if($records) {
$i = 0;
$length = count($records)-1;
foreach($records as $singlerecord){
if($i == $length) {
$set = $singlerecord['ID'];
} else {
$set .= ",";
$set .= $singlerecord['ID'];
}
$i++;
}
return $set;
}
}
}
3) Create a modified CMSMain_right.ss template to output data.
mysite/templates/CMSMain_right.ss
<div id="CategoryPageCopyIDs" style="height: 0px; display: none;">$getData</div>
<div id="form_actions_right" class="ajaxActions">
</div>
<% if EditForm %>
$EditForm
<% else %>
<form id="Form_EditForm" action="admin?executeForm=EditForm" method="post" enctype="multipart/form-data">
<h1>$ApplicationName</h1>
<p><% _t('WELCOMETO','Welcome to') %> $ApplicationName! <% _t('CHOOSEPAGE','Please choose a page from the left.') %></p>
</form>
<% end_if %>
<p id="statusMessage" style="visibility:hidden"></p>
4) Add some jQuery to grab info from page and add new or remove css class to the sitetree nodes.
mysite/javascript/treeaddclass.js
(function(jQuery) {
jQuery(document).ready(function() {
//Gets the ID's of category pages
var IDs = jQuery('div#CategoryPageCopyIDs').html();
if(IDs){
var IDsString = jQuery.parseJSON('[' + IDs + ']');
jQuery.each(IDsString, function() {
jQuery('li#record-'+ this).addClass('copyIcon');
});
}
jQuery("input#Form_EditForm_action_publish").live("click", function() {
var ID = jQuery('input#Form_EditForm_ID').val();
if(jQuery('#Form_EditForm input#Form_EditForm_CategoryPageCopy').is(':checked')) {
jQuery('li#record-'+ ID).addClass('copyIcon');
} else {
jQuery('li#record-'+ ID).removeClass('copyIcon');
}
})
})
})(jQuery);
5) Add styling to the sitetree nodes.
mysite/css/treeicon.css
ul.tree li.copyIcon {
background: #E8F3FC;
border-radius: 10px;
/* CSS3 tweaks for modern browsers */
-moz-border-radius:10px;
-webkit-border-radius:10px;
}
That will allow you to easily tell if you have a checkbox ticked on a certain page and updates when save and publish is pressed or the window is reloaded. I hope this helps others.
Thanks,
Jim