1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-20 04:32:01 +02:00

Page/Menu: Experimental Custom Fields

This commit is contained in:
Cameron 2017-01-19 12:39:28 -08:00
parent 7e6dbefd1a
commit 71730c2e6e
2 changed files with 129 additions and 32 deletions

View File

@ -9,7 +9,7 @@
* Custom Menus/Pages Administration
* Admin-related functions for custom page and menu creation
*/
define('e_MINIMAL',true);
//define('e_MINIMAL',true);
require_once('../class2.php');
if (!getperms("5|J")) { e107::redirect('admin'); exit; }
@ -77,6 +77,19 @@ class page_admin extends e_admin_dispatcher
);
protected $menuTitle = ADLAN_42;
function init()
{
}
}
class page_admin_form_ui extends e_admin_form_ui
@ -582,7 +595,7 @@ class page_admin_ui extends e_admin_ui
'page_title' => array('title'=> LAN_TITLE, 'tab' => 0, 'type' => 'text', 'inline'=>true, 'width'=>'25%', 'writeParms'=>'size=block-level'),
'page_chapter' => array('title'=> CUSLAN_63, 'tab' => 0, 'type' => 'dropdown', 'width' => '20%', 'filter' => true, 'batch'=>true, 'inline'=>true),
'page_template' => array('title'=> LAN_TEMPLATE, 'tab' => 0, 'type' => 'dropdown', 'width' => 'auto','filter' => true, 'batch'=>true, 'inline'=>true, 'writeParms'=>''),
'page_template' => array('title'=> LAN_TEMPLATE, 'tab' => 0, 'type' => 'dropdown', 'width' => 'auto','filter' => true, 'batch'=>true, 'inline'=>true, 'writeParms'=>array()),
'page_author' => array('title'=> LAN_AUTHOR, 'tab' => 0, 'type' => 'user', 'inline'=>true, 'data'=>'int','width' => 'auto', 'thclass' => 'left'),
'page_text' => array('title'=> CUSLAN_9, 'tab' => 0, 'type' => 'bbarea', 'data'=>'str', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1', 'writeParms'=>array('media'=>'page', 'template'=>'page')),
@ -768,9 +781,41 @@ class page_admin_ui extends e_admin_ui
$this->fields['page_chapter']['writeParms']['optArray'] = $this->cats;
$this->fields['page_chapter']['writeParms']['size'] = 'xxlarge';
if(e_DEBUG === true && $this->getAction() === 'edit')
if(e_DEBUG !== false && $this->getAction() === 'create')
{
// $this->initCustomFields();
$this->fields['page_chapter']['writeParms']['ajax'] = array('src'=>e_SELF."?mode=page&action=chapter-change",'target'=>'tabadditional');
}
if(e_AJAX_REQUEST && isset($_POST['page_chapter']) ) //&& $this->getAction() === 'chapter-change'
{
$this->initCustomFields($_POST['page_chapter']);
$elid = 'core-page-create';
$model = $this->getModel();
$tabId = 'additional';
$data = array(
'tabs' => $this->getTabs(),
'legend' => '',
'fields' => $this->getFields(),
);
$text = $this->getUI()->renderCreateFieldset($elid, $data, $model, $tabId);
if(empty($text))
{
echo "<div class='alert alert-info alert-block'>There are no additional fields for the selected chapter</div>";
}
else
{
echo $text;
}
exit;
}
@ -778,48 +823,79 @@ class page_admin_ui extends e_admin_ui
}
private function initCustomFields()
private function initCustomFields($chap=null)
{
$row = e107::getDb()->retrieve('page', 'page_chapter, page_fields', 'page_id='.$this->getId());
$chap = intval($row['page_chapter']);
$this->tabs['additional'] = "Additional Fields";
$this->getModel()->set('page_fields', null);
if(!empty($this->chapterFields[$chap]))
{
$curVal = e107::unserialize($row['page_fields']);
$this->tabs[] = "Additional Fields";
$tabCount = count($this->tabs) -1;
foreach($this->chapterFields[$chap] as $key=>$fld)
if(!empty($this->chapterFields[$chap]))
{
$fld['tab'] = $tabCount;
$fld['data'] = false;
foreach($this->chapterFields[$chap] as $key=>$fld)
{
$fld['tab'] = 'additional';
$fld['data'] = false;
$this->fields['page_fields__'.$key] = $fld;
$this->fields['page_fields__'.$key] = $fld;
}
$this->getModel()->set('page_fields__'.$key, $curVal[$key]);
}
}
}
private function loadCustomFieldsData()
{
$row = e107::getDb()->retrieve('page', 'page_chapter, page_fields', 'page_id='.$this->getId());
$chap = intval($row['page_chapter']);
$this->getModel()->set('page_fields', null);
$curVal = e107::unserialize($row['page_fields']);
if(!empty($this->chapterFields[$chap]))
{
foreach($this->chapterFields[$chap] as $key=>$fld)
{
$this->getModel()->set('page_fields__'.$key, $curVal[$key]);
}
}
}
function CreateObserver()
{
parent::CreateObserver();
$this->initCustomFields(0);
}
// Override default so we can alter the field db table data after it is loaded. .
function EditObserver()
{
$this->getModel()->load($this->getId());
$this->addTitle();
if(e_DEBUG !== true)
parent::EditObserver();
if(!deftrue('e_DEBUG'))
{
return;
}
$this->initCustomFields();
$row = e107::getDb()->retrieve('page', 'page_chapter, page_fields', 'page_id='.$this->getId());
$chap = intval($row['page_chapter']);
$this->initCustomFields($chap);
$this->loadCustomFieldsData();
}

View File

@ -1112,7 +1112,7 @@ class e_form
}
e107::getDebug()->log($sc_parameters);
// e107::getDebug()->log($sc_parameters);
$default_thumb = $default;
$class = '';
@ -4866,9 +4866,11 @@ e107::getDebug()->log($sc_parameters);
$ajaxParms['data-src'] = varset($parms['ajax']['src']);
$ajaxParms['data-target'] = varset($parms['ajax']['target']);
$ajaxParms['data-method'] = varset($parms['ajax']['method'], 'html');
$ajaxParms['data-loading'] = varset($parms['ajax']['loading'], $tp->toGlyph('fa-spinner', array('spin'=>1)));
$ajaxParms['data-loading'] = varset($parms['ajax']['loading'], 'fa-spinner'); //$tp->toGlyph('fa-spinner', array('spin'=>1))
unset($attributes['writeParms']['ajax']);
// e107::getDebug()->log($parms['ajax']);
}
if(!empty($attributes['multilan']))
@ -5590,7 +5592,7 @@ e107::getDebug()->log($sc_parameters);
".$this->token()."
";
foreach ($form['fieldsets'] as $elid => $data) //XXX rename 'fieldsets' to 'forms' ?
foreach ($form['fieldsets'] as $elid => $data)
{
$elid = $form['id'].'-'.$elid;
@ -5609,6 +5611,12 @@ e107::getDebug()->log($sc_parameters);
{
$active = (strval($tabId) === $curTab) ? 'active' : '';
$text .= '<div class="tab-pane '.$active.'" id="tab'.$tabId.'">';
// e107::getDebug()->log('elid: '.$elid. " tabid: ".$tabId);
// e107::getDebug()->log($data);
// e107::getDebug()->log($model);
$text .= $this->renderCreateFieldset($elid, $data, $model, $tabId);
$text .= "</div>";
}
@ -5648,12 +5656,13 @@ e107::getDebug()->log($sc_parameters);
* @param string $id field id
* @param array $fdata fieldset data
* @param object $model
* @return string
* @return string | false
*/
function renderCreateFieldset($id, $fdata, $model, $tab=0)
{
$text = vartrue($fdata['fieldset_pre'])."
$start = vartrue($fdata['fieldset_pre'])."
<fieldset id='{$id}-".$tab."'>
<legend>".vartrue($fdata['legend'])."</legend>
".vartrue($fdata['table_pre'])."
@ -5665,6 +5674,8 @@ e107::getDebug()->log($sc_parameters);
<tbody>
";
$text = '';
// required fields - model definition
$model_required = $model->getValidationRules();
$required_help = false;
@ -5830,17 +5841,27 @@ e107::getDebug()->log($sc_parameters);
$required_help = '<div class="form-note">'.$this->getRequiredString().' - required fields</div>'; //TODO - lans
}
$text .= "
if(!empty($text) || !empty($hidden_fields))
{
$text = $start.$text;
$text .= "
</tbody>
</table>";
$text .= implode("\n", $hidden_fields);
$text .= implode("\n", $hidden_fields);
$text .= "</fieldset>";
$text .= vartrue($fdata['fieldset_post']);
return $text;
}
$text .= "</fieldset>";
$text .= vartrue($fdata['fieldset_post']);
return $text;
return false;
/*
$text .= "