Skip to content

Commit

Permalink
Issue #5083 - Inline editor order fix for userclasses etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed Sep 25, 2023
1 parent cb1bbc7 commit 26f393b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
38 changes: 12 additions & 26 deletions e107_handlers/form_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3795,18 +3795,18 @@ public function submit_image($name, $value, $image, $title='', $options = array(
switch ($image)
{
case 'edit':
$icon = deftrue('e_ADMIN_AREA') ? ADMIN_EDIT_ICON : $tp->toIcon('e-edit-32');
$icon = deftrue('e_ADMIN_AREA') ? defset('ADMIN_EDIT_ICON') : $tp->toIcon('e-edit-32');
$options['class'] = $options['class'] === 'action' ? 'btn btn-default btn-secondary action edit' : $options['class'];
break;

case 'delete':
$icon = deftrue('e_ADMIN_AREA') ? ADMIN_DELETE_ICON : $tp->toIcon('fa-trash.glyph');
$icon = deftrue('e_ADMIN_AREA') ? defset('ADMIN_DELETE_ICON') : $tp->toIcon('fa-trash.glyph');
$options['class'] = $options['class'] === 'action' ? 'btn btn-default btn-secondary action delete' : $options['class'];
$options['data-confirm'] = LAN_JSCONFIRM;
break;

case 'execute':
$icon = deftrue('e_ADMIN_AREA') ? ADMIN_EXECUTE_ICON : $tp->toIcon('fa-power-off.glyph');
$icon = deftrue('e_ADMIN_AREA') ? defset('ADMIN_EXECUTE_ICON') : $tp->toIcon('fa-power-off.glyph');
$options['class'] = $options['class'] === 'action' ? 'btn btn-default btn-secondary action execute' : $options['class'];
break;

Expand Down Expand Up @@ -5050,11 +5050,11 @@ public function renderInline($dbField, $pid, $fieldName, $curVal, $linkText, $ty
{
foreach($array as $k=>$v)
{
$jsonArray[$k] = str_replace("'", '`', (string) $v);
$jsonArray[] = ['value' => $k, 'text' => str_replace("'", '`', (string) $v)]; // required format to retain order of elements.
}
}

$source = $this->tp->toJSON($jsonArray, true);
$source = $this->tp->toJSON($jsonArray);

$mode = preg_replace('/[\W]/', '', vartrue($_GET['mode']));

Expand Down Expand Up @@ -5083,7 +5083,9 @@ public function renderInline($dbField, $pid, $fieldName, $curVal, $linkText, $ty
'data-value' => $curVal,
'href' => '#',
];

$options['token'] = $this->inlineToken();

if (!empty($options))
{
foreach ($options as $k => $opt)
Expand Down Expand Up @@ -5238,7 +5240,7 @@ private function renderOptions($parms, $id, $attributes)
'style' => 'cursor:move',
'data-target' => e_SELF . "?mode=$mode&action=sort&ajax_used=1&from=$from",
'title' => LAN_RE_ORDER,
]) . ">" . ADMIN_SORT_ICON . '</a> ';
]) . ">" . defset('ADMIN_SORT_ICON') . '</a> ';
}


Expand Down Expand Up @@ -6057,24 +6059,8 @@ public function renderValue($field, $value, $attributes, $id = 0)
$uc_options = vartrue($parms['classlist'], 'public,guest, nobody,member,admin,main,classes'); // defaults to 'public,guest,nobody,member,classes' (userclass handler)
$array = e107::getUserClass()->uc_required_class_list($uc_options); //XXX Ugly looking (non-standard) function naming - TODO discuss name change.

//$mode = preg_replace('/[^\w]/', '', vartrue($_GET['mode'], ''));
$mode = $tp->filter(vartrue($_GET['mode']), 'w');
$source = str_replace('"', "'", json_encode($array, JSON_FORCE_OBJECT));

//NOTE Leading ',' required on $value; so it picks up existing value.
$value = "<a" . $this->attributes([
'class' => "e-tip e-editable editable-click",
'data-placement' => 'bottom',
'data-value' => ",$value",
'data-name' => $field,
'data-source' => $source,
'title' => LAN_EDIT . ' ' . $attributes['title'],
'data-type' => 'checklist',
'data-pk' => $id,
'data-token' => $this->inlineToken(),
'data-url' => e_SELF . "?mode=$mode&action=inline&id=$id&ajax_used=1",
'href' => '#',
]) . ">" . $dispvalue . '</a>';
$value = $this->renderInline($field,$id,$attributes['title'],",$value",$dispvalue,'checklist',$array,['placement'=>'bottom']);
}
else
{
Expand Down Expand Up @@ -6193,7 +6179,7 @@ public function renderValue($field, $value, $attributes, $id = 0)
*/
case 'bool':
case 'boolean':
$false = vartrue($parms['trueonly']) ? '' : ADMIN_FALSE_ICON;
$false = vartrue($parms['trueonly']) ? '' : defset('ADMIN_FALSE_ICON');

if(!empty($parms['enabled']))
{
Expand Down Expand Up @@ -6240,11 +6226,11 @@ public function renderValue($field, $value, $attributes, $id = 0)

if(!empty($parms['reverse']))
{
$value = ($value) ? $false : ADMIN_TRUE_ICON;
$value = ($value) ? $false : defset('ADMIN_TRUE_ICON');
}
else
{
$value = $value ? ADMIN_TRUE_ICON : $false;
$value = $value ? defset('ADMIN_TRUE_ICON') : $false;
}

break;
Expand Down
35 changes: 35 additions & 0 deletions e107_tests/tests/unit/e_formTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,41 @@ public function testRenderElementDropdown()

$this->assertSame($expected, $result);
}

public function testRenderValueUserclassesInline()
{

$field = array('title'=>'Userclasses', 'type'=>'userclasses', 'inline'=>true);
$result = $this->_frm->renderValue('uc', 252, $field,999);

$result = str_replace(array("\n", "\r"), "", $result);

$tags = e107::getParser()->getTags($result,'a');

$this->assertNotEmpty($tags['a'][0]);

$expected = array (
'class' => 'e-tip e-editable editable-click ',
'data-placement' => 'bottom',
'data-value' => ',252',
'data-name' => 'uc',
'data-source' => '[{"value":0,"text":"Everyone (public)"},{"value":252,"text":"Guests"},{"value":255,"text":"No One (inactive)"},{"value":253,"text":"Members"},{"value":254,"text":"Admin"},{"value":250,"text":"Main Admin"},{"value":249,"text":"Admins and Mods"},{"value":2,"text":"CONTACT PEOPLE"},{"value":248,"text":"Forum Moderators"},{"value":1,"text":"PRIVATEMENU"},{"value":3,"text":"NEWSLETTER"}]',
'title' => 'Edit Userclasses',
'data-type' => 'checklist',
'data-pk' => '999',
'href' => '#',
);

foreach($expected as $k=>$value)
{
$this->assertSame($value, $tags['a'][0][$k], "Failed '$k' is not the same");
}

$this->assertNotEmpty($tags['a'][0]['data-token']);
$this->assertNotEmpty($tags['a'][0]['data-url']);


}
/*
public function testRenderListForm()
{
Expand Down

0 comments on commit 26f393b

Please sign in to comment.