GithubHelp home page GithubHelp logo

fredi's Introduction

Fredi - Friendly Frontend Editing for ProcessWire

(c) Antti Peisa 2013-2015

Introduction

Fredi will bring quick edit links to frontend. Developer can freely decide where she will output the links and how to style them. Edit link can be for a single field or for multiple fields together.

Clicking edit links will open modal view to quickly edit and save fields. After saving it will reload the page and content editor will see his changes immediatly.

Since Fredi will integrate on frontend (though only for admins), I wanted to keep it as lightweight as possible. There is no javascript library dependencies and only few lines of css required.

Installation

Extract /Fredi/ directory under your /site/modules/ directory and install the Fredi.module. It will automatically install the required FrediProcess.module.

Edit your template file(s) and load fredi there using this line:

$fredi = $modules->get("Fredi");

Best place for above line depends on how you are using your template files. But for basic demo site that PW ships with the best place would be right in the start of head.inc file.

Other thing you need to do is to add required JS and CSS to your html. Two files that are required are /Fredi/modal/modal.js and /Fredi/modal/modal.css. Easiest way to do that is load them using this code:

echo $fredi->renderScript();

It also includes fredi.js and fredi.css files, which creates "show only when hovered" styling. This is not optimal in all cases, so you can disable them by giving false as first param for renderScript method.

echo $fredi->renderScript(false);

Good place to add above line is inside your head-tags. Body is fine too, but it should be loaded before the first edit link you want to provide. There isn't any 3rd party code dependencies, so it doesn't matter if you have loaded any other scripts or not.

Using renderScript method is not required, you can load script other ways also (if you are using some common means to add styles and scripts to your site).

That's it, now you are ready for Fredi!

How to use

Using Fredi is very simple and you can easily implement it after you have already finished your site. So it doesn't force you to build your site in any special way.

Most simple example of Fredi is this:

Before:

echo $page->body;

After:

echo $fredi->body;
echo $page->body;

It will show "edit" link right before your body field. Link will be shown only for logged in users that have rights to edit that page (or to be precise, that field).

On version 1.1.0 and up, Fredi links will be automatically styled and positioned in relation of the parent element. You can of course tweak the styling with your own css.

Editing multiple fields

If you provide edit links for each of your fields, certain templates might get pretty crowded. Also certain fields are meant to go together. This is how you can feed Fredi with multiple fields:

echo $fredi->render("headline|title|summary");

Editing all the fields

If you want to show all the fields, you can achieve that with renderAll method:

echo $fredi->renderAll();

Setting page context

One thing we all love in ProcessWire is the ability to easily use content from other pages. Often we use content from pages that are not show on editor at all. Page context allows you to add edit links for other pages that the currently viewed one.

Setting page context for single field

echo $fredi->body($another_page);

Setting page context for multiple fields

echo $fredi->render("headline|title|images|body", $another_page);

Setting custom text and classes for edit links

Fields and page context are special settings in Fredi, since those are set per edit link. All the other settings can be given through setter methods. Currently there is only one setting available and it gives possibility to overwrite the default edit text. These setter methods all return the $fredi object back, so you can chain these nicely.

echo $fredi->setText("Edit bodytext")->body;
// Or
echo $fredi->setText("Manage footer images")->images($footer_settings_page);
// Or
echo $fredi->setText("Edit press release details")->render("title|summary|publishdate", $another_page);

Fredi has good memory, so when you once setText, it will remember it. You can always set new text or even reset to default.

You can also add additional css classes for link element:

echo $fredi->setClass("featured")->body;
// Or
echo $fredi->setClass("featured small")->body;

Hiding tabs

In context of inline editing, the additional tabs (Children, Settings and Delete) might be undesirable. You can edit ProcessFredi settings to globally disable those from Fredi modals. Other option is to disable them case by case. It works in similar manner like setText above:

echo $fredi->hideTabs("children")->body;
// Or
echo $fredi->hideTabs("children|delete|settings")->body;

Reset settings

$fredi->reset(); // This will reset all the settings: link text, classes and tabs hiding.

Support development

I built Fredi for my own needs and I really hope it will be helpful tool for you too. I have no plans to make it commercial. If you find Fredi valuable for you and want to support future development, please consider [donating few bucks] donation. Thanks!

If you are short on money, you can also support yourself by listening great Finnish singer Fredi.

License

Fredi is licensed under GNU/GPL V2

Uses few images from tinybox2 modal, which is free of charge for both personal or commercial projects under the creative commons license. SOURCE: http://www.scriptiny.com/2011/03/javascript-modal-windows/

fredi's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fredi's Issues

Page fields doesn't work, if custom php code used to find selectable pages

Problem seems to be with $page variable - it somehow doesn't respect it, it believes the $page is the modal Fredi Edit Process page instead of the context page.

How to replicate: edit page field and open "input" tab. Open "Custom PHP code to find selectable pages" and add something that uses $page. Like "return $page->parent->children;"

Now when you edit that field through Fredi you get totally different results than you would expect.

Fredi not closing when editing user template

Normal behaviour when using Fredi is that when hitting Save, page refreshes and modal closes. But when using it to edit a User template (that is the PW template for users), the page inside the modal refreshes but the modal stays open. So my client is confused as to wether the page is saved or not. It's confusing that on this particular template, behaviour is different. Any idea as to why is this way, or workaround? I've currently failed at trying to inject a javascript "fredi.close()" when that template is modified.
thanks

Adding page, just creates the page and redirects to the new page

I don't get why when I create a page I fill in title and save, then modal closes and I get redirected to the newly added page.

I was waiting for the editor to show to fill in values.

The pages I create aren't pages that are viewable, just entries on a parent. Maybe some option to configure this behaviour would be nice.

Multilanguage Strings

Please use __("Text") so we can translate things like

$out = "<h2>Adding new page under $parent->title</h2><p>{$parent->path}</p>";

ProcessFredi not active on alternative languages

I stumbled over this issue already a couple times, so time to file an issue.

If I install this module and have two or more languages setup with LanguageSupportPageNames installed, the process page will not be active for alternative languages. So the edit links don't work when viewing an alternative language, because the admin edit url could not be found and the url is "blank".

This could be a simple check in the install process of the module to set active state for alternative languages

// support for multi-languages, set the status[langid] of alternative languages
// to active (1) so we can get the url when editing alternative languages / @soma
if($this->modules->isInstalled("LanguageSupportPageNames")){
    if(count($this->languages) > 1){
        foreach($this->languages as $lang){
            if(!$lang->isDefault()) $page->set("status$lang->id",1);
        }
    }
}

Thanks

Compatibility with LanguageTabs (core)

Since now Ryan put LanguageTabs in core and the code to load when Fredi process is loading is now missing and so doesn't work anymore with Fredi modals. This was something I added to LanguageTabs via a PR... https://github.com/adamspruijt/LanguageFieldTabs/blob/master/LanguageFieldTabs.module#L42 , but Ryan got an older version it seems and it's not in anymore.

Now I'm not sure which modules should check for the existing of the other anymore. :) Since Lanugage Tabs listens only to ProcessPageEdit.

Now trying if Fredi could support LanguageTabs. And I got it working again with adding:

if($this->modules->isInstalled("LanguageTabs")){
$this->modules->get("LanguageTabs")->loadTabs();
}

in the ___execute of FrediProcess.module

But not sure about if LanguageTabs should really use ProcessPageEdit::execute to load and why not on all forms? What you think?

$this->fields problematic and it shows with latest dev

I get an error in my Fork of fredi I'm using since some time. I need to fix the module every now and then.

TemplateFile: Field 'frediAll' is not applicable to this page#0 /.../wire/core/Modules.php(387): ProcessPageEdit->init() ...

This seems that the use of $this->fields as a property was always problematic as this also points to $fields API same like $this->pages. I think new way to do it in future is $this->wire("pages"), but anyway I get this error because $this->fields = "frediAll"; etc.

Just wanted to mention.

Delete Pages

It doesn't work. Any thoughts? Have you experienced this too? I select move to trash and click "move to trash" and it says the page is saved but actually not trashed.

File uploads inside repeater doesn't work

Progress bar goes all the way to 100% and after that it just disappears. Looking ajax requests it sends back this response text: "page not saved (no changes)".

Some track changes needed, but where?

Cropping Images feature does not work

If I want to edit a picture and take advantage of the new PW image-cropping function, this does not work. I think because of Modal in Modal. PW 2.5.27

ProcessFredi need 'requires' => array('Fredi'),

After some problem with installing this module and uninstalling... (fault on my other module code) I noticed that if uninstalling Fredi, it doesn't uninstall ProcessFredi.

'requires' => array('Fredi'),

fixed it.

No frediparent class

What if there's not class on the parent?

parent.className = parent.className + " frediparent";

Won't add anything.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.