- Posts: 3722
COMMUNITY FORUM
K2 Add new item window resize
- william white
-
- Offline
- Platinum Member
Please Log in or Create an account to join the conversation.
- Hanny
-
- Offline
- Senior Member
- Posts: 48
If you add the following line of code to your item.php file it will close the window after the article is saved (the file is found in your_site\components\com_k2\views\item\tmpl\form.php)
Add this code at or around line 36 - after the line 'submitform( pressbutton );'
parent.$('sbox-window').close();
So it should now look like:
<?php endif; ?>submitform( pressbutton );parent.$('sbox-window').close();
I'm currently working on the javascript needed to refresh the page once the window closes so you'll see the 'Item Saved' text at the top of the screen.
If you do not change line 254 the article will be 'locked' on the backend - if you want the article to save without being locked you can change the text on line 254 to read:
<a class="toolbar" href="#" onclick="javascript: submitbutton('save'); return true;">
If you do this - the 'your item has been saved' text will not show - I'm working on resolving this
I hope this helps other people who were running into the same issue as me.
Please Log in or Create an account to join the conversation.
- Peter Clarke
-
- Offline
- New Member
- Posts: 4
Please Log in or Create an account to join the conversation.
- Hanny
-
- Offline
- Senior Member
- Posts: 48
From my reading it looks as if we don't even need to include
parent.$('sbox-window').close();
to get the window to close.
All that needs to be done is the following:
window.parent.location.reload();
That will reload the page, and since the new item is opened in an Iframe, when the page is reloaded the iframe will go away automatically.
BUT, it needs to be added to the postback from the javascript (which exists somewhere, that's why 'Add Item' changes to 'Edit Item')
I'm just too new to javascript to know where to look or where to put it in order for it to work.
Wish the developers would chime in on this considering it's been such a huge stumbling block for so many...
Please Log in or Create an account to join the conversation.
- Hanny
-
- Offline
- Senior Member
- Posts: 48
If you have users creating articles from the front end and you want the 'save' button to close the model box window that pops up when they add or edit an article - just follow the steps below to achieve this:
*Note: there are a few other fixes that work to close the box, but not refresh the page - this does both.
The key is passing an extra parameter through the URL that gets created when the user clicks "Save", then we just check to see if that parameter (which I will call 'step') exists - if it does, we refresh the page.
Lets follow along, first we must add this parameter to the URL created -
Open the item.php file located at:
Yoursite->administrator->components->com_k2->models->item.php
On or around line 646 - you will see some text that resembles:
case 'save': default: $msg = JText::_('Item Saved'); if ($front) $link = 'index.php?option=com_k2&view=item&task=edit&cid='.$row->id.'&tmpl=component'; else $link = 'index.php?option=com_k2&view=items'; break;
So what we need to do is add our parameter to that URL so it will look like this (remember I called the parameter 'step', and will be setting it =1) - the code will now look like this:
if ($front) $link = 'index.php?option=com_k2&view=item&task=edit&cid='.$row->id.'&step=1&tmpl=component';
Now when the user clicks 'save' the parameter 'step' is getting passed along, and when the form reloads to show the user their information they had entered, step=1!
So then we have to add the php to check for that - that's simple enough:
Open the form.php file located at:
Yoursite->components->com_k2->views->item->tmpl->form.php
In there you can see where the form actually begins (on or around line 249), what we want to do is just add a little bit of php that checks to see if our 'step' parameter is equal to 1. If it is - we'll refresh the parent page using some javascript, that will automatically close the model box and cause the 'item saved' text to display to the user letting them know what happened.
The existing code looks like :
<form action="index.php" enctype="multipart/form-data" method="post" name="adminForm" id="adminForm"> <div class="k2Frontend"> <table class="toolbar" cellpadding="2" cellspacing="4">
When finished it will look like this:
<form action="index.php" enctype="multipart/form-data" method="post" name="adminForm" id="adminForm"> <div class="k2Frontend"> <?php if (JRequest::getInt('step')=='1') { ?> <script language="javascript"> window.parent.location.reload(); </script> <?php } ?> <table class="toolbar" cellpadding="2" cellspacing="4">
That checks to see if 'step' is =1. If it is - it runs javascript to refresh the parent window - closing the box and refreshing the page automatically.
This ensures the easiest possible thing for the user (i.e. they don't have to click 'back' and 'refresh' which is extremely counter-intuitive) and gives the front end user a back-end experience.
I hope this helps people - it took me a LOT of chasing things in the wrong direction before I thought of this solution.
I'm pretty saddened the developers never helped with something that's affected so many people, but oh well - problem was solved!
Keep on, keepin' on!
Okay, here's how it's done.
If you have users creating articles from the front end and you want the 'save' button to close the model
box window that pops up when they add or edit an article - just follow
the steps below to achieve this:
*Note: there are a few other fixes that work to close the box, but not refresh the page - this does both.
The key is passing an extra parameter through the URL that gets created
when the user clicks "Save", then we just check to see if that parameter
(which I will call 'step') exists - if it does, we refresh the page.
Lets follow along, first we must add this parameter to the URL created -
Open the item.php file located at:
Yoursite->administrator->components->com_k2->models->item.php
On or around line 646 - you will see some text that resembles:
case 'save': default:
$msg = JText::_('Item Saved');
if ($front)
$link =
'index.php?option=com_k2&view=item&task=edit&cid='.$row->id.'&step=1&tmpl=component';
else
$link = 'index.php?option=com_k2&view=items';
break;
Please Log in or Create an account to join the conversation.
- juju
-
- Offline
- Premium Member
- Posts: 119
But I still don't like the pop-up box, I prefer a lot the Joomla basic window, integrate in the website, for adding article...
Has anyone tried to do that ? : remplace the pop-up box system and have a display like in backend, I mean with window integrate in the website ?
Thanks a lot ;)
Please Log in or Create an account to join the conversation.
- Andy Connell
-
- Offline
- Senior Member
- Posts: 54
Please Log in or Create an account to join the conversation.
- juju
-
- Offline
- Premium Member
- Posts: 119
For example, the user "Juju" add 4 articles, they are all locked. And when "Juju" logout, all article unlock itself.
Any idea ? It's really weird Oo ...
Thanks ;)
Please Log in or Create an account to join the conversation.
- Andy Connell
-
- Offline
- Senior Member
- Posts: 54
Please Log in or Create an account to join the conversation.
- Hanny
-
- Offline
- Senior Member
- Posts: 48
At least that was my understanding of what I saw.
Please Log in or Create an account to join the conversation.
- Odin Mayland
-
- Offline
- Platinum Member
- Posts: 404
If you log everyone out and you still see lock icons on the items then there is a problem.
Hanny said:
I thought it was a safety feature - so that if someone is logged in, their articles are 'locked' so they can't be edited/worked on while they may be working with them.
At least that was my understanding of what I saw.
Please Log in or Create an account to join the conversation.
- juju
-
- Offline
- Premium Member
- Posts: 119
I thought the security is only when the user edit an article, nobody can edit THIS article in the same time.
But here, each time a user is connected, all his article are locked in back end Oo
Please Log in or Create an account to join the conversation.
- juju
-
- Offline
- Premium Member
- Posts: 119
So what I could change that caused that ? The last thing I do is modify the button save to redirect with the code here : community.getk2.org/forum/topics/k2-add-new-item-window-resize?id=3536014%3ATopic%3A73456&page=13#comments
I don't understand, someone had an idea ?
Thanks ;)
Please Log in or Create an account to join the conversation.
- juju
-
- Offline
- Premium Member
- Posts: 119
So the problem really come from the modification :
<?php if (JRequest::getInt('step')=='1') { ?> <script language="javascript"> window.parent.location.reload(); </script> <?php } ?>
Can anybody confirm the problem ?
Thanks for your help ;)
Please Log in or Create an account to join the conversation.
- Hanny
-
- Offline
- Senior Member
- Posts: 48
All that bit of code does is say "If there is an integer that is = 1, refresh the page" it has nothing to do with the locking and/or unlocking of the pages.
Also, that code is ran after the database stuff has executed and the article is saved, so I really don't understand how that causes the issue - but if it does, it does. I'll have to look into it a bit myself - although I can't promise anything because for me it's not a big issue - I don't allow editing of other peoples articles anyway, so if they're 'locked' when that user is logged in I am okay with it.
I'll have to dig around, see what I can find.
Please Log in or Create an account to join the conversation.
- juju
-
- Offline
- Premium Member
- Posts: 119
In fact, if you quit the pop-up window with the little cross in top right corner, it's not the same than simply refresh the window.
Clicking on the cross or on cancel button do something.
When you refresh the window, the popup disappear,but it's not the same than clicking on the cross or cancel button ;)
Did you try to see the problem ? It's simple to trigger the problem :
Open a page, Log in backend, with admin account.
Open an other page, Log in front end with author account.
Click on "Add an article" on front end, and click on save, your modification quit the popup window and refresh the page behind.
Go in backend, go see your articles list, the last added is locked...
Please Log in or Create an account to join the conversation.
- Hanny
-
- Offline
- Senior Member
- Posts: 48
I'll have to figure out what the close window button is doing (and/or the cancel button) and try to add that code into the if statement.
That should essentially cure the issue (in theory anyway). I'll see what I can hack up.
Please Log in or Create an account to join the conversation.
- juju
-
- Offline
- Premium Member
- Posts: 119
But I did only few tests, so maybe you'll make it, I hope so :)
Thanks again ;)
Please Log in or Create an account to join the conversation.
- Jasper Newton
-
Topic Author
- Offline
- Senior Member
- Posts: 58
Please Log in or Create an account to join the conversation.
- Hanny
-
- Offline
- Senior Member
- Posts: 48
So the users who do use this, can stop being inconvenienced. Isn't that the point of a developer? To work to remove things that make the user experience inconvenient? If it wasn't for a few features K2 has that I couldn't find elsewhere, I would be using a different component for sure. Heck, might have been easier to integrate features the others were lacking, than it is to try and fix this 'inconvenience'.
Please Log in or Create an account to join the conversation.