Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nick Dunn
committed
Aug 13, 2010
0 parents
commit a69aaab
Showing
4 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
body.publish-tabs h2 { | ||
border-bottom: 0; | ||
} | ||
|
||
#publish-tabs-controls { | ||
list-style-type: none; | ||
margin: 0; | ||
overflow: hidden; | ||
border-bottom: 1px solid #ddddcc; | ||
} | ||
|
||
#publish-tabs-controls li { | ||
float: left; | ||
list-style-type: none; | ||
display: block; | ||
padding: 5px 15px; | ||
margin: 0 3px 0 0; | ||
cursor: pointer; | ||
background-color: #bbb; | ||
-moz-border-radius: 5px 5px 0 0; | ||
-webkit-border-radius: 5px 5px 0 0; | ||
border-radius: 5px 5px 0 0; | ||
color: #fff; | ||
} | ||
|
||
#publish-tabs-controls li:hover { | ||
background-color: #aaa; | ||
} | ||
|
||
#publish-tabs-controls li.selected { | ||
background-color: #5a82b0; | ||
} | ||
|
||
#publish-tabs-controls li.invalid span { | ||
background-color: #DD4422; | ||
display: inline-block; | ||
font-weight: bold; | ||
font-family: "Times New Roman", Times, serif; | ||
font-size: 11px; | ||
padding: 1px 5px; | ||
-moz-border-radius: 10px 10px; | ||
-webkit-border-radius: 10px 10px; | ||
border-radius: 10px 10px; | ||
line-height: 1; | ||
margin: 0 -5px 0 7px; | ||
} | ||
|
||
.tab-group { | ||
position: absolute; | ||
top: -99999em; | ||
left: -99999em; | ||
} | ||
|
||
.tab-group-selected { | ||
position: static; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/*----------------------------------------------------------------------------- | ||
Language strings | ||
-----------------------------------------------------------------------------*/ | ||
|
||
Symphony.Language.add({ | ||
'Untitled Tab': false, | ||
}); | ||
|
||
|
||
/*----------------------------------------------------------------------------- | ||
PublishTabs | ||
-----------------------------------------------------------------------------*/ | ||
|
||
var PublishTabs = { | ||
|
||
tab_controls: null, | ||
new_entry: null, | ||
|
||
init: function() { | ||
var self = this; | ||
|
||
// thy shalt not pass if no Publush Tab fields used | ||
var tab_fields = jQuery('.field-publish_tabs'); | ||
if (!tab_fields.length) return; | ||
|
||
jQuery('body').addClass('publish-tabs'); | ||
|
||
// are we creating a new entry or editing an existing one? | ||
this.new_entry = jQuery('form:first').attr('action').replace(/\//g,'').match(/new$/); | ||
|
||
var has_invalid_tabs = false; | ||
this.tab_controls = jQuery('<ul id="publish-tabs-controls"></ul>'); | ||
|
||
for(tab in publish_tabs) { | ||
|
||
var main_fields = ''; | ||
var sidebar_fields = ''; | ||
|
||
for(field in publish_tabs[tab].main) main_fields += '#' + publish_tabs[tab].main[field] + ', '; | ||
for(field in publish_tabs[tab].sidebar) sidebar_fields += '#' + publish_tabs[tab].sidebar[field] + ', '; | ||
|
||
main_fields = main_fields.replace(/, $/,''); | ||
sidebar_fields = sidebar_fields.replace(/, $/,''); | ||
|
||
jQuery(main_fields).wrapAll('<div class="tab-group tab-group-' + tab + '"></div>'); | ||
jQuery(sidebar_fields).wrapAll('<div class="tab-group tab-group-' + tab + '"></div>'); | ||
|
||
var tab_field = jQuery('#tab-' + tab).remove(); | ||
var tab_text = (tab_field.text() != '') ? tab_field.text() : Symphony.Language.get('Untitled Tab'); | ||
var tab_button = jQuery('<li class="'+tab+'">' + tab_text + '</li>'); | ||
|
||
this.tab_controls.append(tab_button); | ||
|
||
// add click event to tab | ||
tab_button.bind('click', function() { | ||
if (jQuery(this).hasClass('selected')) return; | ||
var tab_class = jQuery(this).attr('class') | ||
.replace(/invalid/,'') | ||
.replace(/selected/,'') | ||
.replace(/ /g,''); | ||
self.showTab(tab_class); | ||
}); | ||
|
||
// find invalid fields | ||
if (jQuery('.tab-group-' + tab + ' .invalid').length) { | ||
has_invalid_tabs = true; | ||
tab_button.addClass('invalid').append('<span>!</span>'); | ||
} | ||
|
||
} | ||
|
||
if (has_invalid_tabs) { | ||
this.tab_controls.find('li.invalid:first').click(); | ||
} else { | ||
this.tab_controls.find('li:first').click(); | ||
} | ||
|
||
jQuery('h2').after(this.tab_controls); | ||
|
||
}, | ||
|
||
showTab: function(tab) { | ||
// deselect current tab and select the new tab | ||
this.tab_controls.find('li.selected').removeClass('selected'); | ||
this.tab_controls.find('li.' + tab).addClass('selected'); | ||
|
||
// hide current tab group and select new group | ||
jQuery('.tab-group-selected').removeClass('tab-group-selected'); | ||
jQuery('.tab-group-' + tab).addClass('tab-group-selected'); | ||
|
||
var invalid_field = jQuery('.tab-group-' + tab + ' .invalid'); | ||
// focus first invalid element | ||
if (invalid_field.length) { | ||
invalid_field.eq(0).find('*[name*="fields["]').focus(); | ||
} | ||
// focus first field in tab when creating a new entry | ||
else if (this.new_entry) { | ||
jQuery('.tab-group-' + tab + ' .field:first *[name*="fields["]').focus(); | ||
} | ||
} | ||
|
||
} | ||
|
||
jQuery(document).ready(function() { | ||
PublishTabs.init(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
class extension_publish_tabs extends Extension { | ||
|
||
public function about() { | ||
return array( | ||
'name' => 'Publish Tabs', | ||
'version' => '0.1', | ||
'release-date' => '2010-08-13', | ||
'author' => array( | ||
'name' => 'Nick Dunn', | ||
'website' => 'http://nick-dunn.co.uk' | ||
), | ||
'description' => 'Add tab groups to entry forms' | ||
); | ||
} | ||
|
||
public function uninstall() { | ||
Symphony::Database()->query("DROP TABLE `tbl_fields_publish_tabs`"); | ||
} | ||
|
||
public function install() { | ||
Symphony::Database()->query( | ||
"CREATE TABLE IF NOT EXISTS `tbl_fields_publish_tabs` ( | ||
`id` int(11) NOT NULL auto_increment, | ||
`field_id` int(11) NOT NULL, | ||
PRIMARY KEY (`id`) | ||
)" | ||
); | ||
return true; | ||
} | ||
|
||
public function getSubscribedDelegates() { | ||
return array( | ||
array( | ||
'page' => '/backend/', | ||
'delegate' => 'InitaliseAdminPageHead', | ||
'callback' => 'initializeAdmin' | ||
), | ||
); | ||
} | ||
|
||
public function initializeAdmin($context) { | ||
$page = $context['parent']->Page; | ||
|
||
$callback = Administration::instance()->getPageCallback(); | ||
|
||
// only proceed on New or Edit publish pages | ||
if ($page instanceof contentPublish and in_array($page->_context['page'], array('new', 'edit'))) { | ||
|
||
$page->addStylesheetToHead(URL . '/extensions/publish_tabs/assets/publish-tabs.css', 'screen', 9876543213); | ||
$page->addScriptToHead(URL . '/extensions/publish_tabs/assets/publish-tabs.js', 987654322); | ||
|
||
include_once(TOOLKIT . '/class.sectionmanager.php'); | ||
$sm = new SectionManager(Administration::instance()); | ||
|
||
$section_id = $sm->fetchIDFromHandle($callback['context']['section_handle']); | ||
$section = $sm->fetch($section_id); | ||
|
||
$tabs = array(); | ||
$current_tab = ''; | ||
|
||
foreach($section->fetchFieldsSchema() as $i => $field) { | ||
if ($i == 0 && $field['type'] != 'publish_tabs') $current_tab = 'untitled-tab'; | ||
if ($field['type'] == 'publish_tabs') { | ||
$current_tab = $field['element_name']; | ||
} else { | ||
$tabs[$current_tab][$field['location']][] = 'field-' . $field['id']; | ||
} | ||
} | ||
|
||
$page->addElementToHead(new XMLElement( | ||
'script', | ||
'var publish_tabs = ' . json_encode($tabs), | ||
array('type' => 'text/javascript') | ||
), 987654321); | ||
} | ||
|
||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
Class fieldPublish_Tabs extends Field{ | ||
|
||
function __construct(&$parent){ | ||
parent::__construct($parent); | ||
$this->_name = 'Publish Tab'; | ||
$this->_required = false; | ||
$this->set('hide', 'no'); | ||
} | ||
|
||
public function processRawFieldData($data, &$status, $simulate=false, $entry_id=null) { | ||
$status = self::__OK__; | ||
return array( | ||
'value' => '' | ||
); | ||
} | ||
|
||
function commit(){ | ||
if(!parent::commit()) return false; | ||
$id = $this->get('id'); | ||
if($id === false) return false; | ||
$fields = array(); | ||
$fields['field_id'] = $id; | ||
$this->_engine->Database->query("DELETE FROM `tbl_fields_".$this->handle()."` WHERE `field_id` = '$id' LIMIT 1"); | ||
return $this->_engine->Database->insert($fields, 'tbl_fields_' . $this->handle()); | ||
} | ||
|
||
function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL, $fieldnamePrefix=NULL, $fieldnamePostfix=NULL){ | ||
$wrapper->setAttribute('id', 'tab-' . Lang::createHandle($this->get('label'))); | ||
$wrapper->setValue($this->get('label')); | ||
} | ||
|
||
public function appendFormattedElement(&$wrapper, $data, $encode=false, $mode=null) { | ||
|
||
|
||
} | ||
|
||
public function createTable(){ | ||
|
||
return $this->Database->query( | ||
|
||
"CREATE TABLE IF NOT EXISTS `tbl_entries_data_" . $this->get('id') . "` ( | ||
`id` int(11) unsigned NOT NULL auto_increment, | ||
`entry_id` int(11) unsigned NOT NULL, | ||
`value` double default NULL, | ||
PRIMARY KEY (`id`), | ||
KEY `entry_id` (`entry_id`), | ||
KEY `value` (`value`) | ||
) TYPE=MyISAM;" | ||
|
||
); | ||
} | ||
|
||
} | ||
|
||
?> |