1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-17 12:01:05 +02:00

admin UI: templates & layouts field types added, bugfixes and improvements; Featurebox plugin administration ready, front-end in progress

This commit is contained in:
secretr
2009-11-28 15:34:46 +00:00
parent 76ffe278f0
commit 9626059142
9 changed files with 335 additions and 148 deletions

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/featurebox/admin_config.php,v $
| $Revision: 1.10 $
| $Date: 2009-11-26 17:15:46 $
| $Revision: 1.11 $
| $Date: 2009-11-28 15:34:46 $
| $Author: secretr $
+----------------------------------------------------------------------------+
*/
@@ -69,43 +69,19 @@ class fb_category_ui extends e_admin_ui
protected $perPage = 0; //no limit
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center first'),
'fb_category_id' => array('title'=> LAN_ID, 'type' => 'number', 'data' => 'int', 'width' =>'5%', 'forced'=> TRUE),
'fb_category_title' => array('title'=> LAN_TITLE, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'validate' => 'str', 'rule' => '1-200', 'error' => 'String between 1-200 characters expected', 'help' => 'up to 200 characters', 'thclass' => 'left'),
'fb_category_layout' => array('title'=> 'Layout', 'type' => 'dropdown', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left', 'batch' => true, 'filter' => true),
'fb_category_icon' => array('title'=> LAN_ICON, 'type' => 'icon', 'data' => 'str', 'width' => '5%', 'thclass' => 'center', 'class'=>'center'),
'fb_category_title' => array('title'=> LAN_TITLE, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'validate' => 'str', 'rule' => '1-200', 'error' => 'String between 1-200 characters expected', 'help' => 'up to 200 characters', 'thclass' => 'left'),
'fb_category_layout' => array('title'=> 'Render type', 'type' => 'templates', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left', 'writeParms' => 'plugin=featurebox&location=layout&default=Default', 'filter' => true),
'fb_category_random' => array('title'=> 'Random', 'type' => 'boolean', 'data' => 'int', 'width' => '5%', 'thclass' => 'center', 'class' => 'center', 'batch' => true, 'filter' => true),
'fb_category_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'data' => 'int', 'width' => 'auto'),
'fb_category_limit' => array('title'=> 'Limit', 'type' => 'number', 'data' => 'int', 'width' => '5%', 'thclass' => 'left', 'help' => 'number of items to be shown'),
'fb_category_limit' => array('title'=> 'Limit', 'type' => 'number', 'data' => 'int', 'width' => '5%', 'thclass' => 'left', 'help' => 'number of items to be shown, 0 - show all'),
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center')
);
function init()
{
// build layout dropdown params
$templates = array();
$templates['default'] = 'Default';
$tmp = e107::getFile()->get_files(e_PLUGIN.'featurebox/templates/layout');
foreach($tmp as $files)
{
$key = str_replace('_template.php', '', $files['fname']);
$templates[$key] = implode(' ', array_map('ucfirst', explode('_', $key))); //TODO add LANS?
}
// TODO we need something like getFrontTheme()/getAdminTheme() - this will fail on user theme!
$tmp = e107::getFile()->get_files(e_THEME.e107::getPref('sitetheme').'/featurebox/templates/layout');
foreach($tmp as $files)
{
$key = str_replace('_template.php', '', $files['fname']);
$templates[$key] = implode(' ', array_map('ucfirst', explode('_', $key))); //TODO add LANS?
}
$this->fields['fb_category_layout']['readParms'] = $templates;
$this->fields['fb_category_layout']['writeParms'] = $templates;
}
/**
* User defined pre-delete logic
* Prevent deletion of categories in use
*/
public function beforeDelete($data, $id)
{
@@ -116,6 +92,55 @@ class fb_category_ui extends e_admin_ui
}
return true;
}
/**
* Some default values
* TODO - 'default' fields attribute (default value on init)
*/
public function beforeCreate($new_data)
{
if(!is_numeric($new_data['fb_category_limit']))
{
$new_data['fb_category_limit'] = 1;
}
return $new_data;
}
/**
* Create error callback
*/
public function onCreateError($new_data, $old_data)
{
return $this->_handleUnique($new_data, 'create');
}
/**
* Create error callback
*/
public function onUpdateError($new_data, $old_data, $id)
{
return $this->_handleUnique($new_data, 'update');
}
/**
* Provide user friendly message on mysql duplicate entry error #1062
* No need of beforeCreate callback and additional SQL query - mysql error number give us
* enough info
* @return boolean true - suppress model errors
*/
protected function _handleUnique($new_data, $mod)
{
if($this->getModel()->getSqlErrorNumber() == 1062)
{
$templates = $this->getFieldAttr('fb_category_layout', 'writeParms', array());
$msg = e107::getMessage();
$msg->error('Layout <strong>'.vartrue($templates[$new_data['fb_category_layout']], 'n/a').'</strong> is in use by another category. Layout should be unique per category. ');
$msg->error($mod == 'create' ? LAN_CREATED_FAILED : LAN_UPDATED_FAILED);
return (!E107_DEBUG_LEVEL); // suppress messages (TRUE) only when not in debug mod
}
return false;
}
}
/*class fb_cat_form_ui extends e_admin_form_ui
@@ -133,19 +158,18 @@ class fb_main_ui extends e_admin_ui
protected $batchDelete = true;
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'fb_id' => array('title'=> LAN_ID, 'type' => 'int', 'width' =>'5%', 'forced'=> TRUE),
'fb_title' => array('title'=> LAN_TITLE, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left first'),
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center first', 'class'=>'center'),
'fb_id' => array('title'=> LAN_ID, 'type' => 'number', 'data'=> 'int', 'width' =>'5%', 'forced'=> TRUE),
'fb_category' => array('title'=> LAN_CATEGORY, 'type' => 'dropdown', 'data'=> 'int', 'width' => '5%', 'filter'=>TRUE, 'batch'=>TRUE),
'fb_title' => array('title'=> LAN_TITLE, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left'),
'fb_text' => array('title'=> "Message Text", 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name
'fb_image' => array('title'=> "Image", 'type' => 'image', 'width' => 'auto', 'thclass' => 'left first'),
'fb_imageurl' => array('title'=> "Image Link", 'type' => 'url', 'width' => 'auto', 'thclass' => 'left first'),
'fb_mode' => array('title'=> FBLAN_12, 'type' => 'dropdown', 'data'=> 'int', 'width' => '5%', 'filter'=>TRUE, 'batch'=>TRUE),
//DEPRECATED 'fb_mode' => array('title'=> FBLAN_12, 'type' => 'dropdown', 'data'=> 'int', 'width' => '5%', 'filter'=>TRUE, 'batch'=>TRUE),
//DEPRECATED 'fb_rendertype' => array('title'=> FBLAN_22, 'type' => 'dropdown', 'data'=> 'int', 'width' => 'auto', 'noedit' => TRUE),
'fb_template' => array('title'=> FBLAN_25, 'type' => 'layouts', 'data'=> 'str', 'width' => 'auto', 'thclass' => 'center', 'class'=>'center', 'writeParms' => 'plugin=featurebox', 'filter' => true, 'batch' => true), // Photo
'fb_image' => array('title'=> "Image", 'type' => 'image', 'width' => 'auto', 'thclass' => 'left first'),
'fb_imageurl' => array('title'=> "Image Link", 'type' => 'url', 'width' => 'auto', 'thclass' => 'left first'),
'fb_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'data' => 'int', 'width' => 'auto'), // User id
'fb_rendertype' => array('title'=> FBLAN_22, 'type' => 'dropdown', 'data'=> 'int', 'width' => 'auto', 'noedit' => TRUE),
'fb_template' => array('title'=> FBLAN_25, 'type' => 'dropdown', 'data'=> 'str', 'width' => 'auto', 'thclass' => 'center', 'class'=>'center', 'writeParms' => '', 'filter' => true, 'batch' => true), // Photo
'fb_category' => array('title'=> LAN_CATEGORY, 'type' => 'dropdown', 'data'=> 'int', 'width' => '5%', 'filter'=>TRUE, 'batch'=>TRUE),
'fb_order' => array('title'=> LAN_ORDER, 'type' => 'number', 'data'=> 'int','width' => '5%', 'thclass' => 'center' ),
'fb_order' => array('title'=> LAN_ORDER, 'type' => 'number', 'data'=> 'int','width' => '5%', 'thclass' => 'center' ),
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center')
);
@@ -161,18 +185,7 @@ class fb_main_ui extends e_admin_ui
function init()
{
$templates = array();
$categories = array();
$tmp = e107::getTemplate('featurebox', 'featurebox');
foreach($tmp as $key=>$val)
{
$templates[$key] = $key; //TODO add LANS?
}
if(e107::getDb()->db_Select('featurebox_category'))
{
$categories[0] = LAN_SELECT;
@@ -182,16 +195,16 @@ class fb_main_ui extends e_admin_ui
$categories[$id] = $row['fb_category_title'];
}
}
$this->fields['fb_category']['writeParms'] = $categories;
$this->fields['fb_template']['writeParms'] = $templates;
$this->fields['fb_rendertype']['writeParms'] = array(FBLAN_23,FBLAN_24);
$this->fields['fb_mode']['writeParms'] = array(FBLAN_13,FBLAN_14);
// DEPRECATED
//$this->fields['fb_rendertype']['writeParms'] = array(FBLAN_23,FBLAN_24);
//$this->fields['fb_mode']['writeParms'] = array(FBLAN_13,FBLAN_14);
$this->fields['fb_category']['readParms'] = $categories;
$this->fields['fb_template']['readParms'] = $templates;
$this->fields['fb_rendertype']['readParms'] = array(FBLAN_23,FBLAN_24);
$this->fields['fb_mode']['readParms'] = array(FBLAN_13,FBLAN_14);
// DEPRECATED
//$this->fields['fb_rendertype']['readParms'] = array(FBLAN_23,FBLAN_24);
//$this->fields['fb_mode']['readParms'] = array(FBLAN_13,FBLAN_14);
}