1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-07 15:16:30 +02:00

Issue #5083 - Inline editor order fix for userclasses etc.

This commit is contained in:
camer0n
2023-09-25 10:07:48 -07:00
parent cb1bbc7f3c
commit 26f393b7ab
2 changed files with 47 additions and 26 deletions

View File

@@ -3795,18 +3795,18 @@ var_dump($select_options);*/
switch ($image) switch ($image)
{ {
case 'edit': 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']; $options['class'] = $options['class'] === 'action' ? 'btn btn-default btn-secondary action edit' : $options['class'];
break; break;
case 'delete': 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['class'] = $options['class'] === 'action' ? 'btn btn-default btn-secondary action delete' : $options['class'];
$options['data-confirm'] = LAN_JSCONFIRM; $options['data-confirm'] = LAN_JSCONFIRM;
break; break;
case 'execute': 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']; $options['class'] = $options['class'] === 'action' ? 'btn btn-default btn-secondary action execute' : $options['class'];
break; break;
@@ -5050,11 +5050,11 @@ var_dump($select_options);*/
{ {
foreach($array as $k=>$v) 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'])); $mode = preg_replace('/[\W]/', '', vartrue($_GET['mode']));
@@ -5083,7 +5083,9 @@ var_dump($select_options);*/
'data-value' => $curVal, 'data-value' => $curVal,
'href' => '#', 'href' => '#',
]; ];
$options['token'] = $this->inlineToken(); $options['token'] = $this->inlineToken();
if (!empty($options)) if (!empty($options))
{ {
foreach ($options as $k => $opt) foreach ($options as $k => $opt)
@@ -5238,7 +5240,7 @@ var_dump($select_options);*/
'style' => 'cursor:move', 'style' => 'cursor:move',
'data-target' => e_SELF . "?mode=$mode&action=sort&ajax_used=1&from=$from", 'data-target' => e_SELF . "?mode=$mode&action=sort&ajax_used=1&from=$from",
'title' => LAN_RE_ORDER, 'title' => LAN_RE_ORDER,
]) . ">" . ADMIN_SORT_ICON . '</a> '; ]) . ">" . defset('ADMIN_SORT_ICON') . '</a> ';
} }
@@ -6057,24 +6059,8 @@ var_dump($select_options);*/
$uc_options = vartrue($parms['classlist'], 'public,guest, nobody,member,admin,main,classes'); // defaults to 'public,guest,nobody,member,classes' (userclass handler) $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. $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. //NOTE Leading ',' required on $value; so it picks up existing value.
$value = "<a" . $this->attributes([ $value = $this->renderInline($field,$id,$attributes['title'],",$value",$dispvalue,'checklist',$array,['placement'=>'bottom']);
'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>';
} }
else else
{ {
@@ -6193,7 +6179,7 @@ var_dump($select_options);*/
*/ */
case 'bool': case 'bool':
case 'boolean': case 'boolean':
$false = vartrue($parms['trueonly']) ? '' : ADMIN_FALSE_ICON; $false = vartrue($parms['trueonly']) ? '' : defset('ADMIN_FALSE_ICON');
if(!empty($parms['enabled'])) if(!empty($parms['enabled']))
{ {
@@ -6240,11 +6226,11 @@ var_dump($select_options);*/
if(!empty($parms['reverse'])) if(!empty($parms['reverse']))
{ {
$value = ($value) ? $false : ADMIN_TRUE_ICON; $value = ($value) ? $false : defset('ADMIN_TRUE_ICON');
} }
else else
{ {
$value = $value ? ADMIN_TRUE_ICON : $false; $value = $value ? defset('ADMIN_TRUE_ICON') : $false;
} }
break; break;

View File

@@ -1306,6 +1306,41 @@ class e_formTest extends \Codeception\Test\Unit
$this->assertSame($expected, $result); $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() public function testRenderListForm()
{ {