Jump to content
apeisa

Fredi - friendly frontend editing

Recommended Posts

When I try to fill it with images using fredi on the frontend the edit modal pops up as expected and the "choose file" button for the field brings up my file explorer.  When I choose an image you can see that the image is trying to load but nothing happens.  

I'm not sure I totally understand the issue and might need a little screengrab/video to see exactly what you are talking about. But any javascript errors occurring in your JS console? It sounds like there would be two modals on top of each other here, and wondering if the targets are getting mixed up. 

Share this post


Link to post
Share on other sites

Ryan, for some reason images / files inside repeater doesn't work in Fredi. I have (blindly) added setTrackChanges(true) in different places, but without any luck. I recorded screencast that should open this issue better: 

(video works now).

I am pretty sure that the problem isn't JS side (console is silent, response seems to be ok). Problematic code is here (it works without repeaters just fine): https://github.com/apeisa/Fredi/blob/master/FrediProcess.module#L54

Share this post


Link to post
Share on other sites

Thanks for the screencast Antti. Your cat sounds exactly like mine. :) This definitely helps clarify for me what the issue is. On the other hand, I'm still at a loss to know what is causing it. It's interesting to see the responses all appear successful and no indication of errors. I hope to experiment more with this soon. Correct me if I'm wrong, but doesn't it seem like the bit of code starting here is where it's getting stuck?

  • Like 1

Share this post


Link to post
Share on other sites

Your cat sounds exactly like mine. :) This definitely helps clarify for me what the issue is. 

You understand their language? My cat understand code? Joking aside, we actually have four cats and I have no clue which one is performing there...

I debugged this little more. The responses are actually totally wrong: it responses with page save instead of field save. This is what I get when saving in normal admin:

[
    {
        "error": false,
        "message": "Added file: desert.jpg",
        "file": "/frontendedit/site/assets/files/1037/desert.jpg",
        "size": 845941,
        "markup": "\n\t<li class='InputfieldFile InputfieldImage ui-widget'>\n\t\t<p class='InputfieldFileInfo ui-widget ui-widget-header'>\n\t\t\t<span class='ui-icon ui-icon-arrowthick-2-n-s'></span>\n\t\t\t<span class='InputfieldFileName'>desert.jpg</span> \n\t\t\t<span class='InputfieldFileStats'>• 826 kB • 1024x768</span> \n\t\t\t<label class='InputfieldFileDelete'><input type='checkbox' name='delete_images_2057dd75f2e9f7b52e3dda4ccd0ea4a2' value='1' /><span class='ui-icon ui-icon-trash'>Delete</span></label>\n\t\t\t<a class='InputfieldFileMove InputfieldFileMoveBottom' href='#'><span class='ui-icon ui-icon-arrowthickstop-1-s'></span></a> \n\t\t\t<a class='InputfieldFileMove InputfieldFileMoveTop' href='#'><span class='ui-icon ui-icon-arrowthickstop-1-n'></span></a> \n\t\t</p>\n\t\t<p class='InputfieldFileData ui-widget ui-widget-content'>\n\t\t\t<a class='InputfieldFileLink' target='_blank' href='/frontendedit/site/assets/files/1037/desert.jpg'><img src='/frontendedit/site/assets/files/1037/desert.0x100.jpg' alt='desert.jpg' /></a>\n\t\t\t<label class='InputfieldFileTags'><span class='detail'>Tags</span><input type='text' name='tags_images_2057dd75f2e9f7b52e3dda4ccd0ea4a2' id='tags_images_2057dd75f2e9f7b52e3dda4ccd0ea4a2' value='' /></label><label class='InputfieldFileDescription'><span class='detail'>Description</span><input type='text' name='description_images_2057dd75f2e9f7b52e3dda4ccd0ea4a2' id='description_images_2057dd75f2e9f7b52e3dda4ccd0ea4a2' value='' /></label>\n\t\t\t<input class='InputfieldFileSort' type='text' name='sort_images_2057dd75f2e9f7b52e3dda4ccd0ea4a2' value='1' />\n\t\t</p>\n\t</li>",
        "replace": false
    }
]

And this is what I get from ProcessFredi:

{
    "error": false,
    "message": "Saved page '1035' multiple fields"
}

So it seems that my code is too eager or something. This is where I believe the problems are: https://github.com/apeisa/Fredi/blob/master/FrediProcess.module#L54

Share this post


Link to post
Share on other sites
You understand their language? My cat understand code? Joking aside, we actually have four cats and I have no clue which one is performing there...

We have 3 cats, and two of them are into singing. Your cat sounds like our cat Sasha. 

I debugged this little more. The responses are actually totally wrong: it responses with page save instead of field save. This is what I get when saving in normal admin:

I'm thinking the gateway if() might be here. That $numFields variable must be greater than 1 since your JSON response says "multiple fields". Yet I think you want it to be 1. And it looks that could happen if HTTP_X_FIELDNAME wasn't set for one reason or another, here

I don't understand the technical details of how Fredi works yet (though hoping to learn soon), but I do wonder if this could be solved by just sending the ajax post request to ProcessPageEdit only, rather than Fredi? The reason is that it seems like if something is hooking into ProcessPageEdit, that Fredi doesn't call, wouldn't get executed. An example is this line in FieldtypeRepeater, which I think is attaching a hook that doesn't get executed via Fredi. 

One other thing, unrelated, is that it looks like these lines should be moved above the ajax section in your execute() function?

// Check if there is not such a page found
if ( ! $this->pageContext->id) throw new WireException("Page not found");

// Check that this page is editable by current user
if ( ! $this->pageContext->editable()) throw new WireException("You don't have right to edit this page")

Share this post


Link to post
Share on other sites

Yes, that's it. If I change fredi form to use /page/edit/ directly, the image field inside repeater works. But normal saving fails, and I think because the forms are different, so the processing doesn't go right. I tried to get them to same structure by getting page edit form and then removing the fields that aren't needed. But cannot get the removing going.

I have changed the renderFieldsForm to this:

public function renderFieldsForm() {
	$this->fieldsArray = explode("|", $this->fields);
		
	foreach($this->fieldsArray as $fieldName) {
		// Check if page has the field that wants to be edited
		if ( ! $this->pageContext->fields->has($fieldName)) throw new WireException("There is no field $fieldName on editable page");
			
		// Check if the current user has rights to edit that field
		if ( ! $this->pageContext->editable($fieldName)) throw new WireException("You don't have rights to edit field $fieldName");
	}

	$form = $this->modules->get('InputfieldForm');
	$form = $this->pageEdit->buildForm($form);
	$form->attr("action", "/processwire/page/edit/?id=$this->pageId&modal=1"); //TODO: url is hardcoded now..
	
	// Build the form (loop fields and add their respected inputfields)
	foreach($form->fields as &$field) {
		if ( ! in_array($field->name, $this->fieldsArray)) {
			$form->remove($field); // Script goes here, but it doesn't remove the field
		}
	}
	
	return $form->render();
}

I don't understand why, but $form->remove($field) isn't working.

Share this post


Link to post
Share on other sites

Hi Antti,

So I have Fredi installed, the header and JS code in place. My template edit access is set to admin as well as another role. I have a user setup with that role enabled. Can I still use Fredi for that non-superuser user?

Regards

Marty

Share this post


Link to post
Share on other sites

Marty, I'm sure Antti will confirm, but the basic tenet is that if the user has the correct permission(s) to edit in the backend then they can edit in the frontend with Fredi. I use Fredi on one site with several user types and all permissions apply across backend and Fredi.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks Dave. I thought as much. It might just be me being daft somewhere along the line.

Share this post


Link to post
Share on other sites

Hi,

I have just installed Fredi and am getting the following error when the edit window is displayed:

Notice: Undefined variable: out in \site\modules\Fredi\FrediProcess.module on line 116

$submit = $this->modules->get('InputfieldSubmit');        $form->add($submit);
        
        // If form was submitted, process it
        if (count($_POST)) return $this->processInput($form);
        
        $out .= $form->render();  // Line 112
        
        
        return $out;
 

Share this post


Link to post
Share on other sites

It's just a notice. To fix this right now you can change it easily:

$out = $form->render();

Apeisa will propably fix this in his repo.

Share this post


Link to post
Share on other sites

It's just a notice. To fix this right now you can change it easily:

$out = $form->render();

Apeisa will propably fix this in his repo.

Thanks  :-)

Share this post


Link to post
Share on other sites

Hey Apeisa, just took this for a test run and she rocks! I have developed something very similar, but I have to say your effort is just quite a bit nicer. I'll have to pull it apart to see how do did it, and learn some stuff at the same time no doubt.

Awesome job, frontend editing is what I loved from modX, PW just gets better and it feels complete now  :rolleyes:

I see you were looking at adding a $fredi->newPage method, is this still on the cards? This would be the ultimate. Thanks for the awesome module :rolleyes:

Edit: Hey, just noticed mention of work-in-progress on $fredi->newPage in another thread, look forward to seeing that.

Share this post


Link to post
Share on other sites

Don't know if anyone else is seeing this or it's something confined to my site, but when I use Fredi with a TinyMCE field and click the insert image icon I get an error: 

TemplateFile: No page specified

 
It works fine in the backend. 

Share this post


Link to post
Share on other sites

Hey Antti,

Does the current version support the "=50" field percentages that you mentioned? I'm using Fredi on the 2.3.5. PW build and I lose the 'edit' link whenever I try to use them. 

Share this post


Link to post
Share on other sites

Marty, that is implemented here, but not yet committed. I will add that soon, since there seems to be lots of interest for Fredi lately.

  • Like 1

Share this post


Link to post
Share on other sites

Ok, got little bit too excited and started building Fredi with Ajax saving & ajax page refresh (instead of the old clumsy submit => post processing => page reload). This is working great already, simplified code a lot and actually fixed the "images don't save inside repeaters" problem too. 

I also changed the code so that you won't be able to define the columns, but those will be inherited from the actual template context. This is great now that Ryan made tweaks along field dependencies so that there won't be "empty" spots at all (if fields doesn't make 100%, then last one in row will get larger). I also believe that even field dependencies will work on Fredi now (not tested yet).

Only problem I am having currently: it seems AjaxSave method doesn't support multilang fields yet? https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module#L1037

I have only two languages: "default" and "test". If I change the default title value and save, that new value will be put on the test title and default will remain old.

  • Like 1

Share this post


Link to post
Share on other sites

Note about ajax save & multilang: it actually save the default language to the langue that user has active. It ignores the others.

Share this post


Link to post
Share on other sites

Just pushed this "ajaxified" stuff on dev-branch: https://github.com/apeisa/Fredi/tree/dev

Hope you guys find time to test it. It feels superfast to use. Probably few bugs here and there, but we will sort those :)

Marty: I decided to leave the FieldName=<Width> syntax all together and it now uses whatever there is for the field on settings (old default was always 100% for each field).

Share this post


Link to post
Share on other sites

Hmm.. it seems repeaters don't work either (images inside repeaters do work, but images/files go different route). I guess that is because of lacking support in ProcessPageEdit::AjaxSave method, but not 100% sure about that.

Share this post


Link to post
Share on other sites

It does feel faster. Thanks for the update. The only thing I can see that doesn't work is image field re-ordering.

Share this post


Link to post
Share on other sites

Thanks Marty. That is probably also something that AjaxSave method in core doesn't support, at least yet.

I just pushed new version: I added animation after submit (modal goes small again with spinning wheel), which makes this feel faster than before. Also made some tweaks etc, and this version works great on IE (10 at least, not tested others yet, I don't believe this works in 8, but probably works in 9), Firefox and Chrome.

Hopefully someone of you Mac people can test if it works in Safari too?

Share this post


Link to post
Share on other sites

have you made hard refresh? works great here with chrome. also tested with Android browsers i have and all works.

Share this post


Link to post
Share on other sites

Yeah I did a hard refresh, clear cache, cleared any other modules out and still no go with being able to get past Submit on the modal box.

In Safari (6.0.5) I just get a blank modal box.

  • Like 1

Share this post


Link to post
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 bernhard
      --- Please use RockFinder3 ---
    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory (pending approval) If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
    • By Craig
      I've been using Fathom Analytics for a while now and on a growing number of sites, so thought it was about time there was a PW module for it.
      WayFathomAnalytics
      WayFathomAnalytics is a group of modules which will allow you to view your Fathom Analytics dashboard in the PW admin panel and (optionally) automatically add and configure the tracking code on front-end pages.
      Links
      GitHub Readme & documentation Download Zip Modules directory Module settings screenshot What is Fathom Analytics?
      Fathom Analytics is a simple, privacy-focused website analytics tool for bloggers and businesses.

      Stop scrolling through pages of reports and collecting gobs of personal data about your visitors, both of which you probably don't need. Fathom is a simple and private website analytics platform that lets you focus on what's important: your business.
      Privacy focused Fast-loading dashboards, all data is on a single screen Easy to get what you need, no training required Unlimited email reports Private or public dashboard sharing Cookie notices not required (it doesn't use cookies or collect personal data) Displays: top content, top referrers, top goals and more
    • By daniels
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      You can find the Module in the Modules directory and on Github
      It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe, update, unsubscribe or delete users to/from different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns *I have only tested it with PHP 7.x so far, so use on owners risk
      EDIT:
      Since 0.0.4, instructions and changelog can be found in the README only. You can find it here  🙂
      If you have questions or like to contribute, just post a reply or create an issue or pr on github, thanks!
    • By MoritzLost
      Sorry for the convoluted title. I have a problem with Process modules that define a custom page using the page key through getModuleInfo (as demonstrated in this excellent tutorial by @bernhard). Those pages are created automatically when the module is installed. The problem is that the title of the page only gets set in the current language. That's not a problem if the current language (language of the superuser who is installing the module) is the default language; if it isn't, the Process page is missing a title in the default language. This has the very awkward effect that a user using the backend in the default language (or any other language) will see an empty entry in the setup menu:

      This screenshot comes from my Cache Control module which includes a Process page. Now I realize the description sounds obscure, but for us it's a common setup: We a multiple bilingual sites where the default language is German and the second language is English. While the clients use the CMS in German, as a developer I prefer the English interface, so whenever I install a Process module I get this problem.
      As a module author, is there a way to handle this situation? I guess it would be possible to use post-installation hooks or create the pages manually, but I very much prefer the declarative approach. The page title is already translatable (through the __ function), but of course at the time of installation there is no translation, and as far as I'm aware it's not possible to ship translations with a module so they are used automatically. Could this situation be handled better in the core? I would prefer if the module installation process would always set the title of the Process page in the default language, instead of the language of the current user.
×
×
  • Create New...