e107sk.com

Content Category Admin UI stuff

Admin UI stuff (6 items)

Topics related to admin stuff Thursday 02 May 2019 comments: 0

ID field on 18 May 2020

Display ID field:

I don't remember that I had to set displaying this field, but it is not displayed by default now (generated by Plugin builder). You need to add "force" parameter to display it.

'uid' => array ( 'title' => LAN_ID, 'data' => 'int', 'forced'=> TRUE, 'readonly'=>TRUE),

SEF URL field on 07 Dec 2019

 SEF-URL field

Basic settings:

'sef' => array ( 'title' => LAN_SEFURL, 'type' => 'text', 'data' => 'str', 'writeParms' => 'size=xxlarge&sef=title' ),

Batch option: 

'news_sef' => array('title' => LAN_SEFURL, 'batch'=>1,  (....)  'writeParms'=>array('size'=>'xxlarge', 'show'=>1, 'sef'=>'news_title'))

Date field on 07 Dec 2019

Date field (with calender)

minimal settings:

'date_added' => array ( 'title' => 'Added', 'type' => 'datestamp', 'data' => 'int' ),
'date_modified' => array ( 'title' => 'Modified', 'type' => 'datestamp', 'data' => 'int' ),

Readonly:

'date_added' => array ( 'title' => 'Added', 'type' => 'datestamp', 'data' => 'int', 'readonly' => true ),
'date_modified' => array ( 'title' => 'Modified', 'type' => 'datestamp', 'data' => 'int', 'readonly' => true ),<span></span>

Readonly has 2 modes:
1 = read-only, but only when there is a value,
2 = read-only regardless.

Correct values:

public function beforeCreate($new_data,$old_data)
{ 
if(empty($new_data['date_added']))
{
$new_data['date_added'] = time();
}
$new_data['date_modified'] = time(); 
return $new_data;
}

public function beforeUpdate($new_data, $old_data, $id)
{
$new_data['date_modified'] = time(); 
return $new_data;
}

Multicheckbox field on 07 Dec 2019

How to set multicheck field

Multicheck field in admin UI


Inspiration (or core check): admin/newspost.php and field: news_render_type

Example:

 
'blank_compatibility' 		 
=> array( 
	'title' => "Checkbox check", 
	'type' => 'dropdown', 
	'data'=>'str', 
	'inline'=>true, 
	'readParms'=>array('type'=>'checkboxes'), 
	'writeParms'=>array('multiple'=>'1', 'optArray' => array('0'=>'first option', '1' => 'second option')),<br />
	'width' => 'auto', 
	'thclass' => 'left', 
	'class' => 'left', 
	'nosort' => false, 
),<br />


Explanation:
- 'data' - Data Type: string (it saves values separated by comma)
- 'type' - news uses dropdown, type checkbox is only for one value ( (0 or 1 is returned)

Inline editing:

 
'inline'=>true, 
'readParms'=>array('type'=>'checkboxes'), 

type checkboxes allows multiselect

117d9c2965fc

Options:
'multiple' - you can select more than one option

'optArray' - list of options. It's just example, you can fill it in init() method from database values. If you don't use keys, they will be 0,1,2..., but if you use keys, those ones will be used.

Example how to get data from related table:

$parents = e107::getDb()->retrieve("property_location", "*", "WHERE parent_id = 0", true);
            $parent_item[0] = "None selected";
 
            foreach($parents as $parent) {
              $parent_item[$parent['id']] = $parent['title'];
            }
	        $this->fields['parent_id']['writeParms']['optArray'] =  $parent_item;

Options field on 18 Oct 2019

How to customize options field

By default, there are only edit and delete buttons.

Available options (only tested ones):

'noselector' => true, removes option to select displayed fields in read mode
'readParms'=>'sort=1' adds sort option. It doesn't work if you add buttons manually 

Add/change your own buttons:

Change type key to be able customize those buttons:

'options' => array(
'type' => 'method',
'width' => '10%',
'forced' => true,
'thclass' => 'center last',
'class' => 'center',
'sort' => false,
),

and  add

/**
* Override the default Options field.
*
* @param $parms
* @param $value
* @param $id
* @param $attributes
*
* @return string
*/
function options($parms, $value, $id, $attributes)
{
$text = '';if($attributes['mode'] == 'read')
{

} 
return $text;
} 

Result:  no buttons

Add edit button back:  ( f.e. if you want your own icons)

parse_str(str_replace('&amp;', '&', e_QUERY), $query); //FIXME - FIX THIS
$query['action'] = 'edit';
$query['id'] = $id;
$query = http_build_query($query,null, '&amp;');

$text = "<a href='".e_SELF."?{$query}' class='btn btn-default' title='".LAN_EDIT."' data-toggle='tooltip' data-placement='left'>
".ADMIN_EDIT_ICON."</a>";

Result: only Edit button

Add delete button back: ( f.e. if you want your own icons)

$text .= $this->submit_image('menu_delete['.$id.']', $id, 'delete', LAN_DELETE.' [ ID: '.$id.' ]', array('class' => 'action delete btn btn-default'));

Result: Edit and Delete buttons

NEW 18.12.2019

Add delete button for record deleting (tested): 

$text .= $this->submit_image('etrigger_delete['.$id.']', $id, 'delete', LAN_DELETE.' [ ID: '.$id.' ]', 
array('class' => 'action delete btn btn-danger',
'icon'=> '<i class="fa fa-trash-o"></i>'));

The different way how to do the same thing:  (the same result as default options)

$att['readParms'] = 'sort=1';

if($attributes['mode'] == 'read')
{
$text = "<div class='btn-group'>";
//add your button here
$text .= $this->renderValue('options',$value,$att,$id);
//or here
$text .= "</div>"; 
} 
return $text;

Boolean field on 20 Aug 2019

Boolean type

radio buttons with enable/disable

Default generated value by plugin builder:

'redirection_status' => array ( 'title' => 'Statust', 'type' => 'boolean',
'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => array (),
'writeParms' => array (), 'class' => 'left', 'thclass' => 'left',),

The result is ON/OFF switcher

Available parameters (from official documentation)

inverse 0 or 1 Invert the values of 0 and 1. ie. "Disabled" = 1 and "Enabled" = 0.
enabled (string) Alternate text to replace "Enabled"
disabled (string) Alternate text to replace "Disabled"

The parameter to change the text to YES/NO

'redirection_status' => array ( 'title' => 'Status', 'type' => 'boolean',
'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => array (), 'writeParms' => 'label=yesno',
'class' => 'left', 'thclass' => 'left',),

Other links

Follow us