Jquery select item from popup and post back to parent - php

In one of my projects, I have many different sections where I need to filter some data and select the required, for example - On newsletter page where I need to click a link to "add users" which opens up a popup window where I can search users by name, ID etc then check the checkboxes and click "Select". This adds their IDs (or maybe emails) in the hidden form on the Newsletter page.
Similarly, I need to attach a file to newsletter then I click on an another link which opens up a popup with list of files which I can search and then finally select one. I have similar other requirements in other sections of the website which means I have to write similar type of code again and again.
I won't mind duplicating code if it were to be used at one or two places. But I have more than 8-9 different sections where I have to select users, files, some other items etc so I was thinking if there was a generic plugin sort of tool which takes a url of the search page and returns the data back in a specific format to the parent opener window then I just include that code on each of these pages and just have to maintain one/two files only.
How would you handle this sort of requirement? Is there any JQuery plugin available which does similar thing?

I'm not aware of a plugin for this, but this Q&A looks relevant:
Open popup and refresh parent page on close popup
Perhaps you can be the hero who implements such a plugin, Mr user1421214!

Related

Quick Help: ExpressionEngine

Please forgive this question, I have just under an hour to get this done for a client and I have NEVER used Expression Engine before. I currently have multiple tabs open for the Documentation, Google etc... and am really struggling to find it. I don't have the time to go through all of them extensively for this.
This is what I need to edit:
When I log into the CMS there are three containers float next to each other; Create, Modify or Delete and View.
In the first one: Create. There is a link that says entry which when clicked slides down to reveal a plethora of options to create. One of them is Events. When I click events I am then taken to a page with multiple inputs and textareas etc..
What I need to do is this. I need to create a new option textfield there so the user can input a URL. Then I also need to be able to echo that out.
Cheers for the help folks
In your control panel nav bar, click Admin > Channel Administration > Channel Fields. You should see a list of "field groups". Likely one of them is called Events. Click on it, and you should be led to a list of existing fields in the Events channel. There should be a button on the upper right that says "Create a New Channel Field". Click that and you'll be taken to a form.
For Field Type you'll probably want to leave it as Text Input. Field label is what the end user will see on the publish form (ex. Event URL). Short name is what you'll use inside your templates to echo the url (ex. event_url). You can most likely leave all the other settings to their default values.
After you've created your field, you can now go to create a new entry in the Events channel, and you should see your new field in that form.
The next step is to edit your template. Go to Design > Templates > Template Manager. This will show you a list of all the templates on your site. You'll have to find your events template in this list (try searching for events). In this template you'l find your HTML and your "template tags". This is where you'd add your custom field for "echoing". Surround your custom field short name with one curly brace:
<p>LINK TO EVENT</p>
I hope this gets you on the right track.

Create paginated Drupal form. (Drupal 6)

I am trying to create a form which provide a checkbox element on each row. Problem is that I have 2000 rows which takes some time to load and also it is not easy to navigate through whole list.
Is there a way to create some kind of pagination in Drupal form ?
There's no built-in pagination of field values within the context of a larger form that I'm aware of. Instead, you'd probably want to consider a Javascript solution, where you load all 2000 form values, but you use JS and CSS to hide all but the first page. Then you create Javascript forward/back and page links which dynamically hide the first "page" of checkboxes and load the page in question.
The reason I recommend this, instead of an AJAX request that loads only the first 20 records and then dynamically loads more via a pager, is that you'd have to separately track and store which values had been checked (since the AJAX would literally throw away and reload the next 20 checkbox values). By contrast, if it doesn't slow the page down to load all 2000 checkboxes as, say, 100 individual sections behind the scenes, and then use your custom JS pager to show/hide the pages, your user could check and uncheck while paging and all the values would be remembered. (It's an often overlooked feature of HTML forms that they retain their field values even when hidden via CSS, which can be super helpful when you're aware of it).
I don't think a code snippet would be too useful here because this is a fairly open-ended problem, but the basic process would be:
Use hook_form_alter() to change the specific checkbox group field(s). Specifically, you would use markup to add the paginator controls after running the database query to retrieve the results and determine the number of pages.
Also as part of using hook_form_alter(), you would loop a page at a time and generate all 100 (or whatever number) pages of checkbox options, setting all but the first page to display:none in the <div> tags surrounding the checkbox options.
Create JS or jQuery functions in your site's custom theme, or put the code into an includes/ folder and load it dynamically through hook_form_alter (not elegant - I recommend always having a custom theme or sub-theme available). This function would listen for the link press and the current page and hide/show the proper CSS blocks.
If you wanted to get fancy, you could also create a JS-enabled page number field where you could type in a page number and hit Enter, or a search feature that would return individual results (more complex since now you'd have to be able to show/hide all individual records), and a check all/uncheck all feature for individual pages. Have fun!

Keeping track of more than one level of page referrers

The scenario (all happening within the administration area/backend):
From the listing page, the user clicks a link to view an article (on the backend).
From the article view page, the user clicks a link to edit that article.
In the article edit page, form is submitted to the current uri.
If validation succeeds or user cancels, user is redirected to the article view page.
From the article view page, the user click a 'back' link to return to the listing page.
List <--> View <--> Edit
Right now, I'm only able to track referring url from a previous page. In the edit form, I'm using a hidden field to maintain referral to the view page, lest it be changed during failed form POST submission to itself and user remains in the edit page.
Problem is that when the user returns to the view page from edit, the 'back' link to the listing page is now linked to the edit page.
FYI,
The listing page url is dynamic as the user should return to the listing on the same page and sort order (stored in query strings); therefore a fixed url is out of the question.
In the past, I've tried using sessions (e.g. SESSION['view_to_list_ref'] SESSION['edit_to_view_ref']), but it messed up with multiple tabs.
I could transition between view/edit via ajax, but I'm hoping to keep the app simple and ajaxless at this point of time.
I'm using PHP + Kohana 3.2 Framework
The only solution I can think of is to have the list page url encoded and appended to the 'view article' link via query string. This way, the location of the listing page is preserved even while in the edit page; as the referring url back to view page would also contain the listing page url in the query string. However I don't really like the idea of 'dirtying' the url with long parameter values (encoded or not).
I'm really hoping there is a more elegant solution to this problem of generally tracking multiple levels of page referrals; not just specifically to solving the scenario I've mentioned.
EDIT: Oh and the solution should be able to support multiple tabs performing the same scenario.
You could track the pages by using a unique identifying code in a PHP session, a temporary variable, and using a temporary database table that tracks page loads by these temporary values.
The database structure might be:
+-------------+-------------------+---------------------+
| Unique ID | Page Referral | Time of page load |
+-------------+-------------------+---------------------+
Tracking time of page load would allow you to selectively wipe loads older than X minutes, and keep the table relatively small.
Anyway, this would allow you to keep as many levels as you'd like, and if you wanted to add an auto incrementing counter field, or your own counter field, you could even keep a simple to use number system that tracks page loads, though I believe the time of page load would suffice for that scenario.

Store different data to each tab

I need store different post data to each tab in a browser. If I open a new instance of the same page, the data aren't shared between both.
My problem:
I'm building a CMS to control my website content. But I will open some instances of the same page (many tabs). So I have a search form to find news that I been created on my CMS. If I open a news item I have a cancel button that back to previous page (the news list).
The problem is that the news list have a pagination and a filter form. So I can, for instance, search by a term like "john doe" and advance to page 5, and open a news item. If I cancel, currently I back to news list without filter and on first page.
My solutions:
Well, I don't want to use the history.back() because I can submit a news form and click on back/cancel button. So, I'll back to the current form, what is wrong.
My second idea is to store a $_SESSION with the $_POST sent to the news list and the back button send me to /news/list/recovery-session, that will recovery the $_POST data from session. But it have a problem: if I open two tabs and make two searchs, I'll have only the last session saved.
Your solutions:
Well, I can work with PHP and JS to make it work. You can suggest a idea of what I can do. I think about work with COOKIES, but I belive that it is shared by domain, and not by tab, what is a problem.
Someone?
Generate a unique id and attach it to the form or some hidden element that will be submitted. Save that unique id in a cookie or session variable. Compare the two at time of submission.
If second tab has generated a new id, the first tab will not evaluate to true.
The main problem is the need to persist the state of what page to return to and also the search term when returning back to the news list page. There are many ways to accomplish this, but one simple method is by encoding this data into your query string.
As an example, assuming your search term is "john doe" and you are on page 5, pass that data along to your news page.
news.php?returnSearchTerm=john+doe&returnPage=5& ....
When the news page is created, you can format your cancel link to send you back to the list page with the correct parameters.
news_list.php?search=john+doe&page=5

Creative way to display tables with 35 columns

I have a form where users are entering 35 different fields.
I have a Content Management System where I want to display the results of an order on the form.
I've thought about adding a horizontal scrollbar inside the table, or limiting the table to the 10 most important columns and then making it so the administrator has to click on an entry to view all of the information on its own details page.
Do you know any creative ways that I can display the 35 fields on one page?
A standard Master/Detail Form should work. The table/grid would have key pieces of data and below it, the detail form would have all the details in a user friendly layout. To see the detail a user simply needs to select or click a row in the table/grid and the information rendered in the detail area is updated by the On_Click/On_Hover/etc event.
I don't know if this will fit your needs, but the jQuery ScrollTo plugin might be an interesting alternative to just a plain horizontal scrollbar.
Edit: There is another addon you might want to look at called columnManager.
I have had instances dealing with grids that are wide. In my own opinion, I think it is best to use the browser's (horizontal) scroll bar instead of having an "inner" (horizontal) scrollbar. A problem with http://demos.flesler.com/jquery/scrollTo/
Also, no clicks are involved or whatsoever. The user will be able to see everything by just scrolling. On the other hand, allowing the user to hide/show columns would also be good.

Categories