Hello Andrew,
Thanks for your answer.
I modify the code of time.php and now it works replacing this
Code:
$field->label = JText::_($field->label);
// execute the code only if the field type match the plugin type
if($field->field_type != 'date') return;
$field->{$prop} = $field->value ? $field->value : JText::_( 'FLEXI_NO_VALUE' );
by
Code:
$field->label = JText::_($field->label);
// execute the code only if the field type match the plugin type
if($field->field_type != 'time') return;
$field->{$prop} = $field->value ? $field->value : JText::_( 'FLEXI_NO_VALUE' );
$n=0;
foreach ($values as $value) {
$field->{$prop}[] = $values[$n] ? JHTML::_('time', $values[$n] ) : JText::_( 'FLEXI_NO_VALUE' );
$n++;
}
$field->{$prop} = implode($separatorf, $field->{$prop});
I also added the possibility to add values and choose separator, though I'm aware the multiple values might be ignored in the agenda.
The complete file :
Code:
<?php
/**
* @version $Id: time.php 1.0 2010-07-28 14:11:51Z andrewp $
* @package FLEXIcontent
* @author Andrew Patton
* @copyright Copyright (C) 2010 Pure Cobalt. All rights reserved.
* @license GNU/GPL v2
**/
defined( '_JEXEC' ) or die( 'Restricted access' );
//jimport('joomla.plugin.plugin');
jimport('joomla.event.plugin');
class plgFlexicontent_fieldsTime extends JPlugin
{
function plgFlexicontent_fieldsTime( &$subject, $params )
{
parent::__construct( $subject, $params );
}
function onDisplayField(&$field, $item)
{
$field->label = JText::_($field->label);
// execute the code only if the field type match the plugin type
if($field->field_type != 'time') return;
// some parameter shortcuts
$required = $field->parameters->get( 'required', 0 ) ;
$multiple = $field->parameters->get( 'allow_multiple', 1 ) ;
$maxval = $field->parameters->get( 'max_values', 0 ) ;
$required = $required ? ' class="required"' : '';
// initialise property
if (!$field->value) {
$field->value = array();
$field->value[0] = '';
}
if ($multiple) // handle multiple records
{
$document = & JFactory::getDocument();
//add the drag and drop sorting feature
$js = "
window.addEvent('domready', function(){
new Sortables($('sortables_".$field->id."'), {
'handles': $('sortables_".$field->id."').getElements('span.drag'),
'onDragStart': function(element, ghost){
ghost.setStyles({
'list-style-type': 'none',
'opacity': 1
});
element.setStyle('opacity', 0.3);
},
'onDragComplete': function(element, ghost){
element.setStyle('opacity', 1);
ghost.remove();
this.trash.remove();
}
});
});
";
$document->addScriptDeclaration($js);
$js = "
var curRowNum".$field->id." = ".count($field->value).";
var maxVal".$field->id." = ".$maxval.";
function addField".$field->id."(el) {
if((curRowNum".$field->id." < maxVal".$field->id.") || (maxVal".$field->id." == 0)) {
var thisField = $(el).getPrevious().getLast();
var thisNewField = thisField.clone();
var fx = thisNewField.effects({duration: 0, transition: Fx.Transitions.linear});
thisNewField.getFirst().setProperty('value','');
thisNewField.injectAfter(thisField);
new Sortables($('sortables_".$field->id."'), {
'handles': $('sortables_".$field->id."').getElements('span.drag'),
'onDragStart': function(element, ghost){
ghost.setStyles({
'list-style-type': 'none',
'opacity': 1
});
element.setStyle('opacity', 0.3);
},
'onDragComplete': function(element, ghost){
element.setStyle('opacity', 1);
ghost.remove();
this.trash.remove();
}
});
fx.start({ 'opacity': 1 }).chain(function(){
this.setOptions({duration: 600});
this.start({ 'opacity': 0 });
})
.chain(function(){
this.setOptions({duration: 300});
this.start({ 'opacity': 1 });
});
curRowNum".$field->id."++;
}
}
function deleteField".$field->id."(el) {
if(curRowNum".$field->id." > 1) {
var field = $(el);
var row = field.getParent();
var fx = row.effects({duration: 300, transition: Fx.Transitions.linear});
fx.start({
'height': 0,
'opacity': 0
}).chain(function(){
row.remove();
});
curRowNum".$field->id."--;
}
}
";
$document->addScriptDeclaration($js);
$css = '
#sortables_'.$field->id.' { margin: 0px; padding: 0px; list-style: none; white-space: nowrap; }
#sortables_'.$field->id.' li {
list-style: none;
height: 20px;
}
#sortables_'.$field->id.' li input { cursor: text;}
#sortables_'.$field->id.' li input.fcbutton, .fcbutton { cursor: pointer; margin-left: 3px; }
span.drag img {
margin: -4px 8px;
cursor: move;
}
';
$document->addStyleDeclaration($css);
$move2 = JHTML::image ( 'administrator/components/com_flexicontent/assets/images/move3.png', JText::_( 'FLEXI_CLICK_TO_DRAG' ) );
$n = 0;
$field->html = '<ul id="sortables_'.$field->id.'">';
foreach ($field->value as $value) {
$field->html .= '<li>'.$pretext.'<input name="'.$field->name.'[]" type="text" size="'.$size.'" value="'.$value.'"'.$required.' />'.$posttext.'<input class="fcbutton" type="button" value="'.JText::_( 'FLEXI_REMOVE_VALUE' ).'" onclick="deleteField'.$field->id.'(this);" /><span class="drag">'.$move2.'</span></li>';
$n++;
}
$field->html .= '</ul>';
$field->html .= '<input type="button" id="add'.$field->name.'" onclick="addField'.$field->id.'(this);" value="'.JText::_( 'FLEXI_ADD_VALUE' ).'" />';
} else { // handle single records
$field->html = '<div>'.$pretext.'<input name="'.$field->name.'[]" type="text" size="'.$size.'" value="'.$field->value[0].'"'.$required.' />'.$posttext.'</div>';
}
}
function onBeforeSaveField( $field, &$post, &$file )
{
// execute the code only if the field type match the plugin type
if($field->field_type != 'time') return;
$newpost = array();
$new = 0;
foreach ($post as $n=>$v)
{
if ($v != '')
{
// validate:
$vParts = explode('h', $v);
if (count($vParts < 2)) {
if (strlen($vParts[0]) > 2) {
$vParts = array(substr($v, 0, -2), substr($v, -2));
}
else {
$vParts[] = '00';
}
}
$vParts[0] = (int) $vParts[0];
$vParts[1] = (int) $vParts[1];
if ($vParts[0] > 23)
$vParts[0] = 0;
if ($vParts[1] > 59)
$vParts[1] = 0;
if ($vParts[0] < 10)
$vParts[0] = '0' . $vParts[0];
if ($vParts[1] < 10)
$vParts[1] = '0' . $vParts[1];
$newpost[$new] = $vParts[0] . 'h' . $vParts[1];
}
$new++;
}
$post = $newpost;
}
function onDisplayFieldValue(&$field, $item, $values=null, $prop='display')
{
// some parameter shortcuts
$separatorf = $field->parameters->get( 'separatorf', 1 ) ;
switch($separatorf)
{
case 0:
$separatorf = ' ';
break;
case 1:
$separatorf = '<br />';
break;
case 2:
$separatorf = ' | ';
break;
case 3:
$separatorf = ', ';
break;
default:
$separatorf = ' ';
break;
}
$field->label = JText::_($field->label);
// execute the code only if the field type match the plugin type
if($field->field_type != 'time') return;
$field->{$prop} = $field->value ? $field->value : JText::_( 'FLEXI_NO_VALUE' );
$n=0;
foreach ($values as $value) {
$field->{$prop}[] = $values[$n] ? JHTML::_('time', $values[$n] ) : JText::_( 'FLEXI_NO_VALUE' );
$n++;
}
$field->{$prop} = implode($separatorf, $field->{$prop});
}
}
?>
Add have added that in the file time.xml :
Code:
<param name="allow_multiple" type="radio" default="1" label="FLEXI_FIELD_ALLOW_MULTIPLE" description="FLEXI_FIELD_ALLOW_MULTIPLE_DESC">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="max_values" type="text" default="0" size="2" label="FLEXI_FIELD_MAX_VALUES" description="FLEXI_FIELD_MAX_VALUES_DESC" />
<param name="separatorf" type="list" default="1" label="FLEXI_FIELD_SEPARATOR_FRONTEND" description="FLEXI_FIELD_SEPARATOR_FRONTEND_DESC">
<option value="0">FLEXI_SPACE</option>
<option value="1">FLEXI_LINE_BREAK</option>
<option value="2">FLEXI_PIPE</option>
<option value="3">FLEXI_COMMA</option>
</param>
I'm looking for a way to add another text field in the tooltip. I try that but it doesn't work :
Code:
echo $this->fields->field_name->display;
Any idea how I could do that ?
Thanks again for this great work
Regards,