Jump to content

HannaCodeDialog


Robin S

Recommended Posts

1 hour ago, Robin S said:

Or here's a hacky solution that involves adding an extra "path" attribute to your Hanna tag..

Brilliant - thanks. I was thinking along those lines, but obviously not hacky enough 😁

  • Like 1
Link to comment
Share on other sites

12 hours ago, Robin S said:

Or here's a hacky solution that involves adding an extra "path" attribute to your Hanna tag...

Just to report that this works well. I also added some css to hide the path attribute in the dialog box, so as not to confuse the user or risk inadvertant amendment.

Super module , super support!

Link to comment
Share on other sites

Following the above discussion, I decided that it made more sense to display the title rather than the path (since it is only for display purposes). I also wanted a solution for attribute types pagelistselectmultiple, not just pagelistselect. In case it is useful to anyone else, my suggested js is:

$(document).ready(function() {
    /* Author: Mark Evens, based on an original script by Robin Sallis */
    /* This version displays the title text rather than the path name */
    /* It also works for pagelistselectmultiple as well as pagelistselect */

    /* Hide the text field  */
    /* id_title is the name of a text attribute in the hanna code*/
    /* change id_title throughout the code below to match your attribute name */
    $('#wrap_id_title').addClass('hide-field');

    // Must use mousedown instead of click event due to frustrating event propagation issues across PW core
    // https://github.com/processwire/processwire-issues/issues/1028
    // .PageListActionSelect is the button 'Select' with appears when a page is clicked (no normally visible - loaded by js)
    $(document).on('mousedown', '.PageListActionSelect a', function (event) {
        var id_title;
        // Adapt unselect label to suit your language
        if ($(this).text() === 'Unselect') {
            id_title = '';
        } else {
            id_title = ($(this).closest('.PageListItem').children('.PageListPage').text()); // replace .text() by .attr('title') for path name
        }
        $('#id_title').val(id_title);
    });

    // For pagelistselectmultiple, get all the selected pages when the selection is updated
    // This returns the contents of the label displayed in the pagelist item. This can be set in your HannaCodeDialog::buildForm hook
    // The default is the page title. For the path name, set $f->labelFieldName = 'path'; in your hook
    $(document).on('change', '.InputfieldPageListSelectMultiple', function(event) {
        var id_title = [];
        $(this).find('.InputfieldContent ol li:not(.itemTemplate)').each(function(){
            id_title.push($(this).children('span.itemLabel').text())
        })
        $('#id_title').val(id_title);
    });

});

To hide the id_title attribute in the dialog, you need to add the following css:

#hanna-form .hide-field {
  display: none !important;
}

 

  • Like 3
Link to comment
Share on other sites

@Robin S - I have been using this module since it was released and always thought it was a necessary tool for inserting Hanna codes, but I just starting using some of its other features like: linked_page__pagelistselect

which makes it an entirely new beast - amazing.

Thanks!

  • Like 4
Link to comment
Share on other sites

@Robin S - just discovered that if you have this attached to a field that is editable under a user's profile page, it breaks the field with a JS error because it can't load this component.

No rush for a fix for my needs, but someone else might come across it.

  • Like 1
Link to comment
Share on other sites

Thanks for the report @adrian.

The newly released v0.3.6 adds support for ProcessProfile and ProcessUser, and also adds a config field to show the Tracy debug bar in the dialog which can be helpful for debugging if you are building the dialog form with a hook.

  • Like 4
Link to comment
Share on other sites

@Robin S - I am trying to offer selection of an uploaded file and not sure if I am taking the most efficient approach, but either way, it's not quite working. I am using https://processwire.com/modules/fieldtype-select-file/ to give me a InputfieldSelectFile

$wire->addHookAfter('HannaCodeDialog::buildForm', function(HookEvent $event) {

    // The Hanna tag that is being opened in the dialog
    $tag_name = $event->arguments(0);

    // Other arguments if you need them
    /* @var Page $edited_page */
    $edited_page = $event->arguments(1); // The page open in Page Edit
    $current_attributes = $event->arguments(2); // The current attribute values
    $default_attributes = $event->arguments(3); // The default attribute values

    // The form rendered in the dialog
    /* @var InputfieldForm $form */
    $form = $event->return;

    if($tag_name === 'audio') {

        $modules = $event->wire('modules');

        /* @var InputfieldSelect $f */
        $f = $modules->InputfieldSelectFile;
        $f->name = 'selected_file';
        $f->id = 'selected_file';
        $f->label = 'Select File';
        $f->folderPath = 'assets/files/'.$edited_page->id.'/';
        $form->add($f);

    }

});

image.png.11df4fb41967af68a57ac2a557cd2b89.png

image.png.336021b43c2e6f894a7aa14cc420ce7f.png

All looks good so far, but then I end up with:

image.png.e54b3d00af90a7daf82b7ec16bad69ab.png

Any ideas what I might be doing wrong, or if there is a better way?

FYI, I had to change the root path in that File Select module to start at /site/ instead of /site/templates/

Thanks for any thoughts!

 

Link to comment
Share on other sites

4 minutes ago, adrian said:

I am using https://processwire.com/modules/fieldtype-select-file/ to give me a InputfieldSelectFile

If you're using non-core inputfields beyond those described in the module readme it will be a case of "your mileage may vary" and I can't really offer support for those kinds of cases.

I suggest just using a normal InputfieldSelect and setting the options from files in Files field(s) on the page, or via $files->find()/DirectoryIterator/glob.

  • Like 1
Link to comment
Share on other sites

7 minutes ago, Robin S said:

I suggest just using a normal InputfieldSelect and setting the options from files in Files field(s) on the page

Of course - that works perfectly, thank you!

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

Good day and once again thanks for the great module!

Is it possible to use ckeditor as an inputfield for text? I am trying to create a readmore hannacode and need to provide a rich text input for the content to be only partly shown.

Link to comment
Share on other sites

9 hours ago, Ivan Gretsky said:

Is it possible to use ckeditor as an inputfield for text?

No, CKEditor isn't a supported inputfield. I expect it would create rendering issues in the tag if it contains HTML, and if you are putting anything more than a short piece of text in your "read more" it would result in a huge, cumbersome tag widget.

Instead I think you should wrap the "read more" text in "open" and "close" Hanna tags.

[[rm-open]]
<p>Your text here.</p>
[[rm-close]]

Then replace the [[rm-open]] with a "Read more..." button and a div open tag, and the [[rm-close]] with a div close tag. Use JS to toggle the visibility of the div when the button is clicked.

You could also look at TextformatterPagination and TextformatterAccordion for inspiration but I think the above method would be the simplest.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

@Robin S - Ryan's update to the HannaCode module yesterday has broken this. Looks like it's probably just because he namespaced it, so should be an easy fix.

image.png.ed85b64ee977df76253cc62bf819aa91.png

PS - @teppo - I wonder if your HannaCodeHelper module might suffer the same fate?

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

On 4/8/2021 at 3:18 AM, adrian said:

Ryan's update to the HannaCode module yesterday has broken this. Looks like it's probably just because he namespaced it, so should be an easy fix.

Thanks. The v0.3.0 update to HannaCode is actually a major refactoring of the module so there were a few things in HannaCodeDialog that needed updating for compatibility. The new v0.4.0 of HannaCodeDialog should be compatible with HannaCode v0.3.0 and it requires HannaCode >= v0.3.0.

  • Like 6
  • Thanks 2
Link to comment
Share on other sites

  • 2 months later...

@Robin S

I'm having some issues with getting this to work – using the latest PW, and Hanna Code, and Hanna Code Dialog; The field with the hanna codes (body) isn't wrapping the codes so they just look like text and don't get identified as widgets. Not sure what i'm doing wrong; Tried uninstalling everything and re-install, but since the upgrades, no widgets; The HCD was working fine before I upgraded it...

thanks for any insights you might have - looking forward to using this on a particular project..

Link to comment
Share on other sites

55 minutes ago, Macrura said:

The field with the hanna codes (body) isn't wrapping the codes so they just look like text and don't get identified as widgets.

That sounds like a JavaScript issue - have a look for errors in the browser console. I just checked with the latest PW/HannaCode/HannaCodeDialog and it all seems to be working here.

  • Like 1
Link to comment
Share on other sites

Thanks!! - i just did another test and figured out the problem – tt only recognizes the shortcodes if you have the Hanna Code textformatter applied to the field.

I'm not actually using Hanna Code, i'm processing the shortcodes with my own textformatter, but using your module to enable editing of my custom shortcodes...

In any case, you're right and it completely works now; I have the Hanna Code Textformatter after my textformatter so it won't do anything (the codes will all be processed by the time it hits that one)..

Link to comment
Share on other sites

@Macrura - thanks to @Robin S in another post: https://processwire.com/talk/topic/15902-hannacodedialog/?do=findComment&comment=208498

// add hanna code dialog to fields even though the Hanna code text formatter isn't applied
// https://processwire.com/talk/topic/15902-hannacodedialog/?do=findComment&comment=208498
$this->wire()->addHookAfter('InputfieldCKEditor::renderReadyHook', function (HookEvent $event) {
    $inputfield = $event->object;
    $field = $inputfield->hasField;
    // For your field name(s)...
    if(!$field || $field->name !== 'XXXX') return;
    $config_name = "InputfieldCKEditor_{$field->name}";
    $config_name_matrix = "InputfieldCKEditor_{$field->name}_matrix";
    $config = $this->wire('config');
    $js_config = $config->js();
    foreach($js_config as $key => $value) {
        if($key === $config_name || strpos($key, $config_name_matrix) === 0) {
            $js_config[$key]['extraPlugins'] .= ',hannadropdown,hannadialog';
            $config->js($key, $js_config[$key]);
        }
    }
});

 

  • Like 2
Link to comment
Share on other sites

Couple of questions and issues...

(1)

On 2/11/2021 at 5:35 PM, Robin S said:
		// Add JS file to Hanna Code Dialog form
		$js_file = $config->paths->templates . 'hannas/select_page.js';
		if(is_file($js_file)) {
			$js_url = $config->urls->templates . 'hannas/select_page.js?v=' . filemtime($js_file);
			$form->appendMarkup = "<script src='$js_url'></script>";
		}

For some reason I can't get this to work at all; not sure why but my hook is in ready.php, and the markup is not appended to the form. I put my js into ACF ProcessPageEdit.js and that works, but it would be interesting to know why the code above didn't work, in case i wanted to keep the js file along with my other hanna code stuff.

(2) I enabled Tracy in the form (module config), but not getting any tracy...not loading. Wondering if there is any way to troubleshoot that.

(3) The CK editor widget things are great, makes it much easier for editors to see where a code is, and of course double click it to edit parameters.
But one thing that is tricky is getting the cursor in front of a widget, if it is the first thing in the editor. For me no problem of course i can just switch to code mode and put in some placeholder in front of it; but for the average user, i do wonder if there is any solution to this...

thanks!

 

 

Link to comment
Share on other sites

5 hours ago, Macrura said:

the markup is not appended to the form

Double-check that the path to your JS file is correct, because that conditional will only append the script markup if is_file() is true. With some debugging (see item 2) hopefully you can get it working. I just tested here again and it works for me.

 

5 hours ago, Macrura said:

(2) I enabled Tracy in the form (module config), but not getting any tracy

The label of that config setting is perhaps not perfect - I'll update it. The setting doesn't actually ensure that Tracy is displayed, rather it only disables the default CSS in the module that would otherwise hide the Tracy debug bar.

<?php if(!$hcd->show_tracy): ?>
	#tracy-debug { display:none !important; }
<?php endif; ?>

So you first need to have Tracy set to display the debug bar in the PW admin generally and then if you have that HCD setting checked it won't be hidden in the dialog.

 

5 hours ago, Macrura said:

But one thing that is tricky is getting the cursor in front of a widget

There's not much I can do about that because it's just how the CKEditor Widget plugin works. In such a situation I tend to use the arrow keys to move the cursor to the start of the field, or type the text underneath and then drag the widget to its new position.

hcd.gif.8cc40b7f3866f2316e30199bd67d3352.gif

  • Like 1
Link to comment
Share on other sites

Many thanks for your post and help! All has been revealed, and some facepalm moments...

(1) had to change $config to wire('config') (🤦‍♂️)
(2) had to set Tracy config to show in dialog  (🤦‍♂️)
(3) Yep, i'll just tell people up front if they need to put something in front of it, they need to move the widget..

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By Marco Ro
      Hi guys!
      I'm a bit anxious because this is the first module I present! (beta modulo) But I will finally be able to share something with the community too! :)
      This is a BETA version of the PayPal payment system called: PayPal Commerce Platform.
      It is an advanced system (Business Pro account is needed) that brings various benefits in terms of fees and above all integrates direct payment with credit/debit cards. 
      The module integrates with Padloper 0.0.2, which is the current installation I'm using.
      This system integrates the classic PayPal buy button, the alternative or local payment method and the new payment system: credit/debit cards that doesn't go through the PayPal account. It is a Stripe-style payment, it connects directly with the bank and integrates 3D security validation.
      I say that it is a BETA because this module currently only works with Sandbox account, to put it live you need to change API url manually (manually for the moment).
      Because this module is not ready for live:
      I would like to have your opinion on how I built the module (is the first one I do). I don't want to share something that is not fish but I need a comparison with someone more experienced than me, for be sure that this is the best way to code the module.
      If you want to try this I created a git, you will find all the instructions for installation and correct operation. (Git has a MIT licensed)
      https://github.com/MarcooRo/processwire-PayPal-Commerce-Platform I hope I did something that you guys can like :)
    • By monollonom
      (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website 😅. Thx @teppo !)
      FieldtypeQRCode
      Github: https://github.com/romaincazier/FieldtypeQRCode
      Modules directory: https://processwire.com/modules/fieldtype-qrcode/
      A simple fieldtype generating a QR Code from the public URL of the page, and more.
      Using the PHP library QR Code Generator by Kazuhiko Arase.

      Options
      In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default.
      You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field.
      If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated.
      Formatting
      Unformatted value
      When using $page->getUnformatted("qrcode_field") it returns an array with the following structure:
      [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value
      The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup.
      Should you need the same markup as in the admin you could use:
      $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value.
      Static QR code generator
      You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are:
      string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) Hooks
      Please have a look at the source code for more details about the hookable functions.
      Examples
      $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }) $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; })
    • By Sebi
      AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api. 
      This module relies on the base module AppApi, which must be installed before AppApiFile can do its work.
      Features
      You can access all files that are uploaded at any ProcessWire page. Call api/file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call api/file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.
      The GET-param "file" defines the basename of the file which you want to get.
      The following GET-params (optional) can be used to manipulate an image:
      width height maxwidth maxheight cropX cropY Use GET-Param format=base64 to receive the file in base64 format.
    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.
      https://github.com/techcnet/ProcessFileManager

      Warning
      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      Dragscroll
      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
       
×
×
  • Create New...