mirror of
https://github.com/e107inc/e107.git
synced 2025-05-06 12:15:38 +02:00
admin UI: more improvements and bugfixes, array fieldname support added; code split; preparing for: JS validation, better notifications, JS tabs
This commit is contained in:
parent
efd184fd93
commit
c424a273e1
e107_handlers
@ -9,8 +9,8 @@
|
||||
* Administration UI handlers, admin helper functions
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_handlers/admin_handler.php,v $
|
||||
* $Revision: 1.34 $
|
||||
* $Date: 2009-11-18 19:57:07 $
|
||||
* $Revision: 1.35 $
|
||||
* $Date: 2009-11-21 11:15:29 $
|
||||
* $Author: secretr $
|
||||
*/
|
||||
|
||||
@ -2552,29 +2552,34 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
*/
|
||||
protected function convertToData(&$data)
|
||||
{
|
||||
$model = new e_model($data);
|
||||
foreach ($this->getFields() as $key => $attributes)
|
||||
{
|
||||
if(!isset($data[$key]))
|
||||
$value = vartrue($attributes['dataPath']) ? $model->getData($attributes['dataPath']) : $model->get($data[$key]);
|
||||
if(null === $value)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
switch($attributes['type'])
|
||||
{
|
||||
case 'datestamp':
|
||||
if(!is_numeric($data[$key]))
|
||||
if(!is_numeric($value))
|
||||
{
|
||||
$data[$key] = trim($data[$key]) ? e107::getDateConvert()->toTime($data[$key], 'input') : 0;
|
||||
$value = trim($value) ? e107::getDateConvert()->toTime($value, 'input') : 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'ip': // TODO - ask Steve if this check is required
|
||||
if(strpos($data[$key], '.') !== FALSE)
|
||||
if(strpos($value, '.') !== FALSE)
|
||||
{
|
||||
$data[$key] = trim($data[$key]) ? e107::getInstance()->ipEncode($data[$key]) : '';
|
||||
$value = trim($value) ? e107::getInstance()->ipEncode($value) : '';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$data = $model->getData();
|
||||
unset($model);
|
||||
|
||||
$this->toData($data);
|
||||
}
|
||||
|
||||
@ -3620,7 +3625,7 @@ class e_admin_form_ui extends e_form
|
||||
);
|
||||
$models[] = $controller->getModel();
|
||||
|
||||
return $this->createForm($forms, $models, e_AJAX_REQUEST);
|
||||
return $this->renderCreateForm($forms, $models, e_AJAX_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3651,7 +3656,7 @@ class e_admin_form_ui extends e_form
|
||||
);
|
||||
$models[] = $controller->getConfig();
|
||||
|
||||
return $this->createForm($forms, $models, e_AJAX_REQUEST);
|
||||
return $this->renderCreateForm($forms, $models, e_AJAX_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3667,8 +3672,10 @@ class e_admin_form_ui extends e_form
|
||||
$controller = $this->getController();
|
||||
|
||||
$request = $controller->getRequest();
|
||||
$tree = $controller->getTreeModel();
|
||||
$options = array(
|
||||
$id = $this->getElementId();
|
||||
$tree = $options = array();
|
||||
$tree[$id] = $controller->getTreeModel();
|
||||
$options[$id] = array(
|
||||
'id' => $this->getElementId(), // unique string used for building element ids, REQUIRED
|
||||
'pid' => $controller->getPrimaryName(), // primary field name, REQUIRED
|
||||
//'url' => e_SELF, default
|
||||
@ -3681,7 +3688,7 @@ class e_admin_form_ui extends e_form
|
||||
'fields' => $controller->getFields(), // see e_admin_ui::$fields
|
||||
'fieldpref' => $controller->getFieldPref(), // see e_admin_ui::$fieldpref
|
||||
'table_pre' => '', // markup to be added before opening table element
|
||||
'table_post' => !$tree->isEmpty() ? $this->renderBatch($controller->getBatchDelete()) : '',
|
||||
'table_post' => !$tree[$id]->isEmpty() ? $this->renderBatch($controller->getBatchDelete()) : '',
|
||||
'fieldset_pre' => '', // markup to be added before opening fieldset element
|
||||
'fieldset_post' => '', // markup to be added after closing fieldset element
|
||||
'perPage' => $controller->getPerPage(), // if 0 - no next/prev navigation
|
||||
@ -3689,7 +3696,7 @@ class e_admin_form_ui extends e_form
|
||||
'field' => $controller->getQuery('field'), //current order field name, default - primary field
|
||||
'asc' => $controller->getQuery('asc', 'desc'), //current 'order by' rule, default 'asc'
|
||||
);
|
||||
return $this->listForm($options, $tree, $ajax);
|
||||
return $this->renderListForm($options, $tree, $ajax);
|
||||
}
|
||||
|
||||
function renderFilter($current_query = array(), $location = '', $input_options = array())
|
||||
|
@ -9,9 +9,9 @@
|
||||
* Form Handler
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $
|
||||
* $Revision: 1.88 $
|
||||
* $Date: 2009-11-20 05:01:31 $
|
||||
* $Author: e107coders $
|
||||
* $Revision: 1.89 $
|
||||
* $Date: 2009-11-21 11:15:28 $
|
||||
* $Author: secretr $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -1367,7 +1367,7 @@ class e_form
|
||||
* Expected options array format:
|
||||
* <code>
|
||||
* <?php
|
||||
* $options = array(
|
||||
* $form_options['myplugin'] = array(
|
||||
* 'id' => 'myplugin', // unique string used for building element ids, REQUIRED
|
||||
* 'pid' => 'primary_id', // primary field name, REQUIRED
|
||||
* 'url' => '{e_PLUGIN}myplug/admin_config.php', // if not set, e_SELF is used
|
||||
@ -1388,82 +1388,88 @@ class e_form
|
||||
* 'field' => 'field_name', //current order field name, default - primary field
|
||||
* 'asc' => 'desc', //current 'order by' rule, default 'asc'
|
||||
* );
|
||||
* $list = new e_admin_tree_model($data);
|
||||
* $tree_models['myplugin'] = new e_admin_tree_model($data);
|
||||
* </code>
|
||||
* TODO - move fieldset & table generation in separate methods, needed for ajax calls
|
||||
* @param array $options
|
||||
* @param e_admin_tree_model $list
|
||||
* @param array $form_options
|
||||
* @param e_admin_tree_model $tree_model
|
||||
* @param boolean $nocontainer don't enclose form in div container
|
||||
* @return string
|
||||
*/
|
||||
public function listForm($options, $list, $nocontainer = false)
|
||||
public function renderListForm($form_options, $tree_models, $nocontainer = false)
|
||||
{
|
||||
$tp = e107::getParser();
|
||||
$tree = $list->getTree();
|
||||
$total = $list->getTotal();
|
||||
|
||||
$amount = $options['perPage'];
|
||||
$from = vartrue($options['from'], 0);
|
||||
$field = vartrue($options['field'], $options['pid']);
|
||||
$asc = strtoupper(vartrue($options['asc'], 'asc'));
|
||||
$elid = $options['id'];
|
||||
$query = isset($options['query']) ? $options['query'] : e_QUERY ;
|
||||
$url = (isset($options['url']) ? $tp->replaceConstants($options['url'], 'abs') : e_SELF);
|
||||
$formurl = $url.($query ? '?'.$query : '');
|
||||
$fields = $options['fields'];
|
||||
$current_fields = varset($options['fieldpref']) ? $options['fieldpref'] : array_keys($options['fields']);
|
||||
|
||||
$text = "
|
||||
<form method='post' action='{$formurl}' id='{$elid}-list-form'>
|
||||
".vartrue($options['fieldset_pre'])."
|
||||
<fieldset id='{$elid}-list'>
|
||||
<legend class='e-hideme'>".$options['legend']."</legend>
|
||||
".vartrue($options['table_pre'])."
|
||||
<table cellpadding='0' cellspacing='0' class='adminlist' id='{$elid}-list-table'>
|
||||
".$this->colGroup($fields, $current_fields)."
|
||||
".$this->thead($fields, $current_fields, varset($options['head_query']), varset($options['query']))."
|
||||
<tbody>
|
||||
";
|
||||
|
||||
if(!$tree)
|
||||
{
|
||||
$text .= "
|
||||
<tr>
|
||||
<td colspan='".count($current_fields)."' class='center middle'>".LAN_NO_RECORDS."</td>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
else
|
||||
foreach ($form_options as $fid => $options)
|
||||
{
|
||||
$tree_model = $tree_models[$fid];
|
||||
$tree = $tree_model->getTree();
|
||||
$total = $tree_model->getTotal();
|
||||
|
||||
foreach($tree as $model)
|
||||
$amount = $options['perPage'];
|
||||
$from = vartrue($options['from'], 0);
|
||||
$field = vartrue($options['field'], $options['pid']);
|
||||
$asc = strtoupper(vartrue($options['asc'], 'asc'));
|
||||
$elid = $fid;//$options['id'];
|
||||
$query = isset($options['query']) ? $options['query'] : e_QUERY ;
|
||||
$url = (isset($options['url']) ? $tp->replaceConstants($options['url'], 'abs') : e_SELF);
|
||||
$formurl = $url.($query ? '?'.$query : '');
|
||||
$fields = $options['fields'];
|
||||
$current_fields = varset($options['fieldpref']) ? $options['fieldpref'] : array_keys($options['fields']);
|
||||
|
||||
$text = "
|
||||
<form method='post' action='{$formurl}' id='{$elid}-list-form'>
|
||||
".vartrue($options['fieldset_pre'])."
|
||||
<fieldset id='{$elid}-list'>
|
||||
<legend class='e-hideme'>".$options['legend']."</legend>
|
||||
".vartrue($options['table_pre'])."
|
||||
<table cellpadding='0' cellspacing='0' class='adminlist' id='{$elid}-list-table'>
|
||||
".$this->colGroup($fields, $current_fields)."
|
||||
".$this->thead($fields, $current_fields, varset($options['head_query']), varset($options['query']))."
|
||||
<tbody>
|
||||
";
|
||||
|
||||
if(!$tree)
|
||||
{
|
||||
$text .= $this->renderTableRow($fields, $current_fields, $model->getData(), $options['pid']);
|
||||
$text .= "
|
||||
<tr>
|
||||
<td colspan='".count($current_fields)."' class='center middle'>".LAN_NO_RECORDS."</td>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</tbody>
|
||||
</table>
|
||||
".vartrue($options['table_post'])."
|
||||
";
|
||||
|
||||
|
||||
if($tree && $amount)
|
||||
{
|
||||
$parms = $total.",".$amount.",".$from.",".$url.'?'.($options['np_query'] ? $options['np_query'].'&' : '').'from=[FROM]';
|
||||
$text .= $tp->parseTemplate("{NEXTPREV={$parms}}");
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</fieldset>
|
||||
".vartrue($options['fieldset_post'])."
|
||||
</form>
|
||||
";
|
||||
if(!$nocontainer)
|
||||
{
|
||||
$text = '<div class="e-container">'.$text.'</div>';
|
||||
else
|
||||
{
|
||||
|
||||
foreach($tree as $model)
|
||||
{
|
||||
$text .= $this->renderTableRow($fields, $current_fields, $model->getData(), $options['pid']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</tbody>
|
||||
</table>
|
||||
".vartrue($options['table_post'])."
|
||||
";
|
||||
|
||||
|
||||
if($tree && $amount)
|
||||
{
|
||||
$parms = $total.",".$amount.",".$from.",".$url.'?'.($options['np_query'] ? $options['np_query'].'&' : '').'from=[FROM]';
|
||||
$text .= $tp->parseTemplate("{NEXTPREV={$parms}}");
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</fieldset>
|
||||
".vartrue($options['fieldset_post'])."
|
||||
</form>
|
||||
";
|
||||
if(!$nocontainer)
|
||||
{
|
||||
$text = '<div class="e-container">'.$text.'</div>';
|
||||
}
|
||||
|
||||
}
|
||||
return (vartrue($options['form_pre']).$text.vartrue($options['form_post']));
|
||||
}
|
||||
@ -1507,7 +1513,7 @@ class e_form
|
||||
* @param boolean $nocontainer don't enclose in div container
|
||||
* @return string
|
||||
*/
|
||||
function createForm($forms, $models, $nocontainer = false)
|
||||
function renderCreateForm($forms, $models, $nocontainer = false)
|
||||
{
|
||||
$text = '';
|
||||
foreach ($forms as $fid => $form)
|
||||
@ -1523,103 +1529,9 @@ class e_form
|
||||
foreach ($form['fieldsets'] as $elid => $data)
|
||||
{
|
||||
$elid = $form['id'].'-'.$elid;
|
||||
$text .= vartrue($data['fieldset_pre'])."
|
||||
<fieldset id='{$elid}'>
|
||||
<legend>".vartrue($data['legend'])."</legend>
|
||||
".vartrue($data['table_pre'])."
|
||||
<table cellpadding='0' cellspacing='0' class='adminedit'>
|
||||
<colgroup span='2'>
|
||||
<col class='col-label' />
|
||||
<col class='col-control' />
|
||||
</colgroup>
|
||||
<tbody>
|
||||
";
|
||||
|
||||
foreach($data['fields'] as $key => $att)
|
||||
{
|
||||
// convert aliases - not supported in edit mod
|
||||
if(!$model->has($key) && $att['alias'])
|
||||
{
|
||||
$key = $att['field'];
|
||||
}
|
||||
$parms = vartrue($att['formparms'], array());
|
||||
if(!is_array($parms)) parse_str($parms, $parms);
|
||||
$label = vartrue($att['note']) ? '<div class="label-note">'.deftrue($att['note'], $att['note']).'</div>' : '';
|
||||
$help = vartrue($att['help']) ? '<div class="field-help">'.deftrue($att['help'], $att['help']).'</div>' : '';
|
||||
|
||||
// type null - system (special) fields
|
||||
if($att['type'] !== null && !vartrue($att['noedit']) && $key != $model->getFieldIdName())
|
||||
{
|
||||
$text .= "
|
||||
<tr>
|
||||
<td class='label'>
|
||||
".defset($att['title'], $att['title']).$label."
|
||||
</td>
|
||||
<td class='control'>
|
||||
".$this->renderElement($key, $model->getIfPosted($key), $att)."
|
||||
{$help}
|
||||
</td>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
//if($bckp) $model->remove($bckp);
|
||||
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</tbody>
|
||||
</table>
|
||||
".vartrue($data['table_post'])."
|
||||
<div class='buttons-bar center'>
|
||||
";
|
||||
// After submit options
|
||||
$defsubmitopt = array('list' => 'go to list', 'create' => 'create another', 'edit' => 'edit current');
|
||||
$submitopt = isset($data['after_submit_options']) ? $data['after_submit_options'] : true;
|
||||
if(true === $submitopt)
|
||||
{
|
||||
$submitopt = $defsubmitopt;
|
||||
}
|
||||
|
||||
if($submitopt)
|
||||
{
|
||||
$selected = isset($data['after_submit_default']) && array_key_exists($data['after_submit_default'], $submitopt) ? $data['after_submit_default'] : '';
|
||||
$text .= '
|
||||
<div class="options">
|
||||
After submit: '.$this->radio_multi('__after_submit_action', $submitopt, $selected, false).'
|
||||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
$triggers = vartrue($data['triggers'], 'auto');
|
||||
if(is_string($triggers) && 'auto' === $triggers)
|
||||
{
|
||||
$triggers = array();
|
||||
if($model->getId())
|
||||
{
|
||||
$triggers['submit'] = array(LAN_UPDATE, 'update', $model->getId());
|
||||
}
|
||||
else
|
||||
{
|
||||
$triggers['submit'] = array(LAN_CREATE, 'create', 0);
|
||||
}
|
||||
$triggers['cancel'] = array(LAN_CANCEL, 'cancel');
|
||||
}
|
||||
|
||||
foreach ($triggers as $trigger => $tdata)
|
||||
{
|
||||
$text .= $this->admin_button('etrigger_'.$trigger, $tdata[0], $tdata[1]);
|
||||
if(isset($tdata[2]))
|
||||
{
|
||||
$text .= $this->hidden($trigger.'_value', $tdata[2]);
|
||||
}
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</div>
|
||||
</fieldset>
|
||||
".vartrue($data['fieldset_post'])."
|
||||
";
|
||||
$text .= $this->renderCreateFieldset($elid, $data, $model, $nocontainer);
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</form>
|
||||
";
|
||||
@ -1632,6 +1544,120 @@ class e_form
|
||||
return $text;
|
||||
}
|
||||
|
||||
function renderCreateFieldset($id, $fdata, $model, $nocontainer = false)
|
||||
{
|
||||
$text = vartrue($fdata['fieldset_pre'])."
|
||||
<fieldset id='{$id}'>
|
||||
<legend>".vartrue($fdata['legend'])."</legend>
|
||||
".vartrue($fdata['table_pre'])."
|
||||
<table cellpadding='0' cellspacing='0' class='adminedit'>
|
||||
<colgroup span='2'>
|
||||
<col class='col-label' />
|
||||
<col class='col-control' />
|
||||
</colgroup>
|
||||
<tbody>
|
||||
";
|
||||
|
||||
foreach($fdata['fields'] as $key => $att)
|
||||
{
|
||||
// convert aliases - not supported in edit mod
|
||||
if($att['alias'] && !$model->hasData($key))
|
||||
{
|
||||
$key = $att['field'];
|
||||
}
|
||||
|
||||
$parms = vartrue($att['formparms'], array());
|
||||
if(!is_array($parms)) parse_str($parms, $parms);
|
||||
$label = vartrue($att['note']) ? '<div class="label-note">'.deftrue($att['note'], $att['note']).'</div>' : '';
|
||||
$help = vartrue($att['help']) ? '<div class="field-help">'.deftrue($att['help'], $att['help']).'</div>' : '';
|
||||
|
||||
$valPath = trim(vartrue($att['dataPath'], $key), '/');
|
||||
$keyName = $key;
|
||||
if(strpos($valPath, '/')) //not TRUE, cause string doesn't start with /
|
||||
{
|
||||
$tmp = explode('/', $valPath);
|
||||
$keyName = array_shift($tmp);
|
||||
foreach ($tmp as $path)
|
||||
{
|
||||
$keyName .= '['.$path.']';
|
||||
}
|
||||
}
|
||||
|
||||
// type null - system (special) fields
|
||||
if($att['type'] !== null && !vartrue($att['noedit']) && $key != $model->getFieldIdName())
|
||||
{
|
||||
$text .= "
|
||||
<tr>
|
||||
<td class='label'>
|
||||
".defset($att['title'], $att['title']).$label."
|
||||
</td>
|
||||
<td class='control'>
|
||||
".$this->renderElement($keyName, $model->getIfPosted($valPath), $att)."
|
||||
{$help}
|
||||
</td>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
//if($bckp) $model->remove($bckp);
|
||||
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</tbody>
|
||||
</table>
|
||||
".vartrue($fdata['table_post'])."
|
||||
<div class='buttons-bar center'>
|
||||
";
|
||||
// After submit options
|
||||
$defsubmitopt = array('list' => 'go to list', 'create' => 'create another', 'edit' => 'edit current');
|
||||
$submitopt = isset($fdata['after_submit_options']) ? $fdata['after_submit_options'] : true;
|
||||
if(true === $submitopt)
|
||||
{
|
||||
$submitopt = $defsubmitopt;
|
||||
}
|
||||
|
||||
if($submitopt)
|
||||
{
|
||||
$selected = isset($fdata['after_submit_default']) && array_key_exists($fdata['after_submit_default'], $submitopt) ? $fdata['after_submit_default'] : '';
|
||||
$text .= '
|
||||
<div class="options">
|
||||
After submit: '.$this->radio_multi('__after_submit_action', $submitopt, $selected, false).'
|
||||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
$triggers = vartrue($fdata['triggers'], 'auto');
|
||||
if(is_string($triggers) && 'auto' === $triggers)
|
||||
{
|
||||
$triggers = array();
|
||||
if($model->getId())
|
||||
{
|
||||
$triggers['submit'] = array(LAN_UPDATE, 'update', $model->getId());
|
||||
}
|
||||
else
|
||||
{
|
||||
$triggers['submit'] = array(LAN_CREATE, 'create', 0);
|
||||
}
|
||||
$triggers['cancel'] = array(LAN_CANCEL, 'cancel');
|
||||
}
|
||||
|
||||
foreach ($triggers as $trigger => $tdata)
|
||||
{
|
||||
$text .= $this->admin_button('etrigger_'.$trigger, $tdata[0], $tdata[1]);
|
||||
if(isset($tdata[2]))
|
||||
{
|
||||
$text .= $this->hidden($trigger.'_value', $tdata[2]);
|
||||
}
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</div>
|
||||
</fieldset>
|
||||
".vartrue($fdata['fieldset_post'])."
|
||||
";
|
||||
return $text;
|
||||
}
|
||||
|
||||
// The 2 functions below are for demonstration purposes only, and may be moved/modified before release.
|
||||
function filterType($fieldarray)
|
||||
{
|
||||
|
@ -9,8 +9,8 @@
|
||||
* e107 Base Model
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_handlers/model_class.php,v $
|
||||
* $Revision: 1.42 $
|
||||
* $Date: 2009-11-18 14:46:27 $
|
||||
* $Revision: 1.43 $
|
||||
* $Date: 2009-11-21 11:15:29 $
|
||||
* $Author: secretr $
|
||||
*/
|
||||
|
||||
@ -1195,9 +1195,10 @@ class e_admin_model extends e_model
|
||||
*/
|
||||
public function getIfPosted($key, $default = '', $index = null)
|
||||
{
|
||||
if(null !== $this->getPostedData((string) $key))
|
||||
$posted = $this->getPostedData((string) $key, null, $index);
|
||||
if(null !== $posted)
|
||||
{
|
||||
return e107::getParser()->post_toForm($this->getPostedData((string) $key, null, $index));
|
||||
return e107::getParser()->post_toForm($posted);
|
||||
}
|
||||
return e107::getParser()->toForm($this->getData((string) $key, $default, $index));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user