atk4 dialogURL close button - php

I'm using atk dialogURL with button false, i've some fields and added my buttons:
$f2->addSubmit();
$f2->addButton('Close')->js('click',$f2->js()->univ()->closeDialog());
if($f->isSubmitted()){
$f->update();
}
after push "Save" button my dialog don't close (I don't want it) then I click my close button dialog, but appear :
"'Changes on the form will be lost. Continue?'"
why? my data is correct saved in database. Seem that .form_changed is not updated

inside isSubmitted, you need to explicitly close the dialog:
if($f->isSubmitted()){
$f->update();
$f->js()->univ()->closeDialog()->execute();
}
By default before dialog is destroyed it checks if it's been changed. It's implemented by adding a class (form_changed) to the form tag. You have few other options. For example, you can remove the form altogether:
if($f->isSubmitted()){
$f->update();
$f->js()->remove()->execute()
}
Or:
$this->addButton('Close')->js('click',
$form->js()->find('form')->removeClass('form_changed')
)->univ()->closeDialog();

Related

Exit Tour on triggering of any event caused by parent view - Intro.js

File Manager - Home Normal
I am using most of my content based on AJAX callbacks. Clicking a link button on my page pops-up a modal (the btn has some class and jquery event is triggered to load that modal-pop-up and shows content). The Tour Guide used in my Application is Intro.js which I downloaded from http://www.introjs.com based on some recommendations from community.
IntroJs is working fine as long as the normal routine is carried out.
Here is my code for that (only related lines are included):
elementsArrays = getIntroElements(); // Get All the elements that can be in tour list
availableElements = getAvailableElements(elementsArrays) // Input the Array of Elements and Return Available Elements in page
TotalCount = availableElements.ids.length + availableElements.classes.length + 2; // Set the Object for ease-of-access
setUpIntroElements(); // SetsUp the route path for tourguide to move through
introJs().start(); // Starts the Tour Guide
But when I click a link button (when the tour guide is in progress, that button is accessible at that moment (e.g the target highlighted element is main container and update button is a part of highlighted area. so it is clickable.)), the corresponding modal window pops up but the tour is not done yet. I press left/right arrow keys and the next data-step of introjs appears over my modal popup window. (Modal popup window)
Here is my code for trying to shut the tour down
// Close the wizard on any button click or disabled clicking any button there in the page
$("body").on("click", ".filemgt-file-index a", function(e){
if( $(".introjs-showElement")[0] ) // case: the tour is in process
{
//e.stopPropagation(); // not working
e.stopImmediatePropagation() // not working
//var esc = $.event("keydown", {keyCode:27});
//$("body").trigger(esc); // didnt work at all
// Trigger the below event
// a.introjs-button.introjs-skipbutton
introJs().exit(); // Exit the Tour and Work on new set // doesn't work very well
// need to apply "press Esc event" programmatically in jquery
// Triggering event equavalent to pressing Esc button
// disable all events associated with it
introJs().exitIntro()
}
});
When I close/cancel my modal window, still the tour is not terminated and pressing left/right arrow key shows the corresponding data-step element intro. (File Manager - Home (after Closing Modal popup))
What I want to achieve is, if any of the links within tour guide is clicked, the tour should end and the new modal should popup with all focus on it.
The attached images illustrate what the situation is and what exactly I want to have. take a look and them, and let me know if I am missing something in the problem statement.
Thank you very much in Advance.
Stay Blessed.
This is not a standard solution but it helped me fix my problem on the go.
while looking at the source code appeared in my browser window (inspect Element (F12 Function-key), I found a class "introjs-skipbutton" against skip button of tool-tip pop.
I found that clicking on this button exits the tour so I put the below code in my JQUERY file:
// Close the wizard on any button click or disabled clicking any button there in the page
$("body").on("click", ".main_container_div_of_view a", function(e){
if( $(".introjs-showElement")[0] ) // case: the tour is in process
{
$('.introjs-skipbutton').click(); // Terminate Introduction
}
});
This does the trick and exits the tour. But still its not a standard practice in my opinion.

How to cache dynamically created form fields

I have Laravel project with view where user adds form fields dynamically.
There's AJAX "SAVE" button and link which opens "print view" of page.
If user hits Back button after printing, there's no dynamically added fields, although they are saved ( - if I reload the page, it renders correctly)
Am I missing something regarding caching these fields?
ok, i found few possible solutions:
1) target: _blank for links that lead away
2) input type=hidden for dynamically added fields, populated on onbeforeunload, and restored on page load (link)
but i choosed to force reloading pages after back button with such (dyn) content.
after BODY tag:
<input type="hidden" id="tmkReloadTest" value="reloaded" />
<script>
if(document.getElementById('tmkReloadTest').value!=="reloaded") {
location.reload();
}
window.onbeforeunload = function (e) {
document.getElementById("tmkReloadTest").value = "fromcache";
}
</script>
hope it helps..
br
Y

Submit two forms to the same page

I have been on this site all day and can't seem to find what I need - no duplicate post intended.
I have a form containing a link which calls a modal popup containing a different form.
###### PARENT PAGE #############
<form...>
...
link
...
</form>
**** MODAL POPUP ****
<form...>
...
<input type="submit" />
</form>
**** END MODAL POPUP ****
### END PARENT PAGE #############
When I submit the form in the modal popup, the parent page is refreshed to show the updated info in the corresponding section of the page; except that the first form is not submitted and when the page refreshes to update the necessary section, the contents of the first form is lost.
I have tried using ajax to refresh only the necessary section of the page but that doesn't work as the sections that need refreshing use php variables with contents from mysql.
The system does what it needs to do and I don't mind the refresh. But I need a way to keep the user data entered into the first form.
Is it possible to submit the first form at the same time as the second to the same php page or any other way of preserving the user data in the first form on page reload without submitting it.
You cannot do this with pure php. You'll need javascript and write it in a way that when you hit submit on the modal it 'puts' the information back into the parent form.
One way is to make the modal form submit button not an actual submit button.
You might even be able to get away with taking the filled out section dom elements in the modal injected back into the parent form. Some jquery plugins already do this. For example colorbox
Here is a working example using only ONE <form> tag and jquery colorbox. http://jsbin.com/olalam/1/edit
I am not a php developer, so I'll suggest an alternative approach.
Before you refresh the page, you can serialize the form and store the data locally (e.g. in a cookie) then restore the data back into the form. Granted, that will require a bit more JS code, but should get you what you want.
UPDATE: Since you mentioned that you might need a little assistance on the JS front, here is some guidance:
Grab the jquery.cookie plugin here.
Grab the jquery.deserialize plugin here.
Use the following code as a starting point.
.
// the name of the cookie
var cookieName = 'myCookieName';
function beforeSubmit() {
// serialize the form into a variable
var serializedForm = $('#id-of-form').serialize();
// store the serialized form
$.cookie(cookieName, serializedForm, { path: '/' });
}
function afterRefresh() {
// read the cookie
var serializedForm = $.cookie(cookieName);
// de-serialize the form
$('#id-of-form').deserialize(serializedForm, true);
}
HTH

Showing a lister when grid button clicked? (in Agile Toolkit)

I have a grid that have buttons in one of it's columns like this:
how can I show a lister or a new grid when the button clicked?
$grid=$page->add('Grid');
$grid->setModel('Tickets',array('subject','date','time','department','status','text'));
$grid->addColumn("button",'read_ticket_id','Read');
if($_GET['read_ticket_id']){
// this generates javascript to be executed on buttion click
//how can I show a lister or a new grid when the button clicked?
}
Check out examples in ATK4 Codepad.
http://agiletoolkit.org/codepad/gui/grid
Edit:
This is snippet from one of my pages. Maybe you can find it useful.
The idea behind this is that you actually generate JavaScript inside this IF statement and JavaScript then is sent back to your browser which then can make another request for something (reload existing object, create new, redirect to somewhere etc.)
...
if($_GET['ticket']){
// Join this report with selected ticket
$this->grid->model->addToTicket($_GET['ticket']);
// Reload
$this->js(null,array(
$x->js()->reload(),
$this->js()->univ()->successMessage('Successfully saved')
))->execute();
}
...
With $_GET['ticket'] you get ID of record in grid in which you clicked button "Add to Ticket". $x is some other object in this page, for example, some form, field, tab or other grid. With $this->grid->model you get reference to model associated with this grid and in that model I have custom action/method defined - addToTicket which do something with database.
You can also redirect to other page with $this->js()->redirect() or $this->js()->location() etc. Basically you can do whatever you want, but all of this need to generate JavaScript as result or instructions for your browser what to do next.
And don't forget to add ->execute() at the end! That will stop further parsing your page and will instantly generate JS response.
I found a good example for this question:
http://agiletoolkit.org/doc/grid/interaction
==========
$g=$p->add('Grid');
$g->setSource('user');
$g->addColumn('name');
$g->addColumn('surname');
$g->addColumn('button','info','More Info');
$g->dq->where('name is not null')->limit(5);
if($_GET['info']){
$g->js()->univ()->dialogURL('More info',
$this->api->getDestinationURL(
null,array(
'more_info'=>$_GET['info'],
'cut_object'=>'myform'
)))
->execute();
}
if($_GET['more_info']){
$f=$this->add('Form','myform');
$f->addField('readonly','name');
$f->addField('readonly','surname');
$f->setSource('user');
$f->setConditionFromGET('id','more_info');
}

Zend Framework - using jquery dialog for popup form in a Zend controller/action

I am editing to try to put my primary question at the beginning of this post:
1) I am sitting at my customers/preferences page updating info in the form
2) I want to add a widget to my list of available widgets, so I need to open the widgets/addWidget page/form to add a new widget (note I am still working in my current customers/preferences page/form, so I need to continue with this page after adding a new widget in the widgets/addWidget page/form.
3) I select a link to go to widgets/addWidget, and I have jQuery dialog open this link in a dialog with the addWidget form and submit button
4) after adding a newWidget in the dialog popup form, I want to submit the newWidget (the code for addWidget is in the widgets/addWidget controller/action, not in the customers/preferences action)
Problem: the addWidget form action goes to widgets/addWidget, so when I submit the addWidget form in the dialog, it takes me away from my current customers/preferences page
Question 1) what is the proper/best way given this scenario to popup a form in another controller/action to submit that form, but then resume my current controller/action?
Question 2) should I move all of my form and code from the widgets/addWidget controller action into my existing customers/preferences action? (that seems to be the wrong approach)
I have researched jQuery documentation, Zend documentation, and searched other threads with trusty Google and stackoverflow, but I am still struggling to figure out the right way to get this to work with Zend Framework and popup forms such as jQuery dialog.
I have a working Zend action/controller that using a Zend Form and view to display and process my form. I have also been able to use jQuery dialog to popup a window when I click the link to that controller/action.
My issue is with the proper way to get the dialog to display the form and still be able to submit and process the page. If I only load the #content tag in the dialog the form and submit button appear in the dialog box, but the submit button no longer works. If I let the dialog open the full page (not just the #content) now the form will process properly, but the form submit is set to go to my action page for processing, so the form submits and takes me away from the original page and to the real controller/action page instead.
In my customerController I have a preferencesAction where a customer can choose a widget from a list of widgets. When the customer needs to add a new widget to the list, I want to open the addWidgetAction from the WidgetsController in a popup form. I want to add the widget in the popup form, submit the form to the addWidgetAction, and come back to the customer/preferences page I was already working in (with the newly added widget available in my list to select from).
//CustomerController
public function preferencesAction(){
//this is where I click a link to /widgets/addWidget and use jQuery dialog for form
}
//Customer preferences.phtml
<script>
$(document).ready(function() {
$('#add-link').each(function() {
var $link = $(this);
var $dialog = $('<div></div>')
.load($link.attr('href'))
.dialog({
autoOpen: false,
title: $link.attr('title'),
width: 600,
height: 500,
buttons: {
"Add Widget": function(){
$("#AddWidget").submit();
},
"Cancel": function(){
$(this).dialog("close");
}
}
});
$link.click(function() {
$dialog.dialog('open');
return false;
});
});
});
</script>
<a id="add-link" href='<?php echo $this->url(array('controller' => 'widgets',
'action' => 'addwidget')); ?>'>Add a Widget...</a>
//WidgetsController
public function addWidgetAction(){
// display form to add widget
// process form, validate, add to widgets table
$baseUrl = $this->getRequest()->getBasePath();
$action = $baseUrl . '/widgets/addWidget';
$form = new Form_Widget();
$form->setName('Add Widge')
->setAction($action);
}
I need to understand how to get the dialog to load my Zend action page for form processing, but without requiring the entire layout with header, footer, etc. I also need to understand how to process the form in the dialog popup without moving away from my original page where the popup was linked from.
Thank you for your assistance!
Well, I am not sure if i understand your question but you can try this
You can load your form in UI dialog box, to disable layout do this on you can do this
public function addwidgetAction(){
$this->_helper->layout()->disableLayout();
//just diable layout and do eveything normal
}
on your preferences.phtml file load the content of url baseurl/contrller/addwidget to jquery modal dialog
UPDATE
One way is use a jqueryplugin fancybox (external src) check the forgot password link
The other way is to use ajax
UPDATE
Well now i read your question well, though don't understand so clearly, i understand that you are trying to do something that is quite ambitious. And you cannot achieve through normal load method. You need to use ajax
I have to admit that I don't like jquery ui modal dialog so i don't know much about it, and i usually use jquery fancy box where it would give me an ability to load external page. Maybe you can do this through jquery ui modal dialog box.
I guess the problem that you are facing right now is you open a dialog box, you get the form in dialog, and you submit the form, it sends the normal post request, so dialog is reloaded, that's what happens in the link i have above, just click on forgot password link
Well there's solution for that too, the solution is ajax, and i hope you are quite familiar with it. you send ajax request and get response back, and depending on your response, you can exit dialog box as well update the the parent (preferences controller page) but that is quite ..... I tried to so same with few months back, but not with zf, i don't know how much i accomplished but it sure gave me a nasty headache

Categories