Skip to content

Commit

Permalink
feat: add rm-hints to field and template gui
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed May 16, 2023
1 parent b3c9add commit 27b5b25
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
32 changes: 25 additions & 7 deletions RockMigrations.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
// fix language tabs sometimes not having the correct language
$(window).load(function() {
if(typeof ProcessWire == 'undefined') return;
if(typeof ProcessWire.config == 'undefined') return;
if(typeof ProcessWire.config.rmUserLang == 'undefined') return;
$(window).load(function () {
if (typeof ProcessWire == "undefined") return;
if (typeof ProcessWire.config == "undefined") return;
if (typeof ProcessWire.config.rmUserLang == "undefined") return;
let lang = ProcessWire.config.rmUserLang;
setTimeout(() => {
let tabs = $(".langTab"+lang);
if(!tabs.length) return;
let tabs = $(".langTab" + lang);
if (!tabs.length) return;
tabs.click();
console.log('LanguageTabs set via RockMigrations');
console.log("LanguageTabs set via RockMigrations");
}, 200);
});

// add tooltips in the backend
$(document).ready(() => {
let addTooltip = function (el) {
let name = el.name;
if (name == "templateLabel") name = "label";
else if (name == "field_label") name = "label";
else if (name == "asmSelect0") return;
$(el).attr("title", name + " = " + el.value);
UIkit.tooltip(el);
console.log("added tooltip", el, el.value);
};
$(
".rm-hints input[name], .rm-hints textarea[name], .rm-hints select[name]"
).each((i, el) => {
addTooltip(el);
});
});
36 changes: 28 additions & 8 deletions RockMigrations.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function init()
$this->addHookBefore("Modules::uninstall", $this, "unwatchBeforeUninstall");
$this->addHookAfter("Modules::install", $this, "migrateAfterModuleInstall");
$this->addHookAfter("Page(template=admin)::render", $this, "addColorBar");
$this->addHookBefore("InputfieldForm::render", $this, "addRmHints");

// other actions on init()
$this->loadFilesOnDemand();
Expand Down Expand Up @@ -764,6 +765,17 @@ public function addPermissionToRole($permission, $role)
return $role->save();
}

public function addRmHints(HookEvent $event)
{
if (!$this->wire->user->isSuperuser()) return;
$form = $event->object;
$showHints = false;
if ($form->id == 'ProcessTemplateEdit') $showHints = true;
elseif ($form->id == 'ProcessFieldEdit') $showHints = true;
if (!$showHints) return;
$form->addClass('rm-hints');
}

/**
* Add role to user
*
Expand Down Expand Up @@ -1505,14 +1517,7 @@ public function downloadModule($url)
*/
public function echo($data)
{
if (is_array($data)) echo $log = print_r($data, true);
elseif (is_string($data)) echo $log = "$data\n";
else {
ob_start();
var_dump($data);
echo $log = ob_get_clean();
}
$this->wire->log->save("LineUpr", $log, [
$this->wire->log->save("LineUpr", $this->str($data), [
'showUser' => false,
'showUrl' => false,
]);
Expand Down Expand Up @@ -3811,6 +3816,21 @@ public function sort($data)
return $arr->sort('name');
}

/**
* Convert data to string (for logging)
*/
public function str($data): string
{
if (is_array($data)) return print_r($data, true);
elseif (is_string($data)) return "$data\n";
else {
ob_start();
var_dump($data);
return ob_get_clean();
}
return '';
}

/**
* Convert a comma separated string into an array of single values
*/
Expand Down

0 comments on commit 27b5b25

Please sign in to comment.