Jump to content

Admin Custom Pages Module


diogo

Recommended Posts

No I don't know of a better solution. But I don't really see a problem much as the script and styles gets added after the admin main.css...

One other solution would be to add an additional script and styles foreach to the admin default.php after the ones already there.

<?php foreach($config->cpScripts->unique() as $file) echo "\n\t<script type='text/javascript' src='$file'></script>"; ?>

And load scripts and styles to a new config array:

$this->config->cpStyles = new FilenameArray;
$this->config->cpScripts = new FilenameArray;

Then add scripts and styles to that.

This way you could also add styles and script even from within the template too.

Link to comment
Share on other sites

Maybe adding something like that would benefit to allow adding scripts and styles before all admin ones. Of course admin templates would have to implement it aswell as long as it's "hardcoded" in admin template. Which in the long run makes it hard to change those parts and every iteration (already were a couple in admin templates) all admin templates suffer from missing something. I could even see go as far as modularize the output so there would be a core module that would be hookable to add scripts and styles more precisely. Just thinking loud.

  • Like 1
Link to comment
Share on other sites

I agree, but in this case I will wait for Ryan to enter this discussion. Although he must have other things to worry about now :)

Another thing that could be done would be change the way that the files are added in the admin templates. Right now we have this:

$config->styles->prepend($config->urls->adminTemplates . "styles/main.css?v=2"); 
$config->styles->append($config->urls->adminTemplates . "styles/inputfields.css"); 
$config->styles->append($config->urls->adminTemplates . "styles/ui.css?v=2"); 
$config->scripts->append($config->urls->adminTemplates . "scripts/inputfields.js"); 
$config->scripts->append($config->urls->adminTemplates . "scripts/main.js?v=2"); 

But we could invert the order, and have this instead:

$config->styles->prepend($config->urls->adminTemplates . "styles/ui.css?v=2");
$config->styles->prepend($config->urls->adminTemplates . "styles/inputfields.css"); 
$config->styles->prepend($config->urls->adminTemplates . "styles/main.css?v=2");
$config->scripts->prepend($config->urls->adminTemplates . "scripts/main.js?v=2");
$config->scripts->prepend($config->urls->adminTemplates . "scripts/inputfields.js");
// here wold be prepended jQueryUi
// and here jQuery

Of course like this jQuery and jQueryUi would have to be included only here, and not on a file before, but we would be sure that any script or style added with $config->styles->append() would be the last.

Link to comment
Share on other sites

@Soma,

The "small" problem is when one needs to use CSS frameworks. Those need to come first before any custom styles. So, I'd want my foundation.min.css to come before mycustomstyles.css. At the end of the day, this file will need to be placed at the very bottom of the list. It's not such a big deal since one can always use a custom admin site template (even just a clone of the default admin theme) in which they can call the js and css in the order they want. This way, no worries about upgrades.

Link to comment
Share on other sites

  • 2 weeks later...

I will Ryan. For now I didn't have any problem with the module, and I know there where more people testing it, what do you guys think? Is the module ready to go to the directory? Kongondo, I guess you tested it much more than me, have you had some undesirable effects?

Link to comment
Share on other sites

Oops, Diogo, I forgot to respond to your question above! No undesirable effects (older version). I haven't had time to test the latest version of the module. Will do so soon and report any issues. Thanks for the release!

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

I've just merged a pull request by Pete that automatically replaces the admin.php file and creates the scripts&styles field during installation. That's two steps less  ;)

The version on github is now 1.0.4. Thanks Pete!!

  • Like 3
Link to comment
Share on other sites

  • 2 weeks later...

I'm trying to use this theme with one of the admin templates that has dropdowns in the top menu and it displays the child page there which is not necessary; I tried making the child page hidden but that doesn't currently work;

Just wondering if there is a workaround for those of us using this module, but where we can't have the top level menu item show a dropdown ... hope you get what i mean...

Link to comment
Share on other sites

I'm trying to use this theme with one of the admin templates that has dropdowns in the top menu and it displays the child page there which is not necessary; I tried making the child page hidden but that doesn't currently work;

Just wondering if there is a workaround for those of us using this module, but where we can't have the top level menu item show a dropdown ... hope you get what i mean...

I think you just have to do it at that template's theme level (e.g. teflon) using CSS/JS. What theme are you using? Maybe making it hidden didn't work because of CSS specificity?

Link to comment
Share on other sites

@kongondo - sorry i wasn't super coherent:

basically if you use this module with the default theme, it's fine because then your custom page appears in the top level menu.

But if you use this module on the latest stable version, you have to create a custom admin page as well as a child page of that to store the template reference;

And then if you use one of the admin templates with dropdowns in the admin, there is a child menu item which is useless because it will try to render the page in the admin template, which of course has no header/footer etc.. would be confusing for the client to see the parent and the child in the dropdown.

hope i'm making more sense, i guess i could post screenshots to make it more clear...

so the question would be can we make the child page unpublished or hidden, without throwing an error; this would solve the issue of the child menu item display.

Link to comment
Share on other sites

Actually I understood you the first time :) That's why I gave the example of the admin theme "teflon"; it does the sub-menus you talk about. 

Maybe the hidden route is what we should take. So, if this is to work in PW 2.3, we need to be able to render a hidden page....Is that possible?

Btw, making the child page hidden does not throw up an error in my tests (default theme); it just doesn't show the page...Does it throw up an error in your case?

Link to comment
Share on other sites

OK...quick hack to set child page hidden (hide it from sub-menu) but be able to render it...
 
change
 

// for the current stable version use this method
return $this->page->child->render();

to

// for the current stable version use this method [Kongondo ugly hack; how dare you!?! Tsk tsk ]
$k = $this->page->child("include=hidden");
return $k->render();

Works for me; tested with Teflon. Will try others...

@Diogo:

Is my Macrura's "hack" a solution/concept you could incorporate as we all wait to move to PW 2.3.x ? :D

Edit:

Macrura's solution requires less changes...see below

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

@kongondo - thanks and apologies for my verbosity..

so this can be fixed by changing line 72 and 75 like so:

        } elseif ($this->page->child('include=hidden')->id) {

            // for the current stable version use this method
            return $this->page->child('include=hidden')->render();
 

and then making the child page hidden..

well you beat me to it...but your code looks slightly different

Edited by Macrura
  • Like 2
Link to comment
Share on other sites

yes, this module is really essential - almost all new sites have some sort of data that needs to be brought together into a custom DataTable with various fields being displayed a certain format...

right now i have 2 ecommerce sites using this in combination with jquery datatables to make sortable/searchable products list, with direct edit links and add new products link...

ABB

Link to comment
Share on other sites

Thanks Diogo...you've been quiet lately...summer break? :)

Edit

This throws up an error

return $this->page->child->render('include=hidden'); 

Warning: array_merge() function.array-merge: Argument #2 is not an array in F:\xampp\htdocs\pwtests\wire\modules\PageRender.module on line 224


Can you supply arguments to render() like that?

  • 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.
×
×
  • Create New...